:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #4d525a;
  --muted: #7b8088;
  --border: #b8bcc2;
  --grid: #e1e3e6;
  --blue: #16a34a;
  --red: #ef2b2d;
  --amber: #f2a900;
  --surface: #fff;
  --page: #f7f8fa;
  --topbar: #fff;
  --control: #fff;
  --tooltip: rgba(255,255,255,.96);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #cbd5e1;
  --muted: #8c99aa;
  --border: #27313e;
  --grid: #263241;
  --surface: #0b1118;
  --page: #070c12;
  --topbar: #0c131c;
  --control: #111b27;
  --tooltip: rgba(13,20,29,.97);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--page); color: var(--ink); }
body { overflow: hidden; }

.topbar {
  height: 46px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--topbar);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; width: max-content; color: #1d2430; font-weight: 700; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 7px; background: #0bc995; color: #fff; font-size: 13px; }
.page-title { display: flex; align-items: center; gap: 12px; font-weight: 700; color: #333942; }
.page-name { white-space: nowrap; }
.timeframe-switcher { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid #dfe2e7; border-radius: 6px; background: #f3f4f6; }
.timeframe-switcher button { min-width: 34px; height: 25px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; color: #8a9098; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; }
.timeframe-switcher button:hover { color: #5545ad; background: #ece9ff; }
.timeframe-switcher button[aria-pressed="true"] { color: #fff; background: #9c84df; box-shadow: 0 1px 3px rgba(67,48,122,.22); }
.timeframe-switcher button:disabled { cursor: wait; opacity: .58; }
.reference-control { display: inline-flex; align-items: center; gap: 5px; color: #7b8088; font-size: 10px; font-weight: 500; white-space: nowrap; }
.reference-control[hidden] { display: none !important; }
.reference-control input { width: 112px; height: 27px; padding: 0 5px; border: 1px solid #d6dae0; border-radius: 5px; background: #fff; color: #4d525a; font: inherit; font-size: 10px; }
.chart-type-control { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 500; white-space: nowrap; }
.chart-type-control select { height: 27px; padding: 0 22px 0 7px; border: 1px solid #d6dae0; border-radius: 5px; background: var(--control); color: var(--ink); font: inherit; font-size: 10px; font-weight: 600; }
.update-state { justify-self: end; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #12be83; box-shadow: 0 0 0 4px #12be8318; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; min-width: 0; }
.theme-toggle, .account-state { height: 28px; display: inline-flex; align-items: center; justify-content: center; padding: 0 9px; border: 1px solid #d6dae0; border-radius: 6px; background: var(--control); color: var(--ink); font: inherit; font-size: 11px; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer; }
.theme-toggle:hover, .account-state:hover { border-color: #8d75d4; color: #7358c4; }
.account-state.authenticated { color: #087f5b; border-color: #45c9a1; }

.dashboard {
  --left-column: 50%;
  position: relative;
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-columns: minmax(360px, var(--left-column)) repeat(2, minmax(220px, 1fr));
  grid-template-rows: 1fr 1fr;
  background: var(--border);
  gap: 1px;
}
.panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); overflow: hidden; }
.panel:nth-child(1) { grid-column: 1; grid-row: 1; }
.panel:nth-child(2) { grid-column: 2; grid-row: 1; }
.panel:nth-child(3) { grid-column: 3; grid-row: 1; }
.panel:nth-child(4) { grid-column: 1; grid-row: 2; }
.panel:nth-child(5) { grid-column: 2; grid-row: 2; }
.panel:nth-child(6) { grid-column: 3; grid-row: 2; }
.panel-header { flex: 0 0 auto; min-height: 48px; padding: 13px 15px 2px; }
.panel-header h1, .panel-header h2 { margin: 0; color: #73777d; font-size: clamp(17px, 1.12vw, 21px); font-weight: 500; line-height: 1.15; }
.panel-header small { margin-left: 5px; color: #a0a4aa; font-size: 10px; font-weight: 500; }
.panel-current { display: inline-block; margin-left: 8px; font-size: .82em; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel-current.positive { color: #16a34a; }
.panel-current.negative { color: #ef2b2d; }
.panel-current.neutral { color: var(--muted); }
#drawdownCurrent.sentiment-drawdown-green { color: #00d438; }
#drawdownCurrent.sentiment-drawdown-red { color: #ff2d2d; }
#drawdownCurrent.sentiment-floor { color: #00e5e5; }
.candle-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.candle-title-control { display: flex; align-items: center; gap: 8px; min-width: 0; }
.index-selector { flex: 0 0 auto; max-width: 112px; height: 27px; padding: 0 23px 0 7px; border: 1px solid #d8dce2; border-radius: 5px; background: #fff; color: #565c65; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
.candle-heading h1, .candle-heading h2 { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.candle-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.range-change { flex: 0 0 auto; font-size: .72em; font-weight: 700; letter-spacing: .01em; }
.last-close { flex: 0 0 auto; margin-left: 2px; color: var(--ink); font-size: .72em; font-weight: 700; letter-spacing: .01em; }
.last-close::before, .range-change::before { content: "·"; margin-right: 5px; color: var(--muted); font-weight: 500; }
.range-change.positive { color: #16a34a; }
.range-change.negative { color: #ef2b2d; }
.range-change.neutral { color: #7b8088; }
.ma-legend { display: flex; align-items: center; gap: 12px; color: #777d85; font-size: 10px; }
.ma-legend span { display: inline-flex; align-items: center; gap: 5px; }
.ma-legend span::before { content: ""; width: 14px; height: 2px; background: currentColor; }
.ma-legend .ma24 { color: #e0a000; }
.ma-legend .ma288 { color: #a24bc4; }
.chart-wrap { position: relative; min-height: 0; flex: 1; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.panel-wide canvas { cursor: grab; }
.panel-wide canvas.dragging { cursor: grabbing; }

.touch-crosshair {
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
}
.touch-crosshair::before,
.touch-crosshair::after {
  content: "";
  position: absolute;
  background: color-mix(in srgb, var(--ink) 58%, transparent);
}
.touch-crosshair::before { top: -100vh; left: 0; width: 1px; height: 200vh; }
.touch-crosshair::after { top: 0; left: -100vw; width: 200vw; height: 1px; }
.touch-crosshair.visible { opacity: 1; }
.chart-touch-locked,
.chart-touch-locked body { overscroll-behavior: none; }

.column-resizer {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 0;
  left: var(--left-column);
  width: 12px;
  transform: translateX(-6px);
  cursor: col-resize;
  touch-action: none;
  outline: none;
}
.column-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 2px;
  background: transparent;
  transition: background .12s ease, box-shadow .12s ease;
}
.column-resizer:hover::before,
.column-resizer:focus-visible::before,
.dashboard.resizing-columns .column-resizer::before {
  background: #4285f4;
  box-shadow: 0 0 0 3px rgba(66,133,244,.13);
}
.dashboard.resizing-columns { user-select: none; }

.shared-crosshair {
  position: absolute;
  z-index: 7;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 1px dashed #596675;
  pointer-events: none;
  opacity: 0;
}
.shared-crosshair.visible { opacity: 1; }
.shared-crosshair span {
  position: absolute;
  left: 0;
  bottom: 1px;
  transform: translate(-50%, 0);
  padding: 3px 6px;
  border-radius: 4px;
  background: #414b58;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.legend { display: flex; flex-wrap: wrap; gap: 12px; min-height: 17px; margin-top: 5px; color: #7c8189; font-size: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-swatch { width: 12px; height: 3px; background: var(--legend-color); }
.legend-item.dashed .legend-swatch { height: 0; border-top: 3px dashed var(--legend-color); background: transparent; }

.tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  transform: translate(10px, -105%);
  padding: 7px 9px;
  border: 1px solid #cbd0d6;
  border-radius: 5px;
  background: var(--tooltip);
  box-shadow: 0 3px 12px rgba(30,35,45,.12);
  color: #424750;
  font-size: 11px;
  line-height: 1.45;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .08s ease;
}
.tooltip.visible { opacity: 1; }
.tooltip-time { margin-bottom: 4px; color: var(--muted); font-weight: 700; }
.tooltip-series { display: grid; gap: 3px; }
.tooltip-row { display: grid; grid-template-columns: minmax(72px, 1fr) auto; align-items: baseline; gap: 12px; }
.tooltip-series-name { font-weight: 700; }
.tooltip-row strong { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.error-banner { position: fixed; left: 50%; bottom: 18px; z-index: 10; transform: translateX(-50%); max-width: min(620px, 90vw); padding: 10px 14px; border-radius: 7px; background: #b42318; color: #fff; font-size: 13px; box-shadow: 0 7px 24px #0003; }

:root[data-theme="dark"] .brand { color: #e7edf5; }
:root[data-theme="dark"] .page-title { color: #d4dce6; }
:root[data-theme="dark"] .timeframe-switcher { border-color: #2b3745; background: #111a25; }
:root[data-theme="dark"] .reference-control input,
:root[data-theme="dark"] .index-selector,
:root[data-theme="dark"] .chart-type-control select { border-color: #354253; background: var(--control); color: #d7dee8; }
:root[data-theme="dark"] .panel-header h1,
:root[data-theme="dark"] .panel-header h2 { color: #c3ccd7; }
:root[data-theme="dark"] .panel-header small,
:root[data-theme="dark"] .ma-legend,
:root[data-theme="dark"] .legend { color: #8593a4; }
:root[data-theme="dark"] .tooltip { border-color: #364353; color: #dce4ed; box-shadow: 0 3px 15px #0008; }
:root[data-theme="dark"] .theme-toggle,
:root[data-theme="dark"] .account-state { border-color: #354253; }

@media (max-width: 1050px) {
  body { overflow-x: hidden; overflow-y: auto; }
  .dashboard { height: auto; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(4, 360px); }
  .panel:nth-child(1) { grid-column: 1 / -1; grid-row: 1; }
  .panel:nth-child(2) { grid-column: 1; grid-row: 2; }
  .panel:nth-child(3) { grid-column: 2; grid-row: 2; }
  .panel:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  .panel:nth-child(5) { grid-column: 1; grid-row: 4; }
  .panel:nth-child(6) { grid-column: 2; grid-row: 4; }
  .column-resizer { display: none; }
}
@media (max-width: 680px) {
  .topbar { height: auto; min-height: 46px; grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 7px 10px; }
  .page-title { grid-column: 1; grid-row: 1; justify-self: stretch; min-width: 0; overflow-x: auto; gap: 8px; padding-bottom: 2px; }
  .page-title > * { flex-shrink: 0; }
  .header-actions { max-width: 100%; }
  .update-state { display: none; }
  .page-name { display: none; }
  .dashboard { display: flex; flex-direction: column; }
  .panel { min-height: 330px; }
  .panel-wide { min-height: 390px; }
  .panel-header { padding-inline: 8px; }
  .candle-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 8px;
  }
  .candle-title-control {
    grid-column: 1 / -1;
    width: 100%;
    gap: 6px;
  }
  .index-selector {
    width: clamp(88px, 29vw, 112px);
    min-width: 0;
    padding-left: 6px;
    font-size: 10px;
  }
  .candle-heading h1,
  .candle-heading h2 {
    flex: 1 1 auto;
    overflow: hidden;
    gap: 5px;
    font-size: 15px;
    white-space: nowrap;
  }
  .candle-symbol { display: none; }
  .candle-label { flex: 1 1 auto; }
  .last-close,
  .range-change { font-size: 11px; }
  .last-close::before,
  .range-change::before { margin-right: 3px; }
  .ma-legend {
    grid-column: 2;
    justify-self: end;
    gap: 10px;
    min-height: 14px;
  }
}

.candle-title-control .timeframe-selector{width:67px;min-width:67px;max-width:67px;flex:0 0 67px;padding-left:7px;font-size:11px}

/* Keep the candle controls and full title reachable on narrow screens. */
@media(max-width:680px){.candle-title-control{overflow-x:auto;overflow-y:hidden;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;touch-action:pan-x;scrollbar-width:none;padding-bottom:3px}.candle-title-control::-webkit-scrollbar{display:none}.candle-title-control>*{flex-shrink:0}.candle-heading .candle-title-control h1,.candle-heading .candle-title-control h2{flex:0 0 auto;overflow:visible}.candle-title-control .candle-label{flex:0 0 auto;overflow:visible;text-overflow:clip}}

:root{--cold-strong-bg:#ff2424;--cold-strong-text:#000;--cold-light-bg:#ff52524d;--cold-light-text:#ff9c9c}
#coldM5Current{padding:2px 6px;border-radius:3px;color:var(--ink)}
#coldM5Current.cold-strong{background:var(--cold-strong-bg);color:var(--cold-strong-text);font-weight:750}
#coldM5Current.cold-light{background:var(--cold-light-bg);color:var(--cold-light-text);font-weight:650}
