:root {
    --bg: #080c14;
    --panel: rgba(18, 24, 38, 0.75);
    --panel-solid: #121826;
    --border: rgba(255, 255, 255, 0.07);
    --primary: #4facfe;
    --primary-end: #00f2fe;
    --gradient: linear-gradient(135deg, var(--primary) 0%, var(--primary-end) 100%);
    --text: #e8edf5;
    --muted: #64748b;
    --danger: #f87171;
    --success: #34d399;
    --warn: #fbbf24;
    --font: 'Inter', system-ui, sans-serif;
    --font-heading: 'Outfit', system-ui, sans-serif;
    --radius: 20px;
    --sidebar-w: 310px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    background-image:
        radial-gradient(ellipse 60% 50% at 10% 50%, rgba(79, 172, 254, 0.13), transparent),
        radial-gradient(ellipse 50% 40% at 90% 20%, rgba(0, 242, 254, 0.09), transparent);
}

.glass-panel {
    background: var(--panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

/* === APP SHELL === */
.app-shell {
    display: flex;
    height: 100vh;
    padding: 16px;
    gap: 14px;
}

/* === SIDEBAR === */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 20px 18px;
    gap: 20px;
    overflow: hidden;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    background: var(--gradient);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    flex-shrink: 0;
}

.brand-logo i {
    width: 22px;
    height: 22px;
}

.brand h2 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.brand h2 span {
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 2px;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 8px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 9px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
    position: relative;
}

.tab-btn i {
    width: 15px;
    height: 15px;
}

.tab-btn.active {
    background: var(--panel-solid);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tab-btn:hover:not(.active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.doc-count-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--primary);
    color: #000;
    font-size: 0.6rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.doc-count-badge.hidden {
    display: none;
}

/* Tab Content Panels */
.tab-content {
    display: none;
    flex-direction: column;
    gap: 10px;
}

.tab-content.active {
    display: flex;
}

.section-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted);
    font-weight: 700;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    background: rgba(255, 255, 255, 0.02);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(79, 172, 254, 0.07);
}

.upload-icon {
    width: 30px;
    height: 30px;
    color: var(--muted);
    margin-bottom: 8px;
    transition: color 0.25s, transform 0.25s;
}

.upload-zone:hover .upload-icon {
    color: var(--primary);
    transform: translateY(-2px);
}

.upload-zone p {
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-subtext {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
    display: block;
}

.status-msg {
    font-size: 0.8rem;
    padding: 9px 12px;
    border-radius: 8px;
    line-height: 1.4;
}

.status-msg.success {
    background: rgba(52, 211, 153, 0.1);
    color: var(--success);
}

.status-msg.error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger);
}

.status-msg.info {
    background: rgba(79, 172, 254, 0.1);
    color: var(--primary);
}

.hidden {
    display: none !important;
}

/* Document Library */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
}

.doc-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.doc-empty-state i {
    width: 28px;
    height: 28px;
    opacity: 0.4;
}

.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    transition: all 0.25s;
}

.doc-item:hover {
    background: rgba(255, 255, 255, 0.07);
}

.doc-item.deleting {
    opacity: 0.5;
    pointer-events: none;
}

.doc-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.doc-item-icon {
    width: 15px;
    height: 15px;
    color: var(--primary);
    flex-shrink: 0;
}

.doc-item-name {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.doc-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.doc-delete-btn i {
    width: 14px;
    height: 14px;
}

.doc-delete-btn:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
}

/* Vitals Card */
.vitals-card {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    border-left: 3px solid var(--primary);
}

.vitals-header {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 12px;
}

.vitals-icon {
    width: 16px;
    height: 16px;
    color: var(--danger);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    margin-left: auto;
    box-shadow: 0 0 8px var(--success);
    animation: pulseDot 1.5s infinite ease-in-out;
}

@keyframes pulseDot {

    0%,
    100% {
        transform: scale(0.8);
        opacity: 0.6;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

.vitals-grid {
    display: flex;
    justify-content: space-between;
}

.vital-stat {
    display: flex;
    flex-direction: column;
}

.vital-label {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vital-value {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
}

.vital-value small {
    font-size: 0.65rem;
    color: var(--muted);
    font-family: var(--font);
    font-weight: 400;
}

.status-ok {
    font-size: 0.85rem !important;
    color: var(--success) !important;
    font-weight: 500;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.agent-pill {
    display: flex;
    align-items: center;
    gap: 10px;
}

.agent-avatar {
    width: 38px;
    height: 38px;
    background: var(--gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    flex-shrink: 0;
}

.agent-avatar i {
    width: 18px;
    height: 18px;
}

.agent-name {
    font-weight: 600;
    font-size: 0.88rem;
}

.agent-online {
    font-size: 0.72rem;
    color: var(--success);
    margin-top: 2px;
}

/* === WORKSPACE === */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
}

.workspace-header {
    padding: 18px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.workspace-header h1 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 3px;
}

.workspace-header p {
    font-size: 0.87rem;
    color: var(--muted);
}

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

.model-dropdown {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    appearance: none;
}

.model-dropdown option {
    background: var(--panel-solid);
    color: var(--text);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn i {
    width: 18px;
    height: 18px;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* === CHAT === */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* Messages */
.message {
    display: flex;
    gap: 10px;
    max-width: 88%;
    align-items: flex-start;
}

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

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar i {
    width: 17px;
    height: 17px;
}

.system-avatar {
    background: rgba(79, 172, 254, 0.12);
    color: var(--primary);
}

.user-avatar {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.message-content {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 4px 16px 16px 16px;
    padding: 14px 18px;
    font-size: 0.93rem;
    line-height: 1.65;
    color: var(--text);
}

.user-message .message-content {
    background: rgba(79, 172, 254, 0.1);
    border-color: rgba(79, 172, 254, 0.2);
    border-radius: 16px 4px 16px 16px;
}

.message-content.error-content {
    color: var(--danger);
}

.message-content p+p {
    margin-top: 8px;
}

.context-preview {
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.25);
    border-left: 2px solid var(--primary);
    font-size: 0.78rem;
    color: var(--muted);
    border-radius: 0 8px 8px 0;
    line-height: 1.5;
}

.citation-badge {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    background: rgba(79, 172, 254, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 500;
    margin: 0 2px;
    white-space: nowrap;
    cursor: help;
    transition: all 0.2s ease;
}

.citation-badge:hover {
    background: rgba(79, 172, 254, 0.2);
}

.system-notice {
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    padding: 4px 0;
}

/* Live Hero Card */
.live-hero-card {
    background: rgba(20, 25, 35, 0.4);
    border-bottom: 1px solid var(--border);
    padding: 20px 24px;
}

.hero-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.hero-header h2 {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.hero-header i {
    color: var(--primary);
}

.hero-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.hero-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(255, 255, 255, 0.03);
    padding: 15px 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.hero-label {
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hero-value {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text);
}

.hero-value small {
    font-size: 1rem;
    color: var(--muted);
    font-weight: 400;
}

/* Input Area */
.chat-input-area {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    padding: 8px 10px;
    transition: border-color 0.25s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
}

textarea#query-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    padding: 6px 4px;
    line-height: 1.5;
}

textarea#query-input::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

.action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.action-btn i {
    width: 18px;
    height: 18px;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.send-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: var(--gradient);
    color: #000;
    border-radius: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn i {
    width: 17px;
    height: 17px;
}

.send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(79, 172, 254, 0.35);
}

.send-btn:active {
    transform: translateY(0);
}

.input-hint {
    font-size: 0.72rem;
    color: var(--muted);
    padding-left: 4px;
}

.input-hint kbd {
    display: inline-block;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.7rem;
    font-family: var(--font);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--muted);
    border-radius: 50%;
    animation: bounce 1.3s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Animations */
.fade-in {
    animation: fadeIn 0.35s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === MOBILE RESPONSIVENESS === */
@media (max-width: 768px) {
    .app-shell {
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-shrink: 0;
    }

    .workspace {
        height: 75vh;
        flex-shrink: 0;
        margin-top: 10px;
    }

    .workspace-header {
        padding: 14px 18px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .workspace-header h1 {
        font-size: 1.2rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .chat-messages {
        padding: 16px;
    }

    .message {
        max-width: 95%;
    }
}

/* === ROLE TABS === */
.role-tabs {
    display: inline-flex;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    padding: 4px;
    border: 1px solid var(--border);
}

.role-tab {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
}

.role-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.report-btn {
    border-color: var(--primary);
    color: var(--primary);
    display: flex;
}

.generate-pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(45, 212, 191, 0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.generate-pdf-btn i {
    width: 14px;
    height: 14px;
}

.generate-pdf-btn:hover {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(45, 212, 191, 0.4);
}

/* === PATIENT THEME (RELAXING LIGHT GREEN/BLUE) === */
body.theme-patient .sidebar {
    display: none !important;
}

body.theme-patient {
    --bg: #fdfdfd;
    /* Clean warm white */
    --panel: rgba(255, 255, 255, 0.95);
    --panel-solid: #ffffff;
    --border: rgba(14, 165, 233, 0.15);
    --primary: #0ea5e9;
    /* Sky blue */
    --primary-end: #10b981;
    /* Emerald green */
    --text: #0f172a;
    /* Slate 900 for high readability */
    --muted: #64748b;
    --danger: #ef4444;
    --success: #10b981;
    background-image:
        radial-gradient(ellipse 60% 50% at 10% 50%, rgba(16, 185, 129, 0.1), transparent),
        radial-gradient(ellipse 50% 40% at 90% 20%, rgba(14, 165, 233, 0.1), transparent);
}

body.theme-patient .brand-logo,
body.theme-patient .agent-avatar,
body.theme-patient .send-btn {
    color: #ffffff;
}

body.theme-patient .generate-pdf-btn {
    background: rgba(14, 165, 233, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

body.theme-patient .generate-pdf-btn:hover {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

body.theme-patient .role-tabs {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(14, 165, 233, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

body.theme-patient .role-tab {
    color: var(--muted);
}

body.theme-patient .role-tab.active {
    background: var(--primary);
    color: #fff;
}

body.theme-patient .icon-btn {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(14, 165, 233, 0.2);
    color: var(--text);
}

body.theme-patient .icon-btn:hover {
    background: #fff;
}

body.theme-patient .input-wrapper {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(14, 165, 233, 0.2);
}

body.theme-patient .message-content {
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    border-color: var(--border);
}

body.theme-patient .user-message .message-content {
    background: rgba(14, 165, 233, 0.08);
    border-color: rgba(14, 165, 233, 0.15);
}

body.theme-patient .context-preview {
    background: rgba(14, 165, 233, 0.05);
    color: var(--text);
}

body.theme-patient .action-btn:hover {
    color: var(--primary);
    background: rgba(14, 165, 233, 0.1);
}

/* Fix Hero Telemetry Panel Contrast for Patient Theme */
body.theme-patient .hero-panel {
    background: rgba(255, 255, 255, 0.6);
    border-color: rgba(14, 165, 233, 0.15);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
}

body.theme-patient .hero-panel h3 {
    color: var(--text);
}

body.theme-patient .hero-panel h3 i {
    color: var(--primary);
}

body.theme-patient .hero-card {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(14, 165, 233, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

body.theme-patient .hero-label {
    color: var(--muted);
    font-weight: 600;
}

body.theme-patient .hero-value {
    color: var(--text);
}

body.theme-patient .hero-value small {
    color: var(--muted);
}