/* Strategy Backtester - CI theme, color scheme 29 (hue 201.6 deg: blue accent, red tone).
   Taken from ../CI/styles.css; only the tokens below differ. The blue accent is light, so its
   ink is dark (WCAG AA 5.4:1). Gains/losses and buy/sell use --ok / --danger, always with a sign
   or label too. --series-1..8 are the validated categorical chart colors (dataviz reference
   palette, adjacent pairs pass CVD checks in both modes); charts.js reads all tokens at runtime. */

:root {
  /* surfaces */
  --bg: #eef3f6;
  --panel: #fcfdfd;
  --panel-2: #f2f5f8;
  --border: #d1dbe0;
  --grid: #e1e8ec;
  --shadow: 0 1px 2px rgba(20, 33, 41, .06), 0 4px 16px rgba(20, 33, 41, .07);

  /* text */
  --text: #142129;
  --muted: #576a75;

  /* brand / primary (primary buttons, active states, featured items) */
  --accent: #209adf;
  --accent-ink: #0d1f2a;

  /* secondary (related items, "selected" highlight) */
  --tone: #932534;
  --tone-ink: #ffffff;

  /* keyboard focus ring (distinct from the blue accent) */
  --focus: #8a3fd6;

  /* semantic status colors (badges, gains/losses, buy/sell) */
  --ok: #2e7d4f;
  --info: #3b5bb5;
  --danger: #a33b5c;
  --warn: #8a5a00;
  --neutral: #6b6a77;

  /* categorical chart series (fixed order) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e161b;
    --panel: #172126;
    --panel-2: #1d2c35;
    --border: #33434c;
    --grid: #24343e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --text: #eaf1f5;
    --muted: #a1b1ba;
    --accent: #55b2e7;
    --accent-ink: #0d1f2a;
    --tone: #d45466;
    --tone-ink: #1a0b0e;
    --focus: #c49bff;
    --ok: #5fc98a;
    --info: #8aa5ff;
    --danger: #f08aa9;
    --warn: #e6b450;
    --neutral: #b2b4c0;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e161b;
  --panel: #172126;
  --panel-2: #1d2c35;
  --border: #33434c;
  --grid: #24343e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --text: #eaf1f5;
  --muted: #a1b1ba;
  --accent: #55b2e7;
  --accent-ink: #0d1f2a;
  --tone: #d45466;
  --tone-ink: #1a0b0e;
  --focus: #c49bff;
  --ok: #5fc98a;
  --info: #8aa5ff;
  --danger: #f08aa9;
  --warn: #e6b450;
  --neutral: #b2b4c0;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { letter-spacing: -.01em; }
h1 { margin: 0; font-size: clamp(28px, 5vw, 42px); letter-spacing: -.03em; }
h2 { margin: 0; font-size: 19px; }
p { margin: 0; }
a { color: var(--accent); }

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

/* ---------- Layout ---------- */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

main.container {
  padding-top: 8px;
  padding-bottom: 24px;
  display: grid;
  gap: 16px;
}

.top {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 16px 6px;
  display: flex;
  align-items: center;
  gap: 12px 22px;
  flex-wrap: wrap;
}

.brand-name { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.lang { margin-left: auto; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 0 16px 28px;
}

.hero { text-align: center; padding: 18px 0 8px; }
.hero p { margin: 8px auto 0; max-width: 560px; color: var(--muted); font-size: 17px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  padding: 18px 0 40px;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

/* ---------- Card (clickable) ---------- */
.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 26px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; flex: 1; }
.card .go { margin-top: 10px; font-weight: 700; color: var(--accent); }

/* ---------- Navigation ---------- */
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 5px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid transparent;
}
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.on {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

/* Segmented sub-navigation */
.subnav {
  display: inline-flex;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
}
.subnav a {
  padding: 6px 16px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14.5px;
}
.subnav a.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ---------- Buttons & form controls ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .4; cursor: default; }

.seg {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}
.seg button {
  font: inherit;
  font-size: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

select, input[type="text"], input[type="number"], input[type="date"], input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  max-width: 100%;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.row { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end; }

/* ---------- Badges & status ---------- */
.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid currentColor;
}
.status-ok { color: var(--ok); }
.status-info { color: var(--info); }
.status-danger { color: var(--danger); }
.status-warn { color: var(--warn); }
.status-neutral { color: var(--neutral); }

.tag {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--muted) 16%, transparent);
  color: var(--muted);
}
.tag.primary { background: var(--accent); color: var(--accent-ink); }
.tag.secondary { background: color-mix(in srgb, var(--tone) 22%, transparent); color: var(--tone); }

.msg { margin: 0; color: var(--muted); font-size: 14px; }
.msg.error { color: var(--danger); font-weight: 600; }

/* ---------- Chips (selectable items) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 62px;
  padding: 8px 10px 6px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip b { font-size: 20px; line-height: 1.2; }
.chip small { color: var(--muted); font-size: 12px; font-weight: 600; }
.chip.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.primary small { color: var(--accent-ink); opacity: .85; }
.chip.secondary { outline: 2px solid var(--tone); outline-offset: 1px; }

/* ---------- Item grid (e.g. chord cards) ---------- */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.item {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: border-color .12s;
}
.item:hover { border-color: var(--muted); }
.item.selected { border-color: var(--tone); box-shadow: 0 0 0 2px var(--tone) inset; }
.item-name { font-size: 24px; font-weight: 800; margin-top: 2px; line-height: 1.1; }
.item-sub { font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 8px 10px 0;
  font-size: 13px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0,0,0,.25);
}
.legend i.l-primary { background: var(--accent); }
.legend i.l-secondary { background: var(--tone); }
.legend i.l-ring { background: transparent; border: 3px solid var(--muted); }

/* ---------- Color reference (numbered swatches) ---------- */
.palette {
  max-width: 1280px;
  width: min(1248px, calc(100% - 32px));
  margin: 16px auto 0;
}
.palette-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 5px;
}
.swatch {
  font: 700 11px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
.palette-info {
  display: block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Helpers ---------- */
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .panel { padding: 14px 12px; }
  .top { padding-top: 16px; }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); }
}
