/* --- MEJORA DE LEGIBILIDAD Y TIPOGRAFÍA --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --secondary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-main: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
}

/* Aplicación global con suavizado de fuentes para mejorar lectura */
* { 
    font-family: 'Inter', sans-serif; 
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden !important; /* Bloqueo total de scroll horizontal */
    width: 100% !important;
    position: relative;
}

/* --- COMPONENTES UI RECURRENTE --- */
.modal-overlay { 
    background-color: rgba(15, 23, 42, 0.7); 
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
}

.chart-container { 
    position: relative; 
    height: 220px; 
    width: 100%; 
}

/* --- ANIMACIONES --- */
.fade-enter-active, .fade-leave-active { 
    transition: opacity 0.4s ease, transform 0.4s ease; 
}
.fade-enter-from, .fade-leave-to { 
    opacity: 0; 
    transform: translateY(10px);
}

@keyframes pulse-red-border {
    0% { border-color: var(--danger); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { border-color: #f87171; box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { border-color: var(--danger); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.alerta-critica-border { 
    animation: pulse-red-border 2s infinite; 
    border-width: 2px !important; 
    border-color: var(--danger) !important; 
}

/* --- SCROLLBARS MODERNOS --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { 
    background: #cbd5e1; 
    border-radius: 10px; 
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.agenda-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; }
.ia-scroll { max-height: 65vh; overflow-y: auto; padding-right: 8px; }
.ia-scroll::-webkit-scrollbar-thumb { background: var(--secondary); }

/* --- DISEÑO RESPONSIVE Y TABS --- */
.tabs-flexible-container {
    display: flex;
    flex-wrap: wrap; 
    gap: 4px;
    background-color: #f1f5f9;
    padding: 6px;
    border-radius: 16px;
    margin-bottom: 1rem;
}

.tabs-flexible-container button {
    flex: 1 1 auto; 
    min-width: 140px; /* Asegura legibilidad en móviles */
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    color: var(--text-muted);
}

.tabs-flexible-container button.tab-active {
    background-color: white;
    color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-top: 4px solid var(--primary); /* Mantenemos tu identidad visual */
}

/* --- NUEVA SECCIÓN: RECETAS ABIERTAS (ORDEN MÉDICA) --- */
.textarea-receta-abierta {
    min-height: 350px;
    line-height: 1.8;
    font-size: 15px;
    color: #334155;
    background-image: linear-gradient(#f1f5f9 1px, transparent 1px);
    background-size: 100% 1.8rem; /* Efecto de líneas de cuaderno para facilitar escritura */
    padding: 1.8rem;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    width: 100%;
    resize: none;
}

.textarea-receta-abierta:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* --- AJUSTES DE FORMULARIOS RESPONSIVE --- */
input, select, textarea {
    font-size: 14px !important; /* Evita zoom automático en iOS */
}

.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* --- CORRECCIÓN PANEL FINANZAS (Ajuste de botones desbordados) --- */
.finanzas-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap; /* Permite que los botones bajen si no hay espacio */
    gap: 1rem;
    width: 100%;
}

.finanzas-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* --- OPTIMIZACIÓN GLOBAL PARA CELULARES Y TABLETS --- */
@media (max-width: 1024px) {
    /* CORRECCIÓN DE LA CABECERA (NAV) */
    nav {
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 15px !important;
        padding: 1rem !important;
        height: auto !important;
    }

    nav .flex {
        flex-wrap: wrap !important;
        justify-content: center !important;
        width: 100% !important;
        gap: 10px !important;
    }

    /* Logo Indestructible */
    nav h1 {
        white-space: nowrap !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        width: auto !important;
        font-size: 1.5rem !important;
    }

    /* Ajuste Panel Finanzas en Móvil */
    .finanzas-header {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .finanzas-actions {
        width: 100% !important;
        justify-content: flex-start !important;
    }

    .finanzas-actions button {
        flex: 1 1 auto !important;
        text-align: center !important;
    }

    /* CORRECCIÓN DE LA AGENDA (DESBORDE DE CONFIRMADOS) */
    .md\:col-span-2.bg-gradient-to-br {
        width: 100% !important;
        padding: 15px !important;
    }

    .md\:col-span-2 .flex.justify-between.items-start {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 15px !important;
    }

    .md\:col-span-2 .text-right {
        text-align: center !important;
        width: 100% !important;
    }

    .md\:col-span-2 input[type="date"] {
        width: 100% !important;
        margin-bottom: 10px !important;
    }

    .agenda-scroll .group {
        flex-direction: column !important;
        text-align: center !important;
        gap: 10px !important;
        padding: 15px !important;
    }

    .agenda-scroll .group .flex.items-center.gap-4 {
        flex-direction: column !important;
    }

    /* Tabs del sistema */
    .tabs-flexible-container button {
        min-width: 45% !important;
        font-size: 10px !important;
        padding: 12px 8px !important;
    }

    .container-main {
        padding: 10px !important;
    }
}

/* Ajustes adicionales para móviles pequeños */
@media (max-width: 480px) {
    nav h1 { font-size: 1.25rem !important; }
    nav span.text-sm { width: 100% !important; text-align: center !important; }
    .tabs-flexible-container button { min-width: 100% !important; }
}