/* =================================================================
   ESTILOS COMPATIBLES CON TAILWIND CSS + ESTILOS PERSONALIZADOS
   ================================================================= */

/* Variables de color originales para compatibilidad */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --background-color: #ecf0f1;
    --text-color: #2c3e50;
    --border-color: #bdc3c7;
    --light-bg: #ffffff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.modal-open {
    overflow: hidden;
}

/* BOTONES COMPATIBLES */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.3s ease;
    display: inline-block;
}

.btn-primary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

/* MODAL */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: var(--light-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 450px;
    width: 90%;
    animation: slideIn 0.3s ease;
}

.modal-content h2 {
    font-size: 1.8em;
    margin-bottom: 10px;
}

.modal-content p {
    margin-bottom: 10px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* LOADING SPINNER */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

.loading-spinner p {
    color: white;
    margin-top: 15px;
    font-weight: 600;
    font-size: 1.1em;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ESTILOS PARA CAMPOS DINÁMICOS COMPATIBILIDAD */
.download-note {
    margin-top: 10px;
    font-size: 0.95em;
}

.download-note a {
    text-decoration: underline;
}

/* CHECKBOX GROUP - Para secciones dinámicas */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: #f8f9fa;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}

.checkbox-item:hover {
    background-color: #e0f2fe;
    border-color: #0ea5e9;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin-right: 10px;
    accent-color: #1258e2;
}

.checkbox-item input[type="checkbox"]:checked ~ span {
    font-weight: 600;
    color: #1258e2;
}

.checkbox-item span {
    flex: 1;
    font-weight: 500;
    color: #334155;
}

/* SELECT GROUP - Para secciones dinámicas */
.select-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
    padding: 24px;
    background-color: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid #1258e2;
}

.select-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.select-item label {
    font-weight: 600;
    margin-bottom: 4px;
    color: #334155;
    font-size: 0.95em;
}

.select-item select {
    padding: 10px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95em;
    background-color: #ffffff;
    transition: all 0.3s ease;
}

.select-item select:focus {
    outline: none;
    border-color: #1258e2;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

.select-item input[type="text"] {
    padding: 10px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95em;
    background-color: #ffffff;
    transition: all 0.3s ease;
}

.select-item input[type="text"]:focus {
    outline: none;
    border-color: #1258e2;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

/* FORM GROUP - Para compatibilidad con código dinámico */
.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #334155;
    font-size: 0.95em;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 10px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    transition: all 0.3s ease;
    background-color: #f8f9fa;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #1258e2;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

/* DYNAMIC SECTION - Para compatibilidad con campos dinámicos */
#dynamicSection .bg-white {
    margin-bottom: 20px;
}

/* COMISIÓN DROPDOWN - Mejorado para diseño moderno */
.comision-dropdown {
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    background-color: #f8f9fa;
    transition: all 0.3s ease;
    width: 100%;
    position: relative;
}

.comision-dropdown[open] {
    border-color: #1258e2;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

.comision-dropdown summary {
    list-style: none;
    padding: 10px 40px 10px 12px;
    cursor: pointer;
    font-size: 0.95em;
    color: #334155;
    background-color: #f8f9fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    font-weight: 500;
    position: relative;
}

.comision-dropdown summary::after {
    content: '▼';
    position: absolute;
    right: 12px;
    color: #64748b;
    font-size: 0.7em;
    transition: transform 0.3s ease;
}

.comision-dropdown[open] summary {
    background-color: white;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 8px 8px 0 0;
}

.comision-dropdown[open] summary::after {
    transform: rotate(180deg);
}

.comision-dropdown summary::-webkit-details-marker {
    display: none;
}

/* COMISIÓN LIST - Lista de checkboxes */
.comision-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    max-height: 350px;
    overflow-y: auto;
    background-color: white;
}

/* COMISIÓN ITEM - Cada checkbox individual con ID */
.comision-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 4px 8px;
    background-color: #f8f9fa;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.9em;
}

.comision-item:hover {
    background-color: #e0f2fe;
    border-color: #1258e2;
}

.comision-item:has(input[type="checkbox"]:checked) {
    background-color: rgba(18, 88, 226, 0.05);
    border-color: #1258e2;
}

.comision-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.comision-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #1258e2;
    margin: 0;
    flex-shrink: 0;
}

.comision-name {
    font-weight: 500;
    color: #334155;
    flex: 1;
}

.comision-checkbox:checked ~ .comision-name {
    font-weight: 600;
    color: #1258e2;
}

.comision-id-input {
    width: 120px;
    padding: 6px 10px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.875em;
    background-color: #ffffff;
    transition: all 0.3s ease;
    text-align: center;
}

.comision-id-input:disabled {
    background-color: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
}

.comision-id-input:enabled:focus {
    outline: none;
    border-color: #1258e2;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

.dark .comision-list {
    background-color: #0f172a;
}

.dark .comision-item {
    background-color: #1e293b;
    border-color: #334155;
}

.dark .comision-item:hover {
    background-color: rgba(96, 165, 250, 0.1);
    border-color: #60a5fa;
}

.dark .comision-item:has(input[type="checkbox"]:checked) {
    background-color: rgba(96, 165, 250, 0.15);
    border-color: #60a5fa;
}

.dark .comision-name {
    color: #e2e8f0;
}

.dark .comision-checkbox:checked ~ .comision-name {
    color: #60a5fa;
}

.dark .comision-id-input {
    background-color: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}

.dark .comision-id-input:disabled {
    background-color: #334155;
    color: #64748b;
}

.dark .comision-id-input:enabled:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* COMISIÓN IDS - Contenedor de inputs por comisión */
.comision-ids {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    padding: 12px 0 0;
}

.comision-id-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.comision-id-item label {
    font-weight: 600;
    font-size: 0.9em;
    color: #475569;
}

.comision-id-item input[type="text"] {
    padding: 10px 12px;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95em;
    background-color: #f8f9fa;
    transition: all 0.3s ease;
}

.comision-id-item input[type="text"]:focus {
    outline: none;
    border-color: #1258e2;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

/* UTILIDADES */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeInElement 0.3s ease;
}

@keyframes fadeInElement {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* SIDEBAR NAVIGATION ACTIVE STATE */
.nav-link.active {
    background-color: #e0f2fe !important;
    border-left: 3px solid #1258e2;
    padding-left: calc(0.5rem - 3px);
}

.dark .nav-link.active {
    background-color: rgba(18, 88, 226, 0.15) !important;
}

.nav-link.active .w-10 {
    background-color: #1258e2 !important;
}

.nav-link.active .material-icons-outlined {
    color: white !important;
}

.nav-link.active span {
    color: #1258e2 !important;
    font-weight: 700 !important;
}

.dark .nav-link.active span {
    color: #60a5fa !important;
}

/* DYNAMIC SECTION headings */
#dynamicSection h3 {
    font-size: 1.4em;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

#dynamicSection h3::before {
    content: '';
    width: 4px;
    height: 28px;
    background: linear-gradient(180deg, #1258e2 0%, #0ea5e9 100%);
    border-radius: 2px;
}

#dynamicSection .bg-white {
    background-color: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(18, 88, 226, 0.1);
    margin-bottom: 20px;
}

/* Mejorar el scroll de listas largas */
.comision-list::-webkit-scrollbar {
    width: 8px;
}

.comision-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.comision-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.comision-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Nav container para desktop y mobile */
.nav-container {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Ocultar el boton de cierre fuera de mobile */
.mobile-close-btn {
    display: none;
}

/* Dropdown de funciones */
.funciones-dropdown {
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    background-color: #f8f9fa;
    transition: all 0.3s ease;
    width: 100%;
    position: relative;
}

.funciones-dropdown[open] {
    border-color: #1258e2;
    box-shadow: 0 0 0 3px rgba(18, 88, 226, 0.1);
}

.funciones-dropdown summary {
    list-style: none;
    padding: 12px 40px 12px 16px;
    cursor: pointer;
    font-size: 0.95em;
    color: #334155;
    background-color: #f8f9fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    font-weight: 500;
    position: relative;
    min-height: 48px;
}

.funciones-dropdown summary::after {
    content: '▼';
    position: absolute;
    right: 16px;
    color: #64748b;
    font-size: 0.7em;
    transition: transform 0.3s ease;
}

.funciones-dropdown[open] summary {
    background-color: white;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 8px 8px 0 0;
}

.funciones-dropdown[open] summary::after {
    transform: rotate(180deg);
}

.funciones-dropdown summary::-webkit-details-marker {
    display: none;
}

.dark .funciones-dropdown {
    border-color: #475569;
    background-color: #1e293b;
}

.dark .funciones-dropdown summary {
    background-color: #1e293b;
    color: #e2e8f0;
}

.dark .funciones-dropdown[open] summary {
    background-color: #0f172a;
    border-bottom-color: #334155;
}

/* Lista de funciones */
.funciones-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    max-height: 350px;
    overflow-y: auto;
    background-color: white;
}

/* Lista de Sub Espacios: sin altura máxima global, cada grupo se expande completo */
#subfuncionCheckboxGroup.funciones-list {
    max-height: none;
    overflow-y: visible;
    gap: 8px;
}

.dark .funciones-list {
    background-color: #0f172a;
}

/* Grupos de funciones dentro del deslizable Sub Espacio */
.subfuncion-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid #e2e8f0;
    margin-bottom: 4px;
}

.subfuncion-group:last-child {
    margin-bottom: 0;
}

.dark .subfuncion-group {
    border-color: #334155;
}

.subfuncion-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    background-color: #1258e2;
    color: white;
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    gap: 8px;
}

.subfuncion-group-header:hover {
    background-color: #0e47c5;
}

.subfuncion-group-header .group-chevron {
    font-size: 1em;
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.subfuncion-group.collapsed .group-chevron {
    transform: rotate(-90deg);
}

.subfuncion-group-counter {
    background-color: rgba(255,255,255,0.25);
    border-radius: 20px;
    padding: 1px 7px;
    font-size: 0.85em;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    margin-left: auto;
}

.subfuncion-group-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background-color: white;
    overflow: visible;
}

.dark .subfuncion-group-body {
    background-color: #0f172a;
}

.subfuncion-group.collapsed .subfuncion-group-body {
    display: none;
}

/* Estilos para checkboxes de funciones */
.funcion-checkbox-item {
    transition: all 0.3s ease;
    margin: 0;
}

.funcion-checkbox-item:has(input:checked) {
    background-color: rgba(18, 88, 226, 0.1) !important;
    border-color: #1258e2 !important;
}

.dark .funcion-checkbox-item:has(input:checked) {
    background-color: rgba(96, 165, 250, 0.2) !important;
    border-color: #60a5fa !important;
}

.funcion-checkbox-item input:checked + span {
    color: #1258e2 !important;
    font-weight: 600;
}

.dark .funcion-checkbox-item input:checked + span {
    color: #60a5fa !important;
}

/* Tarjetas colapsables de funciones */
#dynamicSection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    align-items: start;
}

.function-card {
    transition: all 0.3s ease;
    margin-bottom: 0;
}

.function-card-header {
    position: relative;
}

.function-card-header .material-icons-outlined:last-child {
    transition: transform 0.3s ease;
}

.function-card-body {
    transition: all 0.3s ease;
    overflow: hidden;
}

@media (max-width: 768px) {
    #dynamicSection {
        grid-template-columns: 1fr;
    }
}


/* Responsive para sidebar */
@media (max-width: 1024px) {
    aside {
        width: 250px !important;
    }
}

@media (max-width: 768px) {
    .flex.h-screen {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    aside {
        width: 100% !important;
        height: auto;
        border-right: none;
        border-bottom: 1px solid rgba(18, 88, 226, 0.1);
    }
    
    aside .p-6 {
        padding: 1rem !important;
    }
    
    aside nav {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        padding: 0;
        overflow-y: auto;
        animation: fadeIn 0.2s ease-out;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    aside nav.mobile-show {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    aside nav .nav-container {
        background: white;
        border-radius: 12px;
        padding: 2rem;
        max-width: 90%;
        width: 400px;
        max-height: 80vh;
        overflow-y: auto;
        position: relative;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        animation: slideUp 0.3s ease-out;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(20px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    #sidebarToggle {
        display: block !important;
    }

    .mobile-close-btn {
        display: inline-flex;
    }
    
    aside .p-4.border-t {
        padding: 0.75rem !important;
    }
    
    main {
        flex: 1;
        overflow-y: auto;
        height: auto;
    }
    
    header.sticky {
        position: relative !important;
        padding: 0.75rem 1rem !important;
    }
    
    header .flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.25rem;
    }
    
    header h2 {
        font-size: 1.125rem !important;
    }
    
    header p {
        font-size: 0.7rem !important;
    }
    
    .max-w-5xl {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .px-10 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .py-12, .py-6 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .space-y-16 > * + *, .space-y-8 > * + * {
        margin-top: 1.5rem !important;
    }
    
    .modal-content {
        padding: 20px !important;
        margin: 1rem !important;
    }
    
    .checkbox-group {
        grid-template-columns: 1fr;
    }
    
    .select-group {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
    
    .comision-list {
        gap: 6px;
        padding: 12px;
        max-height: 300px;
    }
    
    .comision-item {
        grid-template-columns: 1fr 80px;
        gap: 8px;
        padding: 8px 10px;
        font-size: 0.85em;
    }
    
    .comision-id-input {
        width: 80px;
        font-size: 0.8em;
        padding: 5px 8px;
    }
    
    .funciones-list {
        gap: 6px;
        padding: 12px;
        max-height: 300px;
    }
    
    .funcion-checkbox-item {
        padding: 10px !important;
        font-size: 0.875rem;
    }
    
    .comision-ids {
        grid-template-columns: 1fr;
    }
    
    #dynamicSection .bg-white {
        padding: 1.25rem !important;
    }
    
    .bg-white.rounded-xl {
        padding: 1.25rem !important;
    }
    
    .grid.grid-cols-1.md\\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* Botones sticky en móviles */
    .sticky.bottom-0 {
        position: sticky;
        bottom: 0;
        padding: 0.75rem !important;
    }
    
    .sticky.bottom-0 .flex {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .sticky.bottom-0 button {
        width: 100%;
        padding: 0.875rem !important;
    }
}

@media (max-width: 480px) {
    header h2 {
        font-size: 1rem !important;
    }
    
    header p {
        font-size: 0.625rem !important;
    }
    
    .text-xl {
        font-size: 1.125rem !important;
    }
    
    .text-2xl {
        font-size: 1.25rem !important;
    }
    
    .w-8.h-8 {
        width: 1.75rem !important;
        height: 1.75rem !important;
    }
}

#sidebarToggle {
    display: none;
}
