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

:root {
    --font-ar: 'Alexandria', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-en: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* Medical Blue Palette */
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-light: #e0f2fe;
    --primary-glow: rgba(2, 132, 199, 0.25);
    
    --secondary: #0ea5e9;
    --accent-teal: #06b6d4;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;

    /* Dark Theme Tokens (Default) */
    --bg-main: #090d16;
    --bg-surface: #0f172a;
    --bg-surface-elevated: #1e293b;
    --bg-glass: rgba(15, 23, 42, 0.75);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(2, 132, 199, 0.5);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #090d16;

    --sidebar-width: 280px;
    --header-height: 72px;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-subtle: 0 4px 20px -2px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 25px rgba(2, 132, 199, 0.35);
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-focus: rgba(2, 132, 199, 0.5);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    --shadow-subtle: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(2, 132, 199, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-ar);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.25s ease, color 0.25s ease;
}

body[dir="ltr"] {
    font-family: var(--font-en);
}

main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

/* Glassmorphism Classes */
.glass-header {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
}

.glass-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.glass-card:hover {
    border-color: rgba(2, 132, 199, 0.35);
    box-shadow: var(--shadow-glow);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.55);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.btn-secondary:hover {
    background: rgba(2, 132, 199, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-outline {
    background: transparent;
    border: 1px solid rgba(2, 132, 199, 0.5);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #ffffff;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 14px 32px;
    font-size: 1.1rem;
    border-radius: var(--radius-md);
}

/* Badge Chips */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-full);
}

.badge-primary {
    background: rgba(2, 132, 199, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.3);
}

.badge-emerald {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-amber {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Landing Page Hero */
.hero-section {
    position: relative;
    padding: 90px 20px 70px;
    text-align: center;
    background: radial-gradient(circle at 50% 10%, rgba(2, 132, 199, 0.18) 0%, transparent 65%);
    overflow: hidden;
}

.hero-glow {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 400px;
    background: radial-gradient(circle, rgba(14, 165, 233, 0.15) 0%, transparent 70%);
    filter: blur(60px);
    pointer-events: none;
    z-index: 0;
}

.hero-content {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    z-index: 1;
}

.hero-title {
    font-size: 2.85rem;
    font-weight: 800;
    line-height: 1.25;
    margin: 20px 0;
    letter-spacing: -0.5px;
}

.hero-title-highlight {
    background: linear-gradient(135deg, #38bdf8 0%, #0284c7 50%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-subtitle {
    font-size: 1.15rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 35px;
    max-width: 750px;
    margin-left: auto;
    margin-right: auto;
}

/* Layout Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Header & Nav */
.header-nav {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 800;
    font-size: 1.4rem;
}

.brand-icon-box {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.brand-text-group {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.1;
}

.brand-subtitle {
    font-size: 0.65rem;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 0.5px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-badge-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 24px;
    list-style: none;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary);
}

/* Language Toggle Dropdown */
.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    text-decoration: none;
}

.lang-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Chat Layout Styles */
.chat-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    max-height: calc(100vh - var(--header-height));
    max-height: calc(100dvh - var(--header-height));
    overflow: hidden;
    position: relative;
}

#doctor-workspace-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    max-height: calc(100vh - var(--header-height));
    max-height: calc(100dvh - var(--header-height));
    overflow: hidden;
    position: relative;
}

.chat-sidebar {
    background: var(--bg-surface);
    border-inline-end: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
}

.chat-main {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    position: relative;
    background: var(--bg-main);
    overflow: hidden;
}

.chat-topbar {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
    gap: 8px;
}

.chat-title-text {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle-btn {
    display: none;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
}

.chat-messages {
    flex: 1 1 0%;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(2, 132, 199, 0.35);
    border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.chat-input-wrapper {
    flex-shrink: 0;
    padding: 14px 20px 18px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    position: relative;
    z-index: 20;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.chat-input-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 8px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

.chat-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
}

/* Message Bubble */
.message-bubble {
    display: flex;
    gap: 14px;
    max-width: 85%;
    width: 100%;
}

.message-bubble.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-bubble.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.message-bubble.assistant .message-avatar {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: #ffffff;
}

.message-bubble.user .message-avatar {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.message-body {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.7;
    width: 100%;
    min-width: 0;
}

.message-bubble.user .message-body {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.2) 0%, rgba(3, 105, 161, 0.15) 100%);
    border-color: rgba(2, 132, 199, 0.35);
}

/* Markdown Typography */
.message-text {
    unicode-bidi: plaintext;
    text-align: start;
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 0.94rem;
    line-height: 1.75;
}

.message-text p {
    margin-bottom: 12px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text h1, .message-text h2, .message-text h3, .message-text h4 {
    color: #38bdf8;
    margin: 16px 0 8px;
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.4;
}

.message-text ul, .message-text ol {
    margin: 10px 0 14px;
    padding-inline-start: 22px;
}

.message-text li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.message-text strong {
    color: #ffffff;
    font-weight: 700;
}

.message-text code {
    background: rgba(2, 132, 199, 0.15);
    color: #38bdf8;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.88rem;
}

/* Clinical Reasoning Accordion */
.reasoning-box {
    margin-bottom: 14px;
    border: 1px solid rgba(14, 165, 233, 0.3);
    background: rgba(14, 165, 233, 0.05);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.reasoning-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #38bdf8;
    background: rgba(14, 165, 233, 0.1);
}

.reasoning-content {
    padding: 12px 16px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    white-space: pre-line;
    border-top: 1px solid rgba(14, 165, 233, 0.15);
    line-height: 1.6;
}

/* Citations Drawer & Chips */
.citation-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(2, 132, 199, 0.12);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.25);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    margin: 2px 4px;
    transition: all 0.15s ease;
}

.citation-chip:hover {
    background: var(--primary);
    color: #ffffff;
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    z-index: 99;
    padding: 0 10px;
    align-items: center;
    justify-content: space-around;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

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

/* Mobile Responsive Overrides */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
    }

    .header-nav {
        height: 60px;
    }

    .brand-subtitle {
        display: none;
    }

    .brand-title {
        font-size: 1.15rem;
    }

    .brand-icon-box {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .desktop-pwa-btn {
        display: none !important;
    }

    .header-register-btn {
        padding: 6px 12px;
        font-size: 0.82rem;
    }

    .lang-btn {
        padding: 5px 10px;
        font-size: 0.78rem;
    }

    .user-role-badge {
        padding: 3px 8px;
        font-size: 0.72rem;
    }

    .logout-btn {
        padding: 6px 8px;
    }

    .chat-container {
        grid-template-columns: 1fr;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
        max-height: calc(100vh - 60px);
        max-height: calc(100dvh - 60px);
    }

    #doctor-workspace-grid {
        grid-template-columns: 1fr;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
        max-height: calc(100vh - 60px);
        max-height: calc(100dvh - 60px);
    }

    /* Mobile Drawer for Sidebar */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    .chat-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        inset-inline-start: 0;
        width: 84%;
        max-width: 320px;
        background: var(--bg-surface);
        z-index: 999;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 0 0 35px rgba(0, 0, 0, 0.85);
        display: flex;
        flex-direction: column;
    }

    [dir="ltr"] .chat-sidebar {
        transform: translateX(-100%);
    }

    .chat-sidebar.active {
        transform: translateX(0) !important;
    }

    .sidebar-close-btn {
        display: inline-block !important;
    }

    .sidebar-toggle-btn {
        display: inline-flex !important;
    }

    /* Hide bottom nav on active chat view to give maximum screen space to messages and input */
    body.is-chat-page .mobile-bottom-nav {
        display: none !important;
    }

    .chat-messages {
        padding: 12px 10px 20px;
        gap: 14px;
    }

    .message-bubble {
        max-width: 98% !important;
        gap: 8px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    .message-body {
        padding: 12px 14px;
        font-size: 0.9rem;
        border-radius: 14px;
    }

    .chat-input-wrapper {
        padding: 8px 10px 10px;
    }

    .chat-input-box {
        padding: 6px 12px;
        gap: 8px;
    }

    .chat-textarea {
        font-size: 0.9rem;
    }

    .hero-title {
        font-size: 1.95rem;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .nav-links {
        display: none;
    }
}

