:root {
  --bg: #0a0a0a;
  --bg-2: #111114;
  --card: #18181b;
  --card-hi: #1f1f23;
  --border: #27272a;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --muted: #71717a;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.error { color: var(--red); margin-top: 8px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); color: #fff; }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--card-hi); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); background: var(--card); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid #4a1f1f;
}
.btn-danger:hover { background: #2a1010; color: #fff; }

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 60px; font-family: ui-monospace, monospace; font-size: 12px; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.form label input, .form label select, .form label textarea { color: var(--text); }

.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ============ LOGIN ============ */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  max-width: 380px;
  width: 100%;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 0; font-size: 12px; }

.logo-glyph {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1.5px solid var(--accent);
  position: relative;
}
.logo-glyph::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
}
.logo-glyph.small { width: 28px; height: 28px; border-radius: 7px; }
.logo-glyph.small::before { inset: 5px; border-radius: 2px; }

/* ============ APP LAYOUT ============ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 57px);
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .layout.has-detail .device-list { display: none; }
}

/* ============ DEVICE LIST ============ */
.device-list {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-2);
}
.list-controls {
  padding: 12px;
  display: flex; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.list-controls select { width: 140px; flex-shrink: 0; }
.devices {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}
.device-item {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.device-item:hover { background: var(--card); }
.device-item.selected {
  background: var(--card);
  border-color: var(--border);
}
.device-item .row.between { gap: 8px; }
.device-item .name { font-weight: 600; }
.device-item .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.offline { background: var(--muted); }
.dot.provisioned { background: var(--amber); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.online { background: rgba(16,185,129,0.15); color: var(--green); }
.badge.offline { background: rgba(113,113,122,0.2); color: var(--text-2); }
.badge.provisioned { background: rgba(245,158,11,0.15); color: var(--amber); }
.badge.suspended { background: rgba(239,68,68,0.15); color: var(--red); }
.badge.unassigned { background: rgba(96,165,250,0.18); color: var(--accent); }

/* ============ DEVICE DETAIL ============ */
.device-detail {
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}
.empty {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}
.empty h2 { margin: 0 0 8px; font-weight: 500; color: var(--text-2); }

.detail-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.detail-header h2 { margin: 0 0 4px; font-size: 22px; }

.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.section h3 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-all; font-family: ui-monospace, monospace; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-x: auto;
}
.activation {
  text-align: center; padding: 24px;
  background: linear-gradient(135deg, rgba(96,165,250,0.1), transparent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.activation .code {
  font-family: ui-monospace, monospace;
  font-size: 28px;
  letter-spacing: 4px;
  font-weight: 700;
  margin: 8px 0 14px;
}

.upload-row {
  display: flex; align-items: center; gap: 12px;
  margin-top: 8px;
}
.upload-preview {
  width: 80px; height: 80px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  flex-shrink: 0;
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.swatch.selected { border-color: #fff; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.toggle {
  position: relative; display: inline-block;
  width: 40px; height: 22px;
}
.toggle input { display: none; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--card-hi);
  border-radius: 11px;
  transition: background 0.15s;
}
.toggle .slider::before {
  content: ''; position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  transition: transform 0.15s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 { margin: 0 0 6px; }

#add-result .code-block { margin-top: 16px; max-height: 200px; overflow-y: auto; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--card-hi);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 200;
  animation: slideUp 0.2s ease;
}
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--card-hi); }
