:root {
  color-scheme: light;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f1f1f5;
  --border: #e3e3ea;
  --text: #16161d;
  --text-2: #4f4f5c;
  --text-3: #80808e;
  --accent: #5b4fc4;
  --accent-soft: #ecebfb;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --good: #1b7a4a;
  --good-soft: #e6f4ec;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e9e9ef;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 4px 16px rgba(20, 20, 40, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111117;
    --surface: #1a1a22;
    --surface-2: #22222c;
    --border: #2e2e3a;
    --text: #f2f2f6;
    --text-2: #c2c2cf;
    --text-3: #8d8d9c;
    --accent: #9d93f0;
    --accent-soft: #2a2748;
    --danger: #ff8a80;
    --danger-soft: #3a1c1b;
    --good: #6fd19b;
    --good-soft: #17301f;
    --warn: #f2c14e;
    --warn-soft: #33290f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2a35;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, sans-serif; }
a { color: var(--accent); }
.boot { padding: 48px; color: var(--text-3); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 600; }
.brand .mark { width: 28px; height: 28px; border-radius: 9px; background: var(--accent-soft);
  display: grid; place-items: center; color: var(--accent); font-size: 15px; }
.nav-group { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px;
  border-radius: 8px; color: var(--text-2); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav .count { font-size: 11px; background: var(--danger-soft); color: var(--danger);
  border-radius: 99px; padding: 0 7px; }
.side-foot { margin-top: 18px; padding: 12px 10px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-3); }
.main { padding: 28px 32px 64px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 600; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--text-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* cards & tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.card .sub { color: var(--text-3); font-size: 12.5px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px;
  margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow); }
.tile .k { color: var(--text-3); font-size: 12.5px; }
.tile .v { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -.02em; }
.tile .h { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-box { position: relative; height: 260px; }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); background: var(--surface-2);
  position: sticky; top: 0; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.muted { color: var(--text-3); }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--text-3); }

/* pills */
.pill { display: inline-block; font-size: 11.5px; font-weight: 500; border-radius: 99px;
  padding: 1px 9px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; width: 100%; }
textarea { min-height: 110px; resize: vertical; }
textarea.tall { min-height: 320px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
label.f small { color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.search { max-width: 280px; }
.btn { font: inherit; font-weight: 500; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 9px; padding: 7px 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: var(--surface); color: var(--text-2);
  padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--text-2);
  font-size: 13px; margin-bottom: 14px; }
.md-preview { border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px;
  min-height: 320px; background: var(--surface-2); overflow: auto; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login h1 { margin: 0 0 6px; font-size: 20px; }
.login p { color: var(--text-3); margin: 0 0 18px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.code { font-family: ui-monospace, Menlo, monospace; word-break: break-all; font-size: 12px; }

/* modal & toast */
.backdrop { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); display: grid;
  place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 720px;
  max-height: 90vh; overflow: auto; padding: 22px; border: 1px solid var(--border); }
.modal.wide { max-width: 1040px; }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 10px;
  font-size: 13px; max-width: 380px; }
.toast.err { background: var(--danger); color: #fff; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px;
  vertical-align: -1px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .main { padding: 18px 16px 48px; }
}
input:disabled, select:disabled, textarea:disabled { opacity: .6; }
