/* =====================================================================================
   CSSFCWeb — sistema de diseño. Sin dependencias externas (CSP 'self').
   Reglas: SFC-Api/docs/tareas/web-componentes-comunes.md. Las pantallas NO llevan estilos propios:
   usan los componentes de Components/Shared y las clases de este archivo.

   Capas (cascade layers), de menor a mayor prioridad. Una capa posterior gana siempre, sin importar
   la especificidad, por eso las utilidades (última capa) siempre se aplican:
     tokens      variables: colores, temas, paletas, espacios, tipografía, puntos de quiebre
     base        elementos HTML sin clase (html, body, h1, input...) y animaciones
     layout      estructura de la app (menú, barra superior) y primitivas de maquetación
                 (.stack, .cluster, .split, .form-grid, .grid-2)
     components  piezas con nombre (.card, .btn, .table, .modal, .data-table, .filter-bar...)
     utilities   ajustes de una sola propiedad (.num, .text-muted, .mt-4, .center...)

   Marca: cambie solo --brand-* y --accent-*. Fondos y textos: --bg, --surface / --surface-2, --border,
   --text / --text-2 / --text-3. Modo claro en :root; oscuro en los bloques "Tema oscuro". Cada usuario
   elige tema y paleta en Mi perfil > Apariencia (atributos data-theme / data-palette en <html>).

   Diseño adaptable: intrínseco (auto-fit/minmax, flex-wrap, clamp, container queries). Los @media
   que quedan son de la estructura común; nunca se agregan @media para una pantalla concreta.
   ===================================================================================== */

@layer tokens, base, layout, components, utilities;

@layer tokens {
    :root {
        --brand-950: #052e1c;
        --brand-900: #0a3d27;
        --brand-800: #0f5132;
        --brand-700: #13663f;
        --brand-600: #178049;
        --brand-500: #1f9d5a;
        --brand-400: #46b97a;
        --brand-200: #b7e7cb;
        --brand-100: #dcf3e5;
        --brand-50: #f0faf4;

        --accent-700: #c2532a;
        --accent-600: #e0673a;
        --accent-500: #f2875a;
        --accent-400: #f6a27e;
        --accent-200: #fbd3c0;
        --accent-100: #fde8de;
        --accent-50: #fff5f0;

        --danger-600: #d23b3b;
        --danger-100: #fde2e2;
        --warning-600: #b7791f;
        --warning-100: #fdf0d5;
        --info-600: #2563eb;
        --info-100: #dfe9fd;

        --bg: #f3f6f4;
        --surface: #ffffff;
        --surface-2: #f8faf9;
        --border: #e2e8e4;
        --border-strong: #cdd6d0;
        --text: #17221c;
        --text-2: #4b5a51;
        --text-3: #7b8a81;

        --radius-sm: 8px;
        --radius: 12px;
        --radius-lg: 18px;
        --shadow-sm: 0 1px 2px rgba(10, 61, 39, .06);
        --shadow: 0 2px 6px rgba(10, 61, 39, .06), 0 10px 30px -12px rgba(10, 61, 39, .18);
        --shadow-lg: 0 30px 80px -20px rgba(5, 46, 28, .45);
        --focus: 0 0 0 3px color-mix(in srgb, var(--brand-500) 30%, transparent);
        /* Texto con el color de la marca (enlaces activos, chips, iconos): oscuro en tema claro, claro en tema oscuro. */
        --brand-text: var(--brand-700);

        --sidebar-w: 268px;
        --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
        --mono: "Cascadia Code", "JetBrains Mono", Consolas, "SFMono-Regular", Menlo, monospace;
        color-scheme: light;
    }

    /* -------------------------------------------------------------------------------------
       Paletas por usuario (Mi perfil > Apariencia). Atributo data-palette en <html>; "verde" = valores de :root.
       Solo cambian los tonos de la marca; los tonos claros (50-200) del tema oscuro se calculan abajo.
       ------------------------------------------------------------------------------------- */
    :root[data-palette="azul"] {
        --brand-950: #0b1f3f; --brand-900: #102a54; --brand-800: #163a72; --brand-700: #1d4b94; --brand-600: #245cb4;
        --brand-500: #2f72d6; --brand-400: #5b93e3; --brand-200: #bcd3f5; --brand-100: #dde8fa; --brand-50: #f1f6fd;
    }
    :root[data-palette="morado"] {
        --brand-950: #24103f; --brand-900: #311654; --brand-800: #421d71; --brand-700: #552592; --brand-600: #6a30b3;
        --brand-500: #8241d6; --brand-400: #a06de3; --brand-200: #d9c6f5; --brand-100: #ece2fa; --brand-50: #f7f2fd;
    }
    :root[data-palette="vino"] {
        --brand-950: #3a0a15; --brand-900: #4f0e1d; --brand-800: #6b1427; --brand-700: #8a1b33; --brand-600: #a82340;
        --brand-500: #c63150; --brand-400: #d9637b; --brand-200: #f2c2cc; --brand-100: #f9e1e6; --brand-50: #fdf2f4;
    }
    :root[data-palette="pizarra"] {
        --brand-950: #0f172a; --brand-900: #1e293b; --brand-800: #273449; --brand-700: #334155; --brand-600: #475569;
        --brand-500: #5b6b82; --brand-400: #8492a6; --brand-200: #cbd5e1; --brand-100: #e2e8f0; --brand-50: #f4f6f9;
    }
    :root[data-palette="naranja"] {
        --brand-950: #3d1a05; --brand-900: #552407; --brand-800: #74310a; --brand-700: #9a420c; --brand-600: #b9520f;
        --brand-500: #c95c10; --brand-400: #ea8a45; --brand-200: #f8d2b4; --brand-100: #fce8d8; --brand-50: #fef5ed;
    }

    /* -------------------------------------------------------------------------------------
       Tema oscuro: según el sistema (sin data-theme o data-theme="system") o elegido (data-theme="dark").
       data-theme="light" fuerza el tema claro aunque el sistema esté en oscuro.
       ------------------------------------------------------------------------------------- */
    @media (prefers-color-scheme: dark) {
        :root:not([data-theme="light"]) {
            --bg: #0c1511;
            --surface: #121e18;
            --surface-2: #17251e;
            --border: #23352b;
            --border-strong: #2f4639;
            --text: #e6efe9;
            --text-2: #a9bbb0;
            --text-3: #7d9185;
            --brand-50: color-mix(in srgb, var(--brand-500) 9%, var(--surface));
            --brand-100: color-mix(in srgb, var(--brand-500) 16%, var(--surface));
            --brand-200: color-mix(in srgb, var(--brand-500) 28%, var(--surface));
            --brand-text: color-mix(in srgb, var(--brand-400) 70%, #ffffff);
            --accent-50: #2a1910;
            --accent-100: #3a2116;
            --danger-100: #3a1717;
            --warning-100: #3a2c12;
            --info-100: #15233f;
            --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 10px 30px -12px rgba(0, 0, 0, .55);
            color-scheme: dark;
        }
    }
    :root[data-theme="dark"] {
        --bg: #0c1511;
        --surface: #121e18;
        --surface-2: #17251e;
        --border: #23352b;
        --border-strong: #2f4639;
        --text: #e6efe9;
        --text-2: #a9bbb0;
        --text-3: #7d9185;
        --brand-50: color-mix(in srgb, var(--brand-500) 9%, var(--surface));
        --brand-100: color-mix(in srgb, var(--brand-500) 16%, var(--surface));
        --brand-200: color-mix(in srgb, var(--brand-500) 28%, var(--surface));
        --brand-text: color-mix(in srgb, var(--brand-400) 70%, #ffffff);
        --accent-50: #2a1910;
        --accent-100: #3a2116;
        --danger-100: #3a1717;
        --warning-100: #3a2c12;
        --info-100: #15233f;
        --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 10px 30px -12px rgba(0, 0, 0, .55);
        color-scheme: dark;
    }

    /* Escalas del sistema de diseño. 1rem = 14.5px (tamaño base de html). */
    :root {
        /* Espacios: márgenes, rellenos y separaciones (clases .mt-N, .mb-N, .p-N, .gap-N usan esta escala). */
        --space-0: 0;
        --space-1: .25rem;
        --space-2: .5rem;
        --space-3: .75rem;
        --space-4: 1rem;
        --space-5: 1.25rem;
        --space-6: 1.5rem;
        --space-7: 2rem;
        --space-8: 3rem;

        /* Tamaños de letra (--fs-*: no confundir con --text-*, que son colores de texto). */
        --fs-xs: .8rem;
        --fs-sm: .85rem;
        --fs-md: 1rem;
        --fs-lg: 1.15rem;
        --fs-xl: 1.35rem;

        /* Maquetación intrínseca: anchos mínimos antes de pasar a la fila siguiente. */
        --field-min: 12rem;     /* campo de formulario (.form-grid, FormGrid) */
        --filter-min: 10rem;    /* campo de filtro (.filter-bar, FilterBar) */
        --form-gap: 14px;       /* separación horizontal entre campos */

        /* Puntos de quiebre de la estructura común (referencia: las variables no funcionan dentro de @media).
           640px móvil · 960px tablet (menú lateral oculto) · 1320px escritorio. */
        --bp-sm: 640px;
        --bp-md: 960px;
        --bp-lg: 1320px;
    }
}

@layer base {
    *, *::before, *::after { box-sizing: border-box; }

    html, body {
        margin: 0;
        background: var(--bg);
        color: var(--text);
        font-family: var(--font);
        font-size: 14.5px;
        line-height: 1.5;
        -webkit-font-smoothing: antialiased;
    }

    a { color: var(--brand-text); text-decoration: none; }
    a:hover { color: var(--brand-text); }
    h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
    h1 { font-size: 1.55rem; font-weight: 700; }
    h1:focus { outline: none; }
    h2 { font-size: 1.2rem; font-weight: 650; }
    h3 { font-size: 1rem; font-weight: 650; }
    p { margin: 0; }
    code, .mono { font-family: var(--mono); font-size: .92em; }

    input, select, textarea {
        width: 100%; font: inherit; color: var(--text); background: var(--surface);
        border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px;
        transition: border-color .15s, box-shadow .15s;
    }
    textarea { resize: vertical; }
    input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--focus); }
    input:disabled, select:disabled { background: var(--surface-2); color: var(--text-3); }
    input[type="checkbox"] { width: 17px; height: 17px; padding: 0; accent-color: var(--brand-600); cursor: pointer; flex: none; }
    select { padding-right: 28px; }
    /* Lista desplegable: colores explícitos para que siempre se lea (el select puede tener fondo transparente). */
    select option, select optgroup { background-color: var(--surface); color: var(--text); }
    select option:checked { background-color: var(--brand-600); color: #ffffff; }
    select option:disabled { color: var(--text-3); }

    /* ----------------------------------------------------------------- Animations */
    @keyframes spin { to { transform: rotate(360deg); } }
    @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
    @keyframes pop { from { opacity: 0; transform: translate(-50%, 8px) scale(.98); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
    @keyframes slide { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
    @keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
    @keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after { animation: none !important; transition: none !important; }
    }
}

@layer layout {
    /* ----------------------------------------------------------------- Layout */
    .shell { display: flex; min-height: 100vh; }

    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
        display: flex; flex-direction: column;
        background:
            radial-gradient(120% 60% at 0% 0%, rgba(242, 135, 90, .18), transparent 55%),
            linear-gradient(180deg, var(--brand-800) 0%, var(--brand-900) 55%, var(--brand-950) 100%);
        color: #e7f5ec;
        transition: transform .25s ease;
    }

    .brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; color: #fff; }
    .brand:hover { color: #fff; }
    .brand-logo { width: 42px; height: 42px; border-radius: 12px; background: rgba(255, 255, 255, .1); padding: 5px; }
    .brand-text { display: flex; flex-direction: column; }
    .brand-text strong { font-size: 1.05rem; letter-spacing: .01em; }
    .brand-text small { color: var(--accent-400); font-weight: 600; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; }

    .nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
    .nav-group { margin-top: 14px; }
    .nav-group-title { display: block; padding: 0 12px 6px; font-size: .7rem; letter-spacing: .09em; text-transform: uppercase; color: rgba(231, 245, 236, .5); font-weight: 650; }
    .nav-item {
        position: relative; display: flex; align-items: center; gap: 12px;
        padding: 9px 12px; margin: 2px 0; border-radius: 10px;
        color: rgba(231, 245, 236, .82); font-weight: 520;
        transition: background .15s, color .15s;
    }
    .nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
    .nav-item.active { background: rgba(255, 255, 255, .12); color: #fff; }
    .nav-item.active::before {
        content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
        border-radius: 0 4px 4px 0; background: var(--accent-500);
    }
    .nav-item.active .icon { color: var(--accent-400); }

    .sidebar-footer { padding: 14px 20px 20px; }
    .env-pill { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-size: .78rem; color: rgba(231, 245, 236, .8); }
    .env-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-400); box-shadow: 0 0 0 3px rgba(70, 185, 122, .25); }

    .sidebar-scrim { display: none; }

    .main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

    .topbar {
        position: sticky; top: 0; z-index: 30; height: 64px;
        display: flex; align-items: center; gap: 14px; padding: 0 28px;
        background: color-mix(in srgb, var(--surface) 86%, transparent);
        backdrop-filter: saturate(160%) blur(10px);
        border-bottom: 1px solid var(--border);
    }
    .topbar-spacer { flex: 1; }
    .menu-toggle { display: none; }

    .company-switch {
        display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 6px;
        border: 1px solid var(--border); border-radius: 999px; background: var(--surface); min-width: 0;
    }
    .company-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-100); color: var(--brand-text); }
    .company-switch select { border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--text); padding: 4px 26px 4px 2px; max-width: 360px; box-shadow: none; }
    .company-switch select { min-width: 0; text-overflow: ellipsis; }
    .company-switch select + select { border-left: 1px solid var(--border); border-radius: 0; padding-left: 8px; }
    .company-switch:focus-within { box-shadow: var(--focus); }
    .company-name { font-weight: 600; padding-right: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .company-name small { color: var(--text-3); font-family: var(--mono); margin-left: 6px; font-weight: 500; }

    .user-menu { position: relative; }
    .user-chip { display: flex; align-items: center; gap: 10px; background: transparent; border: 0; padding: 4px 6px; border-radius: 999px; cursor: pointer; color: var(--text); font: inherit; }
    .user-chip:hover { background: var(--surface-2); }
    .user-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
    .user-text small { color: var(--text-3); font-size: .76rem; }
    .dropdown-backdrop { position: fixed; inset: 0; z-index: 45; background: transparent; cursor: default; }
    .dropdown {
        position: absolute; right: 0; top: calc(100% + 8px); z-index: 46; min-width: 210px; padding: 6px;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
        animation: fade .14s ease-out;
    }
    .dropdown a, .dropdown button {
        display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 8px;
        color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
    }
    .dropdown button.danger { color: var(--danger-600); }
    .dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }
    .dropdown form { margin: 0; }

    .content { padding: 28px; max-width: 1480px; width: 100%; margin: 0 auto; }

    /* ----------------------------------------------------------------- Primitivas de maquetación
       Se adaptan solas al ancho disponible (no al de la ventana): sirven igual en una página, una tarjeta
       o un modal. Ajuste fino con variables en el contenedor, nunca con @media por pantalla. */

    /* Pila vertical con separación uniforme. --stack-gap para cambiarla. */
    .stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-4)); }
    .stack > * { margin-block: 0; }

    /* Fila que se parte en varias líneas (botones, chips, filtros). --cluster-gap para cambiarla. */
    .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-3)); }
    .cluster-between { justify-content: space-between; }
    .cluster-end { justify-content: flex-end; }

    /* Barra lateral + contenido: lado a lado si caben (--split-side y 60% del contenido), si no, apilados. */
    .split { display: flex; flex-wrap: wrap; gap: var(--split-gap, var(--space-5)); align-items: flex-start; }
    .split > :first-child { flex: 1 1 var(--split-side, 20rem); }
    .split > :last-child { flex: 999 1 0; min-inline-size: 60%; }

    /* Formularios: hasta --form-cols columnas de al menos --field-min; con menos espacio bajan solas a menos
       columnas (sin @media). .form-grid = 2, .form-grid-3 = 3, .form-grid-4 = 4. */
    .form-grid, .form-grid-3, .form-grid-4 {
        --form-cols: 2;
        display: grid;
        gap: 0 var(--form-gap);
        grid-template-columns: repeat(auto-fit, minmax(min(100%, max(var(--field-min), (100% - (var(--form-cols) - 1) * var(--form-gap)) / var(--form-cols))), 1fr));
    }
    .form-grid-3 { --form-cols: 3; align-items: end; }
    .form-grid-4 { --form-cols: 4; align-items: end; }
    /* Ocupa la fila completa (en .form-grid de 2 columnas equivale a 2 columnas). */
    .span-full { grid-column: 1 / -1; }

    /* Dos tarjetas o bloques lado a lado; en tablet y móvil, uno debajo del otro. */
    .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
    .grid-2 > .card + .card { margin-top: 0; }

    /* Rejilla intrínseca de métricas o fichas informativas. */
    .metric-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--metric-min, 150px)), 1fr));
        gap: var(--metric-gap, var(--space-3));
    }
    .metric-grid-wide { --metric-min: 220px; --metric-gap: var(--space-6); }
}

@layer components {
    .avatar {
        display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%;
        background: linear-gradient(135deg, var(--accent-500), var(--accent-600)); color: #fff;
        font-weight: 700; font-size: .82rem; letter-spacing: .02em;
    }

    /* ----------------------------------------------------------------- Page */
    .page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; flex-wrap: wrap; }
    .page-title { display: flex; align-items: center; gap: 14px; }
    .page-title p { margin-top: 4px; }
    .page-icon {
        display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px;
        background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; box-shadow: 0 8px 18px -8px var(--brand-600);
    }
    .page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

    .card {
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm); padding: 20px; min-width: 0;
    }
    .card + .card { margin-top: 18px; }
    .card.narrow { max-width: 520px; }
    .card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
    .card-header p { margin-top: 4px; }
    .summary-box { background: var(--surface-2); padding: var(--space-4); border-radius: var(--radius); }
    .metric-tile { background: var(--surface-2); padding: var(--space-3); border-radius: var(--radius); }
    .metric-value { font-size: var(--fs-lg); font-weight: 700; }
    .total-banner {
        display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-2);
        padding: var(--space-3) var(--space-4); border-radius: var(--radius);
        background: var(--brand-50); border: 1px solid var(--brand-200);
    }
    .total-banner strong:last-child { font-size: var(--fs-xl); color: var(--brand-text); }
    .total-banner-strong { border-width: 2px; border-color: var(--brand-500); border-radius: var(--radius-sm); font-size: 1.25rem; font-weight: 800; color: var(--brand-text); }
    .report-sheet { max-width: 600px; margin: 0 auto; background: var(--surface-2); padding: var(--space-6); border-radius: var(--radius); }
    .line-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: 8px 0; border-bottom: 1px solid var(--border); }
    .line-row-subtotal { border-bottom: 2px solid var(--border-strong); font-weight: 700; background: var(--surface); }
    .summary-strip { padding: var(--space-4) var(--space-5); background: var(--surface-2); display: flex; gap: var(--space-7); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
    .summary-strip-value { font-size: 1.2rem; font-weight: 700; }
    .cash-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }

    /* ----------------------------------------------------------------- Buttons */
    .btn {
        display: inline-flex; align-items: center; justify-content: center; gap: 8px;
        padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
        font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
        transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
    }
    .btn:active { transform: translateY(1px); }
    .btn:focus-visible, .btn-icon:focus-visible { outline: none; box-shadow: var(--focus); }
    .btn:disabled { opacity: .55; cursor: not-allowed; }
    .btn-primary { background: linear-gradient(180deg, var(--brand-500), var(--brand-600)); color: #fff; box-shadow: 0 6px 14px -8px var(--brand-600); }
    .btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, var(--brand-600), var(--brand-700)); color: #fff; }
    .btn-accent { background: linear-gradient(180deg, var(--accent-500), var(--accent-600)); color: #fff; box-shadow: 0 6px 14px -8px var(--accent-600); }
    .btn-accent:hover:not(:disabled) { background: var(--accent-700); color: #fff; }
    .btn-danger { background: var(--danger-600); color: #fff; }
    .btn-danger:hover:not(:disabled) { filter: brightness(.92); color: #fff; }
    .btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
    .btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
    .btn-soft { background: var(--brand-100); color: var(--brand-text); }
    .btn-soft:hover:not(:disabled) { background: var(--brand-200); color: var(--brand-text); }
    .btn-secondary { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
    .btn-secondary:hover:not(:disabled) { background: var(--border); border-color: var(--border-strong); color: var(--text); }
    .btn-sm { padding: 6px 11px; font-size: .86rem; border-radius: 8px; }
    .btn-lg { padding: 12px 20px; font-size: 1rem; }
    .btn-block { width: 100%; }

    .btn-icon {
        display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
        border: 0; background: transparent; color: var(--text-2); cursor: pointer;
    }
    .btn-icon:hover:not(:disabled) { background: var(--surface-2); color: var(--brand-text); }
    .btn-icon:disabled { opacity: .35; cursor: not-allowed; }

    /* ----------------------------------------------------------------- Forms */
    .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
    .field > span { font-size: .82rem; font-weight: 600; color: var(--text-2); }

    .input-icon { position: relative; display: flex; align-items: center; }
    .input-icon .icon { position: absolute; left: 12px; color: var(--text-3); pointer-events: none; }
    .input-icon input { padding-left: 38px; }

    .check { display: flex; align-items: center; gap: 10px; margin: 4px 0 18px; color: var(--text-2); cursor: pointer; }
    .form-grid > .check, .form-grid-3 > .check, .form-grid-4 > .check { align-self: end; margin: 0 0 14px; min-height: 38px; }

    .validation-message { color: var(--danger-600); font-size: .82rem; }
    .invalid { border-color: var(--danger-600) !important; }

    .segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
    .segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--text-2); cursor: pointer; }
    .segmented button.active { background: var(--surface); color: var(--brand-text); box-shadow: var(--shadow-sm); }

    /* ----------------------------------------------------------------- Tables */
    .table { width: 100%; border-collapse: separate; border-spacing: 0; }
    .table th {
        text-align: left; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3);
        font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
    }
    .table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
    .table tbody tr { transition: background .12s; }
    .table tbody tr:hover { background: var(--brand-50); }
    .table-click tbody tr { cursor: pointer; }
    .table .actions { text-align: right; white-space: nowrap; width: 1%; }
    .table .actions > * { margin-left: 2px; }
    .table td.num { white-space: nowrap; }
    .table-compact th, .table-compact td { padding: 8px 6px; font-size: .86rem; }
    .table-compact td { white-space: normal; word-break: break-word; }
    .table-compact td.num, .table-compact td.actions { white-space: nowrap; }
    .input-qty { width: 88px; min-width: 72px; text-align: right; }
    .row-muted td { opacity: .62; }
    .row-danger td { background: var(--danger-100); }

    .pager { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; gap: 10px; flex-wrap: wrap; }
    .pager-buttons { display: flex; align-items: center; gap: 6px; }
    .pager-page { font-weight: 600; color: var(--text-2); font-size: .9rem; }

    /* ----------------------------------------------------------------- Badges, alerts */
    .badge {
        display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
        font-size: .78rem; font-weight: 650; white-space: nowrap; line-height: 1.5; align-self: flex-start;
    }
    .badge + .badge { margin-left: 4px; }
    .badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
    .badge-success { background: var(--brand-100); color: var(--brand-text); }
    .badge-danger { background: var(--danger-100); color: var(--danger-600); }
    .badge-warning { background: var(--accent-100); color: var(--accent-700); }
    .badge-info { background: var(--info-100); color: var(--info-600); }
    .badge-neutral { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
    .badge-accent { background: var(--accent-100); color: var(--accent-700); }

    .alert { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: .92rem; }
    .alert .icon { flex: none; }
    .alert-danger { background: var(--danger-100); color: var(--danger-600); }
    .alert-warning { background: var(--accent-100); color: var(--accent-700); }
    .alert-success { background: var(--brand-100); color: var(--brand-text); }
    .alert-info { background: var(--info-100); color: var(--info-600); }
    .alert-list { margin: var(--space-2) 0 0; padding-left: var(--space-5); font-size: var(--fs-sm); }
    /* CloneNoticeList: avisos de una copia arriba del formulario de "Nuevo". */
    /* Asignaciones (roles, compañías, sucursales, permisos directos): AssignmentChip */
.chip-list { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 4px 3px 10px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: .88rem;
}
.chip-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip-meta { color: var(--text-3); white-space: nowrap; }
.chip-default { border-color: var(--brand-500); }
.chip-inactive { background: var(--surface-2); }
.chip-inactive .chip-label { color: var(--text-3); text-decoration: line-through; }
.chip .badge + .badge { margin-left: 0; }
.chip-btn {
    display: inline-grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%;
    background: transparent; color: var(--text-3); cursor: pointer;
}
.chip-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.chip-btn:focus-visible { box-shadow: var(--focus); outline: none; }
.chip-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Contenido desplazable de un modal grande (modal-xl no desplaza su cuerpo) */
.modal-pane { padding: 8px 22px 6px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-pane > * { flex-shrink: 0; }

/* Editor de permisos: PermissionMatrix (celdas de tres estados con icono y texto) */
.perm-node { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding-left: calc(var(--depth, 0) * 1.1rem); min-width: 12rem; }
.perm-apply { display: inline-flex; align-items: center; gap: 2px; }
.perm-cell-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.perm-cell-actions { display: inline-flex; gap: 2px; }
.perm-cell-actions:empty { display: none; }
.perm-cell-actions > .chip-btn { width: 20px; height: 20px; }
.perm-cell {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-3); font: inherit; font-size: .8rem; white-space: nowrap; cursor: default;
}
button.perm-cell { cursor: pointer; }
button.perm-cell:hover:not(:disabled) { border-color: var(--text-3); }
button.perm-cell:focus-visible { box-shadow: var(--focus); outline: none; }
.perm-allow { background: var(--brand-100); color: var(--brand-text); border-color: transparent; }
.perm-deny { background: var(--danger-100); color: var(--danger-600); border-color: transparent; }
.perm-inactive { opacity: .55; text-decoration: line-through; }
.perm-note { color: var(--text-3); font-size: .72rem; max-width: 12rem; text-align: center; }
.perm-specials { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
.perm-special { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.perm-special > small { color: var(--text-3); }

.clone-notices { align-items: flex-start; }
    .clone-notices-body { --stack-gap: var(--space-1); min-width: 0; }
    .clone-notices .alert-list { margin-top: 0; }

    .section-kicker { font-size: var(--fs-sm); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); margin-bottom: var(--space-3); }
    .option-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--space-3); }
    .option-btn { justify-content: flex-start; text-align: left; padding: var(--space-3) var(--space-4); border-color: var(--border); }
    .option-btn.btn-primary { border-color: var(--brand-500); }
    .option-sub { font-size: var(--fs-xs); font-weight: 400; opacity: .85; }

    /* ----------------------------------------------------------------- KPI & dashboard */
    .kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
    .kpi {
        position: relative; overflow: hidden; display: flex; gap: 14px; align-items: flex-start;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
        padding: 18px; box-shadow: var(--shadow-sm); min-height: 112px;
    }
    .kpi::after { content: ""; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; opacity: .5; }
    .kpi-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; flex: none; }
    .kpi-body { display: flex; flex-direction: column; min-width: 0; z-index: 1; }
    .kpi-label { color: var(--text-2); font-weight: 600; font-size: .86rem; }
    .kpi-value { font-size: clamp(1.25rem, 1.45vw, 1.75rem); font-weight: 750; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; overflow-wrap: anywhere; }
    .kpi-hint { color: var(--text-3); font-size: .8rem; margin-top: 2px; }
    .kpi-brand .kpi-icon { background: var(--brand-100); color: var(--brand-text); }
    .kpi-brand::after { background: var(--brand-50); }
    .kpi-accent .kpi-icon { background: var(--accent-100); color: var(--accent-700); }
    .kpi-accent::after { background: var(--accent-50); }
    .kpi-danger .kpi-icon { background: var(--danger-100); color: var(--danger-600); }
    .kpi-danger::after { background: var(--danger-100); }
    .kpi-info .kpi-icon { background: var(--info-100); color: var(--info-600); }
    .kpi-info::after { background: var(--info-100); }

    .chart svg { width: 100%; height: 220px; display: block; }
    .chart-grid { stroke: var(--border); stroke-width: 1; }
    .chart-bar-ok { fill: var(--brand-500); }
    .chart-labels { display: flex; justify-content: space-around; color: var(--text-3); font-size: .74rem; margin-top: 6px; }
    .chart-legend { display: flex; gap: 18px; margin-top: 12px; color: var(--text-2); font-size: .84rem; }
    .chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
    .legend-ok { background: var(--brand-500); }

    .tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
    .tabs button { border: 0; background: none; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
    .tabs button.active { color: var(--brand-text); border-bottom-color: var(--accent-500); }

    /* ----------------------------------------------------------------- Modal, confirm, toasts */
    .modal-backdrop { position: fixed; inset: 0; background: rgba(5, 25, 16, .45); backdrop-filter: blur(3px); z-index: 70; }
    .modal-backdrop.modal-top-backdrop { z-index: 80; }
    .modal {
        position: fixed; left: 50%; top: 8vh; transform: translateX(-50%); z-index: 71; width: calc(100% - 32px);
        max-height: 84vh; display: flex; flex-direction: column;
        background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .18s ease-out;
    }
    .modal.modal-top { z-index: 81; }
    .modal-sm { max-width: 440px; }
    .modal-md { max-width: 580px; }
    .modal-lg { max-width: 760px; }
    .modal-xl { max-width: 1120px; width: 95vw; height: 92vh; max-height: 92vh; top: 4vh; }
    .modal-xl .modal-body { padding: 0; overflow: hidden; flex: 1; display: flex; flex-direction: column; min-height: 0; }
    .modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 22px 12px; }
    .modal-header p { margin-top: 4px; font-size: .9rem; }
    .modal-body { padding: 8px 22px 6px; overflow-y: auto; }
    .modal-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; border-top: 1px solid var(--border); margin-top: 8px; }

    .confirm { display: flex; gap: 14px; align-items: flex-start; }
    .confirm-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--info-100); color: var(--info-600); flex: none; }
    .confirm-icon.danger { background: var(--danger-100); color: var(--danger-600); }

    .toasts { position: fixed; right: 20px; top: 78px; z-index: 90; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100% - 40px)); pointer-events: none; }
    body:has(.modal) .toasts { top: auto; bottom: 16px; flex-direction: column-reverse; }
    .toast {
        display: flex; gap: 12px; align-items: flex-start; padding: 14px 14px 14px 16px; border-radius: var(--radius);
        background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: slide-in .2s ease-out;
        border-left: 4px solid var(--brand-500); pointer-events: auto;
    }
    .toast-text { display: flex; flex-direction: column; flex: 1; gap: 2px; font-size: .9rem; }
    .toast-text span { color: var(--text-2); }
    .toast-success { border-left-color: var(--brand-500); }
    .toast-success > .icon { color: var(--brand-text); }
    .toast-error { border-left-color: var(--danger-600); }
    .toast-error > .icon { color: var(--danger-600); }
    .toast-warning { border-left-color: var(--accent-500); }
    .toast-warning > .icon { color: var(--accent-600); }
    .toast-info { border-left-color: var(--info-600); }
    .toast-info > .icon { color: var(--info-600); }

    /* ----------------------------------------------------------------- Empty, loading */
    .empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 20px; }
    .empty-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--brand-100); color: var(--brand-text); margin-bottom: 6px; }
    .empty .btn, .empty code { margin-top: 10px; }
    .boot { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 60px; color: var(--text-3); }

    .spinner { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--brand-200); border-top-color: var(--brand-600); animation: spin .7s linear infinite; }
    .spinner-sm { width: 15px; height: 15px; border-width: 2px; }
    .btn-primary .spinner, .btn-accent .spinner { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }

    /* ----------------------------------------------------------------- Login */
    .login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
    .login-brand {
        position: relative; overflow: hidden; display: flex; align-items: center; padding: 64px;
        background: linear-gradient(160deg, var(--brand-600) 0%, var(--brand-800) 45%, var(--brand-950) 100%);
        color: #eaf7ef;
    }
    .login-shapes i { position: absolute; border-radius: 50%; }
    .login-shapes i:nth-child(1) {
        width: 440px; height: 440px; right: -170px; bottom: -190px;
        background: linear-gradient(135deg, var(--accent-400), var(--accent-600)); box-shadow: 0 0 120px rgba(242, 135, 90, .35);
    }
    .login-shapes i:nth-child(2) { width: 240px; height: 240px; left: -80px; top: -80px; border: 36px solid rgba(255, 255, 255, .07); }
    .login-shapes i:nth-child(3) { width: 70px; height: 70px; right: 26%; top: 14%; background: var(--accent-500); opacity: .85; }
    .login-brand-content { position: relative; max-width: 480px; }
    .login-logo { width: 74px; height: 74px; border-radius: 20px; background: rgba(255, 255, 255, .12); padding: 8px; margin-bottom: 26px; }
    .login-brand h1 { font-size: 2.3rem; color: #fff; margin-bottom: 14px; }
    .login-brand p { color: rgba(234, 247, 239, .82); font-size: 1.05rem; }
    .login-features { list-style: none; padding: 0; margin: 30px 0 0; display: flex; flex-direction: column; gap: 14px; }
    .login-features li { display: flex; align-items: center; gap: 12px; font-weight: 550; }
    .login-features .icon { display: grid; padding: 7px; width: 34px; height: 34px; border-radius: 10px; background: rgba(255, 255, 255, .1); color: var(--accent-400); }
    .login-panel { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
    .login-card { width: 100%; max-width: 410px; background: var(--surface); padding: 36px 34px; border-radius: 22px; box-shadow: var(--shadow); border: 1px solid var(--border); }
    .login-card h2 { font-size: 1.6rem; margin-bottom: 6px; }
    .login-card > p { margin-bottom: 24px; }
    .login-foot { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; font-size: .8rem; }


    /* ----------------------------------------------------------------- Responsive */
    @media (max-width: 1320px) {
        .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    }

    @media (max-width: 960px) {
        .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s; }
        .menu-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform .25s ease; }
        .menu-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(5, 25, 16, .4); }
        .main { margin-left: 0; }
        .menu-toggle { display: inline-grid; }
        .topbar { padding: 0 14px; }
        .content { padding: 18px 14px; }
        .grid-2 { grid-template-columns: 1fr; }
        .user-text { display: none; }
        .company-switch select { max-width: 52vw; }
        .login { grid-template-columns: 1fr; }
        .login-brand { display: none; }
    }

    @media (max-width: 640px) {
        .topbar { gap: 8px; padding: 0 10px; }
        .topbar-pos-btn span { display: none; }
        .company-switch { max-width: calc(100vw - 170px); }
        .company-switch:has(select + select) select { max-width: 30vw; }
        .company-name { padding-right: 8px; font-size: .88rem; }
        .kpi-grid { grid-template-columns: 1fr; }
    }

    /* Apariencia (Mi perfil): selector de paleta con muestra de color. */
    .appearance-block + .appearance-block { margin-top: 18px; }
    .appearance-block h4 { margin: 0 0 8px; font-size: .9rem; color: var(--text-2); }
    .palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
    .palette-option {
        display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
        border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left;
    }
    .palette-option:hover { border-color: var(--border-strong); background: var(--surface-2); }
    .palette-option.active { border-color: var(--brand-500); box-shadow: var(--focus); }
    .palette-swatch { width: 22px; height: 22px; border-radius: 50%; flex: none; background: var(--swatch); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); }
    .appearance-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }

    /* Submenú Navegación Expandible/Colapsable */
    .nav-toolbar { display: flex; justify-content: flex-end; padding: 2px 4px 6px; }
    .nav-collapse-all {
        display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
        border: 1px solid rgba(255, 255, 255, .12); border-radius: 999px;
        background: rgba(255, 255, 255, .05); color: rgba(231, 245, 236, .75);
        font: inherit; font-size: .74rem; font-weight: 550; cursor: pointer;
        transition: background .15s, color .15s;
    }
    .nav-collapse-all:hover { background: rgba(255, 255, 255, .12); color: #fff; }
    .nav-group-btn {
        display: flex; align-items: center; justify-content: space-between; width: 100%;
        padding: 6px 12px; margin: 0 0 2px; border: none; border-radius: 8px; background: transparent;
        color: rgba(231, 245, 236, .68); cursor: pointer; text-align: left;
        transition: background .15s, color .15s;
    }
    .nav-group-btn:hover { background: rgba(255, 255, 255, .06); color: rgba(231, 245, 236, .95); }
    .nav-group-btn-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
    .nav-group-btn .nav-group-title { padding: 0; color: inherit; }
    .nav-chevron { flex: none; opacity: .72; transition: transform .2s ease; }
    .nav-group-btn[aria-expanded="true"] > .nav-chevron,
    .nav-expand-btn[aria-expanded="true"] > .nav-chevron { transform: rotate(180deg); }
    .nav-collapse {
        display: grid;
        grid-template-rows: 0fr;
        transition: grid-template-rows .22s ease;
    }
    .nav-collapse.open { grid-template-rows: 1fr; }
    .nav-collapse-inner {
        overflow: hidden;
        min-height: 0;
        visibility: hidden;
        transition: visibility 0s linear .22s;
    }
    .nav-collapse.open > .nav-collapse-inner {
        visibility: visible;
        transition: visibility 0s linear 0s;
    }
    .nav-expand-btn {
        display: flex; align-items: center; justify-content: space-between; width: 100%;
        padding: 9px 12px; margin: 2px 0; border-radius: 10px; border: none; background: transparent;
        color: rgba(231, 245, 236, .82); font-weight: 520; font-size: .92rem; cursor: pointer; text-align: left;
        transition: background .15s, color .15s;
    }
    .nav-expand-btn:hover { background: rgba(255, 255, 255, .07); color: #fff; }
    .nav-expand-btn.active { background: rgba(255, 255, 255, .1); color: #fff; }
    .nav-expand-btn-left { display: flex; align-items: center; gap: 12px; }
    .nav-submenu {
        display: flex; flex-direction: column; gap: 2px; padding: 4px 0 6px 14px;
        border-left: 2px solid rgba(255, 255, 255, .12); margin-left: 18px; margin-top: 2px;
    }
    .nav-submenu .nav-submenu { margin-left: 12px; }
    .nav-subitem {
        display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 8px;
        color: rgba(231, 245, 236, .75); font-size: .84rem; font-weight: 500; text-decoration: none;
        transition: background .15s, color .15s;
    }
    .nav-subitem:hover { background: rgba(255, 255, 255, .08); color: #fff; }
    .nav-subitem.active { background: rgba(255, 255, 255, .15); color: #fff; font-weight: 600; }
    .nav-subitem.active .icon { color: var(--accent-400); }
    .nav :is(button, a):focus-visible { outline: 2px solid var(--accent-400); outline-offset: -2px; }
    @media (prefers-reduced-motion: reduce) {
        .nav-collapse, .nav-collapse-inner, .nav-chevron { transition: none; }
    }

    /* Layout Vertical de Catálogos (Master-Detail Vertical) */
    .catalogs-layout {
        display: grid;
        grid-template-columns: 290px minmax(0, 1fr);
        gap: 1.25rem;
        align-items: start;
        margin-top: 1.25rem;
        transition: grid-template-columns .2s ease;
    }
    .catalogs-layout.collapsed {
        grid-template-columns: 68px minmax(0, 1fr);
    }
    .catalogs-sidebar {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 0.75rem;
        box-shadow: var(--shadow);
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        position: sticky;
        top: 80px;
    }
    .catalogs-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 0.6rem 0.75rem;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0.5rem;
    }
    .catalogs-sidebar-title {
        font-size: 0.82rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-2);
    }
    .catalogs-sidebar-toggle {
        padding: 4px 6px;
        margin-left: auto;
    }
    .catalogs-content {
        min-width: 0;
    }
    .catalogs-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }
    .catalogs-search {
        position: relative;
        width: 220px;
        max-width: 100%;
    }
    .catalogs-search input {
        width: 100%;
        padding: 6px 10px 6px 32px;
        font-size: 0.85rem;
        border-radius: var(--radius-sm);
    }
    .catalogs-search-icon {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-3);
        pointer-events: none;
        display: inline-flex;
    }
    .catalog-item-btn {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.65rem 0.85rem;
        border-radius: var(--radius-sm);
        border: 1px solid transparent;
        background: transparent;
        color: var(--text-2);
        font: inherit;
        font-size: 0.9rem;
        text-align: left;
        width: 100%;
        min-width: 0;
        cursor: pointer;
        transition: background .15s, border-color .15s, color .15s;
    }
    .catalogs-tab-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .catalog-item-btn:hover {
        background: var(--surface-2);
        color: var(--text);
        border-color: var(--border);
    }
    .catalog-item-btn.active {
        background: var(--brand-50);
        color: var(--brand-800);
        font-weight: 600;
        border-color: var(--brand-200);
    }
    .catalog-item-btn .catalog-badge {
        margin-left: auto;
        font-size: 0.76rem;
        padding: 2px 7px;
        border-radius: 999px;
        background: var(--surface-2);
        color: var(--text-3);
        border: 1px solid var(--border);
    }
    .catalog-item-btn.active .catalog-badge {
        background: var(--brand-200);
        color: var(--brand-950);
        font-weight: 700;
    }
    @media (min-width: 901px) {
        .catalogs-layout.collapsed .catalogs-sidebar-title,
        .catalogs-layout.collapsed .catalogs-tab-label,
        .catalogs-layout.collapsed .catalog-badge {
            display: none;
        }
        .catalogs-layout.collapsed .catalog-item-btn {
            justify-content: center;
            padding-inline: 0.6rem;
        }
    }
    @media (max-width: 900px) {
        .catalogs-layout,
        .catalogs-layout.collapsed {
            grid-template-columns: minmax(0, 1fr);
        }
        .catalogs-sidebar {
            position: static;
            top: auto;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
            gap: 0.35rem;
        }
        .catalogs-sidebar-header {
            grid-column: 1 / -1;
            margin-bottom: 0.25rem;
        }
        .catalogs-sidebar-toggle {
            display: none;
        }
    }
    @media (max-width: 640px) {
        .catalogs-sidebar {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
        .catalogs-toolbar {
            width: 100%;
        }
        .catalogs-search {
            width: 100%;
            flex: 1 1 100%;
        }
        .catalogs-toolbar .btn {
            flex: 1 1 auto;
        }
    }

    /* ===================== Punto de venta (Fase 3) ===================== */
    .ws-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 10px 16px; margin-bottom: 14px;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
    .ws-item { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
    .ws-message { flex-basis: 100%; color: var(--danger-600); font-size: .88rem; }
    .pos-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
    .pos-layout > .card + .card { margin-top: 0; }
    .pos-products-list { margin-top: 12px; max-height: calc(100vh - 260px); overflow: auto; }
    .pos-banner { padding: 8px 12px; margin-bottom: 12px; border-radius: 8px; background: var(--accent-100); color: var(--accent-700); }
    .pos-customer { position: relative; }
    .pos-dropdown { position: absolute; z-index: 20; left: 0; right: 0; top: 70px; display: flex; flex-direction: column;
        background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow, 0 10px 30px -12px rgba(0,0,0,.3)); }
    .pos-dropdown-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px; border: 0;
        background: transparent; color: var(--text); text-align: left; cursor: pointer; }
    .pos-dropdown-item:hover { background: var(--brand-50); }
    .pos-customer-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; margin: -6px 0 12px;
        border-radius: 8px; background: var(--surface-2); }
    .pos-lines { margin: 6px 0 12px; max-height: 40vh; overflow: auto; }
    .pos-totals { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-top: 1px solid var(--border); }
    .pos-totals > div { display: flex; justify-content: space-between; }
    .pos-total { font-size: 1.35rem; color: var(--brand-text); }
    .pos-change { display: flex; flex-direction: column; align-items: flex-end; margin-bottom: 14px; color: var(--brand-text); }
    .pos-change strong { font-size: 1.3rem; }
    .pos-change.short { color: var(--danger-600); }
    .line-info { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 12px; color: var(--text-2); font-size: .9rem; }
    .form-error { padding: 8px 12px; border-radius: 8px; background: var(--danger-100); color: var(--danger-600); font-size: .9rem; }
    .receipt { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
    .receipt-row { display: flex; justify-content: space-between; }
    .picker-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 0.75rem; align-items: end; margin-top: 0.5rem; }
    .picker-row .field { margin-bottom: 0; }
    .live-summary-bar { background: var(--surface-2); padding: 0.75rem 1rem; border-radius: var(--radius); margin-top: 0.75rem; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.65rem 1.25rem; font-size: 0.88rem; }
    .criterion-group { display: flex; align-items: center; gap: 4px; }
    .criterion-group .operator-select { width: 72px; flex-shrink: 0; padding: 0.35rem 0.4rem; font-size: 0.8125rem; height: 38px; }
    .criterion-group input { flex: 1; min-width: 0; height: 38px; }

    /* RecordLimitInput: combobox numérico con opciones estándar */
    .combobox-container { position: relative; }
    .combobox-input-group { display: flex; align-items: center; position: relative; }
    .combobox-input-group.open { z-index: 1000; }
    .combobox-input { padding-right: 28px; width: 100%; height: 38px; }
    .combobox-caret-btn {
        position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
        background: transparent; border: none; padding: 4px 6px; cursor: pointer;
        color: var(--text-3); display: flex; align-items: center;
    }
    .combobox-backdrop { position: fixed; inset: 0; z-index: 998; cursor: default; }
    .combobox-menu {
        position: absolute; top: calc(100% + 3px); left: 0; right: 0;
        background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
        z-index: 999; box-shadow: var(--shadow); padding: 4px 0; max-height: 180px; overflow-y: auto;
    }
    .combobox-item {
        width: 100%; border: none; text-align: left; padding: 6px 12px; cursor: pointer;
        font-size: .875rem; display: flex; align-items: center; justify-content: space-between;
        transition: background .15s; background: transparent; color: var(--text);
    }
    .combobox-item:hover { background: var(--surface-2); }
    .combobox-item.selected { background: var(--brand-50); color: var(--brand-text); font-weight: 600; }
    .combobox-item-label { pointer-events: none; }
    .combobox-item-check { pointer-events: none; display: inline-flex; }

    .rma-summary { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 10px 0 14px; }
    @media (max-width: 1100px) {
        .pos-layout { grid-template-columns: 1fr; }
        .pos-products-list { max-height: 40vh; }
    }
    @media (max-width: 640px) {
        .picker-row { grid-template-columns: 1fr; }
        .picker-row .btn { width: 100%; }
        .modal-footer { gap: 8px; padding: 12px 16px 16px; }
        .modal-footer .btn { flex: 1 1 auto; }
    }

    /* ===================== ReportViewer ===================== */
    .report-viewer-container {
        display: flex; flex-direction: column; width: 100%; height: 100%;
        flex: 1; min-height: 0; overflow: hidden;
    }
    .report-viewer-toolbar {
        display: flex; justify-content: space-between; align-items: center;
        padding: 8px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
        flex-shrink: 0; gap: 8px; flex-wrap: wrap;
    }
    .report-toolbar-group {
        display: flex; align-items: center; gap: 8px; position: relative; flex-wrap: wrap;
    }
    .zoom-controls {
        background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius-sm); padding: 2px 4px; gap: 2px;
    }
    .zoom-label { font-size: .82rem; padding: 4px 8px; color: var(--text-2); }
    .zoom-label:hover { color: var(--text); }
    .export-dropdown { position: relative; }
    .export-dropdown .dropdown-backdrop { z-index: 1040; }
    .export-menu {
        position: absolute; top: 100%; right: 0; z-index: 1050; min-width: 170px;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
        box-shadow: var(--shadow); padding: 4px; margin-top: 4px; display: flex; flex-direction: column;
    }
    .export-item {
        display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px;
        border: 0; border-radius: 6px; background: transparent; color: var(--text);
        font: inherit; font-size: .875rem; text-align: left; cursor: pointer;
    }
    .export-item:hover:not(:disabled) { background: var(--surface-2); }
    .export-item:disabled { opacity: .55; cursor: not-allowed; }
    .report-viewer-body {
        flex: 1; min-height: 0; overflow: hidden; position: relative;
        background: #525659; display: flex; flex-direction: column;
    }
    .report-loading {
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 10px; padding: 48px 20px; color: var(--text-2);
    }
    .report-error-wrap { padding: 20px; }
    .report-error-wrap .alert { flex-wrap: wrap; }
    .report-error-wrap .alert span { flex: 1; min-width: 180px; }
    .report-canvas-container {
        flex: 1; width: 100%; height: 100%; min-height: 0; overflow: auto;
        padding: 24px 16px 80px; display: flex; flex-direction: column; align-items: center;
    }
    .pdf-page-card {
        background: #ffffff; box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
        border-radius: 4px; margin: 0 auto 24px; max-width: 100%; flex-shrink: 0; overflow: hidden;
    }
    .pdf-page-canvas { display: block; margin: 0 auto; max-width: 100%; height: auto; }

    @media (max-width: 640px) {
        .modal.modal-xl { width: calc(100vw - 12px); height: 94vh; max-height: 94vh; top: 3vh; }
        .report-viewer-toolbar { padding: 8px 10px; }
        .report-toolbar-group { width: 100%; justify-content: flex-start; }
        .export-menu { left: 0; right: auto; }
        .report-canvas-container { padding: 12px 8px 60px; }
    }

    /* ===================== Componentes comunes de maquetación (Components/Shared) =====================
       Se adaptan con container queries (ancho del contenedor, no de la ventana): funcionan igual en
       una página, una tarjeta o un modal. Las pantallas no agregan @media. */

    /* FormField: etiqueta + control + ayuda + error. */
    .field-help { color: var(--text-3); font-size: var(--fs-xs); }
    .field > .validation-message { font-weight: 500; }

    /* FilterBar: campos de filtro que se acomodan solos + acciones a la derecha (abajo si no caben). */
    .filter-bar {
        container: filter-bar / inline-size;
        display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3);
        margin-bottom: var(--space-4); padding-bottom: var(--space-4); border-bottom: 1px dashed var(--border);
    }
    .filter-bar-fields {
        flex: 999 1 26rem; min-width: 0;
        display: grid; gap: var(--space-3);
        grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--filter-min)), 1fr));
        align-items: end;
    }
    .filter-bar-fields > .field { margin: 0; }
    .filter-bar-fields > .check { margin: 0; min-height: 38px; }
    .filter-bar-fields > .segmented { grid-column: 1 / -1; justify-self: start; max-width: 100%; flex-wrap: wrap; }
    .filter-bar-actions { flex: 1 1 auto; display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; align-items: flex-end; }
    @container filter-bar (min-width: 36rem) {
        .filter-bar-fields > .field-wide { grid-column: span 2; }
        .filter-bar-fields > .segmented { grid-column: span 2; }
    }
    @container filter-bar (max-width: 26rem) {
        .filter-bar-actions > .btn { flex: 1 1 auto; }
    }

    /* ActionBar: fila de botones; en contenedores angostos los botones ocupan el ancho disponible. */
    .action-bar { container: action-bar / inline-size; }
    .action-bar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); justify-content: flex-end; }
    .action-bar-start .action-bar-inner { justify-content: flex-start; }
    .action-bar-between .action-bar-inner { justify-content: space-between; }
    @container action-bar (max-width: 26rem) {
        .action-bar-inner > .btn { flex: 1 1 auto; }
    }

    /* DataTable: tabla común. Ancho angosto: desplazamiento interno (Scroll) o tarjetas (Cards). */
    /* Siempre con desplazamiento interno: si la tabla no cabe (también en modo Cards por encima de 40rem),
       se desplaza ella, nunca la página. position: relative contiene a los elementos absolutos (.sr-only de
       los encabezados): sin ella quedan fuera del recorte y estiran la página. */
    .data-table { container: data-table / inline-size; position: relative; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; }
    .data-table + .pager, .data-table .pager { border-top: 1px solid var(--border); }
    .data-table > .table th, .data-table > .table td.num, .data-table > .table td.actions { white-space: nowrap; }
    .dt-state { display: grid; place-items: center; padding: var(--space-8) var(--space-4); }
    .dt-busy { opacity: .6; transition: opacity .15s; }
    .table tbody tr.dt-clickable { cursor: pointer; }
    .table tbody tr.dt-clickable:focus-visible { outline: none; box-shadow: inset var(--focus); }
    .table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; background: var(--surface-2); }

    @container data-table (max-width: 40rem) {
        .dt-cards .table, .dt-cards .table tbody, .dt-cards .table tfoot, .dt-cards .table tr, .dt-cards .table td { display: block; width: auto; }
        .dt-cards .table thead { display: none; }
        .dt-cards .table tr {
            padding: var(--space-2) var(--space-3); margin-bottom: var(--space-3);
            border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
        }
        .dt-cards .table tbody tr:hover { background: var(--surface); }
        .dt-cards .table td {
            display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3);
            padding: var(--space-1) 0; border: 0; text-align: right; white-space: normal; overflow-wrap: anywhere;
        }
        .dt-cards .table td::before {
            content: attr(data-label); flex: none; max-width: 45%; text-align: left;
            color: var(--text-3); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
        }
        .dt-cards .table td.dt-primary { justify-content: flex-start; text-align: left; font-size: var(--fs-md); padding-bottom: var(--space-2); }
        .dt-cards .table td.dt-primary::before, .dt-cards .table td.actions::before, .dt-cards .table td[data-label=""]::before { content: none; }
        .dt-cards .table td.actions { justify-content: flex-end; flex-wrap: wrap; border-top: 1px dashed var(--border); margin-top: var(--space-1); padding-top: var(--space-2); }
        .dt-cards .table tfoot tr { background: var(--surface-2); }

        /* Al final y con más especificidad que las reglas de tarjetas (td { display: flex }). */
        .data-table .table .dt-hide-narrow { display: none; }
    }
}

@layer utilities {
    .muted { color: var(--text-3); }
    .small { font-size: .86em; }
    .strong { font-weight: 650; }
    .num { text-align: right; font-variant-numeric: tabular-nums; }
    .truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .icon { flex: none; }
    .grow { flex: 1; }
    .only-sm { display: none; }
    .text-center { text-align: center; }

    /* Texto */
    .text-muted { color: var(--text-3); }
    .text-danger { color: var(--danger-600); }
    .text-brand { color: var(--brand-text); }
    .text-brand-dark { color: var(--brand-700); }
    .text-accent { color: var(--accent-600); }
    .text-accent-dark { color: var(--accent-700); }
    .text-warning { color: var(--warning-600); }
    .section-divider { border-top: 1px solid var(--border); padding-top: var(--space-4); }
    .text-xs { font-size: var(--fs-xs); }
    .text-sm { font-size: var(--fs-sm); }
    .text-lg { font-size: var(--fs-lg); }
    .text-right { text-align: right; }
    .center { text-align: center; }
    .fw-semibold { font-weight: 600; }
    .fw-bold { font-weight: 700; }
    .nowrap { white-space: nowrap; }
    .break-all { word-break: break-all; }
    /* Solo para lectores de pantalla (títulos de tabla, encabezados de columnas de acciones). */
    .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; }

    /* Espacios (escala --space-N). */
    .m-0 { margin: 0; }
    .mx-auto { margin-inline: auto; }
    .mt-0 { margin-top: 0; }
    .mt-1 { margin-top: var(--space-1); }
    .mt-2 { margin-top: var(--space-2); }
    .mt-3 { margin-top: var(--space-3); }
    .mt-4 { margin-top: var(--space-4); }
    .mt-5 { margin-top: var(--space-5); }
    .mt-6 { margin-top: var(--space-6); }
    .mt-7 { margin-top: var(--space-7); }
    .mt-8 { margin-top: var(--space-8); }
    .mb-0 { margin-bottom: 0; }
    .mb-1 { margin-bottom: var(--space-1); }
    .mb-2 { margin-bottom: var(--space-2); }
    .mb-3 { margin-bottom: var(--space-3); }
    .mb-4 { margin-bottom: var(--space-4); }
    .mb-5 { margin-bottom: var(--space-5); }
    .mb-6 { margin-bottom: var(--space-6); }
    .mb-7 { margin-bottom: var(--space-7); }
    .mb-8 { margin-bottom: var(--space-8); }
    .p-0 { padding: 0; }
    .p-4 { padding: var(--space-4); }
    .p-6 { padding: var(--space-6); }
    .p-7 { padding: var(--space-7); }
    .p-8 { padding: var(--space-8); }

    /* Mostrar u ocultar según el ancho de la ventana (móvil <= 640px). */
    @media (max-width: 640px) {
        .only-sm { display: block; }
    }
}
