/* =========================================================
   CONTROL REMOTO RADAR — Design System v2
   Mobile-first. Breakpoints: móvil (<640px) · tablet (640–1023px) · desktop (≥1024px)
   ========================================================= */

:root {
    /* Color */
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #3b82f6;
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border-color: #e2e8f0;

    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 16px 32px -8px rgba(15, 23, 42, 0.14), 0 4px 8px -4px rgba(15, 23, 42, 0.06);
    --shadow-primary: 0 8px 20px -6px rgba(37, 99, 235, 0.35);

    /* Escala de espaciado (rem, base 16px) */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.5rem;
    --sp-6: 2rem;
    --sp-8: 3rem;

    /* Radios */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Tipografía fluida: crece de móvil a desktop sin saltos por breakpoint */
    --fs-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8rem);
    --fs-sm: clamp(0.85rem, 0.82rem + 0.15vw, 0.95rem);
    --fs-base: clamp(0.95rem, 0.92rem + 0.15vw, 1rem);
    --fs-lg: clamp(1.05rem, 1rem + 0.3vw, 1.15rem);
    --fs-xl: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
    --fs-2xl: clamp(1.5rem, 1.3rem + 1vw, 1.8rem);

    /* Altura mínima táctil (Apple/Material recomiendan 44–48px) */
    --tap-target: 44px;

    /* Ancho de la barra lateral en desktop */
    --sidebar-w: 260px;

    /* Alto de la barra inferior en móvil */
    --bottom-nav-h: 64px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-dark);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    font-size: var(--fs-base);
    /* Deja hueco para la barra inferior fija en móvil */
    padding-bottom: var(--bottom-nav-h);
}

.hidden { display: none !important; }

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--sp-5) var(--sp-4);
}

/* Accesibilidad: foco visible siempre, sin importar el dispositivo de entrada */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* =========================================
   CABECERA (HEADER)
   ========================================= */
.modern-header {
    background: var(--card-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    box-shadow: var(--shadow-xs);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 30;
}

.brand h1 { font-weight: 800; font-size: var(--fs-xl); color: var(--text-dark); letter-spacing: -0.5px; }
.brand h1 strong { color: var(--primary); }
.brand span { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; display: block; }

.user-controls {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
}

.user-details {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.user-name { font-weight: 600; font-size: var(--fs-sm); }

/* En móvil el nombre completo sobra: se oculta y se conserva solo el avatar/botón salir */
@media (max-width: 639px) {
    .user-name { display: none; }
    .brand span { display: none; }
}

/* =========================================
   BARRA DE AVISOS (TICKER)
   ========================================= */
.aviso-bar {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    color: #fff;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-weight: 600;
    margin: var(--sp-5) 0;
    box-shadow: 0 6px 16px -6px rgba(245, 158, 11, 0.45);
    display: flex;
    align-items: center;
}

.aviso-bar:empty { display: none; }

/* =========================================
   TARJETAS Y LAYOUT
   ========================================= */
.modern-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.layout {
    display: flex;
    gap: var(--sp-6);
    align-items: flex-start;
}

.sidebar {
    width: var(--sidebar-w);
    padding: var(--sp-4);
    flex-shrink: 0;
    /* Sidebar pegada bajo el header, con scroll propio si el menú es largo */
    position: sticky;
    top: calc(76px + var(--sp-5));
    max-height: calc(100dvh - 96px - var(--sp-5));
    overflow-y: auto;
}

.content { flex-grow: 1; min-width: 0; }

.form-container { padding: var(--sp-6); }
.section-title {
    margin-bottom: var(--sp-6);
    font-size: var(--fs-xl);
    font-weight: 700;
    color: var(--text-dark);
    padding-left: var(--sp-3);
    border-left: 4px solid var(--primary);
}

/* =========================================
   MENÚ LATERAL / NAVEGACIÓN
   ========================================= */
.main-menu { display: flex; flex-direction: column; gap: var(--sp-2); }

.nav-btn {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    min-height: var(--tap-target);
    text-align: left;
    background: transparent;
    color: var(--text-muted);
    padding: var(--sp-3) var(--sp-4);
    border-radius: 10px;
    border-left: 3px solid transparent;
    font-size: var(--fs-sm);
    font-weight: 600;
    border-top: none;
    border-right: none;
    border-bottom: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav-btn:hover { background: #f1f5f9; color: var(--text-dark); }
.nav-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    box-shadow: inset 0 1px 2px rgba(37, 99, 235, 0.06);
}

/* =========================================
   BOTONES
   ========================================= */
button { font-family: inherit; cursor: pointer; transition: all 0.2s ease; }
button:active { transform: scale(0.98); }

.btn-primary,
.btn-outline,
.btn-success {
    min-height: var(--tap-target);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: var(--sp-3) var(--sp-5);
    font-weight: 600;
    font-size: var(--fs-sm);
    box-shadow: var(--shadow-primary);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 10px 24px -6px rgba(37, 99, 235, 0.45); }

.btn-outline {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-dark);
    border-radius: var(--radius-sm);
    padding: var(--sp-2) var(--sp-4);
    font-weight: 600;
    font-size: var(--fs-sm);
}
.btn-outline:hover { border-color: var(--text-muted); background: var(--bg-main); }

.btn-success {
    background: var(--success);
    color: #fff;
    border: none;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: var(--fs-sm);
}

.btn-large { padding: var(--sp-4) var(--sp-6); font-size: var(--fs-base); }
.full-width { width: 100%; }

/* =========================================
   FORMULARIOS E INPUTS
   ========================================= */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); }
.flex-row { display: flex; gap: var(--sp-4); align-items: center; flex-wrap: wrap; }
.align-bottom { align-items: flex-end; }

.input-group { margin-bottom: var(--sp-5); display: flex; flex-direction: column; }
.input-group label {
    font-size: var(--fs-xs);
    font-weight: 700;
    margin-bottom: var(--sp-2);
    color: var(--text-dark);
}

input, select, textarea {
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    background: #fff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    /* 16px mínimo evita el zoom automático de iOS al enfocar el campo */
    min-height: var(--tap-target);
}
textarea { min-height: 96px; }

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    background: var(--bg-main);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    margin-top: var(--sp-2);
    min-height: var(--tap-target);
}
.checkbox-group label { margin: 0; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; color: var(--text-dark); }
.checkbox-group input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; accent-color: var(--primary); flex-shrink: 0; }

.border-upload {
    border: 2px dashed var(--border-color);
    padding: var(--sp-5);
    border-radius: var(--radius-sm);
    background: #fafafa;
}
.upload-help { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-2); }

/* =========================================
   TARJETAS DE EVENTOS (GRID)
   ========================================= */
.header-action { margin: 0 0 var(--sp-6) 0; }

.header-action h2 {
    font-size: var(--fs-lg);
    color: #ffffff;
    font-weight: 700;
    background: linear-gradient(90deg, #f97316, #fb923c);
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--radius-sm);
    display: inline-block;
    box-shadow: 0 6px 16px -6px rgba(249, 115, 22, 0.4);
}

/* Mobile-first: 1 columna por defecto, crece con el ancho disponible */
.grid-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-5);
}

.card-event {
    padding: var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
/* El hover con translateY solo aplica en dispositivos con puntero fino (mouse) */
@media (hover: hover) and (pointer: fine) {
    .card-event:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow-lg);
        border-color: #cbd5e1;
    }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: var(--sp-3);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-1);
}
.card-header h3 { font-size: var(--fs-lg); font-weight: 700; color: var(--text-dark); line-height: 1.3; }

.badge {
    padding: var(--sp-2) var(--sp-3);
    border-radius: 20px;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
}
.role-badge { background: #e0e7ff; color: var(--primary); }
.badge.pendiente { background: #fef3c7; color: #b45309; }
.badge.autorizado { background: #d1fae5; color: #047857; }

.info-row { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.7; }
.info-row strong { color: var(--text-dark); font-weight: 600; }

.map-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    width: fit-content;
    min-height: var(--tap-target);
    transition: background 0.2s;
}
.map-link:hover { background: #dbeafe; }

/* Login */
.login-card { max-width: 440px; margin: 8vh auto; padding: var(--sp-6); box-shadow: var(--shadow-lg); }
.login-header { text-align: center; margin-bottom: var(--sp-5); }
.login-header h2 { font-size: var(--fs-2xl); font-weight: 800; color: var(--text-dark); }
.login-header p { color: var(--text-muted); margin-top: var(--sp-2); }

/* =========================================
   BOTONES DE WHATSAPP
   ========================================= */
.btn-whatsapp {
    background-color: #25D366;
    color: white;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--fs-xs);
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    margin: var(--sp-1) var(--sp-1) 0 0;
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.2);
    transition: background 0.2s;
    min-height: 36px;
}
.btn-whatsapp:hover { background-color: #128C7E; color: white; }
.wa-container { margin-top: var(--sp-3); border-top: 1px dashed #f87171; padding-top: var(--sp-3); }

/* =========================================
   NAVEGACIÓN INFERIOR (SOLO MÓVIL)
   No se duplica HTML ni se tocan los id/JS: el mismo <aside class="sidebar">
   que ya existe se reposiciona con CSS como barra fija inferior en móvil.
   ========================================= */
@media (max-width: 639px) {
    .layout .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: none;
        z-index: 40;
        padding: var(--sp-2);
        border-radius: 0;
        border-top: 1px solid var(--border-color);
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
        overflow-x: auto;
        overflow-y: visible;
    }
    .layout .sidebar .main-menu {
        flex-direction: row;
        gap: var(--sp-1);
    }
    .layout .sidebar .nav-btn {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2px;
        flex: 1 1 0;
        min-width: 0;
        min-height: 52px;
        padding: var(--sp-1);
        border-radius: 10px;
        border-left: none;
        border-top: 3px solid transparent;
        /* El texto del botón viene suelto en el HTML (sin span propio), así que
           colapsa a 0 aquí y solo se restaura en .icon: en móvil la barra
           inferior muestra únicamente el ícono, evitando que las etiquetas
           largas ("Historial Eliminados", "Viáticos (Auxiliar)") se encimen. */
        font-size: 0;
        white-space: nowrap;
        overflow: hidden;
    }
    .layout .sidebar .nav-btn.active {
        border-left-color: transparent;
        border-top-color: var(--primary);
    }
    .layout .sidebar .nav-btn .icon { font-size: 1.35rem; line-height: 1; }
}

/* =========================================
   BREAKPOINTS — TABLET (640–1023px)
   ========================================= */
@media (min-width: 640px) and (max-width: 1023px) {
    .layout { flex-direction: column; gap: var(--sp-5); }

    /* La sidebar se convierte en una barra horizontal con scroll,
       cómoda para dedo pulgar en tablet/landscape móvil */
    .sidebar {
        width: 100%;
        position: static;
        max-height: none;
        padding: var(--sp-3);
        overflow-x: auto;
    }
    .main-menu {
        flex-direction: row;
        gap: var(--sp-2);
    }
    .main-menu .nav-btn { white-space: nowrap; width: auto; }

    .grid-cards { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .form-container { padding: var(--sp-5); }
}

/* =========================================
   BREAKPOINTS — MÓVIL (<640px)
   ========================================= */
@media (max-width: 639px) {
    .container { padding: var(--sp-3); }

    .modern-header { padding: var(--sp-3); }
    .user-controls { gap: var(--sp-3); }

    .layout { flex-direction: column; gap: var(--sp-4); }

    .grid-2 { grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
    .form-container { padding: var(--sp-4); }
    .input-group { margin-bottom: var(--sp-3); }
    textarea { min-height: 72px; }

    .card-header { flex-direction: column; align-items: start; gap: var(--sp-2); }

    .section-title { margin-bottom: var(--sp-4); }
    .border-upload { padding: var(--sp-3); }
    .checkbox-group { padding: var(--sp-2) var(--sp-3); }

    .login-card { margin: 4vh auto; padding: var(--sp-5); width: 92%; }

    /* Los botones ocupan el ancho completo: más fáciles de tocar */
    .btn-primary, .btn-outline, .btn-success { width: 100%; justify-content: center; }
    .flex-row.align-bottom { flex-direction: column; align-items: stretch; }
}

/* =========================================
   BREAKPOINTS — DESKTOP GRANDE (≥1400px)
   ========================================= */
@media (min-width: 1400px) {
    .grid-cards { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
}

/* En desktop estándar (1024–1399px) ya se ve bien con auto-fill */
@media (min-width: 1024px) {
    .grid-cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
}

/* =========================================
   IMPRESIÓN
   ========================================= */
.print-only { display: none; }
@media print {
    .no-print { display: none !important; }

    .print-only { display: block; font-family: Arial, sans-serif; }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body { background: white; padding-bottom: 0; }
    #area-impresion { font-size: 12px; color: black; }

    @page { size: letter; margin: 10mm; }
}
