:root {
  --bg: #161616; --panel: #1e1e1e; --panel2: #2a2a2a; --box: #2b2b2b; --border: #2e2e2e; --text: #e3e3e3; --muted: #8a8a8a;
  --hover: #2c2c2c; --accent: #22c55e; --accent-ink: #0b1a10; --blue: #2962ff; --up: #089981; --down: #f23645;
  --shadow: 0 8px 28px rgba(0,0,0,.55); --icon: #c9c9c9;
}
body[data-theme="light"] {
  --bg: #f4f4f5; --panel: #ffffff; --panel2: #eef0f2; --box: #eef0f2; --border: #e2e4e8; --text: #18181b; --muted: #71717a;
  --hover: #eceef1; --icon: #3f3f46; --shadow: 0 8px 28px rgba(0,0,0,.15);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Ubuntu, sans-serif; user-select: none; }
button { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.up { color: var(--up); } .dn { color: var(--down); }

/* ---------- top bar ---------- */
#top { height: 44px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 6px; background: var(--panel); border-bottom: 1px solid var(--border); }
.tb-left, .tb-right { display: flex; align-items: center; gap: 2px; }
.tb-right { justify-content: flex-end; }
.tb-center { display: flex; align-items: center; gap: 8px; }
.ib { width: 34px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 4px; background: transparent; cursor: pointer; color: var(--icon); padding: 0; }
.ib svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ib:hover { background: var(--hover); color: var(--text); }
.ib.on { color: var(--accent); }
.ib.green { color: var(--accent); }
.ib.sm { width: 24px; height: 24px; }
.ib.sm svg { width: 16px; height: 16px; }
.box { height: 30px; display: inline-flex; align-items: center; gap: 10px; padding: 0 8px 0 12px; border: 1px solid transparent; border-radius: 3px; background: var(--box); cursor: pointer; color: var(--text); font-size: 13.5px; white-space: nowrap; min-width: 90px; justify-content: space-between; }
.box:hover { border-color: #444; }
.box .chev { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
#symBox { min-width: 150px; font-weight: 600; }
.badge { font-size: 11.5px; padding: 4px 10px; border-radius: 3px; background: var(--box); color: var(--muted); margin-right: 6px; cursor: pointer; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.badge.live { color: var(--accent); }
.badge.live::before { content: '● '; }
.badge.demo { color: #f59e0b; }

.dd { position: relative; }
.menu { position: absolute; top: 36px; left: 0; z-index: 30; min-width: 200px; background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); padding: 4px 0; display: none; border: 1px solid var(--border); max-height: 70vh; overflow-y: auto; }
.dd.open .menu { display: block; }
.dd.up .menu { top: auto; bottom: 34px; }
.tb-center .menu { left: 50%; transform: translateX(-50%); }
.menu .mi { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.menu .mi:hover { background: var(--hover); }
.menu .mi.active { color: var(--accent); }
.menu .mh { padding: 8px 14px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.tf-menu { min-width: 170px; }

/* ---------- layout ---------- */
#body { display: flex; height: calc(100% - 44px - 34px); }
#tools { width: 40px; flex: none; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding-top: 6px; gap: 2px; overflow-y: auto; scrollbar-width: none; }
#tools .ib { width: 30px; height: 30px; }
#tools .ib svg { width: 19px; height: 19px; stroke-width: 1.5; }
#tools .ib.on { background: var(--accent); color: var(--accent-ink); }
#tools .ib.tog.on { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
#tools .tsep { width: 18px; height: 1px; background: var(--border); margin: 6px 0; flex: none; }
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#chart { flex: 1; position: relative; min-height: 0; }
#brand { position: absolute; left: 8px; bottom: 34px; font-size: 12.5px; color: var(--muted); pointer-events: none; z-index: 2; }
#right { width: 290px; flex: none; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }

/* ---------- bottom bar ---------- */
#bottom { height: 34px; display: flex; align-items: center; gap: 4px; padding: 0 8px 0 0; background: var(--panel); border-top: 1px solid var(--border); }
.corner { width: 40px; height: 34px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--accent); border-right: 1px solid var(--border); }
.corner svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.fb { height: 26px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 0; border-radius: 3px; background: transparent; cursor: pointer; color: var(--text); white-space: nowrap; }
.fb svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.fb:hover { background: var(--hover); }
.fb.sm { font-size: 12px; color: var(--muted); }
.fb.on { color: var(--accent); }
.toggles { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tg { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px; border: 0; background: transparent; cursor: pointer; color: var(--text); white-space: nowrap; border-radius: 3px; font-size: 12.5px; }
.tg:hover { background: var(--hover); }
.tg i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--muted); position: relative; flex: none; }
.tg.on i { border-color: var(--accent); }
.tg.on i::after { content: ''; position: absolute; inset: 2px; border-radius: 50%; background: var(--accent); }
.clock { color: var(--muted); font-size: 12px; margin: 0 10px; font-variant-numeric: tabular-nums; cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; }
.switch input { display: none; }
.switch i { width: 30px; height: 16px; border-radius: 8px; background: #555; position: relative; transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 16px; }

/* ---------- watchlist ---------- */
.wl-head { padding: 10px 12px 6px; font-weight: 600; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.wl-head:first-child { border-top: 0; }
.wl-cols, .wl-row { display: grid; grid-template-columns: 1.1fr 1fr .8fr .8fr; padding: 0 12px; align-items: center; }
.wl-cols { color: var(--muted); font-size: 11px; height: 24px; }
.wl-cols span:not(:first-child), .wl-row span:not(:first-child) { text-align: right; }
.wl-row { height: 32px; cursor: pointer; font-variant-numeric: tabular-nums; }
.wl-row:hover { background: var(--hover); }
.wl-row.active { background: rgba(34,197,94,.1); }
.wl-row .s { font-weight: 600; }
.flash-up { animation: fu .5s; } .flash-dn { animation: fd .5s; }
@keyframes fu { from { background: rgba(8,153,129,.35); } } @keyframes fd { from { background: rgba(242,54,69,.35); } }
#details { padding: 12px; border-top: 1px solid var(--border); }
#details .big { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
#details .name { font-weight: 600; font-size: 15px; }
#details .desc { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
#details .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-top: 10px; font-size: 12px; }
#details .grid span:nth-child(odd) { color: var(--muted); }
#details .grid span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.range-bar { height: 4px; background: var(--panel2); border-radius: 2px; position: relative; margin: 10px 0 4px; }
.range-bar i { position: absolute; top: -3px; width: 2px; height: 10px; background: var(--text); }
#alerts { padding: 0 12px 12px; font-size: 12px; }
.alert-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.alert-row button { background: none; border: 0; color: var(--muted); cursor: pointer; }

/* ---------- chart overlays ---------- */
.chart-root { position: relative; overflow: hidden; touch-action: none; }
.chart-root canvas { position: absolute; left: 0; top: 0; display: block; }
.chart-over { cursor: crosshair; }
.legends { position: absolute; left: 0; top: 0; pointer-events: none; }
.legend { position: absolute; left: 8px; font-size: 13px; white-space: nowrap; }
.lg-main { display: flex; gap: 10px; align-items: center; height: 22px; }
.lg-sym { font-weight: 600; font-size: 13px; color: var(--text); }
.lg-ohlc { color: var(--text); font-variant-numeric: tabular-nums; }
.lg-ohlc b { font-weight: 400; margin: 0 8px 0 1px; }
.lg-ohlc.up b { color: var(--lg-up, #a78bfa); } .lg-ohlc.dn b { color: var(--lg-dn, #a78bfa); }
.lg-ind { display: flex; gap: 8px; align-items: center; height: 21px; color: var(--muted); pointer-events: auto; width: max-content; padding-right: 6px; border-radius: 3px; }
.lg-ind .lg-name { color: var(--text); cursor: default; }
.lg-ind b { font-weight: 400; font-variant-numeric: tabular-nums; }
.lg-ind.off { opacity: .45; }
.lg-btns { display: none; gap: 2px; }
.lg-ind:hover { background: color-mix(in srgb, var(--bg) 85%, transparent); }
.lg-ind:hover .lg-btns { display: inline-flex; }
.lg-btns button { width: 22px; height: 20px; border: 0; background: transparent; border-radius: 3px; cursor: pointer; color: var(--text); font-size: 12px; padding: 0; }
.lg-btns button:hover { background: var(--hover); }

#drawbar { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 15; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; box-shadow: var(--shadow); }
#drawbar .sw { width: 20px; height: 20px; border-radius: 3px; border: 2px solid transparent; cursor: pointer; }
#drawbar .sw.sel { border-color: var(--text); }
#drawbar select { background: var(--panel2); color: var(--text); border: 0; border-radius: 3px; height: 28px; padding: 0 4px; }
#drawbar .btn { height: 28px; padding: 0 8px; border: 0; background: transparent; border-radius: 3px; cursor: pointer; display: inline-flex; align-items: center; }
#drawbar .btn:hover { background: var(--hover); }
#drawbar .btn.on { color: var(--accent); }
#drawbar .btn svg { width: 20px; height: 20px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; display: flex; align-items: center; justify-content: center; }
.dialog { width: 540px; max-width: calc(100vw - 32px); max-height: 84vh; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.dialog.wide { width: 680px; }
.dialog h3 { margin: 0; padding: 14px 20px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.dialog h3 button { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.dialog .search { margin: 12px 20px; height: 34px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 3px; padding: 0 12px; font: inherit; outline: none; }
.dialog .search:focus { border-color: var(--accent); }
.dialog .list { overflow-y: auto; padding-bottom: 8px; }
.dialog .item { padding: 8px 20px; cursor: pointer; display: flex; justify-content: space-between; }
.dialog .item:hover, .dialog .item.hl { background: var(--hover); }
.dialog .item small { color: var(--muted); }
.dialog .form { padding: 16px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; align-items: center; overflow-y: auto; }
.dialog .form input, .dialog .form select { height: 30px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px; padding: 0 8px; font: inherit; width: 100%; }
.dialog .form input[type=color] { padding: 2px; width: 60px; }
.dialog .foot { padding: 12px 20px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; border-top: 1px solid var(--border); }
.pbtn { height: 32px; padding: 0 16px; border-radius: 3px; border: 1px solid var(--border); background: transparent; cursor: pointer; }
.pbtn:hover { background: var(--hover); }
.pbtn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* settings dialog */
.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.sgrid { padding: 14px 20px; display: grid; grid-template-columns: 1fr auto auto; gap: 10px 14px; align-items: center; overflow-y: auto; }
.sgrid .sh { grid-column: 1 / -1; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 6px; }
.sgrid input[type=color] { width: 44px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 3px; background: none; cursor: pointer; }
.sgrid input[type=range] { width: 110px; accent-color: var(--accent); }
.sgrid input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px 0; }
.preset { border: 1px solid var(--border); border-radius: 4px; padding: 6px 10px 6px 6px; display: flex; align-items: center; gap: 8px; cursor: pointer; background: transparent; }
.preset:hover { border-color: var(--accent); }
.preset span.sw { width: 34px; height: 22px; border-radius: 2px; display: flex; align-items: center; justify-content: center; gap: 3px; }
.preset span.sw b { width: 5px; height: 14px; border-radius: 1px; display: block; }

.ctx { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; box-shadow: var(--shadow); padding: 4px 0; min-width: 230px; }
.ctx .mi { padding: 7px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 20px; }
.ctx .mi small { color: var(--muted); }
.ctx .mi:hover { background: var(--hover); }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--border); padding: 10px 18px; border-radius: 4px; box-shadow: var(--shadow); z-index: 70; font-size: 14px; }
.text-edit { position: absolute; z-index: 40; background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: 3px; padding: 4px 8px; font: 14px sans-serif; outline: none; }

/* connect wizard */
.steps { display: flex; gap: 6px; padding: 12px 20px 0; flex-wrap: wrap; font-size: 12px; }
.steps span { padding: 4px 10px; border-radius: 12px; background: var(--panel2); color: var(--muted); }
.steps span.cur { background: var(--accent); color: var(--accent-ink); }
.steps span.done { color: var(--accent); }
.wz { padding: 4px 20px 12px; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.wz p, .wz ol { line-height: 1.5; margin: 10px 0; }
.wz ol { padding-left: 20px; }
.wz a { color: var(--accent); }
.wz .form { padding: 4px 0; grid-template-columns: 110px 1fr; }
.wz .search { margin: 12px 0 8px; }
.wz .list { margin: 0 -20px; max-height: 46vh; }
.copy { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.copy code { background: var(--bg); border: 1px solid var(--border); padding: 4px 8px; border-radius: 3px; user-select: all; }
.copy .btn { height: 26px; padding: 0 10px; border: 1px solid var(--border); background: transparent; border-radius: 3px; cursor: pointer; }
.err { color: var(--down); min-height: 1em; margin: 6px 0 !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chips:empty { display: none; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 14px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips.sel .chip.on { background: rgba(34,197,94,.14); color: var(--accent); }
.pk-list .item { align-items: center; gap: 12px; }
.pk-list .item small, .dialog .item small { margin-left: 6px; }
.pk-list input { vertical-align: middle; margin-right: 6px; accent-color: var(--accent); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--panel2); color: #f59e0b; }
.tag.live { color: var(--accent); }
.acct { display: flex; justify-content: space-between; align-items: center; padding: 14px; margin-top: 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 15px; }
.keys { padding: 12px 20px; display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; overflow-y: auto; }
.keys kbd { background: var(--panel2); border: 1px solid var(--border); border-radius: 3px; padding: 1px 6px; font: 12px monospace; white-space: nowrap; }

@media (max-width: 1000px) {
  #top { grid-template-columns: auto 1fr auto; }
  #rangeDD, #fitBtn, #undoBtn, #redoBtn { display: none; }
  .badge { max-width: 140px; }
}
@media (max-width: 700px) {
  #acctBtn, #shotBtn, #setBtn, #panelBtn { display: none; }
  #symBox { min-width: 100px; } .box { min-width: 70px; }
  .toggles, .switch span, .clock { display: none; }
}
#drawbar svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- login ---------- */
.login-page { overflow: auto; }
.login-top { grid-template-columns: 1fr auto 1fr; }
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; padding-left: 6px; }
.badge .lock { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; display: inline-block; vertical-align: -2px; margin-right: 6px; }
.login-wrap { min-height: calc(100% - 44px - 34px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.login-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.login-card p { margin: 0 0 18px; line-height: 1.45; }
.login-card label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.login-card input { height: 40px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px; padding: 0 12px; font: inherit; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card input.otp { font-size: 24px; letter-spacing: 12px; text-align: center; font-variant-numeric: tabular-nums; height: 52px; }
.login-card .err { margin: 8px 0 6px !important; font-size: 12.5px; }
.pbtn.wide { width: 100%; height: 40px; font-size: 14px; }
.pbtn:disabled { opacity: .6; cursor: default; }
.login-links { display: flex; justify-content: space-between; margin-top: 14px; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 12.5px; }
.linkbtn:disabled { color: var(--muted); cursor: default; }
.login-foot { font-size: 12px; text-align: center; }
#bottom.login-bottom { padding: 0 14px; position: fixed; bottom: 0; left: 0; right: 0; }
.menu .mi.user { color: var(--muted); cursor: default; font-size: 12px; }
.menu .mi.user:hover { background: transparent; }
