:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 16px;
}

[data-theme="dark"] {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --glass: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-light: #1e3a8a;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Layout --- */
.portal-container {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100vw;
}

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 100;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 48px;
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary);
}

.logo-circle {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

.nav-item:hover, .nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* --- Main Content --- */
.main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.search-container {
    position: relative;
    width: 400px;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 48px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.9rem;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* --- Landing Page --- */
.landing-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 48px;
    max-width: 600px;
}

.action-cards {
    display: flex;
    gap: 24px;
}

.action-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 24px;
    width: 300px;
    cursor: pointer;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.action-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.action-card .icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

/* --- Patient Dashboard --- */
.patient-dashboard {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 24px;
}

.summary-card {
    grid-column: span 2;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-main) 100%);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    display: flex;
    gap: 24px;
    position: relative;
    overflow: hidden;
}

.summary-card::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
    opacity: 0.3;
    z-index: 0;
}

.patient-avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: white;
    font-weight: 700;
    z-index: 1;
}

.patient-info {
    flex-grow: 1;
    z-index: 1;
}

.patient-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 24px;
}

.badge-group {
    display: flex;
    gap: 8px;
}

.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-stable { background: #d1fae5; color: #065f46; }
.badge-critical { background: #fee2e2; color: #991b1b; animation: pulse 2s infinite; }
.badge-observation { background: #fef3c7; color: #92400e; }

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.info-item label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.info-item span {
    font-weight: 700;
    font-size: 1.1rem;
}

/* --- Timeline --- */
.timeline-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.timeline {
    position: relative;
    padding-left: 40px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 15px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 20px;
}

.timeline-icon {
    position: absolute;
    left: -40px;
    width: 32px;
    height: 32px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    font-size: 0.9rem;
}

.timeline-item.active .timeline-icon {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.timeline-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.timeline-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary-light);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.timeline-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.timeline-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 8px;
}

/* --- Widgets --- */
.widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.widget-title {
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- Alerts --- */
.alert-banner {
    background: var(--danger);
    color: white;
    padding: 12px 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* --- Utilities --- */
.hidden { display: none !important; }

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover { background: var(--primary-dark); }

.glass {
    background: var(--glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease forwards;
}

/* --- Global Search Results --- */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 8px;
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
}

.search-result-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--primary-light);
}

/* --- AI Chat Widget --- */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 350px;
    height: 500px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.ai-chat-widget.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    display: flex !important; /* Override the default hidden display:none to allow transition */
}

.ai-chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-body {
    flex-grow: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-main);
}

.ai-message {
    background: var(--bg-card);
    padding: 12px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 85%;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.user-message {
    background: var(--primary);
    color: white;
    padding: 12px;
    border-radius: 12px;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    max-width: 85%;
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}

.ai-chat-input-container {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: var(--bg-card);
}

.ai-chat-input-container input {
    flex-grow: 1;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-main);
    color: var(--text-main);
}

.ai-chat-input-container input:focus {
    outline: none;
    border-color: var(--primary);
}

.ai-chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 1999;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 20px -3px rgba(0, 0, 0, 0.2);
}

/* --- Patient Directory --- */
.patient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* --- Emergency Dashboard --- */
.emergency-dashboard {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 24px;
    padding: 32px;
}

[data-theme="dark"] .emergency-dashboard {
    background: rgba(153, 27, 27, 0.1);
    border-color: rgba(220, 38, 38, 0.3);
}

/* --- Upload Center Global --- */
.upload-center-container {
    max-width: 800px;
    margin: 0 auto;
}

/* --- Modals --- */
.qr-scanner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 6000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
}

/* --- Premium Nexus ID Card --- */
.nexus-id-card {
    width: 380px;
    height: 240px;
    border-radius: 16px;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
    color: white;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: 'Outfit', sans-serif;
    margin: 0 auto;
}

.nexus-id-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    transform: rotate(30deg);
    pointer-events: none;
}

.id-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
}

.id-card-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.id-card-chip {
    width: 45px;
    height: 35px;
    background: linear-gradient(135deg, #fef08a 0%, #ca8a04 100%);
    border-radius: 6px;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

.id-card-chip::after {
    content: '';
    position: absolute;
    top: 5px; left: 5px; right: 5px; bottom: 5px;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 2px;
}

.id-card-body {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 1;
}

.id-card-info {
    flex-grow: 1;
}

.id-card-name {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 4px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.id-card-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: rgba(255,255,255,0.7);
    letter-spacing: 1px;
}

.id-card-value {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    font-family: monospace;
    letter-spacing: 2px;
}

.id-card-photo {
    width: 80px;
    height: 80px;
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.id-card-qr-container {
    background: white;
    padding: 8px;
    border-radius: 8px;
    display: inline-block;
}

/* --- OTP Input --- */
.otp-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

.otp-input {
    width: 50px;
    height: 60px;
    font-size: 2rem;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-main);
    font-family: monospace;
    transition: all 0.2s ease;
}

.otp-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-light);
}
