/* ============ THEMES ============
   Variable names match the Ladder module (--text --muted --panel --up --down --warn),
   so the ladder SVG follows the selected theme automatically. */
:root, :root[data-theme="dark"] {
  --bg:#0d1117; --panel:#161b22; --panel2:#1c2330; --line:#2b3647; --text:#e6edf3; --muted:#8b98a5;
  --up:#2fbf71; --down:#ef5350; --warn:#f0b429; --accent:#7aa2ff; --accent-ink:#0d1117; --grid:rgba(139,152,165,.12);
}
:root[data-theme="light"] {
  --bg:#f6f7f9; --panel:#ffffff; --panel2:#f0f2f5; --line:#d5dae1; --text:#1b2230; --muted:#6b7280;
  --up:#0f9d58; --down:#d93025; --warn:#b7791f; --accent:#1d4ed8; --accent-ink:#ffffff; --grid:rgba(27,34,48,.07);
}
:root[data-theme="midnight"] {
  --bg:#0a0f1e; --panel:#111a2e; --panel2:#17223b; --line:#25324f; --text:#e2e8f7; --muted:#8794b4;
  --up:#22c58b; --down:#ff5c6c; --warn:#f6b73c; --accent:#5b8cff; --accent-ink:#ffffff; --grid:rgba(135,148,180,.12);
}
:root[data-theme="graphite"] {
  --bg:#161616; --panel:#202020; --panel2:#2a2a2a; --line:#383838; --text:#ececec; --muted:#9b9b9b;
  --up:#4cbb6c; --down:#f0524f; --warn:#ffb020; --accent:#a3a3ff; --accent-ink:#161616; --grid:rgba(255,255,255,.07);
}
:root[data-theme="solarized"] {
  --bg:#002b36; --panel:#073642; --panel2:#0b3f4c; --line:#1b5260; --text:#eee8d5; --muted:#93a1a1;
  --up:#94b200; --down:#ef4f4b; --warn:#d6a400; --accent:#3b9ae0; --accent-ink:#002b36; --grid:rgba(147,161,161,.13);
}
:root[data-theme="sepia"] {
  --bg:#f3ead6; --panel:#fbf6ea; --panel2:#efe5cd; --line:#dccfae; --text:#3b2f1e; --muted:#7a6a52;
  --up:#2e7d32; --down:#b23b2a; --warn:#a66a00; --accent:#8b5e34; --accent-ink:#ffffff; --grid:rgba(59,47,30,.08);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
:root[data-theme="light"], :root[data-theme="sepia"] { color-scheme: light; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
header.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 18px; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--muted); text-decoration: none; }
nav.tabs a.on { background: var(--panel2); color: var(--text); }
.hdr-right { display: flex; align-items: center; gap: 12px; }
.hdr-right a { text-decoration: none; }
main { max-width: 1280px; margin: 0 auto; padding: 18px; }
main.wide { max-width: 1600px; }
h1 { margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.grid .card { margin-bottom: 0; }
.muted, .mut { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--up); font-weight: 600; }
.neg { color: var(--down); font-weight: 600; }
.warn { color: var(--warn); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; vertical-align: middle; margin-left: 6px; border: 1px solid var(--line); }
.badge.paper { color: var(--accent); border-color: var(--accent); }
.badge.live { color: var(--down); border-color: var(--down); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.on { background: var(--up); } .dot.off { background: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline { display: inline; margin: 0; }
.btn, button, select, input[type=number], input[type=text], textarea {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 7px 12px; border-radius: 7px; font: inherit; }
.btn, button { cursor: pointer; }
.btn:hover, button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; border-color: var(--down); color: var(--down); }
.btn.ghost { background: transparent; }
.btn.small, button.small { padding: 2px 8px; font-size: 12px; }
select.theme { padding: 4px 8px; font-size: 13px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 17px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }
td.wrap { white-space: normal; }
table.kv td { white-space: normal; }
table.kv td:first-child { color: var(--muted); width: 120px; }
pre.log { background: var(--bg); color: var(--text); border: 1px solid var(--line); padding: 10px; border-radius: 8px; font-size: 12px;
  max-height: 340px; overflow: auto; margin: 0; white-space: pre-wrap; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--panel); }
.flash.ok { border-color: var(--up); }
.flash.err { border-color: var(--down); }
.flash.warn { border-color: var(--warn); }
.flash.info { border-color: var(--accent); }
.flash ul { margin: 6px 0 0; padding-left: 18px; }
.login { max-width: 360px; margin: 12vh auto; background: var(--panel); padding: 28px; border-radius: 12px; border: 1px solid var(--line); }
.login label { display: block; margin: 16px 0; color: var(--muted); }
.login input { display: block; width: 100%; margin-top: 6px; padding: 9px; border: 1px solid var(--line); border-radius: 7px;
  font: inherit; background: var(--panel2); color: var(--text); }
.login .btn { width: 100%; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 9px; font-size: 12px; border: 1px solid var(--line); }
.tag.buy { color: var(--up); border-color: var(--up); }
.tag.sell { color: var(--down); border-color: var(--down); }
.tag.hot { color: var(--warn); border-color: var(--warn); }

/* ============ AI RANK PAGE ============ */
.ai-controls label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.progress { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 980px) { .lists { grid-template-columns: 1fr; } }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--panel2); }
tr.pick td:first-child { border-left: 3px solid transparent; }
tr.pick.buy td:first-child { border-left-color: var(--up); }
tr.pick.sell td:first-child { border-left-color: var(--down); }
.counts span { margin-right: 14px; }
.big { font-size: 22px; font-weight: 700; }
textarea { width: 100%; min-height: 160px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

/* stock detail drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: none; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(1500px, 100vw); background: var(--bg); z-index: 50;
  border-left: 1px solid var(--line); overflow-y: auto; transform: translateX(100%); transition: transform .2s; }
.drawer.open { transform: none; }
.drawer-bg.open { display: block; }
.drawer-head { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.drawer-body { padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr) 560px; gap: 14px; }
@media (max-width: 1200px) { .drawer-body { grid-template-columns: 1fr; } }
.chart-box { position: relative; height: 560px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; touch-action: none; }
.chart-box canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.legend label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.sw { display: inline-block; width: 14px; height: 8px; border-radius: 2px; }
.plan { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.plan div { background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.plan span { display: block; font-size: 11px; color: var(--muted); }
.plan b { font-size: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 10px; font-size: 12px; background: transparent; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
svg.ladder { width: 100%; height: auto; }
.bucket-bar { display: inline-block; height: 8px; border-radius: 2px; vertical-align: middle; }
