/* ==========================================================================
   Sistema Integral de Proveeduría Municipal
   Sistema de diseño — capa de tokens y componentes.

   Contrato: los nombres de clase son estables. Cualquier módulo nuevo debe
   usar estas clases; no se inventan variantes ad hoc.

   Tabla de contenidos
     1. Tokens
     2. Reset y base
     3. Tipografía y utilidades
     4. Shell: barra lateral y barra superior
     5. Encabezado de página y migas
     6. Tarjetas
     7. Indicadores (KPI)
     8. Botones
     9. Formularios
     10. Tablas
     11. Insignias y estados
     12. Alertas
     13. Modales
     14. Notificaciones
     15. Estados vacíos, carga y esqueleto
     16. Toolbar, filtros y paginación
     17. Progreso y resumen presupuestal
     18. Pestañas
     19. Línea de tiempo
     20. Gráficas
     21. Paleta de órdenes (captura)
     22. Acceso y protección
     23. Instalador
     24. Paleta de comandos
     25. Asistente de inteligencia artificial
     26. Impresión
     27. Adaptación a pantallas pequeñas
   ========================================================================== */

/* ==========================================================================
   1. TOKENS
   ========================================================================== */

:root {
    /* --- Identidad institucional (sobrescritos en runtime por el layout) --- */
    --brand-primary: #1f3a5f;
    --brand-secondary: #2e5a88;
    --brand-accent: #c9a227;

    --brand-50: #f2f6fb;
    --brand-100: #e2ebf5;
    --brand-200: #c5d6e9;
    --brand-300: #9db8d4;
    --brand-400: #6e92ba;
    --brand-500: #4a72a0;
    --brand-600: #2e5a88;
    --brand-700: #25476e;
    --brand-800: #1f3a5f;
    --brand-900: #16294a;

    --accent-soft: rgba(201, 162, 39, 0.16);
    --accent-line: rgba(201, 162, 39, 0.34);
    --brand-soft: rgba(31, 58, 95, 0.09);
    --brand-line: rgba(31, 58, 95, 0.18);

    /* Color del botón principal en estado hover. En modo oscuro se calcula a
       partir de la marca, no de la rampa: la rampa es oscura y dejaba el
       texto del botón sin contraste. */
    --brand-primary-hover: var(--brand-700);

    /* --- Neutros (fríos, con matiz azulado) --- */
    --gray-0: #ffffff;
    --gray-25: #fbfcfe;
    --gray-50: #f6f8fb;
    --gray-100: #eef1f6;
    --gray-150: #e6eaf1;
    --gray-200: #dce2ec;
    --gray-300: #c3ccda;
    --gray-400: #94a1b6;
    --gray-500: #6b7a92;
    --gray-600: #4d5b73;
    --gray-700: #3a4658;
    --gray-800: #26303f;
    --gray-900: #161d29;

    /* --- Superficies --- */
    --bg-canvas: #f4f6fa;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-subtle: #f8fafc;
    --bg-muted: #eef1f6;
    --bg-inset: #f1f4f9;
    --bg-sidebar: #131f33;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
    --bg-sidebar-active: rgba(255, 255, 255, 0.11);

    /* --- Texto --- */
    --text-strong: #101828;
    --text-body: #344054;
    --text-muted: #667085;
    --text-subtle: #98a2b3;
    --text-inverse: #ffffff;
    --text-sidebar: #c9d4e3;
    --text-sidebar-muted: #7f8fa8;

    /* --- Bordes --- */
    --border-color: #e3e8ef;
    --border-strong: #cdd5e0;
    --border-subtle: #edf0f5;
    --border-focus: var(--brand-600);

    /* --- Estados --- */
    --color-success: #067647;
    --color-success-strong: #055f3a;
    --color-success-bg: #ecfdf3;
    --color-success-border: #abefc6;
    --color-warning: #b54708;
    --color-warning-bg: #fffaeb;
    --color-warning-border: #fedf89;
    --color-danger: #b42318;
    --color-danger-bg: #fef3f2;
    --color-danger-border: #fecdca;
    --color-info: #175cd3;
    --color-info-bg: #eff8ff;
    --color-info-border: #b2ddff;

    /* --- Tipografía --- */
    --font-sans: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

    --font-size-xs: 0.75rem;      /* 12px — etiquetas */
    --font-size-sm: 0.8125rem;    /* 13px — metadatos */
    --font-size-base: 0.9375rem;  /* 15px — cuerpo */
    --font-size-md: 1rem;         /* 16px — controles */
    --font-size-lg: 1.125rem;     /* 18px */
    --font-size-xl: 1.375rem;     /* 22px */
    --font-size-2xl: 1.75rem;     /* 28px */
    --font-size-3xl: 2.125rem;    /* 34px */

    --line-height-tight: 1.25;
    --line-height: 1.5;
    --line-height-relaxed: 1.65;

    --tracking-tight: -0.021em;
    --tracking-label: 0.055em;

    /* --- Espaciado --- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-7: 1.75rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* --- Radios --- */
    --radius-xs: 5px;
    --radius-sm: 8px;
    --radius-md: 11px;
    --radius-lg: 15px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* --- Sombras (capas, no planas) --- */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 2px 4px -1px rgba(16, 24, 40, 0.05), 0 4px 10px -2px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 4px 8px -2px rgba(16, 24, 40, 0.06), 0 12px 24px -6px rgba(16, 24, 40, 0.12);
    --shadow-xl: 0 8px 16px -6px rgba(16, 24, 40, 0.08), 0 24px 40px -12px rgba(16, 24, 40, 0.18);
    --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.6);

    /* --- Foco --- */
    --focus-ring: 0 0 0 3px rgba(46, 90, 136, 0.22);
    --focus-ring-danger: 0 0 0 3px rgba(180, 35, 24, 0.2);

    /* --- Estructura --- */
    --sidebar-width: 264px;
    --sidebar-collapsed: 76px;
    --topbar-height: 64px;
    --content-max: 1680px;
    --row-height: 48px;
    --row-height-compact: 38px;

    /* --- Movimiento --- */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition: 160ms var(--ease);
    --transition-slow: 260ms var(--ease-out);

    /* El tema de la aplicación manda sobre el del sistema operativo. Sin esto,
       los controles nativos (checkbox, radio, selector, calendario, barras de
       desplazamiento) se dibujan con la paleta del sistema y rompen el
       contraste de una interfaz que está en modo claro. */
    color-scheme: light;
}

/* Se usa `html[data-theme="dark"]` y no `[data-theme="dark"]` a propósito:
   el layout inyecta la marca institucional en un bloque <style> con `:root`
   (especificidad 0,1,0). Con el selector de attribute la especificidad
   empataba y ganaba el bloque del layout, dejando el tema oscuro con los
   colores de marca del modo claro. Con `html[...]` (0,1,1) gana el tema. */
html[data-theme="dark"] {
    color-scheme: dark;
    --brand-primary: #7aa7d8;
    --brand-secondary: #94b9e2;
    --brand-accent: #e0bd52;

    --brand-soft: rgba(122, 167, 216, 0.14);
    --brand-line: rgba(122, 167, 216, 0.28);
    --accent-soft: rgba(224, 189, 82, 0.16);
    --accent-line: rgba(224, 189, 82, 0.32);

    --bg-canvas: #0c121c;
    --bg-surface: #141d2b;
    --bg-elevated: #1a2434;
    --bg-subtle: #172130;
    --bg-muted: #1e2a3b;
    --bg-inset: #101927;
    --bg-sidebar: #080d15;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
    --bg-sidebar-active: rgba(122, 167, 216, 0.14);

    --text-strong: #eef2f8;
    --text-body: #c2cddb;
    --text-muted: #8d9cb2;
    --text-subtle: #62718a;
    --text-sidebar: #b6c4d6;
    --text-sidebar-muted: #6d7d95;

    --border-color: #24303f;
    --border-strong: #33415a;
    --border-subtle: #1c2635;
    --border-focus: #7aa7d8;

    --color-success: #6ce9a6;
    --color-success-strong: #86f0bd;
    --color-success-bg: rgba(6, 118, 71, 0.18);
    --color-success-border: rgba(108, 233, 166, 0.28);
    --color-warning: #fdb022;
    --color-warning-bg: rgba(181, 71, 8, 0.2);
    --color-warning-border: rgba(253, 176, 34, 0.3);
    --color-danger: #fda29b;
    --color-danger-bg: rgba(180, 35, 24, 0.2);
    --color-danger-border: rgba(253, 162, 155, 0.3);
    --color-info: #84caff;
    --color-info-bg: rgba(23, 92, 211, 0.2);
    --color-info-border: rgba(132, 202, 255, 0.3);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.42), 0 8px 20px rgba(0, 0, 0, 0.34);
    --shadow-lg: 0 6px 14px rgba(0, 0, 0, 0.46), 0 18px 36px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 12px 26px rgba(0, 0, 0, 0.5), 0 30px 56px rgba(0, 0, 0, 0.46);
    --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.04);

    --focus-ring: 0 0 0 3px rgba(122, 167, 216, 0.3);

    /* El hover se deriva de la marca vigente: al aclararse la marca en modo
       oscuro, el hover debe aclararse también y no volver al azul marino. */
    --brand-primary-hover: color-mix(in srgb, var(--brand-primary) 86%, #000000);
}

/* Densidad de tabla: el usuario elige. Compacta = más registros en pantalla. */
[data-density="compact"] {
    --row-height: 38px;
    --font-size-base: 0.875rem;
}

[data-density="compact"] .table td,
[data-density="compact"] .table th {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}

/* ==========================================================================
   2. RESET Y BASE
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--text-body);
    background: var(--bg-canvas);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv02", "cv03", "cv04";
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    color: var(--text-strong);
    font-weight: 640;
    letter-spacing: var(--tracking-tight);
    line-height: var(--line-height-tight);
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }
h4 { font-size: var(--font-size-md); }

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

a {
    color: var(--brand-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover { color: var(--brand-primary); }

ul, ol { margin: 0; padding: 0; }
li { list-style: none; }

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: var(--space-5) 0;
}

img { max-width: 100%; height: auto; }

code, pre, .mono {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

code {
    background: var(--bg-muted);
    padding: 0.1em 0.38em;
    border-radius: var(--radius-xs);
    color: var(--text-strong);
}

:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-xs);
}

::selection {
    background: var(--brand-soft);
    color: var(--text-strong);
}

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
    border: 3px solid var(--bg-canvas);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ==========================================================================
   3. TIPOGRAFÍA Y UTILIDADES
   ========================================================================== */

.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;
}

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 300;
    background: var(--brand-primary);
    color: var(--text-inverse);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: top var(--transition);
}

.skip-link:focus { top: var(--space-4); color: var(--text-inverse); }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-strong { color: var(--text-strong); }
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.w-full { width: 100%; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.hidden { display: none !important; }

/* ==========================================================================
   4. SHELL: BARRA LATERAL Y BARRA SUPERIOR
   ========================================================================== */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-slow);
}

.app-body {
    flex: 1;
    padding: var(--space-6) var(--space-8) var(--space-12);
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

.app-body--flush { padding: 0; max-width: none; }

/* --- Barra lateral --- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: width var(--transition-slow), transform var(--transition-slow);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--topbar-height);
    padding: 0 var(--space-4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar__logo {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    object-fit: contain;
    background: rgba(255, 255, 255, 0.94);
    padding: 3px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.sidebar__logo--fallback {
    display: grid;
    place-items: center;
    font-weight: 700;
    color: var(--brand-primary);
    font-size: var(--font-size-sm);
}

.sidebar__titles {
    min-width: 0;
    line-height: 1.3;
}

.sidebar__title {
    font-size: var(--font-size-sm);
    font-weight: 640;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.sidebar__subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-5) var(--space-3) var(--space-6);
}

.sidebar__nav::-webkit-scrollbar { width: 6px; }
.sidebar__nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.11);
    border: 0;
}

.sidebar__section { margin-bottom: var(--space-6); }

.sidebar__section-title {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-sidebar-muted);
    font-weight: 640;
    padding: 0 var(--space-3);
    margin-bottom: var(--space-2);
    white-space: nowrap;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.5rem var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    font-size: var(--font-size-base);
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.sidebar__link:hover {
    background: var(--bg-sidebar-hover);
    color: #fff;
}

.sidebar__link.is-active {
    background: var(--bg-sidebar-active);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.sidebar__link.is-active::before {
    content: "";
    position: absolute;
    left: calc(var(--space-3) * -1);
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--brand-accent);
    border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.sidebar__icon {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
    stroke-width: 1.75;
    opacity: 0.85;
}

.sidebar__link.is-active .sidebar__icon { opacity: 1; }

.sidebar__badge {
    margin-left: auto;
    background: var(--brand-accent);
    color: #2b2103;
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: var(--radius-full);
}

.sidebar__footer {
    padding: var(--space-3);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    min-width: 0;
    transition: background var(--transition);
}

.sidebar__user:hover { background: var(--bg-sidebar-hover); }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(140deg, var(--brand-500), var(--brand-800));
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 650;
    font-size: var(--font-size-sm);
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}

.avatar--lg { width: 48px; height: 48px; font-size: var(--font-size-md); }

.sidebar__user-info { min-width: 0; line-height: 1.35; }

.sidebar__user-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__user-role {
    font-size: var(--font-size-xs);
    color: var(--text-sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
body.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed); }
body.sidebar-collapsed .sidebar__titles,
body.sidebar-collapsed .sidebar__link span,
body.sidebar-collapsed .sidebar__section-title,
body.sidebar-collapsed .sidebar__user-info { display: none; }
body.sidebar-collapsed .sidebar__link { justify-content: center; }
body.sidebar-collapsed .sidebar__brand { justify-content: center; padding: 0; }
body.sidebar-collapsed .sidebar__user { justify-content: center; }
body.sidebar-collapsed .sidebar__section { margin-bottom: var(--space-4); }

/* --- Barra superior --- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-8);
    background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(10px);
    border-bottom: 1px solid var(--border-color);
}

.topbar__toggle {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    color: var(--text-body);
    cursor: pointer;
    transition: all var(--transition);
}

.topbar__toggle:hover {
    background: var(--bg-muted);
    color: var(--text-strong);
    border-color: var(--border-strong);
}

.topbar__toggle svg { width: 19px; height: 19px; }

.topbar__title {
    font-size: var(--font-size-lg);
    font-weight: 640;
    color: var(--text-strong);
    margin: 0;
    letter-spacing: var(--tracking-tight);
}

.topbar__spacer { flex: 1; }

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    transition: all var(--transition);
}

.icon-btn svg { width: 19px; height: 19px; }

.icon-btn:hover {
    background: var(--bg-muted);
    color: var(--text-strong);
}

.icon-btn__dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 8px;
    height: 8px;
    background: var(--color-danger);
    border-radius: 50%;
    border: 2px solid var(--bg-surface);
}

/* Lanzador de la paleta de comandos */
.command-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 38px;
    padding: 0 var(--space-2) 0 var(--space-3);
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-size-sm);
    min-width: 210px;
    transition: all var(--transition);
}

.command-trigger:hover {
    background: var(--bg-surface);
    border-color: var(--border-strong);
    color: var(--text-body);
}

.command-trigger__label { flex: 1; text-align: left; }

.command-trigger svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    opacity: 0.75;
}

.command-trigger kbd {
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-subtle);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-bottom-width: 2px;
    border-radius: var(--radius-xs);
    padding: 1px 6px;
}

/* --- Menú desplegable --- */

.dropdown { position: relative; }

.dropdown__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 248px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-2);
    z-index: 80;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top right;
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}

.dropdown.is-open .dropdown__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.dropdown__header {
    padding: var(--space-3);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-2);
}

.dropdown__name {
    font-weight: 640;
    color: var(--text-strong);
    font-size: var(--font-size-base);
}

.dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-body);
    font-size: var(--font-size-base);
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background var(--transition), color var(--transition);
}

.dropdown__item svg { flex-shrink: 0; opacity: 0.7; }

.dropdown__item:hover {
    background: var(--bg-muted);
    color: var(--text-strong);
}

.dropdown__item--danger { color: var(--color-danger); }
.dropdown__item--danger:hover { background: var(--color-danger-bg); color: var(--color-danger); }
.dropdown__divider { height: 1px; background: var(--border-color); margin: var(--space-2) 0; }

/* ==========================================================================
   5. ENCABEZADO DE PÁGINA Y MIGAS
   ========================================================================== */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-5);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

.page-header__title {
    font-size: var(--font-size-2xl);
    font-weight: 680;
    color: var(--text-strong);
    margin: 0 0 var(--space-1);
    letter-spacing: -0.022em;
}

.page-header__subtitle {
    color: var(--text-muted);
    font-size: var(--font-size-md);
    margin: 0;
    max-width: 72ch;
}

.page-header__actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    align-items: center;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-2);
    flex-wrap: wrap;
}

.breadcrumbs a { color: var(--text-muted); font-weight: 500; }
.breadcrumbs a:hover { color: var(--brand-secondary); }
.breadcrumbs__sep { color: var(--text-subtle); }

/* ==========================================================================
   6. TARJETAS
   ========================================================================== */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    background: linear-gradient(180deg, var(--bg-surface), var(--bg-subtle));
}

.card__title {
    font-size: var(--font-size-md);
    font-weight: 640;
    color: var(--text-strong);
    margin: 0;
    letter-spacing: -0.012em;
}

.card__subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin: 3px 0 0;
}

.card__body { padding: var(--space-5); }
.card__body--tight { padding: var(--space-3); }

.card__footer {
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.card--flush .card__body { padding: 0; }
.card--interactive { cursor: pointer; transition: transform var(--transition), box-shadow var(--transition); }
.card--interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ==========================================================================
   7. INDICADORES (KPI)
   ========================================================================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--brand-primary);
    opacity: 0;
    transition: opacity var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: var(--border-strong);
}

.stat-card:hover::before { opacity: 1; }

.stat-card__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.stat-card__label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 640;
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    line-height: 1.35;
    /* Altura fija de dos renglones: las cifras quedan alineadas entre tarjetas
       aunque una etiqueta ocupe una línea y otra dos. */
    min-height: calc(2 * 1.35em);
    display: flex;
    align-items: flex-start;
}

.stat-card__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand-primary);
    flex-shrink: 0;
}

.stat-card__icon svg { width: 20px; height: 20px; }

.stat-card__value {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--text-strong);
    line-height: 1.08;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat-card__value--sm { font-size: var(--font-size-2xl); }

.stat-card__meta {
    margin-top: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.stat-card--success .stat-card__icon { background: var(--color-success-bg); color: var(--color-success); }
.stat-card--success::before { background: var(--color-success); }
.stat-card--warning .stat-card__icon { background: var(--color-warning-bg); color: var(--color-warning); }
.stat-card--warning::before { background: var(--color-warning); }
.stat-card--danger .stat-card__icon { background: var(--color-danger-bg); color: var(--color-danger); }
.stat-card--danger::before { background: var(--color-danger); }
.stat-card--info .stat-card__icon { background: var(--color-info-bg); color: var(--color-info); }
.stat-card--info::before { background: var(--color-info); }
.stat-card--accent .stat-card__icon { background: var(--accent-soft); color: var(--brand-accent); }
.stat-card--accent::before { background: var(--brand-accent); }

.trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-weight: 640;
    font-size: var(--font-size-sm);
    font-variant-numeric: tabular-nums;
}

.trend--up { color: var(--color-success); }
.trend--down { color: var(--color-danger); }
.trend--flat { color: var(--text-muted); }

/* ==========================================================================
   8. BOTONES
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0 var(--space-4);
    height: 40px;
    font-family: inherit;
    font-size: var(--font-size-base);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.005em;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), color var(--transition),
                box-shadow var(--transition), transform var(--transition);
    vertical-align: middle;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled,
.btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn svg { width: 17px; height: 17px; flex-shrink: 0; }

.btn--primary {
    background: var(--brand-primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-xs);
}

.btn--primary:hover {
    background: var(--brand-primary-hover);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .btn--primary { color: #0b121c; }
[data-theme="dark"] .btn--primary:hover { color: #0b121c; }

/* En modo oscuro los colores de estado son claros: el texto blanco sobre
   ellos no alcanza el contraste mínimo. */
[data-theme="dark"] .btn--danger { color: #2a0d09; }
[data-theme="dark"] .btn--success { color: #04291a; }

.btn--accent {
    background: var(--brand-accent);
    color: #2b2103;
}

.btn--accent:hover { filter: brightness(0.94); color: #2b2103; }

.btn--secondary {
    background: var(--bg-surface);
    color: var(--text-body);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-xs);
}

.btn--secondary:hover {
    background: var(--bg-subtle);
    color: var(--text-strong);
    border-color: var(--text-subtle);
}

.btn--ghost {
    background: transparent;
    color: var(--text-body);
}

.btn--ghost:hover { background: var(--bg-muted); color: var(--text-strong); }

.btn--danger {
    background: var(--color-danger);
    color: #fff;
}

.btn--danger:hover { filter: brightness(0.93); color: #fff; }

.btn--success {
    background: var(--color-success);
    color: #fff;
}

.btn--success:hover { filter: brightness(0.93); color: #fff; }

.btn--sm { height: 34px; padding: 0 var(--space-3); font-size: var(--font-size-sm); }
.btn--lg { height: 46px; padding: 0 var(--space-6); font-size: var(--font-size-md); }
.btn--icon { width: 36px; height: 36px; padding: 0; }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* ==========================================================================
   9. FORMULARIOS
   ========================================================================== */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-4) var(--space-5);
}

.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form-field { margin-bottom: var(--space-4); }
.form-grid .form-field { margin-bottom: 0; }

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-body);
    margin-bottom: var(--space-2);
    letter-spacing: -0.003em;
}

.form-label__required { color: var(--color-danger); margin-left: 2px; }

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--space-2);
    display: block;
    line-height: 1.45;
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-danger);
    margin-top: var(--space-2);
    display: block;
    font-weight: 550;
}

.input,
.select,
.textarea {
    width: 100%;
    padding: 0 var(--space-3);
    height: 40px;
    font-family: inherit;
    font-size: var(--font-size-base);
    color: var(--text-strong);
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    appearance: none;
}

.textarea {
    height: auto;
    min-height: 96px;
    padding: var(--space-3);
    line-height: var(--line-height-relaxed);
    resize: vertical;
}

.select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7a92' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
    cursor: pointer;
}

.input::placeholder,
.textarea::placeholder { color: var(--text-subtle); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
    background: var(--bg-muted);
    color: var(--text-muted);
    cursor: not-allowed;
    border-color: var(--border-color);
}

.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid {
    border-color: var(--color-danger);
    background: var(--color-danger-bg);
}

.input.is-invalid:focus,
.select.is-invalid:focus,
.textarea.is-invalid:focus {
    box-shadow: var(--focus-ring-danger);
}

/* Zona de arrastre: sustituye al selector nativo de archivos. El control
   real (`input[type=file]`) queda oculto con `.sr-only` y esta zona actúa
   como su botón: al pulsarla se abre el diálogo del sistema. */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 188px;
    padding: var(--space-6) var(--space-5);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg-subtle);
    color: var(--text-muted);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background-color var(--transition), color var(--transition);
}

.dropzone:hover {
    border-color: var(--brand-400);
    background: var(--brand-soft);
}

.dropzone:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* Arrastrando el archivo sobre la zona. */
.dropzone.is-dragging {
    border-style: solid;
    border-color: var(--brand-primary);
    background: var(--brand-soft);
}

/* Ya hay un archivo seleccionado: la zona deja de inviting a cargar. */
.dropzone.has-file {
    border-style: solid;
    border-color: var(--color-success-border);
    background: var(--color-success-bg);
}

.dropzone.has-file:hover { border-color: var(--color-success-border); background: var(--color-success-bg); }

.dropzone__icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--brand-primary);
}

.dropzone__icon svg { width: 24px; height: 24px; }

.dropzone__title {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-strong);
    line-height: 1.4;
}

.dropzone__hint {
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.dropzone__file {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2) var(--space-3);
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.dropzone__file-name {
    font-weight: 600;
    color: var(--text-strong);
    word-break: break-all;
}

.dropzone__file-meta {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.input--money { text-align: right; font-variant-numeric: tabular-nums; }

/* Controles de selección: mismo tamaño y color de acento estén dentro de
   una etiqueta .checkbox o sueltos en una celda de tabla (caso del IVA en la
   captura de órdenes). */
input[type="checkbox"],
input[type="radio"] {
    width: 17px;
    height: 17px;
    margin: 2px 0 0;
    accent-color: var(--brand-primary);
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox,
.radio {
    display: inline-flex;
    align-items: flex-start;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--font-size-base);
    color: var(--text-body);
    user-select: none;
}

.checkbox__text { line-height: 1.45; }

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
}

.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch__track {
    width: 42px;
    height: 24px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    position: relative;
    transition: background var(--transition);
    flex-shrink: 0;
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: var(--shadow-xs);
}

.switch input:checked + .switch__track { background: var(--brand-primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--focus-ring); }

/* Búsqueda asíncrona */
.search { position: relative; }

.search__results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: 70;
    display: none;
    padding: var(--space-1);
}

.search.is-open .search__results { display: block; }

.search__option {
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    align-items: center;
    transition: background var(--transition);
}

.search__option:hover,
.search__option.is-selected { background: var(--brand-soft); }

.search__option-title { font-weight: 600; color: var(--text-strong); }
.search__option-meta { font-size: var(--font-size-xs); color: var(--text-muted); }

/* ==========================================================================
   10. TABLAS
   ========================================================================== */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-size-base);
}

.table th {
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: 640;
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    color: var(--text-muted);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.table th:first-child { border-top-left-radius: var(--radius-lg); }
.table th:last-child { border-top-right-radius: var(--radius-lg); }

.table th.is-sortable { cursor: pointer; user-select: none; }
.table th.is-sortable:hover { color: var(--text-strong); background: var(--bg-muted); }

.table th .sort-icon {
    display: inline-block;
    margin-left: 5px;
    opacity: 0.35;
    font-size: 10px;
    transition: opacity var(--transition);
}

.table th.is-sorted { color: var(--brand-primary); }
.table th.is-sorted .sort-icon { opacity: 1; color: var(--brand-primary); }

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-body);
    vertical-align: middle;
    height: var(--row-height);
}

.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--bg-subtle); }
.table tbody tr:hover td { border-bottom-color: var(--border-color); }
.table tbody tr:last-child td { border-bottom: 0; }

.table--compact td,
.table--compact th { padding-top: 0.45rem; padding-bottom: 0.45rem; }

.table__num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-feature-settings: "tnum";
}

.table__actions {
    display: flex;
    gap: var(--space-1);
    justify-content: flex-end;
}

.table__primary { font-weight: 600; color: var(--text-strong); }
.table__secondary { font-size: var(--font-size-sm); color: var(--text-muted); }

.row-detail > td {
    background: var(--bg-subtle);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
}

.table tfoot td {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
    font-weight: 640;
    color: var(--text-strong);
}

/* ==========================================================================
   11. INSIGNIAS Y ESTADOS
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 640;
    line-height: 1.6;
    border: 1px solid transparent;
    white-space: nowrap;
    letter-spacing: 0.005em;
}

.badge--neutral { background: var(--bg-muted); color: var(--text-muted); border-color: var(--border-color); }
.badge--success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-border); }
.badge--danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger-border); }
.badge--info { background: var(--color-info-bg); color: var(--color-info); border-color: var(--color-info-border); }
.badge--accent { background: var(--accent-soft); color: var(--brand-accent); border-color: var(--accent-line); }

.badge__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* ==========================================================================
   12. ALERTAS
   ========================================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid;
    font-size: var(--font-size-base);
    margin-bottom: var(--space-4);
    line-height: var(--line-height);
}

.alert svg { width: 19px; height: 19px; flex-shrink: 0; margin-top: 1px; }
.alert__title { font-weight: 640; color: inherit; display: block; }
.alert__body { min-width: 0; flex: 1; }
.alert ul { margin: var(--space-2) 0 0; padding-left: var(--space-4); }
.alert ul li { list-style: disc; margin-bottom: 2px; }

.alert--success { background: var(--color-success-bg); border-color: var(--color-success-border); color: var(--color-success-strong); }
.alert--warning { background: var(--color-warning-bg); border-color: var(--color-warning-border); color: var(--color-warning); }
.alert--danger { background: var(--color-danger-bg); border-color: var(--color-danger-border); color: var(--color-danger); }
.alert--info { background: var(--color-info-bg); border-color: var(--color-info-border); color: var(--color-info); }

/* ==========================================================================
   13. MODALES
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 28, 0.58);
    backdrop-filter: blur(3px);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: var(--space-10) var(--space-4);
    z-index: 100;
    overflow-y: auto;
}

.modal-backdrop.is-open { display: flex; animation: backdrop-in 160ms var(--ease); }

@keyframes backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 560px;
    margin: auto;
    animation: modal-in 220ms var(--ease-out);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--space-16));
    border: 1px solid var(--border-color);
}

.modal--lg { max-width: 820px; }
.modal--xl { max-width: 1080px; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(-14px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal__title {
    font-size: var(--font-size-lg);
    font-weight: 650;
    color: var(--text-strong);
    margin: 0;
}

.modal__subtitle { font-size: var(--font-size-sm); color: var(--text-muted); margin: var(--space-1) 0 0; }

.modal__body {
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.modal__close {
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    line-height: 0;
    transition: background var(--transition), color var(--transition);
}

.modal__close:hover { background: var(--bg-muted); color: var(--text-strong); }
.modal__close svg { width: 18px; height: 18px; }

/* ==========================================================================
   14. NOTIFICACIONES
   ========================================================================== */

.toast-container {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--brand-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3) var(--space-4);
    animation: toast-in 240ms var(--ease-out);
    cursor: pointer;
}

.toast--success { border-left-color: var(--color-success); }
.toast--error { border-left-color: var(--color-danger); }
.toast--warning { border-left-color: var(--color-warning); }
.toast--info { border-left-color: var(--color-info); }

.toast__icon { flex-shrink: 0; line-height: 0; margin-top: 1px; }
.toast__icon svg { width: 19px; height: 19px; }
.toast--success .toast__icon { color: var(--color-success); }
.toast--error .toast__icon { color: var(--color-danger); }
.toast--warning .toast__icon { color: var(--color-warning); }
.toast--info .toast__icon { color: var(--color-info); }

.toast__message { font-size: var(--font-size-base); color: var(--text-body); flex: 1; }
.toast__title { font-weight: 640; color: var(--text-strong); display: block; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(28px) scale(0.97); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

.toast.is-leaving { animation: toast-out 180ms var(--ease) forwards; }

@keyframes toast-out {
    to { opacity: 0; transform: translateX(28px) scale(0.97); }
}

/* ==========================================================================
   15. ESTADOS VACÍOS, CARGA Y ESQUELETO
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
}

.empty-state__icon {
    width: 56px;
    height: 56px;
    margin: 0 auto var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--bg-muted);
    color: var(--text-subtle);
    display: grid;
    place-items: center;
}

.empty-state__icon svg { width: 26px; height: 26px; }

.empty-state__title {
    font-size: var(--font-size-md);
    font-weight: 640;
    color: var(--text-strong);
    margin-bottom: var(--space-1);
}

.empty-state__text {
    color: var(--text-muted);
    max-width: 46ch;
    margin: 0 auto var(--space-4);
    font-size: var(--font-size-base);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    display: inline-block;
}

.spinner--lg { width: 34px; height: 34px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--bg-surface) 72%, transparent);
    display: grid;
    place-items: center;
    z-index: 5;
    border-radius: inherit;
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-inset) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius-xs);
    height: 14px;
}

.skeleton--title { height: 20px; width: 45%; }
.skeleton--line { height: 13px; }
.skeleton--circle { border-radius: var(--radius-full); }

@keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

.skeleton-rows { padding: var(--space-3) var(--space-4); display: grid; gap: var(--space-3); }

/* ==========================================================================
   16. TOOLBAR, FILTROS Y PAGINACIÓN
   ========================================================================== */

.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-subtle);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.toolbar__search { flex: 1; min-width: 220px; max-width: 420px; }
.toolbar__filters { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.toolbar__spacer { flex: 1; }
.toolbar .input,
.toolbar .select { height: 36px; font-size: var(--font-size-sm); }

/* Los controles del toolbar se acomodan en línea: no deben heredar el
   ancho completo del contenedor (los selects traen width: 100% por defecto). */
.toolbar__filters .input,
.toolbar__filters .select {
    width: auto;
    min-width: 150px;
    max-width: 220px;
}

.toolbar__filters .input[type="date"] { min-width: 142px; }
.toolbar__filters .btn { width: auto; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    background: var(--bg-subtle);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.pagination__info { font-size: var(--font-size-sm); color: var(--text-muted); }
.pagination__pages { display: flex; gap: var(--space-1); align-items: center; }

.page-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 var(--space-2);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-body);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 560;
    display: grid;
    place-items: center;
    transition: all var(--transition);
    font-variant-numeric: tabular-nums;
}

.page-btn:hover:not(:disabled) { background: var(--bg-muted); color: var(--text-strong); border-color: var(--border-strong); }
.page-btn.is-active { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--text-inverse); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ==========================================================================
   17. PROGRESO Y RESUMEN PRESUPUESTAL
   ========================================================================== */

.progress {
    height: 7px;
    background: var(--bg-muted);
    border-radius: var(--radius-full);
    overflow: hidden;
    width: 100%;
    min-width: 80px;
}

.progress__bar {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--brand-primary);
    transition: width 500ms var(--ease-out);
}

.progress__bar--warning { background: var(--color-warning); }
.progress__bar--danger { background: var(--color-danger); }
.progress__bar--success { background: var(--color-success); }

/* Área de progreso: la fase en curso, el porcentaje y el detalle. */
.progress-area {
    margin-top: var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-subtle);
}

.progress-area__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.progress-area__label {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-strong);
}

.progress-area__value {
    font-size: var(--font-size-sm);
    font-weight: 640;
    color: var(--brand-primary);
    font-variant-numeric: tabular-nums;
}

.progress-area__detail {
    margin: var(--space-3) 0 0;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* Fase sin porcentaje conocido (el servidor procesa): la barra recorre el
   carril en bucle hasta que la fase termina. */
.progress--indeterminate .progress__bar {
    width: 38%;
    animation: progress-indeterminate 1.15s var(--ease) infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(285%); }
}

.budget-summary {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 200px;
}

.budget-summary__row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.budget-summary__value {
    font-weight: 640;
    color: var(--text-strong);
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   18. PESTAÑAS
   ========================================================================== */

.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-5);
    overflow-x: auto;
}

.tab {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
    background: none;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    cursor: pointer;
    font-family: inherit;
}

.tab:hover { color: var(--text-strong); }
.tab.is-active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

/* ==========================================================================
   19. LÍNEA DE TIEMPO
   ========================================================================== */

.timeline { position: relative; padding-left: var(--space-6); }

.timeline::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--border-color);
}

.timeline__item { position: relative; padding-bottom: var(--space-5); }
.timeline__item:last-child { padding-bottom: 0; }

.timeline__dot {
    position: absolute;
    left: calc(var(--space-6) * -1 + 2px);
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 2px solid var(--brand-primary);
    box-shadow: 0 0 0 3px var(--bg-surface);
}

.timeline__title { font-weight: 600; color: var(--text-strong); font-size: var(--font-size-base); }
.timeline__meta { font-size: var(--font-size-xs); color: var(--text-muted); margin-top: 3px; }

/* ==========================================================================
   20. GRÁFICAS
   ========================================================================== */

.chart-card__body { padding: var(--space-5); }

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: 200px;
    padding-top: var(--space-4);
    border-bottom: 1px solid var(--border-color);
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    height: 100%;
    position: relative;
}

.chart-bar__value {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--transition);
}

.chart-bar:hover .chart-bar__value { opacity: 1; }

.chart-bar__track {
    width: 100%;
    max-width: 46px;
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: var(--bg-muted);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    overflow: hidden;
}

.chart-bar__fill {
    width: 100%;
    background: linear-gradient(180deg, var(--brand-500), var(--brand-700));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: height 600ms var(--ease-out), filter var(--transition);
    min-height: 3px;
}

.chart-bar:hover .chart-bar__fill { filter: brightness(1.12); }

.chart-bar__label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-align: center;
    /* Dos renglones: los nombres de departamento largos no se truncan. */
    white-space: normal;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    max-width: 100%;
    padding-top: var(--space-2);
    min-height: 2.5em;
}

.donut-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    flex-wrap: wrap;
}

.donut {
    width: 156px;
    height: 156px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.donut__center {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
}

.donut__value { font-size: var(--font-size-xl); font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.donut__label { font-size: var(--font-size-xs); color: var(--text-muted); }

.legend { display: grid; gap: var(--space-2); flex: 1; min-width: 200px; }

.legend__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
}

.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend__label { flex: 1; color: var(--text-body); }
.legend__value { font-weight: 640; color: var(--text-strong); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   21. PALETA DE ÓRDENES (captura)
   ========================================================================== */

.order-items {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-size-base);
}

.order-items th {
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: 640;
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    white-space: nowrap;
}

.order-items th:first-child { border-left: 1px solid var(--border-color); border-radius: var(--radius-sm) 0 0 0; }
.order-items th:last-child { border-right: 1px solid var(--border-color); border-radius: 0 var(--radius-sm) 0 0; }

.order-items td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.order-items td:first-child { border-left: 1px solid var(--border-color); }
.order-items td:last-child { border-right: 1px solid var(--border-color); }
.order-items tbody tr:last-child td { border-bottom: 1px solid var(--border-color); }
.order-items tbody tr:hover td { background: var(--bg-subtle); }

.order-items .input,
.order-items .select { height: 36px; }

.order-totals {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 260px;
}

.order-totals__row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    font-size: var(--font-size-base);
    color: var(--text-muted);
}

.order-totals__row strong { color: var(--text-strong); font-variant-numeric: tabular-nums; }

.order-totals__row--total {
    border-top: 1px solid var(--border-color);
    padding-top: var(--space-3);
    margin-top: var(--space-1);
    font-size: var(--font-size-lg);
    color: var(--text-strong);
    font-weight: 650;
}

.order-totals__row--total strong { font-size: var(--font-size-xl); }

/* ==========================================================================
   22. ACCESO Y PROTECCIÓN
   ========================================================================== */

.auth-page {
    position: relative;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-10) var(--space-4);
    overflow: hidden;
    background:
        radial-gradient(1180px 820px at 6% 8%, color-mix(in srgb, var(--brand-primary) 82%, #ffffff) 0%, transparent 56%),
        radial-gradient(960px 740px at 94% 14%, #2f6bff 0%, transparent 58%),
        radial-gradient(940px 900px at 44% 106%, #12bd88 0%, transparent 60%),
        #101b3c;
}

/* Grano sutil: da la textura de la referencia sin cargar una imagen. */
.auth-page::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.2;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23g)' opacity='0.55'/%3E%3C/svg%3E");
}

.auth-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1060px;
}

.auth-card {
    display: grid;
    grid-template-columns: 1fr;
    background: #0b0f16;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 40px 90px rgba(3, 8, 26, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

@media (min-width: 900px) {
    .auth-card { grid-template-columns: 1.05fr 1fr; }
}

/* --- Lado izquierdo: la imagen elegible --- */

.auth-card__media {
    padding: 22px;
    display: flex;
    min-height: 180px;
}

.auth-card__frame {
    position: relative;
    flex: 1;
    min-height: 200px;
    border-radius: 18px;
    overflow: hidden;
    background:
        radial-gradient(700px 500px at 16% 12%, color-mix(in srgb, var(--brand-primary) 74%, #0b0f16) 0%, transparent 62%),
        radial-gradient(560px 460px at 90% 98%, color-mix(in srgb, var(--brand-accent) 30%, #0b0f16) 0%, transparent 66%),
        linear-gradient(160deg, #16294a, #0b0f16);
    display: flex;
    flex-direction: column;
    padding: 26px;
}

@media (min-width: 900px) {
    .auth-card__frame { min-height: 520px; }
}

.auth-card__photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Velo para que el pie se lea sobre cualquier fotografía. */
.auth-card__frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(to top, rgba(5, 9, 18, 0.9) 0%, rgba(5, 9, 18, 0.42) 30%, rgba(5, 9, 18, 0) 58%);
}

.auth-card__caption {
    position: relative;
    z-index: 2;
    /* Empuja el pie al final del panel, como en la referencia. */
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    color: #fff;
}

.auth-card__logo {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 12px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.94);
    padding: 5px;
}

.auth-card__name {
    font-size: var(--font-size-lg);
    font-weight: 650;
    color: #fff;
    letter-spacing: -0.015em;
    text-shadow: 0 1px 14px rgba(0, 0, 0, 0.6);
}

.auth-card__tagline {
    font-size: var(--font-size-sm);
    color: rgba(255, 255, 255, 0.76);
    text-shadow: 0 1px 12px rgba(0, 0, 0, 0.6);
}

.auth-card__features {
    position: relative;
    z-index: 2;
    list-style: none;
    display: grid;
    gap: 12px;
    margin: 0 0 var(--space-4);
}

.auth-card__feature {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.84);
    font-size: var(--font-size-sm);
}

.auth-card__feature svg { width: 17px; height: 17px; color: var(--brand-accent); flex-shrink: 0; }

/* --- Lado derecho: el formulario --- */

.auth-card__panel {
    padding: 44px 40px;
    color: #e8ecf4;
}

@media (max-width: 640px) {
    .auth-card__panel { padding: 32px 24px; }
    .auth-card__media { padding: 16px; }
    .auth-card__frame { min-height: 150px; padding: 18px; }
    .auth-card__features { display: none; }
}

.auth-card__title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: #fff;
    margin-bottom: var(--space-2);
    letter-spacing: -0.022em;
}

.auth-card__subtitle {
    color: rgba(232, 236, 244, 0.62);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-6);
}

.auth-card .form-label {
    color: rgba(232, 236, 244, 0.82);
    font-size: var(--font-size-sm);
}

.auth-card .input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.13);
    color: #fff;
    height: 46px;
}

.auth-card .input::placeholder { color: rgba(232, 236, 244, 0.38); }

.auth-card .input:hover { border-color: rgba(255, 255, 255, 0.22); }

.auth-card .input:focus {
    border-color: var(--brand-primary);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 30%, transparent);
}

.auth-card__submit {
    width: 100%;
    height: 50px;
    margin-top: var(--space-2);
    border: 0;
    border-radius: 12px;
    background: color-mix(in srgb, var(--brand-accent) 72%, #ffffff);
    color: #17130a;
    font-size: var(--font-size-base);
    font-weight: 640;
    cursor: pointer;
    transition: filter var(--transition), transform var(--transition);
}

.auth-card__submit:hover { filter: brightness(1.05); }
.auth-card__submit:active { transform: translateY(1px); }

.auth-card__submit:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.auth-card__footer {
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    font-size: var(--font-size-xs);
    color: rgba(232, 236, 244, 0.46);
    text-align: center;
}

.auth-card .alert {
    background: rgba(180, 35, 24, 0.16);
    border-color: rgba(240, 120, 110, 0.32);
    color: #ffd7d3;
}

.auth-card .alert svg { color: #ff9c92; }


/* ==========================================================================
   23. INSTALADOR
   ========================================================================== */

.install-shell {
    min-height: 100vh;
    background: var(--bg-canvas);
    display: flex;
    flex-direction: column;
}

.install-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-4) var(--space-8);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.install-header__logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    padding: 4px;
    border: 1px solid var(--border-color);
}

.install-steps {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
    flex-wrap: wrap;
}

.install-step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    padding: var(--space-1) var(--space-2);
}

.install-step__num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: var(--font-size-xs);
    font-weight: 700;
    background: var(--bg-muted);
    color: var(--text-muted);
    flex-shrink: 0;
    transition: all var(--transition);
}

.install-step.is-active { color: var(--text-strong); font-weight: 600; }
.install-step.is-active .install-step__num { background: var(--brand-primary); color: var(--text-inverse); }
.install-step.is-done .install-step__num { background: var(--color-success); color: #fff; }

.install-body {
    flex: 1;
    padding: var(--space-10) var(--space-8);
    max-width: 980px;
    margin: 0 auto;
    width: 100%;
}

.requirements { display: grid; gap: var(--space-2); }

.requirement {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    transition: border-color var(--transition);
}

.requirement--ok { border-left: 3px solid var(--color-success); }
.requirement--warn { border-left: 3px solid var(--color-warning); }
.requirement--fail { border-left: 3px solid var(--color-danger); }

.requirement__icon { flex-shrink: 0; line-height: 0; margin-top: 2px; }
.requirement__icon svg { width: 19px; height: 19px; }
.requirement--ok .requirement__icon { color: var(--color-success); }
.requirement--warn .requirement__icon { color: var(--color-warning); }
.requirement--fail .requirement__icon { color: var(--color-danger); }

.requirement__name { font-weight: 620; color: var(--text-strong); font-size: var(--font-size-base); }
.requirement__detail { font-size: var(--font-size-sm); color: var(--text-muted); }
.requirement__value { font-family: var(--font-mono); font-size: var(--font-size-xs); color: var(--text-subtle); margin-top: 2px; }

.identity-preview {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.identity-preview__bar {
    background: var(--brand-primary);
    padding: var(--space-4) var(--space-5);
    color: #fff;
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.identity-preview__logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.identity-preview__name { font-weight: 640; font-size: var(--font-size-md); }
.identity-preview__sub { font-size: var(--font-size-sm); opacity: 0.85; }
.identity-preview__body { padding: var(--space-5); }

/* Vista previa de la imagen de la pantalla de acceso. */
.identity-preview__image {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-bottom: 1px solid var(--border-color);
}

.identity-preview .checkbox {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
}

/* Vista previa de la apariencia (barra lateral y tipografía). */
.appearance-preview {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-height: 156px;
}

.appearance-preview__sidebar {
    background: var(--bg-sidebar);
    color: #fff;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.appearance-preview__brand {
    font-weight: 650;
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-2);
}

.appearance-preview__link {
    padding: 4px 6px;
    border-radius: var(--radius-xs);
    font-size: var(--font-size-xs);
    color: rgba(255, 255, 255, 0.72);
}

.appearance-preview__link.is-active {
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
}

.appearance-preview__body {
    padding: var(--space-4);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    justify-content: center;
}

.appearance-preview__title {
    font-weight: 650;
    font-size: var(--font-size-md);
    color: var(--text-strong);
}

.appearance-preview__text {
    color: var(--text-muted);
    font-size: var(--font-size-base);
}

.color-picker { display: flex; align-items: center; gap: var(--space-2); }

.color-picker input[type="color"] {
    width: 44px;
    height: 40px;
    padding: 3px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    cursor: pointer;
}

.preview-swatch {
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    flex: 1;
}

/* ==========================================================================
   24. PALETA DE COMANDOS
   ========================================================================== */

.command-palette {
    position: fixed;
    inset: 0;
    z-index: 180;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    background: rgba(11, 17, 28, 0.5);
    backdrop-filter: blur(3px);
}

.command-palette.is-open { display: flex; animation: backdrop-in 140ms var(--ease); }

.command-palette__box {
    width: 100%;
    max-width: 620px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: modal-in 200ms var(--ease-out);
}

.command-palette__input {
    width: 100%;
    height: 56px;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--space-5);
    font-family: inherit;
    font-size: var(--font-size-md);
    color: var(--text-strong);
    background: transparent;
    outline: none;
}

.command-palette__input::placeholder { color: var(--text-subtle); }

.command-palette__list {
    max-height: 340px;
    overflow-y: auto;
    padding: var(--space-2);
}

.command-palette__group {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    color: var(--text-subtle);
    font-weight: 640;
    padding: var(--space-3) var(--space-3) var(--space-1);
}

.command-palette__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-body);
    font-size: var(--font-size-base);
}

.command-palette__item svg { width: 17px; height: 17px; opacity: 0.65; flex-shrink: 0; }
.command-palette__item:hover,
.command-palette__item.is-active { background: var(--brand-soft); color: var(--text-strong); }
.command-palette__item strong { font-weight: 620; color: var(--text-strong); }
.command-palette__meta { margin-left: auto; font-size: var(--font-size-xs); color: var(--text-subtle); }

.command-palette__empty {
    padding: var(--space-8);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-base);
}

.command-palette__footer {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
    font-size: var(--font-size-xs);
    color: var(--text-subtle);
}

.command-palette__footer kbd {
    font-family: var(--font-sans);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    padding: 0 5px;
    margin-right: 3px;
}

/* ==========================================================================
   25. ASISTENTE DE INTELIGENCIA ARTIFICIAL
   ========================================================================== */

.ai-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--space-6);
    align-items: start;
}

.ai-layout__main,
.ai-layout__side { min-width: 0; }

.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.ai-chip {
    display: inline-flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-body);
    font-size: var(--font-size-sm);
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.ai-chip:hover:not(:disabled) {
    border-color: var(--brand-400);
    background: var(--brand-soft);
    color: var(--brand-600);
}

.ai-chip:disabled { opacity: 0.55; cursor: not-allowed; }

.ai-tools {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-3);
}

.ai-tool {
    padding: var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.ai-tool__name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-strong);
}

.ai-tool__description {
    margin: var(--space-1) 0 0;
    font-size: var(--font-size-sm);
    line-height: 1.45;
    color: var(--text-muted);
}

.ai-history {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    max-height: 420px;
    overflow-y: auto;
}

.ai-history__item {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition);
}

.ai-history__item:hover { background: var(--bg-muted); }

.ai-history__title {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 550;
    color: var(--text-strong);
    line-height: 1.4;
}

.ai-history__meta {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.ai-report {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.ai-report__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-subtle);
}

.ai-report__title {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 650;
    letter-spacing: var(--tracking-tight);
    color: var(--text-strong);
}

.ai-report__meta {
    margin: var(--space-1) 0 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.ai-report__question {
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}

.ai-report__question-label {
    display: inline-block;
    margin-bottom: var(--space-1);
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
}

.ai-report__question p {
    margin: 0;
    font-size: var(--font-size-base);
    color: var(--text-body);
}

.ai-report__summary {
    margin: 0;
    padding: var(--space-5) var(--space-6);
    font-size: var(--font-size-md);
    line-height: var(--line-height-relaxed);
    color: var(--text-body);
}

.ai-report__section { padding: 0 var(--space-6) var(--space-5); }

.ai-report__section-title {
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-md);
    font-weight: 650;
    color: var(--text-strong);
}

.ai-report__section p {
    margin: 0;
    line-height: var(--line-height-relaxed);
    color: var(--text-body);
}

.ai-report__list {
    margin: 0;
    padding-left: var(--space-5);
    line-height: var(--line-height-relaxed);
    color: var(--text-body);
}

.ai-report__list li { margin-bottom: var(--space-2); }
.ai-report__list li:last-child { margin-bottom: 0; }
.ai-report__list--accent li::marker { color: var(--brand-accent); }
.ai-report__list--muted { color: var(--text-muted); font-size: var(--font-size-sm); }

.ai-report__table-note {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.ai-report__footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
}

.ai-report__footer-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--text-subtle);
}

.ai-report__sources {
    margin: var(--space-2) 0 0;
    padding: 0;
    list-style: none;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.ai-sources-list {
    margin: 0;
    padding-left: var(--space-5);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    color: var(--text-body);
}

.ai-sources-list li { margin-bottom: var(--space-1); }

.ai-report__sources li { margin-bottom: var(--space-1); }

@media (max-width: 1080px) {
    .ai-layout { grid-template-columns: minmax(0, 1fr); }
    .ai-history { max-height: 300px; }
}

@media (max-width: 640px) {
    .ai-report__header { flex-direction: column; padding: var(--space-4); }
    .ai-report__summary { padding: var(--space-4); }
    .ai-report__section { padding: 0 var(--space-4) var(--space-4); }
    .ai-report__question,
    .ai-report__footer { padding: var(--space-4); }
}

/* ==========================================================================
   26. IMPRESIÓN
   ========================================================================== */

@media print {
    .sidebar,
    .topbar,
    .page-header__actions,
    .toolbar,
    .pagination,
    .no-print { display: none !important; }

    .app-main { margin-left: 0; }
    .app-body { padding: 0; }
    .card { border: 1px solid #ccc; box-shadow: none; }
}

/* ==========================================================================
   27. ADAPTACIÓN A PANTALLAS PEQUEÑAS
   ========================================================================== */

@media (max-width: 1280px) {
    .app-body { padding: var(--space-6); }
    .topbar { padding: 0 var(--space-6); }
}

@media (max-width: 1080px) {
    .form-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .command-trigger { min-width: 0; }
    .command-trigger__label, .command-trigger kbd { display: none; }
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
        width: var(--sidebar-width);
    }

    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(11, 17, 28, 0.45);
        z-index: 55;
        animation: backdrop-in 160ms var(--ease);
    }

    .app-main { margin-left: 0; }
    body.sidebar-collapsed .app-main { margin-left: 0; }

    .app-body { padding: var(--space-4); }
    .topbar { padding: 0 var(--space-4); }
    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
    .form-grid--2, .form-grid--3, .form-grid--4 { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header__title { font-size: var(--font-size-xl); }
    .modal-backdrop { padding: var(--space-4) var(--space-2); }
    .toast-container { left: var(--space-3); right: var(--space-3); max-width: none; }
    .toolbar { padding: var(--space-3) var(--space-4); }
    .toolbar__search { max-width: none; }
    .install-header { padding: var(--space-3) var(--space-4); }
    .install-body { padding: var(--space-6) var(--space-4); }
    .auth-main { padding: var(--space-6) var(--space-4); }
}

@media (max-width: 640px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
    .stat-card { padding: var(--space-4); }
    .stat-card__value { font-size: var(--font-size-2xl); }
    .stat-card__icon { width: 34px; height: 34px; }
    .card__header, .card__body { padding: var(--space-4); }
    .card__header { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
    .toolbar { padding: var(--space-3); }
    .toolbar__filters { width: 100%; }
    .toolbar__filters .input,
    .toolbar__filters .select { max-width: none; flex: 1 1 140px; }
    .page-header__actions { width: 100%; }
    .page-header__actions .btn { flex: 1 1 auto; }
    .topbar__title {
        font-size: var(--font-size-md);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
        flex: 1;
    }
    /* La barra superior no cabe: el control de densidad pasa al menú de usuario. */
    #densityToggle { display: none; }
    .modal__body, .modal__header, .modal__footer { padding: var(--space-4); }
    .modal__footer .btn { flex: 1 1 auto; }
    .pagination { justify-content: center; }
    .pagination__info { width: 100%; text-align: center; }
    .empty-state { padding: var(--space-8) var(--space-4); }
    .chart-bars { height: 160px; }
    .donut { width: 128px; height: 128px; }
}

/* Objetivos táctiles: 44 px en punteros gruesos */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .btn--sm { min-height: 38px; }
    .btn--icon { width: 44px; height: 44px; }
    .icon-btn { width: 44px; height: 44px; }
    .topbar__toggle { width: 44px; height: 44px; }
    .page-btn { min-width: 44px; height: 44px; }
    .input, .select { height: 44px; }
    .modal__close { padding: var(--space-2); }
}

/* Respeta la preferencia de movimiento reducido */
@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;
    }

    .spinner { animation: spin 1.2s linear infinite !important; }
    .skeleton { animation: none !important; }

    /* Sin animación la barra indeterminada se dibuja fija: si no, el
       recorrido en bucle la dejaría fuera del carril y no se vería. */
    .progress--indeterminate .progress__bar {
        width: 100% !important;
        transform: none !important;
        opacity: 0.45;
    }
}

/* Impresión en alto contraste */
@media (forced-colors: active) {
    .btn, .input, .select, .card, .stat-card { border: 1px solid CanvasText; }
}
