/* ============================================================
   Gastify — hoja de estilos unica
   ------------------------------------------------------------
   Sin Tailwind, sin CDN, sin fuentes de Google: todo propio.
   Eso hace que la app cargue rapido, funcione sin conexion y
   no filtre visitas a terceros.

   Orden del archivo:
     1. Tokens y tema
     2. Reset
     3. Tipografia y utilidades
     4. Componentes
     5. Estructura (movil primero)
     6. Pantallas
     7. Impresion y accesibilidad
   ============================================================ */

/* ── 1. TOKENS ─────────────────────────────────────────────── */
:root {
    /* Marca */
    --brand-50:  #ecfdf5;
    --brand-100: #d1fae5;
    --brand-200: #a7f3d0;
    --brand-400: #34d399;
    --brand-500: #10b981;
    --brand-600: #059669;
    --brand-700: #047857;
    --brand-800: #065f46;

    /* Neutros */
    --gray-0:   #ffffff;
    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --gray-950: #020617;

    /* Semanticos */
    --amber-50:   #fffbeb;  --amber-200: #fde68a;  --amber-600: #d97706;  --amber-700: #b45309;
    --blue-50:    #eff6ff;  --blue-200:  #bfdbfe;  --blue-600:  #2563eb;  --blue-700:  #1d4ed8;
    --green-50:   #ecfdf5;  --green-200: #a7f3d0;  --green-600: #059669;  --green-700: #047857;
    --red-50:     #fef2f2;  --red-200:   #fecaca;  --red-600:   #dc2626;  --red-700:   #b91c1c;
    --purple-50:  #faf5ff;  --purple-200:#e9d5ff;  --purple-600:#9333ea;
    --orange-50:  #fff7ed;  --orange-200:#fed7aa;  --orange-600:#ea580c;

    /* Superficies (tema claro) */
    --bg:          var(--gray-50);
    --surface:     var(--gray-0);
    --surface-2:   var(--gray-100);
    --surface-3:   var(--gray-200);
    --border:      var(--gray-200);
    --border-soft: var(--gray-100);
    --text:        var(--gray-900);
    --text-soft:   var(--gray-600);
    /* gray-500 y no gray-400: con gray-400 el texto apagado quedaba en
       2.45:1 sobre el fondo, muy por debajo del 4.5:1 que pide WCAG AA.
       Este da 4.55:1 contra el fondo y mas contra las tarjetas blancas,
       y sigue leyendose como secundario frente a --text-soft (7.2:1). */
    --text-mute:   var(--gray-500);
    /* #059669 y #047857: los mismos que el icono de la app y la marca. */
    --accent:      var(--brand-600);
    --accent-hover:var(--brand-700);
    --accent-soft: var(--brand-50);
    --accent-text: #ffffff;
    --on-accent-soft: var(--brand-800);

    /* Formas */
    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 24px;
    --r-full: 999px;

    /* Sombras */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12), 0 2px 8px rgba(15, 23, 42, .06);
    --shadow-accent: 0 6px 18px rgba(5, 150, 105, .28);

    /* Medidas */
    --header-h: 56px;
    --tabbar-h: 64px;
    --sidebar-w: 256px;
    --content-max: 1180px;

    /* Tipografia del sistema: 0 bytes que descargar */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
            "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --tap: 44px;               /* area minima tactil comoda */
    --ease: cubic-bezier(.4, 0, .2, 1);
}

/* Tema oscuro: sigue al sistema y se puede forzar con data-theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:          var(--gray-950);
        --surface:     #0b1220;
        --surface-2:   #131d2f;
        --surface-3:   #1e293b;
        --border:      #1e293b;
        --border-soft: #172033;
        --text:        #e2e8f0;
        --text-soft:   #94a3b8;
        /* 5.3:1 sobre el fondo y 4.9:1 sobre las tarjetas. El #64748b
           anterior se quedaba en 4.24:1. */
        --text-mute:   #75849a;
        --accent:      var(--brand-500);
        --accent-hover:var(--brand-400);
        --accent-soft: rgba(16, 185, 129, .12);
        --accent-text: #022c22;
        --on-accent-soft: var(--brand-200);

        --amber-50: rgba(217, 119, 6, .14);   --amber-200: rgba(217, 119, 6, .35);  --amber-700: #fcd34d;
        --blue-50:  rgba(37, 99, 235, .14);   --blue-200:  rgba(37, 99, 235, .35);  --blue-700:  #93c5fd;
        --green-50: rgba(5, 150, 105, .14);   --green-200: rgba(5, 150, 105, .35);  --green-700: #6ee7b7;
        --red-50:   rgba(220, 38, 38, .14);   --red-200:   rgba(220, 38, 38, .35);  --red-700:   #fca5a5;
        --purple-50:rgba(147, 51, 234, .14);  --purple-200:rgba(147, 51, 234, .35);
        --orange-50:rgba(234, 88, 12, .14);   --orange-200:rgba(234, 88, 12, .35);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, .45);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
        --shadow-accent: 0 6px 18px rgba(16, 185, 129, .25);
    }
}

:root[data-theme="dark"] {
    --bg: var(--gray-950);      --surface: #0b1220;   --surface-2: #131d2f;
    --surface-3: #1e293b;       --border: #1e293b;    --border-soft: #172033;
    --text: #e2e8f0;            --text-soft: #94a3b8; --text-mute: #75849a;
    --accent: var(--brand-500); --accent-hover: var(--brand-400);
    --accent-soft: rgba(16, 185, 129, .12); --accent-text: #022c22;
    --on-accent-soft: var(--brand-200);
    --amber-50: rgba(217, 119, 6, .14);  --amber-200: rgba(217, 119, 6, .35);  --amber-700: #fcd34d;
    --blue-50:  rgba(37, 99, 235, .14);  --blue-200:  rgba(37, 99, 235, .35);  --blue-700:  #93c5fd;
    --green-50: rgba(5, 150, 105, .14);  --green-200: rgba(5, 150, 105, .35);  --green-700: #6ee7b7;
    --red-50:   rgba(220, 38, 38, .14);  --red-200:   rgba(220, 38, 38, .35);  --red-700:   #fca5a5;
    --purple-50:rgba(147, 51, 234, .14); --purple-200:rgba(147, 51, 234, .35);
    --orange-50:rgba(234, 88, 12, .14);  --orange-200:rgba(234, 88, 12, .35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

/* ── 2. RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-wrap: break-word;
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }

button, input, select, textarea {
    font: inherit;
    color: inherit;
    margin: 0;
}

button { background: none; border: none; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

[hidden] { display: none !important; }

/* ── 3. TIPOGRAFIA Y UTILIDADES ────────────────────────────── */
.h1 { font-size: 1.5rem;  font-weight: 700; letter-spacing: -.02em; }
.h2 { font-size: 1.125rem; font-weight: 700; letter-spacing: -.01em; }
.h3 { font-size: .9375rem; font-weight: 600; }

.text-sm   { font-size: .8125rem; }
.text-xs   { font-size: .75rem; }
.text-soft { color: var(--text-soft); }
.text-mute { color: var(--text-mute); }
.text-danger { color: var(--red-600); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.strong { font-weight: 600; }

.num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.row   { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.col   { display: flex; flex-direction: column; }
.grow  { flex: 1; min-width: 0; }
.wrap  { flex-wrap: wrap; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8  { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon {
    width: 20px; height: 20px;
    flex: none;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }

/* ── 4. COMPONENTES ────────────────────────────────────────── */

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 10px 18px;
    border-radius: var(--r-md);
    font-size: .9375rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    transition: background .15s var(--ease), transform .1s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: var(--shadow-accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-700); }

.btn-danger-soft { background: var(--red-50); color: var(--red-600); border-color: var(--red-200); }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .8125rem; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: var(--tap); min-height: var(--tap); border-radius: var(--r-md); }

/* Tarjetas */
.card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px; }
.card-hover { transition: box-shadow .18s var(--ease), transform .18s var(--ease), border-color .18s var(--ease); }
.card-hover:hover { box-shadow: var(--shadow-md); border-color: var(--border); }
.card-hover:active { transform: scale(.99); }

/* Formularios */
.field { display: block; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.label {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text-soft);
    margin-bottom: 6px;
}
.label .opt { font-weight: 400; color: var(--text-mute); }

.input, .select, .textarea {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    /* 16px evita el zoom automatico de iOS al enfocar un campo */
    font-size: 16px;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
    appearance: none;
    -webkit-appearance: none;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.5; padding-top: 10px; }

.input::placeholder, .textarea::placeholder { color: var(--text-mute); }

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input[aria-invalid="true"], .select[aria-invalid="true"] {
    border-color: var(--red-600);
}
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--red-50); }

.select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
}

.input-group { position: relative; }
.input-group .input { padding-left: 40px; }
.input-group .input-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-mute);
    pointer-events: none;
}
.input-group .input-action {
    position: absolute;
    right: 4px; top: 50%;
    transform: translateY(-50%);
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border-radius: var(--r-sm);
    color: var(--text-mute);
}
.input-group .input-action:hover { color: var(--text); background: var(--surface-2); }

.input-prefix { display: flex; align-items: stretch; }
.input-prefix > .prefix {
    display: grid; place-items: center;
    padding: 0 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--r-md) 0 0 var(--r-md);
    color: var(--text-soft);
    font-size: .8125rem;
    font-weight: 600;
}
.input-prefix > .input { border-radius: 0 var(--r-md) var(--r-md) 0; }

.hint  { display: block; font-size: .75rem; color: var(--text-mute); margin-top: 6px; }
.error { display: block; font-size: .75rem; color: var(--red-600); margin-top: 6px; font-weight: 500; }

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    padding: 8px 0;
    user-select: none;
}
.check input[type="checkbox"] {
    width: 20px; height: 20px;
    flex: none;
    margin-top: 1px;
    accent-color: var(--accent);
    cursor: pointer;
}
.check span { font-size: .875rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Etiquetas de estado */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .01em;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-pendiente     { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-200); }
.badge-por_facturar  { background: var(--blue-50);  color: var(--blue-700);  border-color: var(--blue-200); }
.badge-facturado     { background: var(--green-50); color: var(--green-700); border-color: var(--green-200); }
.badge-no_facturable { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }
.badge-warn          { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-200); }
.badge-info          { background: var(--accent-soft); color: var(--on-accent-soft); border-color: transparent; }

/* Filtros tipo pastilla */
.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
    /* Se desborda hasta el borde en movil para que no parezca cortado */
    margin-inline: calc(var(--pad) * -1);
    padding-inline: var(--pad);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: none;
    padding: 7px 14px;
    border-radius: var(--r-full);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-soft);
    font-size: .8125rem;
    font-weight: 600;
    white-space: nowrap;
    scroll-snap-align: start;
    transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/*
    Area tactil sin engordar el diseno.

    Un chip mide 36 px de alto y un boton pequeno tambien; el minimo
    comodo con el pulgar son los 44 px que declara --tap. Subir la
    altura real los volveria pesados y rompe la linea del diseno, asi
    que se extiende solo la zona que recibe el toque: el pseudoelemento
    no ocupa espacio en el flujo, de modo que nada se mueve.
*/
/* .input-action ya es absolute: anadirle relative lo sacaba del sitio
   y lo tiraba encima del icono del candado. Un absolute ya ancla a su
   propio ::after, asi que solo lo necesitan estos dos. */
.chip,
.btn-sm { position: relative; }

.chip::after,
.btn-sm::after,
.input-group .input-action::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: var(--tap);
    transform: translateY(-50%);
}

/* Con raton no hace falta, y asi no se solapan zonas invisibles. */
@media (hover: hover) and (pointer: fine) {
    .chip::after,
    .btn-sm::after,
    .input-group .input-action::after { display: none; }
}

.chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}
.chip .count {
    margin-left: 4px;
    opacity: .7;
    font-variant-numeric: tabular-nums;
}

/* Icono de categoria */
.cat {
    width: 42px; height: 42px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--r-md);
}
.cat-sm { width: 34px; height: 34px; }
.cat-alimentos   { background: var(--orange-50); color: var(--orange-600); }
.cat-transporte  { background: var(--blue-50);   color: var(--blue-600); }
.cat-combustible { background: var(--red-50);    color: var(--red-600); }
.cat-hospedaje   { background: var(--purple-50); color: var(--purple-600); }
.cat-peajes      { background: var(--amber-50);  color: var(--amber-600); }
.cat-oficina     { background: var(--green-50);  color: var(--green-600); }
.cat-otros       { background: var(--surface-2); color: var(--text-soft); }

/* Avatar */
.avatar {
    width: 36px; height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--r-full);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    font-size: .875rem;
}
.avatar-lg { width: 56px; height: 56px; font-size: 1.375rem; }

/* Fila de lista */
.list { display: flex; flex-direction: column; gap: 8px; }

.item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    text-align: left;
    transition: border-color .15s var(--ease), background .15s var(--ease), transform .1s var(--ease);
}
.item:hover { border-color: var(--border); background: var(--surface); text-decoration: none; }
.item:active { transform: scale(.995); }
.item.is-selected { border-color: var(--accent); background: var(--accent-soft); }

.item-thumb {
    width: 42px; height: 42px;
    flex: none;
    border-radius: var(--r-md);
    object-fit: cover;
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
}

/* Panel de estadistica */
.stat {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-lg);
    text-align: left;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.stat:hover { border-color: var(--accent); box-shadow: var(--shadow-md); text-decoration: none; }
.stat:active { transform: scale(.985); }
.stat-label { font-size: .75rem; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.stat-value { font-size: 1.375rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-meta  { font-size: .75rem; color: var(--text-mute); margin-top: 2px; }
.stat-up    { color: var(--red-600); }
.stat-down  { color: var(--green-600); }

/* Barra de progreso / desglose */
.bar {
    height: 8px;
    border-radius: var(--r-full);
    background: var(--surface-2);
    overflow: hidden;
}
.bar > span {
    display: block;
    height: 100%;
    border-radius: var(--r-full);
    background: var(--accent);
    transition: width .4s var(--ease);
}

/* Grafico de barras de meses */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 96px;
    padding-top: 8px;
}
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.spark-bar {
    width: 100%;
    max-width: 34px;
    margin-top: auto;
    background: var(--accent-soft);
    border-radius: var(--r-xs) var(--r-xs) 2px 2px;
    min-height: 3px;
    transition: height .4s var(--ease);
    position: relative;
}
.spark-col.is-current .spark-bar { background: var(--accent); }
.spark-label { font-size: .6875rem; color: var(--text-mute); font-weight: 600; }

/* Estado vacio */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    padding: 48px 24px;
    color: var(--text-soft);
}
.empty-icon {
    width: 64px; height: 64px;
    display: grid; place-items: center;
    border-radius: var(--r-xl);
    background: var(--surface-2);
    color: var(--text-mute);
}
.empty h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.empty p { font-size: .875rem; max-width: 34ch; }

/* Esqueleto de carga */
.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: var(--r-sm);
}
@keyframes shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
.skeleton-row { height: 66px; border-radius: var(--r-md); margin-bottom: 8px; }

/* Aviso */
.alert {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    font-size: .8125rem;
    border: 1px solid transparent;
    line-height: 1.45;
}
.alert .icon { margin-top: 1px; }
.alert-error   { background: var(--red-50);   color: var(--red-700);   border-color: var(--red-200); }
.alert-warn    { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-200); }
.alert-info    { background: var(--blue-50);  color: var(--blue-700);  border-color: var(--blue-200); }
.alert-success { background: var(--green-50); color: var(--green-700); border-color: var(--green-200); }

/* Avisos */
.toast-stack {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 420px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--r-md);
    background: var(--gray-900);
    color: #fff;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in .25s var(--ease);
}
.toast-success { background: var(--green-700); }
.toast-error   { background: var(--red-700); }
.toast-warn    { background: var(--amber-700); color: #1c1917; }
.toast.is-leaving { animation: toast-out .2s var(--ease) forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(8px) scale(.97); } }

/* Modal / hoja inferior */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(2, 6, 23, .55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: fade-in .18s var(--ease);
    padding: 0;
}
@keyframes fade-in { from { opacity: 0; } }

.sheet {
    width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    animation: sheet-up .28s var(--ease);
    overflow: hidden;
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.sheet-grab {
    width: 38px; height: 4px;
    border-radius: var(--r-full);
    background: var(--border);
    margin: 10px auto 0;
    flex: none;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    flex: none;
}
.sheet-title { font-size: 1rem; font-weight: 700; }
.sheet-sub { font-size: .75rem; color: var(--text-mute); margin-top: 2px; }

.sheet-body {
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.sheet-foot {
    display: flex;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-soft);
    background: var(--surface);
    flex: none;
}
.sheet-foot .btn { flex: 1; }

/* ── 5. ESTRUCTURA ─────────────────────────────────────────── */
:root { --pad: 16px; }

.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* Encabezado movil */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--header-h);
    padding: 0 var(--pad);
    padding-top: env(safe-area-inset-top);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-soft);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .topbar { background: var(--surface); }
}

.topbar-title { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: -.02em;
    color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .mark {
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--accent-text);
}
.brand .dot { color: var(--accent); }

/* Contenido */
.main {
    flex: 1;
    padding: var(--pad);
    padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

.page-head { margin-bottom: 16px; }
.page-head .h1 { margin-bottom: 2px; }

.section { margin-bottom: 24px; }
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.section-head .h2 { font-size: .9375rem; }
.section-link { font-size: .8125rem; font-weight: 600; }

/* Barra de pestanas inferior (movil) */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border-soft);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .tabbar { background: var(--surface); }
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 100%;
    color: var(--text-mute);
    font-size: .625rem;
    font-weight: 600;
    transition: color .15s var(--ease);
}
.tab:hover { text-decoration: none; color: var(--text-soft); }
.tab[aria-current="page"] { color: var(--accent); }
.tab .icon { width: 22px; height: 22px; }

/* Boton central de escaneo */
.tab-scan { position: relative; }
.tab-scan .scan-fab {
    position: absolute;
    top: -18px;
    width: 52px; height: 52px;
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: var(--shadow-accent);
    border: 3px solid var(--bg);
    transition: transform .15s var(--ease);
}
.tab-scan:active .scan-fab { transform: scale(.92); }

/* El botón central no tiene icono en el flujo (es absoluto), así que su
   etiqueta se alinea por abajo para quedar a la misma altura que las demás. */
.tab-scan {
    justify-content: flex-end;
    padding-bottom: 13px;
}

/* Barra lateral (escritorio) */
.sidebar { display: none; }

/* Escritorio */
@media (min-width: 1024px) {
    :root { --pad: 28px; }

    .app { flex-direction: row; }

    .sidebar {
        display: flex;
        flex-direction: column;
        gap: 4px;
        position: sticky;
        top: 0;
        width: var(--sidebar-w);
        height: 100vh;
        height: 100dvh;
        flex: none;
        padding: 20px 14px;
        background: var(--surface);
        border-right: 1px solid var(--border-soft);
    }

    .sidebar .brand { padding: 0 10px 18px; }

    .nav-link {
        display: flex;
        align-items: center;
        gap: 11px;
        padding: 10px 12px;
        border-radius: var(--r-md);
        color: var(--text-soft);
        font-size: .9375rem;
        font-weight: 600;
        transition: background .15s var(--ease), color .15s var(--ease);
    }
    .nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
    .nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--on-accent-soft); }
    .nav-link .badge-count {
        margin-left: auto;
        background: var(--accent);
        color: var(--accent-text);
        border-radius: var(--r-full);
        padding: 1px 7px;
        font-size: .6875rem;
        font-weight: 700;
    }

    .sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-soft); }

    .tabbar { display: none; }
    .topbar { display: none; }

    .content { flex: 1; min-width: 0; }
    .main { padding: 28px; padding-bottom: 48px; }

    .page-head { margin-bottom: 22px; }
    .page-head .h1 { font-size: 1.75rem; }

    /* En escritorio el modal se centra en vez de subir desde abajo */
    .overlay { align-items: center; padding: 24px; }
    .sheet {
        max-width: 560px;
        max-height: 86vh;
        border-radius: var(--r-xl);
        animation: sheet-pop .2s var(--ease);
    }
    .sheet-grab { display: none; }
    .sheet-wide { max-width: 780px; }
    .sheet-foot { padding-bottom: 14px; }

    @keyframes sheet-pop { from { opacity: 0; transform: scale(.97) translateY(8px); } }

    .toast-stack { bottom: 24px; left: auto; right: 24px; transform: none; }
}

/* ── 6. PANTALLAS ──────────────────────────────────────────── */

/* ── Acceso ────────────────────────────────────────────────────
   Se conserva la identidad original de Gastify: el escudo verde
   claro con el logo escáner + símbolo de peso, el nombre en grande
   y el lema en versalitas. */

.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
    background: var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 448px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Cabecera separada del formulario, como en el diseño original */
.auth-head {
    text-align: center;
    padding: 32px 24px 28px;
    border-bottom: 1px solid var(--border-soft);
}

.auth-body { padding: 26px 24px 30px; }

/* Escudo del logo: tono claro de marca con halo alrededor */
.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    border-radius: var(--r-lg);
    background: var(--accent-soft);
    color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-sm);
}

/* El escáner y el símbolo de peso se superponen en el mismo cuadro */
.auth-logo .logo-stack {
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
}
.auth-logo .logo-scan { width: 40px; height: 40px; stroke-width: 2; }
.auth-logo .logo-money {
    position: absolute;
    width: 20px;
    height: 20px;
    stroke-width: 3;
}

.auth-name {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -.025em;
    color: var(--text);
    margin-bottom: 4px;
}
.auth-name .dot { color: var(--accent); }

.auth-tag {
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .85;
}

.auth-foot {
    text-align: center;
    margin-top: 24px;
    font-size: .875rem;
    color: var(--text-soft);
}
.auth-foot a { font-weight: 700; }

/* Campos con fondo suave que se aclara al enfocar */
.auth-card .input {
    background: var(--surface-2);
    padding-top: 13px;
    padding-bottom: 13px;
}
.auth-card .input:focus { background: var(--surface); }

.auth-card .btn-primary {
    padding-top: 13px;
    padding-bottom: 13px;
    font-weight: 700;
}

/* La flecha acompaña al cursor, como en la versión anterior */
.auth-card .btn-primary .icon { transition: transform .15s var(--ease); }
.auth-card .btn-primary:hover:not(:disabled) .icon { transform: translateX(3px); }

/* Crear cuenta: botón oscuro para distinguirlo de "Entrar" */
.btn-dark {
    background: var(--gray-900);
    color: #fff;
    box-shadow: var(--shadow-md);
}
.btn-dark:hover:not(:disabled) { background: var(--gray-800); }

/* En tema oscuro el negro no contrasta: se invierte a claro. */
:root[data-theme="dark"] .btn-dark { background: var(--gray-200); color: var(--gray-900); }
:root[data-theme="dark"] .btn-dark:hover:not(:disabled) { background: #fff; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-dark { background: var(--gray-200); color: var(--gray-900); }
    :root:not([data-theme="light"]) .btn-dark:hover:not(:disabled) { background: #fff; }
}

.forgot-link {
    display: block;
    text-align: right;
    margin-top: 8px;
    font-size: .75rem;
    font-weight: 500;
    color: var(--accent);
}

/* Separador "o" entre entrar con contraseña y entrar con huella */
.auth-divider {
    position: relative;
    text-align: center;
    margin: 20px 0 16px;
}
.auth-divider::before {
    content: "";
    position: absolute;
    inset: 50% 0 auto;
    height: 1px;
    background: var(--border);
}
.auth-divider span {
    position: relative;
    padding: 0 12px;
    background: var(--surface);
    color: var(--text-mute);
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* Botón de huella: destaca sin competir con el botón principal */
.btn-bio {
    background: var(--accent-soft);
    color: var(--on-accent-soft);
    border-color: transparent;
}
.btn-bio:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }
.btn-bio .icon { width: 22px; height: 22px; }

/* Dispositivo registrado en Ajustes */
.device-row { display: flex; align-items: center; gap: 12px; }
.device-row .device-icon {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    color: var(--accent);
    flex: none;
}

/* Panel de estadisticas */
.grid-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid-cards { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* Estas van DESPUES de las reglas base a proposito: con la misma
   especificidad manda la ultima, y antes las de 2 columnas las pisaban. */
@media (min-width: 640px) {
    .grid-stats { grid-template-columns: repeat(4, 1fr); }
    .grid-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .grid-cards { grid-template-columns: repeat(3, 1fr); }
}

/* Tarjeta de viaje */
.trip-card {
    position: relative;
    display: block;
    min-height: 150px;
    padding: 16px;
    border-radius: var(--r-lg);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-sm);
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
}
.trip-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; }
.trip-card:active { transform: scale(.99); }
.trip-card .trip-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.trip-card .trip-total { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.trip-card .trip-name { font-size: 1.0625rem; font-weight: 700; margin-bottom: 3px; }
.trip-card .trip-meta { font-size: .75rem; color: var(--text-mute); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

/* Tarjeta con foto de portada: la imagen va de fondo y un velo oscuro
   garantiza que el texto se lea sea cual sea la foto. */
.trip-card.has-cover {
    background-size: cover;
    background-position: center;
    border-color: transparent;
    color: #fff;
}
.trip-card.has-cover::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(2, 6, 23, .25) 0%, rgba(2, 6, 23, .78) 100%);
    transition: background .2s var(--ease);
}
.trip-card.has-cover:hover::before {
    background: linear-gradient(180deg, rgba(2, 6, 23, .35) 0%, rgba(2, 6, 23, .85) 100%);
}
.trip-card.has-cover > * { position: relative; z-index: 1; }
.trip-card.has-cover .trip-name,
.trip-card.has-cover .trip-total { color: #fff; }
.trip-card.has-cover .trip-meta { color: rgba(255, 255, 255, .85); }
.trip-card.has-cover .cat { background: rgba(255, 255, 255, .22); color: #fff; }
.trip-card.has-cover .badge-pendiente {
    background: rgba(255, 255, 255, .2);
    color: #fff;
    border-color: transparent;
}

/* Selector de portada en el formulario de viaje */
.cover-picker {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 148px;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text-soft);
    text-align: center;
    overflow: hidden;
    transition: border-color .15s var(--ease), background .15s var(--ease);
}
.cover-picker:hover, .cover-picker.is-over { border-color: var(--accent); background: var(--accent-soft); }
.cover-picker img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cover-remove {
    position: absolute;
    top: 8px; right: 8px;
    z-index: 2;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: rgba(2, 6, 23, .6);
    color: #fff;
}
.cover-remove:hover { background: var(--red-600); }

/* Detalle de ticket */
.detail-img {
    width: 100%;
    max-height: 46vh;
    object-fit: contain;
    border-radius: var(--r-md);
    background: var(--surface-2);
    cursor: zoom-in;
}

.kv { display: flex; flex-direction: column; }
.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: .875rem;
}
.kv-row:last-child { border-bottom: none; }
.kv-key { color: var(--text-soft); flex: none; }
.kv-val { text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.kv-val.num { font-variant-numeric: tabular-nums; }

/* Selector de estado */
.status-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) { .status-picker { grid-template-columns: repeat(4, 1fr); } }

.status-opt {
    padding: 10px 6px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    font-size: .75rem;
    font-weight: 700;
    text-align: center;
    transition: all .15s var(--ease);
}
.status-opt[aria-pressed="true"].s-pendiente     { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-200); }
.status-opt[aria-pressed="true"].s-por_facturar  { background: var(--blue-50);  color: var(--blue-700);  border-color: var(--blue-200); }
.status-opt[aria-pressed="true"].s-facturado     { background: var(--green-50); color: var(--green-700); border-color: var(--green-200); }
.status-opt[aria-pressed="true"].s-no_facturable { background: var(--surface-3); color: var(--text); border-color: var(--border); }

/* Escaneo */
.drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 32px 20px;
    border: 2px dashed var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--text-soft);
    text-align: center;
    transition: border-color .15s var(--ease), background .15s var(--ease);
    width: 100%;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--text); font-size: .9375rem; }

.scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.review-card {
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    background: var(--surface);
    margin-bottom: 12px;
}
.review-head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-soft);
}
.review-thumb {
    width: 56px; height: 56px;
    flex: none;
    border-radius: var(--r-sm);
    object-fit: cover;
    background: var(--surface-3);
    cursor: zoom-in;
}
.review-body { padding: 12px; }

.group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-radius: var(--r-md) var(--r-md) 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--surface-2);
}
.group-new { background: var(--amber-50); border-color: var(--amber-200); }
.group-body {
    border: 1px solid var(--border);
    border-radius: 0 0 var(--r-md) var(--r-md);
    padding: 12px;
    background: var(--bg);
}

/* Camara */
.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: #000;
    display: flex;
    flex-direction: column;
}
.camera-view {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
}
.camera-view video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.camera-guide {
    position: absolute;
    inset: 12% 8%;
    border: 2px dashed rgba(255, 255, 255, .45);
    border-radius: var(--r-lg);
    pointer-events: none;
}
.camera-flash {
    position: absolute;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s var(--ease);
}
.camera-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
    background: #000;
    color: #fff;
}
.camera-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: #000;
    color: #fff;
}
.shutter {
    width: 68px; height: 68px;
    border-radius: var(--r-full);
    background: #fff;
    border: 4px solid rgba(255, 255, 255, .35);
    background-clip: padding-box;
    transition: transform .1s var(--ease);
}
.shutter:active { transform: scale(.92); }
.camera-thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; background: #000; }
.camera-thumbs img {
    width: 48px; height: 48px;
    object-fit: cover;
    border-radius: var(--r-xs);
    border: 2px solid rgba(255, 255, 255, .5);
}
.camera-thumb-wrap { position: relative; flex: none; }
.camera-thumb-del {
    position: absolute;
    top: -4px; right: -4px;
    width: 20px; height: 20px;
    border-radius: var(--r-full);
    background: var(--red-600);
    color: #fff;
    font-size: .75rem;
    line-height: 1;
    display: grid;
    place-items: center;
}

/* Visor de imagen a pantalla completa */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(2, 6, 23, .94);
    display: grid;
    place-items: center;
    padding: 20px;
    animation: fade-in .15s var(--ease);
}
.lightbox img {
    max-width: 100%;
    max-height: 88vh;
    object-fit: contain;
    border-radius: var(--r-sm);
}
.lightbox-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    width: var(--tap); height: var(--tap);
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: rgba(255, 255, 255, .14);
    color: #fff;
}

/* Cargando a pantalla completa */
.busy {
    position: fixed;
    inset: 0;
    z-index: 450;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    text-align: center;
    padding: 24px;
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .busy { background: var(--bg); }
}
.busy p { font-size: .875rem; color: var(--text-soft); max-width: 30ch; }

.spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--surface-3);
    border-top-color: var(--accent);
    border-radius: var(--r-full);
    animation: spin .7s linear infinite;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Barra de seleccion multiple */
.selbar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom));
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 8px 16px;
    border-radius: var(--r-full);
    background: var(--gray-900);
    color: #fff;
    box-shadow: var(--shadow-lg);
    width: calc(100% - 24px);
    max-width: 480px;
    animation: toast-in .2s var(--ease);
}
.selbar .count { font-size: .875rem; font-weight: 700; white-space: nowrap; }
.selbar .btn { background: rgba(255, 255, 255, .14); color: #fff; min-height: 36px; padding: 6px 12px; font-size: .8125rem; }
.selbar .btn:hover { background: rgba(255, 255, 255, .24); }
@media (min-width: 1024px) { .selbar { bottom: 24px; } }

/* Indicador de conexion */
.offline-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 350;
    padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
    background: var(--amber-600);
    color: #1c1917;
    font-size: .75rem;
    font-weight: 700;
    text-align: center;
}

/* ── 7. IMPRESION ──────────────────────────────────────────── */
@media print {
    .no-print, .tabbar, .topbar, .sidebar, .toast-stack { display: none !important; }

    body { background: #fff; color: #000; font-size: 11pt; }
    .main { padding: 0; max-width: none; }

    .report-table { width: 100%; border-collapse: collapse; }
    .report-table th, .report-table td {
        border: 1px solid #cbd5e1;
        padding: 5px 7px;
        text-align: left;
        font-size: 8.5pt;
    }
    .report-table thead { display: table-header-group; background: #f1f5f9; }
    .report-table tr { break-inside: avoid; }

    @page { margin: 14mm 10mm; size: A4 landscape; }
}

.report-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.report-table th, .report-table td {
    border: 1px solid var(--border);
    padding: 7px 9px;
    text-align: left;
}
.report-table th { background: var(--surface-2); font-weight: 700; font-size: .75rem; }
.report-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Accesibilidad ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

@media (prefers-contrast: more) {
    :root { --border: var(--gray-400); --border-soft: var(--gray-300); --text-soft: var(--gray-700); }
}
