/* Tokens de color de gráficos y superficies (paleta validada para daltonismo) */
:root,
[data-bs-theme="light"] {
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ef;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --grid: #e7e5df;
  --series-1: #2a78d6;   /* azul: ingresos / periodo actual */
  --series-2: #eb6834;   /* naranja: salidas / periodo anterior */
  --series-3: #1baf7a;   /* aguamarina: disponible */
  --good: #008300;
  --bad: #c62828;
}
[data-bs-theme="dark"] {
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9d9c93;
  --grid: #383835;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good: #4caf50;
  --bad: #ef6b6b;
}

body { background: var(--surface-2); color: var(--text-primary); }
.app-navbar { background: var(--surface-1); }
.card { background: var(--surface-1); border-color: var(--grid); }

.kpi .etiqueta { color: var(--text-secondary); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi .valor { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .85rem; color: var(--text-secondary); }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }

.tabla-informe { font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla-informe th, .tabla-informe td { text-align: right; vertical-align: middle; }
.tabla-informe th:first-child, .tabla-informe td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); z-index: 1; }
.tabla-informe thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 2; }
.tabla-informe thead th:first-child { z-index: 3; }
.tabla-informe tfoot td, .tabla-informe tfoot th { font-weight: 700; border-top: 2px solid var(--text-secondary); background: var(--surface-2); }
.tabla-informe .destacada { font-weight: 600; }
.tabla-informe a { text-decoration: none; }
.tabla-informe a:hover { text-decoration: underline; }
.tabla-scroll { max-height: 70vh; overflow: auto; }

.grafico { position: relative; height: 300px; }
.grafico-alto { position: relative; height: 340px; }

.filtros .form-label { font-size: .8rem; color: var(--text-secondary); margin-bottom: .2rem; }
.dias-semana .btn { min-width: 2.8rem; }

.leyenda-viz { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .8rem; color: var(--text-secondary); }
.leyenda-viz span::before { content: ""; display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; background: var(--c); }
.leyenda-viz .linea::before { height: 2px; vertical-align: 3px; }

.estado-ok { color: var(--good); }
.estado-err { color: var(--bad); }

@media print {
  .app-navbar, .filtros, .no-print { display: none !important; }
  .tabla-scroll { max-height: none; overflow: visible; }
}

/* Fichas de establecimientos */
.ficha { transition: border-color .15s, box-shadow .15s; }
.ficha:hover { border-color: var(--series-1); box-shadow: 0 2px 10px rgba(0, 0, 0, .08); }
.ficha-icono { width: 2.4rem; height: 2.4rem; border-radius: .5rem; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--series-1); font-size: 1.2rem; flex-shrink: 0; }
.ficha-datos .kpi-linea { display: flex; align-items: baseline; gap: .5rem; padding: .15rem 0; color: var(--text-primary); }
.ficha-datos .kpi-linea .nombre { color: var(--text-secondary); flex: 0 0 5.5rem; }
.ficha-datos .kpi-linea .importe { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: auto; }
.ficha-datos .kpi-linea .var { flex: 0 0 auto; min-width: 4.8rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ficha-datos .kpi-linea .importe { white-space: nowrap; }
.min-w-0 { min-width: 0; }

/* ---------------------------------------------------------------------
   Diseño adaptable (móvil / tablet)
   --------------------------------------------------------------------- */
.periodos-rapidos { display: flex; flex-wrap: wrap; gap: .35rem; }
.periodos-rapidos .btn { border-radius: 2rem; padding-left: .8rem; padding-right: .8rem; }
.btn-mas-filtros[aria-expanded="true"] .bi-chevron-down { transform: rotate(180deg); }
.kpi .valor { font-size: clamp(1.1rem, 4.2vw, 1.5rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acciones-informe .btn { white-space: nowrap; }

@media (max-width: 767.98px) {
  main { padding-left: .75rem !important; padding-right: .75rem !important; }
  h1.h4 { font-size: 1.15rem; }
  .card-body { padding: .85rem; }

  /* Periodos rápidos: una sola fila deslizable con el dedo */
  .periodos-rapidos { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; margin: 0 -.85rem; padding: 0 .85rem .1rem; width: calc(100% + 1.7rem); }
  .periodos-rapidos::-webkit-scrollbar { display: none; }
  .periodos-rapidos .btn { flex: 0 0 auto; }

  /* Objetivos táctiles cómodos */
  .filtros .btn, .filtros .form-control, .filtros .form-select, .ficha .btn, .acciones-informe .btn,
  .btn-tema { min-height: 2.5rem; }
  .filtros .form-control, .filtros .form-select { font-size: 1rem; } /* evita el zoom automático de iOS */
  .dias-semana { display: flex; width: 100%; }
  .dias-semana .btn { flex: 1 1 0; min-width: 0; padding-left: 0; padding-right: 0; }

  .kpi .etiqueta { font-size: .7rem; }
  .kpi .delta { font-size: .75rem; }

  .grafico-alto { height: 250px; }
  .grafico { height: 220px; }

  .tabla-informe { font-size: .78rem; }
  .tabla-scroll { max-height: none; }
  .acciones-informe { width: 100%; }
  .acciones-informe .btn { flex: 1 1 0; }

  .navbar .dropdown-menu { border: 0; padding-left: .75rem; background: transparent; }
  .navbar-nav .nav-link { padding-top: .6rem; padding-bottom: .6rem; }
}

/* Detalle en móvil: lista de periodos desplegables */
.periodo-movil { border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.periodo-movil > summary, .periodo-movil.cabecera { display: grid; grid-template-columns: 1fr auto auto; gap: .75rem;
  align-items: center; padding: .6rem 0; list-style: none; cursor: pointer; font-size: .85rem; }
.periodo-movil > summary::-webkit-details-marker { display: none; }
.periodo-movil > summary > span:not(.etiqueta), .periodo-movil.cabecera > span:not(:first-child) { text-align: right; min-width: 6.2rem; }
.periodo-movil > summary .etiqueta::before { content: "\F285"; font-family: "bootstrap-icons"; font-size: .7rem; margin-right: .35rem;
  display: inline-block; transition: transform .15s; color: var(--text-secondary); }
.periodo-movil[open] > summary .etiqueta::before { transform: rotate(90deg); }
.periodo-movil.cabecera { cursor: default; font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-secondary); padding: 0 0 .3rem; }
.periodo-movil.total { font-weight: 700; border-top: 2px solid var(--text-secondary); border-bottom: 0; }
.periodo-movil dl { display: grid; grid-template-columns: 1fr auto; gap: .15rem .75rem; margin: 0 0 .6rem 1rem; font-size: .82rem; }
.periodo-movil dt { font-weight: 400; color: var(--text-secondary); }
.periodo-movil dd { margin: 0; text-align: right; }

/* Listas simples en móvil (gastos, tickets) */
.lista-simple .item { padding: .55rem 0; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.lista-simple .item.total { font-weight: 700; border-top: 2px solid var(--text-secondary); border-bottom: 0; }

/* Indicador de carga al cambiar de página */
.barra-progreso { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 2000;
  background: var(--series-1); box-shadow: 0 0 6px var(--series-1);
  animation: progreso 12s cubic-bezier(.08, .7, .2, 1) forwards; }
@keyframes progreso { 0% { width: 0; } 20% { width: 45%; } 100% { width: 92%; } }
.capa-carga { position: fixed; inset: 0; z-index: 1990; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent); backdrop-filter: blur(2px);
  animation: aparecer .2s ease-out; }
.capa-carga[hidden], .barra-progreso[hidden] { display: none; }
.capa-carga-caja { background: var(--surface-1); border: 1px solid var(--grid); border-radius: .75rem;
  padding: 1.5rem 2rem; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .15); max-width: 90vw; }
.capa-carga-caja .spinner-border { width: 2.5rem; height: 2.5rem; }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .barra-progreso { animation: none; width: 60%; } .capa-carga { animation: none; } }
