/* ==========================================================================
   APP STYLES - Solid Disco ERP & Facturación Electrónica
   Paleta: Slate (Superficie) + Indigo/Brand (Acento)
   ========================================================================== */

/* Inter servida desde el propio sitio (sin Google Fonts): fuente variable (todos los pesos, la app usa 400-800) en un
   solo woff2, subconjunto latin (@fontsource-variable/inter, ver assets/vendor/LICENSES.md). Tailwind la usa como
   font-sans; un carácter fuera del subconjunto se dibuja con la fuente del sistema. El ?v= es la versión del paquete:
   súbela al actualizar el woff2 para que el navegador no use la copia vieja.
   Inter 5.3.0 · Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) · SIL Open Font License 1.1
   (https://openfontlicense.org; texto completo en assets/vendor/inter/OFL.txt). */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('../vendor/inter/inter-latin-wght-normal.woff2?v=5.3.0') format('woff2');
}

/* Variables CSS para consistencia de tema */
:root {
    color-scheme: light;
    --color-surface-ground: #f8fafc;
    --color-surface-card: #ffffff;
    --color-surface-border: #e2e8f0;
    --color-text-main: #0f172a;
    --color-text-muted: #64748b;
    --color-brand-primary: #4f46e5;
}

html.dark,
.dark {
    color-scheme: dark;
    --color-surface-ground: #0f172a;
    --color-surface-card: #172033;
    --color-surface-border: #1e293b;
    --color-text-main: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-brand-primary: #6366f1;
}

/* Scrollbars modernos y discretos */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 9999px;
}

.dark ::-webkit-scrollbar-thumb {
    background: #475569;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Barras de desplazamiento finas en contenedores con scroll propio (listas, modales, menú lateral) */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.dark .custom-scrollbar {
    scrollbar-color: #475569 transparent;
}

/* Animación shimmer para Skeletons de carga */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-shimmer {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.dark .skeleton-shimmer {
    background: linear-gradient(90deg, #1e293b 25%, #334155 37%, #1e293b 63%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Fade in suave de elementos montados. backwards (no forwards): al terminar no queda ningún transform en el
   contenedor; si quedara, un hijo position:fixed (un diálogo con inset-0) se mediría contra él y no contra la ventana */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.animate-fade-in {
    animation: fadeIn 0.25s ease-out backwards;
}

/* Ajustes de foco accesibles */
.focus-ring {
    outline: 2px solid transparent;
    outline-offset: 2px;
}

.focus-ring:focus-visible {
    outline-color: var(--color-brand-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Foco visible por defecto para todo lo interactivo (WCAG 2.4.7). :where() no suma especificidad:
   cualquier estilo de foco propio (focus-ring, focus:ring-*, focus:border-*) sigue prevaleciendo. */
:where(a[href], button, summary, [role="button"], [role="tab"], [role="option"], [tabindex]:not([tabindex="-1"]), input[type="checkbox"], input[type="radio"]):focus-visible {
    outline: 2px solid var(--color-brand-primary);
    outline-offset: 2px;
}

/* Movimiento reducido (WCAG 2.3.3): sin animaciones ni transiciones si el sistema lo pide */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Pantallas de operación rápida en computadora (DESIGN.md §10.8.1): lista de líneas en la columna ancha. Dos líneas por
   artículo: nombre y total arriba; precio, código, existencias y cantidad abajo. «±10» solo si la lista mide 640 px o más. Las clases de
   Tailwind de estos elementos no tocan display (tailwind.css carga después y lo anularía) */
.line-list {
    container-type: inline-size;
}

.line-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name total" "meta qty";
    column-gap: 1rem;
    row-gap: 0.5rem;
    align-items: center;
}

.line-row + .line-row {
    border-top-width: 1px;
}

.line-name { grid-area: name; }
.line-total { grid-area: total; }
.line-meta { grid-area: meta; }
.line-qty { grid-area: qty; }

.line-step {
    display: none;
}

@container (min-width: 640px) {
    .line-step {
        display: inline-flex;
    }
}

/* Reportes impresos (raíz .print-report): carta horizontal, sin menú ni controles y la tabla con bordes finos a 7 pt
   (un reporte puede tener 20 columnas). Todo va acotado a las páginas que tienen un .print-report para no cambiar la
   impresión de otras pantallas. */
.print-report {
    page: print-report;
}

@page print-report {
    size: letter landscape;
    margin: 8mm 6mm 10mm 6mm;
}

@media print {
    body:has(.print-report) {
        background: #ffffff !important;
        color: #0f172a !important;
    }

    body:has(.print-report) header,
    body:has(.print-report) aside,
    body:has(.print-report) nav,
    body:has(.print-report) button,
    body:has(.print-report) input,
    body:has(.print-report) select {
        display: none !important;
    }

    body:has(.print-report) main {
        padding: 0 !important;
        max-width: none !important;
    }

    .print-report .print-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 7pt !important;
    }

    .print-report .print-table .text-xs {
        font-size: 7pt !important;
        line-height: 1.2 !important;
    }

    /* En papel no hay desplazamiento horizontal: el texto largo pasa a la línea siguiente en lugar de cortarse */
    .print-report .print-table th,
    .print-report .print-table td {
        border: 1px solid #cbd5e1 !important;
        padding: 1px 2px !important;
        white-space: normal !important;
        max-width: none !important;
        overflow: visible !important;
        text-overflow: clip !important;
        color: #0f172a !important;
    }

    /* Los códigos largos (número de control, identificadores) se cortan donde haga falta; los montos nunca */
    .print-report .print-table td.font-mono {
        overflow-wrap: anywhere;
    }

    .print-report .print-table td.text-right {
        white-space: nowrap !important;
    }

    /* En papel no hay desplazamiento: la tabla entera a la vista, sin recortes del contenedor */
    .print-report .overflow-x-auto,
    .print-report .overflow-hidden {
        overflow: visible !important;
    }

    /* Tipo y estado como texto: la pastilla de pantalla ocupa ancho que el papel no tiene */
    .print-report .print-table td span {
        white-space: normal !important;
        border: 0 !important;
        padding: 0 !important;
        background: none !important;
        font-weight: inherit !important;
    }

    .print-report .print-table th {
        background-color: #f1f5f9 !important;
        font-weight: 700 !important;
        text-transform: none !important;
        letter-spacing: normal !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-report .print-table tfoot td {
        background-color: #f8fafc !important;
        font-weight: 700 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-report .print-table thead {
        display: table-header-group;
    }

    .print-report .print-table tr {
        break-inside: avoid;
    }
}

/* Reportes anchos en pantalla: vista compacta (oculta columnas de referencia) y # + fecha fijos al desplazar.
   El impreso siempre lleva todas las columnas y sin posiciones fijas. */
@media screen {
    .report-compact .col-opt {
        display: none;
    }

    .report-sticky thead th:nth-child(-n + 2),
    .report-sticky tbody td:nth-child(-n + 2) {
        position: sticky;
        z-index: 1;
        background-color: var(--color-surface-card);
    }

    .report-sticky thead th:nth-child(-n + 2) {
        background-color: #f8fafc;
    }

    .dark .report-sticky thead th:nth-child(-n + 2) {
        background-color: #0f172a;
    }

    .report-sticky thead th:first-child,
    .report-sticky tbody td:first-child {
        left: 0;
        width: 4rem;
        min-width: 4rem;
        max-width: 4rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .report-sticky thead th:nth-child(2),
    .report-sticky tbody td:nth-child(2) {
        left: 4rem;
        box-shadow: inset -1px 0 0 var(--color-surface-border);
    }
}

/* ==========================================================================
   Modo oscuro de controles nativos (desplegables y campos del navegador)
   ========================================================================== */

/* Desplegables nativos en modo oscuro */
.dark select {
    background-color: #0f172a;
    color: #f8fafc;
}

.dark select option {
    background-color: #0f172a;
    color: #f8fafc;
}

/* Asegurar legibilidad en campos de texto en modo oscuro */
.dark input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="color"]),
.dark textarea {
    color: #f8fafc;
}

.dark input::placeholder,
.dark textarea::placeholder {
    color: #94a3b8;
}

/* Pantalla de carga con el logo, opcional (layouts/base.php, core/brandLoader.js). El logo tiene fondo transparente */
.brand-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ffffff;
    transition: opacity 250ms ease-out;
}

.brand-loader img {
    width: 96px;
    max-width: 40vw;
    height: auto;
    animation: brand-loader-pulse 1.4s ease-in-out infinite;
}

@keyframes brand-loader-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.94); }
}

.brand-loader--out {
    opacity: 0;
    pointer-events: none;
}

.dark .brand-loader {
    background-color: #0f172a;
}

@media (prefers-reduced-motion: reduce) {
    .brand-loader {
        transition: none;
    }

    .brand-loader img {
        animation: none;
    }
}
