:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand h1 { margin: 0; font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.sidebar-brand span.sub { display: block; font-size: 11px; color: #94a3b8; margin-top: 2px; }
.nav-section { padding: 14px 12px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #64748b; font-weight: 600; }
.nav-list { list-style: none; margin: 0; padding: 0 8px; }
.nav-list a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px; color: var(--sidebar-text); font-weight: 500; font-size: 13.5px; transition: background 0.12s, color 0.12s; }
.nav-list a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-list a.active { background: var(--primary); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12.5px; }
.sidebar-footer .user-name { color: #fff; font-weight: 600; display: block; }
.sidebar-footer .user-role { color: #94a3b8; font-size: 11px; text-transform: uppercase; }
.sidebar-footer-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.content { padding: 24px 28px 40px; max-width: 1440px; width: 100%; }

/* Auth Layout */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
.auth-card { background: var(--surface); width: 100%; max-width: 440px; border-radius: 14px; padding: 32px; box-shadow: 0 20px 45px rgba(0,0,0,0.3); }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; }
.auth-card .muted { color: var(--muted); margin-bottom: 22px; }

/* Cards & Grids */
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); background: var(--surface-alt); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:hover td { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--success); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-slate { background: #f1f5f9; color: #475569; }

/* Forms & Buttons */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="file"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; transition: background 0.12s; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid rgba(255,255,255,0.18); padding: 5px 10px; font-size: 12px; }
.btn-ghost:hover { color: #fff; border-color: rgba(255,255,255,0.4); }

/* Filter Bar & Tabs */
.filter-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.scope-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.scope-pill { padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--border); background: #fff; color: #334155; }
.scope-pill:hover { background: #f1f5f9; text-decoration: none; }
.scope-pill.active { background: var(--sidebar-bg); color: #fff; border-color: var(--sidebar-bg); }

/* Flashes */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.flash-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.flash-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.flash-info { background: var(--info-bg); color: #075985; border-color: #bae6fd; }

/* Charts (Zero-dep crisp SVG/CSS) */
.bar-row { margin-bottom: 10px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.bar-track { height: 9px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 180px; }
.legend-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 3px 0; }
.legend-left { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* Collapsible Form Panels */
details.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow); }
details.panel summary { padding: 13px 18px; cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.panel summary::-webkit-details-marker { display: none; }
details.panel[open] summary { border-bottom: 1px solid var(--border); }
details.panel .panel-body { padding: 16px 18px; }

.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
.recovery-code { font-family: ui-monospace, monospace; font-size: 15px; font-weight: 700; text-align: center; padding: 10px; background: #f8fafc; border: 1px dashed #94a3b8; border-radius: 6px; letter-spacing: 0.08em; }

@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .content { padding: 16px; }
  .grid-4 { grid-template-columns: 1fr; }
}
