/**
 * PreheatMail · El panel como aplicación (24-11-2026).
 *
 * Solo lo cargan las páginas del panel y del acceso (App::cabecera en includes/app.php); la web
 * pública no. Se carga al final del <head>, después de los <style> de cada página, para ganarles.
 *
 *  1. Zonas seguras y modo instalado (sin barra del navegador).
 *  2. Barra de abajo del móvil (4 destinos + «Más») y hojas que suben desde abajo.
 *  3. Cabeceras compactas, márgenes y botones al alcance del pulgar en cada pantalla del panel.
 *  4. Ventanas (modales) como hojas, botones flotantes dentro de «Más», avisos sobre la barra.
 *  5. Tablas como tarjetas (app.js pone a cada celda el nombre de su columna), esqueleto de carga.
 *  6. Transiciones entre pantallas (View Transitions) y respeto de «reducir movimiento».
 *
 * Por debajo de 1024 px el menú lateral se esconde (nordic.css): ahí manda la barra de abajo.
 * La zona de superadministrador conserva su menú de siempre (html.zona-admin, sin barra).
 */

:root {
    --app-pestanas-h: 64px;
    --app-pestanas-total: calc(var(--app-pestanas-h) + env(safe-area-inset-bottom, 0px));
    --app-curva: cubic-bezier(.2, .8, .2, 1);
    --app-hoja-fondo: rgba(7, 14, 26, 0.48);
}

/* ============================================================
   1. Zonas seguras y modo instalado
   ============================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
a, button, [role="button"], summary, label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* El menú lateral (ordenador y tableta) no se mete bajo la muesca en horizontal. */
.sidebar { padding-left: env(safe-area-inset-left, 0px); }
.sidebar-footer { padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px)); }

/* Instalada (sin barra del navegador): sin selección accidental en la navegación ni rebote de
   «tirar para recargar» encima de la barra de abajo. */
html.app-instalada .app-pestanas, html.app-instalada .sidebar-nav, html.app-instalada .app-hoja-cabeza { -webkit-user-select: none; user-select: none; }
@media (display-mode: standalone) {
    .app-pestanas, .sidebar-nav, .app-hoja-cabeza { -webkit-user-select: none; user-select: none; }
}
/* Lo de instalar no sale si ya se está dentro de la aplicación. */
html.app-instalada [data-app-instalar], html.app-instalada .app-aviso-instalar { display: none !important; }

/* ============================================================
   2. Barra de abajo y hojas
   ============================================================ */
.app-pestanas, .app-esqueleto { display: none; }

@media (max-width: 1023px) {
    /* --- Barra de abajo --- */
    html.con-pestanas .app-pestanas {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
        display: flex; align-items: stretch; justify-content: space-around;
        height: var(--app-pestanas-total);
        padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
        background: color-mix(in srgb, var(--bg-card) 90%, transparent);
        -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
        border-top: 1px solid var(--border-light);
        box-shadow: 0 -6px 24px rgba(20, 33, 58, 0.06);
        view-transition-name: app-pestanas;
    }
    .app-pestana {
        flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        padding: 6px 2px 4px; border: 0; background: none; cursor: pointer; text-decoration: none;
        color: var(--text-secondary); font: inherit;
    }
    .app-pestana:hover { color: var(--text-primary); }
    .app-pestana-ic {
        position: relative; display: flex; align-items: center; justify-content: center;
        width: 56px; height: 30px; border-radius: 999px; font-size: 23px; line-height: 1;
        transition: background-color .2s ease, transform .12s ease;
    }
    .app-pestana-ic .ph-fill { display: none; }
    .app-pestana-txt { max-width: 100%; font-size: 11.5px; line-height: 1.15; font-weight: 500; letter-spacing: -0.005em;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* «Prueba de spam» (Joan, 23-11-2026) es la etiqueta más larga: un poco más de sitio para que se lea
       entera a 360 px; «Más» y el resto se quedan con lo suyo. */
    .app-pestana[data-app-pestana="spam"] { flex-grow: 1.45; }
    @media (max-width: 345px) { .app-pestana[data-app-pestana="spam"] .app-pestana-txt { font-size: 10px; letter-spacing: -0.01em; } }
    .app-pestana.activa { color: var(--text-primary); }
    .app-pestana.activa .app-pestana-ic { background: var(--accent-subtle); color: var(--accent-hover); }
    .app-pestana.activa .app-pestana-ic .ph { display: none; }
    .app-pestana.activa .app-pestana-ic .ph-fill { display: inline-block; }
    .app-pestana.activa .app-pestana-txt { font-weight: 700; }
    .app-pestana:active .app-pestana-ic { transform: scale(.92); }
    .app-pestana:focus-visible { outline: none; }
    .app-pestana:focus-visible .app-pestana-ic { box-shadow: var(--focus-ring); }

    /* Con la barra, sobra el botón de menú de la esquina (el resto del menú está en «Más»). */
    html.con-pestanas .sidebar-mobile-trigger,
    html.con-pestanas .mobile-toggle { display: none !important; }
    html.con-pestanas .sidebar, html.con-pestanas .sidebar-overlay { display: none !important; }

    /* Nada queda debajo de la barra. */
    html.con-pestanas .main-content {
        padding: calc(14px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px))
                 calc(var(--app-pestanas-total) + 28px) calc(16px + env(safe-area-inset-left, 0px)) !important;
        margin-left: 0 !important;
        height: auto !important; min-height: 100vh; min-height: 100dvh;
        overflow: visible !important;
    }
    html.con-pestanas body { padding-bottom: 0; }
}

/* --- Hojas que suben desde abajo («Más», instalar) --- */
.app-hoja { position: fixed; inset: 0; z-index: 1200; display: flex; flex-direction: column; justify-content: flex-end; }
.app-hoja[hidden] { display: none; }
.app-hoja-fondo { position: absolute; inset: 0; background: var(--app-hoja-fondo); opacity: 0; transition: opacity .24s ease; }
.app-hoja-panel {
    position: relative; width: 100%; max-width: 560px; margin: 0 auto;
    max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0px));
    display: flex; flex-direction: column;
    background: var(--bg-primary); color: var(--text-primary);
    border-radius: 22px 22px 0 0; box-shadow: 0 -12px 40px rgba(7, 14, 26, 0.28);
    transform: translateY(104%); transition: transform .32s var(--app-curva);
    outline: none; overscroll-behavior: contain;
}
.app-hoja.abierta .app-hoja-fondo { opacity: 1; }
.app-hoja.abierta .app-hoja-panel { transform: translateY(0); }
.app-hoja.arrastrando .app-hoja-panel { transition: none; }
.app-hoja-asa { display: flex; justify-content: center; padding: 8px 0 2px; cursor: grab; touch-action: none; }
.app-hoja-asa span { width: 40px; height: 5px; border-radius: 3px; background: var(--border-control); opacity: .55; }
.app-hoja-cabeza { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 12px 6px 20px; touch-action: none; }
.app-hoja-cabeza h2 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.app-hoja-x {
    width: 44px; height: 44px; flex: 0 0 44px; display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 50%; background: var(--bg-hover); color: var(--text-secondary); font-size: 18px; cursor: pointer;
}
.app-hoja-x:hover { color: var(--text-primary); }
.app-hoja-cuerpo {
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding: 4px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}
html.app-hoja-abierta, html.app-hoja-abierta body { overflow: hidden !important; }

/* Filas agrupadas (como los ajustes de un teléfono). */
.app-grupo-t { margin: 18px 6px 6px; font-size: 13px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .04em; }
.app-grupo { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 16px; overflow: hidden; }
.app-grupo-fin { margin-top: 18px; }
.app-grupo > * + *, .app-grupo > .app-fila-form + *, .app-grupo > * + .app-fila-form { border-top: 1px solid var(--border-light); }
.app-grupo > [hidden] + *, .app-grupo > :first-child { border-top: 0; }
.app-fila-form { margin: 0; }
.app-fila {
    display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 8px 14px;
    border: 0; background: none; color: var(--text-primary); font: inherit; font-size: 16px; text-align: left; text-decoration: none; cursor: pointer;
}
.app-fila[hidden] { display: none; }
.app-fila:hover { background: var(--bg-hover); color: var(--text-primary); }
.app-fila:active { background: var(--bg-hover); }
.app-fila-ic {
    width: 36px; height: 36px; flex: 0 0 36px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; background: var(--bg-secondary); color: var(--accent); font-size: 19px;
}
.app-fila-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.app-fila-txt small { font-size: 13.5px; color: var(--text-secondary); margin-top: 1px; }
.app-fila-fin { color: var(--text-tertiary); font-size: 16px; flex: 0 0 auto; }
.app-fila.activa { color: var(--accent-hover); font-weight: 600; }
.app-fila.activa .app-fila-ic { background: var(--accent-subtle); color: var(--accent-hover); }
.app-fila-salir, .app-fila-salir .app-fila-ic { color: var(--error); }
.app-fila-salir .app-fila-ic { background: var(--error-light); }
.app-fila-instalar .app-fila-ic { background: var(--accent); color: var(--text-inverse); }

.app-yo {
    display: flex; align-items: center; gap: 14px; margin-top: 6px; padding: 12px 14px; min-height: 64px;
    background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 16px; color: var(--text-primary); text-decoration: none;
}
.app-yo:hover { color: var(--text-primary); background: var(--bg-hover); }
.app-yo-av { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-light); color: var(--accent-hover); font-weight: 700; font-size: 15px; }
.app-yo-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.app-yo-txt strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-yo-txt small { font-size: 13.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Hoja «Instalar la aplicación». */
.app-instalar-cabeza { display: flex; gap: 14px; align-items: flex-start; margin: 4px 2px 10px; }
.app-instalar-cabeza img { width: 64px; height: 64px; flex: 0 0 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(255, 138, 31, .28); }
.app-instalar-cabeza p { margin: 0; color: var(--text-secondary); font-size: 15.5px; line-height: 1.5; }
.app-hoja-instalar h3 { margin: 16px 2px 8px; font-size: 16px; font-weight: 700; }
.app-pasos { margin: 0; padding: 0; list-style: none; counter-reset: paso; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 16px; overflow: hidden; }
.app-pasos li { counter-increment: paso; position: relative; padding: 13px 14px 13px 56px; font-size: 15.5px; line-height: 1.45; min-height: 52px; }
.app-pasos li + li { border-top: 1px solid var(--border-light); }
.app-pasos li::before { content: counter(paso); position: absolute; left: 14px; top: 12px; width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; background: var(--accent-subtle); color: var(--accent-hover); font-weight: 700; font-size: 14px; }
.app-instalar-otro { margin: 14px 4px 0; color: var(--text-secondary); font-size: 14.5px; }
.app-instalar-hecha { display: flex; gap: 8px; align-items: center; margin: 8px 2px; padding: 12px 14px; border-radius: 12px;
    background: var(--success-light); color: var(--success); font-weight: 600; }
.app-instalar-ok { width: 100%; min-height: 50px; margin-top: 14px; justify-content: center; font-size: 16px; }
.app-instalar-ok + .app-instalar-ok { margin-top: 10px; }

/* Aviso discreto en el inicio (una sola vez; si se descarta, no vuelve a salir solo). */
.app-aviso-instalar { display: none; grid-template-columns: 44px minmax(0, 1fr) 40px; grid-template-areas: "img txt x" "img btn x"; column-gap: 12px; row-gap: 8px;
    align-items: start; margin: 0 0 14px; padding: 12px 6px 12px 14px;
    background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 16px; box-shadow: var(--shadow-sm); }
.app-aviso-instalar.visible { display: grid; }
.app-aviso-instalar > img { grid-area: img; }
.app-aviso-instalar > .txt { grid-area: txt; }
.app-aviso-instalar > .btn { grid-area: btn; justify-self: start; }
.app-aviso-instalar > .x { grid-area: x; margin-top: -6px; }
.app-aviso-instalar img { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 11px; }
.app-aviso-instalar .txt { flex: 1; min-width: 0; line-height: 1.35; }
.app-aviso-instalar strong { display: block; font-size: 15px; }
.app-aviso-instalar span { font-size: 13.5px; color: var(--text-secondary); }
.app-aviso-instalar .btn { min-height: 40px; padding: 0 14px; font-size: 14px; white-space: nowrap; }
.app-aviso-instalar .x { width: 40px; height: 40px; flex: 0 0 40px; border: 0; background: none; border-radius: 50%; color: var(--text-tertiary); font-size: 16px; cursor: pointer; }

/* ============================================================
   3. Cada pantalla del panel en el móvil: cabecera compacta, márgenes, toques de 44 px
   ============================================================ */
@media (max-width: 1023px) {
    /* Cabecera de cada pantalla: título y acción principal en una fila, sin el hueco del botón de menú. */
    html.con-pestanas .main-content > .d-head,
    html.con-pestanas .main-content > .page-header,
    html.con-pestanas .main-content > .sl-cabecera,
    html.con-pestanas .main-content > .st-head,
    html.con-pestanas .main-content > .act-head,
    html.con-pestanas .main-content > .pf-head,
    html.con-pestanas .main-content > .ws-head {
        display: flex !important; flex-wrap: wrap !important; align-items: center; justify-content: space-between;
        gap: 6px 12px; margin: 0 0 14px !important; padding: 0 !important; min-height: 44px;
    }
    html.con-pestanas .main-content > :is(.d-head, .page-header, .sl-cabecera, .act-head, .pf-head, .ws-head) > div:first-child { flex: 1 1 220px; min-width: 0; }
    /* Filtros de la cabecera (entregabilidad): a lo ancho, debajo del título. */
    html.con-pestanas .main-content > .page-header .page-actions:has(select) { flex: 1 1 100%; display: grid !important; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
    html.con-pestanas .main-content > .page-header .page-actions select { width: 100% !important; }
    html.con-pestanas .main-content :is(.d-head, .page-header, .sl-cabecera, .st-head, .act-head, .pf-head, .ws-head) h1 {
        font-size: 24px !important; line-height: 1.2 !important; font-weight: 700 !important; letter-spacing: -0.015em; margin: 0 !important; padding: 0 !important;
    }
    html.con-pestanas .main-content :is(.d-head .sub, .page-subtitle, .sl-sub, .act-head .sub, .pf-head .sub, .ws-head .sub) {
        font-size: 14px !important; line-height: 1.4; margin: 3px 0 0 !important; color: var(--text-secondary);
    }
    html.con-pestanas .main-content > .page-header .page-actions { margin: 0 !important; flex-wrap: wrap; }
    /* La acción principal, con 44 px. */
    html.con-pestanas .main-content > :is(.d-head, .page-header) .btn { min-height: 44px; padding: 0 16px; border-radius: 12px; font-size: 15px; }
    /* Textos de enlaces «Volver» como botón de atrás tocable. */
    html.con-pestanas .main-content :is(.sl-volver a, .detail-wrap > a.btn-ghost:first-child) { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }

    /* Todos los controles, a 16 px (el iPhone no hace zoom al tocar) y de 44 px de alto. */
    html.con-pestanas :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]), select, textarea),
    body.escena-acceso :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) { font-size: 16px !important; }
    html.con-pestanas :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]), select) { min-height: 44px; }
    html.con-pestanas .main-content .btn:not(.btn-sm) { min-height: 44px; }
    html.con-pestanas .main-content .btn-sm { min-height: 40px; }
}
@media (max-width: 420px) {
    /* En los anchos de teléfono, la acción principal de la cabecera es un botón redondo con su
       icono (el texto se queda para los lectores de pantalla). */
    html.con-pestanas .main-content > .d-head > a.btn-primary,
    html.con-pestanas .main-content > .page-header .page-actions > .btn-primary:only-child {
        font-size: 0 !important; width: 48px; min-width: 48px; height: 48px; min-height: 48px; padding: 0 !important; border-radius: 50%;
        justify-content: center; box-shadow: 0 4px 14px rgba(168, 76, 6, .28);
    }
    html.con-pestanas .main-content > .d-head > a.btn-primary i,
    html.con-pestanas .main-content > .page-header .page-actions > .btn-primary:only-child i { font-size: 22px; margin: 0; }
}

/* ============================================================
   4. Ventanas como hojas, botones flotantes y avisos
   ============================================================ */
@media (max-width: 1023px) {
    /* Ventanas del panel (Añadir buzón…): hoja que sube desde abajo, no un recuadro pequeño. */
    html.con-pestanas .modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
    html.con-pestanas .modal-backdrop .modal {
        position: relative !important; inset: auto !important; width: 100% !important; max-width: 560px !important; margin: 0 auto !important;
        height: auto !important; max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px)) !important;
        border-radius: 22px 22px 0 0 !important; display: flex; flex-direction: column;
        transform: translateY(100%) !important; transition: transform .32s var(--app-curva) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    html.con-pestanas .modal-backdrop.show .modal { transform: translateY(0) !important; }
    html.con-pestanas .modal-backdrop .modal::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; margin: 8px auto 0; background: var(--border-control); opacity: .55; flex: 0 0 auto; }
    html.con-pestanas .modal-backdrop .modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
    html.con-pestanas .modal-backdrop .modal-header { padding: 8px 12px 10px 20px; }
    html.con-pestanas .modal-backdrop .modal-close { width: 44px; height: 44px; border-radius: 50%; background: var(--bg-hover); }
    html.con-pestanas .modal-backdrop .modal-body { max-height: none !important; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
    html.con-pestanas .modal-backdrop .modal-footer { flex-wrap: nowrap; }
    html.con-pestanas .modal-backdrop .modal-footer .btn { flex: 1 1 0; min-height: 48px; justify-content: center; }

    /* «Reportar un problema»: también como hoja. */
    html.con-pestanas .fb-overlay { align-items: flex-end !important; padding: 0 !important; }
    html.con-pestanas .fb-modal { max-width: 560px !important; border-radius: 22px 22px 0 0 !important; max-height: calc(100dvh - 24px) !important; padding-bottom: env(safe-area-inset-bottom, 0px); }

    /* Los dos botones flotantes (chat y fallos) pasan a la hoja «Más»: no tapan nada. */
    html.con-pestanas .phm-sop-boton, html.con-pestanas .fb-toggle { display: none !important; }
    html.con-pestanas .phm-sop { bottom: 0 !important; right: 0 !important; }
    /* El chat de soporte, abierto desde «Más»: hoja a toda la pantalla (se cierra con su X). */
    html.con-pestanas .phm-sop-caja {
        position: fixed !important; left: 0 !important; right: 0 !important; width: auto !important; max-width: 560px !important; margin: 0 auto;
        top: calc(10px + env(safe-area-inset-top, 0px)) !important; bottom: 0 !important;
        height: auto !important; max-height: none !important; border-radius: 22px 22px 0 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 0px); box-shadow: 0 -12px 40px rgba(7, 14, 26, 0.3) !important;
    }
    html.con-pestanas .phm-sop-icono { width: 44px !important; height: 44px !important; }

    /* Avisos que se van solos: encima de la barra. */
    html.con-pestanas #toast-container { bottom: calc(var(--app-pestanas-total) + 10px) !important; top: auto !important; }
}

/* ============================================================
   5. Tablas como tarjetas y esqueleto de carga
   ============================================================ */
@media (max-width: 640px) {
    /* app.js marca las tablas que pasan a tarjetas (con cabecera y sin data-app-tabla="tal-cual"). */
    table.app-tarjetas, table.app-tarjetas tbody { display: block; width: 100%; min-width: 0 !important; }
    table.app-tarjetas thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    table.app-tarjetas tr { display: block; margin: 0 0 10px; padding: 10px 14px; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 14px; }
    table.app-tarjetas td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0 !important; border: 0 !important; text-align: right !important; font-size: 15px; min-width: 0; }
    table.app-tarjetas td + td { border-top: 1px solid var(--border-light) !important; }
    table.app-tarjetas td::before { content: attr(data-etiqueta); flex: 0 0 auto; max-width: 48%; text-align: left; color: var(--text-secondary); font-size: 13.5px; font-weight: 500; }
    table.app-tarjetas td[data-etiqueta=""]::before { content: none; }
    table.app-tarjetas td[data-etiqueta=""] { justify-content: flex-start; text-align: left !important; }
    /* La primera columna (nombre, correo, dominio) es el título de la tarjeta, sin etiqueta. */
    table.app-tarjetas td:first-child { display: block; text-align: left !important; font-weight: 600; font-size: 16px; padding: 2px 0 8px !important; }
    table.app-tarjetas td:first-child::before { content: none; }
    /* Quita el desplazamiento lateral que ponía theme.css a la caja de la tabla. */
    .table-responsive:has(> table.app-tarjetas) { overflow: visible !important; }
    .table-responsive > table.app-tarjetas { min-width: 0 !important; }
}

@media (max-width: 1023px) {
    /* Esqueleto: si una pantalla tarda en llegar tras tocar la barra, se ve su forma en vez de nada. */
    html.app-cargando .app-esqueleto {
        display: block; position: fixed; z-index: 850; left: 0; right: 0; top: 0; bottom: var(--app-pestanas-total);
        padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 16px; background: var(--bg-primary);
        animation: app-aparece .18s ease both;
    }
    .app-esqueleto i { display: block; border-radius: 14px; background: var(--bg-hover); position: relative; overflow: hidden; }
    .app-esqueleto i::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%);
        background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--bg-card) 70%, transparent), transparent);
        animation: app-brillo 1.2s ease-in-out infinite; }
    .app-esqueleto .t { width: 55%; height: 28px; margin: 8px 0 10px; border-radius: 8px; }
    .app-esqueleto .s { width: 75%; height: 14px; margin-bottom: 22px; border-radius: 6px; }
    .app-esqueleto .c { height: 112px; margin-bottom: 12px; }
    .app-esqueleto .c.alta { height: 200px; }
}
@keyframes app-brillo { to { transform: translateX(100%); } }
@keyframes app-aparece { from { opacity: 0; } to { opacity: 1; } }

/* Barra fina de carga arriba (también en ordenador e instalada): sale si la página tarda. */
.app-progreso { position: fixed; z-index: 3500; top: 0; left: 0; right: 0; height: 3px; pointer-events: none; opacity: 0; transition: opacity .2s ease; }
.app-progreso::before { content: ''; display: block; height: 100%; width: 40%; border-radius: 0 2px 2px 0; background: var(--accent);
    animation: app-progreso 1.1s var(--app-curva) infinite; }
html.app-cargando .app-progreso { opacity: 1; }
@keyframes app-progreso { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ============================================================
   6. Transiciones entre pantallas (navegador que las sepa hacer; si no, nada cambia)
   ============================================================ */
@media (max-width: 1023px) and (prefers-reduced-motion: no-preference) {
    @view-transition { navigation: auto; }
    ::view-transition-old(root) { animation: app-sale .16s ease both; }
    ::view-transition-new(root) { animation: app-entra .22s var(--app-curva) both; }
}
@media (display-mode: standalone) and (prefers-reduced-motion: no-preference) {
    @view-transition { navigation: auto; }
}
@keyframes app-sale { to { opacity: 0; } }
@keyframes app-entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
    .app-hoja-panel, .app-hoja-fondo, .app-pestana-ic,
    html.con-pestanas .modal-backdrop .modal { transition: none !important; }
    .app-esqueleto i::after, .app-progreso::before { animation: none !important; }
    .app-progreso::before { width: 100%; opacity: .6; }
}

/* Ajustes → «Aplicación» (settings.php). data-estado lo pone app.js: puede | instalada | otro. */
.app-ajustes { display: flex; gap: 14px; align-items: flex-start; }
.app-ajustes img { width: 52px; height: 52px; flex: 0 0 52px; border-radius: 12px; }
.app-ajustes p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; color: var(--text-secondary); }
.app-ajustes .app-ajustes-hecha { color: var(--success); font-weight: 600; display: none; }
.app-ajustes .app-ajustes-otro { display: none; }
[data-app-ajustes-instalar][data-estado="instalada"] .app-ajustes-hecha { display: block; }
[data-app-ajustes-instalar][data-estado="otro"] .app-ajustes-otro { display: block; }
.app-ajustes-boton { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }

/* Menú lateral: «Instalar la aplicación» como icono junto al nombre (no quita alto al menú). */
.sidebar-instalar { width: 36px; height: 36px; flex: 0 0 36px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); color: var(--accent); font-size: 18px; cursor: pointer; }
.sidebar-instalar[hidden] { display: none; }
.sidebar-instalar:hover { border-color: var(--accent); background: var(--accent-subtle); }

/* Lo escondido se queda escondido aunque su clase le dé otro «display» (.btn es inline-flex). */
[data-app-instalar][hidden], [data-app-instalar-sistema][hidden], .app-hoja [hidden], [data-app-ayuda][hidden] { display: none !important; }

/* ============================================================
   7. Pantalla a pantalla (móvil), tras mirar las capturas a 360, 390 y 430
   ============================================================ */
@media (max-width: 1023px) {
    /* Cabecera de las pantallas de salud, seguridad, planes y prueba de spam: en fila, a la izquierda. */
    html.con-pestanas .main-content > .sl-cabecera { flex-direction: row !important; align-items: flex-start; text-align: left; }
    /* «Volver» de las fichas: botón de atrás de 44 px. */
    html.con-pestanas .main-content > p.hz-nota:first-child a,
    html.con-pestanas .detail-wrap > a.btn-ghost:first-child { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; font-size: 15px; }
    html.con-pestanas .main-content > p.hz-nota:first-child { margin: -6px 0 2px !important; }

    /* Cifras en tarjetas de 2 × 2 (inicio y ficha del buzón): en fila se partían las palabras. */
    html.con-pestanas .stats-row { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px !important; overflow: visible !important; }
    html.con-pestanas .stats-row > * { min-width: 0; }
    html.con-pestanas .stats-row, html.con-pestanas .stats-row * { overflow-wrap: normal !important; word-break: normal !important; }
    html.con-pestanas .stat-box { padding: 14px 16px !important; }
    html.con-pestanas .stat-box .lbl { font-size: 13px !important; line-height: 1.3; }

    /* Formularios en fila (crear una llave de la API…): uno debajo de otro. */
    html.con-pestanas .main-content .form-row { display: grid !important; grid-template-columns: 1fr !important; gap: 12px !important; }
    html.con-pestanas .main-content .form-row > * { min-width: 0 !important; }
    html.con-pestanas .main-content .form-row .btn { width: 100%; min-height: 48px; justify-content: center; }

    /* Etiquetas de los campos legibles (algunas pantallas las tenían a 11 px). */
    html.con-pestanas .main-content .form-label { font-size: 14px !important; }
    html.con-pestanas .main-content .form-control { padding: 10px 12px; }
    html.con-pestanas .main-content .pf-card-head h3, html.con-pestanas .main-content .card-head h3 { font-size: 16px; }
    html.con-pestanas .main-content .pf-card-foot .btn, html.con-pestanas .main-content .card-body > form > .btn { min-height: 44px; }

    /* Actividad: filtros a lo ancho, con letra de verdad y botón de 44 px. */
    html.con-pestanas .filters { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px !important; padding: 10px !important; border-radius: 14px !important; }
    html.con-pestanas .filters select { width: 100%; min-width: 0 !important; min-height: 44px; font-size: 16px !important; padding: 0 10px !important; border-radius: 10px !important; }
    html.con-pestanas .filters select:first-child { grid-column: 1 / -1; }
    html.con-pestanas .filters .btn { grid-column: 1 / -1; min-height: 44px; font-size: 15px !important; justify-content: center; }

    /* Pestañas que se deslizan de lado (estadísticas): se ve que hay más. */
    html.con-pestanas :is(.tabs, .st-tabs, .config-tabs) { scroll-snap-type: x proximity; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }

    /* Mis buzones: el contenido de cada tarjeta usa todo el ancho (el icono queda a la izquierda del correo). */
    html.con-pestanas .card[id^="cuenta-"] > .flex.items-start { display: block !important; padding-right: 0 !important; }
    html.con-pestanas .card[id^="cuenta-"] > .flex.items-start > .email-avatar { float: left; width: 42px !important; height: 42px !important; margin: 0 12px 4px 0; }
    html.con-pestanas .card[id^="cuenta-"] > .flex.items-start > div:last-child > :first-child { padding-right: 44px; min-height: 42px; }
    html.con-pestanas .card[id^="cuenta-"] > .flex.items-start > div:last-child > :nth-child(n+2) { clear: left; }
    html.con-pestanas .card[id^="cuenta-"] .dropdown > .btn { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; }
}

/* Estados vacíos con la mascota (móvil): la lupa en vez del icono suelto. */
@media (max-width: 1023px) {
    html.con-pestanas :is(.chart-empty, .empty-full, .sl-vacio, .empty-box, .st-vacio, .empty-state-icon) > i:first-child {
        display: block; width: 96px; height: 104px; margin: 0 auto 8px; font-size: 0 !important;
        background: url('/assets/img/portada/mascota-lupa-160.webp') center / contain no-repeat;
    }
    html.con-pestanas :is(.chart-empty, .empty-full, .sl-vacio, .empty-box, .st-vacio, .empty-state-icon) > i:first-child::before { content: none !important; }
    html.con-pestanas .empty-state-icon { background: none !important; width: auto !important; height: auto !important; }
    /* Actividad sin nada: el texto a tamaño de lectura y sin el hueco enorme. */
    html.con-pestanas .empty-box { padding: 28px 16px; min-height: 0 !important; text-align: center; }
    html.con-pestanas .empty-box p { font-size: 15px !important; line-height: 1.5; }
    html.con-pestanas .table-wrap:has(> .empty-box) { min-height: 0 !important; height: auto !important; }
}

@media (max-width: 1023px) {
    /* Casillas y opciones con su texto al lado (theme.css hacía saltar el texto a otra línea) y de 44 px. */
    html.con-pestanas .main-content label:has(> input[type="radio"], > input[type="checkbox"]) {
        flex-wrap: nowrap !important; min-height: 44px; gap: 12px !important; font-size: 15px !important; line-height: 1.4;
    }
    html.con-pestanas .main-content label[style*="flex"]:has(> input[type="radio"], > input[type="checkbox"]) { align-items: center !important; }
    html.con-pestanas .main-content label > input:is([type="radio"], [type="checkbox"]):not(.toggle-input) { width: 20px; height: 20px; flex: 0 0 20px; margin: 0 !important; }
}

/* En ordenador, las hojas («Instalar la aplicación») son una ventana en el centro. */
@media (min-width: 1024px) {
    .app-hoja { justify-content: center; padding: 24px; }
    .app-hoja-panel { border-radius: 22px; max-height: min(86vh, 760px); transform: translateY(16px) scale(.98); opacity: 0;
        transition: transform .24s var(--app-curva), opacity .2s ease; }
    .app-hoja.abierta .app-hoja-panel { transform: none; opacity: 1; }
    .app-hoja-asa { display: none; }
    .app-hoja-cabeza { padding-top: 16px; }
}

/* Menú de «Ver la guía» lanzado desde «Más»: abajo, a lo ancho, encima de la barra. */
@media (max-width: 1023px) {
    html.con-pestanas .sw-guia-menu { left: 8px !important; right: 8px !important; top: auto !important; bottom: calc(var(--app-pestanas-total) + 8px) !important;
        width: auto !important; max-width: 560px; margin: 0 auto; border-radius: 18px; padding: 8px; }
}

/* En ordenador, el aviso del inicio no sale (el inicio de ordenador va a pantalla fija): ahí
   «Instalar» es el icono junto al nombre, en el menú, y el bloque de Ajustes. */
@media (min-width: 1024px) {
    .app-aviso-instalar.visible { display: none; }
}

/* Zona de superadministrador en el móvil: su menú de siempre (cajón de la izquierda), con toques de
   44 px, y el contenido no queda debajo de los dos botones flotantes. */
@media (max-width: 1023px) {
    html.zona-admin .sidebar-admin .nav-link { min-height: 44px; }
    html.zona-admin .main-content { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important; }
}

@media (max-width: 1023px) {
    /* Estadísticas de un buzón: el correo arriba a lo ancho y las cuatro cifras debajo, en fila. */
    html.con-pestanas .indiv-head { display: grid !important; grid-template-columns: 44px minmax(0, 1fr); gap: 10px 12px !important; padding: 14px !important; border-radius: 14px !important; }
    html.con-pestanas .indiv-head .email { font-size: 16px !important; overflow-wrap: anywhere; }
    html.con-pestanas .indiv-head .meta { font-size: 13.5px !important; }
    html.con-pestanas .indiv-head .stats { grid-column: 1 / -1; display: grid !important; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px !important;
        padding-top: 10px; border-top: 1px solid var(--border-light); }
    html.con-pestanas .indiv-head .stat, html.con-pestanas .indiv-head .stat * { overflow-wrap: normal !important; word-break: normal !important; }
    html.con-pestanas .indiv-head .stat .l { font-size: 12.5px !important; }
}

/* Nota de la prueba de 14 días dentro de «Más» (en el ordenador va al pie del menú). */
.app-nota { display: flex; gap: 8px; align-items: flex-start; margin: 12px 2px 0; padding: 10px 12px; border-radius: 12px;
    background: var(--bg-card); border: 1px solid var(--border-light); color: var(--text-secondary); font-size: 14px; line-height: 1.45; }
.app-nota i { color: var(--accent); margin-top: 2px; }

@media (max-width: 1023px) {
    /* Toques pequeños que quedaban (medidos en las capturas): primeros pasos, «Ver todo», accesos
       rápidos del inicio y «¿Qué significa cada cifra?» de Mis buzones. */
    html.con-pestanas .ob-action { display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px !important; }
    html.con-pestanas .act-card h3 a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; margin: -10px -4px; }
    html.con-pestanas .quick-links a { min-height: 44px; }
    html.con-pestanas .cifras-ayuda summary { min-height: 44px; }
}
