:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --accent: #c9a227;        /* gold */
  --accent-ink: #111;
  --bull: #0ca30c;
  --bull-text: #3fcf3f;
  --bear: #d03b3b;
  --bear-text: #e66767;
  --warn: #fab219;
  --serious: #ec835a;
  --neutral: #383835;
  --s1: #3987e5; --s2: #d95926; --s7: #9085e9;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #e9e8e2;
    --border: rgba(11, 11, 11, 0.10); --text: #0b0b0b; --text-2: #52514e; --muted: #6f6d68; --grid: #e1e0d9;
    --accent: #a8841a; --accent-ink: #fff; --bull: #0ca30c; --bull-text: #006300; --bear: #d03b3b; --bear-text: #b42d2d;
    --neutral: #f0efec; --s1: #2a78d6; --s2: #eb6834; --s7: #4a3aa7;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #e9e8e2;
  --border: rgba(11, 11, 11, 0.10); --text: #0b0b0b; --text-2: #52514e; --muted: #6f6d68; --grid: #e1e0d9;
  --accent: #a8841a; --accent-ink: #fff; --bull: #0ca30c; --bull-text: #006300; --bear: #d03b3b; --bear-text: #b42d2d;
  --neutral: #f0efec; --s1: #2a78d6; --s2: #eb6834; --s7: #4a3aa7;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; } h2 { font-size: 15px; } h3 { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.num, td.num, .mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .t2 { color: var(--text-2); }
.bull { color: var(--bull-text); } .bear { color: var(--bear-text); } .warn-t { color: var(--warn); }
.small { font-size: 12px; } .tiny { font-size: 11px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.nav .sep { height: 1px; background: var(--border); margin: 10px 6px; }
.side .foot { margin-top: auto; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.content { padding: 20px; display: flex; flex-direction: column; gap: 16px; max-width: 1600px; width: 100%; }
.menu-btn { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
}

/* ---------- cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card > .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 2px; }

/* ---------- watchlist tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; text-decoration: none; display: flex; flex-direction: column; gap: 8px; transition: border-color .15s; }
.tile:hover { border-color: var(--accent); }
.tile.fav { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.tile .sym { font-weight: 700; font-size: 15px; }
.tile .px { font-size: 18px; font-weight: 600; }

/* ---------- probability bar (diverging, neutral midpoint) */
.pbar { position: relative; height: 8px; border-radius: 4px; background: var(--neutral); overflow: hidden; }
.pbar .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.pbar .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--surface); }
.plabel { display: flex; justify-content: space-between; font-size: 12px; font-variant-numeric: tabular-nums; }
.pbig { font-size: 34px; font-weight: 700; line-height: 1.1; }

/* ---------- badges, buttons, forms */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.buy { background: color-mix(in srgb, var(--bull) 22%, transparent); color: var(--bull-text); }
.badge.sell { background: color-mix(in srgb, var(--bear) 22%, transparent); color: var(--bear-text); }
.badge.neutral, .badge.wait { background: var(--surface-3); color: var(--text-2); }
.badge.high { background: color-mix(in srgb, var(--bear) 25%, transparent); color: var(--bear-text); }
.badge.medium { background: color-mix(in srgb, var(--serious) 25%, transparent); color: var(--serious); }
.badge.gold { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.buy { background: var(--bull); color: #fff; border-color: transparent; font-weight: 600; }
.btn.sell { background: var(--bear); color: #fff; border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bear-text); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 11px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface-3); color: var(--text); font-weight: 600; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
input, select, textarea { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 80px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.num, th.num { text-align: right; }

/* ---------- lists */
.list { display: flex; flex-direction: column; }
.item { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 550; }
.ev { display: grid; grid-template-columns: 14px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ev .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--muted); }
.ev .dot.bullish { background: var(--bull); } .ev .dot.bearish { background: var(--bear); }

.factor { display: grid; grid-template-columns: 90px 1fr 48px; gap: 8px; align-items: center; font-size: 12px; }
.chart { height: 460px; width: 100%; }
.chart.sm { height: 240px; }
.tv { height: 560px; }

/* ---------- misc */
.callout { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.callout.warn { border-color: var(--warn); }
.callout.bad { border-color: var(--bear); }
.kill-on { background: var(--bear); color: #fff; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; min-height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface-3); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.35); font-size: 13px; }
.toast.err { border-left: 3px solid var(--bear); } .toast.ok { border-left: 3px solid var(--bull); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px; }
pre.raw { white-space: pre-wrap; background: var(--surface-2); padding: 8px; border-radius: 6px; font-size: 12px; margin: 6px 0 0; max-height: 160px; overflow: auto; }
.item > .badge, .item > span:first-child { align-self: flex-start; flex-shrink: 0; }
@media (max-width: 700px) {
  #status { display: none; }
  .topbar { gap: 6px; padding: 8px 12px; }
  #page-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pbig { font-size: 26px; }
  .chart { height: 340px; }
}
