/* Colour roles. The chart canvas reads these same variables, so a theme lives in one place.
   The up/down pair in each theme was checked for colour-blind separation and 3:1 contrast
   against its surface. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover: rgba(11, 11, 11, 0.05);
  --selected: rgba(11, 11, 11, 0.09);
  --crosshair-label: #52514e;
  --up: #089981;
  --down: #f23645;
  --rates: #2a78d6;
  /* Zones are drawn as translucent bands of this colour; round-number lines in --round. */
  --zone: #b8429a;
  --round: #898781;
  --shadow: 0 8px 28px rgba(11, 11, 11, 0.14);
  --focus: #2a78d6;
  --live: #0ca30c;
  --error: #d03b3b;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --raised: #242423;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --hover: rgba(255, 255, 255, 0.06);
  --selected: rgba(255, 255, 255, 0.11);
  --crosshair-label: #52514e;
  --up: #26a69a;
  --down: #ef5350;
  --rates: #3987e5;
  --zone: #e48fd4;
  --round: #8f8d86;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  --focus: #3987e5;
  --live: #0ca30c;
  --error: #e66767;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.toolbar__spacer {
  flex: 1 1 auto;
}

.pair-title {
  margin: 0 6px 0 2px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pair-select {
  display: none;
  font-weight: 600;
}

.control {
  height: 30px;
  padding: 0 8px;
  color: var(--ink);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.control--button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--ink-2);
  text-decoration: none;
  cursor: pointer;
}

.control--button:hover {
  color: var(--ink);
  background: var(--hover);
}

.control--icon {
  width: 30px;
  padding: 0;
}

select.control:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.segmented button {
  min-width: 40px;
  height: 24px;
  padding: 0 9px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

.segmented button:hover {
  color: var(--ink);
  background: var(--hover);
}

.segmented button[aria-pressed="true"] {
  color: var(--surface);
  background: var(--ink);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status__dot {
  flex: none;
  width: 8px;
  height: 8px;
  background: var(--muted);
  border-radius: 50%;
}

.status[data-state="live"] .status__dot {
  background: var(--live);
}

.status[data-state="error"] .status__dot {
  background: var(--error);
}

/* ---------- Chart ---------- */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  min-height: 0;
}

.chart-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.chart {
  position: absolute;
  inset: 0;
  transition: opacity 120ms;
}

/* While another pair or timeframe loads, the old candles stay in place, dimmed. */
.chart-wrap.is-busy .chart {
  opacity: 0.45;
}

.legend {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 3;
  max-width: calc(100% - 96px);
  pointer-events: none;
}

.legend__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
}

.legend__tf {
  color: var(--ink);
  font-weight: 650;
}

.legend__time {
  color: var(--muted);
}

.legend__ohlc {
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.legend__key {
  margin-right: 4px;
  color: var(--muted);
}

.legend__value {
  color: var(--ink);
  font-weight: 550;
}

.legend__change {
  color: var(--ink);
}

/* Direction is carried by the arrow glyph and the sign; the colour only reinforces it. */
.legend__arrow {
  margin-right: 4px;
  font-size: 10px;
}

.legend__arrow[data-direction="up"] {
  color: var(--up);
}

.legend__arrow[data-direction="down"] {
  color: var(--down);
}

/* ---------- Zones ---------- */

.zones-row {
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.zones-row__name,
.zones-row__note {
  color: var(--muted);
}

.zones-row__item {
  color: var(--ink-2);
}

.zones-row__value {
  color: var(--ink);
  font-weight: 550;
}

/* ---------- Rates trend ---------- */

.trend {
  position: relative;
  margin-top: 3px;
}

/* The legend lets the pointer through to the chart; the trend readout is the one part that takes it. */
.trend__toggle {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  margin: 0 -6px;
  padding: 2px 6px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
}

.trend__toggle:hover,
.trend__toggle[aria-expanded="true"] {
  background: var(--hover);
}

.trend__name,
.trend__key,
.trend__note {
  color: var(--muted);
}

.trend__key {
  margin-right: 5px;
}

.trend__value {
  font-weight: 550;
}

/* As in the legend, the glyph and the sign carry the direction; the colour reinforces it. */
.trend__arrow {
  margin-right: 4px;
  color: var(--muted);
  font-size: 10px;
}

.trend__arrow[data-direction="up"] {
  color: var(--up);
}

.trend__arrow[data-direction="down"] {
  color: var(--down);
}

.trend__arrow[data-direction="flat"] {
  font-size: 8px;
}

.trend-details {
  position: absolute;
  top: calc(100% + 6px);
  left: -6px;
  z-index: 1;
  width: max-content;
  max-width: min(420px, calc(100vw - 24px));
  max-height: 74vh;
  padding: 12px 14px;
  overflow-y: auto;
  color: var(--ink-2);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.trend-details p {
  margin: 8px 0 0;
}

.trend-details__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.trend-details__title {
  color: var(--ink);
  font-weight: 650;
}

.trend-details__asof,
.trend-details__facts,
.trend-details p.trend-details__note {
  color: var(--muted);
}

.trend-details__rows {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 12px;
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
}

.trend-details__rows dt {
  color: var(--muted);
}

.trend-details__rows dd {
  margin: 0;
}

.trend-details__call {
  color: var(--ink);
  font-weight: 550;
}

.trend-details__signal {
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.trend-details p.trend-details__lead + .trend-details__signal {
  margin-top: 6px;
}

.trend-details p.trend-details__lead {
  margin-top: 12px;
  padding-top: 10px;
  color: var(--ink);
  font-weight: 600;
  border-top: 1px solid var(--border);
}

.trend-details p.trend-details__rule {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Caption of the rate-gap pane; app.js moves it into that pane, whose cell is the positioning box. */
.pane-label {
  position: absolute;
  top: 8px;
  left: 12px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  max-width: calc(100% - 24px);
  color: var(--ink-2);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  pointer-events: none;
}

.pane-label__swatch {
  align-self: center;
  width: 12px;
  height: 2px;
  background: var(--rates);
  border-radius: 1px;
}

.pane-label__value {
  color: var(--ink);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.overlay__title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.overlay__detail {
  max-width: 46ch;
  color: var(--ink-2);
}

.go-latest {
  position: absolute;
  right: 84px;
  bottom: 40px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--ink-2);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}

.go-latest:hover {
  color: var(--ink);
}

/* ---------- Pair list ---------- */

.watchlist {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
}

.watchlist__search {
  flex: none;
  height: 30px;
  margin: 10px 10px 6px;
  padding: 0 8px;
  color: var(--ink);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.watchlist__search::placeholder {
  color: var(--muted);
}

.watchlist__list {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 6px 10px;
  overflow-y: auto;
}

.watchlist__group {
  margin: 10px 6px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.watchlist__item {
  display: block;
  width: 100%;
  height: 28px;
  padding: 0 8px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
}

.watchlist__item:hover {
  color: var(--ink);
  background: var(--hover);
}

.watchlist__item[aria-current="true"] {
  color: var(--ink);
  background: var(--selected);
  font-weight: 650;
}

.watchlist__empty {
  margin: 12px 8px;
  color: var(--muted);
}

/* ---------- Narrow screens: the list becomes a dropdown in the toolbar ---------- */

@media (max-width: 860px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
  }

  .watchlist,
  .pair-title {
    display: none;
  }

  .pair-select {
    display: block;
  }

  .toolbar {
    flex-wrap: wrap;
  }
}

@media (max-width: 560px) {
  .toolbar__spacer {
    display: none;
  }

  .status {
    flex: 1 1 100%;
    order: 10;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chart {
    transition: none;
  }
}
