:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e3e2dd;
  --text: #121212;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #d1500f;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee6;
  --series-1: #2a78d6;
  --good: #16803c;
  --good-soft: #e5f4ea;
  --warn: #9a6200;
  --warn-soft: #fbf1dc;
  --bad: #c42b2b;
  --bad-soft: #fbe7e7;
  --info: #2a62b8;
  --info-soft: #e6eefa;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1013;
    --surface: #17191e;
    --surface-2: #1e2127;
    --border: #2a2e36;
    --text: #eceef2;
    --text-2: #b4b8c2;
    --muted: #8a8f9b;
    --accent: #f1641e;
    --accent-ink: #ffffff;
    --accent-soft: #3a2116;
    --series-1: #3987e5;
    --good: #4ade80;
    --good-soft: #133222;
    --warn: #fbbf24;
    --warn-soft: #3a2d0e;
    --bad: #f87171;
    --bad-soft: #3b1717;
    --info: #7cb0ff;
    --info-soft: #172840;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1013;
  --surface: #17191e;
  --surface-2: #1e2127;
  --border: #2a2e36;
  --text: #eceef2;
  --text-2: #b4b8c2;
  --muted: #8a8f9b;
  --accent: #f1641e;
  --accent-ink: #ffffff;
  --accent-soft: #3a2116;
  --series-1: #3987e5;
  --good: #4ade80;
  --good-soft: #133222;
  --warn: #fbbf24;
  --warn-soft: #3a2d0e;
  --bad: #f87171;
  --bad-soft: #3b1717;
  --info: #7cb0ff;
  --info-soft: #172840;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.boot { padding: 40px; color: var(--muted); }

/* ── Layout ─────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; padding: 0 7px; }
.side-foot { margin-top: auto; display: flex; gap: 6px; padding: 0 6px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-bar { display: none; }

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 30; transform: translateX(-105%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .main { padding: 16px 16px 60px; }
}

/* ── Components ─────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stat .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 1px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }

.banner { border-radius: 10px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner .btn { margin-left: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 120px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.field .help { font-weight: 400; color: var(--muted); font-size: 12px; }
label.check { display: inline-flex; gap: 7px; align-items: center; font-weight: 400; cursor: pointer; }
label.check input { width: auto; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form .two { grid-template-columns: 1fr; } }
details.adv summary { cursor: pointer; color: var(--text-2); font-weight: 500; }
details.adv[open] summary { margin-bottom: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-weight: 500; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { appearance: none; border: 0; background: var(--surface); padding: 5px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* shop cards */
.shop-card { display: flex; flex-direction: column; gap: 12px; }
.shop-top { display: flex; gap: 12px; align-items: center; min-width: 0; }
.avatar { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.shop-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shop-meta div { background: var(--surface-2); border-radius: 8px; padding: 7px 9px; }
.shop-meta b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.shop-meta span { font-size: 11.5px; color: var(--muted); }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; font-size: 15px; }
.feed .ico.order { background: var(--good-soft); color: var(--good); }
.feed .ico.review { background: var(--info-soft); color: var(--info); }
.feed .ico.review_low, .feed .ico.error, .feed .ico.token { background: var(--bad-soft); color: var(--bad); }
.feed .ico.overdue { background: var(--warn-soft); color: var(--warn); }
.feed .body { min-width: 0; flex: 1; }
.feed .title { font-weight: 500; }
.feed .meta { color: var(--muted); font-size: 12px; }
.feed .desc { color: var(--text-2); font-size: 12.5px; margin-top: 2px; overflow-wrap: anywhere; }
.feed li.unseen .title::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--series-1); }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .bar.hl { filter: brightness(1.15); }
.chart-empty { height: 220px; display: grid; place-items: center; color: var(--muted); }
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 7px 10px; border-radius: 8px; font-size: 12.5px; box-shadow: 0 4px 18px rgba(0,0,0,.25); max-width: 260px;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* code + copy */
.code { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.code pre { margin: 0; white-space: pre; }
.code .copy { position: absolute; top: 6px; right: 6px; }
.keybox { font-family: var(--mono); background: var(--surface-2); border: 1px dashed var(--accent); padding: 10px 12px; border-radius: 8px; overflow-wrap: anywhere; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.issue { display: flex; gap: 6px; align-items: baseline; font-size: 12.5px; margin: 2px 0; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.json { max-height: 520px; overflow: auto; }
.tool-list { max-height: 640px; overflow: auto; }
.tool-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.tool-item:hover { background: var(--surface-2); }
.tool-item.active { background: var(--accent-soft); }
.tool-item .n { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.tool-item .d { color: var(--muted); font-size: 12px; }
.group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 10px 4px; font-weight: 700; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 12, .55); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; }
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; }
.modal-head .x { margin-left: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login img { width: 40px; margin-bottom: 12px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kv td:first-child { color: var(--text-2); white-space: nowrap; width: 1%; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1 1 220px; min-width: 0; }
