/* Harmony Charts: dark, full-viewport, no page scroll or bounce. */
:root {
  --bg: #131722;
  --panel: #171b26;
  --panel-2: #1e222d;
  --line: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --accent: #2962ff;
  --hover: #2a2e39;
  --up: #26a69a;
  --down: #ef5350;
  --warn: #f7a600;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}
button, input, select { font: inherit; color: inherit; }
button {
  height: 26px; min-width: 26px; padding: 0 8px; border: 0; border-radius: 4px;
  background: transparent; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--hover); }
button[aria-pressed="true"] { color: #fff; background: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
input, select {
  height: 24px; padding: 0 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2);
  -webkit-user-select: text; user-select: text;
}
.link { color: var(--accent); }
.spacer { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--line); flex: none; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr) 22px;
}

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 6px; padding: 0 8px; min-width: 0;
  border-bottom: 1px solid var(--line); overflow: hidden;
}
.group { display: flex; gap: 2px; align-items: center; }
.group button { min-width: 30px; padding: 0 6px; }
#type-group button { width: 28px; padding: 0; display: grid; place-items: center; }
#type-group svg .fill { fill: currentColor; }
.sym-btn { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px 0 8px; }
.sym-btn .sym-id { font-weight: 600; font-size: 13px; letter-spacing: 0.01em; }
.sym-btn .sym-label { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#ind-btn { display: flex; align-items: center; gap: 6px; }
#ind-btn .count:not(:empty) { color: var(--muted); }
#side-btn { width: 28px; padding: 0; display: grid; place-items: center; }
.guest-chip {
  font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: 9px; white-space: nowrap; cursor: default;
  color: var(--muted); border: 1px solid var(--line);
}

/* ---- workspace ---- */
#workspace {
  display: grid; min-height: 0;
  grid-template-columns: 44px minmax(0, 1fr) 260px;
}
#app.side-closed #workspace { grid-template-columns: 44px minmax(0, 1fr) 0; }
#app.side-closed #side { display: none; }
#toolbar-left {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0;
  border-right: 1px solid var(--line); min-height: 0; overflow: hidden;
}
#chart-wrap {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  overscroll-behavior: none; touch-action: none;
}
#chart { position: absolute; inset: 0; }

/* legend (top-left): OHLC readout + one row per indicator line */
.legend {
  position: absolute; left: 8px; top: 6px; z-index: 2; pointer-events: none;
  font-variant-numeric: tabular-nums; max-width: calc(100% - 100px);
}
.lg-row { display: flex; align-items: baseline; gap: 6px; min-height: 18px; white-space: nowrap; }
.lg-sym { font-weight: 600; color: var(--text); }
.lg-tf { color: var(--muted); margin-right: 4px; }
.lg-ohlc { display: inline-flex; gap: 4px; align-items: baseline; }
.lg-k { color: var(--muted); }
.lg-ohlc .lg-v { margin-right: 4px; }
.lg-ohlc[data-dir="up"] .lg-v { color: var(--up); }
.lg-ohlc[data-dir="down"] .lg-v { color: var(--down); }
.lg-chg[data-dir="up"] { color: var(--up); }
.lg-chg[data-dir="down"] { color: var(--down); }
/* Only an indicator row's name and x take the pointer: its value and the gaps let clicks, hover (the
   crosshair) and drags through to the chart. The x sits flush against the name (no gap), so the pointer
   glides from the name onto it; at opacity 0 it still takes the click. */
.lg-ind { width: max-content; }
.lg-ind .lg-name { pointer-events: auto; cursor: pointer; }
.lg-ind .lg-x {
  pointer-events: auto; height: 16px; min-width: 16px; padding: 0 3px; margin: 0 -4px 0 -6px; line-height: 16px;
  color: var(--muted); opacity: 0;
}
.lg-ind:hover .lg-x, .lg-ind .lg-x:focus-visible { opacity: 1; }
.lg-ind[data-cont] .lg-name, .lg-ind[data-cont] .lg-x { visibility: hidden; }

/* price-axis auto/manual badge */
.axis-mode {
  position: absolute; z-index: 2; height: 15px; min-width: 0; padding: 0 4px; border-radius: 3px;
  font-size: 10px; line-height: 15px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); background: transparent; text-align: center;
}
.axis-mode.manual { color: #fff; background: var(--accent); }

#loading-bar {
  position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 3; overflow: hidden; pointer-events: none;
}
#loading-bar::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 30%; background: var(--accent);
  animation: slide 1s ease-in-out infinite;
}
@keyframes slide { from { left: -30%; } to { left: 100%; } }
#chart-msg {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 3;
  max-width: 420px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); text-align: center;
}
#chart-msg p { margin: 0 0 10px; }
#chart-msg button { border: 1px solid var(--line); }

/* ---- side panel ---- */
#side {
  display: grid; grid-template-rows: 32px minmax(0, 1fr); min-height: 0;
  border-left: 1px solid var(--line); background: var(--panel);
}
.side-tabs { display: flex; gap: 2px; align-items: center; padding: 0 6px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.side-tab { height: 24px; color: var(--muted); }
.side-tab[aria-selected="true"] { color: var(--text); background: var(--hover); }
.side-panels { min-height: 0; overflow: hidden; }
.side-panel { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 4px;
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}
.panel-head button { height: 20px; padding: 0 4px; text-transform: none; letter-spacing: 0; }

.wl-list { list-style: none; margin: 0; padding: 0 0 8px; }
.wl-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 62px 18px; align-items: center; gap: 6px;
  height: 28px; padding: 0 6px 0 10px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.wl-list li:hover { background: var(--hover); }
.wl-list li.active { background: rgba(41, 98, 255, 0.16); }
.wl-list li.empty { display: block; color: var(--muted); cursor: default; padding-top: 6px; }
.wl-id { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-id sup { color: var(--muted); font-weight: 400; margin-left: 2px; }
.wl-last { text-align: right; }
.wl-chg { text-align: right; color: var(--muted); }
.wl-chg[data-dir="up"] { color: var(--up); }
.wl-chg[data-dir="down"] { color: var(--down); }
.wl-x { height: 18px; min-width: 18px; padding: 0; color: var(--muted); visibility: hidden; }
.wl-list li:hover .wl-x { visibility: visible; }

/* ---- status bar ---- */
#statusbar {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; min-width: 0;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden;
}
#st-flags { display: flex; gap: 4px; }
.tag { padding: 0 5px; border: 1px solid var(--line); border-radius: 3px; line-height: 15px; }
.tag.warn { color: var(--warn); border-color: rgba(247, 166, 0, 0.4); }
#st-msg { overflow: hidden; text-overflow: ellipsis; }
#st-msg[data-kind="error"] { color: var(--down); }

/* ---- overlays: popovers, modal, toast, symbol search ---- */
#overlays { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#overlays > * { pointer-events: auto; }
.popover {
  position: fixed; min-width: 220px; max-height: calc(100vh - 80px); overflow-y: auto;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.ind-panel { width: 340px; padding-bottom: 8px; }
.ip-list, .ip-presets { list-style: none; margin: 0; padding: 0 8px; }
.ip-list li { display: flex; align-items: center; gap: 6px; padding: 3px 2px; border-radius: 4px; }
.ip-list li.focus { background: rgba(41, 98, 255, 0.12); }
.ip-list li.empty { color: var(--muted); padding: 4px 2px; }
.ip-list .swatch { width: 10px; height: 2px; border-radius: 1px; flex: none; }
.ip-kind { width: 70px; }
.ip-len { width: 70px; }
.ip-color { width: 30px; padding: 1px 2px; }
.ip-width { width: 58px; }
.ip-x { color: var(--muted); padding: 0 6px; }
.ip-add { display: flex; gap: 6px; padding: 6px 10px 2px; }
.ip-add button { border: 1px solid var(--line); }
.ip-presets button {
  width: 100%; height: auto; padding: 5px 6px; text-align: left; display: flex; flex-direction: column; gap: 1px;
}
.ip-presets small { color: var(--muted); }

.modal-back { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.45); }
.modal {
  min-width: 320px; max-width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); overflow: auto;
  padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.modal-title { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.modal-body { margin-bottom: 14px; -webkit-user-select: text; user-select: text; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { border: 1px solid var(--line); }
.modal-actions button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.modal-actions button.danger { color: var(--down); }

.toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%); padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.toast[data-kind="error"] { color: var(--down); }

.symsearch {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.symsearch input { width: 100%; height: 40px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; font-size: 15px; text-transform: uppercase; }
.symsearch input::placeholder { text-transform: none; color: var(--muted); }
.symsearch-list { list-style: none; margin: 0; padding: 4px 0; max-height: 320px; overflow-y: auto; }
.symsearch-list li { display: grid; grid-template-columns: minmax(110px, auto) 1fr auto; gap: 10px; align-items: center; padding: 6px 14px; cursor: pointer; }
.symsearch-list li[aria-selected="true"] { background: rgba(41, 98, 255, 0.2); }
.symsearch-list .id { font-weight: 600; }
.symsearch-list .label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.symsearch-list .kind { color: var(--muted); font-size: 11px; }
.symsearch-hint { padding: 6px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@media (max-width: 760px) {
  #workspace, #app.side-closed #workspace { grid-template-columns: 40px minmax(0, 1fr) 0; }
  #side { display: none; }
  .sym-btn .sym-label { display: none; }
}
