:root {
    /* Color Palette - Premium SaaS Aesthetics */
    --primary: #4F46E5;        /* Indigo 600 */
    --primary-hover: #4338CA;  /* Indigo 700 */
    --primary-light: rgba(79, 70, 229, 0.1);
    
    --success: #10B981;        /* Emerald 500 */
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #F59E0B;        /* Amber 500 */
    --danger: #EF4444;         /* Red 500 */
    --danger-bg: rgba(239, 68, 68, 0.1);
    
    --text-main: #0F172A;      /* Slate 900 */
    --text-secondary: #475569; /* Slate 600 */
    --text-muted: #94A3B8;     /* Slate 400 */
    
    /* Backgrounds & Glassmorphism */
    --bg-card: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 10px 40px -10px rgba(31, 38, 135, 0.08);
    --inner-border: rgba(226, 232, 240, 0.5); /* Slate 200 light */
    
    /* Variables Typography */
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    
    /* Metrics */
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
    --spacing-xs: 8px;
    --spacing-sm: 16px;
    --spacing-md: 24px;
    --spacing-lg: 32px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family);
}

body {
    background-color: #F8FAFC;
    color: var(--text-main);
    overflow: hidden; /* Prevent body scroll, handled internally */
    -webkit-font-smoothing: antialiased;
}

/* Beautiful dynamic background mesh */
.app-background {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle at 15% 50%, rgba(79, 70, 229, 0.08), transparent 25%),
                radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.06), transparent 25%),
                linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 50%, #ede9fe 100%);
    z-index: -1;
}

/* Base Layout */
.app-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
}

/* Glass Panel Reusable Component */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius-lg);
}

/* Typography Helpers */
h1 { font-size: 1.5rem; font-weight: 700; color: var(--text-main); }
h2 { font-size: 1.25rem; font-weight: 600; color: var(--text-main); }
h3 { font-size: 1.1rem; font-weight: 600; color: var(--text-main); }
h4 { font-size: 0.95rem; font-weight: 600; color: var(--text-main); }
p { font-size: 0.95rem; color: var(--text-secondary); line-height: 1.5; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}
.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.39);
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}
.btn-outline:hover { background: rgba(255,255,255,0.5); }
.btn-block { width: 100%; }

.icon-btn {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none; background: transparent;
    cursor: pointer; color: var(--text-secondary);
    transition: 0.2s;
    position: relative;
}
.icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-main); }
.icon-btn.small { width: 32px; height: 32px; }

svg { width: 20px; height: 20px; stroke-width: 2px; }
.sm-icon svg { width: 16px; height: 16px; margin-right: 4px; }
.large-icon svg { width: 48px; height: 48px; color: var(--text-muted); stroke-width: 1.5px; opacity: 0.5;}

/* Avatars */
.avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white;
    font-size: 0.9rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.avatar.large { width: 56px; height: 56px; font-size: 1.25rem; }
.gradient-avatar-1 { background: linear-gradient(135deg, #6366f1, #a855f7); }
.gradient-avatar-2 { background: linear-gradient(135deg, #10B981, #059669); }

/* Status Badges */
.badge {
    position: absolute; top: 0; right: 0;
    background: var(--danger); color: white;
    font-size: 0.7rem; font-weight: bold;
    padding: 2px 6px; border-radius: 20px;
    border: 2px solid white;
}
.status-badge {
    display: inline-flex; align-items: center;
    padding: 4px 12px; border-radius: 20px;
    font-size: 0.85rem; font-weight: 600;
}
.risk-low { background: var(--success-bg); color: var(--success); }
.risk-high { background: var(--danger-bg); color: var(--danger); }

/* Layout: Sidebar */
.sidebar {
    display: flex; flex-direction: column;
    padding: var(--spacing-md);
    height: 100%;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding-left: 4px;
}
.logo-icon {
    background: var(--primary);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevents icon from shrinking with long text */
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}
.brand h2 {
    font-size: 1.1rem;
    line-height: 1.2;
    margin: 0;
    font-weight: 700;
    color: var(--text-main);
}

.nav-menu { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    text-decoration: none; color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: 0.2s;
}
.nav-item:hover { background: rgba(0,0,0,0.03); color: var(--text-main); }
.nav-item.active { background: white; color: var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,0.02); }
.spacer { flex-grow: 1; }

.divider-top { border-top: 1px solid var(--inner-border); padding-top: var(--spacing-md); margin-top: auto; }

.user-profile {
    display: flex; align-items: center; gap: 12px;
}

/* Layout: Main Content */
.main-content {
    display: flex; flex-direction: column;
    height: 100%;
    overflow-y: auto;
    padding-right: 8px;
    gap: var(--spacing-md);
}

/* Custom Scrollbar for Main Content */
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 10px; }

/* Topbar */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
}
.search-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    width: 400px;
    border-radius: var(--radius-md);
}
.search-bar input {
    border: none; background: transparent; font-size: 0.95rem;
    width: 100%; color: var(--text-main); outline: none;
}
.keyboard-shortcut {
    background: rgba(0,0,0,0.05); padding: 4px 8px;
    border-radius: 6px; font-size: 0.75rem; color: var(--text-muted); font-weight: 600;
}
.header-actions { display: flex; gap: 12px; }

/* Welcome Hero Banner (Doctor Dashboard) */
.welcome-hero {
    width: 100%;
    padding: 40px;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: white;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(79, 70, 229, 0.25);
}

.welcome-hero::before {
    content: '';
    position: absolute;
    width: 300px; height: 300px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    top: -150px; right: -50px;
}

.welcome-hero h1 {
    color: white;
    font-size: 2.2rem;
    margin-bottom: 8px;
    font-weight: 700;
}

.welcome-hero p.hero-subtitle {
    color: rgba(255,255,255,0.8);
    font-size: 1.1rem;
}

.hero-next-card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 24px;
    border-radius: var(--radius-md);
    min-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hero-next-card h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.9;
}

.hero-next-info {
    display: flex;
    flex-direction: column;
}

.hero-next-info strong {
    font-size: 1.25rem;
    font-weight: 700;
}

.hero-next-info span {
    font-size: 0.9rem;
    opacity: 0.85;
}

@media (max-width: 768px) {
    .welcome-hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 24px;
        padding: 32px 24px;
    }
    .hero-next-card {
        width: 100%;
        min-width: unset;
    }
}
.patient-banner { padding: var(--spacing-md); display: flex; flex-direction: column; gap: var(--spacing-md); }
.patient-info-row { display: flex; justify-content: space-between; align-items: center; }
.patient-profile { display: flex; align-items: center; gap: 16px; }
.title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.patient-actions { display: flex; align-items: center; gap: 12px; }

.patient-stats {
    display: flex; gap: 40px;
}
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-weight: 600; font-size: 1.05rem; }
.stat .value.positive { color: var(--success); }
.stat .value.highlight { color: var(--primary); background: var(--primary-light); padding: 2px 8px; border-radius: 6px; display: inline-block; }

/* Tabs */
.tabs-container {
    display: flex; gap: 8px; border-bottom: 1px solid var(--inner-border);
    padding-bottom: 0;
}
.tab-btn {
    background: transparent; border: none; padding: 12px 20px;
    font-size: 1rem; font-weight: 500; color: var(--text-secondary);
    cursor: pointer; position: relative; transition: 0.2s;
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); font-weight: 600; }
.tab-btn.active::after {
    content: ''; position: absolute; bottom: -1px; left: 0; width: 100%; height: 2px;
    background: var(--primary); border-radius: 2px 2px 0 0;
}

/* Notes Layout */
.notes-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: var(--spacing-md);
    margin-top: 8px;
    min-height: 500px;
}

/* Timeline */
.timeline { padding: var(--spacing-md); display: flex; flex-direction: column; }
.timeline-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.timeline-list { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; flex-grow: 1; margin-right: -8px; padding-right: 8px;}
.timeline-list::-webkit-scrollbar { width: 4px; }
.timeline-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 4px; }

.timeline-item {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--inner-border);
    background: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: all 0.2s;
}
.timeline-item:hover { background: rgba(255, 255, 255, 0.9); transform: translateX(2px); }
.timeline-item.active {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-light);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.05);
    border-left: 3px solid var(--primary);
}

.t-date { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; display: flex; justify-content: space-between; }
.t-date span { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; }
.t-desc { font-size: 0.85rem; color: var(--text-secondary); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }

/* Note Viewer */
.note-viewer { padding: var(--spacing-lg); overflow-y: auto;}
.viewer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--inner-border); }
.viewer-meta { display: flex; align-items: center; gap: 12px; }
.modality-badge { background: #F1F5F9; color: var(--text-secondary); padding: 4px 10px; border-radius: 6px; font-size: 0.8rem; font-weight: 600; }

.note-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}
.note-section {
    background: rgba(255, 255, 255, 0.5);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--inner-border);
}
.note-section.full { grid-column: 1 / -1; }
.note-section.half { grid-column: span 1; }
.note-section h4 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; color: var(--text-main); }
.note-section h4 svg { color: var(--primary); }

.private-zone {
    background: #FFFBEB; /* Amber 50 */
    border-color: #FEF3C7;
    position: relative;
    overflow: hidden;
}
.private-zone h4 svg { color: var(--warning); }
.private-zone::before {
    content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--warning);
}

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-muted); gap: 16px; text-align: center;
}

/* Animations */
.fade-in { animation: fadeIn 0.4s ease forwards; }
.slide-up { animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(15px); } to { transform: translateY(0); } }

/* Global Utilities */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
}

.responsive-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
}

.responsive-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
}

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


/* Responsive Design (Móvil y Tablet) */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 80px 1fr; /* Colapsa el panel izquierdo */
        height: 100vh;
    }
    .brand h2, .nav-item span, .user-info { display: none; } /* Oculta textos de la barra lateral */
    .brand { margin-bottom: 24px; justify-content: center; }
    .logo-icon { width: 40px; height: 40px; }
    .nav-item { justify-content: center; padding: 12px; }
    .user-profile { justify-content: center; border-top: none; }
    
    .notes-layout { grid-template-columns: 1fr; }
    .timeline { max-height: 250px; }
}

@media (max-width: 768px) {
    body { overflow-y: auto; overflow-x: hidden; } /* Habilita el scroll global */
    .app-container {
        display: flex; flex-direction: column;
        height: auto; min-height: 100vh;
        padding-bottom: 90px; /* Margen para la barra inferior */
    }
    
    /* Transformación de la Barra Lateral a Barra Inferior Flotante (App Style) */
    .sidebar {
        position: fixed;
        bottom: 0; left: 0; width: 100%; height: 75px;
        flex-direction: row; justify-content: space-between; align-items: center;
        padding: 0 16px; z-index: 1000;
        border-radius: 24px 24px 0 0;
        border-top: 1px solid var(--glass-border);
        box-shadow: 0 -10px 40px rgba(31, 38, 135, 0.1);
    }
    .brand, .user-profile, .spacer, .bottom-nav { display: none; }
    
    .nav-menu { display: flex; flex-direction: row; width: 100%; justify-content: space-around; }
    .nav-item { 
        padding: 8px; flex-direction: column; gap: 4px; font-size: 0.65rem; 
        border-radius: var(--radius-sm); justify-content: center;
    }
    .nav-item span { display: block; font-weight: 600; }
    
    .main-content { overflow-y: visible; height: auto; padding-right: 0; }
    
    .topbar { flex-direction: column; gap: 16px; align-items: stretch; margin-bottom: 8px;}
    .search-bar { width: 100%; }
    
    .patient-info-row { flex-direction: column; align-items: flex-start; gap: 16px; }
    .patient-actions { width: 100%; justify-content: flex-start; }
    
    .patient-stats { flex-wrap: wrap; gap: 16px; }
    .stat { flex: 1 1 calc(50% - 16px); } /* Grid nativo usando flex-basis */
    
    .tabs-container { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
    .tab-btn { flex: 0 0 auto; }
    
    .note-grid { grid-template-columns: 1fr; }
    .viewer-header { flex-direction: column; align-items: flex-start; gap: 12px; }

    /* Collapse Utilities */
    .responsive-grid-2, 
    .responsive-grid-3,
    .responsive-grid-auto {
        grid-template-columns: 1fr;
    }

    /* Fix SweetAlert Mobile Overflow */
    .swal2-popup {
        width: 90% !important;
        padding: 1rem !important;
    }
}

/* FOUC Prevention */
body.loading-fouc {
    opacity: 0 !important;
    visibility: hidden !important;
}
body.ready-fouc {
    opacity: 1 !important;
    visibility: visible !important;
    transition: opacity 0.4s ease, visibility 0.4s ease !important;
}
