/* ============================================================
   PERIMETRA - Sistema CSS Completo
   Paleta UNACEM integrada: Blanco, Rojo Corporativo, Gris Oscuro
   ============================================================ */

:root {
    /* --- PALETA BASE INSTITUCIONAL (Sidebar) --- */
    --navy:      #1a1a1a;      /* Gris Muy Oscuro */
    --navy-mid:  #2d2d2d;      /* Gris Medio Oscuro */
    --steel:     #CC0000;      /* ROJO UNACEM (primario) */
    --steel-hover: #aa0000;    /* Rojo Hover */
    --ice:       #e63333;      /* Rojo Claro (acentos) */
    --ice-light: #fde8e8;      /* Rojo muy claro (fondos) */
    --cream:     #f5f5f5;      /* Gris muy claro */
    --cream-dark:#e0e0e0;      /* Gris claro */
    --bg-page:   #f4f4f4;      /* Fondo principal UNACEM (blanco-gris) */
    --bg-card:   #ffffff;      /* Fondo de tarjetas */
    --bg-sidebar:#1a1a1a;      /* Fondo sidebar = Charcoal UNACEM */
    --sidebar-text: #e0e0e0;   /* Texto sidebar */
    --sidebar-hover: #333333;  /* Hover sidebar */
    
    /* --- SEMÁNTICOS --- */
    --success:   #27ae60;
    --warning:   #f39c12;
    --danger:    #e74c3c;
    --accent-red: #CC0000;
    --info:      #3a6d96;
    
    /* --- TIPOGRAFÍA --- */
    --font-base: 'Inter', sans-serif;
    --font-title: 'Outfit', sans-serif;
    --text-primary:   #1a1a1a;
    --text-secondary: #555555;
    --text-muted:     #888888;
    --text-white:     #ffffff;
    --text-on-dark:   #e0e0e0;
    
    /* --- LAYOUT --- */
    --sidebar-width: 280px;
    --topbar-height: 70px;
    --border-radius: 12px;
    --radius-sm: 8px;
    --radius-xl: 20px;
    
    /* --- SOMBRAS --- */
    --shadow-sm:  0 1px 4px rgba(0,0,0,0.07);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.14);
    --shadow-xl:  0 20px 60px rgba(0,0,0,0.20);
    
    /* --- TRANSITIONS --- */
    --t-fast:   0.15s ease;
    --t-normal: 0.25s ease;
    --t-slow:   0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* --- BORDERS --- */
    --border-color: rgba(0,0,0,0.10);
    --border-width: 1px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-base);
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.hidden { display: none !important; }
.active { display: flex !important; }

/* ============================================================
   SCREENS
   ============================================================ */
.screen { display: none; }
.screen.active { display: block; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -20%;
    width: 700px;
    height: 700px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(30,58,138,0.3) 0%, transparent 70%);
    pointer-events: none;
}

.login-bg::after {
    content: '';
    position: absolute;
    bottom: -20%;
    left: -15%;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(96,165,250,0.15) 0%, transparent 70%);
    pointer-events: none;
}

.login-container {
    display: flex;
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(24px);
    border-radius: var(--radius-xl);
    width: 95%;
    max-width: 1240px;
    height: 85vh;
    min-height: 600px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: fadeInUp 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-card {
    flex: 0 0 420px;
    background: #ffffff;
    padding: 3.5rem 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--border-color);
}

.login-hero {
    flex: 1;
    background: #fdfdfd; /* Fondo casi blanco */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 4rem;
    text-align: center;
    position: relative;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
}

.login-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 70% 30%, rgba(30,58,138,0.04), transparent 70%);
    pointer-events: none;
}

.hero-content {
    max-width: 720px;
    padding: 2rem;
    animation: fadeInUp 1.2s cubic-bezier(0.2, 1, 0.3, 1) both;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hero-logo {
    width: 260px;
    max-width: 90%;
    height: auto;
    margin-bottom: 1rem;
    mix-blend-mode: multiply;
    filter: drop-shadow(0 15px 35px rgba(26,45,74,0.12));
}

.hero-title {
    font-family: var(--font-title);
    font-size: 3.6rem;
    color: var(--navy);
    margin-bottom: 0.5rem;
    letter-spacing: -0.03em;
    font-weight: 800;
}

.hero-subtitle {
    font-family: var(--font-title);
    font-size: 1.1rem;
    color: var(--navy-mid);
    font-weight: 700;
    margin-bottom: 2rem;
    text-transform: uppercase;
    letter-spacing: 0.35em;
    opacity: 0.9;
}

.hero-motto {
    font-family: var(--font-base);
    font-size: 1.25rem;
    line-height: 1.8;
    color: #334e6f;
    margin-bottom: 3.5rem;
    max-width: 600px;
    margin-inline: auto;
    font-weight: 300;
    font-style: italic;
}

.hero-motto::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: var(--navy-mid);
    margin: 2rem auto 0;
    border-radius: 99px;
    opacity: 0.6;
}

.hero-credit {
    font-size: 0.875rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(26,45,74,0.06);
    padding-top: 2.5rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.logo-img {
    width: 260px;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    margin-bottom: 1rem;
    opacity: 0.95;
    mix-blend-mode: multiply;
}


@media (max-width: 1000px) {
    .login-container { flex-direction: column; height: auto; width: 100%; max-width: 480px; margin: 1rem; }
    .login-card { flex: 1; border-right: none; border-bottom: 1px solid var(--border-color); padding: 2.5rem 2rem; }
    .login-hero { display: none; } /* Ocultar hero en mobile para priorizar login */
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #dbeafe; /* Borde azul muy claro */
}

.login-form { display: flex; flex-direction: column; gap: 1.25rem; }

.login-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2rem;
}

/* ============================================================
   LAYOUT PRINCIPAL (Sidebar + Content)
   ============================================================ */
#screen-app {
    display: grid !important;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    background: var(--bg-sidebar);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--t-slow);
    z-index: 50;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem 1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: #ffffff;
    min-height: 80px;
}

h1, h2, h3, h4, h5, h6, .page-title, .modal-header h3, .card-header h3 {
    font-family: var(--font-title);
    font-weight: 700;
}

.sidebar-logo {
    display: block;
    width: 140px;
    height: auto;
    object-fit: contain;
    margin: 0 auto;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-on-dark);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    transition: background var(--t-fast);
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.1); }
.sidebar-toggle svg { width: 20px; height: 20px; display: block; }

.sidebar-install-selector {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-install-selector label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.5);
    margin-bottom: 0.5rem;
}

.sidebar-install-selector select {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-white);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    font-family: var(--font-base);
    transition: all var(--t-fast);
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1em;
}

.sidebar-install-selector select:hover { background: rgba(255,255,255,0.1); }
.sidebar-install-selector select:focus { border-color: var(--steel); }

.sidebar-install-selector select option {
    background: var(--navy);
    color: var(--text-white);
    font-weight: normal;
    padding: 10px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-x: hidden;
    min-width: 0;
    width: 100%;
}

.nav-group { margin-bottom: 1rem; }

.nav-group-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.4);
    padding: 0 0.5rem;
    margin-bottom: 0.5rem;
}

/* Nav item admin-only (oculto por defecto) */
.nav-item.admin-only { display: none; }
body.is-superadmin .nav-item.admin-only { display: flex; }

/* Badge admin en nav */
.nav-badge {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 0.55rem;
    font-weight: 700;
    background: #666;
    color: white;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    text-transform: uppercase;
    white-space: nowrap;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.75rem;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--t-fast);
    position: relative;
    line-height: 1.35;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-right: -0.25rem;
}

.nav-item span:not(.nav-badge) {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.nav-item:hover {
    background: rgba(255,255,255,0.15);
    color: #ffffff;
    transform: translateX(4px);
}

.nav-item.active {
    background: var(--steel);
    color: var(--text-white);
    box-shadow: 0 6px 16px rgba(204, 0, 0, 0.3);
    font-weight: 600;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.15);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--steel), var(--ice));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    display: block;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.topbar-left { display: flex; flex-direction: column; justify-content: center; }
.page-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--navy);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.breadcrumb {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: capitalize;
}

.topbar-right { display: flex; flex-direction: column; align-items: flex-end; }
.topbar-clock { font-size: 1.2rem; font-weight: 700; color: var(--steel); font-variant-numeric: tabular-nums; }
.topbar-date { font-size: 0.75rem; color: var(--text-muted); }

/* ============================================================
   MODULE SECTIONS
   ============================================================ */
.module { display: none; padding: 2rem; flex-direction: column; gap: 1.5rem; }
.module.active { display: flex; }

.module-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.toolbar-filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--t-normal), transform var(--t-fast);
}

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.75rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(90deg, #fafafa 0%, rgba(255,255,255,0.5) 100%);
}

.card-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: -0.02em;
}

.card-body {
    padding: 1.75rem;
    line-height: 1.6;
}

.card-badge {
    background: var(--ice-light);
    color: var(--steel);
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-warning {
    background: rgba(243,156,18,0.15);
    color: var(--warning);
}

/* ============================================================
   STATS CARDS (Dashboard)
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all var(--t-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px;
    height: 100%;
}

.stat-blue::before { background: var(--steel); }
.stat-steel::before { background: var(--ice); }
.stat-warning::before { background: var(--warning); }
.stat-success::before { background: var(--success); }

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-blue .stat-icon { background: rgba(58,109,150,0.12); color: var(--steel); }
.stat-steel .stat-icon { background: rgba(106,170,212,0.15); color: var(--ice); }
.stat-warning .stat-icon { background: rgba(243,156,18,0.12); color: var(--warning); }
.stat-success .stat-icon { background: rgba(46,204,113,0.12); color: var(--success); }

.stat-icon svg { width: 24px; height: 24px; }

.stat-data { flex: 1; }
.stat-number { display: block; font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }

/* ============================================================
   DASHBOARD GRID
   ============================================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
}

/* ============================================================
   DATA TABLES
   ============================================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead th {
    background: var(--bg-page);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background var(--t-fast);
}

.data-table tbody tr:hover { background: rgba(58,109,150,0.04); }

.data-table tbody td {
    padding: 0.875rem 1rem;
    color: var(--text-primary);
    vertical-align: middle;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 3rem !important;
}

/* ============================================================
   BADGES / PILLS
   ============================================================ */
.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-entrada { background: rgba(46,204,113,0.15); color: #27ae60; }
.badge-salida  { background: rgba(231,76,60,0.12);  color: #c0392b; }
.badge-baja    { background: rgba(46,204,113,0.12);  color: #27ae60; }
.badge-media   { background: rgba(243,156,18,0.15);  color: #e67e22; }
.badge-alta    { background: rgba(231,76,60,0.12);   color: #c0392b; }
.badge-critica { background: rgba(155,89,182,0.15);  color: #8e44ad; }
.badge-abierto { background: rgba(231,76,60,0.12);   color: #c0392b; }
.badge-cerrado { background: rgba(46,204,113,0.12);  color: #27ae60; }
.badge-en-proceso { background: rgba(52,152,219,0.12); color: #2980b9; }
.badge-empleado   { background: rgba(58,109,150,0.12); color: var(--steel); }
.badge-visita     { background: rgba(106,170,212,0.15); color: #2980b9; }
.badge-contratista { background: rgba(232,223,200,0.5); color: var(--cream-dark); border: 1px solid var(--cream-dark); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0;
}

.field-group label {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--navy);
}

.input-field,
.input-wrap input,
.input-wrap select {
    width: 100%;
    padding: 0.75rem 0.875rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: var(--font-base);
    color: var(--text-primary);
    background: var(--bg-card);
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background-color var(--t-fast);
    outline: none;
}

.input-field:focus,
.input-wrap input:focus,
.input-wrap select:focus {
    border-color: var(--steel);
    box-shadow: 0 0 0 4px rgba(204, 0, 0, 0.1);
    background-color: #fafafa;
}

.input-field::placeholder { color: var(--text-muted); }

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 0.875rem;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 1;
}

.input-wrap input { padding-left: 2.5rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-base);
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all var(--t-fast);
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--steel);
    color: white;
    border-color: var(--steel);
    box-shadow: 0 4px 12px rgba(204, 0, 0, 0.25);
}

.btn-primary:hover {
    background: var(--steel-hover);
    border-color: var(--steel-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(204, 0, 0, 0.35);
}

.btn-secondary {
    background: var(--bg-page);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover { border-color: var(--steel); color: var(--steel); }

.btn-outline {
    background: transparent;
    color: var(--steel);
    border-color: var(--steel);
}

.btn-outline:hover { background: var(--steel); color: white; }

.btn-full { width: 100%; justify-content: center; padding: 0.875rem; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    transition: all var(--t-fast);
    display: flex;
    align-items: center;
}

.btn-icon:hover { background: var(--bg-page); color: var(--steel); }
.btn-icon svg { width: 18px; height: 18px; }

.btn-export {
    flex: 1;
    justify-content: center;
    background: var(--bg-page);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
}

.btn-export:hover {
    border-color: var(--steel);
    color: var(--steel);
    background: rgba(58,109,150,0.06);
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

.alert-error { background: rgba(231,76,60,0.1); color: var(--danger); border: 1px solid rgba(231,76,60,0.2); }
.alert-success { background: rgba(46,204,113,0.1); color: var(--success); border: 1px solid rgba(46,204,113,0.2); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 45, 74, 0.75);
    backdrop-filter: blur(6px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.25s ease;
}

.modal-overlay.hidden { display: none !important; }
.modal-overlay:not(.hidden) { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.25s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 1.1rem; font-weight: 700; color: var(--navy); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--steel);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 280px;
    animation: slideInRight 0.3s ease;
    pointer-events: all;
}

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

/* ============================================================
   INCIDENT LIST (Bitácora)
   ============================================================ */
.incident-list { display: flex; flex-direction: column; gap: 1rem; }

.incident-item {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--t-normal);
}

.incident-item:hover { box-shadow: var(--shadow-md); }

.incident-severity {
    width: 10px;
    min-width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 0.45rem;
}

.sev-baja    { background: var(--success); }
.sev-media   { background: var(--warning); }
.sev-alta    { background: var(--danger); }
.sev-critica { background: #8e44ad; }

.incident-content { flex: 1; }
.incident-title { font-weight: 700; color: var(--navy); margin-bottom: 0.25rem; }
.incident-desc { font-size: 0.875rem; color: var(--text-secondary); }
.incident-meta { display: flex; gap: 1rem; margin-top: 0.5rem; font-size: 0.78rem; color: var(--text-muted); }

/* ============================================================
   REPORTS MODULE
   ============================================================ */
.reports-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.date-range { display: flex; align-items: center; gap: 0.5rem; }
.date-range span { color: var(--text-muted); font-size: 0.875rem; flex-shrink: 0; }

.export-formats { display: flex; gap: 0.75rem; }

.report-preview { min-height: 400px; }
.report-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    height: 100%;
    min-height: 300px;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

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

/* ============================================================
   SCROLLBAR CUSTOM
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ice-light); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--steel); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .reports-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   MOBILE HAMBURGER BUTTON
   ============================================================ */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--navy);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: background var(--t-fast);
}
.mobile-menu-btn:hover { background: var(--bg-page); }
.mobile-menu-btn svg { width: 24px; height: 24px; display: block; }

/* Overlay detrás del sidebar en mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26,45,74,0.6);
    z-index: 49;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

@media (max-width: 900px) {
    #screen-app { grid-template-columns: 1fr; }

    .mobile-menu-btn { display: flex; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform var(--t-slow);
        z-index: 50;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }

    .main-content { grid-column: 1; }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-grid { grid-template-columns: 1fr; }
    .reports-grid { grid-template-columns: 1fr; }
    .module { padding: 1rem; }
    .module-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-filters { flex-direction: column; }
    .topbar { padding: 0 1rem; }
    .export-formats { flex-direction: column; }
    .data-table { font-size: 0.8rem; }
    .data-table thead th,
    .data-table tbody td { padding: 0.6rem 0.6rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 1rem; }
    .stat-number { font-size: 1.5rem; }
    .login-card { padding: 2rem 1.25rem; margin: 1rem; }
    .modal { margin: 0.75rem; max-height: 95vh; }
    .topbar-clock { font-size: 1rem; }
    .topbar-date { display: none; }
    
    /* Forzar que grillas de 2 columnas en modales colapsen en móviles */
    .modal-body > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   TABLE RESPONSIVENESS
   ============================================================ */
.table-container,
.table-responsive,
.card-body.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Solo aplicar el colapso de tabla en pantallas muy pequeñas si tienen data-label */
@media (max-width: 600px) {
    .data-table:not(.no-responsive) thead { display: none; }
    .data-table:not(.no-responsive), 
    .data-table:not(.no-responsive) tbody, 
    .data-table:not(.no-responsive) tr, 
    .data-table:not(.no-responsive) td { display: block; width: 100%; }
    .data-table:not(.no-responsive) tr { margin-bottom: 1rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: white; }
    .data-table:not(.no-responsive) td { text-align: right; padding-left: 50%; position: relative; border-bottom: 1px solid rgba(0,0,0,0.05); }
    .data-table:not(.no-responsive) td::before {
        content: attr(data-label);
        position: absolute;
        left: 1rem;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 700;
        color: var(--text-secondary);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
    .data-table:not(.no-responsive) td:last-child { border-bottom: none; text-align: center; padding-left: 1rem; background: var(--bg-page); }
}

/* Modales responsivos */
@media (max-width: 600px) {
    .modal-body > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
}
