:root {
  --bg: #0d1117;
  --bg-2: #141b24;
  --bg-3: #1b242f;
  --line: #243040;
  --fg: #e6edf3;
  --fg-2: #9aa7b4;
  --fg-3: #64748b;
  --up: #3fb950;
  --down: #f85149;
  --warn: #d29922;
  --accent: #58a6ff;
  --accent-2: #a371f7;
  --flash-up: rgba(63, 185, 80, .22);
  --flash-down: rgba(248, 81, 73, .22);
}
:root[data-theme="light"] {
  --bg: #f6f8fa; --bg-2: #ffffff; --bg-3: #eef2f6; --line: #d5dce4;
  --fg: #10151b; --fg-2: #4a5665; --fg-3: #7b8794;
  --up: #1a7f37; --down: #cf222e; --warn: #9a6700; --accent: #0969da; --accent-2: #8250df;
  --flash-up: rgba(26,127,55,.16); --flash-down: rgba(207,34,46,.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--fg); min-height: 100vh;
  font: 13px/1.45 ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
button, input, select {
  font: inherit; color: var(--fg); background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 11px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.ghost { background: transparent; }
.muted { color: var(--fg-2); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------------------------------------------------------------- header */
.top {
  position: sticky; top: 0; z-index: 30; display: flex; flex-wrap: wrap;
  gap: 12px 20px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 15px; letter-spacing: .2px; }
.tag { font-size: 11px; color: var(--fg-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--fg-3); flex: none; }
.dot.on { background: var(--up); box-shadow: 0 0 0 3px rgba(63,185,80,.16); }
.dot.off { background: var(--down); }
.stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11.5px; color: var(--fg-2); }
.stats b { color: var(--fg); font-variant-numeric: tabular-nums; font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions input { width: 170px; }

.ticker-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line); min-height: 30px;
  scrollbar-width: thin;
}
.ticker-strip .ev {
  flex: none; font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: var(--bg-3); border: 1px solid var(--line); white-space: nowrap;
}
.ticker-strip .ev.liq-long { border-color: rgba(248,81,73,.5); }
.ticker-strip .ev.liq-short { border-color: rgba(63,185,80,.5); }
.ticker-strip .ev.ann { border-color: var(--accent); }

/* ----------------------------------------------------------------- table */
main { padding: 0 0 40px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 1450px; }
thead th {
  position: sticky; top: 0; z-index: 10; background: var(--bg-2);
  border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap;
  padding: 8px 10px; font-size: 11px; font-weight: 600; color: var(--fg-2);
  cursor: pointer; user-select: none;
}
thead th:first-child, thead th.l { text-align: left; }
thead th:hover { color: var(--fg); }
thead th.sorted { color: var(--accent); }
thead th .arrow { font-size: 9px; opacity: .8; }
tbody td {
  padding: 6px 10px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
tbody td.l { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-2); }
tbody tr.sel { background: var(--bg-3); box-shadow: inset 3px 0 0 var(--accent); }

td.flash-up { animation: fu .9s ease-out; }
td.flash-down { animation: fd .9s ease-out; }
@keyframes fu { from { background: var(--flash-up); } to { background: transparent; } }
@keyframes fd { from { background: var(--flash-down); } to { background: transparent; } }

.sym { display: flex; align-items: center; gap: 8px; }
.sym img { width: 18px; height: 18px; border-radius: 50%; background: var(--bg-3); }
.sym .code { font-weight: 650; }
.sym .nm { color: var(--fg-3); font-size: 11px; max-width: 130px; overflow: hidden;
           text-overflow: ellipsis; }
.up { color: var(--up); } .down { color: var(--down); } .warn { color: var(--warn); }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 10px;
  border: 1px solid var(--line); color: var(--fg-2);
}
.badge.cao { color: var(--down); border-color: rgba(248,81,73,.45); }
.badge.tb { color: var(--warn); border-color: rgba(210,153,34,.45); }
.badge.thap { color: var(--up); border-color: rgba(63,185,80,.4); }
.badge.new { color: var(--accent-2); border-color: rgba(163,113,247,.45); }
.score { font-weight: 650; }
.bar { display: inline-block; height: 4px; border-radius: 2px; background: var(--accent);
       vertical-align: middle; margin-left: 6px; }
.dim { color: var(--fg-3); }
.livedot { display:inline-block; width:6px; height:6px; border-radius:50%;
           background: var(--up); margin-right: 5px; vertical-align: middle; }
.livedot.stale { background: var(--fg-3); }
.empty { padding: 40px 16px; color: var(--fg-2); text-align: center; }

/* ---------------------------------------------------------------- drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
         opacity: 0; pointer-events: none; transition: opacity .18s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); z-index: 50;
  background: var(--bg-2); border-left: 1px solid var(--line);
  transform: translateX(101%); transition: transform .2s ease; display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 19px; }
.drawer-actions { display: flex; gap: 8px; }
.drawer-body { overflow-y: auto; padding: 14px 16px 60px; }

.sec { margin-bottom: 20px; }
.sec > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
            color: var(--fg-2); margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; }
.kv .cell { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
            padding: 7px 9px; }
.kv .cell .k { font-size: 10.5px; color: var(--fg-2); }
.kv .cell .v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.buckets { display: flex; flex-direction: column; gap: 5px; }
.brow { display: grid; grid-template-columns: 92px 1fr 42px; align-items: center; gap: 8px;
        font-size: 11.5px; }
.brow .track { height: 7px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.brow .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.flags { display: flex; flex-direction: column; gap: 6px; }
.flag { border-left: 3px solid var(--line); padding: 5px 9px; background: var(--bg-3);
        border-radius: 0 6px 6px 0; font-size: 11.5px; }
.flag.high { border-left-color: var(--down); }
.flag.medium { border-left-color: var(--warn); }
.flag.info { border-left-color: var(--accent); }
.flag .code { font-weight: 650; margin-right: 6px; }
table.mini { width: 100%; min-width: 0; font-size: 11.5px; }
table.mini th { position: static; background: transparent; padding: 4px 6px; }
table.mini td { padding: 4px 6px; }
.note { font-size: 11px; color: var(--fg-3); margin-top: 6px; }
.spark { display: block; width: 100%; height: 46px; }
.pill { display:inline-block; padding:2px 8px; border-radius:20px; background:var(--bg-3);
        border:1px solid var(--line); font-size:11px; margin:0 4px 4px 0; }
.loading { color: var(--fg-2); font-size: 12px; }
a { color: var(--accent); }

footer { padding: 14px 16px 30px; color: var(--fg-3); font-size: 11px;
         border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .stats { order: 3; width: 100%; }
  .actions input { width: 120px; }
}
