/* CONFIGURACIÓN BASE - FUENTE ARIAL Y ALTO CONTRASTE */
* {
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    margin: 0;
    padding: 0;
    background-color: #FFFFFF;
    color: #1A1A1A;
    overflow-x: hidden; /* Evita scroll horizontal en toda la página */
}

/* LAYOUT RESPONSIVO */
.main-wrapper, .layout {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
    width: 100%;
}

/* SIDEBAR / MENÚ */
.sidebar {
    width: 260px;
    background-color: #F2F4F7;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border-right: 1px solid #E2E8F0;
    flex-shrink: 0;
}

/* ESTADOS DE COLAPSADO EN ESCRITORIO */
.sidebar.collapsed {
    width: 70px;
    min-width: 70px;
}

.sidebar.collapsed .sidebar-logo {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 15px 10px;
}

.sidebar.collapsed .sidebar-nav span {
    display: none;
}

.sidebar.collapsed .sidebar-nav a {
    justify-content: center;
    padding: 14px 0;
}

.sidebar.collapsed .sidebar-nav a i {
    width: auto;
    margin: 0;
    font-size: 1.2rem;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background-color: #2D426C;
}

.sidebar-logo {
    max-width: 130px;
    height: auto;
}

.toggle-btn {
    background: none;
    border: none;
    color: #FFFFFF;
    font-size: 1.3rem;
    cursor: pointer;
}

.sidebar-nav ul {
    list-style: none;
    padding: 10px 0;
    margin: 0;
}

.sidebar a, .sidebar-nav li a {
    display: flex;
    align-items: center;
    color: #2D426C;
    padding: 14px 20px;
    text-decoration: none;
    border-bottom: 1px solid #E2E8F0;
    font-weight: bold;
    letter-spacing: 0.5px;
    transition: background-color 0.3s ease, color 0.3s ease;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.sidebar a i, .sidebar-nav li a i {
    width: 28px;
    font-size: 1.1rem;
}

.sidebar a:hover, .sidebar-nav li a:hover {
    background-color: #E6EDF8;
    color: #4A6CAE;
}

/* CONTENIDO PRINCIPAL */
.content, .content-wrapper {
    flex-grow: 1;
    padding: 20px;
    width: 100%;
    min-width: 0; /* Permite que el flexbox encaje tablas sin desbordar */
    background-color: #FFFFFF;
    transition: all 0.3s ease;
}

/* HEADER CON EL COLOR DEL LOGO */
.header {
    background-color: #2D426C;
    color: #FFFFFF;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header h1, .header h2 {
    color: #FFFFFF;
    margin: 0;
    font-size: 1.3rem;
    text-transform: uppercase;
}

.header-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* BOTONES DE CABECERA */
.btn-head {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-decoration: none;
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.25s ease-in-out;
    border: none;
    cursor: pointer;
}

.btn-head:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.btn-head:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-head-primary {
    background-color: #10B981;
    color: #FFFFFF !important;
}

.btn-head-primary:hover {
    background-color: #059669;
}

.btn-head-danger {
    background-color: #EF4444;
    color: #FFFFFF !important;
}

.btn-head-danger:hover {
    background-color: #DC2626;
}

/* TARJETAS (CARDS) */
.card {
    background: #FFFFFF;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    margin-bottom: 25px;
    border: 1px solid #E2E8F0;
    width: 100%;
}

.card h2, .card h3 {
    color: #2D426C;
    margin-top: 0;
    border-bottom: 3px solid #2D426C;
    padding-bottom: 10px;
    font-size: 1.25rem;
    text-transform: uppercase;
}

/* FORMULARIOS Y BOTONES GENERALES */
input, select, button {
    width: 100%;
    padding: 10px 12px;
    margin: 6px 0;
    border: 2px solid #CBD5E1;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: bold;
}

label {
    text-transform: uppercase;
}

input:focus, select:focus {
    border-color: #2D426C;
    outline: none;
    background-color: #F8FAFC;
}

.btn-primario, .btn-login, button {
    background-color: #2D426C;
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    transition: background-color 0.3s, transform 0.2s;
}

.btn-primario:hover, .btn-login:hover, button:hover {
    background-color: #3C578D;
    transform: translateY(-1px);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 15px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

/* ALERTAS */
.alert {
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-weight: bold;
    border-left: 6px solid;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.alert.success { background: #E6F4EA; color: #137333; border-color: #137333; }
.alert.error { background: #FCE8E6; color: #C5221F; border-color: #C5221F; }

/* BOTONES DE ACCIONES EN TABLAS */
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 4px;
    color: #FFFFFF;
    text-decoration: none;
    margin: 0 2px;
    font-size: 0.85rem;
}

.btn-edit { background-color: #0284C7; }
.btn-edit:hover { background-color: #0369A1; }

.btn-delete { background-color: #EF4444; }
.btn-delete:hover { background-color: #DC2626; }

.btn-view { background-color: #475569; }
.btn-view:hover { background-color: #334155; }

/* ENLACE DE ORDENAMIENTO EN LA COLUMNA */
.th-sortable {
    color: #2D426C !important;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
    text-transform: uppercase;
}

.th-sortable:hover {
    color: #0284C7 !important;
}

.sort-icon {
    font-size: 0.85rem;
    color: #0284C7;
}

/* CONTENEDOR DE TABLA CON SCROLL HORIZONTAL Y VERTICAL */
.table-responsive {
    width: 100%;
    max-height: 70vh;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    margin-bottom: 15px;
}

/* TABLAS ADAPTATIVAS */
.data-table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #F1F5F9 !important;
    color: #2D426C !important;
    font-weight: 700 !important;
    font-size: 0.8rem !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 12px;
    border-bottom: 2px solid #CBD5E1 !important;
    white-space: nowrap !important;
}

.data-table th, 
.data-table td {
    padding: 8px 10px;
    vertical-align: middle;
    font-size: 0.85rem;
    white-space: nowrap !important;
}

.usuario-login {
    text-transform: lowercase !important;
}

/* MODALES SOBREPUESTOS (OVERLAY FIX) */
.custom-modal {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    z-index: 9999 !important;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.custom-modal-content {
    background-color: #FFFFFF !important;
    padding: 15px 20px !important;
    border-radius: 8px !important;
    width: 100% !important;
    max-width: 620px !important;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3) !important;
    position: relative !important;
    margin: auto !important;
}

.custom-modal-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 2px solid #E9ECEF !important;
    padding-bottom: 8px !important;
    margin-bottom: 12px !important;
}

.custom-modal-header h4 {
    margin: 0 !important;
    color: #2D426C !important;
    font-size: 1.05rem !important;
}

.close-modal {
    font-size: 1.4rem !important;
    font-weight: bold !important;
    cursor: pointer !important;
    color: #AAA !important;
    line-height: 1 !important;
}

.close-modal:hover { color: #000 !important; }

/* GRID COMPACTA DE 3 COLUMNAS PARA FORMULARIOS */
.form-grid-compact {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px 12px !important;
}

.col-span-3 { grid-column: span 3 !important; }
.col-span-1-5 { grid-column: span 1.5 !important; }

.form-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    margin: 0 !important;
}

.form-group label {
    font-size: 0.78rem !important;
    font-weight: 700 !important;
    color: #495057 !important;
    margin-bottom: 2px !important;
}

.form-control-sm {
    padding: 4px 8px !important;
    border: 1px solid #CBD5E1 !important;
    border-radius: 4px !important;
    font-size: 0.85rem !important;
    height: 32px !important;
    margin: 0 !important;
}

.btn-sm {
    padding: 4px 12px !important;
    font-size: 0.82rem !important;
    height: 32px !important;
    margin: 0 !important;
}

/* BOTÓN BUSCAR JUNTO AL INPUT */
.input-select-group {
    display: flex !important;
    gap: 6px !important;
    align-items: center !important;
}

.input-select-group input {
    flex: 1 !important;
    width: auto !important;
}

.input-select-group button {
    width: auto !important;
    padding: 0 12px !important;
    margin: 0 !important;
}

/* CONTENEDORES INTERNOS Y BOTONES DE MODALES */
.search-box-modal { margin-bottom: 10px !important; }

.modal-list-container {
    max-height: 220px !important;
    overflow-y: auto !important;
    border: 1px solid #CBD5E1 !important;
    border-radius: 4px !important;
}

.modal-footer-btns {
    display: flex !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    margin-top: 15px !important;
    border-top: 1px solid #E9ECEF !important;
    padding-top: 10px !important;
}

.modal-footer-btns button {
    width: auto !important;
    margin: 0 !important;
}

/* ==========================================================================
   MEDIA QUERIES (ADAPTACIÓN COMPLETA MÓVIL Y TABLET)
   ========================================================================== */

/* TABLETS (Pantallas medianas hasta 992px) */
@media (max-width: 992px) {
    .sidebar { 
        width: 200px; 
        min-width: 200px; 
    }
    
    .sidebar a, .sidebar-nav li a {
        padding: 12px 15px;
        font-size: 0.82rem;
    }

    .content, .content-wrapper {
        padding: 15px;
    }
}

/* MÓVILES Y PANTALLAS PEQUEÑAS (Hasta 768px) */
@media screen and (max-width: 768px) {
    .main-wrapper, .layout { 
        flex-direction: column; 
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid #E2E8F0;
    }

    /* Ocultar menú en móvil por defecto */
    .sidebar .sidebar-nav {
        display: none;
    }

    /* Mostrar menú al hacer clic en el botón de 3 barras */
    .sidebar.show-mobile .sidebar-nav {
        display: block;
    }

    .sidebar-nav ul {
        display: flex;
        flex-wrap: wrap;
        padding: 0;
    }

    .sidebar-nav li {
        flex: 1 1 50%; /* Dos ítems por fila en móvil */
    }

    .sidebar a, .sidebar-nav li a { 
        padding: 10px; 
        font-size: 0.78rem; 
        justify-content: center;
        border-right: 1px solid #E2E8F0;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 15px;
    }

    .header h2 {
        font-size: 1.1rem;
    }

    .header-buttons {
        width: 100%;
        display: flex;
        justify-content: space-between;
        gap: 10px;
    }

    .btn-head {
        flex: 1;
        justify-content: center;
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    .card {
        padding: 12px;
    }

    .table-responsive {
        max-height: 60vh;
    }

    .form-grid-compact {
        grid-template-columns: 1fr !important;
    }

    .col-span-3, .col-span-1-5 {
        grid-column: span 1 !important;
    }
}