:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #17171a;
  --text-2: #55545a;
  --muted: #8a8990;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #9a6400;
  --warn-soft: #fdf1d8;
  --err: #c0362c;
  --err-soft: #fbe6e4;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #ecebe7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121214;
    --surface: #1b1b1e;
    --surface-2: #232327;
    --border: #2e2e33;
    --text: #f2f2f3;
    --text-2: #b9b8c0;
    --muted: #85848c;
    --accent: #3987e5;
    --accent-soft: #1b2a3d;
    --ok: #4cc38a;
    --ok-soft: #16291f;
    --warn: #e0a940;
    --warn-soft: #2d2412;
    --err: #ef6b61;
    --err-soft: #331a18;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #26262a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121214; --surface: #1b1b1e; --surface-2: #232327; --border: #2e2e33; --text: #f2f2f3;
  --text-2: #b9b8c0; --muted: #85848c; --accent: #3987e5; --accent-soft: #1b2a3d; --ok: #4cc38a;
  --ok-soft: #16291f; --warn: #e0a940; --warn-soft: #2d2412; --err: #ef6b61; --err-soft: #331a18;
  --series-1: #3987e5; --series-2: #d95926; --grid: #26262a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
h1 .mono, h2 .mono { font-size: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); font-weight: 600; }
.sub { color: var(--text-2); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* layout */
.layout {
  display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh;
  background: linear-gradient(to right, var(--surface) 231px, var(--border) 231px, var(--border) 232px, var(--bg) 232px);
}
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 16px;
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2);
  font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 20px; text-align: center; }
.sidebar .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }
.me-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
[data-theme-toggle] { line-height: 1; }
.main { padding: 28px 32px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.topbar { display: none; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--text-2); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .hint { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

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

/* forms */
label { display: block; font-weight: 500; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 3px; }
.field .error { color: var(--err); font-size: 12.5px; margin-top: 3px; }
input[type=text], input[type=number], input[type=password], input[type=url], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.inline-form { display: inline; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 0; font-weight: 500; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.error { background: var(--err-soft); color: var(--err); }

.pager { display: flex; gap: 6px; align-items: center; margin-top: 14px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented a { padding: 6px 12px; color: var(--text-2); font-weight: 500; border-right: 1px solid var(--border); }
.segmented a:last-child { border-right: none; }
.segmented a.active { background: var(--accent-soft); color: var(--accent); }
.segmented a:hover { text-decoration: none; background: var(--surface-2); }

.poster { width: 100%; max-width: 220px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
details summary { cursor: pointer; font-weight: 600; }
.kbd { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend .key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend .key.box { height: 10px; width: 10px; border-radius: 3px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 140px; z-index: 5; display: none;
}
.tooltip .t-title { color: var(--text-2); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .t-key { width: 12px; height: 3px; border-radius: 2px; }
.chart-table { display: none; margin-top: 10px; max-height: 260px; overflow: auto; }
.chart-table.show { display: block; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .card { padding: 24px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 18px 0; font-size: 12.5px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); background: var(--bg); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
  .main { padding: 18px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
