/* ============================================================
   BASE.CSS — Design System Unificado · OptiCore IA v2.0
   Única fuente de verdad para tokens de diseño.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
    /* --- 1. Paleta de Marca (Core Identity) --- */
    --brand:            #004a99;
    --brand-dark:       #002a5c;
    --brand-light:      #e7f0ff;
    --brand-accent:     #63b3ed;
    --brand-gradient:   linear-gradient(135deg, #004a99 0%, #0066cc 50%, #004a99 100%);

    /* --- 2. Semantica de Estados --- */
    --success:          #28a745;
    --success-bg:       #d4edda;
    --success-text:     #155724;
    --success-glow:     rgba(40, 167, 69, 0.25);
    --danger:           #dc3545;
    --danger-bg:        #f8d7da;
    --danger-text:      #721c24;
    --danger-glow:      rgba(220, 53, 69, 0.25);
    --warning:          #ffc107;
    --warning-bg:       #fff3cd;
    --warning-text:     #856404;
    --warning-glow:     rgba(255, 193, 7, 0.25);
    --info:             #17a2b8;
    --info-bg:          #d1ecf1;
    --info-text:        #0c5460;

    /* --- 3. Superficies y Fondos --- */
    --bg:               #f4f7f6;
    --bg-elevated:      #e8ecef;
    --white:            #ffffff;
    --surface:          #ffffff;
    --surface-2:        #f8f9fa;
    --sidebar-bg:       #1a202c;
    --sidebar-hover:    rgba(255, 255, 255, 0.06);

    /* --- 4. Tipografia (Inter font) --- */
    --text:             #2c3e50;
    --text-main:        #2c3e50;
    --text-muted:       #6c757d;
    --text-light:       #adb5bd;
    --text-inverse:     #ffffff;
    --font-main:        'Inter', system-ui, -apple-system, sans-serif;
    --font-mono:        'SF Mono', 'Fira Code', monospace;

    /* --- 5. Bordes y Sombras --- */
    --border:           #e0e0e0;
    --border-focus:     #004a99;
    --radius-sm:        6px;
    --radius:           10px;
    --radius-lg:        16px;
    --radius-xl:        24px;
    --shadow-sm:        0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow:           0 4px 12px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md:        0 8px 24px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
    --shadow-lg:        0 16px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);
    --shadow-brand:     0 4px 16px rgba(0, 74, 153, 0.2);
    --shadow-success:   0 4px 16px rgba(40, 167, 69, 0.2);
    --shadow-danger:    0 4px 16px rgba(220, 53, 69, 0.2);

    /* --- 6. Layout Tokens --- */
    --sidebar-w:        260px;
    --sidebar-w-mini:   72px;
    --header-h:         70px;

    /* --- 7. Transiciones --- */
    --transition-fast:   0.15s ease;
    --transition-base:   0.25s ease;
    --transition-slow:   0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);

     --gray-50:      var(--surface-2);    /* #f8f9fa */
    --gray-100:     var(--bg-elevated);  /* #e8ecef */
    --border-light: var(--border);       /* #e0e0e0 */


}

/* ============================================================
   MODO OSCURO (Dark Mode)
   ============================================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:               #0f172a; /* Slate 900 */
        --bg-elevated:      #1e293b; /* Slate 800 */
        --white:            #1e293b;
        --surface:          #1e293b;
        --surface-2:        #273548;
        
        /* 🚨 Ajuste de Textos (Más luminosos) */
        --text:             #f8fafc;
        --text-main:        #f8fafc;
        --text-muted:       #cbd5e1; /* Gris claro (antes oscuro) */
        --text-light:       #94a3b8; 
        --border:           #334155;
        
        /* 🚨 AJUSTE DE MARCA PARA CONTRASTE: 
           Cambia el azul oscuro por un celeste/azul vibrante */
        --brand:            #60a5fa; /* Azul vibrante (Tailwind blue-400) */
        --brand-dark:       #3b82f6; /* Azul medio */
        --brand-light:      rgba(96, 165, 250, 0.15); /* Fondo translúcido suave */
        --brand-gradient:   linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
        
        --gray-50:      var(--surface-2); 
        --gray-100:     var(--bg-elevated); 
        --border-light: var(--border); 
    }
}

[data-theme="dark"] {
    --bg:               #0f172a;
    --bg-elevated:      #1e293b;
    --white:            #1e293b;
    --surface:          #1e293b;
    --surface-2:        #273548;
    
    /* 🚨 Ajuste de Textos */
    --text:             #f8fafc;
    --text-main:        #f8fafc;
    --text-muted:       #cbd5e1;
    --text-light:       #94a3b8;
    --border:           #334155;
    
    /* 🚨 Ajuste de Marca */
    --brand:            #60a5fa; 
    --brand-dark:       #3b82f6;
    --brand-light:      rgba(96, 165, 250, 0.15);
    --brand-gradient:   linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
}

@media (prefers-color-scheme: dark) {
    .app-header {
        background-color: var(--bg-elevated) !important;
        border-bottom: 1px solid var(--border);
    }
}

/* ------------------------------------------------------------
   RESETS & BASE STYLES
   ------------------------------------------------------------ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body, html {
    height: 100vh;
    width: 100vw;
    font-family: var(--font-main);
    font-size: 14px;
    line-height: 1.6;
    background-color: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    overflow-y: auto;
}

/* ------------------------------------------------------------
   TIPOGRAFIA LOGICA
   ------------------------------------------------------------ */
h1 { font-size: 26px; font-weight: 800; margin: 0 0 10px; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 20px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; }
h3 { font-size: 16px; font-weight: 600; margin: 0 0 6px; }
h4 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
p  { margin: 0 0 10px; line-height: 1.65; }
small { font-size: 12px; color: var(--text-muted); font-weight: 500; }
a { color: var(--brand); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--brand-dark); }

/* ------------------------------------------------------------
   COMPONENTES ATOMICOS (Botones, Badges, Inputs)
   ------------------------------------------------------------ */

/* --- Botones Premium --- */
button, .btn {
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn::after, button::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.15) 0%, transparent 100%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:hover::after, button:hover::after { opacity: 1; }

.btn-primary {
    background: var(--brand-gradient);
    color: var(--white);
    padding: 12px 24px;
    box-shadow: var(--shadow-brand);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 74, 153, 0.35);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #1e8a3a 100%);
    color: var(--white);
    padding: 12px 24px;
    box-shadow: var(--shadow-success);
}
.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.35);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #b02a37 100%);
    color: var(--white);
    padding: 12px 24px;
    box-shadow: var(--shadow-danger);
}
.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.35);
}

.btn-outline {
    background: transparent;
    color: var(--brand);
    border: 1.5px solid var(--brand);
    padding: 10px 22px;
}
.btn-outline:hover {
    background: var(--brand);
    color: var(--white);
    transform: translateY(-2px);
}

.btn-neutral {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 20px;
}
.btn-neutral:hover {
    background: var(--bg-elevated);
    transform: translateY(-1px);
}

.btn-sm { padding: 8px 16px; font-size: 12px; }
.btn-lg { padding: 16px 32px; font-size: 16px; }

button:hover, .btn:hover { opacity: 1; transform: translateY(-1px); }
button:active, .btn:active { transform: translateY(0) scale(0.98); }
button:disabled, .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* --- Badges Premium --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-danger  { background: var(--danger-bg); color: var(--danger-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-info    { background: var(--info-bg); color: var(--info-text); }
.badge-brand   { background: var(--brand-light); color: var(--brand); }
.badge-dark    { background: #2d3748; color: #ffffff; }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* Status pills */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
}
.status-pill::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
}
.status-active { background: #dcfce7; color: #15803d; }
.status-active::before { background: #22c55e; }
.status-inactive { background: #fee2e2; color: #b91c1c; }
.status-inactive::before { background: #ef4444; }
.status-pending { background: #fef9c3; color: #854d0e; }
.status-pending::before { background: #eab308; animation: pulse-dot 2s infinite; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Inputs y Formularios Premium --- */
input, select, textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: var(--white);
    color: var(--text);
    outline: none;
    transition: all var(--transition-base);
}

input::placeholder, textarea::placeholder {
    color: var(--text-light);
    font-weight: 400;
}

input:hover, select:hover, textarea:hover {
    border-color: var(--text-light);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px rgba(0, 74, 153, 0.1);
    background: var(--white);
}

input:disabled, select:disabled {
    background: var(--surface-2);
    cursor: not-allowed;
    opacity: 0.6;
}

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text-main);
}

label .required::after {
    content: ' *';
    color: var(--danger);
}

/* --- Select estilizado --- */
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

/* Checkbox y Radio mejorados */
input[type="checkbox"], input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand);
    cursor: pointer;
}

/* ------------------------------------------------------------
   UTILIDADES GLOBALES
   ------------------------------------------------------------ */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-left   { text-align: left; }
.mt-10 { margin-top: 10px; }
.mt-15 { margin-top: 15px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }
.p-20  { padding: 20px; }
.p-30  { padding: 30px; }
.gap-10 { gap: 10px; }
.gap-15 { gap: 15px; }
.gap-20 { gap: 20px; }

.flex      { display: flex; }
.flex-col  { display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; justify-content: center; align-items: center; }
.flex-wrap    { flex-wrap: wrap; }
.items-center { align-items: center; }

.w-full   { width: 100%; }
.h-full   { height: 100%; }
.min-h-screen { min-height: 100vh; }

/* Scrollbar Premium */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-light); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--brand); }
::-webkit-scrollbar-corner { background: transparent; }

/* Firefox scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--text-light) transparent; }

/* ------------------------------------------------------------
   ANIMACIONES GLOBALES
   ------------------------------------------------------------ */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeInRight {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
    0% { opacity: 0; transform: scale(0.97); } /* Cambié 0.95 a 0.97 para que el "salto" sea menor */
    100% { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 8px rgba(255, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes bounce-subtle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

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

.animate-fadeIn { animation: fadeIn 0.4s ease; }
.animate-fadeInUp { animation: fadeInUp 0.5s ease; }
.animate-fadeInDown { animation: fadeInDown 0.4s ease; }
.animate-fadeInLeft { animation: fadeInLeft 0.4s ease; }
.animate-fadeInRight { animation: fadeInRight 0.4s ease; }
.animate-scaleIn { animation: scaleIn 0.3s var(--transition-spring); }
.animate-slideDown { animation: slideDown 0.5s ease; }

/* Stagger delays */
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
.stagger-5 { animation-delay: 0.25s; }

/* ------------------------------------------------------------
   SKELETON / LOADING STATES
   ------------------------------------------------------------ */
.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--bg-elevated) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 20px;
    width: 60%;
    margin-bottom: 12px;
}

.skeleton-circle {
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

/* ------------------------------------------------------------
   LIVE BADGE (Estado en tiempo real)
   ------------------------------------------------------------ */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 800;
    background: rgba(255,255,255,0.15);
    padding: 4px 10px;
    border-radius: 999px;
    letter-spacing: 0.5px;
}

.live-dot {
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

/* ------------------------------------------------------------
   GLASSMORPHISM (Para overlays y modales)
   ------------------------------------------------------------ */
.glass {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.glass-dark {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ------------------------------------------------------------
   EMPTY STATES
   ------------------------------------------------------------ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h4 {
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    max-width: 300px;
    font-size: 13px;
}

/* ------------------------------------------------------------
   MODALES UNIFICADOS
   ------------------------------------------------------------ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
   
    border: 1px solid var(--border);
}

.modal-content-lg {
    max-width: 960px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    color: var(--brand);
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.btn-close-modal {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-close-modal:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ------------------------------------------------------------
   CARDS
   ------------------------------------------------------------ */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------------
   PAGE HEADER
   ------------------------------------------------------------ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 16px;
    animation: fadeInDown 0.4s ease;
}

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

.page-header p {
    color: var(--text-muted);
    margin: 0;
}

/* ------------------------------------------------------------
   TOAST / NOTIFICACIONES
   ------------------------------------------------------------ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: slideDown 0.4s ease, fadeOut 0.3s ease 4.7s forwards;
    max-width: 400px;
    font-size: 14px;
    font-weight: 500;
}

.toast-success { background: var(--success); color: white; }
.toast-danger  { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: var(--text); }
.toast-info    { background: var(--info); color: white; }

@keyframes fadeOut {
    to { opacity: 0; transform: translateX(100%); }
}

/* ------------------------------------------------------------
   RESPONSIVE UTILITIES
   ------------------------------------------------------------ */
@media (max-width: 768px) {
    .page-header { flex-direction: column; }
    .page-header h1 { font-size: 20px; }
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
    .modal-content { margin: 10px; }
    #ia-chat-window { width: calc(100vw - 40px); right: -10px; }
}

/* Print styles */
@media print {
    .sidebar, #ia-chat-container, .btn, button { display: none !important; }
    .main-content { padding: 0 !important; margin: 0 !important; }
    body { background: white !important; }
}


/* Títulos de sección pequeños con línea decorativa */
.section-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
}


.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}