/* ============================================================================
   theme.css — Estilos base con CSS variables
   ============================================================================
   Los colores reales se inyectan dinámicamente desde ThemeManager::cssVariables()
   en <style> del <head>. Este archivo define los estilos estructurales.
   ============================================================================ */

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

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

body {
    margin: 0;
    font-family: var(--fuente-base, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    font-size: var(--tamano-base, 16px);
    line-height: 1.5;
    color: var(--color-texto, #212529);
    background: var(--color-fondo, #ffffff);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Reseteo básico */
h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5em; font-weight: 600; line-height: 1.25; }
p { margin: 0 0 1em; }
a { color: var(--color-primario, #0056b3); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

/* Foco visible para accesibilidad (WCAG 2.4.7) */
*:focus-visible {
    outline: 3px solid var(--color-primario, #0056b3);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Skip link (WCAG 2.4.1) */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    padding: 0.5rem 1rem;
    background: var(--color-primario, #0056b3);
    color: #ffffff;
    z-index: 9999;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus {
    top: 0;
}

/* Visualmente oculto pero accesible para lectores de pantalla */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ============================================================================
   Layout principal
   ============================================================================ */
.layout {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
}

.header {
    background: var(--color-superficie, #f8f9fa);
    border-bottom: 1px solid var(--color-borde, #dee2e6);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primario, #0056b3);
    text-decoration: none;
}

.nav-main {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-main a {
    color: var(--color-texto, #212529);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-weight: 500;
}

.nav-main a:hover, .nav-main a[aria-current="page"] {
    background: var(--color-primario, #0056b3);
    color: #ffffff;
}

.main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.footer {
    background: var(--color-superficie, #f8f9fa);
    border-top: 1px solid var(--color-borde, #dee2e6);
    padding: 1rem 2rem;
    text-align: center;
    color: var(--color-secundario, #6c757d);
    font-size: 0.875rem;
}

/* ============================================================================
   Componentes básicos
   ============================================================================ */
.card {
    background: var(--color-fondo, #ffffff);
    border: 1px solid var(--color-borde, #dee2e6);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all 0.15s ease;
    min-height: 44px;
    min-width: 44px;
    line-height: 1.25;
}

.btn-primary {
    background: var(--color-primario, #0056b3);
    color: #ffffff;
}
.btn-primary:hover { filter: brightness(0.9); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    color: var(--color-primario, #0056b3);
    border-color: var(--color-primario, #0056b3);
}
.btn-secondary:hover { background: var(--color-superficie, #f8f9fa); }

.btn-danger { background: var(--color-error, #dc3545); color: #ffffff; }
.btn-success { background: var(--color-exito, #198754); color: #ffffff; }
.btn-warning { background: var(--color-advertencia, #ffc107); color: var(--color-texto, #212529); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; min-height: 36px; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.9375rem;
}
.form-control {
    display: block;
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--color-borde, #dee2e6);
    border-radius: 6px;
    background: var(--color-fondo, #ffffff);
    color: var(--color-texto, #212529);
    min-height: 44px;
}
.form-control:focus-visible {
    border-color: var(--color-primario, #0056b3);
    outline: 3px solid var(--color-primario, #0056b3);
    outline-offset: 0;
}
.form-help { font-size: 0.8125rem; color: var(--color-secundario, #6c757d); margin-top: 0.25rem; }
.form-error { color: var(--color-error, #dc3545); font-size: 0.875rem; margin-top: 0.25rem; }

/* Tablas */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-fondo, #ffffff);
    border: 1px solid var(--color-borde, #dee2e6);
    border-radius: 6px;
    overflow: hidden;
}
.table th, .table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-borde, #dee2e6);
}
.table th {
    background: var(--color-superficie, #f8f9fa);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.table tbody tr:hover { background: var(--color-superficie, #f8f9fa); }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    border-left: 4px solid;
}
.alert-success { background: #d1e7dd; border-color: var(--color-exito, #198754); color: #0a3622; }
.alert-error   { background: #f8d7da; border-color: var(--color-error, #dc3545);  color: #58151c; }
.alert-warning { background: #fff3cd; border-color: var(--color-advertencia, #ffc107); color: #664d03; }
.alert-info    { background: #cff4fc; border-color: var(--color-info, #0dcaf0); color: #055160; }

/* Modo oscuro automático (si el SO lo prefiere y no hay override) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-fondo: #1a1d23;
        --color-superficie: #222831;
        --color-texto: #f8f9fa;
        --color-borde: #2d3139;
        --color-secundario: #adb5bd;
    }
}

/* Densidades */
[data-density="compact"] .form-control,
[data-density="compact"] .btn {
    padding: 0.5rem 0.75rem;
    min-height: 38px;
    font-size: 0.9375rem;
}

[data-density="comfy"] .form-control,
[data-density="comfy"] .btn {
    padding: 0.75rem 1rem;
    min-height: 50px;
}

/* Responsive */
@media (max-width: 768px) {
    .header { padding: 1rem; flex-direction: column; align-items: stretch; }
    .nav-main { justify-content: center; }
    .main { padding: 1rem; }
    .table { font-size: 0.875rem; }
    .table th, .table td { padding: 0.5rem; }
}

/* ============================================================================
   WCAG 2.1 AA - Mejoras de accesibilidad
   ============================================================================ */

/* Multiple skip links */
.skip-links {
    position: absolute;
    top: 0; left: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
}
.skip-link { margin: 0; }

/* Mejor focus para botones */
button:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--color-acento, #0d6efd);
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(13, 110, 253, 0.3);
}

/* Mejor focus para inputs */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--color-acento, #0d6efd);
    outline-offset: 1px;
    border-color: var(--color-acento, #0d6efd);
}

/* Focus para table rows al tabular */
table tbody tr:focus-within {
    background: rgba(0, 86, 179, 0.08);
}

/* Links en cuerpo con mejor contraste (≥ 4.5:1) */
.card a:not(.btn) {
    text-decoration: underline;
    text-underline-offset: 2px;
}
.card a:not(.btn):hover {
    text-decoration-thickness: 2px;
}

/* Texto más legible */
body {
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
}

/* Reducir motion si usuario lo prefiere */
@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;
    }
}

/* Contraste alto si usuario lo prefiere */
@media (prefers-contrast: more) {
    body {
        background: #fff;
        color: #000;
    }
    .card {
        border: 2px solid #000;
    }
    a:not(.btn) {
        color: #0000EE;
        text-decoration: underline;
    }
}

/* Forzar tamaño mínimo de área clickeable (44x44 px - WCAG 2.5.5) */
button.btn, a.btn, input[type="checkbox"], input[type="radio"] {
    min-height: 36px;
}
input[type="checkbox"], input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
    cursor: pointer;
}

/* Labels visibles (WCAG 3.3.2) */
label {
    display: inline-block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

/* Mensajes de error con iconos y buen contraste */
.alert-error,
.error-message {
    color: #58151c;
    background: #f8d7da;
    border-left: 4px solid var(--color-error, #dc3545);
    padding: 0.75rem 1rem;
}

/* Indicador de requerido visible */
.form-label .required,
label .required,
[aria-required="true"] + *::before {
    /* indicador se aplica desde HTML con <span aria-hidden>*</span> */
}

/* Inputs inválidos con aria-invalid */
[aria-invalid="true"] {
    border-color: var(--color-error, #dc3545);
    background: #fff5f5;
}
[aria-invalid="true"]:focus-visible {
    outline-color: var(--color-error, #dc3545);
}

/* Fieldset/legend accesibles */
fieldset {
    border: 1px solid var(--color-borde, #dee2e6);
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
}
legend {
    padding: 0 0.5rem;
    font-weight: 600;
    color: var(--color-primario, #0056b3);
}

/* Tablas accesibles */
table caption {
    text-align: left;
    caption-side: top;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-secundario);
}

/* Roles ARIA ya estructurados en HTML, no hace falta más */

/* Theme oscuro (si se activa en el futuro) */
@media (prefers-color-scheme: dark) {
    /* Por ahora respeta el tema del usuario; el ThemeManager maneja los colores */
}

/* Asegurar que el documento siempre tiene buen contraste de fondo */
body {
    background-color: var(--color-fondo, #ffffff);
}

/* ============================================================
   APP LAYOUT: topbar + sidebar (UX fix 2026-06-23)
   ============================================================ */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
    background: var(--color-fondo, #f4f6f8);
}

/* SIDEBAR */
.sidebar {
    background: linear-gradient(180deg, #002952 0%, #003d80 100%);
    box-shadow: 4px 0 16px rgba(0, 41, 82, 0.12);
    padding: 0;
    display: flex;
    flex-direction: column;
    color: #fff;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: background 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}
.sidebar-link:hover,
.sidebar-link:focus-visible {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-left-color: var(--color-acento, #ffc107);
    font-weight: 600;
}
.sidebar-icon {
    font-size: 1.15rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
}
.sidebar-label {
    flex: 1;
}
.nav-badge {
    background: var(--color-error, #dc3545);
    color: #fff;
    border-radius: 999px;
    padding: 0.05rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 1.5rem;
    text-align: center;
}

/* MAIN WRAPPER */
.app-main-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* TOPBAR */
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--color-borde, #dee2e6);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.topbar-center {
    flex: 1;
    min-width: 0;
}
.topbar-brand {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-primario, #003366);
    text-decoration: none;
}
.topbar-brand:hover { text-decoration: underline; }

.topnav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}
.topnav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.85rem;
    color: var(--color-secundario, #495057);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease;
}
.topnav-link:hover,
.topnav-link:focus-visible {
    background: var(--color-superficie, #e9ecef);
    color: var(--color-primario, #003366);
}
.topnav-link.active {
    background: var(--color-primario, #003366);
    color: #fff;
    font-weight: 600;
}
.topnav-link.active .nav-badge { background: #fff; color: var(--color-primario); }

/* USER MENU */
.user-menu { position: relative; }
.user-menu-btn {
    background: transparent;
    border: 1px solid var(--color-borde);
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-texto);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.user-menu-btn:hover { background: var(--color-superficie); }
.user-menu-btn:focus-visible { outline: 2px solid var(--color-primario); outline-offset: 2px; }
.user-menu-btn small { color: var(--color-secundario); }
.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--color-borde);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    min-width: 200px;
    z-index: 100;
    padding: 0.5rem 0;
}
.user-menu-dropdown a,
.user-menu-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.6rem 1rem;
    color: var(--color-texto);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
}
.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover { background: var(--color-superficie); }
.user-menu-dropdown hr { margin: 0.35rem 0; border: 0; border-top: 1px solid var(--color-borde); }
.user-menu-logout { color: var(--color-error); font-weight: 600; }

/* MOBILE TOGGLE */
.mobile-nav-toggle {
    background: transparent;
    border: 1px solid var(--color-borde);
    border-radius: 6px;
    width: 38px;
    height: 38px;
    font-size: 1.25rem;
    cursor: pointer;
    display: none;
    color: var(--color-texto);
}
.mobile-nav-toggle:hover { background: var(--color-superficie); }
.mobile-nav-toggle:focus-visible { outline: 2px solid var(--color-primario); }

/* MOBILE DRAWER */
.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
}
.mobile-drawer[data-open="true"] { display: block; }
.mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    animation: fade-in 0.2s ease;
}
.mobile-drawer-content {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: min(280px, 85vw);
    background: var(--color-primario, #003366);
    color: #fff;
    overflow-y: auto;
    animation: slide-in 0.25s ease;
}
.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}
.mobile-drawer-title { font-weight: 600; }
.mobile-drawer-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

/* BREADCRUMBS */
.breadcrumbs {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--color-secundario);
}
.breadcrumbs ol {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}
.breadcrumbs li { display: inline-flex; align-items: center; }
.breadcrumbs a {
    color: var(--color-primario, #003366);
    text-decoration: none;
}
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs span[aria-current="page"] {
    color: var(--color-texto);
    font-weight: 600;
}
.breadcrumb-sep { margin: 0 0.25rem; opacity: 0.5; }

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: #fff;
    border: 1px dashed var(--color-borde);
    border-radius: 8px;
    color: var(--color-secundario);
}
.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.6;
}
.empty-state h3 {
    color: var(--color-texto);
    margin: 0 0 0.5rem;
}
.empty-state p { margin: 0 0 1rem; }

/* RESPONSIVE */
@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
    /* En móvil el sidebar vive DENTRO del drawer (no en el grid) */
    .app-layout > .sidebar { display: none; }
    .mobile-nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .topnav-list { gap: 0.15rem; }
    .topnav-link { padding: 0.35rem 0.55rem; font-size: 0.825rem; }
    .topnav-link span:last-child { display: none; } /* sólo icono en móvil */
    .topnav-link span:first-child { font-size: 1.1rem; }
    .topbar-brand-text { font-size: 0.95rem; }
    .user-menu-btn .user-info { display: none; }
}

@media (max-width: 900px) {
    .topbar-context-title { display: none; }
    .topbar-search-kbd { display: none; }
    .topbar-search { max-width: 100%; }
}
@media (max-width: 600px) {
    .topbar { padding: 0 0.75rem; gap: 0.5rem; }
    .topbar-center { display: none; } /* en mobile el search está en el drawer */
    .topbar-right { margin-left: auto; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header-actions { width: 100%; }
    .kpi-grid { grid-template-columns: 1fr 1fr !important; }
    .quick-actions { grid-template-columns: 1fr 1fr !important; }
}

/* Drawer mobile: sidebar adentro */
.mobile-drawer-content .sidebar {
    position: static;
    height: auto;
    width: 100%;
    box-shadow: none;
    display: flex !important;
}

@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; padding: 0.5rem 0.75rem; }
    .topbar-center { order: 3; width: 100%; }
    .topbar-right { margin-left: auto; }
}

/* Animaciones */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slide-in {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
    .mobile-drawer-backdrop,
    .mobile-drawer-content {
        animation: none;
    }
}

/* ============================================================
   PAGE HEADER (migas + título + acciones)
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-borde, #dee2e6);
}
.page-header-main { flex: 1; min-width: 240px; }
.page-title {
    font-size: 1.625rem;
    font-weight: 700;
    color: var(--color-texto, #212529);
    margin: 0;
    line-height: 1.2;
}
.page-subtitle {
    color: var(--color-secundario, #6c757d);
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
}
.page-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
@media (max-width: 600px) {
    .page-title { font-size: 1.35rem; }
}

/* ============================================================
   UX FIX EXPERT 2026-06-23: mobile + tablas + responsive
   ============================================================ */

/* Topbar móvil: ocultar items del menú (queda sólo brand + ☰ + user-menu) */
@media (max-width: 900px) {
    .topbar-center { display: none !important; }
}

/* KPIs: 2 columnas en móvil en vez de 1 */
@media (max-width: 600px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem;
    }
    .kpi-card { padding: 0.65rem 0.75rem; }
    .kpi-num { font-size: 1.5rem; }
    .kpi-num-sm { font-size: 1rem; }
    .kpi-card small { font-size: 0.7rem; }
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    .quick-action { padding: 0.65rem 0.5rem; }
    .quick-action-icon { font-size: 1.4rem; }
    .dashboard-hero {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .dashboard-cta { justify-content: center; }
}

/* Tablas: scroll horizontal en móvil, headers con nowrap */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0.5rem 0;
}
.table-responsive .table { margin: 0; }
.table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
}
.table th, .table td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-borde);
    vertical-align: top;
}
.table th {
    background: var(--color-superficie);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-secundario);
    white-space: nowrap;
}
.table .num { text-align: right; white-space: nowrap; }

/* Lista de versiones (colapsable) */
.versions-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
}
.versions-list li {
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--color-borde);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.versions-list li:last-child { border-bottom: 0; }
.versions-list small.text-muted {
    color: var(--color-secundario);
    font-size: 0.825rem;
}

/* Contenedor de acciones inline que se rompe en móvil */
.action-bar {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}
.action-bar form { display: inline; }

/* Botón peligro más visible */
.btn-danger {
    background: var(--color-error, #dc3545);
    color: #fff;
    border: 1px solid var(--color-error, #dc3545);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
}
.btn-danger:hover { background: #c82333; border-color: #bd2130; color: #fff; }
.btn-danger:focus-visible { outline: 2px solid var(--color-error); outline-offset: 2px; }

/* Topbar brand en móvil más pequeño */
@media (max-width: 600px) {
    .topbar-brand { font-size: 1rem; }
    .user-menu small { display: none; } /* ocultar rol en móvil */
}

/* Estilo sr-only de Bootstrap-like */
.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;
}

/* Paginación */
.pagination {
    display: flex;
    gap: 0.25rem;
    margin: 1rem 0;
    justify-content: center;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--color-borde);
    border-radius: 4px;
    text-decoration: none;
    color: var(--color-texto);
    font-size: 0.875rem;
    min-width: 2rem;
    text-align: center;
}
.pagination a:hover { background: var(--color-superficie); }
.pagination .active {
    background: var(--color-primario);
    color: #fff;
    border-color: var(--color-primario);
}
.pagination .disabled { color: var(--color-secundario); cursor: not-allowed; }

/* Skip link WCAG */
.skip-link {
    position: absolute;
    left: -10000px;
    top: 0;
    background: var(--color-primario);
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 9999;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}
.skip-link:focus { left: 0; }

/* Focus visible global */
:focus-visible {
    outline: 2px solid var(--color-primario, #003366);
    outline-offset: 2px;
}

/* Respetar usuarios que no quieren animaciones */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* KPI grid: 6 columnas en desktop ancho, 3 en medio, 2 en móvil */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Badges: nowrap para que no se corten */
.badge { white-space: nowrap; }

/* A11y fix 2026-06-23: contraste WCAG AA en headers y footer */
.table th {
    color: #495057; /* era var(--color-secundario) #6c757d — subió contraste */
}
footer p, footer { color: #495057; }
/* Skip-link visible */
.skip-link {
    background: var(--color-primario, #003366);
    color: #fff;
    z-index: 9999;
}

/* A11y fix v2: contraste headers */
.table th {
    color: #1a1d20 !important;
    background: #e9ecef !important;
}

/* Variantes de badges (movidos desde dashboard.php para uso global) */
.badge { white-space: nowrap; }
.badge-success { background: #198754; color: #fff; }
.badge-error   { background: #dc3545; color: #fff; }
.badge-warning { background: #b88300; color: #fff; }
.badge-info    { background: #0dcaf0; color: #0c4a5a; }
.badge-secondary { background: #495057; color: #fff; }

/* Combobox (cliente search) */
.combobox-listbox {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-borde);
    border-top: 0;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-height: 280px;
    overflow-y: auto;
    list-style: none;
    padding: 0.25rem 0;
    margin: 0;
    z-index: 100;
}
.combobox-listbox li {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    border-bottom: 1px solid var(--color-superficie);
}
.combobox-listbox li:last-child { border-bottom: 0; }
.combobox-listbox li:hover,
.combobox-listbox li.active,
.combobox-listbox li[aria-selected="true"] {
    background: var(--color-superficie);
}
.combobox-listbox li.create-new {
    color: var(--color-primario);
    font-weight: 600;
    background: #f0f7ff;
}
.combobox-listbox li.create-new:hover { background: #d6e7ff; }
.combobox-listbox .cb-rut {
    font-size: 0.75rem;
    color: var(--color-secundario);
}
.combobox-listbox .cb-empty {
    padding: 0.75rem;
    color: var(--color-secundario);
    text-align: center;
    font-style: italic;
}

/* Admin tabs (nav dentro de página de configuración) */
.admin-tabs {
    margin: 0 0 1.5rem 0;
    border-bottom: 1px solid var(--color-borde);
    overflow-x: auto;
}
.admin-tabs ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0;
}
.admin-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.65rem 1rem;
    color: var(--color-secundario, #495057);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.admin-tab:hover { color: var(--color-primario, #003366); }
.admin-tab.active {
    color: var(--color-primario, #003366);
    border-bottom-color: var(--color-primario, #003366);
    font-weight: 600;
}

/* Form groups: invertir orden label-small (label arriba, small abajo) */
.form-group { margin-bottom: 1rem; }
.form-group .form-label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    color: var(--color-texto);
}
.form-group small,
.form-group .form-help {
    display: block;
    margin-top: 0.25rem;
    margin-bottom: 0;
    color: var(--color-secundario, #495057);
    font-size: 0.825rem;
}

/* Cliente form: input RUT ancho + botón SII pequeño */
.client-form-grid {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: 1rem 1.25rem;
    align-items: start;
}
.client-form-grid > div:first-child {
    display: flex;
    flex-direction: column;
}
.client-form-grid #rut {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    margin-bottom: 0.4rem;
}
.client-form-grid #btn-sii {
    align-self: flex-start;        /* sólo lo ancho del texto */
    width: auto !important;
    padding: 0.35rem 0.85rem;
    font-size: 0.875rem;
    margin-bottom: 0.4rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.client-form-grid #rut-feedback,
.client-form-grid small[id="rut-feedback"] {
    display: block;                /* forzar block, no inline */
    width: 100%;
    clear: both;
    margin-top: 0;
}
@media (max-width: 720px) {
    .client-form-grid { grid-template-columns: 1fr; }
}

/* Banner informativo sobre SII */
.sii-info-banner {
    background: linear-gradient(135deg, #e7f3ff 0%, #f0f7ff 100%);
    border-left: 4px solid #0dcaf0;
    padding: 1rem 1.25rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
}
.sii-info-banner h3 { margin: 0 0 0.5rem; font-size: 1rem; color: #0c5460; }
.sii-info-banner p  { margin: 0 0 0.5rem; color: #0c5460; }
.sii-info-banner ul { margin: 0 0 0.5rem 1.25rem; padding: 0; color: #0c5460; }
.sii-info-banner code { background: rgba(0,0,0,0.05); padding: 0.1rem 0.4rem; border-radius: 3px; }

/* Badge del proveedor SII */
.sii-provider-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #d1ecf1;
    color: #0c5460;
    margin-left: 0.5rem;
    vertical-align: middle;
}
.sii-provider-badge.configured { background: #d4edda; color: #155724; }
.sii-provider-badge.empty { background: #f8d7da; color: #721c24; }

/* Portal: bloque "Quién emite" + equivalencia UF/CLP */
.empresa-emite {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-left: 4px solid var(--color-primario);
}
.empresa-emite h2 { color: var(--color-primario); }
.equiv-box {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: #f0f7ff;
    border-left: 4px solid #0dcaf0;
    border-radius: 4px;
    text-align: right;
    color: #0c5460;
}
.equiv-box strong { display: block; font-size: 1rem; margin-bottom: 0.2rem; }
.equiv-box small { display: block; color: var(--color-secundario); font-size: 0.8rem; margin-top: 0.2rem; }

/* ============================================================
   UX FIX 2026-06-24: Sidebar + Topbar rediseño + Logo
   ============================================================ */

/* Sidebar: gradiente + jerarquía + indicador activo moderno */
.app-layout {
    background: linear-gradient(135deg, #f8f9fa 0%, #eef2f7 100%);
}
.sidebar {
    background: linear-gradient(180deg, #002952 0%, #003d80 100%);
    box-shadow: 4px 0 16px rgba(0, 41, 82, 0.12);
    padding: 0;
    display: flex;
    flex-direction: column;
}
.sidebar-brand {
    padding: 1.5rem 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-decoration: none;
}
.sidebar-brand:hover { background: rgba(255,255,255,0.04); }
.sidebar-brand-logo-wrap {
    width: 64px; height: 64px;
    background: #fff;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    padding: 8px;
    overflow: hidden;
}
.sidebar-brand-logo {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}
.sidebar-brand-logo-fallback {
    width: 100%; height: 100%;
    background: linear-gradient(135deg, var(--color-primario, #003366) 0%, #0d6efd 100%);
    color: #fff;
    font-size: 2rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.sidebar-brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.sidebar-brand-sub {
    color: rgba(255,255,255,0.55);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.25rem;
    color: rgba(255,255,255,0.78);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    position: relative;
}
.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}
.sidebar-link.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: #ffc107;
    font-weight: 600;
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, #ffc107 0%, #ff8c00 100%);
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.6);
}
.sidebar-icon { font-size: 1.15rem; flex-shrink: 0; width: 1.5rem; text-align: center; }
.sidebar-label { flex: 1; }
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.75rem;
    color: rgba(255,255,255,0.45);
    text-align: center;
}

/* Topbar: sombra + avatar circular + mejor espaciado */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e3e8ef;
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
    z-index: 50;
    position: sticky;
    top: 0;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-center { flex: 1; display: flex; justify-content: center; max-width: 480px; margin: 0 auto; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* Título contextual de la sección actual */
.topbar-context { display: flex; flex-direction: column; min-width: 0; }
.topbar-context-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-secundario, #5a6168);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Buscador global */
.topbar-search {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 360px;
    background: #f4f6f8;
    border: 1px solid #e3e8ef;
    border-radius: 999px;
    padding: 0.3rem 0.4rem 0.3rem 0.85rem;
    gap: 0.5rem;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.topbar-search:focus-within {
    background: #fff;
    border-color: var(--color-primario, #003366);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}
.topbar-search-icon { color: var(--color-secundario); font-size: 0.9rem; }
.topbar-search input {
    flex: 1;
    border: 0;
    background: transparent;
    outline: none;
    font-size: 0.9rem;
    color: var(--color-texto, #1a1d20);
    min-width: 0;
}
.topbar-search input::placeholder { color: var(--color-secundario); }
.topbar-search-kbd {
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    font-size: 0.7rem;
    font-family: monospace;
    color: var(--color-secundario);
}

/* Botón de ayuda (ícono) */
.topbar-icon-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: #f4f6f8;
    border: 1px solid #e3e8ef;
    color: var(--color-secundario, #5a6168);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
}
.topbar-icon-btn:hover { background: var(--color-primario); color: #fff; border-color: var(--color-primario); }
.topbar-icon-btn:focus-visible { outline: 2px solid var(--color-primario); outline-offset: 2px; }

/* Topnav links: más limpios con indicador activo animado */
.topnav-list { gap: 0.15rem; }
.topnav-link {
    padding: 0.55rem 0.95rem;
    font-weight: 500;
    border-radius: 8px;
}
.topnav-link.active {
    background: linear-gradient(135deg, var(--color-primario) 0%, #0056b3 100%);
    box-shadow: 0 2px 8px rgba(0, 86, 179, 0.25);
}

/* Avatar circular en user-menu */
.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: transparent;
    border: 1px solid #e3e8ef;
    border-radius: 24px;
    padding: 0.3rem 0.85rem 0.3rem 0.35rem;
    transition: background 0.15s, border-color 0.15s;
}
.user-menu-btn:hover {
    background: #f4f6f8;
    border-color: var(--color-primario);
}
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primario) 0%, #0d6efd 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-menu-btn small {
    color: var(--color-secundario);
    font-size: 0.7rem;
}
.user-info { text-align: left; line-height: 1.15; }
.user-info strong { display: block; font-size: 0.85rem; color: var(--color-texto); }

/* ============================================================
   AUTH: Logo + título del sitio
   ============================================================ */
.auth-brand-logo {
    max-height: 60px;
    max-width: 220px;
    margin: 0 auto 1rem;
    display: block;
}
