:root {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --border: #1f2937;
  --border-soft: #1e293b;
  --text: #e5edf8;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --accent: #2563eb;
  --accent-2: #60a5fa;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header {
  height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 20px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15px;
}
.sidebar-logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--muted); cursor: pointer; font-weight: 500; transition: all 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(37, 99, 235, 0.15); color: var(--accent-2); border-left: 2px solid var(--accent); padding-left: 10px; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.content { flex: 1; padding: 24px; overflow-y: auto; }

@media (max-width: 768px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .hamburger { display: inline-flex !important; }
}
.hamburger { display: none; background: transparent; border: 0; color: var(--text); padding: 8px; cursor: pointer; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; }
.backdrop.open { display: block; }

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; transition: all 0.15s; font-size: 13px;
  background: var(--accent); color: white;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.warning { background: var(--warning); color: #1f2937; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

/* Inputs */
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }
.textarea { height: auto; padding: 10px 12px; min-height: 80px; resize: vertical; }
.label { display: block; color: var(--muted); font-size: 12px; font-weight: 500; margin: 12px 0 6px; }
.form-grid { display: grid; gap: 4px; }
.form-grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge.active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge.expiring { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge.expired { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge.suspended { background: rgba(148, 163, 184, 0.18); color: var(--muted); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* KPI */
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 24px; font-weight: 700; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi-icon {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: rgba(37, 99, 235, 0.12); color: var(--accent-2);
}
.kpi.success .kpi-icon { background: rgba(34, 197, 94, 0.12); color: var(--success); }
.kpi.warning .kpi-icon { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.kpi.danger .kpi-icon { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.kpi.muted .kpi-icon { background: rgba(148, 163, 184, 0.12); color: var(--muted); }

/* Table */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table th { background: var(--surface-2); color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--surface-2); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.code { font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace; font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.7);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-weight: 600; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.close-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.close-btn:hover { color: var(--text); }

/* Toast */
#toast-root { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; min-width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: slide-in 0.2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Login */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(circle at 10% 10%, rgba(37, 99, 235, 0.18), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(96, 165, 250, 0.12), transparent 50%),
    var(--bg);
}
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 24px; font-size: 13px; }

/* Filter chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); cursor: pointer; font-size: 12px; font-weight: 500;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: rgba(37, 99, 235, 0.18); color: var(--accent-2); border-color: var(--accent); }

/* Chart container */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 220px; }

/* Empty state */
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Misc utility */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--muted); }
.font-mono { font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

/* Env block */
.env-block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-all; color: var(--accent-2);
  position: relative;
}
.copy-btn { position: absolute; top: 8px; right: 8px; }

/* Status row helper */
.status-line { display: flex; align-items: center; gap: 8px; }
