:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --ink: #16202a;
  --muted: #5e6b7a;
  --hair: #d9dee4;
  --accent: #0e7c7b;
  --accent-ink: #ffffff;
  --gain: #1f8a5b;
  --loss: #c8442b;
  --warn: #b7791f;
  --line: #2f5f9e;
  --focus: #0e7c7b;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a21; --surface: #1c242d; --ink: #e7ecf2; --muted: #98a5b4; --hair: #2e3944;
    --accent: #3fb9b4; --accent-ink: #0d1a1a; --gain: #4cc38a; --loss: #f08a75; --warn: #e0b35a;
    --line: #8fb4f0; --focus: #3fb9b4;
  }
}
:root[data-theme="dark"] {
  --bg: #141a21; --surface: #1c242d; --ink: #e7ecf2; --muted: #98a5b4; --hair: #2e3944;
  --accent: #3fb9b4; --accent-ink: #0d1a1a; --gain: #4cc38a; --loss: #f08a75; --warn: #e0b35a;
  --line: #8fb4f0; --focus: #3fb9b4;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; color: var(--ink); }
p { margin: 0 0 0.75rem; }
code { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.9em; background: var(--hair); padding: 0 0.3em; border-radius: 3px; }

/* --- marco ------------------------------------------------------------ */
.top {
  display: flex; align-items: center; gap: 1.5rem;
  max-width: 1120px; margin: 0 auto; padding: 1rem 16px 0;
}
.brand { font-weight: 600; font-size: 1.15rem; letter-spacing: -0.02em; color: var(--ink); }
.brand::before {
  content: ""; display: inline-block; width: 0.6em; height: 0.6em; margin-right: 0.45em;
  border-radius: 50%; background: var(--accent); vertical-align: 0.05em;
}
.top nav { display: flex; gap: 1.1rem; flex: 1; }
.top nav a { color: var(--muted); padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.top nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.top nav a:hover { text-decoration: none; color: var(--ink); }
main { max-width: 1120px; margin: 0 auto; padding: 1rem 16px 3rem; }
main > section, .two-col > section { padding: 1.25rem 0; border-top: 1px solid var(--hair); }
main > section:first-child, main > .status { border-top: 0; }
.foot { max-width: 1120px; margin: 0 auto; padding: 0 16px 2rem; color: var(--muted); font-size: 0.85rem; }
.inline { display: inline; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.num { text-align: right; white-space: nowrap; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.page-head .lead { color: var(--muted); max-width: 70ch; }
.empty { color: var(--muted); max-width: 62ch; margin: 0; }
.notice { padding: 0.6rem 0.9rem; border-radius: var(--radius); background: var(--surface); border-left: 3px solid var(--warn); }
.notice.error { border-left-color: var(--loss); }

/* --- botones ---------------------------------------------------------- */
button {
  font: inherit; cursor: pointer; border-radius: var(--radius);
  padding: 0.5rem 0.95rem; border: 1px solid var(--hair); background: var(--surface); color: var(--ink);
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.secondary { background: transparent; }
button.quiet { background: none; border: 0; color: var(--muted); padding: 0.25rem 0.4rem; }
button.quiet:hover { color: var(--ink); text-decoration: underline; }
button:hover:not(.quiet) { filter: brightness(0.96); }

/* --- estado ----------------------------------------------------------- */
.status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1.5rem; padding: 0.75rem 0 !important; }
.status-line { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.75rem; }
.lamp { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--gain); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gain) 20%, transparent); }
.lamp.paused { background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 22%, transparent); }
.lamp.off { background: var(--muted); box-shadow: none; }
@media (prefers-reduced-motion: no-preference) {
  .lamp.on { animation: breathe 3s ease-in-out infinite; }
  @keyframes breathe { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--gain) 10%, transparent); } }
}

/* --- hero ------------------------------------------------------------- */
.hero { padding-top: 1.5rem !important; }
.hero-label { color: var(--muted); margin: 0; }
.hero-number { font-size: clamp(2.4rem, 7vw, 3.6rem); font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; margin: 0 0 0.35rem; }
.hero-number .unit { font-size: 0.4em; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 0.2em; }
.hero-sub { color: var(--muted); max-width: 70ch; }
.chart-wrap { position: relative; height: 340px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 0.75rem 0.75rem 0.5rem; margin: 1rem 0; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); text-align: center; padding: 1rem; }
.chart-empty[hidden] { display: none; }
@media (max-width: 600px) { .chart-wrap { height: 240px; } }
.facts { display: flex; flex-wrap: wrap; gap: 0.5rem 2.5rem; margin: 0; }
.facts div { display: flex; flex-direction: column; }
.facts dt { color: var(--muted); font-size: 0.85rem; }
.facts dd { margin: 0; font-size: 1.15rem; font-weight: 500; }

/* --- columnas y tablas ----------------------------------------------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 3rem; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }
table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.data th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.85rem; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--hair); }
table.data td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--hair); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data th:first-child, table.data td:first-child { padding-left: 0; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }
table.compact td { padding: 0.4rem 0.5rem; }
table.data tr.ref td { color: var(--muted); }
.table-scroll { overflow-x: auto; }
table.data time, table.data .num { white-space: nowrap; }

/* --- pares ------------------------------------------------------------ */
.pairs { list-style: none; margin: 0; padding: 0; }
.pairs li { padding: 0.6rem 0; border-bottom: 1px solid var(--hair); }
.pairs li:last-child { border-bottom: 0; }
.pair-head { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.pair-state { margin: 0.15rem 0 0; }
.tag { display: inline-block; font-size: 0.8rem; font-weight: 500; padding: 0.05rem 0.5rem; border-radius: 999px; margin-left: 0.25rem; vertical-align: 0.1em; }
.tag.buy { background: color-mix(in srgb, var(--gain) 15%, transparent); color: var(--gain); }
.tag.sell { background: color-mix(in srgb, var(--loss) 15%, transparent); color: var(--loss); }

/* --- avisos ----------------------------------------------------------- */
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0.75rem; padding: 0.45rem 0; border-bottom: 1px solid var(--hair); position: relative; padding-left: 1rem; }
.events li::before { content: ""; position: absolute; left: 0; top: 1.05rem; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--muted); }
.events li.ev-success::before { background: var(--gain); }
.events li.ev-loss::before, .events li.ev-error::before { background: var(--loss); }
.events li.ev-warn::before { background: var(--warn); }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 0.9rem; }
@media (max-width: 600px) { .events li { grid-template-columns: 1fr; gap: 0; } }

/* --- backtests -------------------------------------------------------- */
.plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.plots figure { margin: 0; }
.plots img { width: 100%; height: auto; border: 1px solid var(--hair); border-radius: var(--radius); background: #fff; }
.plots figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

/* --- login ------------------------------------------------------------ */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { font-size: 1.5rem; margin: 0 0 0.25rem; }
.login .lead { color: var(--muted); margin-bottom: 1.5rem; }
.login-form { display: grid; gap: 1rem; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 1.5rem; }
.login-form label { display: grid; gap: 0.3rem; font-weight: 500; }
.login-form input { font: inherit; padding: 0.6rem 0.7rem; border: 1px solid var(--hair); border-radius: var(--radius); background: var(--bg); color: var(--ink); }
.login-form button { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); padding: 0.7rem; }
.form-error { color: var(--loss); margin: 0; }
