/* The chart panel (src/chart, src/panels/chart.ts): top bar, left drawing toolbar, the canvas stage
   with a readout, a selection bar and menus, and a footer. Colours come from the theme tokens in
   base.css; the --tc-* variables below are what the canvas reads (src/chart/view.ts readTheme), so a
   restyle only touches this block. */

.tc {
  --tc-bg: var(--surface-panel);
  --tc-text: var(--ink-1);
  --tc-dim: var(--ink-3);
  --tc-grid: var(--chart-grid);
  --tc-border: var(--rule-2);
  --tc-up: var(--chart-up);
  --tc-down: var(--chart-down);
  --tc-flat: var(--ink-4);
  --tc-cross: var(--chart-cross);
  --tc-cross-label: var(--surface-3);
  --tc-sel: var(--accent);
  --tc-on-color: var(--ink-on-accent);
  --tc-ema1: var(--series-5);
  --tc-ema2: var(--series-2);
  --tc-vwap: var(--series-3);
  /* Drawing colours offered in the selection bar (saved as hex in the chart file). Manila first:
     drawings are the user's marks. */
  --tc-c1: var(--accent);
  --tc-c2: var(--info);
  --tc-c3: var(--danger);
  --tc-c4: var(--caution);
  --tc-c5: var(--ink-1);
  --tc-c6: var(--series-3);
  --tc-c7: var(--fine);

  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  background: var(--tc-bg);
  color: var(--tc-text);
  font: 13px/1.4 var(--sans);
  outline: none;
}
.tc:focus-visible {
  box-shadow: inset 0 0 0 1px var(--acc-dim);
}
.tc:fullscreen,
.tc.is-max {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
}

.pn-chart > .tc {
  height: 100%;
}

/* ---------- top bar */
.tc-top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tc-seg {
  display: inline-flex;
  flex: none;
  padding: 2px;
  gap: 1px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--bg-2);
}
.tc-segbtn {
  height: 22px;
  min-width: 28px;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
}
.tc-segbtn:hover:not(:disabled) {
  color: var(--text);
}
.tc-segbtn.is-on {
  background: var(--panel-3);
  color: var(--text);
}
.tc-segbtn:disabled {
  opacity: 0.4;
  cursor: default;
}
.tc-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 5px;
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tc-btn:hover:not(:disabled) {
  color: var(--text);
  background: var(--panel-3);
  border-color: var(--line-2);
}
.tc-btn.is-on {
  color: var(--acc);
}
.tc-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.tc-btn:focus-visible,
.tc-segbtn:focus-visible,
.tc-tool:focus-visible {
  outline: 1px solid var(--acc);
  outline-offset: -1px;
}
.tc-ico {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- main: tools + stage */
.tc-main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.tc-tools {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 36px;
  padding: 4px 0;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: none;
}
.tc-tool {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: none;
  color: var(--dim);
  cursor: pointer;
}
.tc-tool:hover:not(:disabled) {
  color: var(--text);
  background: var(--panel-3);
}
.tc-tool.is-on {
  color: var(--acc);
  background: var(--acc-glow);
  border-color: var(--acc-dim);
}
.tc-tool:disabled {
  opacity: 0.35;
  cursor: default;
}
.tc-tools-sep {
  flex: none;
  width: 20px;
  height: 1px;
  margin: 4px 0;
  background: var(--line-2);
}
.tc-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.tc-canvas {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ---------- overlays */
.tc-legend {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: calc(100% - 90px);
  font: 11.5px/1.45 var(--sans);
  color: var(--text-2);
  pointer-events: none;
}
.tc-legend b {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--text);
}
.tc-l-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 9px;
}
.tc-l-row:empty {
  display: none;
}
.tc-l-kv {
  display: inline-flex;
  gap: 3px;
}
.tc-l-dim {
  color: var(--dim);
}
.tc-l-ind {
  color: var(--sw, var(--dim));
}
.tc-legend .is-up {
  color: var(--tc-up);
}
.tc-legend .is-down {
  color: var(--tc-down);
}

.tc-status {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  color: var(--text-2);
  background: color-mix(in srgb, var(--tc-bg) 82%, transparent);
}
.tc-status p {
  margin: 0;
  max-width: 420px;
}
.tc-status-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.tc-status .tc-btn {
  border-color: var(--line-2);
  background: var(--panel-2);
  color: var(--text);
}

.tc-selbar {
  position: absolute;
  top: 6px;
  right: 70px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 5px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
}
.tc-selname {
  padding: 0 4px;
  color: var(--dim);
  font-size: 11px;
  white-space: nowrap;
}
.tc-selsep {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: var(--line-2);
}
.tc-swatch {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--line-3);
  border-radius: 50%;
  background: var(--sw);
  cursor: pointer;
}
.tc-swatch.is-on {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.tc-width {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: none;
  cursor: pointer;
}
.tc-width i {
  display: block;
  width: 14px;
  border-radius: 2px;
  background: var(--dim);
}
.tc-width.is-on,
.tc-width:hover {
  border-color: var(--line-3);
}
.tc-width.is-on i {
  background: var(--text);
}
.tc-selbar .tc-btn {
  height: 22px;
  min-width: 22px;
  padding: 0 3px;
}

.tc-menu {
  position: absolute;
  top: 6px;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  max-width: 320px;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--panel-2);
  box-shadow: var(--shadow);
}
.tc-menu p {
  margin: 0;
  color: var(--text-2);
}
.tc-menu-actions {
  display: flex;
  gap: 6px;
}
.tc-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.tc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sw);
}
.tc-num {
  width: 56px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--bg-2);
}

.tc-editor {
  position: absolute;
  z-index: 7;
  width: 200px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--acc-dim);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

/* ---------- footer */
.tc-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  padding: 3px 10px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
}
.tc-foot b {
  color: var(--dim);
  font-weight: 500;
}
.tc-foot-save {
  overflow: hidden;
  text-overflow: ellipsis;
}
.tc-foot-save.is-err {
  color: var(--amber);
}
