/* ==========================================================================
   style.css v66 - B1 Pulse
   Formato: Expandido, Una propiedad por línea.
   Actualización: Buscador Global, Permisos Granulares, Flatpickr Ranges.
   ========================================================================== */

:root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-topbar: #ffffff;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --ai-purple: #8b5cf6;
    
    --sidebar-text: #475569;
    --sidebar-icon-color: #64748b;
    --sidebar-active-bg: #eff6ff;
    --sidebar-active-text: #2563eb;
    
    --border-color: #e2e8f0;
    
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

html, 
body {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    font-family: 'Inter', sans-serif; 
    background-color: var(--bg-body); 
    background-image: radial-gradient(at 0% 0%, hsla(253,16%,7%,0.03) 0, transparent 50%), 
                      radial-gradient(at 50% 0%, hsla(225,39%,30%,0.03) 0, transparent 50%), 
                      radial-gradient(at 100% 0%, hsla(339,49%,30%,0.03) 0, transparent 50%);
    color: var(--text-main); 
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

ul {
    list-style: none;
}

button {
    font-family: inherit;
    outline: none;
}

/* CARGA GLOBAL Y TARJETAS */
.full-page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-body);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.loader-content i {
    font-size: 50px;
    color: var(--primary);
    animation: spin 1.2s linear infinite;
}

.loader-content p {
    font-weight: 600;
    color: var(--text-muted);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* LOGIN */
.login-wrapper { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-color: var(--bg-sidebar); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    z-index: 1000; 
    padding: 20px;
    overflow-y: auto;
}

.login-split { 
    display: flex; 
    width: 450px; 
    max-width: 100%;
    flex-direction: column;
    min-height: auto; 
    background-color: var(--bg-card); 
    border-radius: var(--radius-lg); 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15); 
    border: 1px solid var(--border-color);
    overflow-x: hidden; 
    overflow-y: auto;
    padding: 40px;
    margin: auto;
}

.login-image { 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    text-align: center; 
    margin-bottom: 30px;
}

.login-branding i { 
    font-size: 55px; 
    margin-bottom: 15px;
    color: var(--primary);
}

.login-branding h1 { 
    font-size: 28px; 
    font-weight: 800;
    margin-top: 10px; 
    margin-bottom: 5px; 
    color: var(--text-main);
}

.login-branding p { 
    color: var(--text-muted); 
    font-size: 14px; 
}

#login-custom-logo {
    max-width: 250px;
    max-height: 100px;
    object-fit: contain;
}

.login-form-container { 
    width: 100%;
    display: flex; 
    align-items: center; 
    justify-content: center;
}

.login-form-wrapper { 
    width: 100%; 
}

.login-form-wrapper h2 { 
    font-size: 20px; 
    margin-bottom: 5px; 
    text-align: center;
}

.login-form-wrapper .subtitle { 
    color: var(--text-muted); 
    font-size: 14px; 
    margin-bottom: 30px; 
    text-align: center;
}

/* =========================================================
   INPUTS FLOTANTES (CORRECCIÓN VISIBILIDAD)
   ========================================================= */
.input-floating { 
    position: relative; 
    margin-bottom: 25px; 
    width: 100%;
}

.input-floating input,
.input-floating select { 
    width: 100%; 
    padding: 24px 16px 8px;
    border: 1px solid var(--border-color); 
    border-radius: var(--radius-md); 
    font-family: inherit;
    font-size: 15px;
    color: var(--text-main);
    transition: all 0.2s ease;
    background-color: var(--bg-body);
    height: 54px;
}

.input-floating input:focus,
.input-floating select:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1); 
    background-color: #ffffff;
}

.input-floating label { 
    position: absolute; 
    left: 16px; 
    top: 16px; 
    color: var(--text-muted); 
    transition: 0.2s ease all; 
    pointer-events: none; 
    font-size: 15px;
}

.input-floating input:focus ~ label, 
.input-floating input:not(:placeholder-shown) ~ label,
.input-floating select ~ label { 
    top: 6px; 
    left: 14px; 
    font-size: 11px; 
    color: var(--primary); 
    font-weight: 700; 
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    font-weight: 500;
    margin-bottom: 15px;
}

#app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* SIDEBAR Y MENÚ */
.sidebar { 
    width: 260px; 
    flex-shrink: 0;
    background-color: var(--bg-sidebar); 
    border-right: none;
    border-top-right-radius: 0px; 
    border-bottom-right-radius: var(--radius-lg);
    box-shadow: 4px 0 15px rgba(0,0,0,0.03);
    position: fixed; 
    top: 0;
    left: 0;
    height: 100vh; 
    z-index: 1000; 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.sidebar .logo {
    padding: 30px 24px 20px;
    border-bottom: none; 
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.logo-text {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
}

.logo-text i {
    color: var(--primary);
    font-size: 28px;
    margin-bottom: 5px;
}

#sidebar-custom-logo {
    max-width: 200px;
    max-height: 180px;
    object-fit: contain;
}

.mobile-close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 15px;
}

.sidebar-menu { 
    padding: 20px 12px; 
}

.menu-label { 
    font-size: 11px; 
    color: var(--text-muted); 
    font-weight: 700; 
    letter-spacing: 0.5px; 
    margin-bottom: 8px; 
    margin-top: 16px;
    padding-left: 12px;
}

.sidebar-menu li { 
    padding: 12px 14px; 
    border-radius: var(--radius-md); 
    cursor: pointer; 
    color: var(--sidebar-text); 
    font-weight: 500; 
    font-size: 14px;
    transition: all 0.2s ease; 
    margin-bottom: 4px; 
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-menu li i {
    color: var(--sidebar-icon-color);
    opacity: 0.8;
    font-size: 18px;
    width: 22px;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-menu li:hover { 
    background-color: var(--sidebar-active-bg); 
    color: var(--sidebar-active-text);
}

.sidebar-menu li:hover i {
    opacity: 1;
    color: var(--primary); 
    transform: scale(1.15);
}

.sidebar-menu li.active { 
    background-color: var(--primary); 
    color: white; 
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.sidebar-menu li.active i {
    color: white;
    opacity: 1;
}

.main-content { 
    flex-grow: 1;
    margin-left: 260px; 
    width: calc(100% - 260px);
    max-width: 100%;
    min-height: 100vh; 
    display: flex;
    flex-direction: column;
    background-color: transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 900;
}

.topbar { 
    background-color: var(--bg-topbar); 
    padding: 16px 30px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-bottom: 1px solid var(--border-color);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.mobile-menu-btn {
    display: none;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    font-size: 18px;
    color: var(--text-main);
    cursor: pointer;
}

.user-profile-wrapper {
    position: relative;
    max-width: 50%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
    background-color: var(--bg-topbar); 
    border: 1px solid var(--border-color);
    color: var(--text-main);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    max-width: 100%;
}

.user-profile:hover {
    filter: brightness(0.95);
    border-color: #cbd5e1;
}

.avatar {
    width: 32px;
    height: 32px;
    min-width: 32px; 
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: var(--shadow-sm);
}

#display-username {
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px; 
}

/* =========================================================
   NUEVO: DROPDOWN DE BÚSQUEDA (REPORTES)
   ========================================================= */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    z-index: 2000;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInCategory {
    from { opacity: 0; }
    to { opacity: 1; }
}

.dropdown-menu ul {
    list-style: none;
    margin: 0;
    padding: 5px 0;
}

.dropdown-menu li {
    padding: 12px 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
}

.dropdown-menu li:hover {
    background-color: var(--bg-body);
}

.dropdown-menu li i {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

/* DROPDOWN ESPECÍFICO DE BÚSQUEDA DE REPORTES */
#global_search_results li {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
}
#global_search_results li:last-child {
    border-bottom: none;
}
#global_search_results li span {
    font-size: 11px;
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
}

.text-danger {
    color: var(--danger) !important;
}

.toolbar { 
    padding: 20px 30px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.welcome-hero {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.welcome-text h1 {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -1px;
    color: var(--text-main);
}

.welcome-text p {
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1.5;
    max-width: 500px;
}

.welcome-illustration i {
    font-size: 120px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.8;
}

.quick-filters { 
    display: flex; 
    gap: 8px; 
    flex-wrap: wrap;
}

.quick-filters button {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.quick-filters button:hover {
    background-color: var(--bg-body);
    border-color: #cbd5e1;
}

.btn-pdf { color: var(--text-main) !important; }
.btn-pdf i { color: var(--danger); margin-right: 5px; }

.btn-logout { 
    background-color: transparent; 
    border: 1px solid transparent; 
    padding: 6px 12px; 
    border-radius: var(--radius-sm); 
    cursor: pointer; 
    font-weight: 500; 
    font-size: 13px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.btn-logout:hover {
    background-color: #fee2e2;
    color: var(--danger);
}

.btn-primary, 
.btn-save, 
.btn-login { 
    background-color: var(--primary);
    color: white; 
    border: none; 
    padding: 12px 20px; 
    border-radius: var(--radius-sm); 
    cursor: pointer; 
    font-weight: 600; 
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-login { 
    width: 100%; 
    padding: 16px;
    justify-content: center;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-primary:hover, 
.btn-save:hover, 
.btn-login:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-cancel { 
    background-color: white; 
    border: 1px solid var(--border-color); 
    padding: 12px 20px; 
    border-radius: var(--radius-md); 
    cursor: pointer; 
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
    transition: background-color 0.2s;
}

.btn-cancel:hover { 
    background-color: var(--bg-body); 
}

/* =========================================================
   CALENDARIO FLATPICKR Y FECHAS
   ========================================================= */
.date-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-card);
    padding: 6px 6px 6px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap; 
}

.date-selector input {
    border: none;
    font-family: inherit;
    color: var(--text-main);
    font-weight: 600;
    font-size: 13px;
    outline: none;
    background-color: transparent;
    cursor: pointer;
    flex: 1; 
    text-align: center;
    min-width: 90px;
}

.date-selector input:hover {
    color: var(--primary);
}

.date-selector span {
    font-size: 13px;
    color: var(--text-muted);
}

.btn-refresh { 
    background-color: var(--bg-body); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
    width: 32px; 
    height: 32px; 
    border-radius: 50%; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-refresh:hover {
    background-color: white;
    border-color: var(--primary);
    color: var(--primary);
    transform: rotate(180deg);
}

/* =========================================================
   FOOTER MODULAR
   ========================================================= */
.app-footer {
    margin-top: auto; 
    padding: 20px 30px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-card);
    width: 100%;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--text-muted);
    font-size: 12px;
}

.footer-links {
    display: flex;
    gap: 15px;
    align-items: center;
}

.footer-brand strong {
    color: var(--text-main);
    font-weight: 700;
}

.footer-version {
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

/* =========================================================
   CLASES DE SUMATORIA DOBLE Y ESCALADO
   ========================================================= */
.summary-container {
    display: flex;
    justify-content: center;
    gap: 40px;
    align-items: center;
    flex-wrap: wrap; 
    width: 100%;
    margin-bottom: 20px;
    text-align: center;
}

.summary-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

.summary-label {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
}

.summary-value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
    word-break: break-word;
}

/* NUEVA CLASE PARA PANELES DE SOLICITUD DE VARIABLES (GLASSMORPHISM) */
.var-prompt-overlay {
    background: linear-gradient(135deg, rgba(255,255,255,0.9), rgba(255,255,255,0.7));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: var(--radius-md);
    padding: 30px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    max-width: 400px;
    margin: auto;
}

/* NUEVA CLASE PARA ENCABEZADOS EDITABLES (DOBLE CLIC) */
.editable-header {
    border-bottom: 1px dashed var(--text-light);
    cursor: text;
    transition: all 0.2s ease;
    padding: 2px 5px;
    border-radius: 4px;
}

.editable-header:hover {
    background-color: var(--bg-body);
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.editable-header:focus {
    outline: none;
    background-color: var(--bg-body);
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.dashboard-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); 
    gap: 20px; 
    padding: 0 30px 30px; 
    align-items: start;
    animation: fadeInCategory 0.3s ease-out;
}

/* CONTENCIÓN ESTRICTA FLEXBOX */
.card { 
    background-color: var(--bg-card); 
    border: 1px solid var(--border-color);
    padding: 24px; 
    border-radius: var(--radius-lg); 
    box-shadow: var(--shadow-sm); 
    position: relative; 
    display: flex; 
    flex-direction: column; 
    min-height: 380px; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.card.expanded {
    grid-column: 1 / -1;
    min-height: 500px;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    padding-right: 10px;
    word-break: break-word; 
}

.card-actions {
    display: flex;
    gap: 4px;
    opacity: 0.3; 
    transition: opacity 0.2s ease;
    flex-wrap: wrap; 
    justify-content: flex-end;
}

.card:hover .card-actions { opacity: 1; }

.btn-icon { 
    width: 32px; 
    height: 32px; 
    border-radius: var(--radius-sm); 
    border: 1px solid transparent; 
    background-color: transparent;
    cursor: pointer; 
    color: var(--text-muted); 
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background-color: var(--bg-body);
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-icon.ai-btn:hover { color: var(--ai-purple); background-color: #f5f3ff; border-color: #ddd6fe; }
.btn-icon.filter-btn:hover { color: var(--warning); background-color: #fef3c7; border-color: #fde68a; }
.btn-icon.delete-btn:hover { color: var(--danger); background-color: #fee2e2; border-color: #fca5a5; }
.btn-icon.primary-btn:hover { color: var(--primary); background-color: #eff6ff; border-color: #bfdbfe; }

.card-filter-panel {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 15px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-row input[type="text"],
.filter-row select {
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-main);
    flex: 1;
    min-width: 120px;
}

/* Modificación: flatpickr inputs */
.filter-row input.flatpickr-date {
    cursor: pointer;
    background-color: white;
}

.filter-row input:focus, 
.filter-row select:focus {
    outline: none;
    border-color: var(--primary);
}

.chart-container {
    flex: 1;
    position: relative;
    width: 100%;
    min-height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    max-width: 100%;
}

.card.expanded .chart-container { min-height: 400px; }

.skeleton-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    gap: 20px;
}

.skeleton {
    background-color: #e2e8f0;
    background-image: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-title { height: 20px; }
.skeleton-chart { flex: 1; min-height: 200px; }

.skeleton-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.btn-cancel-query {
    padding: 10px 18px;
    background-color: #fee2e2;
    color: var(--danger);
    border: 1px solid #fca5a5;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-cancel-query:hover { background-color: var(--danger); color: white; }

.kpi-card { min-height: auto; }
.kpi-card .chart-container { min-height: auto; align-items: flex-start; }
.kpi-value { font-size: 36px; font-weight: 700; color: var(--text-main); margin: 5px 0; word-break: break-word; letter-spacing: -1px; }
.kpi-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.kpi-success .kpi-value { color: var(--success); }
.kpi-danger .kpi-value { color: var(--danger); }

.modern-table { 
    width: 100%; 
    min-width: 400px; 
    border-collapse: separate; 
    border-spacing: 0;
    font-size: 13px; 
    text-align: left; 
}

.modern-table th { 
    background-color: var(--bg-body); 
    padding: 12px 16px; 
    border-bottom: 1px solid var(--border-color); 
    position: sticky; 
    top: 0; 
    z-index: 10; 
    color: var(--text-muted); 
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

.modern-table td { 
    padding: 12px 16px; 
    border-bottom: 1px solid #f1f5f9; 
    color: var(--text-main);
}

.modern-table tr:hover td { background-color: #f8fafc; }

.table-scroll { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    max-height: 600px; 
    border: 1px solid var(--border-color); 
    border-radius: var(--radius-sm); 
    width: 100%; 
    max-width: 100%;
}

.mini-table { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
    height: 100%;
    max-height: 250px; 
    border: 1px solid var(--border-color); 
    border-radius: var(--radius-sm); 
    width: 100%; 
    max-width: 100%;
}

.card.expanded .mini-table { max-height: 400px; }

.modal { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(15, 23, 42, 0.5); 
    backdrop-filter: blur(4px);
    z-index: 2000; 
    overflow-y: auto;
    padding: 20px;
}

.modal-content { 
    background-color: var(--bg-card); 
    width: 700px; 
    max-width: 100%;
    margin: 40px auto; 
    padding: 40px; 
    border-radius: var(--radius-lg); 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    position: relative;
    animation: modalSlideUp 0.3s ease-out forwards;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.full-modal { width: 95%; max-width: 1200px; }

.ai-theme { border-top: 5px solid var(--ai-purple); }
.ai-theme #aiModalTitle { color: var(--ai-purple); }

.ai-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f8fafc;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-bubble {
    max-width: 85%;
    padding: 15px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.chat-ai {
    align-self: flex-start;
    background-color: #ffffff;
    border: 1px solid #ddd6fe;
    color: var(--text-main);
    border-top-left-radius: 4px;
}

.chat-user {
    align-self: flex-end;
    background-color: var(--primary);
    color: #ffffff;
    border-top-right-radius: 4px;
}

.ai-chat-input-area { display: flex; gap: 12px; align-items: center; }

.ai-chat-input-area input {
    flex: 1;
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 15px;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
}

.ai-chat-input-area input:focus { border-color: var(--ai-purple); }

.ai-chat-input-area button {
    background-color: var(--ai-purple);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0 25px;
    height: 100%;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
}

.ai-chat-input-area button:hover {
    background-color: #7c3aed;
    transform: translateY(-2px);
}

.modal-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 30px; 
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 { font-size: 22px; font-weight: 700; color: var(--text-main); }

.close-btn { 
    background-color: var(--bg-body); 
    border: 1px solid var(--border-color); 
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px; 
    color: var(--text-muted); 
    cursor: pointer; 
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    box-shadow: var(--shadow-sm); 
}

.close-btn:hover {
    background-color: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: rotate(90deg) scale(1.1);
}

.row { display: flex; gap: 20px; flex-wrap: wrap; }

.input-group { margin-bottom: 24px; flex: 1; min-width: 200px; }

.input-group label { 
    display: block; 
    font-size: 14px; 
    font-weight: 600; 
    margin-bottom: 10px; 
    color: var(--text-main); 
}

.input-group input, 
.input-group select, 
.input-group textarea { 
    width: 100%; 
    padding: 12px 16px; 
    border: 1px solid var(--border-color); 
    border-radius: var(--radius-sm); 
    font-family: inherit;
    font-size: 15px;
    color: var(--text-main);
    background-color: var(--bg-card);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input[type="color"] {
    padding: 2px;
    cursor: pointer;
    height: 45px;
    border-radius: var(--radius-sm);
}

.input-group input:focus, 
.input-group select:focus, 
.input-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

textarea { height: 140px; resize: vertical; }

.actions { 
    display: flex; 
    justify-content: flex-end; 
    gap: 15px; 
    margin-top: 30px; 
    padding-top: 25px;
    border-top: 1px solid var(--border-color);
}

.sql-box { 
    background-color: var(--bg-body); 
    padding: 20px; 
    border-radius: var(--radius-md); 
    border: 1px solid var(--border-color); 
}

.btn-validate {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
}

.btn-validate:hover {
    background-color: var(--sidebar-active-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.msg-box { margin-top: 15px; font-size: 14px; font-weight: 500; text-align: center; }

/* =========================================================
   MEDIA QUERIES (BLINDAJE MÓVIL ESTRICTO)
   ========================================================= */

@media (max-width: 1024px) {
    .dashboard-grid { 
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); 
    }
    
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    
    .main-content { 
        margin-left: 0; 
        width: 100%; 
        max-width: 100vw;
    }
    
    .mobile-menu-btn, 
    .mobile-close-btn { display: block; }
    
    #mobile-overlay.active { display: block; }
    
    .modal { padding: 10px; }
    .modal-content { 
        width: 92%; 
        max-width: 92%;
        padding: 20px; 
        margin: 5% auto; 
        max-height: 90vh;
        overflow-y: auto;
    }
}

@media (max-width: 768px) {
    .login-split { 
        flex-direction: column; 
        width: 90%; 
        max-width: 400px; 
    }
    
    .login-image { padding: 30px 20px; }
    
    .topbar { padding: 15px 20px; }
    .topbar-left .quick-filters { display: none; }
    
    #display-username {
        max-width: 80px; 
    }

    .toolbar { 
        flex-direction: column; 
        align-items: stretch; 
        gap: 15px; 
        padding: 15px 20px; 
    }
    
    .date-selector { 
        width: 100%; 
        flex-wrap: wrap; 
        justify-content: space-between; 
        padding: 10px;
    }
    
    .date-selector input { 
        width: 38%; 
        font-size: 12px;
    }
    
    .date-selector .btn-refresh {
        margin-top: 10px;
        width: 100%;
        border-radius: 8px; 
    }
    
    .mobile-hide { display: none; }
    
    .dashboard-grid { 
        grid-template-columns: 1fr; 
        padding: 15px; 
        gap: 15px; 
    }
    
    .card { padding: 15px; }
    .card-header { flex-direction: column-reverse; gap: 10px; }
    
    .card-actions { 
        opacity: 1; 
        position: relative; 
        top: 0; 
        right: 0; 
        width: 100%; 
        justify-content: flex-end; 
    }
    
    .card-filter-panel .filter-row select,
    .card-filter-panel .filter-row input {
        width: 100%;
    }
    
    .welcome-hero { 
        flex-direction: column; 
        text-align: center; 
        padding: 30px 20px; 
    }
    
    .welcome-illustration { display: none; }
    .row { flex-direction: column; gap: 0; }
    
    .app-footer {
        flex-direction: column;
        text-align: center;
        padding: 20px;
    }
    
    .footer-content { flex-direction: column; gap: 15px;}
    
    .summary-container {
        gap: 15px;
    }
    .summary-value {
        font-size: 20px;
    }
}

@media print {
    body { background-color: white; }
    
    .sidebar, 
    .topbar, 
    .toolbar, 
    .card-actions, 
    .card-filter-panel, 
    .btn-primary, 
    .modal,
    .app-footer { display: none !important; }
    
    .main-content { margin-left: 0 !important; width: 100% !important; }
    .dashboard-grid { display: block !important; padding: 0; }
    
    .card { 
        break-inside: avoid; 
        margin-bottom: 30px; 
        border: 1px solid #e2e8f0; 
        box-shadow: none; 
        page-break-inside: avoid; 
    }
}