:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel2: #f0f2f5; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
  --accent: #2563eb; --accent-text: #ffffff; --up: #15803d; --down: #b91c1c; --warn: #b45309;
  --up-bg: #dcfce7; --down-bg: #fee2e2; --warn-bg: #fef3c7; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --panel: #111a2e; --panel2: #18233b; --text: #e5e7eb; --muted: #94a3b8; --border: #223050;
    --accent: #3b82f6; --up: #4ade80; --down: #f87171; --warn: #fbbf24;
    --up-bg: #12351f; --down-bg: #3b1616; --warn-bg: #3a2e0e; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --panel: #111a2e; --panel2: #18233b; --text: #e5e7eb; --muted: #94a3b8; --border: #223050;
  --accent: #3b82f6; --up: #4ade80; --down: #f87171; --warn: #fbbf24;
  --up-bg: #12351f; --down-bg: #3b1616; --warn-bg: #3a2e0e; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; } h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--muted); } .warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; text-align: right; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: .5rem max(1rem, env(safe-area-inset-left)); flex-wrap: wrap; }
header.top .brand { font-weight: 700; letter-spacing: .02em; }
nav { display: flex; gap: .15rem; overflow-x: auto; flex: 1; }
nav a { color: var(--muted); padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; }
nav a.active, nav a:hover { color: var(--text); background: var(--panel2); text-decoration: none; }
.status-chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; padding: .25rem .6rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel2); cursor: default; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.open { background: var(--up); } .dot.premarket, .dot.afterhours { background: var(--warn); }

main { max-width: 1180px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)) 4rem; }
.grid { display: grid; gap: 1rem; } .cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.stat .label { color: var(--muted); font-size: .8rem; } .stat .value { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; } .row.between { justify-content: space-between; }
.spacer { flex: 1; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; } th.num, td.num { text-align: right; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel2); }

button, .btn, input, select, textarea { font: inherit; color: var(--text); }
button, .btn { background: var(--panel2); border: 1px solid var(--border); padding: .4rem .8rem; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--down); } button.small { padding: .2rem .5rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { background: var(--panel); border: 1px solid var(--border); padding: .4rem .6rem; border-radius: 8px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.formgrid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--panel2); border: 1px solid var(--border); }
.pill.bullish { background: var(--up-bg); color: var(--up); border-color: transparent; }
.pill.bearish { background: var(--down-bg); color: var(--down); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.notice { padding: .6rem .8rem; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: .9rem; }
.notice.error { background: var(--down-bg); color: var(--down); } .notice.ok { background: var(--up-bg); color: var(--up); }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px; z-index: 20; max-width: 90vw; }
.range button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
canvas.chart { width: 100%; height: 340px; display: block; touch-action: pan-y; }
canvas.chart.short { height: 220px; }
.md h2 { font-size: 1.05rem; margin-top: 1rem; } .md h3 { margin-top: .8rem; } .md p { margin: .4rem 0; } .md ul { margin: .3rem 0; padding-left: 1.2rem; }
.bar { height: .5rem; background: var(--panel2); border-radius: 999px; overflow: hidden; } .bar > span { display: block; height: 100%; background: var(--accent); }
.suggest { position: absolute; top: 100%; left: 0; z-index: 6; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; width: min(420px, 90vw); margin-top: .2rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.suggest button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; }
.suggest button:hover { background: var(--panel2); }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; } .auth .card { width: min(380px, 100%); display: grid; gap: .8rem; }
.empty { color: var(--muted); padding: 1rem 0; }
footer.note { color: var(--muted); font-size: .8rem; margin-top: 2rem; }
@media (max-width: 640px) {
  .hide-sm { display: none; } main { padding-bottom: 5rem; }
  header.top { gap: .4rem .6rem; }
  header.top .spacer-sm { flex: 1; }
  nav { order: 3; flex: 0 0 100%; margin: 0 -.25rem; }
  .status-chip { font-size: .78rem; }
}

/* Advisor */
.progress { height: .6rem; background: var(--panel2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.notice.info { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.pill.buy { background: var(--up-bg); color: var(--up); border-color: transparent; font-weight: 650; }
.pill.sell { background: var(--down-bg); color: var(--down); border-color: transparent; font-weight: 650; }
.pill.hold { background: var(--panel2); } .pill.muted { color: var(--muted); }
.pill.calm, .pill.normal { background: var(--up-bg); color: var(--up); border-color: transparent; }
.pill.elevated { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.stress { background: var(--down-bg); color: var(--down); border-color: transparent; }
tr.detail > td { background: var(--panel2); white-space: normal; padding: .8rem 1rem; }
tr.detail ul { margin: .3rem 0 .6rem; padding-left: 1.1rem; }
.grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.small-table th, .small-table td { padding: .3rem .5rem; font-size: .88rem; }
.hl td { background: var(--panel2); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .15rem .8rem; font-size: .9rem; } .kv > :nth-child(odd) { color: var(--muted); }
