/* The one palette. app.js reads the chart colours from these variables, so
   a colour changes here and nowhere else. Each colour has one meaning:
   --accent is UI state only (focus, selection, primary action), --up/--down
   are direction, and every indicator has a hue of its own. */
:root {
  --bg: #11141a;
  --panel: #181c24;
  --card: #1d222c;
  --line: #2a303c;
  --grid: #1e232d;
  --text: #d5d9e0;
  --muted: #8a93a3;
  --accent: #4a90e2;
  --accent-strong: #3a7bc8;
  --up: #26a69a;
  --down: #ef5350;
  --sma50: #f5a623;
  --sma200: #ec407a;
  --bb: #7e8aa2;
  --rsi: #b39ddb;
  --macd: #29b6f6;
  --signal: #ffb74d;
  --wave: #b388ff;
  --fib: #80deea;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, "Segoe UI", sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

/* --- quote ------------------------------------------------------------------ */

#quote {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}
#quote[hidden] { display: none; }
#quote-symbol { font-size: 16px; font-weight: 600; color: #fff; }
#quote-price { font-size: 16px; font-weight: 600; color: #fff; }
#quote-change { font-weight: 500; }

/* --- controls --------------------------------------------------------------- */

form { display: flex; gap: 8px; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
}

#symbol { width: 152px; text-transform: uppercase; }

button { cursor: pointer; }
button:hover, button[aria-pressed="true"] { border-color: var(--accent); color: #fff; }
button[aria-pressed="true"] { background: #1f3350; }
button:disabled, select:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 4px 16px;
}
button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button.primary:active { transform: translateY(1px); }

/* Busy: the Load button grows a spinner while a request is in flight. */
button.primary[aria-busy="true"]::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border: 2px solid #fff;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#intervals { display: flex; gap: 4px; }

#toggles-button { display: none; }

#toggles { display: flex; flex-wrap: wrap; gap: 4px 16px; }
#toggles label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.12s;
}
#toggles label:hover { color: #fff; }
#toggles input { margin: 0 4px 0 0; accent-color: var(--accent); cursor: pointer; }
#toggles label.degree { cursor: default; gap: 8px; }
#toggles label.degree:has(select:disabled) { color: var(--muted); }

/* Legend swatches, one per overlay, in the colour the chart draws it. */
.sw { display: inline-block; width: 12px; height: 4px; border-radius: 2px; }
.sw.sma50 { background: var(--sma50); }
.sw.sma200 { background: var(--sma200); }
.sw.bb { background: var(--bb); }
.sw.rsi { background: var(--rsi); }
.sw.macd { background: var(--macd); }
.sw.wave { background: var(--wave); }
.sw.dashed { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed; }
.sw.fib { border-top-color: var(--fib); background: none; }
.sw.tri { width: 0; height: 0; border-radius: 0; border: 4px solid transparent; }
.sw.tri.golden { border-bottom: 8px solid var(--up); border-top-width: 0; }
.sw.tri.death { border-top: 8px solid var(--down); border-bottom-width: 0; }

#status { margin: 0; padding: 4px 12px; min-height: 28px; color: var(--muted); }
#status.error { color: var(--down); }

/* --- chart + notes ---------------------------------------------------------- */

main { flex: 1; display: flex; min-height: 0; transition: opacity 0.15s; }
main[aria-busy="true"] { opacity: 0.55; }

#chart { flex: 1; min-width: 0; position: relative; }

#pane-labels { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
#pane-labels div { position: absolute; left: 8px; color: var(--muted); font-size: 11px; }

#notes {
  width: 288px;
  overflow-y: auto;
  padding: 4px 12px 12px;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

#notes h2 {
  margin: 12px 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

#notes ul { margin: 0; padding: 0; list-style: none; }
#notes li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; font-variant-numeric: tabular-nums; }
#notes p { margin: 4px 0; }
#notes .card {
  padding: 8px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
}
#notes .card strong { color: #fff; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted, .small { color: var(--muted); }
.small { font-size: 11px; margin-top: 16px; }

nav { display: flex; gap: 4px; }
nav a { padding: 4px 10px; border-radius: 4px; color: var(--muted); text-decoration: none; }
nav a:hover { color: #fff; }
nav a[aria-current] { color: #fff; background: #1f3350; }

header > label, #criteria label { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#criteria { display: flex; flex-wrap: wrap; gap: 6px 10px; flex-basis: 100%; }
fieldset { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 2px 10px 5px; border: 1px solid var(--line); border-radius: 4px; }
legend { padding: 0 4px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
#criteria select { padding: 2px 4px; }
#backtest { margin-top: 24px; }
#backtest h2, #backtest h3 { margin: 16px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
#backtest th { position: static; cursor: default; }
#backtest table { width: auto; min-width: 60%; }
#criteria input[type="checkbox"], header > label input { margin: 0; accent-color: var(--accent); }
input[type="number"] { width: 62px; padding: 2px 4px; }

#results { flex: 1; overflow: auto; padding: 0 12px 12px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  position: sticky; top: 0; background: var(--bg); color: var(--muted);
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; user-select: none;
}
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }
.num { text-align: right; }
td a { color: var(--accent); text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }
td.met { color: var(--up); }
td.unmet { color: var(--muted); }
tr.match td:first-child { box-shadow: inset 3px 0 var(--up); }
tbody tr:hover { background: var(--panel); }
#results .small { max-width: 900px; }

@media (max-width: 800px) {
  /* The eight overlay toggles fold behind one button so the chart stays
     near the top of the screen. */
  #toggles-button { display: inline-block; }
  #toggles-button[aria-expanded="false"] + #toggles { display: none; }
  #toggles { flex-basis: 100%; }
  main { flex-direction: column; overflow-y: auto; }
  #chart { flex: none; height: 70vh; }
  #notes { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { transition: none !important; animation-duration: 0s !important; }
}
