:root {
  --bg: #f4f5fa; --surface: #fff; --surface-2: #f8f9fc; --line: #e4e6ef; --text: #1d2033; --muted: #6b7088;
  --primary: #4338ca; --primary-soft: #eef0ff; --on-primary: #fff;
  --side: #161830; --side-text: #c9cbe0; --side-active: #2a2d55;
  --ok: #067647; --ok-soft: #e7f6ee; --warn: #9a5b00; --warn-soft: #fff4dd; --bad: #b42318; --bad-soft: #fdecea;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020; --surface: #181a2e; --surface-2: #20233b; --line: #353959; --text: #e7e8f3; --muted: #9a9dbb;
    --primary: #8b85ff; --primary-soft: #26285a; --on-primary: #0f1020; --side: #0b0c19; --side-active: #23264c;
    --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #3a2b08; --bad: #f87171; --bad-soft: #3d1414;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 22px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: #4338ca; display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }
.content { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .who { display: flex; align-items: center; gap: 12px; }
.main { padding: 24px 28px 48px; max-width: 1240px; }
.btn.menu-btn { display: none; }

/* building blocks */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-pad { padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.two { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.error-msg { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.note { background: var(--primary-soft); padding: 12px 14px; border-radius: 8px; }
.key-box { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px dashed var(--line); padding: 12px; border-radius: 8px; word-break: break-all; user-select: all; }
dl.facts { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.loading { padding: 30px; color: var(--muted); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin: 14px 0 4px; text-align: center; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.auth .brand-mark { margin: 0 auto; width: 44px; height: 44px; }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 30, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .card-head { position: sticky; top: 0; background: var(--surface); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
#toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 30; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 15; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 18px 16px 40px; }
  .topbar { padding: 10px 16px; }
  .two, .form-grid { grid-template-columns: 1fr; }
  dl.facts { grid-template-columns: 120px 1fr; }
}
@media print {
  .sidebar, .topbar, .no-print, #toast-root { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  body.printing #app, body.printing .modal .card-head, body.printing .modal-foot { display: none !important; }
  body.printing .modal-back { position: static; background: none; padding: 0; }
  body.printing .modal { box-shadow: none; max-height: none; max-width: none; }
}
/* Two-step login setup */
.steps { padding-left: 20px; margin: 0 0 14px; }
.steps li { margin-bottom: 10px; }
.qr { background: #fff; padding: 10px; border-radius: 8px; width: 200px; margin: 8px 0; }
.qr svg { display: block; width: 100%; height: auto; }
.key-box.codes { font-size: 15px; line-height: 1.9; text-align: center; letter-spacing: 1px; }
