/* ============================================================
   NUEVO LAYOUT DASHBOARD 2026 - ALUCINET (ESTRUCTURA BASE)
   ============================================================ */
:root {
    --sidebar-width: 260px;
    --primary-color: #2a5298;
    --bg-light: #f4f6f9;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* El body se actualiza para permitir la barra lateral sin márgenes molestos */
body { 
    background-color: var(--bg-light); 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex; 
    overflow-x: hidden;
}

#appContainer {
    width: 100%;
    height: 100vh;
}

.dashboard-layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* --- ESTILOS DE LA BARRA LATERAL (NUEVO) --- */
.sidebar-main {
    width: var(--sidebar-width);
    background: #1e293b;
    color: white;
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    flex-shrink: 0;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 0 25px 20px;
    font-size: 26px;
    font-family: 'Brush Script MT', cursive, sans-serif;
    font-weight: 400;
    color: #38bdf8;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 15px;
    text-align: center;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    padding: 10px 20px;
    text-align: left;
    width: 100%;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
    border-left: 4px solid transparent;
}

.tab-btn:hover { background: rgba(255,255,255,0.05); color: white; }
.tab-btn.active { background: rgba(42, 82, 152, 0.8); color: white; border-left-color: #38bdf8; font-weight: bold; }

.main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 30px;
    background: var(--bg-light);
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: white; padding: 20px; border-radius: 12px; border: 1px solid #e2e8f0; box-shadow: 0 4px 6px rgba(0,0,0,0.02); display: flex; flex-direction: column; }
.stat-number { font-size: 32px; font-weight: 800; color: var(--primary-color); }
.stat-label { font-size: 12px; color: #64748b; text-transform: uppercase; font-weight: 700; margin-top: 5px; }


/* ============================================================
   --- ESTILOS ORIGINALES DE ALUCINET (CERO MODIFICACIONES) ---
   ============================================================ */
.tabla-correos { width: 100%; border-collapse: collapse; font-size: 0.9em; background: white; }
.tabla-correos thead { background: #2a5298; color: white; }
.tabla-correos th, .tabla-correos td { padding: 10px; border: 1px solid #ddd; text-align: left; vertical-align: middle; }
.tabla-correos th { font-weight: bold; text-transform: uppercase; font-size: 0.85em; }
.tabla-correos tr:nth-child(even) { background-color: #f9f9f9; }
.tabla-correos tr:hover { background-color: #f1f4ff; }
.col-monto { text-align: right !important; font-weight: bold; color: #444; }
.badge-env { padding: 4px 8px; border-radius: 4px; font-size: 0.8em; font-weight: bold; }
.bg-si { background: #d4edda; color: #155724; }
.bg-no { background: #f8d7da; color: #721c24; }
.btn-uniforme { min-width: 90px; text-align: center; display: inline-block; }
.tipo-icono { margin-right: 5px; font-size: 1.1em; }

#configuracion-root { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

#loginOverlay, #loadingOverlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99999; display: flex; align-items: center; justify-content: center; flex-direction: column; }
#loginOverlay { background: rgba(0,0,0,0.9); }
#loadingOverlay { background: rgba(255,255,255,0.9); display: none; color: #2a5298; font-weight: bold; }
.spinner { border: 8px solid #f3f3f3; border-top: 8px solid #2a5298; border-radius: 50%; width: 60px; height: 60px; animation: spin 1s linear infinite; margin-bottom: 20px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.login-card { background: white; width: 100%; max-width: 400px; padding: 40px; border-radius: 12px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.login-title { color: #333; margin-bottom: 20px; font-weight: 700; }
.container { max-width: 1200px; margin: 0 auto; }
.logo-creator { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.9em; color: #555; margin-bottom: 20px; }
.logo-ovulo { width: 24px; height: 24px; background: linear-gradient(45deg, #ff00cc, #333399); border-radius: 50%; position: relative; display: flex; align-items: center; justify-content: center; }
.logo-ovulo:before { content: "A"; font-size: 12px; color: white; position: absolute; font-weight:bold; }
.creator-name { font-size: 1em; font-weight: 600; }
.logout-btn { background: #e74c3c; border: none; padding: 8px 15px; border-radius: 6px; color: white; cursor: pointer; font-size: 0.9em; font-weight: bold; }
.logout-btn:hover { background: #c0392b; }
#tituloEditable { text-align: center; font-size: 36px; font-weight: bold; margin-top: 10px; margin-bottom: 5px; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.4); cursor: text; padding: 0 20px; }
.system-title { text-align: center; color: rgba(255, 255, 255, 0.9); font-size: 1.1em; margin-bottom: 25px; font-weight: 400; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; justify-content: center; }
.tab-content { display: none; background: white; border-radius: 12px; padding: 30px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); animation: slideIn 0.3s ease-in-out; border: 1px solid #e2e8f0; margin-bottom: 30px; }
.tab-content.active { display: block; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.search-container { margin-bottom: 25px; }
.search-box { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: flex-end; }
.search-box label { font-weight: bold; margin-bottom: 5px; display: block;}
.search-box input, .search-box select { flex: 1; min-width: 200px; padding: 12px; border: 2px solid #ddd; border-radius: 6px; }
.search-box button { padding: 12px 25px; background: #2a5298; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 30px; }
.form-group { display: flex; flex-direction: column; }
.form-group label { font-weight: 600; color: #333; margin-bottom: 5px; font-size: 0.9em; }
input, select, textarea { padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 1em; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #2a5298; }
.required { color: #e74c3c; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 30px; }
.btn-primary { background: #2a5298; color: white; padding: 12px 25px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-secondary { background: #e0e0e0; color: #333; padding: 12px 25px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-danger { background: #ff4757; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-weight: bold;}
.btn-warning { background: #f1c40f; color: #333; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn-success { background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn-small { font-size: 0.9em; padding: 5px 10px; }
.action-btn { background: #2a5298; color: white; border: none; border-radius: 6px; padding: 8px 15px; cursor: pointer; }
.result-card { background: #f8f9fa; border-left: 5px solid #2a5298; padding: 20px; margin-bottom: 15px; border-radius: 6px; position: relative; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.result-card.paid { border-left-color: #28a745; background: #f0fff4; }
.card-header-depto { font-size: 1.2em; font-weight: bold; color: #2a5298; border-bottom: 1px solid #ddd; padding-bottom: 8px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.resident-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; }
.data-item { display: flex; flex-direction: column; }
.result-label { font-weight: 700; color: #2a5298; font-size: 0.95em; text-transform: uppercase; margin-bottom: 2px; }
.result-value { color: #000; font-size: 1em; word-break: break-word; }
.data-count { background: #f0f0f0; padding: 10px 20px; border-radius: 6px; margin-top: 20px; color: #666; font-size: 0.9em; }
.alert { padding: 15px; border-radius: 6px; margin-bottom: 20px; display: none; }
.alert.error { background: #f8d7da; color: #721c24; }
.status-badge { font-size: 0.8em; font-weight: bold; padding: 4px 10px; border-radius: 12px; display: inline-flex; align-items: center; gap: 5px; }
.status-ok { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
#listaVisitasSugeridas { border: 1px solid #ddd; background: #fff; max-height: 200px; overflow-y: auto; border-radius: 6px; padding: 10px; margin-top: 5px; display: grid; grid-template-columns: 1fr; gap: 5px; }
.visita-option { display: flex; align-items: center; gap: 8px; font-size: 0.9em; padding: 6px; border-radius: 4px; border-bottom: 1px solid #eee; }
.visita-option:hover { background-color: #f0f4ff; }
.config-box { background: #fff; border: 1px solid #ddd; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
.scanner-input { border: 2px solid #28a745; background-color: #f0fff4; }
.scanner-input:focus { box-shadow: 0 0 5px rgba(40, 167, 69, 0.5); }
.encomienda-card { padding: 25px; display: flex; flex-direction: column; gap: 12px; line-height: 1.6; }
.boleta-container { display:flex; border:1px solid #ccc; background:#fff; box-shadow:0 0 10px rgba(0,0,0,0.1); margin-bottom:20px; border-radius:6px; overflow:hidden; }
.boleta-side { width: 30%; background: #f4f6f9; padding: 20px; border-right: 1px solid #ddd; display: flex; flex-direction: column; justify-content: center; font-size: 0.8em; color: #444; }
.boleta-side strong { color: #2a5298; display:block; margin-top:5px; }
.boleta-main { width: 70%; padding: 25px; }
.boleta-header { display:flex; justify-content:space-between; align-items:center; border-bottom:2px solid #2a5298; padding-bottom:10px; margin-bottom:20px; }
.boleta-item-row { display:flex; justify-content:space-between; margin-bottom:10px; align-items:center; }
.boleta-item-row label { width: 40%; font-weight:600; font-size:0.9em; }
.boleta-item-row input { width: 55%; text-align:right; }
.boleta-total { background:#2a5298; color:white; padding:15px; margin-top:20px; border-radius:6px; font-size:1.2em; text-align:right; font-weight:bold; }

/* TABLA BÚSQUEDA Y RESPONSIVE */
.results-table-container { margin-top: 20px; overflow-x: auto; background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.tabla-busqueda { width: 100%; border-collapse: collapse; font-size: 0.85em; min-width: 1000px; }
.tabla-busqueda th { background-color: #1e3c72; color: white; padding: 12px; text-align: left; text-transform: uppercase; }
.tabla-busqueda td { padding: 10px; border-bottom: 1px solid #eee; color: #333; }
.tabla-busqueda tr:hover { background-color: #f1f4ff; }
.btn-edit-tabla { padding: 4px 8px; background: #f1c40f; border: none; border-radius: 4px; cursor: pointer; font-size: 1.1em; }
.btn-editar-nuevo { background: #10b981; color: #fff; border: none; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1; }
.btn-editar-nuevo:hover { filter: brightness(0.95); }

.tabla-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 10px; }

@media screen and (max-width: 600px) {
    .tabla-correos th, .tabla-correos td { font-size: 11px; padding: 5px; }
}

@media print {
    @page { size: letter; margin: 1.5cm; }
    body { font-family: 'Arial Narrow', Arial, sans-serif; font-size: 10pt; color: #000; background: white; }
    .no-print, button, .tabs, .form-group, input, textarea, h3, .panel-control { display: none !important; }
}

/* ============================================================
   ESTILOS OPERACIONES (MANTENIDOS)
   ============================================================ */
#operaciones .config-layout { display: grid; grid-template-columns: 250px 1fr; gap: 20px; min-height: 500px; margin-top: 15px; }
#operaciones .config-sidebar { background: #ffffff; border-radius: 12px; padding: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); height: fit-content; }
#operaciones .sidebar-title { font-size: 0.9em; font-weight: bold; color: #2a5298; text-transform: uppercase; margin-bottom: 15px; padding-left: 10px; letter-spacing: 1px; }
#operaciones .sidebar-btn { display: block; width: 100%; padding: 12px 15px; margin-bottom: 8px; border: none; background: transparent; color: #555; text-align: left; border-radius: 8px; cursor: pointer; font-size: 0.95em; transition: all 0.3s ease; }
#operaciones .sidebar-btn:hover { background: #f0f4f8; color: #2a5298; }
#operaciones .sidebar-btn.active { background: #2a5298; color: #ffffff !important; font-weight: 500; box-shadow: 0 4px 10px rgba(42, 82, 152, 0.2); }
#operaciones .config-main { background: #ffffff; border-radius: 12px; padding: 25px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
#operaciones .config-section { display: none; animation: fadeInOperaciones 0.3s ease-in-out; }
#operaciones .config-section.active { display: block; }
#operaciones .section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 2px solid #f0f0f0; }
@keyframes fadeInOperaciones { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 768px) {
    #operaciones .config-layout { grid-template-columns: 1fr; }
    #operaciones .config-sidebar { display: flex; overflow-x: auto; padding: 10px; gap: 10px; margin-bottom: 10px; }
    #operaciones .sidebar-btn { white-space: nowrap; width: auto; margin-bottom: 0; }
}

/* ============================================================
   VENTANA MODAL - (UNIFICADA Y CORREGIDA)
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 9999999;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.modal {
    background: white;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
}

.modal-header { display:flex; justify-content:space-between; margin-bottom:15px; border-bottom:1px solid #eee; padding-bottom:10px; }
.modal-close { background:#ff4757; color:white; border:none; width:30px; height:30px; border-radius:50%; font-weight:bold; cursor:pointer; }
.modal-footer { margin-top:20px; display:flex; justify-content:flex-end; gap:10px; border-top:1px solid #eee; padding-top:15px; }

/* MEDIA QUERIES GENERALES PARA MÓVILES */
@media (max-width: 768px) {
    #appContainer { flex-direction: column; }
    .sidebar-main { width: 100%; height: auto; padding: 15px; display: flex; flex-direction: row; overflow-x: auto; white-space: nowrap; align-items: center; border-bottom: 1px solid #334155; }
    .sidebar-brand { padding: 0 15px 0 0; margin: 0; border: none; font-size: 20px; }
    .tab-btn { display: inline-block; width: auto; border-left: none; border-bottom: 3px solid transparent; padding: 10px 15px; }
    .tab-btn.active { border-left: none; border-bottom-color: #38bdf8; }
    .main-content { padding: 15px; }
    
    #tituloEditable { font-size: 1.8em; }
    .resident-grid { grid-template-columns: 1fr 1fr; }
    .tabs { flex-direction: column; }
    .boleta-container { flex-direction:column; }
    .boleta-side { width:100%; border-right:none; border-bottom:1px solid #ddd; }
    .boleta-main { width:100%; }
    #listadoCompleto { overflow-x: auto; }
}

/* ============================================================
   📱 ADAPTACIÓN MÓVIL (DISEÑO RESPONSIVO ALUCINET)
   ============================================================ */

@media screen and (max-width: 768px) {
    /* 1. Layout Principal y Menú (De Vertical a Horizontal Deslizable) */
    .dashboard-layout {
        display: flex;
        flex-direction: column;
    }
    .sidebar-main {
        width: 100%;
        height: auto;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding: 10px;
        box-sizing: border-box;
        border-right: none;
        border-bottom: 2px solid #2a5298;
        -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
    }
    .sidebar-main .tab-btn {
        display: inline-block;
        margin-right: 10px;
        width: auto;
        flex-shrink: 0;
        font-size: 14px;
        padding: 10px 15px;
    }
    .sidebar-brand {
        display: none; /* Ocultamos el logo grande en el menú móvil para ahorrar espacio */
    }
    .sidebar-main > div:last-child {
        display: inline-block;
        padding: 0;
        margin-left: 10px;
    }
    .sidebar-main > div:last-child button {
        width: auto !important;
        padding: 10px 15px !important;
    }

    /* 2. Formularios Generales (1 sola columna) */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    .form-group {
        grid-column: span 1 !important;
    }

    /* 3. Panel de Gastos Comunes (Apilar Izquierda y Derecha) */
    .boleta-container {
        display: flex;
        flex-direction: column;
    }
    .boleta-side {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 2px dashed #ddd;
        margin-bottom: 15px;
        padding-bottom: 15px;
    }
    .boleta-main {
        width: 100% !important;
        padding-left: 0 !important;
    }

    /* 4. Panel de Configuración */
    #config .config-layout {
        flex-direction: column;
        height: auto;
    }
    #config .config-sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    #config .sidebar-btn {
        display: inline-block;
        width: auto;
        border-left: none;
        border-bottom: 4px solid transparent;
    }
    #config .sidebar-btn.active {
        border-left: none;
        border-bottom-color: #2a5298;
    }

    /* 5. Protección de Tablas (Scroll horizontal sin romper la pantalla) */
    .results-table-container, .results {
        overflow-x: auto;
        display: block;
        width: 100%;
    }
    table {
        min-width: 600px; /* Fuerza el scroll interno en vez de aplastar las letras */
    }
    
    /* 6. Ajuste de Ventanas Modales */
    .modal {
        width: 95% !important;
        padding: 15px !important;
    }
}