:root {
  --bg: #0E1117;
  --surface: #151A22;
  --surface-2: #1C222C;
  --border: #262C36;
  --text: #D5DAE2;
  --muted: #8B93A1;
  --accent: #4C8DFF;
  --accent-text: #FFFFFF;
  --up: #1FB98A;
  --down: #F0506E;
  --hover: rgba(255, 255, 255, 0.06);
  --active: rgba(76, 141, 255, 0.16);
  --legend-bg: rgba(14, 17, 23, 0.72);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;
  --tb-h: 44px;
}

:root[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F3F5F8;
  --border: #E3E7ED;
  --text: #1F2733;
  --muted: #6B7482;
  --accent: #2F6FED;
  --up: #12A078;
  --down: #E5405E;
  --hover: rgba(15, 23, 42, 0.05);
  --active: rgba(47, 111, 237, 0.12);
  --legend-bg: rgba(255, 255, 255, 0.78);
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.ic { display: inline-flex; align-items: center; justify-content: center; }
.ic svg { display: block; }

/* ---- toolbar ---- */
.tb {
  flex: none;
  height: var(--tb-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
}
.tb::-webkit-scrollbar { display: none; }
.tb > * { flex: none; }
.tb-sym { display: flex; align-items: baseline; gap: 6px; padding: 0 6px; }
.tb-sym strong { font-size: 14px; font-weight: 650; letter-spacing: 0.01em; }
.tb-sub { color: var(--muted); font-size: 11px; }
.tb-funding { display: inline-flex; align-items: center; gap: 5px; padding: 0 8px; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tb-funding[hidden] { display: none; }
.tf-k { color: var(--muted); }
.tf-up { color: var(--up); }
.tf-down { color: var(--down); }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.tb-spacer { flex: 1 0 8px; }
.tb-group { display: flex; gap: 1px; }
.tb-btn, .seg {
  height: 30px;
  min-width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  transition: background-color 0.12s;
}
.seg { padding: 0 8px; color: var(--muted); font-weight: 550; font-variant-numeric: tabular-nums; }
.seg-ic { padding: 0 6px; }
.tb-btn:hover, .seg:hover { background: var(--hover); color: var(--text); }
.tb-btn.tb-on { background: var(--accent-soft, rgba(80,141,255,0.16)); color: var(--accent, #508DFF); }
.seg-on, .seg-on:hover { background: var(--active); color: var(--accent); }
/* Icon-only toolbar buttons: show the name as a fast, styled tooltip on hover. */
.tb-btn[data-tip], .seg[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  box-shadow: var(--shadow); z-index: 200; pointer-events: none;
}

/* ---- chart ---- */
.work { flex: 1 1 0; min-height: 0; display: flex; position: relative; }
.chart-host { flex: 1 1 0; min-width: 0; min-height: 0; position: relative; }
.rail {
  flex: none;
  width: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail[hidden] { display: none; }
.rail-btn {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.rail-btn:hover { background: var(--hover); color: var(--text); }
.rail-on, .rail-on:hover { background: var(--active); color: var(--accent); }
.rail-end { margin-top: auto; }
.draw-bar {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.draw-bar[hidden] { display: none; }
.replay-bar {
  position: absolute;
  z-index: 4;
  bottom: 42px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.replay-bar[hidden] { display: none; }
.rp-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--text); cursor: pointer; }
.rp-btn:hover { background: var(--hover); }
.rp-btn.rp-main { color: var(--accent, #508DFF); }
.rp-btn.rp-exit { color: var(--muted); }
.rp-speed { min-width: 34px; height: 28px; margin: 0 2px; padding: 0 6px; border: 1px solid var(--border); border-radius: 7px; background: transparent; color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.rp-speed:hover { background: var(--hover); }
.rp-pos { margin: 0 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.al-head { font-weight: 650; font-size: 15px; margin-bottom: 10px; }
.al-form { display: flex; flex-direction: column; gap: 8px; }
.al-cond { display: flex; gap: 8px; }
.al-cond[hidden] { display: none; }
.al-cond > .field, .al-cond > select { flex: 1 1 0; min-width: 0; }
.al-unit { align-self: center; font-size: 12px; color: var(--muted); flex: 0 0 auto; min-width: 48px; }
.al-add { margin: 10px 0 6px; }
.al-sa { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
.scr-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.scr-lab { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.scr-src { width: auto; }
.scr-q { width: 72px; }
.scr-mv { width: 110px; }
.scr-search { flex: 1 1 120px; min-width: 100px; }
.scr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.scr-grow { flex: 1 1 auto; }
.scr-note { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.scr-tabs { display: flex; gap: 6px; }
.scr-tab { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12px; cursor: pointer; }
.scr-tab.on { background: var(--accent, #3b82f6); color: #fff; border-color: transparent; }
.scr-ai-bar { margin-bottom: 6px; }
.scr-ai { flex: 1 1 320px; min-width: 160px; }
.scr-ai-note { font-size: 12px; color: var(--muted); align-self: center; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-ai-note.err { color: var(--down, #ef4444); }
.scr-preset { width: auto; max-width: 240px; }
.scr-lb { width: 70px; }
.scr-cond-bar { margin-top: -4px; }
.scr-cond { width: 100%; flex: 1 1 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.45; resize: vertical; min-height: 120px; white-space: pre; tab-size: 2; }
.scr-cond-err { color: var(--down, #ef4444); font-size: 12px; align-self: center; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.scr-cond-err.on { font-weight: 600; }
.brief-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; line-height: 1.5; }
.brief-list li { color: var(--text); }
.brief-note { margin-top: 12px; font-size: 12px; color: var(--muted); }
.brief-ask { margin-top: 12px; }
.brief-q { flex: 1 1 200px; min-width: 140px; }
.brief-ai { margin-top: 10px; white-space: pre-wrap; line-height: 1.5; color: var(--text); }
.brief-ai.err { color: var(--down, #ef4444); }
.news-head { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 8px; }
.news-senti { font-size: 12px; color: var(--muted); }
.news-senti.bullish { color: var(--up, #16a34a); }
.news-senti.bearish { color: var(--down, #ef4444); }
.news-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.news-item { display: flex; align-items: baseline; gap: 8px; padding: 9px 8px; border-radius: 7px; text-decoration: none; color: var(--text); }
.news-item:hover { background: var(--legend-bg); }
.news-title { flex: 1 1 auto; }
.news-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.news-dot.pos { color: var(--up, #16a34a); }
.news-dot.neg { color: var(--down, #ef4444); }
.guide { display: flex; flex-direction: column; gap: 18px; max-height: 68vh; overflow-y: auto; line-height: 1.55; }
.guide-sec { display: flex; flex-direction: column; gap: 8px; }
.guide-h { margin: 0; font-size: 14px; color: var(--text); }
.guide-p { margin: 0; color: var(--muted); }
.guide-ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.guide-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.guide-tbl th, .guide-tbl td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.guide-tbl th { color: var(--muted); font-weight: 600; }
.guide-tbl td:last-child { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text); }
.cal-list { max-height: 62vh; overflow-y: auto; }
.cal-day { margin: 12px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); position: sticky; top: 0; background: var(--surface, var(--legend-bg)); padding: 3px 0; }
.cal-row { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-bottom: 1px solid var(--border); }
.cal-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 44px; }
.cal-country { font-weight: 600; min-width: 36px; font-size: 12px; }
.cal-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.cal-dot.cal-high { background: var(--down, #ef4444); }
.cal-dot.cal-medium { background: #f59e0b; }
.cal-title { flex: 1 1 auto; }
.cal-fp { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bot-form { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.bot-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; letter-spacing: 0.5px; }
.bot-badge.paper { background: var(--legend-bg); color: var(--muted); }
.bot-badge.live { background: var(--down, #ef4444); color: #fff; }
.bot-killwarn { font-size: 12px; color: var(--down, #ef4444); font-weight: 600; margin-left: 10px; }
.bot-group { display: flex; flex-direction: column; gap: 8px; }
.soc-compose { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.soc-text { resize: vertical; }
.soc-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.soc-item { border: 1px solid var(--border, #2a2e39); border-radius: 8px; padding: 10px 12px; }
.soc-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.soc-sym { font-size: 11px; font-weight: 600; color: var(--accent, #2962ff); background: color-mix(in srgb, var(--accent, #2962ff) 14%, transparent); border-radius: 4px; padding: 1px 6px; }
.soc-tag { font-size: 11px; color: var(--up, #26a69a); border: 1px solid var(--up, #26a69a); border-radius: 4px; padding: 0 5px; }
.soc-time { font-size: 12px; color: var(--muted, #787b86); }
.soc-body { margin: 6px 0 8px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.soc-actions { display: flex; align-items: center; gap: 8px; }
.soc-like { background: none; border: 1px solid var(--border, #2a2e39); border-radius: 6px; color: var(--muted, #787b86); font-size: 12px; padding: 3px 9px; cursor: pointer; }
.soc-like.on { color: var(--down, #ef4444); border-color: var(--down, #ef4444); }
.soc-more[hidden] { display: none; }
.scr-list { max-height: 58vh; overflow-y: auto; }
.scr-table .scr-sym { font-weight: 600; color: var(--text); }
.scr-row { cursor: pointer; }
.scr-row:hover td { background: var(--surface-2, rgba(127, 127, 127, 0.12)); }
.scr-n { width: 70px; }
.scr-tf { width: auto; }
.scr-prog { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.al-sechead { display: flex; align-items: center; gap: 8px; margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
.al-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.al-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; background: var(--legend-bg); }
.al-row.al-off { opacity: 0.55; }
.al-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.al-dot.on { background: #1FB98A; }
.al-dot.fired { background: #F5B83D; }
.al-main { font-weight: 600; font-variant-numeric: tabular-nums; }
.al-note { color: var(--muted); font-size: 12px; }
.al-grow { flex: 1; }
.dot { width: 18px; height: 18px; padding: 0; border: 2px solid transparent; border-radius: 50%; }
.dot-on { border-color: var(--text); }
.kp-log {
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.kp-log:hover { color: var(--text); }
.kp-log.kp-on { color: var(--accent); }

/* ---- data source ---- */
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
[data-status="connected"] .live-dot { background: var(--up); box-shadow: 0 0 0 3px rgba(31, 185, 138, 0.18); }
[data-status="connecting"] .live-dot { background: #F5B83D; }
[data-status="error"] .live-dot { background: var(--down); }
.ds { padding: 10px 12px 4px; }
.ds-list { display: flex; flex-direction: column; gap: 6px; }
.ds-item { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: transparent; text-align: left; }
.ds-item:hover { background: var(--hover); }
.ds-on { border-color: var(--accent); background: var(--active); }
.ds-radio { flex: none; width: 14px; height: 14px; margin-top: 2px; border: 2px solid var(--muted); border-radius: 50%; }
.ds-on .ds-radio { border-color: var(--accent); background: radial-gradient(var(--accent) 45%, transparent 50%); }
.ds-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ds-text span { color: var(--muted); font-size: 12px; white-space: normal; }
.ds-form { padding: 6px 4px 0; }
.ds-form .field { width: 190px; }
.ds-hint { padding: 4px 0 8px; color: var(--muted); font-size: 12px; }
.ds-note { min-height: 18px; padding: 6px 4px; color: var(--muted); font-size: 12px; -webkit-user-select: text; user-select: text; }
.ds-bad { color: var(--down); }

/* ---- strategy report ---- */
.rep { padding: 14px 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px; }
.stats-ls { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.rep-actions { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.opt-head { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.opt-params { width: 100%; border-collapse: collapse; }
.opt-params th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 2px 6px; }
.opt-params td { padding: 3px 6px; }
.opt-params .opt-pname { white-space: nowrap; }
.opt-n { width: 84px; }
.opt-bar { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.opt-obj { display: flex; align-items: center; gap: 6px; }
.opt-obj select { width: auto; }
.opt-count { color: var(--muted); font-size: 12px; }
.opt-prog { color: var(--muted); font-size: 12px; min-height: 16px; }
.opt-res .opt-pv { font-variant-numeric: tabular-nums; color: var(--text); }
.opt-row { cursor: pointer; }
.opt-row:hover td { background: var(--surface-2, rgba(127, 127, 127, 0.12)); }
.opt-row.opt-applied td { background: color-mix(in srgb, var(--accent, #3b82f6) 28%, transparent); }
.opt-apply-hint { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.opt-heat { margin-top: 14px; overflow-x: auto; }
.heat-grid { display: grid; gap: 2px; font-size: 10px; }
.heat-corner, .heat-hx, .heat-hy { color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 2px; }
.heat-hy { justify-content: flex-end; padding-right: 6px; }
.heat-cell { min-width: 26px; height: 22px; border-radius: 2px; cursor: pointer; }
.heat-cell:hover { outline: 1px solid var(--text); }
.heat-na { background: var(--surface); opacity: 0.4; cursor: default; }
.stat { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
.stat-k { color: var(--muted); font-size: 11px; }
.stat-v { margin-top: 2px; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-s { min-height: 16px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.pos { color: var(--up); }
.neg { color: var(--down); }
.rep-h { margin: 16px 0 8px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.eq-canvas { display: block; width: 100%; height: 180px; border: 1px solid var(--border); border-radius: 9px; }
.trades-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 9px; }
.trades { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; -webkit-user-select: text; user-select: text; }
.trades th { position: sticky; top: 0; padding: 7px 10px; background: var(--surface-2); color: var(--muted); font-weight: 600; text-align: left; }
.trades td { padding: 6px 10px; border-top: 1px solid var(--border); }
.trades th:nth-last-child(-n+3), .trades td:nth-last-child(-n+3) { text-align: right; }
.rep-note { margin-top: 10px; color: var(--muted); font-size: 11.500px; line-height: 1.5; }
.kp-flowtip {
  position: absolute; z-index: 30; pointer-events: none; white-space: nowrap;
  padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 600;
  font-variant-numeric: tabular-nums; color: #fff;
  background: rgba(20, 24, 33, 0.92); border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.kp-flowtip[hidden] { display: none; }
.tf-menu {
  position: fixed; z-index: 100; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px;
  padding: 5px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; box-shadow: var(--shadow);
}
.tf-menu-item {
  min-width: 48px; padding: 6px 12px; border: 0; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-weight: 550;
  font-variant-numeric: tabular-nums; text-align: center;
}
.tf-menu-item:hover { background: var(--hover); color: var(--text); }
.tf-menu-item.on { background: var(--active); color: var(--accent); }
.kp-stall {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 50; max-width: min(92vw, 640px); text-align: center;
  padding: 8px 14px; border-radius: 8px; font-size: 12.5px; line-height: 1.45;
  color: #fff3cd; background: rgba(120, 53, 15, 0.92); border: 1px solid rgba(255, 193, 7, 0.5);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); pointer-events: none;
}
.kp-stall[hidden] { display: none; }
.kp-chart { position: absolute; inset: 0; overflow: hidden; }
.kp-canvas { position: absolute; left: 0; top: 0; display: block; }
.kp-over { touch-action: none; outline: none; cursor: crosshair; }
.kp-legends { position: absolute; inset: 0; pointer-events: none; }
.kp-legend {
  position: absolute;
  left: 6px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  overflow: hidden;
  font-size: 12px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}
.kp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 22px;
  padding: 0 2px 0 5px;
  border-radius: 5px;
  background: var(--legend-bg);
  pointer-events: auto;
  white-space: nowrap;
}
.kp-row-main { pointer-events: none; background: transparent; padding-left: 5px; }
.kp-legend-toggle { pointer-events: auto; display: inline-flex; align-items: center; gap: 4px; margin: 1px 0 0 5px; padding: 1px 7px; height: 20px; border: 0; border-radius: 6px; background: var(--legend-bg); color: var(--muted); cursor: pointer; font: inherit; }
.kp-legend-toggle:hover { background: var(--surface-2); color: var(--text); }
.kp-legend-toggle.open svg { transform: rotate(180deg); }
.kp-legend-count { font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kp-legend-folded .kp-row:not(.kp-row-main) { display: none; }
.kp-title { font-weight: 650; font-size: 13px; }
.kp-name { color: var(--text); font-weight: 550; cursor: pointer; }
.kp-row:hover { background: var(--surface-2); }
.kp-off .kp-name { color: var(--muted); }
.kp-values { display: flex; gap: 7px; overflow: hidden; }
.kp-row-main .kp-values { gap: 3px; }
.kp-k { color: var(--muted); margin-left: 5px; }
.kp-error { color: var(--down); overflow: hidden; text-overflow: ellipsis; max-width: 46ch; }
.kp-actions { display: flex; gap: 0; opacity: 0; transition: opacity 0.1s; }
.kp-row:hover .kp-actions, .kp-row:focus-within .kp-actions, .kp-err .kp-actions { opacity: 1; }
.kp-actions button {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}
.kp-actions button:hover { background: var(--hover); color: var(--text); }
@media (hover: none) {
  /* Touch: tap an indicator name to reveal its actions, so values keep the full row width. */
  .kp-actions { display: none; opacity: 1; }
  .kp-open .kp-actions, .kp-err .kp-actions { display: flex; }
  .kp-actions button { width: 30px; height: 26px; }
  .kp-open { height: 26px; background: var(--surface-2); }
}
.kp-latest {
  position: absolute;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.kp-latest[hidden] { display: none; }
.kp-latest:hover { color: var(--accent); }

/* ---- controls ---- */
.btn {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 550;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--hover); }
.btn-icon {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.btn-icon:hover { background: var(--hover); color: var(--text); }
.field {
  height: 34px;
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
.field:focus { outline: none; border-color: var(--accent); }
select.field { padding-right: 6px; }

/* Symbol search */
.sym-head { display: flex; gap: 8px; align-items: center; }
.sym-input { flex: 1; height: 40px; font-size: 15px; }
.sym-src { width: 130px; flex: none; height: 40px; }
.sym-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.sym-tab { padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: transparent; color: var(--muted); font-weight: 550; cursor: pointer; }
.sym-tab:hover { background: var(--hover); color: var(--text); }
.sym-tab.on { background: var(--active); color: var(--accent); border-color: transparent; }
.sym-note { color: var(--muted); font-size: 13px; padding: 6px 2px; min-height: 18px; }
.sym-results { display: flex; flex-direction: column; max-height: min(52vh, 460px); overflow-y: auto; margin: 0 -4px; }
.sym-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; color: var(--text); }
.sym-row:hover { background: var(--hover); }
.sym-sym { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 92px; }
.sym-desc { color: var(--muted); font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym-badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 5px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.sym-badge.sym-crypto { color: #4C8DFF; background: rgba(76,141,255,.12); }
.sym-badge.sym-stock { color: #1FB98A; background: rgba(31,185,138,.12); }
.sym-badge.sym-commodity { color: #F5B83D; background: rgba(245,184,61,.12); }
.sym-badge.sym-forex { color: #B37CFF; background: rgba(179,124,255,.12); }
.sym-ex { color: var(--muted); font-size: 12px; min-width: 96px; text-align: right; white-space: nowrap; }
.sym-star { border: 0; background: none; color: var(--border); font-size: 17px; cursor: pointer; padding: 0 2px; line-height: 1; }
.sym-star:hover { color: var(--muted); }
.sym-star.on { color: #F5B83D; }
.tb-symwrap { position: relative; display: flex; align-items: center; gap: 1px; }
.tb-sym { cursor: pointer; border-radius: 6px; }
.tb-sym:hover { background: var(--hover); }
.sym-type { font-size: 11px; font-weight: 600; color: var(--muted); padding: 1px 6px; border-radius: 4px; background: var(--surface-2); }
.tb-symmore { position: relative; width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; }
.tb-symmore:hover, .tb-symmore.on { background: var(--hover); color: var(--text); }
.tb-symmore svg { width: 15px; height: 15px; }
.tb-symmore.has-funding::before { content: ''; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; border-radius: 50%; background: var(--up); }
.tb-syminfo { position: fixed; z-index: 300; min-width: 230px; padding: 11px 13px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 7px; }
.tb-syminfo[hidden] { display: none; }
.si-row { display: flex; justify-content: space-between; gap: 18px; font-size: 13px; font-variant-numeric: tabular-nums; }
.si-desc { color: var(--text); font-weight: 550; justify-content: flex-start; }
.si-k { color: var(--muted); }

/* Watchlist sidebar */
/* DOM / order-book ladder panel */
.dom { flex: none; width: 0; border-left: 1px solid var(--border); background: var(--surface); overflow: hidden; transition: width 0.12s ease; }
.dom.dom-open { width: 184px; }
.dom-content { display: flex; flex-direction: column; height: 100%; min-width: 184px; font-variant-numeric: tabular-nums; }
.dom-head { flex: none; border-bottom: 1px solid var(--border); padding: 6px 8px 0; }
.dom-spread { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.dom-colhead { display: grid; grid-template-columns: 1fr auto 1fr; gap: 2px; padding: 4px 0 5px; font-size: 10px; color: var(--muted); }
.dom-ch-bid { text-align: left; }
.dom-ch-price { text-align: center; padding: 0 6px; }
.dom-ch-ask { text-align: right; }
.dom-body[hidden], .dom-empty[hidden] { display: none !important; }
.dom-body { flex: 1 1 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.dom-row { height: 20px; flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; border-bottom: 1px solid color-mix(in srgb, var(--border) 45%, transparent); }
.dom-cell { position: relative; display: flex; align-items: center; overflow: hidden; }
.dom-bidcell { justify-content: flex-start; }
.dom-askcell { justify-content: flex-end; }
.dom-bar { position: absolute; top: 2px; bottom: 2px; width: 0; border-radius: 2px; }
.dom-bidcell .dom-bar { right: 0; background: color-mix(in srgb, var(--up) 26%, transparent); }
.dom-askcell .dom-bar { left: 0; background: color-mix(in srgb, var(--down) 26%, transparent); }
.dom-q { position: relative; padding: 0 7px; font-size: 11px; color: var(--text); }
.dom-price { display: flex; align-items: center; justify-content: center; padding: 0 8px; min-width: 60px; font-size: 11px; font-weight: 600; color: var(--muted); background: color-mix(in srgb, var(--border) 22%, transparent); }
.dom-row.dom-bid .dom-price { color: var(--up); }
.dom-row.dom-ask .dom-price { color: var(--down); }
.dom-row.dom-best { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dom-row.dom-best .dom-price { color: var(--text); background: color-mix(in srgb, var(--accent) 22%, transparent); }
.dom-row.dom-big .dom-q { font-weight: 800; }
.dom-row.dom-big.dom-bid .dom-q { color: var(--up); }
.dom-row.dom-big.dom-ask .dom-q { color: var(--down); }
.dom-empty { flex: 1; display: grid; place-items: center; padding: 16px; text-align: center; font-size: 12px; color: var(--muted); }

/* Time & Sales (tape) panel */
.tape { flex: none; width: 0; border-left: 1px solid var(--border); background: var(--surface); overflow: hidden; transition: width 0.12s ease; }
.tape.tape-open { width: 176px; }
.tape-content { display: flex; flex-direction: column; height: 100%; min-width: 176px; font-variant-numeric: tabular-nums; }
.tape-colhead { flex: none; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 2px; padding: 7px 8px 6px; border-bottom: 1px solid var(--border); font-size: 10px; color: var(--muted); }
.tape-ch-time { text-align: left; }
.tape-ch-price { text-align: right; }
.tape-ch-size { text-align: right; }
.tape-body[hidden], .tape-empty[hidden] { display: none !important; }
.tape-body { flex: 1 1 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.tape-row { height: 19px; flex: none; display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; gap: 2px; padding: 0 8px; font-size: 11px; border-bottom: 1px solid color-mix(in srgb, var(--border) 35%, transparent); }
.tape-t { text-align: left; color: var(--muted); }
.tape-p { text-align: right; font-weight: 600; }
.tape-s { text-align: right; }
.tape-row.tape-buy .tape-p, .tape-row.tape-buy .tape-s { color: var(--up); }
.tape-row.tape-sell .tape-p, .tape-row.tape-sell .tape-s { color: var(--down); }
.tape-row.tape-flat .tape-p { color: var(--text); }
.tape-row.tape-buy { background: color-mix(in srgb, var(--up) 7%, transparent); }
.tape-row.tape-sell { background: color-mix(in srgb, var(--down) 7%, transparent); }
.tape-row.tape-big { font-weight: 800; }
.tape-row.tape-big .tape-s { position: relative; }
.tape-row.tape-big.tape-buy { background: color-mix(in srgb, var(--up) 20%, transparent); }
.tape-row.tape-big.tape-sell { background: color-mix(in srgb, var(--down) 20%, transparent); }
.tape-empty { flex: 1; display: grid; place-items: center; padding: 16px; text-align: center; font-size: 12px; color: var(--muted); }

/* Trading account (read-only) modal */
.acct { display: flex; flex-direction: column; gap: 10px; min-width: 300px; font-variant-numeric: tabular-nums; }
.acct-warn { display: flex; gap: 8px; align-items: flex-start; padding: 9px 11px; border-radius: 8px; font-size: 12px; line-height: 1.45;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.acct-warn svg { flex: none; width: 16px; height: 16px; margin-top: 1px; }
.acct-hint { font-size: 12px; color: var(--muted); }
.acct-remember { display: flex; gap: 7px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.acct-note { font-size: 12px; color: var(--down); min-height: 16px; }
.acct-head { display: flex; align-items: center; gap: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.acct-venue { display: flex; align-items: center; gap: 7px; font-weight: 650; }
.acct-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 22%, transparent); }
.acct-grow { flex: 1; }
.acct-equity { font-weight: 700; font-size: 15px; }
.acct-sec-h { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-top: 4px; }
.acct-tbl { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.acct-tr { display: grid; align-items: center; gap: 6px; padding: 6px 10px; font-size: 12.5px; border-bottom: 1px solid color-mix(in srgb, var(--border) 45%, transparent); }
.acct-tr:last-child { border-bottom: 0; }
.acct-th { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: color-mix(in srgb, var(--border) 20%, transparent); }
.acct-pos .acct-tr { grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr; }
.acct-ord .acct-tr { grid-template-columns: 1.6fr 1.2fr 1fr 1.2fr; }
.acct-bal .acct-tr { grid-template-columns: 1fr 1fr 1.2fr; }
.acct-pos .acct-tr > span:not(:first-child), .acct-ord .acct-tr > span:not(:first-child), .acct-bal .acct-tr > span:not(:first-child) { text-align: right; }
.acct-tr b { font-weight: 650; }
.acct-badge { display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.acct-up .acct-badge { color: var(--up); background: color-mix(in srgb, var(--up) 16%, transparent); }
.acct-down .acct-badge { color: var(--down); background: color-mix(in srgb, var(--down) 16%, transparent); }
.acct-pnlup { color: var(--up); font-weight: 650; }
.acct-pnldn { color: var(--down); font-weight: 650; }
.acct-dim { color: var(--muted); }
.acct-empty { padding: 10px; text-align: center; font-size: 12px; color: var(--muted); border: 1px dashed var(--border); border-radius: 8px; }
.btn-icon.spin svg { animation: acct-spin .7s linear infinite; }
@keyframes acct-spin { to { transform: rotate(360deg); } }

.wl { position: relative; flex: none; width: 260px; border-left: 1px solid var(--border); background: var(--surface); overflow: hidden; transition: width 0.12s ease; }
.wl:not(.wl-open) { width: 0 !important; border-left: 0; }
.wl-resize { position: absolute; left: 0; top: 0; width: 6px; height: 100%; cursor: ew-resize; z-index: 2; }
.wl-resize:hover { background: var(--hover); }
.wl-content { display: flex; flex-direction: column; height: 100%; min-width: 180px; }
.wl-head { display: flex; align-items: center; gap: 4px; height: 40px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--border); flex: none; }
.wl-title { font-weight: 650; flex: 1; }
.wl-ic { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.wl-ic:hover { background: var(--hover); color: var(--text); }
.wl-collapse svg { transform: rotate(-90deg); }
.wl-empty { color: var(--muted); font-size: 12.5px; line-height: 1.5; padding: 14px 14px; }
.wl-list { overflow-y: auto; padding: 4px 0 10px; }
.wl-group { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .04em; padding: 10px 12px 3px; text-transform: uppercase; }
.wl-row { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 12px; border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--text); }
.wl-row:hover { background: var(--hover); }
.wl-row.on { background: var(--active); }
.wl-left { display: flex; flex-direction: column; gap: 1px; min-width: 54px; }
.wl-sym { font-weight: 600; }
.wl-src { font-size: 10px; font-weight: 500; color: var(--muted); line-height: 1; }
.wl-price { flex: 1; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.wl-pct { min-width: 60px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.wl-x { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; display: none; place-items: center; border-radius: 4px; color: var(--muted); font-size: 15px; }
.wl-row:hover .wl-x { display: grid; }
.wl-row:hover .wl-pct { opacity: 0; }
.wl-x:hover { background: var(--hover); color: var(--text); }
.wl-reopen { position: absolute; right: 10px; top: 10px; z-index: 5; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; box-shadow: var(--shadow); }
.wl-reopen:hover { color: var(--accent); }
.wl-reopen[hidden] { display: none; }
.color { width: 44px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 38px;
  height: 22px;
  margin: 0;
  border-radius: 11px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background-color 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }

/* ---- modal ---- */
.md-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
  animation: fade 0.14s ease-out;
}
.md-leave { opacity: 0; transition: opacity 0.14s; }
.md-panel {
  width: min(440px, 100%);
  max-height: min(680px, 100%);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise 0.16s ease-out;
}
.md-wide { width: min(860px, 100%); height: min(720px, 100%); }
.md-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); }
.md-title { font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.md-footer { flex: none; display: flex; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.md-footer:empty { display: none; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---- indicator library ---- */
.lib-search { position: sticky; top: 0; z-index: 1; padding: 12px 12px 8px; background: var(--surface); }
.lib-list { padding: 0 6px 8px; }
.lib-wrap { display: flex; gap: 0; align-items: stretch; min-height: 440px; max-height: min(66vh, 620px); }
.lib-nav { width: 190px; flex: none; display: flex; flex-direction: column; gap: 2px; padding: 4px 12px 4px 0; border-right: 1px solid var(--border); overflow-y: auto; }
.lib-nav-head { padding: 12px 8px 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.lib-nav-head:first-child { padding-top: 2px; }
.lib-nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 14px; font-weight: 500; text-align: left; cursor: pointer; }
.lib-nav-item:hover { background: var(--hover); }
.lib-nav-item.on { background: var(--active, rgba(80,141,255,0.16)); color: var(--accent, #508DFF); }
.lib-nav-item .ic { flex: none; color: var(--muted); }
.lib-nav-item.on .ic { color: var(--accent, #508DFF); }
.lib-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 16px; overflow: hidden; }
.lib-main .lib-list { flex: 1; overflow-y: auto; margin: 0 -4px; }
.lib-tabs { display: flex; flex-wrap: wrap; gap: 5px; margin: 2px 0 8px; }
.lib-tab { padding: 4px 11px; border: 1px solid var(--border); border-radius: 999px; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 550; cursor: pointer; }
.lib-tab:hover { background: var(--hover); color: var(--text); }
.lib-tab.on { background: var(--active, rgba(80,141,255,0.16)); color: var(--accent, #508DFF); border-color: transparent; }
.lib-head { padding: 10px 10px 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.lib-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
}
.lib-item:hover { background: var(--hover); }
.lib-name { flex: none; min-width: 76px; font-weight: 600; }
.lib-desc { flex: 1 1 auto; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-add { flex: none; margin-left: auto; color: var(--muted); }
.lib-item:hover .lib-add { color: var(--accent); }
.lib-row { display: flex; align-items: center; gap: 2px; padding-right: 4px; }
.lib-grow { flex: 1 1 auto; min-width: 0; }
.lib-empty { padding: 14px 12px; color: var(--muted); }

/* ---- indicator detail / help page ---- */
.doc-cat { display: inline-block; align-self: flex-start; margin: 0 0 2px; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.03em; }
.doc-summary { margin: 4px 0 2px; color: var(--text); font-size: 13.5px; line-height: 1.6; }
.doc-sec-h { margin-top: 12px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.doc-sec { margin-top: 5px; display: flex; flex-direction: column; gap: 4px; }
.doc-line { position: relative; padding-left: 14px; color: var(--text); font-size: 13px; line-height: 1.55; }
.doc-line::before { content: ''; position: absolute; left: 3px; top: 9px; width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.doc-fig { margin: 10px 0 2px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel, var(--hover)); }
.doc-fig svg { display: block; width: 100%; height: auto; }
.doc-media { width: 100%; margin-top: 10px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.doc-cap { margin-top: 4px; color: var(--muted); font-size: 12px; text-align: center; }
.doc-none { padding: 10px 0; color: var(--muted); }

/* ---- editor ---- */
.ed-body { display: flex; flex-direction: column; gap: 10px; padding: 12px; overflow: hidden; }
.ed-body > .field { flex: none; }
.ed-wrap {
  flex: 1 1 auto;
  min-height: 180px;
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  font: 12.5px/20px var(--mono);
}
.ed-wrap:focus-within { border-color: var(--accent); }
.ed-gutter {
  flex: none;
  min-width: 40px;
  padding: 10px 8px 10px 6px;
  overflow: hidden;
  color: var(--muted);
  text-align: right;
  border-right: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.ed-gutter .ed-errline { color: #fff; background: var(--down); border-radius: 3px; margin: 0 -4px; padding: 0 4px; }
.ed-area {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}
.ed-status { flex: none; min-height: 20px; padding: 0 2px; font-size: 12px; -webkit-user-select: text; user-select: text; }
.ed-ok { color: var(--up); }
.ed-bad { color: var(--down); }

/* ---- settings ---- */
.set-form { padding: 8px 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 46px; }
.set-row .field { width: 150px; flex: none; }
.set-label { color: var(--text); }
.set-group { margin-top: 10px; padding: 6px 0 2px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.set-notes { padding: 0 16px 8px; font-size: 12px; }
.set-notes:empty { display: none; }
.set-warn { color: var(--muted); padding: 4px 0; }
.set-err { color: var(--down); padding: 4px 0; }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(44px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(90vw, 520px);
  padding: 9px 14px;
  border-radius: 8px;
  background: #2B3442;
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s, transform 0.16s;
}
.toast-show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: #B3261E; }

/* ---- phones ---- */
@media (max-width: 640px) {
  .tb-label, .tb-sub { display: none; }
  .rail { width: 36px; }
  .draw-bar { top: auto; bottom: 38px; }
  .rail-btn { width: 30px; height: 30px; }
  .tb { gap: 2px; padding: 0 4px; }
  .tb-sep { margin: 0 2px; }
  .md-backdrop { align-items: flex-end; padding: 0; }
  .md-panel, .md-wide {
    width: 100%;
    height: auto;
    max-height: 88%;
    border-radius: 14px 14px 0 0;
    border-width: 1px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .md-wide { height: 88%; }
  .lib-wrap { flex-direction: column; min-height: 0; max-height: none; }
  .lib-nav { width: auto; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 0 0 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .lib-nav-head { display: none; }
  .lib-nav-item { width: auto; white-space: nowrap; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; }
  .lib-main { padding-left: 0; }
  .kp-legend { font-size: 11px; line-height: 18px; }
  .kp-row-main { height: auto; flex-wrap: wrap; column-gap: 6px; row-gap: 0; white-space: normal; }
  .kp-row-main .kp-values { flex-wrap: wrap; white-space: nowrap; }
  .kp-title { font-size: 12px; }
  .field, .ed-area { font-size: 16px; } /* prevents iOS focus zoom */
  .ed-wrap { font-size: 13px; }
  .ed-area { font: 13px/20px var(--mono); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* App account (login) + Pro gating */
.prof { display: flex; flex-direction: column; gap: 12px; min-width: min(340px, 82vw); padding: 16px 18px 18px; }
.prof .set-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px; min-height: 0; }
.prof .set-label { color: var(--muted); font-size: 13px; }
.prof .field { width: 100%; box-sizing: border-box; }
.prof .btn { width: 100%; justify-content: center; }
.prof-social .btn { font-weight: 550; }
.prof-note { min-height: 16px; color: var(--muted); font-size: 12px; }
.prof-social { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.prof-toggle { text-align: center; margin-top: 2px; }
.prof-link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 4px; }
.prof-head { display: flex; align-items: center; gap: 12px; padding: 2px 0 10px; border-bottom: 1px solid var(--border); }
.prof-head .ic { color: var(--muted); }
.prof-id { display: flex; flex-direction: column; gap: 3px; }
.prof-email { font-weight: 600; }
.prof-sub { display: flex; align-items: center; gap: 8px; }
.prof-badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; letter-spacing: .3px; }
.prof-badge.pro { background: var(--accent); color: var(--accent-text); }
.prof-badge.free { background: var(--hover); color: var(--muted); }
.prof-until { color: var(--muted); font-size: 11px; }
.prof-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }

/* Pro-locked toolbar buttons: dim icon + a small corner dot (tooltip still names the feature) */
.tb-btn.tb-locked .ic { opacity: .5; }
.tb-btn.tb-locked::after { content: ""; position: absolute; right: 2px; bottom: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
/* Profile button shows an accent dot while the user has Pro */
.tb-btn.tb-pro::after { content: ""; position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--up); }

/* Account management (change password / sign out others / delete) */
.prof-divider { height: 1px; background: var(--border); margin: 4px 0; }
.prof-mgmt { display: flex; flex-direction: column; gap: 2px; }
.prof-mgmt-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 13.5px; font-weight: 500; text-align: left; cursor: pointer; }
.prof-mgmt-btn:hover { background: var(--hover); }
.prof-mgmt-btn .ic { color: var(--muted); flex: none; }
.prof-mgmt-btn.danger, .prof-mgmt-btn.danger .ic { color: var(--down); }
.prof-expand { display: flex; flex-direction: column; gap: 10px; padding: 8px 10px 12px; }
.prof-expand[hidden] { display: none; }
.prof-warn { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.prof-row2 { display: flex; gap: 8px; }
.prof-row2 .btn { flex: 1; }

/* Floating chart settings (gear) button + settings panel */
.chart-gear { position: absolute; right: 10px; bottom: 46px; z-index: 6; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2, var(--surface)); color: var(--muted); cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.28); }
.chart-gear:hover { color: var(--text); background: var(--hover); }
.chart-gear .ic { width: 18px; height: 18px; }
.cset { padding: 14px 16px 18px; min-width: min(360px, 84vw); display: flex; flex-direction: column; gap: 6px; }
.cset-item { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 2px; }
.cset-head { display: flex; justify-content: space-between; align-items: baseline; }
.cset-val { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.cset-range { width: 100%; accent-color: var(--accent); }
.cset-hint { color: var(--muted); font-size: 12px; line-height: 1.45; }
.cset-num { width: 100%; box-sizing: border-box; }
.cset-avg { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cset-group { display: flex; align-items: baseline; justify-content: space-between; }
.cset-sym { color: var(--accent); font-weight: 700; font-size: 12px; letter-spacing: 0; text-transform: none; }
.cset-note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: -2px 0 4px; }

/* Watchlist: clickable list-name title + list manager modal */
.wl-title-btn { display: flex; align-items: center; gap: 3px; flex: 1; min-width: 0; height: 30px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.wl-title-btn:hover { background: var(--hover); }
.wl-title-btn .wl-title { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-title-btn .ic { flex: none; color: var(--muted); }
.wl-title-btn .ic svg { width: 16px; height: 16px; }
.wlm { padding: 12px 14px 16px; min-width: min(360px, 84vw); display: flex; flex-direction: column; gap: 10px; }
.wlm-list { display: flex; flex-direction: column; gap: 2px; max-height: 44vh; overflow-y: auto; }
.wlm-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.wlm-row:hover { background: var(--hover); }
.wlm-row.on { background: var(--active, rgba(80,141,255,.16)); color: var(--accent); }
.wlm-check { width: 18px; flex: none; display: flex; align-items: center; color: var(--accent); }
.wlm-check svg { width: 16px; height: 16px; }
.wlm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.wlm-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.wlm-divider { height: 1px; background: var(--border); }
.wlm-actions { display: flex; flex-direction: column; gap: 2px; }
.wlm-act { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font-weight: 500; }
.wlm-act:hover { background: var(--hover); }
.wlm-act .ic { flex: none; color: var(--muted); }
.wlm-act.danger, .wlm-act.danger .ic { color: var(--down); }
.wlm-prompt { display: flex; flex-direction: column; gap: 10px; padding: 8px 2px; }

/* Layout menu rows (name + "SYMBOL, TF" sublabel + favorite star) */
.wlm-row2 { align-items: center; }
.wlm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.wlm-main .wlm-name { flex: 0 0 auto; font-weight: 600; }
.wlm-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wlm-star { width: 24px; flex: none; display: flex; align-items: center; justify-content: center; color: var(--muted); border-radius: 5px; }
.wlm-star svg { width: 15px; height: 15px; }
.wlm-star:hover { background: var(--border); color: var(--text); }
.wlm-star.on { color: var(--accent); }
.wlm-star.on svg { fill: currentColor; }

/* Layout: "unsaved changes" affordances */
.tb-save { color: var(--accent); }
.tb-save[hidden] { display: none !important; }
.tb-btn.tb-dirty::after { content: ""; position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* Contract-data panel */
.cd { flex: none; width: 0; border-left: 1px solid var(--border); background: var(--surface); overflow: hidden; transition: width 0.12s ease; }
.cd.cd-open { width: 204px; }
.cd-content { display: flex; flex-direction: column; height: 100%; min-width: 204px; font-variant-numeric: tabular-nums; }
.cd-head { flex: none; padding: 9px 12px; border-bottom: 1px solid var(--border); font-weight: 650; font-size: 13px; }
.cd-rows { display: flex; flex-direction: column; padding: 2px 0; }
.cd-rows[hidden] { display: none; }
.cd-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid color-mix(in srgb, var(--border) 35%, transparent); }
.cd-k { font-size: 12px; color: var(--muted); }
.cd-v { font-size: 13px; font-weight: 650; }
.cd-v.cd-dim { color: var(--muted); font-weight: 500; }
.cd-na { padding: 16px 12px; color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.5; }
.cd-na[hidden] { display: none; }

/* Multi-window grid */
.grid { flex: 1 1 0; min-width: 0; min-height: 0; display: grid; gap: 2px; background: var(--border); }
.grid.grid-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid.grid-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.grid.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid > .chart-host { min-width: 0; min-height: 0; }
.mpane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.mpane[hidden] { display: none; }
.mp-head { flex: none; display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.mp-title { border: 0; background: transparent; color: var(--text); font-weight: 650; font-size: 12px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.mp-title:hover { background: var(--hover); }
.mp-tf { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.mp-tf:hover { background: var(--hover); color: var(--text); }
.mp-chart { flex: 1 1 0; min-height: 0; position: relative; }
.mp-chart[hidden] { display: none; }
.mp-empty { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 12.5px; cursor: pointer; text-align: center; padding: 10px; }
.mp-empty[hidden] { display: none; }
.mpane.mp-active, .chart-host.mp-active { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Timeframe picker (mini-chart) */
.tfpick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 14px 16px; min-width: min(300px, 80vw); }
.tfpick-b { padding: 10px 0; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text); font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.tfpick-b:hover { background: var(--hover); }
.tfpick-b.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* Combined / spread chart modal */
.cmb { padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: min(360px, 84vw); }
.cmb .set-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px; min-height: 0; }
.cmb .field { width: 100%; box-sizing: border-box; }
.cmb .btn { width: 100%; justify-content: center; }
.cmb-ex { display: flex; flex-wrap: wrap; gap: 6px; }
.cmb-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.cmb-chip:hover { background: var(--hover); }
.cmb-chip b { font-size: 12px; }
.cmb-chip span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cmb-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.scr-saved-bar { align-items: center; }
.scr-saved { width: auto; max-width: 200px; }
.scr-name { width: 150px; }

/* ---- Follow (present / join) ---- */
.kp-follow { position: relative; display: inline-flex; }
.kp-follow-btn {
  height: 30px; padding: 0 11px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; font-weight: 600; font-size: 12.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background-color 0.12s;
}
.kp-follow-btn:hover { background: var(--hover); }
.kp-follow-btn.on { background: var(--active); color: var(--accent); }
.kp-follow-pop {
  position: fixed; top: 0; left: 0; width: 264px; z-index: 300;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 9px;
}
.kp-follow-pop[hidden] { display: none; }
.kp-follow-start, .kp-follow-join {
  height: 34px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
}
.kp-follow-stop {
  height: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  color: var(--text); font: inherit; font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.kp-follow-row { display: flex; gap: 6px; align-items: center; }
.kp-follow-input {
  flex: 1; min-width: 0; height: 34px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font: inherit; font-size: 13px; padding: 0 10px; letter-spacing: 1px;
}
.kp-follow-input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.kp-follow-join { padding: 0 14px; }
.kp-follow-sep { color: var(--muted); font-size: 11px; text-align: center; }
.kp-follow-label { font-size: 12px; color: var(--muted); }
.kp-follow-code {
  flex: 1; font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: 1.5px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px; color: var(--text);
}
.kp-follow-copy {
  padding: 0 12px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.kp-follow-link {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 11px; letter-spacing: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px; color: var(--muted);
}
.kp-follow-err { color: var(--down); font-size: 12px; }

/* ---- Follow window (read-only mirror) ---- */
.follow-win {
  position: fixed; left: 24px; top: 24px;
  width: min(960px, 94vw); height: min(680px, 88vh);
  min-width: 380px; min-height: 300px; max-width: 97vw; max-height: 94vh;
  z-index: 400; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; resize: both;
}
.follow-win.max {
  inset: 12px !important; left: 12px !important; top: 12px !important;
  width: auto !important; height: auto !important; resize: none;
}
.follow-win-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); cursor: grab; touch-action: none;
}
.follow-win-head:active { cursor: grabbing; }
.follow-win-title { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.follow-win-spacer { flex: 1; }
.follow-win-btn {
  height: 26px; padding: 0 9px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--muted); font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.follow-win-btn:hover { color: var(--text); }
.follow-win-btn.on { color: var(--accent); border-color: var(--accent); }
.follow-win-x { padding: 0 8px; }
.follow-win-chart { flex: 1; min-height: 0; position: relative; }
