/* Wealth Tracker – dark financial dashboard theme */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;   /* blue – magnitude charts */
  --up: #0ca30c;
  --down: #d03b3b;
  --accent-2: #199e70;   /* aqua */
  --accent-5: #9085e9;   /* violet */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page) radial-gradient(900px 320px at 50% -120px, #181a1c, var(--page) 70%) no-repeat;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
::selection { background: rgba(57, 135, 229, 0.35); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a46; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- header / tabs / filters ---------- */
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; padding: 20px 24px 8px; flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.asof { color: var(--ink-2); font-size: 13px; }
.asof.live::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--up); margin-right: 7px; vertical-align: 1px;
  animation: livepulse 2.4s ease-in-out infinite;
}
@keyframes livepulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.tabs { display: flex; gap: 4px; padding: 10px 24px 0; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--muted); font: inherit; font-weight: 550;
  padding: 8px 14px 10px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--series-1); }

.filterbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 14px 24px;
}
.filterbar input[type="search"], .filterbar select, .odds-form select {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font: inherit; min-width: 150px;
}
.filterbar input[type="search"] { flex: 1 1 220px; max-width: 340px; }
.filterbar select, .odds-form select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23898781' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}
.scope-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.scope-toggle button {
  background: var(--surface); color: var(--muted); border: none; font: inherit;
  padding: 7px 12px; cursor: pointer;
}
.scope-toggle button.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }

main { padding: 0 24px 40px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- rankings table ---------- */
.table-wrap { overflow-x: auto; }
/* fixed layout: column widths come from the colgroup, so late-rendered long
   values (country names etc.) can never reflow and shift the whole table */
table { border-collapse: collapse; width: 100%; min-width: 1300px; table-layout: fixed; }
thead th {
  position: sticky; top: 0; background: var(--page); z-index: 2;
  text-align: left; color: var(--muted); font-weight: 550; font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--baseline);
  cursor: pointer; user-select: none; white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.sorted-asc::after { content: " ▲"; font-size: 9px; color: var(--ink-2); }
thead th.sorted-desc::after { content: " ▼"; font-size: 9px; color: var(--ink-2); }
tbody td {
  padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
  color: var(--ink-2); overflow: hidden; text-overflow: ellipsis;
}
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--surface); }
td.name { color: var(--ink); font-weight: 550; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person > div:last-child { min-width: 0; }
.person > div:last-child > div { overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
  background: var(--surface-2); flex: none;
}
.avatar.fallback { display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; font-weight: 600; }
.src { color: var(--muted); font-size: 11.5px; font-weight: 400; }
.pos { color: var(--up); }
.neg { color: var(--down); }
.spark { display: block; }
.rowcount { color: var(--muted); padding: 12px 2px; font-size: 12.5px; }
.tablenote { padding-top: 0; font-size: 12px; }
#sentinel { height: 1px; }

/* ---------- analysis ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px; margin: 6px 0 18px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; transition: border-color 0.15s;
}
.tile:hover { border-color: rgba(255, 255, 255, 0.20); }
.tile .label {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 550;
}
.tile .value { font-size: 26px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12.5px; margin-top: 2px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}
/* paired cards (gainers | losers) stay side by side so rows read symmetric */
.grid.pairs { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 760px) { .grid.pairs { grid-template-columns: 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; transition: border-color 0.15s;
}
.card:hover { border-color: rgba(255, 255, 255, 0.18); }
.card h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.card .units { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.chartbox { position: relative; height: 260px; }
.chartbox.tall { height: 400px; }

/* composition stacked bars (pure CSS) */
.comp { margin-bottom: 16px; }
.comp .comp-label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.comp .bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--page); }
.comp .seg { height: 100%; }
.comp .legend { display: flex; gap: 16px; margin-top: 7px; flex-wrap: wrap; }
.comp .legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12.5px; }
.comp .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- performance ---------- */
.periodbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 16px; }
.periodbar-label { color: var(--muted); font-size: 12.5px; margin-right: 2px; }
.chip {
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 13px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { color: var(--ink-2); }
.chip.active { background: var(--surface-2); color: var(--ink); font-weight: 600; border-color: var(--baseline); }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.period-note { color: var(--muted); font-size: 12px; }

tbody tr { cursor: pointer; }

/* ---------- person modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px; width: min(680px, 100%); max-height: 90vh; overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px;
}
.modal-close:hover { color: var(--ink); }
.modal-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; padding-right: 34px; }
.modal-head .avatar { width: 52px; height: 52px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-head .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.modal-head .worth-now { margin-left: auto; text-align: right; }
.modal-head .worth-now .big { font-size: 26px; font-weight: 650; }
.modal-head .worth-now .sub2 { color: var(--muted); font-size: 12px; }
.modal-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px; margin-bottom: 14px;
}
.mstat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.mstat .label { color: var(--muted); font-size: 11.5px; }
.mstat .val { font-size: 14px; font-weight: 600; margin-top: 1px; }
.mstat .pct { font-size: 11.5px; }
.modal-chart { height: 240px; }
.modal-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* ---------- "your odds" view ---------- */
.odds-layout {
  display: grid; grid-template-columns: minmax(260px, 340px) minmax(300px, 1fr);
  gap: 14px; align-items: start; margin-top: 6px; max-width: 1060px;
}
@media (max-width: 720px) { .odds-layout { grid-template-columns: 1fr; } }
.odds-field {
  display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px;
  color: var(--muted); font-size: 12.5px;
}
.odds-field select { width: 100%; }
.odds-note { color: var(--muted); font-size: 12px; margin: 14px 0 0; line-height: 1.5; }

.odds-hero {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 18px; flex-wrap: wrap;
}
.odds-big { font-size: 38px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.odds-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; max-width: 300px; }
.odds-compare-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; min-width: 190px;
}
.ocb-mult { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.ocb-label { color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }

.odds-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-top: 16px; padding: 12px 0;
  border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid);
}
.odds-stat .label { color: var(--muted); font-size: 11.5px; }
.odds-stat .value { font-weight: 600; font-size: 15px; margin-top: 1px; font-variant-numeric: tabular-nums; }

.odds-factors { margin-top: 16px; }
.odds-factors-title {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 550; margin-bottom: 10px;
}
.ofactor { margin-bottom: 13px; }
.ofactor-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ofactor-label { font-weight: 550; }
.ofactor-mult { font-variant-numeric: tabular-nums; font-weight: 600; }
.ofactor-bar {
  position: relative; height: 7px; border-radius: 3px; background: var(--surface-2);
  margin: 6px 0 4px;
}
/* the ×1 center tick the diverging bars grow from */
.ofactor-bar::before {
  content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px;
  width: 1px; background: var(--baseline);
}
.ofactor-bar span { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.ofactor-bar span.pos { background: var(--up); }
.ofactor-bar span.neg { background: var(--down); }
.ofactor-detail { color: var(--muted); font-size: 11.5px; }

.odds-empty { color: var(--muted); font-size: 13px; margin-top: 16px; line-height: 1.5; }
.odds-warn { color: var(--muted); font-size: 12px; margin-top: 12px; }
.odds-presets {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grid);
}
.odds-presets .plabel { color: var(--muted); font-size: 12px; margin-right: 2px; }

.error {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #3a1414; color: #f2b8b8; border: 1px solid #5c2020;
  padding: 10px 18px; border-radius: 8px; max-width: 80vw;
}
