:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}

.topbar {
  padding: 20px 24px 8px;
  position: relative;
}
.topbar-sesion {
  position: absolute;
  top: 20px;
  right: 24px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-sesion a {
  color: var(--series-1);
  text-decoration: none;
  font-weight: 600;
}
.topbar-sesion a:hover { text-decoration: underline; }
.sesion-badge {
  background: var(--series-3);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 4px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-plane);
}
.login-box {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.login-box h1 { margin: 0; font-size: 20px; }
.login-box label {
  display: block;
  margin: 18px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.login-box input[type="password"] {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page-plane);
  color: var(--text-primary);
}
.login-submit { width: 100%; margin-top: 16px; padding: 9px; }
.login-volver {
  display: block;
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.subtitle {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}
.aviso-fallidas {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--series-4) 15%, var(--surface-1));
  border: 1px solid var(--series-4);
  color: var(--text-primary);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--gridline);
}
.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--series-1);
  border-bottom-color: var(--series-1);
}

main {
  padding: 20px 24px 40px;
}
.tab-panel[hidden] { display: none; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-row label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}
.filter-row input[type="date"] {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
}
#input-fecha {
  font-size: 22px;
  padding: 10px 13px;
}
.filter-row select {
  font-family: inherit;
  font-size: 13.5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  max-width: 260px;
}
.spacer { flex: 1; }

.calc-box {
  max-width: 680px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px 24px;
}
.calc-fila {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.calc-box label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}
.calc-box input[type="date"],
.calc-box input[type="text"],
.calc-box select {
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
}
.calc-box input[type="date"] { font-size: 14px; padding: 6px 8px; }
#calc-monto {
  font-size: 24px;
  font-weight: 700;
  padding: 8px 12px;
  width: 260px;
  font-variant-numeric: tabular-nums;
}
.calc-monedas {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.calc-moneda { display: flex; flex-direction: column; gap: 6px; flex: 1 1 240px; }
.calc-moneda select { font-size: 15px; padding: 9px 10px; width: 100%; }
#calc-swap { font-size: 18px; padding: 7px 12px; }
.calc-resultado {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 16px 0 6px;
  border-top: 1px solid var(--gridline);
  word-break: break-word;
}
.calc-resultado .calc-moneda-cod {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 6px;
}
.calc-detalle {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.fecha-estado {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  min-height: 18px;
}
.fecha-estado .spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--gridline);
  border-top-color: var(--series-1);
  border-radius: 50%;
  animation: girar 0.7s linear infinite;
}
.fecha-estado .tilde {
  color: var(--series-3);
  font-weight: 700;
}
@keyframes girar {
  to { transform: rotate(360deg); }
}

.exportar-rango {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--gridline);
}
.exportar-rango h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.btn-secondary, .btn-preset {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}
.btn-secondary:hover, .btn-preset:hover { background: var(--gridline); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-preset.active {
  background: var(--series-1);
  color: white;
  border-color: var(--series-1);
}
.preset-group { display: flex; gap: 4px; }

.aviso {
  background: color-mix(in srgb, var(--series-4) 15%, var(--surface-1));
  border: 1px solid var(--series-4);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 0 0 14px;
}

table.datos {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
table.datos th, table.datos td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--gridline);
  font-size: 13.5px;
}
table.datos th {
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--page-plane);
}
table.datos td.valor { text-align: right; font-weight: 600; }
table.datos tbody tr:last-child td { border-bottom: none; }
table.datos tr.seccion-header td {
  background: var(--page-plane);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.cotizaciones-seccion {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 18px 0 8px;
}
.cotizaciones-seccion:first-child { margin-top: 0; }

.cotizaciones-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.cotizaciones-grid-destacadas {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
}

.cotizacion-card {
  flex: 0 0 auto;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cotizacion-nombre {
  position: relative;
  background: #147a4d;
  color: #ffffff;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.cotizacion-nombre.tiene-editar {
  padding-right: 26px;
}
.cotizacion-valor {
  background: #ffffff;
  color: #0b0b0b;
  padding: 14px 12px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}
@media (max-width: 480px) {
  .cotizaciones-grid { flex-wrap: wrap; }
  .cotizacion-card { flex: 1 1 140px; }
  .cotizacion-nombre, .cotizacion-valor { white-space: normal; }
}
.cotizacion-fuente {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: #898781;
  text-transform: uppercase;
}
.cotizacion-editar {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(255,255,255,0.25);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}
.cotizacion-editar:hover { background: rgba(255,255,255,0.45); }

.comparar-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}
.series-picker {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  max-height: 640px;
  overflow-y: auto;
}
.series-picker h2 {
  margin: 0 0 4px;
  font-size: 14px;
}
.series-picker .hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.series-lista .grupo-nombre {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.series-lista .grupo-nombre:first-child { margin-top: 0; }
.serie-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  font-size: 13.5px;
  cursor: pointer;
}
.serie-item input { cursor: pointer; margin-top: 3px; }
.serie-item .swatch {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0;
  margin-top: 5px;
  visibility: hidden;
}
.serie-item.checked .swatch { visibility: visible; }
.serie-item.disabled { opacity: 0.35; cursor: not-allowed; }
.serie-texto { display: flex; flex-direction: column; }
.serie-cobertura { font-size: 11px; color: var(--text-muted); }

.comparar-main { flex: 1; min-width: 0; }

#chart-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
#chart-container svg { display: block; width: 100%; height: auto; }
.chart-empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 60px 0;
  text-align: center;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-key { width: 14px; height: 2px; border-radius: 1px; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.mini-chart { border: 1px solid var(--gridline); border-radius: 6px; padding: 10px; }
.mini-chart h3 { margin: 0 0 6px; font-size: 12.5px; font-weight: 600; }

.tooltip-box {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 10;
  white-space: nowrap;
}
.tooltip-box .tt-date { font-weight: 700; margin-bottom: 3px; }
.tooltip-row { display: flex; align-items: center; gap: 6px; }
.tooltip-row .key { width: 10px; height: 2px; flex-shrink: 0; }
.tooltip-row .val { font-weight: 700; margin-left: auto; padding-left: 10px; }

footer {
  padding: 14px 24px 24px;
  color: var(--text-muted);
  font-size: 12px;
}
