:root {
  --bg: #08080d;
  --bg2: #0f0f16;
  --surface: #14141f;
  --surface2: #1a1a28;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f4f8;
  --muted: #8b8ba3;
  --primary: #ff6b00;
  --primary-hover: #ff8533;
  --primary-glow: rgba(255, 107, 0, 0.25);
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --sidebar-w: 260px;
  --radius: 14px;
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  font-family: 'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
}

.login-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(255, 107, 0, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(255, 107, 0, 0.08), transparent),
    var(--bg);
  z-index: 0;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.logo-block { text-align: center; margin-bottom: 2rem; }

.logo-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #ff9500);
  border-radius: 16px;
  font-weight: 800;
  font-size: 0.85rem;
  color: #000;
  letter-spacing: -0.02em;
}

.logo-mark.sm { width: 40px; height: 40px; font-size: 0.7rem; border-radius: 12px; }

.logo-block h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.logo-block p { color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; }

.login-foot {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── Shell ─────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-brand strong { display: block; font-size: 0.95rem; }
.sidebar-brand span { font-size: 0.75rem; color: var(--muted); }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }

.nav-item {
  text-align: left;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--primary-glow); color: var(--primary); }

.main { padding: 1.75rem 2rem; overflow-x: hidden; }

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.main-header h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.main-header p { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

/* ── Cards & stats ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.stat-card .num {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--primary);
  line-height: 1.1;
}

.stat-card .lbl { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; font-weight: 500; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-hint { border-color: rgba(255, 107, 0, 0.2); background: linear-gradient(135deg, var(--surface), rgba(255, 107, 0, 0.04)); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}

.card h3 { font-size: 1rem; font-weight: 600; }

.steps {
  margin-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.steps strong { color: var(--text); }

/* ── Forms ─────────────────────────────────────────────────── */
.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select, textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-row { display: flex; gap: 0.5rem; }
.input-row input { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.span-2 { grid-column: 1 / -1; }
.form-actions { margin-top: 0.5rem; }

.search-input { max-width: 280px; }

.form-error { color: var(--bad); font-size: 0.85rem; margin-top: 0.5rem; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:hover { border-color: rgba(255, 255, 255, 0.18); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #ff9500);
  border-color: transparent;
  color: #000;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; }
.btn-danger { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 -0.25rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }

th, td { padding: 0.75rem 0.65rem; text-align: left; border-bottom: 1px solid var(--border); }

th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

tr:hover td { background: rgba(255, 255, 255, 0.02); }

.code-cell { font-family: ui-monospace, monospace; font-weight: 600; letter-spacing: 0.02em; }

.badge {
  display: inline-block;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.active { background: rgba(34, 197, 94, 0.15); color: var(--ok); }
.badge.pending { background: rgba(245, 158, 11, 0.15); color: var(--warn); }
.badge.expired { background: rgba(239, 68, 68, 0.15); color: var(--bad); }
.badge.suspended { background: rgba(139, 139, 163, 0.15); color: var(--muted); }

.filter-tabs { display: flex; gap: 0.35rem; margin-bottom: 1rem; flex-wrap: wrap; }

.tab {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.tab.active, .tab:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-glow); }

.device-detail {
  margin-top: 1.25rem;
  padding: 1.15rem;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.65;
}

.device-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; }
.device-detail dt { color: var(--muted); font-weight: 500; }
.device-detail dd { word-break: break-all; }

.detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

.empty { text-align: center; color: var(--muted); padding: 2rem; font-size: 0.9rem; }

.muted { color: var(--muted); font-size: 0.88rem; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  padding: 0.85rem 1.25rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: 360px;
  animation: slideIn 0.25s ease;
}

.toast.ok { background: #14532d; border: 1px solid var(--ok); color: #bbf7d0; }
.toast.err { background: #450a0a; border: 1px solid var(--bad); color: #fecaca; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  background: var(--surface);
  color: var(--text);
  max-width: 400px;
  width: calc(100% - 2rem);
}

.modal::backdrop { background: rgba(0, 0, 0, 0.65); }
.modal h3 { margin-bottom: 0.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; flex: none; width: 100%; }
  .sidebar-foot { width: 100%; }
  .main { padding: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1; }
}
