/* Reset y base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Layout Principal */
#sidebar {
    width: 280px;
    height: 100vh;
    background: #2c3e50;
    color: white;
    position: fixed;
    left: 0;
    top: 0;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 1000;
}

#main-content-wrapper {
    margin-left: 280px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* Sidebar */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #34495e;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.app-name {
    font-size: 1.1rem;
    font-weight: bold;
}

.sidebar-nav {
    padding: 1rem 0;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section h3 {
    padding: 0 1.5rem 0.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #bdc3c7;
    font-weight: normal;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: #ecf0f1;
    text-decoration: none;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: #34495e;
    color: white;
}

.nav-link.active {
    background: #3498db;
    border-left-color: #2980b9;
    color: white;
}

.nav-icon {
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #34495e;
    margin-top: auto;
}

.user-info {
    margin-bottom: 1rem;
}

.user-info span {
    display: block;
}

#user-name {
    font-weight: bold;
    margin-bottom: 0.25rem;
}

#user-role {
    font-size: 0.8rem;
    color: #bdc3c7;
}

.social-links {
    display: flex;
    gap: 0.5rem;
}

.social-links a {
    color: #bdc3c7;
    text-decoration: none;
    font-size: 1.2rem;
    transition: color 0.3s ease;
}

.social-links a:hover {
    color: #3498db;
}

/* Header Principal */
#main-header {
    background: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
}

#page-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2c3e50;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #7f8c8d;
    font-size: 0.9rem;
}

.status-connected {
    color: #27ae60;
}

.status-disconnected {
    color: #e74c3c;
}

/* Contenido Principal */
#main-content {
    padding: 2rem;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Tarjetas del Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.dashboard-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
}

.dashboard-card h3 {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.card-number {
    font-size: 2.5rem;
    font-weight: bold;
    color: #2c3e50;
}

.card-status {
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0.5rem;
    border-radius: 4px;
}

/* Tablas */
.data-table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #ecf0f1;
}

.data-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

/* Botones */
.btn-primary {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-success {
    background: #27ae60;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.btn-success:hover {
    background: #219a52;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.btn-icon:hover {
    background: #ecf0f1;
}

.btn-add {
    background: #27ae60;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-edit {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-delete {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Formularios */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

.form-grid.cols-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

/* * --- SECCIÓN MODIFICADA: CAD ---
 */

.cad-container {
    display: grid;
    /* Formulario más ancho */
    grid-template-columns: 550px 1fr;
    gap: 2rem;
    height: calc(100vh - 200px);
}

.cad-left {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.cad-form {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.cad-right {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.cad-map {
    /* Tamaño de mapa moderado (alto fijo) */
    height: 450px;
    flex-shrink: 0; /* No se encoge */
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.unit-status {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    /* Ocupa el espacio restante */
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.address-input-group {
    display: flex;
    gap: 0.5rem;
}

.address-input-group input {
    flex: 1;
}


/* --- ESTILO MEJORADO PARA CHECKBOXES --- */
.checkboxes-container {
    /* CAMBIO 1: Scroll horizontal y sin scroll vertical */
    overflow-y: hidden;  
    overflow-x: auto;
    
    display: grid;
    
    /* CAMBIO 2: Define 3 filas. Las columnas se crearán automáticamente */
    grid-template-rows: auto auto auto; 
    
    /* CAMBIO 3: Hace que los items se llenen horizontalmente */
    grid-auto-flow: column; 
    
    gap: 0.75rem; /* Espacio entre items */

    /* Estilo del contenedor */
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    padding: 0.75rem;
    
    /* Para que los items no se compriman */
    min-width: 0;
}

.checkbox-item {
    display: flex;
    align-items: center;
    
    /* Estilo de "tarjeta" */
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    
    /* Evita que el texto se parta en dos líneas */
    white-space: nowrap; 
    
    /* Ancho mínimo para cada item */
    min-width: 150px;
}

.checkbox-item:hover {
    background: #e9ecef;
    border-color: #dee2e6;
}

.checkbox-item input[type="checkbox"] {
    width: 1.1em;
    height: 1.1em;
    margin-right: 0.75rem; /* Espacio entre check y texto */
    flex-shrink: 0;
}
/* --- FIN DE SECCIÓN MODIFICADA --- */


/* Partes */
.parte-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #ecf0f1;
}

.parte-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.parte-tab-btn {
    background: #ecf0f1;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.parte-tab-btn.active {
    background: #3498db;
    color: white;
}

.parte-tab-content {
    display: none;
}

.parte-tab-content.active {
    display: block;
}

.parte-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.tab-btn {
    background: #ecf0f1;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: #3498db;
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Chat */
.chat-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    height: 70vh;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #ecf0f1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-messages {
    flex: 1;
    padding: 1rem 1.5rem;
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    background: #f8f9fa;
}

.chat-message.own {
    background: #3498db;
    color: white;
    margin-left: 2rem;
}

.chat-message-header {
    font-size: 0.8rem;
    color: #7f8c8d;
    margin-bottom: 0.25rem;
}

.chat-message.own .chat-message-header {
    color: rgba(255,255,255,0.8);
}

.chat-input {
    padding: 1rem 1.5rem;
    border-top: 1px solid #ecf0f1;
    display: flex;
    gap: 0.5rem;
}

.chat-input input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #ecf0f1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-actions {
    padding: 1rem 1.5rem;
    border-top: 1px solid #ecf0f1;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Estados y utilidades */
.admin-only,
.despacho-only,
.tesorero-only {
    display: none;
}

.user-admin .admin-only,
.user-despacho .despacho-only,
.user-tesorero .tesorero-only {
    display: block;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
}

.status-active {
    background: #d4edda;
    color: #155724;
}

.status-inactive {
    background: #f8d7da;
    color: #721c24;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
    }
    
    #sidebar.active {
        transform: translateX(0);
    }
    
    #main-content-wrapper {
        margin-left: 0;
    }
    
    #sidebar-toggle {
        display: block;
    }
    
    .cad-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .form-grid.cols-2 {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .parte-tabs {
        overflow-x: auto;
    }
    
    .parte-tab-btn {
        white-space: nowrap;
    }
}

/* Animaciones */
.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-in {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(-20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =========================================
   FIX: CORRECCIÓN COMPLETA DEL SIDEBAR
   (Añadir al final de dashboard.css)
   ========================================= */

/* --- 1. Arreglo de Z-Index (Header por encima de Sidebar) --- */

/* Tu sidebar está en 1000. Subimos el header a 1001 
   para que siempre esté por encima (arregla botón tapado en móvil). */
#main-header {
    z-index: 1001; 
}

/* --- 2. Lógica para Desktop (Colapsar y Empujar) --- */

/* 2a. ESTADO COLAPSADO (Desktop): Achicamos la sidebar */
body.sidebar-collapsed #sidebar {
    /* (Tu ancho original es 280px) */
    width: 80px; /* Nuevo ancho colapsado */
}
        
/* 2b. ESTADO COLAPSADO (Desktop): Ocultamos texto */
body.sidebar-collapsed .app-name,
body.sidebar-collapsed .nav-section h3,
body.sidebar-collapsed .nav-link span { /* Oculta el texto de los links */
    display: none;
    opacity: 0;
}

/* Centramos los iconos que quedan */
body.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 1.5rem 0.5rem; /* Ajuste de padding */
}
body.sidebar-collapsed .nav-link {
    justify-content: center;
}
body.sidebar-collapsed .nav-icon {
    margin-right: 0;
    font-size: 1.3rem;
}

/* Ocultamos el footer de la sidebar (info de usuario) */
body.sidebar-collapsed .sidebar-footer {
    display: none;
}
        
/* 2c. ESTADO COLAPSADO (Desktop): Empujamos el contenido */
body.sidebar-collapsed #main-content-wrapper {
    /* Tu CSS ya tiene margin-left: 280px (perfecto) */
    margin-left: 80px; /* Coincide con el 'width' colapsado */
}

/* --- 3. Lógica para Móvil (max-width: 768px) --- */

/* Sobrescribimos tus reglas de @media para usar la nueva lógica unificada */
@media (max-width: 768px) {
    
    /* ESTADO CERRADO (Colapsado) */
    body.sidebar-collapsed #sidebar {
        transform: translateX(-100%);
        width: 280px; /* Mantenemos su ancho original al estar oculta */
    }
            
    /* ESTADO ABIERTO (Sin .sidebar-collapsed) */
    body:not(.sidebar-collapsed) #sidebar {
        transform: translateX(0);
        width: 280px;
    }

    /* El contenido NO se empuja en móvil */
    #main-content-wrapper,
    body.sidebar-collapsed #main-content-wrapper {
        margin-left: 0;
    }
            
    /* Restauramos el texto de los links para que se vean bien en móvil */
    body.sidebar-collapsed .app-name,
    body.sidebar-collapsed .nav-section h3,
    body.sidebar-collapsed .nav-link span {
        display: block; /* Aseguramos que se vea en móvil */
        opacity: 1;
    }
    
    /* Restauramos el padding y justificado */
    body.sidebar-collapsed .sidebar-header,
    body.sidebar-collapsed .nav-link {
       justify-content: flex-start;
    }
    
    /* Tu regla original para mostrar el botón en móvil */
    #sidebar-toggle {
        display: block;
    }
}
        
/* --- 4. Transiciones Suaves (Tu CSS ya las tiene) --- */

/* Nos aseguramos que #sidebar también tenga transición de 'width' */
#sidebar {
    /* Añadimos 'width' a la transición que ya tenías */
    transition: width 0.3s ease, transform 0.3s ease;
}

/* =========================================
   ESTILOS PARA EL NUEVO DIRECTORIO
   ========================================= */

#directorio-content h3 {
    font-size: 1.8rem;
    color: #c0392b; /* Rojo institucional */
    text-align: center;
    margin: 2rem 0 1.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e74c3c;
    display: inline-block;
}

.directorio-section {
    text-align: center;
    margin-bottom: 3rem;
}

.oficiales-grid {
    display: grid;
    /* Crea columnas de 200px, pero se ajustan para llenar el espacio */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    justify-content: center;
}

.oficial-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    text-align: center;
    padding: 1.5rem 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.oficial-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.oficial-foto {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 1rem auto;
    background-color: #ecf0f1; /* Color de fondo para la foto */
    border: 4px solid white;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    object-fit: cover; /* Asegura que la imagen no se deforme */
}

.oficial-rango {
    background-color: #c0392b; /* Rojo */
    color: white;
    font-weight: bold;
    padding: 0.5rem;
    margin: 0 -1rem 1rem -1rem; /* Lo estira a los bordes */
    font-size: 0.9rem;
}

.oficial-nombre {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: #2c3e50;
}

.oficial-compania, .oficial-telefono {
    font-size: 0.9rem;
    color: #7f8c8d;
}

/* Sección para compañías (ESTA ES LA PARTE DINÁMICA) */
.companias-container {
    display: grid;
    /* Se ajustará automáticamente a 1, 2, 3 o más columnas según el espacio */
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    align-items: start; /* Alinea las secciones de compañía en la parte superior */
}