:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-2: #3fb950;
  --warn: #d29922;
  --chip: #21262d;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
}

/* ---------- login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #18233b 0%, var(--bg) 60%);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.login-logo span, .brand span { color: var(--accent); }
.accent { color: var(--accent-2); }
.login-sub { color: var(--muted); margin: -6px 0 8px; }
.login-card label, .sidebar label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em;
}
.sidebar label.check {
  flex-direction: row; align-items: center; gap: 8px;
  text-transform: none; letter-spacing: 0; cursor: pointer;
}
.sidebar label.check input { width: 15px; height: 15px; accent-color: var(--accent); }
input, select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
button {
  cursor: pointer; border: none; border-radius: 8px;
  background: var(--accent); color: white; font-weight: 600;
  padding: 10px 14px; font-size: 14px;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .6; cursor: default; }
.login-error {
  background: #3d1d1d; border: 1px solid #6e2b2b; color: #ffb4b4;
  padding: 8px 10px; border-radius: 8px; font-size: 13px;
}

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}
.live-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.live-pill.on { color: var(--accent-2); border-color: #1f5132; }
.live-pill.on .dot { background: var(--accent-2); box-shadow: 0 0 6px var(--accent-2);
  animation: pulse 1.6s infinite; }
.live-pill.off { color: var(--warn); }
.live-pill.off .dot { background: var(--warn); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.card.flash { animation: flash 1s ease; }
@keyframes flash { 0% { border-color: var(--accent-2); } 100% { border-color: var(--border); } }
.ghost-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); font-weight: 500; padding: 7px 12px;
}
.ghost-btn:hover { background: var(--panel-2); }
.ghost-btn.full { width: 100%; margin-top: 6px; }

/* ---------- multi-select filters ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
/* The trigger looks exactly like the old <select>; the checkbox list is a
   floating panel (see .ms-opts) opened on click. */
.ms > summary {
  list-style: none; cursor: pointer; user-select: none;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 14px; min-height: 40px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  transition: border-color .12s;
}
.ms > summary::-webkit-details-marker { display: none; }
/* CSS chevron (rotates when open). */
.ms > summary::after {
  content: ""; flex: none; width: 7px; height: 7px; margin-right: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg); transition: transform .15s;
}
.ms > summary:hover { border-color: #3b4761; }
.ms[open] > summary { border-color: var(--accent); }
.ms[open] > summary::after { transform: translateY(1px) rotate(-135deg); }
.ms-text { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-text.placeholder { color: var(--muted); }
/* Per-filter clear (✕): only shown when that filter has a selection. */
.ms-clear {
  display: none; flex: none; cursor: pointer; width: 18px; height: 18px;
  border-radius: 50%; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1; color: var(--muted);
}
.ms.has-sel .ms-clear { display: inline-flex; }
.ms-clear:hover { background: var(--border); color: var(--text); }

/* Floating option panel. position:fixed lifts it out of the sidebar's
   overflow:auto (which would otherwise clip it); JS sets top/left/width from
   the trigger. Shown only while the <details> is open. */
.ms-opts {
  position: fixed; z-index: 50; display: none;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  max-height: 300px; overflow-y: auto; padding: 6px;
}
.ms[open] > .ms-opts { display: block; }
.ms-opts::-webkit-scrollbar { width: 10px; }
.ms-opts::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px; border: 3px solid var(--panel-2);
}
.sidebar .ms-opt {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0;
}
.sidebar .ms-opt:hover { background: var(--panel); }
.sidebar .ms-opt input {
  width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin: 0;
}
.ms-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.layout { display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  padding: 18px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
  height: calc(100vh - 57px); position: sticky; top: 57px; overflow:auto;
}
.sidebar h2 { margin: 0; font-size: 13px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); }
.legend { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.legend p { margin: 4px 0; font-size: 12px; }
.muted { color: var(--muted); }

.content { padding: 18px 22px; }
.status-line { color: var(--muted); margin-bottom: 14px; font-size: 13px; }

/* ---------- view tabs ---------- */
.viewtabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); font-weight: 600; padding: 7px 16px; border-radius: 999px;
}
.tab:hover { background: var(--panel-2); }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

/* ---------- aggregator (compare books) ---------- */
.match-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.agg { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.agg-side {
  font-size: 11px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px;
}
.agg-books { display: flex; flex-direction: column; gap: 5px; }
.agg-book {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 11px; transition: border-color .12s;
}
.agg-book:hover { border-color: var(--accent); }
.agg-book.best { background: #11271a; border-color: #1f5132; }
.agg-book .bk { font-weight: 600; }
.agg-book .bk-cents { font-size: 11px; color: var(--muted); }
.agg-book .bk-fair { font-size: 11px; color: var(--accent-2); }
.agg-book .px { margin-left: auto; font-size: 17px; font-weight: 800; }
.agg-book.best .px { color: var(--accent-2); }
.best-tag {
  font-size: 9px; font-weight: 800; color: var(--accent-2);
  border: 1px solid #1f5132; border-radius: 999px; padding: 2px 7px;
  letter-spacing: .06em;
}

/* ---------- cards ---------- */
.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.card-league { font-size: 12px; color: var(--accent); font-weight: 600; }
.card-book {
  margin-left: 8px; font-size: 10px; font-weight: 700; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px; vertical-align: middle;
}
.card-time { font-size: 12px; color: var(--muted); }
.card-teams { font-size: 16px; font-weight: 700; margin-bottom: 12px; line-height: 1.35; }
.badge {
  font-size: 10px; padding: 2px 7px; border-radius: 999px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; margin-left: 6px;
}
.badge.live { background: #3a1d1d; color: #ff7b7b; }
.badge.upcoming { background: #16263f; color: #6cb6ff; }
.badge.done { background: #21262d; color: var(--muted); }

.ml-row { display: flex; gap: 8px; }
.chip {
  flex: 1; background: var(--chip); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 6px; text-align: center;
  position: relative;
}
.chip .lbl { font-size: 11px; color: var(--muted); display:block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .cents { font-size: 18px; font-weight: 800; }
.chip .am { font-size: 11px; color: var(--muted); }
.card-foot { margin-top: 10px; font-size: 12px; color: var(--muted); }

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

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 20; overflow: auto;
}
/* The hidden attribute must win over the flex display above. */
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; width: min(900px, 100%); box-shadow: var(--shadow);
}
.modal-card.small { width: min(560px, 100%); }
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel); border-radius: 16px 16px 0 0;
}
.m-title { font-size: 18px; font-weight: 800; }
.m-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.modal-body { padding: 16px 20px 24px; }

.market { margin-bottom: 18px; }
.market h3 {
  font-size: 14px; margin: 0 0 8px; display: flex; gap: 8px; align-items: center;
}
.market .mtype { font-size: 11px; color: var(--muted); font-weight: 500; }
.sel-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.sel {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; cursor: pointer;
  transition: border-color .12s;
}
.sel:hover { border-color: var(--accent); }
.sel.susp { opacity: .5; }
.sel-label { font-size: 12px; color: var(--text); display:flex;
  justify-content: space-between; gap: 6px; }
.sel-line { color: var(--warn); font-weight: 700; }
.sel-main { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; }
.sel-cents { font-size: 18px; font-weight: 800; }
.sel-fair { font-size: 11px; color: var(--accent-2); }
.sel-am { font-size: 11px; color: var(--muted); margin-left: auto; }

/* ---------- freshness / staleness gating ---------- */
/* A stale book is shown as "no data": never a usable price, never compared. */
.stale-note { color: var(--warn); font-size: 12px; font-weight: 600; }
.card.stale { border-color: #6e5a1f; }
.card.stale .ml-row { opacity: .85; }
.bk-nodata { color: var(--warn); font-size: 12px; font-weight: 600; margin-left: auto; }
.agg-book.stale { opacity: .55; }
.agg-book.stale .bk { color: var(--muted); }
.stale-banner {
  background: #3a2d11; border: 1px solid #6e5a1f; color: var(--warn);
  border-radius: 9px; padding: 8px 12px; margin-bottom: 14px;
  font-size: 13px; font-weight: 600;
}
.modal-body.stale .sel-main { opacity: .5; }

.hist-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
table.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
table.hist th, table.hist td {
  text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border);
}
table.hist th:first-child, table.hist td:first-child { text-align: left; }
svg.spark { width: 100%; height: 120px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 12px; }
