/* ============================================================
   ESTILOS MEJORADOS PARA DASHBOARD MYG - MOBILE FIRST
   Versión: 2.2.0 - Poda de reglas muertas + doc de estrategia
   ============================================================

   ESTRATEGIA RESPONSIVE (leer antes de tocar este archivo):
   La responsividad real vive en los COMPONENTES vía utilidades
   Tailwind (grid-cols-1 md:grid-cols-N, flex-col md:flex-row, etc.).
   Este archivo aporta SOLO lo que Tailwind no cubre bien de forma
   global:
     · <table> scrollable en móvil (selector genérico, aplica a todas)
     · font-size:16px en inputs (evita zoom iOS)
     · área táctil mínima 44px en botones/enlaces
     · ventana del chatbot y panel de notificaciones (clases .chatbot-*
       / .notif-* que SÍ emiten sus componentes)
     · variables de tema, print, safe-area.

   ⚠️ NO reintroducir reglas por CLASE SEMÁNTICA (.dashboard-header,
   .stats-grid, .stat-card, .modal-content, .tab-button, .button-group,
   .form-grid, .user-menu-*): el DOM real usa utilidades Tailwind, esas
   clases nunca se emiten → reglas muertas. Se podaron en v2.2.0.
   Para un cambio responsive puntual, edítalo en el componente con
   utilidades Tailwind, no aquí. */

/* Reset y Base */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow-x: hidden;
}

/* ============================================================
   ANIMACIONES
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

@keyframes gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes notifSlideIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Aplicar animaciones */
.fade-in { animation: fadeIn 0.5s ease-out; }
.slide-in { animation: slideIn 0.3s ease-out; }
.animate-spin { animation: spin 1s linear infinite; }
.animate-pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
.float-animation { animation: float 3s ease-in-out infinite; }
.animated-gradient { background-size: 200% 200%; animation: gradient 15s ease infinite; }

/* ============================================================
   COMPONENTES MÓVILES
   ============================================================ */

/* (Podados en v2.2.0: bloques "Header Móvil" y "Tabs Móviles" — usaban
   clases semánticas .dashboard-header / .user-menu-* / .tabs-container /
   .tab-button que el DOM Tailwind nunca emite. El header y los tabs ya
   son responsive vía utilidades en sus componentes.) */

/* Tablas Móviles — [MOBILE-FIX] TODA tabla se vuelve scrollable horizontalmente
   sin necesidad de un wrapper por componente. Antes `min-width:800px` sin contenedor
   con scroll empujaba/recortaba el layout (desfase). Patrón display:block + scroll:
   el <table> es el contenedor que hace scroll; thead/tbody mantienen el layout de tabla. */
@media (max-width: 768px) {
    .table-container { overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; }
    table {
        display: block !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        font-size: 0.875rem !important;
    }
    table > thead, table > tbody, table > tfoot {
        display: table !important;
        width: 100% !important;
        min-width: max-content !important;
    }
    th, td { padding: 0.6rem 0.5rem !important; white-space: nowrap; }

    /* EXCEPCIÓN: tablas YA envueltas en su propio scroll (Tailwind .overflow-x-auto
       o .table-container) — varias traen columna sticky (left-0). Revertir el truco
       display:block para no romper la columna fija ni crear doble scroll; el wrapper
       ya hace el scroll horizontal. */
    .overflow-x-auto > table,
    .table-container > table { display: table !important; overflow: visible !important; min-width: max-content !important; }
    .overflow-x-auto > table > thead,
    .table-container > table > thead { display: table-header-group !important; min-width: 0 !important; }
    .overflow-x-auto > table > tbody,
    .table-container > table > tbody { display: table-row-group !important; min-width: 0 !important; }
    .overflow-x-auto > table > tfoot,
    .table-container > table > tfoot { display: table-footer-group !important; min-width: 0 !important; }
}

/* (Podados en v2.2.0: bloques "Cards Móviles" y "Modales Móviles" —
   usaban .stats-grid / .stat-card / .modal-* que el DOM Tailwind no
   emite. Las tarjetas KPI ya colapsan a 1 columna con grid-cols-1
   md:grid-cols-N; los modales usan w-full/max-w-* en su componente.) */

/* ============================================================
   BOTONES MÓVILES — solo reglas por selector GENÉRICO (no por clase)

   ⚠️ CAMBIO CRÍTICO v2.1: `button { width: 100% }` rompía botones
   flotantes, iconos, paginación y el chatbot — nunca reintroducir.
   v2.2.0: se podaron las reglas .button-group / .btn-full-mobile
   (clases semánticas muertas). Se conservan solo las de FAB/iconos,
   que aplican por selector genérico al DOM Tailwind real.
   ============================================================ */

@media (max-width: 768px) {
    /* Botones flotantes (FAB) — NUNCA ancho completo.
       [MOVIL] Sólo a los que NO declaran su ancho (w-N). Antes el `width:auto !important`
       le ganaba por especificidad (button.fixed = 0,1,1) al `.chatbot-fab { width:64px
       !important }` de abajo y a cualquier `w-16 h-16 rounded-full`: el botón del asistente
       quedaba en 28x64, una cápsula aplastada, en todas las pantallas del teléfono.
       `[class*=" w-"]` lleva el espacio a propósito: sin él, "shadow-" también contiene "w-". */
    .fab:not([class^="w-"]):not([class*=" w-"]),
    button.fixed:not([class^="w-"]):not([class*=" w-"]),
    [class*="fixed"][class*="rounded-full"]:not([class^="w-"]):not([class*=" w-"]),
    button[class*="rounded-full"]:not([class^="w-"]):not([class*=" w-"]) {
        width: auto !important;
        min-width: unset !important;
    }

    /* Botones de iconos — NO ancho completo. Los redondos se quedan redondos: un
       min-width de 44px sobre un w-8 h-8 rounded-full lo volvía óvalo de 44x32. */
    button:has(svg:only-child):not([class*="rounded-full"]),
    .btn-icon {
        width: auto !important;
        min-width: 44px !important;
    }
}

/* Botón FAB del chatbot — siempre circular */
.chatbot-fab {
    position: fixed !important;
    width: 64px !important;
    height: 64px !important;
    border-radius: 50% !important;
    bottom: 1.5rem !important;
    right: 1.5rem !important;
    z-index: 50 !important;
}

/* Formularios Móviles (selector genérico; .form-grid muerto podado v2.2.0) */
@media (max-width: 768px) {
    /* Evitar zoom automático en iOS al hacer focus */
    input, select, textarea { font-size: 16px !important; }
}

/* ============================================================
   CHATBOT MÓVIL — VENTANA RESPONSIVA
   ============================================================ */

/* Desktop: posición fija esquina inferior derecha */
.chatbot-window {
    position: fixed;
    bottom: 6rem;
    right: 1.5rem;
    width: 24rem;        /* 384px */
    height: 600px;
    max-height: calc(100vh - 8rem);
    border-radius: 1rem;
    z-index: 49;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

/* Móvil: ocupa casi toda la pantalla */
@media (max-width: 640px) {
    .chatbot-window {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100dvh !important;        /* dynamic viewport height */
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }

    /* El botón FAB sube cuando el chat está abierto */
    .chatbot-fab-open {
        bottom: calc(100dvh + 1rem) !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

/* ============================================================
   NOTIFICACIONES — PANEL RESPONSIVO
   ============================================================ */

/* Panel de notificaciones base */
.notif-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    width: 24rem;        /* 384px */
    max-height: 500px;
    border-radius: 0.75rem;
    z-index: 100;
    animation: notifSlideIn 0.2s ease-out;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

/* Móvil: panel centrado como sheet */
@media (max-width: 640px) {
    .notif-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-height: 80dvh !important;
        border-radius: 1rem 1rem 0 0 !important;
        animation: slideUp 0.25s ease-out !important;
    }
}

/* Overlay oscuro cuando el panel está abierto en móvil */
.notif-overlay {
    display: none;
}
@media (max-width: 640px) {
    .notif-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 99;
        animation: fadeIn 0.2s ease-out;
    }
}

/* ============================================================
   ACCESIBILIDAD TÁCTIL
   ============================================================ */

@media (max-width: 768px) {
    /* Área táctil mínima de 44×44px para elementos interactivos */
    button:not([class*="rounded-full"]),
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
    }

    /* Separar elementos de lista interactivos */
    .interactive-list > * { margin-bottom: 0.5rem !important; }
}

/* ============================================================
   OPTIMIZACIONES DE RENDIMIENTO
   ============================================================ */

.animated-element {
    will-change: transform;
    transform: translateZ(0);
}

/* [IMG-LAZY-INVISIBLE 2026-09-08] Aqui vivia un fundido de entrada:
       img[loading="lazy"]        { opacity: 0; transition: opacity 0.3s; }
       img[loading="lazy"].loaded { opacity: 1; }
   El JS que debia agregar la clase .loaded nunca se escribio. Resultado: TODA
   imagen con loading="lazy" cargaba bien (200 en la red, con su alto reservado)
   y se quedaba transparente para siempre. Falla silenciosa y dificil de ver:
   en DevTools la imagen existe y su peticion salio correcta.
   Se comio las capturas de la guia de la encuesta, las miniaturas de contenido
   y las imagenes del chat de Sistemas.
   Se BORRA en vez de "arreglarse": el navegador ya pinta la imagen al terminar
   de cargar, el fundido no hacia falta, y una regla que depende de un JS
   inexistente solo espera a la siguiente victima. Si algun dia se quiere el
   fundido, tiene que llegar junto con su onLoad que ponga la clase. */

/* ============================================================
   MEJORAS DE UX — HOVER/FOCUS
   ============================================================ */

/* Hover solo en dispositivos con puntero fino (mouse/trackpad) */
@media (hover: hover) and (pointer: fine) {
    button:hover, .btn:hover {
        transform: scale(1.02);
        transition: transform 0.2s ease;
    }
}

button:active, .btn:active { transform: scale(0.98); }

/* Focus visible para navegación por teclado */
*:focus-visible {
    outline: 3px solid #00B2E3;
    outline-offset: 2px;
}

.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #00B2E3;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ============================================================
   TEMAS Y VARIABLES CSS
   ============================================================ */

:root {
    --primary-color: #00B2E3;
    --secondary-color: #0897BA;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --error-color: #EF4444;
    --background-color: #F9FAFB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* Dark mode via html.dark class (controlled by toggle button) */
html.dark {
    --background-color: #111827;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --border-color: #374151;
}
/* [FIX contraste modo claro 2026-07-21] Se ELIMINÓ el bloque
   @media (prefers-color-scheme: dark) { :root:not(.light) { --text-primary:#F9FAFB … } }
   que estaba aquí. Era la causa de "texto casi invisible en modo claro":
   el toggle del tema (index.html + command-palette) prende/apaga SOLO la clase
   html.dark y NUNCA agrega .light, así que el guard :not(.light) jamás se
   cumplía. Para un usuario con SO en oscuro pero app en Claro, el media query
   forzaba --text-primary a #F9FAFB (casi blanco) mientras las tarjetas seguían
   con --bg-card #ffffff (theme.css) → texto blanco sobre blanco. El default por
   preferencia del SO ya lo cubre el script inline de index.html (agrega html.dark
   cuando no hay preferencia guardada y el SO está en oscuro), así que este bloque
   era redundante además de dañino. NO reintroducir sin un marcador .light real. */

/* ============================================================
   UTILIDADES RESPONSIVE
   ============================================================ */

@media (max-width: 768px) { .hide-mobile { display: none !important; } }
@media (min-width: 769px) { .hide-desktop { display: none !important; } }

.container-responsive { padding-left: 1rem; padding-right: 1rem; }
@media (min-width: 768px) {
    .container-responsive { padding-left: 2rem; padding-right: 2rem; }
}

/* ============================================================
   FIXES VARIOS
   ============================================================ */

body, html { overflow-x: hidden; max-width: 100vw; }

/* Fix para inputs en iOS — EXCLUYE checkbox/radio: appearance:none los vuelve
   invisibles (sin las clases del plugin forms de Tailwind, el box queda en blanco
   sin borde). Mantener su apariencia nativa para que la casilla se vea y sea clickeable. */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    -webkit-appearance: none; appearance: none;
}
/* Restaurar apariencia nativa explícitamente por si algún reset previo la quitó */
input[type="checkbox"], input[type="radio"] {
    -webkit-appearance: auto; appearance: auto;
}

.sticky-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

html.dark .sticky-header {
    background: var(--bg-card, #1e293b);
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/* Safe area iPhone */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    .no-print { display: none !important; }
    * { background: white !important; color: black !important; }
    @page { margin: 1cm; }
}