:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #15181d;
  --muted: #677080;
  --accent: #2f6fed;
  --accent-soft: #e8efff;
  --live: #e5484d;
  --live-soft: #fdecec;
  --good: #1f9d55;
  --good-soft: #e5f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --chart: #2f6fed;
  --chart-fill: rgba(47, 111, 237, .14);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --surface-2: #1d222b; --border: #2a303b; --text: #e8ebf0; --muted: #8b94a5;
    --accent: #6e9bff; --accent-soft: #1d2a47; --live: #ff6369; --live-soft: #3a1a1c; --good: #3ecf7a; --good-soft: #15301f;
    --warn: #f0b250; --warn-soft: #362a14; --chart: #6e9bff; --chart-fill: rgba(110, 155, 255, .18);
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --surface-2: #1d222b; --border: #2a303b; --text: #e8ebf0; --muted: #8b94a5;
  --accent: #6e9bff; --accent-soft: #1d2a47; --live: #ff6369; --live-soft: #3a1a1c; --good: #3ecf7a; --good-soft: #15301f;
  --warn: #f0b250; --warn-soft: #362a14; --chart: #6e9bff; --chart-fill: rgba(110, 155, 255, .18);
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--live); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.icon { padding: 6px 9px; line-height: 1; }
.btn.danger { color: var(--live); }
.btn:disabled { opacity: .6; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
textarea { resize: vertical; width: 100%; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; }
.login-card h1 { font-size: 22px; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; padding: 7px 11px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-2); font-size: 11px; text-align: center; }
.tabs button[data-tab="live"] .count:not(:empty):not([data-zero]) { background: var(--live); color: #fff; }
.status { display: flex; align-items: center; gap: 10px; }
.quota { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.quota-bar { width: 70px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
#quota-fill { height: 100%; width: 0; background: var(--good); transition: width .3s; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
main { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.vcard { overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .12s; }
.vcard:hover { transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 16/9; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; top: 8px; left: 8px; background: var(--live); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; letter-spacing: .03em; }
.ccv { position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,.75); color: #fff; font-size: 13px; font-weight: 650; padding: 3px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.vbody { padding: 12px 14px; display: grid; gap: 6px; }
.vchan { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.vtitle { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vstats { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.vstats b { color: var(--text); font-weight: 600; }
.spark { width: 100%; height: 44px; display: block; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.live { background: var(--live-soft); color: var(--live); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.list { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 120px 1fr auto; gap: 14px; align-items: center; padding: 10px; cursor: pointer; }
.row img { width: 120px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.row .right { text-align: right; white-space: nowrap; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
.cell-title { display: flex; gap: 10px; align-items: center; min-width: 260px; }
.cell-title img { width: 64px; aspect-ratio: 16/9; object-fit: cover; border-radius: 5px; flex: none; }
.cell-title img.round { width: 36px; aspect-ratio: 1; border-radius: 50%; }
.delta-up { color: var(--good); }
.delta-down { color: var(--live); }

.add-card { display: flex; gap: 10px; padding: 12px; margin-bottom: 6px; }
.add-card input { flex: 1; min-width: 0; }

.change { padding: 10px 14px; display: grid; gap: 4px; }
.change .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.change .diff { display: grid; gap: 3px; font-size: 13px; }
.change del { color: var(--live); text-decoration: line-through; opacity: .85; }
.change ins { color: var(--good); text-decoration: none; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 12, 16, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
#modal-body { padding: 16px 18px 22px; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--border); }
.detail-top { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.detail-top img { width: 100%; border-radius: 10px; aspect-ratio: 16/9; object-fit: cover; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; align-content: start; }
.fact { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.fact .label { font-size: 11px; color: var(--muted); }
.fact .value { font-weight: 650; font-variant-numeric: tabular-nums; }
.desc { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 12px; max-height: 280px; overflow: auto; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chart { width: 100%; height: 220px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; padding: 16px 18px; }
.settings-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.settings-grid label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.settings-grid .wide { grid-column: 1 / -1; }
#quota-estimate { padding: 0 18px; }

/* insights */
.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.ins-card { padding: 16px; }
.ins-card ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.idea { padding: 16px; display: grid; gap: 8px; }
.idea .headline { font-size: 16px; font-weight: 650; }
.idea .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.idea .copy { cursor: pointer; }
.idea details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); position: relative; min-width: 80px; }
.bar > span { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.heat { display: grid; grid-template-columns: 34px repeat(24, 1fr); gap: 2px; font-size: 10px; color: var(--muted); }
.heat div { aspect-ratio: 1; border-radius: 3px; display: grid; place-items: center; }
.section-title { margin: 22px 0 10px; font-size: 16px; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  main { padding: 12px 16px 30px; }
  .banner { margin: 12px 16px 0; }
  .detail-top { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .ins-grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 90px 1fr; }
  .row img { width: 90px; }
  .row .right { grid-column: 1 / -1; text-align: left; }
  .add-card { flex-direction: column; }
}
