:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e2e1db;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0f7b3e;
  --bad: #c43c3b;
  --warn: #a86b00;
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --good: #3fbf72; --bad: #e66767; --warn: #e0a43a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --good: #3fbf72; --bad: #e66767; --warn: #e0a43a;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px;
  -webkit-font-smoothing: antialiased; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

header.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line); }
header.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; }
header.top .sync { font-size: 12px; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 10px; cursor: pointer; }

main { max-width: 1120px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.card h3 { font-size: 15px; margin: 0 0 4px; }
.hero { font-size: 32px; font-weight: 650; margin: 2px 0; }
.sub { color: var(--muted); font-size: 13px; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.pos { color: var(--good); } .neg { color: var(--bad); }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 20px; font-weight: 600; margin-top: 4px; }

.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0 2px; position: relative; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.hot > span { background: var(--bad); }
.meter::after { content: ""; position: absolute; left: 30%; top: -2px; bottom: -2px; width: 1px; background: var(--ink-2); opacity: .5; }

.cat-bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 0; }
.cat-bar .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.cat-bar .track span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.chip.buy { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.chip.sell { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.r, th.r { text-align: right; }
.scroll-x { overflow-x: auto; }

ul.recs { margin: 0; padding-left: 18px; } ul.recs li { margin-bottom: 8px; line-height: 1.4; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select, .form input, .form select { background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px; min-width: 0; }
.toolbar input[type=search] { flex: 1 1 200px; }
.btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* Ask */
.ask-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ask-bar { position: sticky; bottom: calc(80px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.ask-bar input { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 12px 16px; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.suggest button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }

/* Settings forms */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; align-items: end; }
.form label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
details.set { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
details.set summary { cursor: pointer; font-weight: 600; }

/* Bottom nav (phone) / top tabs (desktop) */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
nav.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font-size: 10.5px; padding: 4px 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; }
nav.tabs button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
nav.tabs button.active { color: var(--accent); }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  nav.tabs { position: sticky; top: 53px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line);
    justify-content: flex-start; gap: 4px; padding: 6px 16px; }
  nav.tabs button { flex: 0 0 auto; flex-direction: row; font-size: 14px; padding: 8px 12px; border-radius: 10px; }
  nav.tabs button.active { background: var(--surface-2); color: var(--ink); }
  nav.tabs button svg { width: 18px; height: 18px; }
  .ask-bar { bottom: 16px; }
}

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login input { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.err { color: var(--bad); font-size: 14px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
.chart-box { position: relative; height: 220px; }
@media (max-width: 480px) {
  .kpi .value { font-size: 16px; }
  .hero { font-size: 28px; }
  main { padding: 12px; }
}

.cyc { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.cyc .row { border-bottom-color: color-mix(in srgb, var(--line) 70%, transparent); padding: 6px 0; }
.cyc-h { font-size: 14px; margin-bottom: 2px; }
