/* ═══ Control de Caja — sistema de diseño propio ═══════════════════
   Tokens → base → layout → componentes. Sin frameworks ni temas.
   Identidad: panadería (crema, tostado, espresso) con un acento azafrán. */

:root {
  /* Color */
  --fondo: #faf6f0;
  --superficie: #ffffff;
  --superficie-2: #f3ece2;
  --borde: #e4d9ca;
  --tinta: #2b1d14;
  --tinta-2: #6b5847;
  --tinta-3: #9a8775;
  --acento: #b5481c;
  --acento-tinta: #ffffff;
  --acento-suave: #f7e3d6;
  --ok: #2f7d4f;
  --ok-suave: #e1f1e6;
  --aviso: #9a6400;
  --aviso-suave: #fbefd3;
  --error: #b42318;
  --error-suave: #fde4e1;
  --foco: #1d64d8;
  /* Tipografía (fuentes del sistema: 0 KB de descarga) */
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --t-xs: .75rem; --t-sm: .875rem; --t-md: 1rem; --t-lg: 1.125rem; --t-xl: 1.375rem; --t-2xl: 1.75rem;
  /* Espaciado (base 4 px) */
  --e1: .25rem; --e2: .5rem; --e3: .75rem; --e4: 1rem; --e5: 1.5rem; --e6: 2rem; --e7: 3rem;
  /* Forma */
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-full: 999px;
  --sombra: 0 1px 2px rgb(43 29 20 / .06), 0 2px 8px rgb(43 29 20 / .06);
  --toque: 44px;            /* alto mínimo de cualquier control táctil */
  --nav-alto: 64px;
  --ancho-max: 1100px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #17110d; --superficie: #211913; --superficie-2: #2b211a; --borde: #3b2e25;
    --tinta: #f4ece3; --tinta-2: #c8b7a6; --tinta-3: #8f7d6c;
    --acento: #e8794a; --acento-tinta: #1b120c; --acento-suave: #3d2418;
    --ok: #6cc28f; --ok-suave: #193325; --aviso: #e6b34d; --aviso-suave: #3a2c10;
    --error: #ff8a7d; --error-suave: #3d1915; --foco: #7fb0ff;
    --sombra: 0 1px 2px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}

/* ─── Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fondo); color: var(--tinta); font: 400 var(--t-md)/1.5 var(--fuente); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: var(--t-xl); font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: var(--t-lg); font-weight: 650; margin-bottom: var(--e3); }
p { margin: 0 0 var(--e3); }
a { color: var(--acento); }
img { max-width: 100%; height: auto; }
code { background: var(--superficie-2); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.neg { color: var(--error); }
.pos { color: var(--ok); }
.meta, small { color: var(--tinta-2); font-size: var(--t-sm); }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ─── Layout ───────────────────────────────────────────────────── */
.main { max-width: var(--ancho-max); margin: 0 auto; padding: var(--e4) var(--e4) calc(var(--nav-alto) + var(--e7) + env(safe-area-inset-bottom)); }
.cab { display: flex; align-items: center; gap: var(--e3); min-height: var(--toque); margin-bottom: var(--e4); }
.cab h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cab-acciones { display: flex; gap: var(--e2); align-items: center; }
.seccion { margin-top: var(--e6); }
.sin-nav .main { padding-bottom: var(--e6); }

/* Navegación: barra inferior en celulares, lateral en pantallas grandes */
.nav { position: fixed; z-index: 20; inset: auto 0 0 0; height: calc(var(--nav-alto) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--superficie); border-top: 1px solid var(--borde); }
.nav-marca { display: none; }
.nav-salir { display: contents; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 0; color: var(--tinta-2); text-decoration: none; font: 500 var(--t-xs)/1 var(--fuente); background: none; border: 0; cursor: pointer; }
.nav-item[aria-current="page"] { color: var(--acento); }
.nav-item[aria-current="page"] .ico { stroke-width: 2.3; }
@media (min-width: 900px) {
  .nav { inset: 0 auto 0 0; width: 220px; height: auto; flex-direction: column; padding: var(--e4) var(--e3); gap: var(--e1); border-top: 0; border-right: 1px solid var(--borde); }
  .nav-marca { display: block; font-weight: 700; padding: var(--e2) var(--e3) var(--e4); }
  .nav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: var(--e3); padding: 0 var(--e3); min-height: var(--toque);
    border-radius: var(--r-md); font-size: var(--t-md); width: 100%; }
  .nav-item:hover { background: var(--superficie-2); }
  .nav-item[aria-current="page"] { background: var(--acento-suave); }
  .nav-salir .nav-item { margin-top: auto; }
  .nav-salir { display: block; margin-top: auto; }
  body:not(.sin-nav) .main { margin-left: 220px; padding: var(--e6) var(--e6) var(--e7); }
  body:not(.sin-nav) .main { max-width: calc(var(--ancho-max) + 220px); }
}

/* ─── Botones ──────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--e2); min-height: var(--toque); padding: 0 var(--e4);
  border-radius: var(--r-md); border: 1px solid transparent; font: 600 var(--t-md)/1 var(--fuente); text-decoration: none; cursor: pointer;
  touch-action: manipulation; transition: background-color .15s, border-color .15s; white-space: nowrap; }
.btn-primario { background: var(--acento); color: var(--acento-tinta); }
.btn-primario:hover { filter: brightness(1.06); }
.btn-secundario { background: var(--superficie); color: var(--tinta); border-color: var(--borde); }
.btn-secundario:hover { background: var(--superficie-2); }
.btn-fantasma { background: transparent; color: var(--tinta-2); }
.btn-fantasma:hover { background: var(--superficie-2); color: var(--tinta); }
.btn-bloque { width: 100%; }
.btn-icono { width: var(--toque); padding: 0; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .6; pointer-events: none; }
@media (max-width: 520px) { .cab-acciones .btn span { display: none; } .cab-acciones .btn { width: var(--toque); padding: 0; } }

/* ─── Formularios ──────────────────────────────────────────────── */
.campo { display: flex; flex-direction: column; gap: var(--e1); margin-bottom: var(--e4); min-width: 0; }
.campo label, legend { font-size: var(--t-sm); font-weight: 600; color: var(--tinta-2); }
input, select, textarea { font: 400 var(--t-md)/1.3 var(--fuente); color: var(--tinta); background: var(--superficie);
  border: 1px solid var(--borde); border-radius: var(--r-sm); min-height: var(--toque); padding: 0 var(--e3); width: 100%; }
textarea { padding: var(--e3); resize: vertical; }
select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { border-color: var(--foco); outline: 2px solid color-mix(in srgb, var(--foco) 25%, transparent); outline-offset: 0; }
input[readonly], textarea[readonly] { background: var(--superficie-2); color: var(--tinta-2); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--acento); flex: none; }
.campo-ayuda { margin: 0; font-size: var(--t-xs); color: var(--tinta-3); }
.campo-msj { margin: 0; font-size: var(--t-sm); color: var(--error); }
.campo-error input { border-color: var(--error); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.num.corto { width: 5rem; }
.interruptor { display: flex; align-items: center; gap: var(--e2); min-height: var(--toque); cursor: pointer; }
.grupo { border: 0; padding: 0; margin: 0 0 var(--e4); min-width: 0; }
.grupo legend { margin-bottom: var(--e2); }
.grilla-campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 var(--e3); }
.filtros, .form-linea { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 var(--e3); align-items: end; margin-bottom: var(--e4); }
.filtros .btn, .form-linea .btn, .filtros .interruptor { margin-bottom: var(--e4); }

/* ─── Superficies ──────────────────────────────────────────────── */
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r-lg); padding: var(--e4); margin-bottom: var(--e4); box-shadow: var(--sombra); }
.tarjeta h2 { margin-bottom: var(--e3); }
.desplegable summary { display: flex; align-items: center; gap: var(--e2); min-height: var(--toque); font-weight: 650; cursor: pointer; list-style: none; }
.desplegable summary::-webkit-details-marker { display: none; }
.desplegable[open] summary { margin-bottom: var(--e3); }
.aviso { padding: var(--e3) var(--e4); border-radius: var(--r-md); background: var(--superficie-2); margin-bottom: var(--e4); }
.aviso-ok { background: var(--ok-suave); color: var(--ok); }
.aviso-error { background: var(--error-suave); color: var(--error); }
.vacio { text-align: center; padding: var(--e6) var(--e4); color: var(--tinta-2); border: 1px dashed var(--borde); border-radius: var(--r-lg); }
.badge { display: inline-flex; align-items: center; padding: 2px var(--e2); border-radius: var(--r-full); font-size: var(--t-xs); font-weight: 600;
  background: var(--superficie-2); color: var(--tinta-2); white-space: nowrap; }
.badge-ok { background: var(--ok-suave); color: var(--ok); }
.badge-aviso { background: var(--aviso-suave); color: var(--aviso); }
.badge-error { background: var(--error-suave); color: var(--error); }
.acciones-sec { display: flex; gap: var(--e2); overflow-x: auto; margin-bottom: var(--e4); padding-bottom: 2px; }

/* KPI */
.grilla-kpi { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: var(--e3); margin-bottom: var(--e4); }
.kpi { display: flex; flex-direction: column; gap: var(--e1); padding: var(--e3) var(--e4); min-width: 0; background: var(--superficie); border: 1px solid var(--borde);
  border-radius: var(--r-lg); color: inherit; text-decoration: none; box-shadow: var(--sombra); }
a.kpi:hover { border-color: var(--acento); }
.kpi-titulo { font-size: var(--t-sm); color: var(--tinta-2); font-weight: 600; }
.kpi-valor { font-size: clamp(var(--t-lg), 5.2vw, var(--t-2xl)); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-vacio { color: var(--tinta-3); font-size: var(--t-lg); }
.kpi-pie { display: flex; flex-wrap: wrap; gap: var(--e2); align-items: center; font-size: var(--t-sm); color: var(--tinta-2); }

/* Listas */
.lista { list-style: none; margin: 0; padding: 0; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r-lg); overflow: hidden; }
.lista > li + li { border-top: 1px solid var(--borde); }
.lista-fila { display: flex; align-items: center; gap: var(--e3); min-height: 56px; padding: var(--e2) var(--e4); color: inherit; text-decoration: none; }
a.lista-fila:hover { background: var(--superficie-2); }
.lista-fila > span:first-child:not(.miniatura), .lf-principal { flex: 1; min-width: 0; }
.lf-principal { display: flex; flex-direction: column; }
.lf-principal strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lf-dato { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.lista-menu .ico { color: var(--tinta-3); }
.miniatura { width: 48px; height: 48px; border-radius: var(--r-md); object-fit: cover; flex: none; background: var(--superficie-2); }
.miniatura-vacia { display: grid; place-items: center; font-weight: 700; color: var(--tinta-3); text-transform: uppercase; }
.foto { border-radius: var(--r-md); margin-bottom: var(--e4); max-height: 320px; }
.ver-mas { text-align: center; margin-top: var(--e4); }

/* Tablas: scroll horizontal propio en pantallas chicas */
.tabla-scroll { overflow-x: auto; border: 1px solid var(--borde); border-radius: var(--r-lg); background: var(--superficie); margin-bottom: var(--e4); }
.tabla { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { padding: var(--e2) var(--e3); text-align: left; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla th { font-size: var(--t-sm); color: var(--tinta-2); font-weight: 600; background: var(--superficie-2); position: sticky; top: 0; }
.tabla .n { text-align: right; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla-edicion td { padding: var(--e1) var(--e2); }
.enlace-sec { font-size: var(--t-sm); font-weight: 500; margin-left: var(--e2); }

/* Gráficos */
.grafico { margin: var(--e4) 0; padding: var(--e4); background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r-lg); }
.grafico svg { width: 100%; height: 160px; display: block; }
.grafico figcaption { font-size: var(--t-sm); color: var(--tinta-2); margin-top: var(--e2); }
.g-barra { fill: var(--acento); }
.g-neg { fill: var(--error); }
.g-eje { fill: var(--tinta-3); font-size: 12px; text-anchor: middle; }
.barras-h { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--e2); }
.barras-h li { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: var(--e3); align-items: center; font-variant-numeric: tabular-nums; }
meter { width: 100%; height: 10px; }
meter::-webkit-meter-bar { background: var(--superficie-2); border: 0; border-radius: var(--r-full); }
meter::-webkit-meter-optimum-value { background: var(--acento); border-radius: var(--r-full); }
meter::-moz-meter-bar { background: var(--acento); border-radius: var(--r-full); }

/* ─── Cierre (pantalla de carga) ───────────────────────────────── */
.resumen-fijo { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr 1fr; gap: var(--e3);
  margin: 0 calc(-1 * var(--e4)); padding: var(--e2) var(--e4); background: color-mix(in srgb, var(--fondo) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--borde); }
.resumen-fijo div { display: flex; flex-direction: column; }
.resumen-fijo strong { font-size: var(--t-xl); font-variant-numeric: tabular-nums; }
.herramientas { display: grid; grid-template-columns: 1fr auto; gap: var(--e3); align-items: center; margin-bottom: var(--e3); }
.chips { display: flex; gap: var(--e2); overflow-x: auto; padding-bottom: var(--e2); margin-bottom: var(--e3); scrollbar-width: none; }
.chip { flex: none; display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--e3); border-radius: var(--r-full);
  border: 1px solid var(--borde); background: var(--superficie); color: var(--tinta); text-decoration: none; font-size: var(--t-sm); font-weight: 600; }
.grupo legend { font-size: var(--t-md); color: var(--tinta); padding-top: var(--e3); scroll-margin-top: 80px; }
.cierre .grupo { scroll-margin-top: 80px; }
.prod { padding: var(--e3) 0; border-bottom: 1px solid var(--borde); }
.prod-cab { display: flex; justify-content: space-between; gap: var(--e2); margin-bottom: var(--e2); }
.prod-nombre { font-weight: 600; }
.prod-meta { font-size: var(--t-xs); color: var(--tinta-3); white-space: nowrap; }
.prod-campos { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--e2); }
.prod-campos label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.prod-campos label > span { font-size: var(--t-xs); color: var(--tinta-3); }
.prod-campos input, .prod-campos output.num { padding: 0 var(--e2); min-height: var(--toque); }
.prod-campos output.num { display: flex; align-items: center; justify-content: flex-end; background: var(--superficie-2); border-radius: var(--r-sm); color: var(--tinta-2); }
.prod-res output { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.prod-imp { font-size: var(--t-xs); color: var(--tinta-2); font-weight: 500 !important; }
.prod.con-mov .prod-nombre::after { content: " •"; color: var(--acento); }
.prod.neg-venta .prod-res output:first-of-type { color: var(--error); }
.solo-mov .prod:not(.con-mov) { display: none; }
@media (min-width: 700px) {
  .prod { display: grid; grid-template-columns: minmax(160px, 1.2fr) 3fr; gap: var(--e4); align-items: center; }
  .prod-cab { flex-direction: column; margin: 0; gap: 0; }
}
.barra-acciones { position: sticky; bottom: calc(var(--nav-alto) + env(safe-area-inset-bottom)); z-index: 10; display: flex; gap: var(--e3); justify-content: flex-end;
  margin: var(--e5) calc(-1 * var(--e4)) 0; padding: var(--e3) var(--e4); background: color-mix(in srgb, var(--fondo) 92%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--borde); }
.barra-acciones .btn { flex: 1; max-width: 260px; }
.tarjeta .barra-acciones { position: static; margin: var(--e4) 0 0; padding: 0; background: none; border: 0; backdrop-filter: none; }
@media (min-width: 900px) { .barra-acciones { bottom: 0; } }

/* Login */
.login { max-width: 400px; margin: 10vh auto 0; }
.login-marca { font-size: var(--t-2xl); font-weight: 750; letter-spacing: -.02em; color: var(--acento); }
.sin-nav .cab { display: none; }

/* ─── Alertas (capítulo 13) ────────────────────────────────────── */
.seccion-alertas h2 { color: var(--error); }
.alertas { list-style: none; margin: 0 0 var(--e4); padding: 0; display: grid; gap: var(--e2); }
.alerta { display: flex; align-items: center; gap: var(--e3); padding: var(--e3) var(--e4); border-radius: var(--r-md);
  background: var(--aviso-suave); border-left: 4px solid var(--aviso); }
.alerta-alta { background: var(--error-suave); border-left-color: var(--error); }
.alerta-revisada { opacity: .65; border-left-color: var(--borde); background: var(--superficie-2); }
.alerta-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.alerta-txt a { color: inherit; }
.alerta form { flex: none; }
.chip[aria-current="page"] { background: var(--acento); color: var(--acento-tinta); border-color: var(--acento); }
