/* theme.css — Track Jimmy design tokens (dark/light/auto) + whale matrix styles.
 * Ported from /hshg-app/static/style.css token system. Never hardcode hex in
 * page CSS — reference these vars so light mode + the toggle work everywhere. */

:root {
  --bg-base: #0a0e0c;
  --bg-surface: #121a16;
  --bg-card: #162018;
  --bg-elevated: #1e2820;
  --bg-hover: #263028;
  --border-subtle: #2a3a30;
  --text-primary: #e4ece6;
  --text-secondary: #7a8e80;
  --text-muted: #4a5e50;
  --accent-green: #4a9e6a;
  --accent-red: #b85a5a;
  --accent-amber: #c4a44a;
  --accent-gold: #c9a961;
  --accent-gold-soft: rgba(201, 169, 97, 0.12);
  --accent-gold-border: rgba(201, 169, 97, 0.28);

  /* consensus cell tints (dark) — derived from green/red, kept subtle */
  --agree-bg: rgba(74, 158, 106, 0.16);
  --agree-fg: #6fce93;
  --agree-bd: rgba(74, 158, 106, 0.40);
  --fade-bg: rgba(184, 90, 90, 0.16);
  --fade-fg: #e08f8f;
  --fade-bd: rgba(184, 90, 90, 0.40);
  --blank-bg: rgba(255, 255, 255, 0.015);
  --blank-fg: var(--text-muted);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
  --bg-base: #f4f7f5;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #edf2ee;
  --bg-hover: #e2eae4;
  --border-subtle: #c4d4c8;
  --text-primary: #1a2820;
  --text-secondary: #4a6050;
  --text-muted: #8ea898;
  --accent-green: #2e7a4a;
  --accent-red: #a04040;
  --accent-amber: #9a7a2a;

  --agree-bg: rgba(46, 122, 74, 0.14);
  --agree-fg: #1f6e3e;
  --agree-bd: rgba(46, 122, 74, 0.38);
  --fade-bg: rgba(160, 64, 64, 0.12);
  --fade-fg: #983636;
  --fade-bd: rgba(160, 64, 64, 0.34);
  --blank-bg: rgba(0, 0, 0, 0.02);
  --blank-fg: var(--text-muted);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-base: #f4f7f5;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-elevated: #edf2ee;
    --bg-hover: #e2eae4;
    --border-subtle: #c4d4c8;
    --text-primary: #1a2820;
    --text-secondary: #4a6050;
    --text-muted: #8ea898;
    --accent-green: #2e7a4a;
    --accent-red: #a04040;
    --accent-amber: #9a7a2a;
    --agree-bg: rgba(46, 122, 74, 0.14);
    --agree-fg: #1f6e3e;
    --agree-bd: rgba(46, 122, 74, 0.38);
    --fade-bg: rgba(160, 64, 64, 0.12);
    --fade-fg: #983636;
    --fade-bd: rgba(160, 64, 64, 0.34);
    --blank-bg: rgba(0, 0, 0, 0.02);
    --blank-fg: var(--text-muted);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg-base); color: var(--text-primary);
  font: 14px/1.5 var(--font-body);
}

/* --- unified app bar + tab bar (shared chrome across all views) --- */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 8px 18px; background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap; }
.appbrand { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.appbrand { color: var(--text-primary); }
.tabbar { display: flex; gap: 4px; flex: 1 1 auto; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tab-link { color: var(--text-secondary); font-weight: 600; font-size: 13px; white-space: nowrap;
  padding: 7px 13px; border-radius: 8px; text-decoration: none; }
.tab-link:hover { color: var(--text-primary); background: var(--bg-hover); text-decoration: none; }
.tab-link.active { color: var(--accent-gold); background: var(--accent-gold-soft);
  box-shadow: inset 0 -2px 0 var(--accent-gold); }
.appbar .theme-toggle { margin-left: auto; flex: 0 0 auto; }
@media (max-width: 680px) {
  .appbar { padding: 6px 10px; gap: 8px; }
  .appbrand { font-size: 13px; }
  .tab-link { padding: 6px 10px; font-size: 12px; }
}

/* --- header / nav --- */
header { padding: 20px 22px 8px; }
h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
h1 .hl { color: var(--accent-gold); }
.sub { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
a { color: var(--accent-green); text-decoration: none; }
a:hover { text-decoration: underline; }
.toollinks { margin-top: 8px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.toollinks a { color: var(--accent-green); }
.toollinks .muted { color: var(--text-muted); }

/* theme toggle */
.theme-toggle { background: var(--bg-elevated); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: 8px; padding: 5px 11px;
  font: 600 12px var(--font-body); cursor: pointer; }
.theme-toggle:hover { color: var(--text-primary); border-color: var(--accent-gold-border); }

/* --- tabs (sections) + category tabs --- */
.tabs { display: flex; gap: 8px; padding: 6px 22px 4px; flex-wrap: wrap; }
.tab { background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; user-select: none; transition: all .15s; }
.tab:hover { color: var(--text-primary); border-color: var(--accent-gold-border); }
.tab.active { background: var(--accent-gold-soft); color: var(--accent-gold);
  border-color: var(--accent-gold-border); }
.tab .ct { opacity: .7; font-weight: 500; margin-left: 5px; }

.cat-tabs { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.cat { background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: 8px; padding: 7px 16px;
  font-size: 14px; font-weight: 700; cursor: pointer; user-select: none; transition: all .15s; }
.cat:hover { color: var(--text-primary); border-color: var(--accent-gold-border); }
.cat.active { background: var(--accent-gold-soft); color: var(--accent-gold);
  border-color: var(--accent-gold-border); }

/* --- matrix grid --- */
.wrap { padding: 10px 16px 50px; overflow-x: auto; }
table { border-collapse: separate; border-spacing: 0; min-width: 100%; margin-bottom: 8px; }
th, td { padding: 0; text-align: center; }
thead th { position: sticky; top: 0; background: var(--bg-base); z-index: 2;
  padding: 8px 6px; color: var(--text-secondary); font-weight: 600; font-size: 12px;
  border-bottom: 1px solid var(--border-subtle); white-space: nowrap; }
th.whale .nm { color: var(--text-primary); display: block; }
th.whale .rk { color: var(--text-muted); font-size: 11px; font-weight: 400; }
/* The three "always visible" columns — Market, Consensus, Volume — are pinned to
   the left as a sticky group, so the numbers you scan most never scroll off no
   matter how many whale columns follow. Their `left` offsets stack: 0, then the
   market width, then market+score width. (Widths below must match these offsets.) */
th.mkt, td.mkt { text-align: left; position: sticky; left: 0; background: var(--bg-base);
  z-index: 3; width: 230px; min-width: 230px; max-width: 230px; padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle); border-right: 1px solid var(--border-subtle); }
th.score, td.score { position: sticky; left: 230px; background: var(--bg-base); z-index: 3;
  width: 74px; min-width: 74px; }
th.vol, td.vol { position: sticky; left: 304px; background: var(--bg-base); z-index: 3;
  width: 66px; min-width: 66px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums; font-size: 12px;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle); }
/* sticky header cells of the pinned group must out-rank both axes */
thead th.mkt, thead th.score, thead th.vol { z-index: 4; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent-gold); }
.sorthint { opacity: .35; font-size: 10px; }
th.sortable:hover .sorthint { opacity: .9; }
/* market title: wrap to 2 lines, clamped — never cut off, no hover needed */
td.mkt .t { font-weight: 600; line-height: 1.3; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td.mkt .lead { color: var(--text-secondary); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.mkt a { color: inherit; }
td.cell { border-bottom: 1px solid var(--border-subtle); }

/* consensus pills: color = agree/fade, but ALWAYS show outcome word + ✓/✗ icon
   (hshg rule: never convey info by color alone) */
/* whale columns are kept narrow — the pill drives their width */
th.whale, td.cell { min-width: 58px; max-width: 72px; }
th.whale .nm { font-size: 12px; }
.pill { display: block; margin: 4px 3px; padding: 6px 3px; border-radius: 7px;
  font-weight: 700; font-size: 11px; letter-spacing: .1px; white-space: nowrap; }
.pill .ico { font-weight: 800; margin-right: 2px; }
.pill.agree { background: var(--agree-bg); color: var(--agree-fg); border: 1px solid var(--agree-bd); }
.pill.fade  { background: var(--fade-bg);  color: var(--fade-fg);  border: 1px solid var(--fade-bd); }
.pill.blank { background: var(--blank-bg); color: var(--blank-fg); border: 1px dashed var(--border-subtle); }
.pill .sub { font-size: 10px; font-weight: 500; opacity: .85; display: block; }

td.score { border-bottom: 1px solid var(--border-subtle); font-weight: 800; font-size: 16px;
  padding: 0 4px; }
.score .frac { display: block; font-size: 11px; font-weight: 500; color: var(--text-secondary); }
.s-strong { color: var(--accent-green); }
.s-mod { color: var(--accent-gold); }
.s-weak { color: var(--accent-red); }

.sectitle { color: var(--accent-gold); font-weight: 800; font-size: 16px; letter-spacing: .4px;
  text-transform: uppercase; margin: 26px 0 6px; padding-top: 8px;
  border-top: 2px solid var(--border-subtle); }
.sectitle .ct { color: var(--text-secondary); font-weight: 500; font-size: 13px;
  text-transform: none; letter-spacing: 0; }
.sectitle .thin-cue { color: var(--text-muted); font-weight: 500; font-size: 12px;
  text-transform: none; letter-spacing: 0; cursor: help; }

/* legend */
.legend { display: flex; gap: 20px; padding: 14px 22px; color: var(--text-secondary);
  font-size: 12px; flex-wrap: wrap; align-items: center; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px;
  margin-right: 6px; vertical-align: middle; border: 1px solid transparent; }
.legend i.agree { background: var(--agree-bg); border-color: var(--agree-bd); }
.legend i.fade  { background: var(--fade-bg);  border-color: var(--fade-bd); }
.legend i.blank { background: var(--blank-bg); border: 1px dashed var(--border-subtle); }

.err { color: var(--text-secondary); padding: 40px 22px; }

/* --- filter bar (search + quick filters) --- */
.filterbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 8px 22px 4px; }
.search { background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: 8px; padding: 8px 12px;
  font: inherit; font-size: 14px; min-width: 260px; flex: 1 1 260px; max-width: 420px; }
.search:focus { outline: none; border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px var(--accent-gold-soft); }
.fctl { display: inline-flex; align-items: center; gap: 7px; color: var(--text-secondary);
  font-size: 12px; white-space: nowrap; }
.fctl input[type=range] { accent-color: var(--accent-gold); }
.fctl select { background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: 7px; padding: 5px 8px; font: inherit; font-size: 12px; }
.fctl output { color: var(--accent-gold); font-weight: 700; min-width: 34px; }
.fcount { color: var(--text-muted); font-size: 12px; }

/* Market titles wrap to 2 lines (clamped) so they're always readable; the native
   title= tooltip on the link still shows the full name on hover for the rare 3-liner. */

/* --- outright / futures leaderboard row (one event, N entities) --- */
td.outright { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card); }
.ohead { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.ohead a { color: var(--text-primary); }
.ohead .osub { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.oteam { display: grid; grid-template-columns: 130px 1fr 150px; align-items: center;
  gap: 10px; padding: 3px 0; }
.oteam .oname { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.oteam .obar { height: 9px; border-radius: 5px; background: var(--bg-elevated); overflow: hidden; }
.oteam .obar > i { display: block; height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, var(--accent-green), var(--accent-gold)); }
.oteam .onum { font-size: 12px; color: var(--text-secondary); text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.omore { color: var(--text-muted); font-size: 12px; margin-top: 6px; }

/* --- whale positions modal (click a trader column) --- */
th.wclick { cursor: pointer; }
th.wclick:hover .nm { color: var(--accent-gold); text-decoration: underline; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; }
.modal-bg[hidden] { display: none; }   /* [hidden] must beat display:flex */
.modal { background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: 14px;
  width: 100%; max-width: 560px; max-height: 86vh; overflow: auto; padding: 18px 20px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.modal-x { position: absolute; top: 12px; right: 12px; background: var(--bg-elevated);
  border: 1px solid var(--border-subtle); color: var(--text-secondary); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; font-size: 14px; }
.modal-x:hover { color: var(--text-primary); }
.wp-head { font-weight: 800; font-size: 17px; margin: 2px 0 10px; }
.wp-prof { font-size: 12px; font-weight: 500; margin-left: 8px; }
.wp-hedge { background: var(--fade-bg); border: 1px solid var(--fade-bd); color: var(--fade-fg);
  border-radius: 9px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 12px; }
.wp-note { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 12px; }
table.wp-tbl { border-collapse: separate; border-spacing: 0; width: 100%; }
table.wp-tbl th { text-align: left; color: var(--text-secondary); font-size: 11px; text-transform: uppercase;
  letter-spacing: .4px; padding: 6px 8px; border-bottom: 1px solid var(--border-subtle); }
table.wp-tbl td { padding: 9px 8px; border-bottom: 1px solid var(--border-subtle); font-size: 13px; vertical-align: top; }
table.wp-tbl td a { color: var(--text-primary); }
.wp-num { text-align: right; font-variant-numeric: tabular-nums; }
.wp-sub { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.wp-foot { color: var(--text-muted); font-size: 11px; margin-top: 12px; }

/* --- "sharp window" countdown (high consensus + starts soon) --- */
.sharp { display: inline-flex; align-items: center; gap: 3px; vertical-align: middle;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  background: var(--accent-gold-soft); color: var(--accent-gold);
  border: 1px solid var(--accent-gold-border); }
.sharp.hot { background: var(--fade-bg); color: var(--fade-fg); border-color: var(--fade-bd);
  animation: sharp-pulse 1.6s ease-in-out infinite; }
@keyframes sharp-pulse { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.alertbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 6px 16px 0; padding: 9px 14px; border-radius: 10px;
  background: var(--accent-gold-soft); border: 1px solid var(--accent-gold-border);
  font-size: 13px; }
.alertbar .alabel { font-weight: 800; color: var(--accent-gold); white-space: nowrap; }
.alertbar .aitems { display: flex; gap: 16px; flex-wrap: wrap; flex: 1 1 auto;
  color: var(--text-secondary); }
.alertbar .ai { white-space: nowrap; }
.alertbar .ai a { color: var(--text-primary); }
.alertbar .ai.hot { color: var(--fade-fg); }
.alertbar .amore { color: var(--text-muted); }
.alertbar .adismiss { margin-left: auto; background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; line-height: 1; padding: 2px 4px; }
.alertbar .adismiss:hover { color: var(--text-primary); }

/* --- mobile / responsive --- */
@media (max-width: 680px) {
  header { padding: 16px 14px 6px; }
  h1 { font-size: 19px; }
  .tabs, .cat-tabs, .filterbar, .legend { padding-left: 14px; padding-right: 14px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .search { min-width: 0; flex-basis: 100%; max-width: none; }
  .wrap { padding: 8px 8px 40px; }
  /* shrink the pinned group + recompute its stacked sticky offsets for phones:
     market 142px -> score at left:142 -> vol at left:200 */
  th.mkt, td.mkt { width: 142px; min-width: 142px; max-width: 142px; padding: 8px 8px; }
  th.score, td.score { left: 142px; width: 58px; min-width: 58px; font-size: 14px; }
  th.vol, td.vol { left: 200px; width: 52px; min-width: 52px; font-size: 11px; }
  thead th { padding: 6px 4px; font-size: 11px; }
  th.whale .rk { display: none; }            /* hide the rank·games subline on phones */
  .pill { font-size: 11px; padding: 6px 3px; margin: 4px 2px; }
  .pill .sub { font-size: 9px; }
  /* keep the grid scannable: pinned cols are #1-3 (mkt/score/vol), so whale cells
     start at #4 — hide whales beyond the 4 most-active (#8+) to reduce side-scroll */
  th.whale:nth-of-type(n+8), td.cell:nth-of-type(n+8) { display: none; }
}

/* --- very small phones: free room on the board grid --- */
@media (max-width: 430px) {
  /* drop Volume from the pinned group; pin only Market + Consensus */
  th.vol, td.vol { display: none; }
  th.mkt, td.mkt { width: 138px; min-width: 138px; max-width: 138px; padding: 7px 7px; }
  th.score, td.score { left: 138px; width: 50px; min-width: 50px; font-size: 13px; }
  td.mkt .t { -webkit-line-clamp: 3; }       /* a touch more title room */
  .pill { font-size: 10px; padding: 5px 2px; margin: 3px 2px; }
  .pill .sub { display: none; }              /* hide the $ subline on tiny screens */
  /* show a couple more whale columns since Vol freed space */
  th.whale:nth-of-type(n+8), td.cell:nth-of-type(n+8) { display: table-cell; }
  th.whale:nth-of-type(n+9), td.cell:nth-of-type(n+9) { display: none; }
}

/* --- responsive card tables: any <table class="responsive"> stacks to cards on phones.
   Desktop is untouched (rules live only in this media query); the data-label attrs on
   each <td> become the row label via ::before. One rule serves every data table. --- */
@media (max-width: 680px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: auto; }
  table.responsive tr { border: 1px solid var(--border-subtle); border-radius: 11px; margin: 0 0 10px;
    padding: 10px 13px; background: var(--bg-surface); }
  table.responsive td { border: none; padding: 4px 0; display: flex; justify-content: space-between;
    align-items: baseline; gap: 14px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--text-muted); font-size: 10px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .4px; text-align: left; white-space: nowrap; }
  table.responsive td[data-label=""]::before, table.responsive td:not([data-label])::before { display: none; }
  /* first cell = the card "title": full-width, bold, no label, divider under it */
  table.responsive td:first-child { display: block; text-align: left; font-weight: 700; font-size: 14px;
    border-bottom: 1px solid var(--border-subtle); padding-bottom: 7px; margin-bottom: 5px; }
  table.responsive td:first-child::before { display: none; }
  /* let the responsive table wrappers go full-width on phones */
  .wrap2 { padding-left: 12px; padding-right: 12px; }
}

/* --- modal: not edge-to-edge on tiny screens --- */
@media (max-width: 430px) {
  .modal-bg { padding: 4vh 8px; }
  .modal { padding: 16px 14px; }
}
