/* --- VARIABLES DE DISEÑO: DEEP BLUE & AZURE SLATE (PROFIT BANK) --- */
:root {
    --primary-brand: #1e3a8a;        /* Soft Azure (Primario corporativo) */
    --accent-cyan: #0ea5e9;         /* Soft Cyan (Acentos y botones alternos) */
    --accent-jade: #34d399;         /* Light Jade (Éxitos y confirmaciones) */
    --header-bg: #020617;           /* Deep Blue (Fondo oscuro barra lateral) */
    --bg-body: #f0fdfa;             /* Icy Teal (Fondo de página sutil) */
    --text-primary: #1e293b;        /* Slate Slate (Texto oscuro principal) */
    --text-secondary: #64748b;      /* Slate Light (Texto secundario) */
    --card-bg: #ffffff;
    --border-color: #cbd5e1;
    --success-green: #34d399;
    --success-hover: #0ea5e9;
    --danger-coral: #ef4444;        /* Coral para indicadores "NO" y alertas */
    --warning-amber: #f59e0b;       /* Ambar corporativo para advertencias */
    
    --sidebar-width: 290px;
    --sidebar-collapsed-width: 80px;
    --border-radius: 16px;
    --transition-speed: 0.3s;
    --editor-bg: #0b1020;
}

body {
    background-color: var(--bg-body);
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: var(--text-primary); 
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* --- OPTIMIZACIÓN: SCROLLBAR DE ALTA FIDELIDAD (EVITA SCROLLBARS DE DEFECTO) --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #020617;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

/* --- BARRA LATERAL (SIDEBAR) --- */
.sidebar {
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--header-bg);
    color: #f1f5f9;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    transition: width var(--transition-speed) ease, padding var(--transition-speed) ease;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    padding: 24px 20px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.05);
    overflow: visible;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: 24px 10px;
}

.sidebar-scroll-area {
    flex-grow: 1;
    overflow-y: auto;      
    overflow-x: hidden;    
    margin-right: -10px;   
    padding-right: 10px;
}

/* Ocultar elementos de texto al colapsar y centrado de iconos */
.sidebar.collapsed .logo-text,
.sidebar.collapsed .filter-label,
.sidebar.collapsed .drop-zone__prompt,
.sidebar.collapsed .btn-text,
.sidebar.collapsed .input-group,
.sidebar.collapsed .form-control,
.sidebar.collapsed .row.g-1,
.sidebar.collapsed .list-item-text,
.sidebar.collapsed .badge-table,
.sidebar.collapsed .section-toggle-icon,
.sidebar.collapsed .sidebar-section-header,
.sidebar.collapsed .collapse,
.sidebar.collapsed .text-center.mt-3.filter-label-home,
.sidebar.collapsed .hide-on-collapse {
    display: none !important;
}

.sidebar.collapsed .logo-icon {
    display: block;
    font-size: 1.65rem;
    text-align: center;
    margin: 0 auto;
    color: var(--accent-cyan);
}

/* Centrado automático de íconos de listas y alertas cuando está colapsado */
.sidebar.collapsed .list-group-item {
    justify-content: center !important;
    padding: 12px 0 !important;
}
.sidebar.collapsed .list-group-item i {
    margin-right: 0 !important;
    font-size: 1.35rem !important;
}
.sidebar.collapsed .alert {
    padding: 10px 0 !important;
}
.sidebar.collapsed .alert i {
    margin: 0 !important;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
    height: 40px;
    white-space: nowrap; 
}

.logo-text { 
    font-weight: 800; 
    font-size: 1.25rem; 
    color: #ffffff; 
    letter-spacing: -0.5px;
}
.logo-icon { 
    font-size: 1.5rem;
    color: var(--accent-cyan); 
}

.toggle-btn {
    position: absolute;
    top: 25px;
    right: -15px; 
    width: 30px;
    height: 30px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    z-index: 1010;
    color: var(--text-secondary);
    transition: transform 0.2s;
}
.toggle-btn:hover {
    color: var(--primary-brand);
    transform: scale(1.1);
}

/* Títulos y etiquetas de alta visibilidad en Sidebar */
.sidebar .filter-label, .sidebar h6 {
    color: #f1f5f9 !important; /* Blanco brillante de alto contraste */
    font-weight: 800;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    margin-top: 15px;
    text-transform: uppercase;
}

.sidebar label.small {
    color: #f1f5f9 !important;
    font-weight: 600;
}

.sidebar .text-white-50 {
    color: #f1f5f9 !important;
    font-weight: 500;
}

.sidebar .fw-bold.text-white {
    color: #ffffff !important;
}

.sidebar .small.text-muted, .sidebar .filter-label-home a {
    color: #cbd5e1 !important;
    font-weight: 600;
}

.sidebar .filter-label-home a:hover {
    color: var(--accent-cyan) !important;
    text-decoration: underline !important;
}

/* Diseño Drag & Drop Sidebar */
.sidebar .drop-zone {
    border: 2px dashed rgba(14, 165, 233, 0.4);
    background: rgba(255, 255, 255, 0.04);
}
.sidebar .drop-zone:hover {
    border-color: var(--accent-cyan);
    background: rgba(255, 255, 255, 0.08);
}
.sidebar .drop-zone__prompt {
    color: #e2e8f0 !important;
}
.sidebar .drop-zone__prompt strong {
    color: #ffffff !important;
    font-weight: 800;
}

/* --- COLLAPSIBLE SECTIONS EN SIDEBAR --- */
.sidebar-section-header {
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
}
.section-toggle-icon {
    transition: transform 0.25s ease-in-out;
    font-size: 0.85rem;
    color: var(--accent-cyan);
}
/* Rotación del Chevron al abrir la sección colapsada */
.sidebar-section-header[aria-expanded="true"] .section-toggle-icon {
    transform: rotate(180deg);
}

/* --- MAIN CONTENT AREA --- */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 30px;
    transition: margin-left var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

/* --- BARRA SUPERIOR (TOP BAR) --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: #ffffff;
    padding: 16px 24px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(0,0,0,0.05);
    flex-wrap: wrap;
    gap: 15px;
    position: sticky;
    top: 0;
    z-index: 990;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.page-title h2 { 
    font-weight: 800; 
    font-size: 1.6rem; 
    margin: 0; 
    color: var(--text-dark);
}
.page-title p { 
    color: var(--text-secondary); 
    margin: 0; 
    font-size: 0.85rem; 
}

/* --- SELECTOR DE BASE DE DATOS PREMIUM --- */
.db-selector-container {
    width: 210px;
}
.text-cyan-brand {
    color: var(--accent-cyan) !important;
}

.db-selector-custom {
    background-color: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
    color: var(--text-primary) !important;
    border-radius: 50px !important;
    padding: 0.45rem 1rem 0.45rem 2.4rem !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    cursor: pointer;
    background-position: right 0.8rem center !important;
}

/* --- CARDS & PANELS --- */
.custom-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 24px;
    border: 1px solid rgba(0,0,0,0.04);
    box-shadow: 0 4px 20px rgba(0,0,0,0.01);
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}
.custom-card:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 8px 30px rgba(0,0,0,0.02);
}

.card-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 18px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* --- ACCIONES FIJAS SIDEBAR --- */
.sidebar-footer-fixed {
    flex-shrink: 0;
    padding-top: 15px;
    background-color: var(--header-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* --- DRAG & DROP ZONE --- */
.drop-zone {
    border: 2px dashed rgba(255,255,255,0.15);
    border-radius: 12px;
    padding: 20px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255,255,255,0.02);
}
.drop-zone:hover { 
    border-color: var(--accent-cyan); 
    background: rgba(255,255,255,0.05); 
}

.sidebar.collapsed .drop-zone {
    padding: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent; 
    background: transparent; 
}
.sidebar.collapsed .drop-zone i {
    font-size: 1.6rem;
    color: var(--accent-cyan);
    margin-bottom: 0 !important;
}

/* --- INDICADORES INTERRUPTORES (TOGGLE GROUPS) --- */
.indicator-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}
.indicator-row:last-child { 
    border-bottom: none; 
}

.btn-group-toggle .btn {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background-color: #f8fafc;
    color: var(--text-secondary);
}

/* Estados Activos Integrados de Toggles */
.btn-check-si:checked + .btn {
    background-color: var(--accent-jade) !important;
    border-color: var(--accent-jade) !important;
    color: #ffffff !important;
}

.btn-check-no:checked + .btn {
    background-color: var(--danger-coral) !important;
    border-color: var(--danger-coral) !important;
    color: #ffffff !important;
}

.btn-check-active:checked + .btn {
    background-color: var(--primary-brand) !important;
    border-color: var(--primary-brand) !important;
    color: #ffffff !important;
}

/* --- LISTAS EN SIDEBAR (TABLAS Y REGISTROS) --- */
.sidebar .list-group-item {
    border: none;
    padding: 12px 15px;
    border-radius: 10px !important;
    margin-bottom: 6px;
    background-color: transparent;
    color: #cbd5e1 !important; 
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}
.sidebar .list-group-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #ffffff !important; 
}
.sidebar .list-group-item.active {
    background-color: rgba(30, 58, 138, 0.4) !important;
    color: #ffffff !important; 
    font-weight: 700;
    border-left: 3px solid var(--accent-cyan);
    border-radius: 0 10px 10px 0 !important;
}
.sidebar .list-group-item i {
    margin-right: 12px;
    font-size: 1.1rem;
}
.badge-table {
    background: rgba(255,255,255,0.15);
    color: #e2e8f0;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 6px;
    margin-left: auto;
}

/* --- CATÁLOGO DE PRODUCTOS SCROLL LIST --- */
.products-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 5px;
    max-height: 380px;
}

.product-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
    border-bottom: 1px solid #f8fafc;
}
.product-item:hover { 
    background-color: rgba(14, 165, 233, 0.05); 
}

.badge-id {
    background: #e0f2fe;
    color: #0369a1;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-right: 12px;
    min-width: 42px;
    text-align: center;
}

/* --- TABS ESTILO PLANO (PILLS) --- */
.nav-pills .nav-link {
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
    transition: all 0.2s;
}
.nav-pills .nav-link:hover {
    color: var(--primary-brand);
    background-color: rgba(30, 58, 138, 0.04);
}
.nav-pills .nav-link.active {
    background-color: var(--primary-brand) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.25);
}

/* --- INPUTS MANUALES --- */
.manual-input-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 12px;
    font-size: 0.85rem;
    resize: none;
    width: 100%;
    font-family: 'JetBrains Mono', monospace;
    transition: border-color 0.2s;
}
.manual-input-box:focus {
    border-color: var(--primary-brand);
    background: #ffffff;
    outline: none;
}

/* --- BOTÓN PRINCIPAL DE PROCESAMIENTO (CON GRADIENTE) --- */
.btn-process-full { 
    background-image: linear-gradient(45deg, #020617, #1e3a8a, #0ea5e9, #34d399); 
    background-size: 300% auto;
    color: white !important; 
    border: none !important; 
    border-radius: 12px !important; 
    padding: 12px 24px !important; 
    width: 100%; 
    font-weight: 700; 
    font-size: 0.95rem; 
    text-transform: uppercase; 
    transition: all 0.5s ease-in-out !important; 
    box-shadow: 0 4px 15px rgba(30, 58, 138, 0.25);
}

.btn-process-full:hover { 
    background-position: right center !important; 
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.45) !important;
    transform: translateY(-1px);
}

.btn-process-full:disabled { 
    background-image: none !important;
    background-color: #cbd5e1 !important; 
    cursor: not-allowed; 
    box-shadow: none !important;
}

/* --- COMPLEMENTOS ADICIONALES --- */
.file-info-tag {
    display: none;
    background-color: rgba(52, 211, 153, 0.15);
    color: #f1f5f9; 
    border: 1px solid rgba(52, 211, 153, 0.3);
    border-radius: 8px;
    padding: 6px 12px;
    margin-top: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

.loading-box {
    display: none;
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    background: rgba(14, 165, 233, 0.1);
    color: #0c4a6e;
    border: 1px solid rgba(14, 165, 233, 0.3);
}

/* --- BOTONES EXCEL Y CSV BAJO NORMAS CORPORATIVAS --- */
.btn-outline-success {
    border-color: var(--primary-brand) !important;
    color: var(--primary-brand) !important;
    background-color: transparent !important;
    font-weight: 600 !important;
    transition: all 0.25s ease-in-out !important;
}
.btn-outline-success:hover {
    background-color: var(--primary-brand) !important;
    color: white !important;
    border-color: var(--primary-brand) !important;
}
.btn-check:checked + .btn-outline-success {
    background-color: var(--primary-brand) !important;
    color: white !important;
    border-color: var(--primary-brand) !important;
}

.btn-outline-primary {
    border-color: var(--accent-cyan) !important;
    color: var(--accent-cyan) !important;
    background-color: transparent !important;
    font-weight: 600 !important;
    transition: all 0.25s ease-in-out !important;
}
.btn-outline-primary:hover {
    background-color: var(--accent-cyan) !important;
    color: white !important;
    border-color: var(--accent-cyan) !important;
}
.btn-check:checked + .btn-outline-primary {
    background-color: var(--accent-cyan) !important;
    color: white !important;
    border-color: var(--accent-cyan) !important;
}

/* --- EFECTOS ADICIONALES PARA COLAPSABLES Y TABLAS --- */
.collapse-icon {
    transition: transform 0.3s ease;
}
.card-header-custom:not(.collapsed) .collapse-icon {
    transform: rotate(180deg);
}

.table-container-wrapper {
    height: auto !important;
    min-height: 250px;
    max-height: calc(100vh - 130px);
}
.table-container-wrapper.collapsed {
    min-height: 60px !important;
    height: 60px !important;
}

/* --- CONEXIONES DE PESTAÑAS Y NAVEGACIÓN UNIFICADA DE BARRA SUPERIOR (TOP BAR) --- */
.nav-pills-container {
    background-color: #f1f5f9;
    padding: 4px;
    border-radius: 50px;
    border: 1px solid #e2e8f0;
}

.btn-nav-modern {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 18px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.25s ease-in-out;
    display: flex;
    align-items: center;
}

.btn-nav-modern:hover {
    color: var(--primary-brand);
    background-color: rgba(30, 58, 138, 0.05);
}

.btn-nav-modern.active {
    background: var(--primary-brand) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 10px rgba(30, 58, 138, 0.2) !important;
}

/* --- ESTRUCTURA SQL AVANZADA (RESIZABLE) --- */
.content-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.col-editor {
    flex: 0 0 auto;
}

.editor-wrapper {
    background-color: var(--editor-bg);
    border-radius: 12px;
    padding: 15px;
    position: relative;
    border: 1px solid rgba(255,255,255,0.08);
    height: 310px;
    min-height: 150px;
    max-height: 75vh;
    resize: vertical;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sql-textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: #e5e7eb;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    resize: none;
    outline: none;
    line-height: 1.6;
    flex-grow: 1;
}

.col-results {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.results-card {
    height: 100%;
    overflow: hidden;
}

.table-responsive {
    border-radius: 12px;
    flex-grow: 1;
    overflow: auto;
}

/* --- INICIO (INDEX) REDISEÑADO CON METRICAS --- */
.metric-widget {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 20px 24px;
    border: 1px solid rgba(0,0,0,0.04);
    box-shadow: 0 4px 15px rgba(0,0,0,0.01);
    display: flex;
    align-items: center;
    gap: 16px;
    height: 100%;
}
.metric-icon-circle {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.metric-val {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--text-dark);
    margin: 0;
    line-height: 1.2;
}
.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 0;
    text-transform: uppercase;
}

.portal-card-premium {
    border: 1px solid rgba(0,0,0,0.04);
    border-radius: 20px;
    background: #ffffff;
    padding: 30px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-decoration: none !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s;
    box-shadow: 0 4px 20px rgba(0,0,0,0.02);
}
.portal-card-premium:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(30, 58, 138, 0.08);
}
.portal-card-premium .card-btn {
    margin-top: auto;
    background-color: var(--primary-brand);
    color: #ffffff;
    padding: 10px 24px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.85rem;
    border: none;
    transition: all 0.2s;
}
.portal-card-premium:hover .card-btn {
    background-color: var(--accent-cyan);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

/* --- CLASES DE UTILIDAD DE COLORES CORPORATIVOS (SOBRESCRIBIENDO BOOTSTRAP NATIVO) --- */
.text-success { color: var(--success-green) !important; }
.bg-success { background-color: var(--success-green) !important; color: #ffffff !important; }

.text-danger { color: var(--danger-coral) !important; }
.bg-danger { background-color: var(--danger-coral) !important; color: #ffffff !important; }

.text-warning { color: var(--warning-amber) !important; }
.bg-warning { background-color: var(--warning-amber) !important; color: #020617 !important; }

/* --- ESTILOS PARA BADGES DE ESTADO EN SIDEBAR --- */
.sidebar .badge.bg-success-subtle {
    background-color: #000000 !important;
    color: var(--accent-jade) !important;
    border: 1px solid rgba(52, 211, 153, 0.3) !important;
    font-weight: 700;
}

/* Código para añadir a tu main.css */
@media (max-width: 768px) {
    .sidebar {
        display: none !important; /* Ocultar sidebar en móviles */
    }
    .main-content {
        padding: 10px !important;
        margin-left: 0 !important;
    }
    .portal-card-premium {
        width: 100% !important;
        margin-bottom: 15px;
    }
}