:root {
  --bg: #f6f6f8; --card: #ffffff; --ink: #18181b; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --brand: #8a1c3c; --brand-ink: #ffffff; --brand-soft: #fbe7ee;
  --red: #b91c1c; --red-soft: #fee2e2; --amber: #b45309; --amber-soft: #fef3c7; --blue: #1d4ed8; --blue-soft: #dbeafe;
  --win: #1d4ed8; --win-soft: #dbeafe; --violet: #6d28d9; --violet-soft: #ede9fe; --gray-soft: #f1f5f9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 3px rgba(0, 0, 0, .07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12; --card: #18181c; --ink: #e7e7ea; --muted: #9ca3af; --line: #2a2a31; --soft: #22222a;
    --brand: #f0739a; --brand-ink: #2a0712; --brand-soft: #3d1322;
    --red: #f87171; --red-soft: #3b1414; --amber: #fbbf24; --amber-soft: #3a2a0a; --blue: #93c5fd; --blue-soft: #172554;
    --win: #93c5fd; --win-soft: #172554; --violet: #c4b5fd; --violet-soft: #2e1065; --gray-soft: #1e1e26;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1500px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 8px 16px; }
.logo { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--ink); }
.logo i { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-style: normal; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; font-weight: 500; position: relative; }
.nav a:hover { background: var(--soft); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--ink); }
.nav a b { background: var(--red); color: #fff; border-radius: 9px; font-size: 10px; padding: 0 5px; margin-left: 4px; }
.user { color: var(--muted); font-size: 13px; white-space: nowrap; }
main { max-width: 1500px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 960px) { .g2, .g3, .g21 { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; cursor: pointer; box-shadow: var(--shadow); border-top: 3px solid var(--line); }
.kpi:hover { border-color: var(--brand); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi.red { border-top-color: var(--red); } .kpi.red .v { color: var(--red); }
.kpi.win { border-top-color: var(--win); } .kpi.amber { border-top-color: var(--amber); } .kpi.violet { border-top-color: var(--violet); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { width: 100%; min-height: 120px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f input, label.f select, label.f textarea { font-size: 14px; }
label.ck { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.help { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--card); position: sticky; top: 0; }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td, table.t tr.sel td { background: var(--soft); }
table.t td.thumb { width: 44px; }
.thumb img { width: 38px; height: 38px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--line); display: block; }
.pname { font-weight: 500; }
.pname small { display: block; color: var(--muted); font-weight: 400; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--muted); }
.pill.losing, .pill.red { background: var(--red-soft); color: var(--red); }
.pill.tied, .pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.cheapest, .pill.win { background: var(--win-soft); color: var(--win); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.chip { display: inline-flex; gap: 4px; align-items: baseline; padding: 2px 7px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; margin: 1px 2px 1px 0; white-space: nowrap; }
.chip b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.low { border-color: var(--red); background: var(--red-soft); }
.chip.oos { opacity: .55; text-decoration: line-through; }
.chip.err { border-style: dashed; color: var(--muted); }
.chip .of { color: var(--violet); font-weight: 700; }
.gap-neg { color: var(--red); font-weight: 600; }
.gap-pos { color: var(--win); font-weight: 600; }

.bulkbar { position: sticky; top: 49px; z-index: 10; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--brand-soft);
  border: 1px solid var(--brand); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { min-width: 220px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tabs a.on { border-color: var(--brand); color: var(--ink); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 10px; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal-card { background: var(--card); border-radius: 12px; padding: 18px; width: min(860px, 100%); position: relative; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal-card.wide { width: min(1200px, 100%); }
.modal-x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--red); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); }
.login input { width: 100%; margin-bottom: 10px; }

.comp-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.comp-row:last-child { border-bottom: 0; }
@media (max-width: 700px) { .comp-row { grid-template-columns: 1fr; } }
.offers { margin: 4px 0 0; padding: 0; list-style: none; font-size: 12px; }
.offers li { padding: 2px 0; }
.offers li .pill { margin-right: 4px; }
.cand { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: 12px; border-top: 1px dashed var(--line); }
.cand:first-child { border-top: 0; }
.score { display: inline-block; min-width: 30px; text-align: center; font-weight: 700; border-radius: 5px; padding: 0 4px; font-size: 12px; }
.score.hi { background: var(--win-soft); color: var(--win); }
.score.mid { background: var(--amber-soft); color: var(--amber); }
.score.lo { background: var(--red-soft); color: var(--red); }
.chart { width: 100%; height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.prog { height: 6px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.prog > i { display: block; height: 100%; background: var(--brand); }
pre.code { background: var(--soft); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.tog { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tog button { border: 0; background: var(--card); padding: 3px 8px; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted); }
.tog button.on { background: var(--brand); color: var(--brand-ink); }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 11px; }
@media (max-width: 700px) { .top-in { flex-wrap: wrap; } .user { display: none; } main { padding: 10px; } }
