:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f9fafb; --border: #e5e7eb; --border-strong: #d1d5db;
  --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef2ff; --accent-text: #4338ca;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --info-soft: #e0f2fe; --info: #0369a1;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06); --shadow-lg: 0 20px 50px -12px rgba(15,23,42,.25);
  --radius: 12px; --radius-sm: 8px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0e14; --surface: #131722; --surface-2: #171c28; --border: #232a3a; --border-strong: #2f384c;
  --text: #e6e9ef; --muted: #94a3b8; --faint: #64748b;
  --accent: #6366f1; --accent-hover: #818cf8; --accent-soft: #1e2140; --accent-text: #a5b4fc;
  --ok: #4ade80; --ok-soft: #10291b; --warn: #fbbf24; --warn-soft: #2e2410; --bad: #f87171; --bad-soft: #2f1517; --info-soft: #0f2533; --info: #7dd3fc;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 15px; } h3 { font-size: 13px; }
a { color: var(--accent-text); text-decoration: none; } a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: grid; place-items: center; color: #fff; box-shadow: 0 4px 12px rgba(99,102,241,.35); }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; } .brand-sub { font-size: 12px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 550; text-decoration: none; transition: background .12s, color .12s; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 14px 10px 6px; font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }
.shell > div { min-width: 0; }
.main { padding: 28px 34px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head > div:first-child { min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.cols-2 { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat-ic { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; }
.stat-val { font-size: 22px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; } .stat-lbl { color: var(--muted); font-size: 12.5px; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 8px 13px; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer; transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); } .btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; } :root[data-theme="dark"] .btn.danger { color: #1a0808; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); } .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 9px; font-size: 12.5px; } .btn.icon { padding: 6px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
label.field small, .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 11px; width: 100%; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { resize: vertical; min-height: 74px; }
.row { display: flex; gap: 10px; align-items: center; } .row > * { min-width: 0; } .grow { flex: 1; }
.form { display: flex; flex-direction: column; gap: 14px; }
.input-group { display: flex; } .input-group input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); } .input-group .addon { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-left: 0; background: var(--surface-2); color: var(--muted); } .input-group select { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; width: auto; max-width: 55%; }
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; } .switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 1px 0 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); } .switch input:checked::after { transform: translateX(16px); }
.switch b { display: block; font-weight: 600; } .switch span { color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; } .seg button { border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; padding: 8px 14px; cursor: pointer; } .seg button.on { background: var(--accent); color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; } tbody tr:hover td { background: var(--surface-2); }
td.right, th.right { text-align: right; } .nowrap { white-space: nowrap; }
.cell-main { font-weight: 600; } .cell-sub { color: var(--muted); font-size: 12.5px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex: none; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; } .badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; } .badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; } .dot.ok { background: #22c55e; box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 22%, transparent); } .dot.bad { background: #ef4444; box-shadow: 0 0 0 3px color-mix(in srgb, #ef4444 22%, transparent); } .dot.warn { background: #f59e0b; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); } .banner.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .banner.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.banner b { display: block; } .banner .btn { margin-left: auto; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; align-items: center; } .kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 550; text-align: right; }
.bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; min-width: 80px; } .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.list { display: flex; flex-direction: column; } .list > div { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: baseline; } .list > div:last-child { border-bottom: 0; }
.list > div > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.list time { color: var(--faint); font-size: 12px; white-space: nowrap; flex: none; width: 108px; }
pre.records { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; font-size: 12px; line-height: 1.7; white-space: pre; max-height: 280px; }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .12s; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .14s; }
.modal.wide { max-width: 720px; }
.modal-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; } .modal-head p { margin: 4px 0 0; color: var(--muted); font-weight: 400; }
.modal-body { padding: 18px 22px; overflow-y: auto; } .modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 550; max-width: 420px; animation: pop .15s; } .toast.err { background: #b91c1c; color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent), var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 30px; }
.login .brand { padding: 0 0 20px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; } @keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 60px; display: grid; place-items: center; color: var(--muted); }
.muted { color: var(--muted); } .mt { margin-top: 16px; } .sep { height: 1px; background: var(--border); margin: 16px 0; }
.topbar { display: none; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); } .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 18px 16px 50px; } .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .stats { grid-template-columns: 1fr; } th, td { padding: 10px 12px; } }
