/* ============================================================
   1. VARIABLES Y RESET
   ============================================================ */
:root {
    --brand-blue: #004B87;
    --brand-red: #E30613;
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --sidebar-w: 280px;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    margin: 0;
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Evita scroll en el body, lo gestiona .main */
}

/* ============================================================
   2. MENÚ HAMBURGUESA (MÓVIL)
   ============================================================ */
.hamburger-btn {
    display: none; /* Oculto en PC */
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;
    background: var(--brand-red) !important;
    color: white !important;
    border: none;
    padding: 12px 18px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(227, 6, 19, 0.4);
    font-weight: 800;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    font-size: 0.8rem;
}

/* ============================================================
   3. SIDEBAR Y NAVEGACIÓN
   ============================================================ */
.sidebar {
    width: var(--sidebar-w);
    background: #0b1120;
    display: flex;
    flex-direction: column;
    height: 100vh;
    border-right: 1px solid var(--border);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    flex-shrink: 0;
}

.logo-container {
    text-align: center;
    padding: 20px 15px;
}

.logo-container img {
    width: 200px;
    height: auto;
    display: block;
    margin: 0 auto 20px auto;
    object-fit: contain;
}

.menu-items {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.menu-group {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #1e293b;
}

.group-title {
    text-align: center;
    padding: 15px;
    font-size: 0.85rem;
    font-weight: 800;
    color: #64748b;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    user-select: none;
}

/* SUBMENÚS: ANIMACIÓN PREMIUM ACCORDION */
.submenu {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-10px);
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s ease, 
                transform 0.3s ease;
    pointer-events: none;
}

.submenu.open {
    max-height: 500px;
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    margin-top: 5px;
    margin-bottom: 15px;
}

.toggle-icon {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.7rem;
    display: inline-block;
    transform: rotate(-90deg);
}

/* BOTONES DE LA SIDEBAR */
.tab-btn {
    display: block !important;
    width: 90% !important;
    margin: 0 auto !important;
    text-align: center !important;
    padding: 12px !important;
    font-size: 0.95rem !important;
    color: #cbd5e1;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    background: var(--brand-blue) !important;
    color: white !important;
}

.tab-btn.active {
    background: var(--brand-blue) !important;
    color: white !important;
    font-weight: 600;
}

.tauler-btn {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white !important;
    padding: 20px;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 12px;
    width: 90%;
    margin: 10px auto 20px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: 0.3s;
}

.tauler-btn:hover {
    background: rgba(0, 75, 135, 0.4);
    border-color: var(--brand-blue);
}

.sidebar-footer {
    padding: 20px;
    background: #0b1120;
    border-top: 1px solid #1e293b;
    text-align: center;
    flex-shrink: 0;
}

.btn-logout {
    background: #DC2626 !important;
    color: white !important;
    width: 100%;
    padding: 14px;
    border-radius: 8px;
    font-weight: 800;
    border: none;
    cursor: pointer;
    transition: 0.3s;
}

.user-info {
    display: block;
    margin-top: 12px;
    font-size: 0.75rem;
    color: #475569;
}

/* ============================================================
   4. CONTENIDO PRINCIPAL (MAIN)
   ============================================================ */
.main {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    height: 100vh;
    box-sizing: border-box;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block !important;
    animation: fadeIn 0.3s ease-out;
}

/* BOTÓN BACKUP ROJO SEGURIDAD (DEGRADADO PREMIUM) */
.action-btn-custom {
    display: block;
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #E30613 0%, #8b0000 100%) !important;
    color: white !important;
    text-align: center;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 800;
    margin-top: 10px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(227, 6, 19, 0.3);
    transition: 0.3s;
}

.action-btn-custom:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(227, 6, 19, 0.5);
    filter: brightness(1.2);
}

/* ============================================================
   5. CARDS Y ESTADÍSTICAS
   ============================================================ */
.card {
    background: var(--card-bg);
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
}

.stat-card {
    background: #1e293b;
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    cursor: pointer;
    transition: 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--brand-blue);
    background: #2d3748;
}

/* ============================================================
   6. TABLAS DINÁMICAS
   ============================================================ */
#table-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    margin-top: 20px;
    box-sizing: border-box;
    overflow-x: auto;
    cursor: grab;
}

#dynamic-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 800px;
    color: #f1f5f9;
}

#dynamic-table th {
    padding: 15px;
    background-color: #0f172a;
    color: #60a5fa;
    cursor: pointer;
    text-transform: uppercase;
    white-space: nowrap;
    text-align: left; /* ALINEACIÓN A LA IZQUIERDA */
}

#dynamic-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #334155;
    white-space: nowrap;
}

#dynamic-table tr:hover {
    background-color: #2d3748;
}

.log-box {
    background: #000;
    color: #0f0;
    padding: 15px;
    border-radius: 6px;
    font-family: 'Consolas', monospace;
    height: 180px;
    overflow-y: auto;
    margin-top: 25px;
    border: 1px solid #333;
    transition: all 0.3s ease;
}

/* ============================================================
   BARRA D'EINES I PANTALLA COMPLETA DE TERMINAL
   ============================================================ */
.log-wrapper {
    position: relative;
    margin-top: 20px;
}

.log-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0b1120;
    padding: 10px 14px;
    border: 1px solid #334155;
    border-bottom: none;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    font-size: 0.85rem;
    color: #94a3b8;
    font-family: inherit;
    font-weight: 600;
}

.btn-log-toggle {
    background: #1e293b;
    border: 1px solid #475569;
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: 0.2s;
}

.btn-log-toggle:hover {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}

.log-box.maximized {
    position: fixed !important;
    top: 25px !important;
    left: 25px !important;
    right: 25px !important;
    bottom: 25px !important;
    width: calc(100vw - 50px) !important;
    height: calc(100vh - 50px) !important;
    max-height: none !important;
    z-index: 100000 !important;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.95) !important;
    border: 2px solid var(--brand-blue) !important;
    border-radius: 8px !important;
    padding: 55px 25px 25px 25px !important;
    box-sizing: border-box !important;
    font-size: 1rem !important;
    line-height: 1.6 !important;
}

.log-box-close-floating {
    display: none;
    position: fixed;
    top: 40px;
    right: 45px;
    z-index: 100001;
    background: #ef4444;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.5);
    text-transform: uppercase;
}

.log-box-close-floating.visible {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ============================================================
   7. FORMULARIOS E INPUTS
   ============================================================ */
.card input, 
.card select, 
.card textarea {
    background-color: #0f172a !important;
    color: #e2e8f0 !important;
    border: 1px solid #334155 !important;
    border-radius: 6px !important;
    padding: 12px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    font-family: inherit;
}

.card .action-btn {
    background: #004B87 !important;
    color: white !important;
    padding: 12px 20px !important;
    border-radius: 6px !important;
    font-weight: bold !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px !important;
    border: none;
    cursor: pointer;
    transition: 0.3s;
}

.card .action-btn:hover {
    background: #003a6a !important;
}

.card .btn-danger {
    background: #ef4444 !important;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.2);
}

.card .btn-danger:hover {
    background: #dc2626 !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(239, 68, 68, 0.4);
}

/* AUTOFILL FIX: TAPA EL FONDO BLANCO DEL NAVEGADOR */
.card input:-webkit-autofill {
    -webkit-text-fill-color: #e2e8f0 !important;
    -webkit-box-shadow: 0 0 0px 1000px #0f172a inset !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* RITMO VERTICAL */
.form-group {
    margin-bottom: 24px;
}

div[style*="display: grid"] > .form-group {
    margin-bottom: 0;
}

/* ============================================================
   8. MODALES PERSONALIZADOS
   ============================================================ */
#custom-modal {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.85) !important;
    display: none !important;
    visibility: hidden;
    opacity: 0;
    align-items: center;
    justify-content: center;
    z-index: 9999 !important;
    transition: opacity 0.2s ease;
}

#custom-modal.visible {
    display: flex !important;
    visibility: visible;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 500px;
    width: 90%;
    color: white;
    text-align: left;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-footer .action-btn {
    background: #004B87 !important;
    color: white !important;
    border: none !important;
    border-radius: 6px !important;
    padding: 10px 20px !important;
    cursor: pointer !important;
    font-weight: bold !important;
    font-family: inherit;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.modal-footer .action-btn.secondary {
    background: #334155 !important;
}

/* ============================================================
   9. SCROLLBAR Y RESPONSIVE
   ============================================================ */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #0b1120;
}

::-webkit-scrollbar-thumb {
    background: #1e293b;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

@media (max-width: 900px) {
    body {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }

    .hamburger-btn {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 1500;
        box-shadow: 10px 0 40px rgba(0,0,0,0.8);
    }

    .sidebar.active {
        left: 0;
    }

    .main {
        margin-left: 0;
        width: 100%;
        padding: 90px 15px 30px 15px;
        height: auto;
        min-height: 100vh;
        overflow-y: visible; /* PERMITE SCROLL EN MÓVIL */
    }

    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

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