:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6; /* blue: transferencia / gasto por categoría / evolución */
  --series-1-soft: #b7d3f6; /* meses fuera de foco en la evolución */
  --series-2: #eb6834; /* orange: efectivo */
  --series-3: #1baf7a; /* aqua: fijo */
  --series-4: #eda100; /* yellow: variable */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}

* {
  box-sizing: border-box;
}

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

.pagina {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.pagina[hidden] {
  display: none;
}

/* --- login --- */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 16px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--series-1);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  color: var(--series-2);
  font-size: 13px;
  margin: 8px 0 0;
  min-height: 16px;
}

/* --- header / filtro --- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

header h1 {
  font-size: 20px;
  margin: 0;
}

#selector-mes {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 14px;
}

/* --- tarjetas --- */

.tarjeta {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.tarjeta h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 16px;
}

.hero {
  font-size: 40px;
  font-weight: 700;
  margin: 0;
}

.hero-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.fila-tarjetas {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 520px) {
  .fila-tarjetas {
    grid-template-columns: 1fr;
  }
}

/* --- stacked bar (blancos/negros, fijo/variable) --- */

.stack {
  display: flex;
  height: 20px;
  gap: 2px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-1);
  margin-bottom: 12px;
}

.stack-segmento {
  height: 100%;
}

.leyenda {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.leyenda-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.leyenda-marca {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.leyenda-valor {
  color: var(--text-primary);
  font-weight: 600;
  margin-left: 2px;
}

/* --- barras horizontales (categoría) --- */

.fila-barra {
  display: grid;
  grid-template-columns: 120px 1fr 74px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.fila-barra .etiqueta {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pista-barra {
  height: 18px;
  background: var(--page);
  border-radius: 4px;
  position: relative;
}

.pista-barra .barra {
  height: 100%;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
  min-width: 2px;
  transition: filter 0.1s ease;
}

.pista-barra .barra:hover,
.pista-barra .barra:focus-visible {
  filter: brightness(1.12);
}

.fila-barra .valor {
  text-align: right;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* --- evolución mensual (columnas) --- */

.evolucion {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  padding-top: 20px;
}

.evolucion-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
}

.evolucion-col .barra {
  width: 100%;
  max-width: 28px;
  background: var(--series-1-soft);
  border-radius: 4px 4px 0 0;
  transition: filter 0.1s ease;
}

.evolucion-col.activo .barra {
  background: var(--series-1);
}

.evolucion-col .etq-valor {
  position: absolute;
  top: -18px;
  font-size: 11px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.evolucion-col .etq-mes {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* --- tooltip --- */

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--page);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  z-index: 10;
}

.tooltip[hidden] {
  display: none;
}

.tooltip strong {
  font-variant-numeric: tabular-nums;
}

/* --- tabla --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

td.monto {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tabla-scroll {
  overflow-x: auto;
}

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