:root {
  --bg: #ffffff;
  --bg-elev: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --faint: #64748b;
  --accent: #0f172a;
  --accent-ink: #ffffff;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --brand-bd: #c7d2fe;
  --emerald: #059669;
  --emerald-bg: #ecfdf5;
  --emerald-bd: #a7f3d0;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-bd: #fde68a;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-bd: #fecaca;
  --violet: #6d28d9;
  --violet-bg: #f5f3ff;
  --violet-bd: #ddd6fe;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 16px -2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, 0.22);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.text-ok { color: var(--emerald); }
.text-warn { color: var(--amber); }
.text-bad { color: var(--red); }

/* Layout helpers */
.container { max-width: 1140px; margin: 0 auto; padding: 0 24px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 680px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 15px; border-radius: 9px; border: 1px solid var(--border-strong); background: #ffffff; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .14s ease; white-space: nowrap; box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--bg-elev); border-color: #94a3b8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #1e293b; }
.btn.brand { background: var(--brand); color: #ffffff; border-color: transparent; font-weight: 600; }
.btn.brand:hover { background: #4338ca; }
.btn.emerald { background: var(--emerald-bg); color: var(--emerald); border-color: var(--emerald-bd); font-weight: 600; box-shadow: none; }
.btn.emerald:hover { background: #d1fae5; }
.btn.danger { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); box-shadow: none; }
.btn.danger:hover { background: #fee2e2; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; }
.btn.ghost:hover { background: var(--bg-card-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 11px; font-size: 12px; border-radius: 7px; }
.btn.lg { height: 44px; padding: 0 22px; font-size: 14px; border-radius: 10px; }

/* Cards & surfaces */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-elev { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.kpi-card { background: #ffffff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 12px; color: var(--faint); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.025em; margin-top: 6px; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 4px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--bg-card-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--emerald-bg); color: var(--emerald); border-color: var(--emerald-bd); }
.badge.warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-bd); }
.badge.bad { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.badge.violet { background: var(--violet-bg); color: var(--violet); border-color: var(--violet-bd); }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-bd); }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; background: #ffffff; border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 9px 12px; color: var(--text); outline: none; transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }
textarea { resize: vertical; min-height: 82px; }
.codebox { display: flex; align-items: center; gap: 8px; background: #0f172a; border: 1px solid #1e293b; border-radius: 9px; padding: 11px 14px; font-family: var(--mono); font-size: 12.5px; color: #e2e8f0; overflow-x: auto; }
.codebox code, .codebox pre { margin: 0; flex: 1; white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 12.5px; color: #e2e8f0; }
.codebox .btn { background: #1e293b; color: #f8fafc; border-color: #334155; box-shadow: none; }
.codebox .btn:hover { background: #334155; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #ffffff; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); font-weight: 600; background: var(--bg-elev); }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #f8fafc; }

/* Dashboard Shell */
.shell { display: flex; min-height: 100vh; background: var(--bg-elev); }
.sidebar { width: 240px; flex: none; background: #ffffff; border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15.5px; letter-spacing: -0.02em; padding: 6px 10px 18px; color: var(--text); }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, #4f46e5, #0ea5e9); color: #ffffff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; border-radius: 8px; color: var(--muted); font-size: 13.5px; font-weight: 500; cursor: pointer; border: 1px solid transparent; background: transparent; width: 100%; text-align: left; transition: all .12s ease; }
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-bd); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.main { flex: 1; min-width: 0; padding: 28px 32px 64px; max-width: 1280px; }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; align-items: center; padding: 12px; }
  .brand { padding: 0 10px 0 0; }
  .sidebar-foot { margin-top: 0; padding-top: 0; border-top: 0; margin-left: auto; }
  .main { padding: 20px 16px 48px; }
}

/* Tabs */
.tabs { display: inline-flex; gap: 3px; background: var(--bg-card-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.tab { padding: 5px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; border: 0; background: transparent; transition: all .12s ease; }
.tab.active { background: #ffffff; color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }

/* Progress bars */
.bar { height: 7px; background: var(--bg-card-2); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.bar > i.warn { background: #f59e0b; }
.bar > i.hot { background: var(--red); }

/* Modals */
dialog.modal { border: 1px solid var(--border); border-radius: 16px; background: #ffffff; color: var(--text); padding: 0; width: min(94vw, 660px); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(4px); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-elev); }

/* Toast */
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 999; background: #0f172a; color: #ffffff; border: 1px solid #1e293b; padding: 11px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: 0 12px 30px rgba(15,23,42,0.22); opacity: 0; transform: translateY(10px); pointer-events: none; transition: all .2s ease; max-width: 440px; }
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.ok { background: #064e3b; border-color: #059669; }
.toast.bad { background: #7f1d1d; border-color: #dc2626; }
.hidden { display: none !important; }

/* Hero subtle light gradient */
.hero-glow { position: relative; overflow: hidden; background: radial-gradient(ellipse 80% 55% at 50% -10%, rgba(79,70,229,0.09), rgba(14,165,233,0.04) 45%, transparent 72%), #ffffff; }
.chart-svg { width: 100%; height: 215px; display: block; }
