/* ER Simulator - Modern Medical Theme (mobile-first) */

:root {
    --primary-medical: #1e88e5;
    --primary-dark: #1565c0;
    --accent-emergency: #e53935;
    --accent-success: #43a047;
    --bg-gradient-start: #f8f9fa;
    --bg-gradient-end: #e3f2fd;
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.12);
    --shadow-strong: 0 8px 30px rgba(0, 0, 0, 0.15);
    /* Safe area for notched devices */
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --safe-right: env(safe-area-inset-right, 0);
    /* Touch target minimum (44px Apple HIG) */
    --touch-min: 44px;
    --app-bg: #020617;
    --app-panel: rgba(15, 23, 42, 0.72);
    --app-panel-strong: rgba(15, 23, 42, 0.88);
    --app-border: rgba(255, 255, 255, 0.1);
    --app-text: #e2e8f0;
    --app-muted: #94a3b8;
    --app-accent: #60a5fa;
    --app-accent-strong: #2563eb;
    --app-danger: #ef4444;
    --app-success: #10b981;
    --app-glow: 0 25px 60px rgba(2, 6, 23, 0.45);
}

/* Global Styles */
body {
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    padding-bottom: var(--safe-bottom);
}

/* Immersive app shell */
.app-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 0;
    min-height: 100vh;
    color: var(--app-text);
    background:
        radial-gradient(circle at top, rgba(59, 130, 246, 0.25), transparent 28%),
        radial-gradient(circle at 20% 80%, rgba(16, 185, 129, 0.16), transparent 26%),
        linear-gradient(180deg, #0f172a 0%, var(--app-bg) 48%, #01030b 100%);
    overflow-x: hidden;
}

.app-shell__backdrop,
.app-shell__aurora {
    position: fixed;
    inset: auto;
    pointer-events: none;
    z-index: 0;
}

.app-shell__backdrop {
    inset: 0;
    background:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 72px 72px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent 90%);
}

.app-shell__aurora {
    width: 38rem;
    height: 38rem;
    border-radius: 999px;
    filter: blur(70px);
    opacity: 0.5;
}

.app-shell__aurora--one {
    top: -12rem;
    right: -10rem;
    background: rgba(37, 99, 235, 0.22);
}

.app-shell__aurora--two {
    bottom: -14rem;
    left: -12rem;
    background: rgba(14, 165, 233, 0.18);
}

.glass-panel {
    background: var(--app-panel);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--app-border);
    box-shadow: var(--app-glow);
}

.app-header,
.app-footer,
.app-main {
    position: relative;
    z-index: 1;
}

.app-header {
    margin: 0.8rem 1rem 0;
    border-radius: 1.5rem;
}

.app-header__inner,
.app-footer__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.25rem;
}

.app-brand,
.app-brand:hover {
    color: #f8fafc !important;
    text-decoration: none;
    font-weight: 1000;
    letter-spacing: -0.03em;
}

.app-header__meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--app-muted);
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-header__dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: var(--app-success);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.9);
    animation: statusPulse 2s infinite;
}

.app-main {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem;
}

.app-footer {
    margin: auto 1rem calc(0.35rem + var(--safe-bottom));
    border-radius: 0.5rem;
}

.app-footer__inner {
    gap: 0.1rem;
    color: var(--app-muted);
    font-size: 0.72rem;
    white-space: nowrap;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
}

.app-footer__links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.app-footer__links a {
    color: var(--app-text);
    text-decoration: none;
}

.app-footer__links a:hover {
    color: white;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* Avatar immersive (this sheet only loads on Avatar, max-width via link media) */
.app-main {
    padding: 0.75rem 1rem 1rem;
}

.avatar-experience {
    position: relative;
    min-height: calc(100vh - 12.5rem);
    border-radius: 2rem;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.16);
    box-shadow: var(--app-glow);
    background: #020617;
}

.avatar-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background:
        radial-gradient(circle at center, rgba(30, 41, 59, 0.98) 0%, rgba(2, 6, 23, 1) 62%);
}

.avatar-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to bottom, rgba(2, 6, 23, 0.18), rgba(2, 6, 23, 0.78)),
        radial-gradient(circle at center, rgba(96, 165, 250, 0.09), transparent 42%);
    pointer-events: none;
}

#avatarVideo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #020617;
}

.avatar-placeholder,
.avatar-loading {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--app-text);
}

.avatar-placeholder__icon {
    display: grid;
    place-items: center;
    width: 6rem;
    height: 6rem;
    margin-bottom: 1.5rem;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.82);
    border: 1px solid rgba(148, 163, 184, 0.18);
    font-size: 2.25rem;
    color: #64748b;
}

.avatar-placeholder__eyebrow,
.consultation-header__eyebrow {
    margin-bottom: 0.1rem;
    color: var(--app-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

.avatar-placeholder h2 {
    margin-bottom: 0.5rem;
    font-size: clamp(1.75rem, 4vw, 2.4rem);
    font-weight: 700;
}

.avatar-placeholder p:last-child,
.avatar-loading p {
    margin: 0;
    max-width: 28rem;
    color: #cbd5e1;
}

.avatar-overlay {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: inherit;
    pointer-events: none;
}

.consultation-header,
.consultation-footer,
.consultation-transcript {
    pointer-events: auto;
}

.consultation-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-start;
    padding: 0.9rem 1rem 0.85rem;
    background:
        linear-gradient(180deg, rgba(2, 6, 23, 0.94) 0%, rgba(2, 6, 23, 0.82) 72%, rgba(2, 6, 23, 0.22) 100%);
}

.consultation-header__title-block {
    min-width: 0;
    width: 100%;
}

.consultation-header__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
}

.consultation-header h1 {
    margin: 0;
    color: #f8fafc;
    font-size: clamp(0.98rem, 1.7vw, 1.14rem);
    font-weight: 700;
    letter-spacing: -0.025em;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.28rem 0.58rem;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: #f8fafc;
    font-size: 0.68rem;
    font-weight: 600;
    flex-shrink: 0;
    line-height: 1;
}

.status-chip .fa-circle {
    font-size: 0.52rem;
    color: #94a3b8 !important;
}

.consultation-session-meta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
    color: #e2e8f0;
    margin-top: 0.55rem;
    line-height: 1;
}

.consultation-session-meta__label {
    color: var(--app-muted);
    font-size: 0.69rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.consultation-session-meta #sessionIdDisplay {
    color: #cbd5e1;
    font-size: 0.74rem;
    font-weight: 600;
}

.consultation-spacer {
    flex: 1 1 auto;
    min-height: 6.8rem;
}

.consultation-transcript {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-self: stretch;
    margin: 0 1.25rem 12.25rem;
    padding: 0.9rem;
    max-height: min(32vh, 18rem);
    background: rgba(15, 23, 42, 0.24);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.4rem;
    box-shadow: 0 18px 42px rgba(2, 6, 23, 0.24);
    overflow-y: auto;
}

.transcript-placeholder {
    align-self: flex-start;
    max-width: min(85%, 24rem);
    padding: 1rem 1.1rem;
    border-radius: 1.25rem 1.25rem 1.25rem 0.35rem;
    background: rgba(15, 23, 42, 0.74);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--app-text);
    box-shadow: 0 20px 45px rgba(2, 6, 23, 0.36);
}

.transcript-placeholder i {
    margin-bottom: 0.6rem;
    color: var(--app-accent);
}

.transcript-placeholder p {
    margin: 0;
}

.chat-bubble-entry {
    max-width: min(85%, 28rem);
    padding: 0.95rem 1rem;
    border-radius: 1.25rem;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 38px rgba(2, 6, 23, 0.34);
    animation: messageSlide 0.28s ease-out;
}

.chat-bubble-entry--user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(29, 78, 216, 0.94), rgba(30, 64, 175, 0.9));
    border-color: rgba(191, 219, 254, 0.28);
    border-bottom-right-radius: 0.35rem;
}

.chat-bubble-entry--user .chat-bubble-entry__sender,
.chat-bubble-entry--user .chat-bubble-entry__body,
.chat-bubble-entry--user .chat-bubble-entry__time {
    color: #eff6ff;
}

.chat-bubble-entry--assistant {
    align-self: flex-start;
    background: rgba(15, 23, 42, 0.78);
    border-bottom-left-radius: 0.35rem;
}

.chat-bubble-entry--system {
    align-self: center;
    background: rgba(148, 163, 184, 0.16);
}

.chat-bubble-entry--error {
    align-self: center;
    background: rgba(127, 29, 29, 0.72);
    border-color: rgba(248, 113, 113, 0.35);
}

.chat-bubble-entry__sender {
    display: block;
    margin-bottom: 0.35rem;
    color: #93c5fd;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.chat-bubble-entry__body {
    color: #e2e8f0;
    line-height: 1.45;
}

.chat-bubble-entry__time {
    display: block;
    margin-top: 0.45rem;
    color: var(--app-muted);
    font-size: 0.72rem;
}

.consultation-footer {
    position: fixed;
    left: 50%;
    width: min(calc(100vw - 2.4rem), 30rem);
    bottom: calc(5rem + var(--safe-bottom));
    transform: translateX(-50%);
    box-sizing: border-box;
    margin: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 0.9rem 0.9rem calc(0.9rem + var(--safe-bottom));
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.55rem;
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.consultation-input-row {
    order: 0;
    width: 100%;
    margin-top: 0;
    margin-bottom: 0.55rem;
    align-self: stretch;
}

.consultation-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin-top: 0;
    min-height: 2.9rem;
    padding: 0.72rem 0.9rem;
    color: white;
    background: rgba(2, 6, 23, 0.56);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.95rem;
}

.consultation-input::placeholder {
    color: #64748b;
}

.consultation-input:disabled {
    opacity: 0.75;
    background: rgb(245, 245, 246);
}

.consultation-actions {
    order: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.session-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 4.15rem;
    padding: 0.58rem 0.45rem;
    color: var(--app-text);
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1rem;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.session-action:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(96, 165, 250, 0.35);
}

.session-action:disabled {
    opacity: 0.55;
}

.session-action--primary {
    background: rgba(37, 99, 235, 0.22);
    border-color: rgba(96, 165, 250, 0.28);
}

.session-action--toggle {
    position: relative;
    cursor: pointer;
}

.session-action--toggle input {
    position: absolute;
    right: 0.55rem;
    top: 0.55rem;
    transform: scale(0.9);
}

.session-action__icon {
    display: grid;
    place-items: center;
    width: 2.45rem;
    height: 2.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    font-size: 0.88rem;
}

.session-action__label {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.session-toggle-button {
    order: 2;
    width: 100%;
    min-height: 3rem;
    border-radius: 1rem;
    font-weight: 800;
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    border: 1px solid transparent;
    transition: transform 0.2s ease, background 0.2s ease;
}

.session-toggle-button:hover {
    transform: translateY(-1px);
}

.session-toggle-button--start {
    color: #020617;
    background: #f8fafc;
}

.session-toggle-button--stop {
    color: #f87171;
    background: rgba(127, 29, 29, 0.3);
    border-color: rgba(248, 113, 113, 0.35);
}

.consultation-footer__meta,
.recording-status {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.65rem;
    color: var(--app-muted);
    font-size: 0.72rem;
}

.consultation-footer__meta {
    order: 3;
}

.recording-status {
    order: 4;
    color: #fbbf24;
}

@media (max-width: 768px) {
    .app-header,
    .app-footer {
        margin-left: 0.75rem;
        margin-right: 0.75rem;
        border-radius: 1.25rem;
    }

    .app-main {
        padding: 0.75rem;
    }

    .avatar-experience {
        min-height: calc(100vh - 11.75rem);
        border-radius: 1.6rem;
    }

    .consultation-header {
        padding: 0.82rem 0.9rem 0.8rem;
    }

    .consultation-header__title-row {
        gap: 0.5rem;
    }

    .consultation-header h1 {
        font-size: 0.95rem;
    }

    .status-chip {
        padding: 0.25rem 0.5rem;
        font-size: 0.64rem;
    }

    .consultation-session-meta {
        margin-top: 0.5rem;
    }

    .consultation-session-meta__label {
        font-size: 0.64rem;
    }

    .consultation-session-meta #sessionIdDisplay {
        font-size: 0.68rem;
    }

    .consultation-transcript {
        margin-left: 0.9rem;
        margin-right: 0.9rem;
        margin-bottom: 12.75rem;
        padding: 0.75rem;
        max-height: 28vh;
    }

    .consultation-footer {
        width: min(calc(100vw - 1.35rem), 30rem);
        bottom: calc(5.5rem + var(--safe-bottom));
        padding-left: 0.8rem;
        padding-right: 0.8rem;
        border-radius: 1.3rem;
    }

    .consultation-actions {
        gap: 0.5rem;
    }

    .session-action {
        min-height: 3.7rem;
        padding: 0.5rem 0.4rem;
    }

    .session-action__icon {
        width: 2.2rem;
        height: 2.2rem;
        font-size: 0.8rem;
    }

    .session-toggle-button {
        min-height: 2.8rem;
        font-size: 0.72rem;
    }

    body:has(.avatar-experience) .app-footer {
        position: fixed;
        left: 50%;
        bottom: calc(0.45rem + var(--safe-bottom));
        margin: 0;
        width: min(calc(100vw - 1.5rem), 26rem);
        transform: translateX(-50%);
        z-index: 15;
        border-radius: 999px;
        background: rgba(15, 23, 42, 0.82);
        box-shadow: 0 18px 36px rgba(2, 6, 23, 0.32);
    }
}

@media (max-width: 576px) {
    .app-header__inner,
    .app-footer__inner {
        align-items: center;
    }

    .app-header__inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .app-footer__inner {
        flex-direction: row;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.12rem 0.12rem;
        font-size: 0.8rem;
    }

    body:has(.avatar-experience) .app-footer__inner {
        justify-content: center;
        gap: 0.75rem;
        padding: 0.25rem 0.85rem;
        font-size: 0.72rem;
    }

    .app-footer__links {
        gap: 0.5rem;
    }

    .consultation-header h1 {
        align-items: flex-start;
    }

    .consultation-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .session-action__label {
        font-size: 0.63rem;
    }
}

/* Navbar Enhancement */
.navbar {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95) !important;
    box-shadow: var(--shadow-soft);
    border-bottom: 2px solid var(--primary-medical) !important;
    padding-top: calc(0.5rem + var(--safe-top));
    padding-left: calc(0.5rem + var(--safe-left));
    padding-right: calc(0.5rem + var(--safe-right));
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--primary-medical) !important;
}

@media (max-width: 576px) {
    .navbar-brand {
        font-size: 1.1rem;
    }
}

/* Chat Container Enhancement */
.chat-container {
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-strong);
    background: white;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--primary-medical) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1rem 1rem 1rem calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    border-bottom: 3px solid rgba(255, 255, 255, 0.2);
}

.chat-header h4 {
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-header small {
    opacity: 0.9;
    font-size: 0.85rem;
}

/* Chat Messages Area */
.chat-messages {
    padding: 1rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    height: 500px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(to bottom, #ffffff 0%, #f8f9fa 100%);
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--primary-medical);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Transcript area on Avatar/Patient pages */
.chat-messages.chat-transcript {
    height: 200px;
}

@media (max-width: 576px) {
    .chat-messages.chat-transcript {
        height: 160px;
    }
}

/* Message Bubbles */
.message-user {
    background: linear-gradient(135deg, var(--primary-medical) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 0.875rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-medium);
    animation: messageSlide 0.3s ease-out;
}

.message-ai {
    background: white;
    color: #2c3e50;
    border-radius: 18px 18px 18px 4px;
    padding: 0.875rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-soft);
    border-left: 4px solid var(--accent-success);
    animation: messageSlide 0.3s ease-out;
}

.message-error {
    background: var(--accent-emergency);
    color: white;
    border-radius: 18px;
    padding: 0.875rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-medium);
    animation: shake 0.5s;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Message Info */
.message-info {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

/* Welcome Screen */
.welcome-screen {
    text-align: center;
    padding: 3rem 2rem;
    color: #64748b;
}

.welcome-icon {
    font-size: 4rem;
    color: var(--primary-medical);
    margin-bottom: 1.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Chat Input Area */
.chat-input-container {
    /*background: linear-gradient(to top, #ffffff 0%, #f8f9fa 100%);*/
    padding: 1rem;
    padding-left: calc(1rem + var(--safe-left));
    padding-right: calc(1rem + var(--safe-right));
    padding-bottom: calc(1rem + var(--safe-bottom));
    border-top: 0px solid #e0e0e0;
}

.input-group {
    position: relative;
}

/* Avatar/Patient page: wrap buttons on small screens */
.chat-input-container .input-group.input-group-mobile {
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-input-container .input-group.input-group-mobile .form-control {
    flex: 1 1 100%;
    min-width: 0;
}

.chat-input-container .input-group.input-group-mobile .btn {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    flex: 1 1 auto;
}

.form-control {
    border-radius: 25px;
    border: 2px solid #e0e0e0;
    padding: 0.75rem 1.5rem;
    min-height: var(--touch-min);
    font-size: 16px; /* prevents zoom on focus in iOS */
    transition: all 0.3s ease;
}

.form-control:focus {
    border-color: var(--primary-medical);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
    outline: none;
}

.btn-send {
    border-radius: 25px;
    padding: 0.75rem 2rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-medical) 0%, var(--primary-dark) 100%);
    border: none;
    box-shadow: var(--shadow-soft);
    transition: all 0.3s ease;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

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

/* Logs Panel */
.logs-panel {
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-strong);
    background: white;
    animation: slideIn 0.3s ease-out 0.1s both;
}

.sources-panel {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-strong);
}

.quiz-launch .btn-quiz {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 30px;
    padding: 0.5rem 1.25rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.quiz-launch .btn-quiz:hover {
    background: white;
    color: var(--primary-medical);
    transform: translateY(-1px);
}

.quiz-container {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-strong);
    padding: 1.5rem;
    border: 1px solid #e2e8f0;
}

.quiz-header h5 {
    margin-bottom: 0;
    color: var(--primary-medical);
    font-weight: 600;
}

.quiz-body {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.quiz-question-card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    transition: all 0.3s ease;
}

.quiz-question-card.quiz-correct {
    border-color: #4ade80;
    background: #f0fdf4;
}

.quiz-question-card.quiz-incorrect {
    border-color: #fca5a5;
    background: #fef2f2;
}

.quiz-question-title {
    color: var(--primary-medical);
    font-weight: 600;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.quiz-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.quiz-option:hover {
    border-color: var(--primary-medical);
    background: #eef6ff;
}

.quiz-option input[type="radio"] {
    accent-color: var(--primary-medical);
}

.quiz-footer {
    margin-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 1rem;
}

.quiz-feedback {
    border-radius: 12px;
}

.quiz-feedback-answer {
    font-weight: 600;
    color: var(--primary-dark);
}

.sources-header {
    background: linear-gradient(135deg, var(--primary-medical) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem;
    border-bottom: 3px solid rgba(255, 255, 255, 0.18);
}

.sources-body {
    padding: 1rem;
    max-height: 550px;
    overflow-y: auto;
}

.source-entry {
    background: #f8fbff;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--primary-medical);
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.source-entry:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-medium);
}

.source-link {
    font-weight: 600;
    color: var(--primary-medical);
    text-decoration: none;
}

.source-link:hover {
    text-decoration: underline;
}

.source-similarity {
    background: rgba(30, 136, 229, 0.12);
    color: var(--primary-dark);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
}

.source-preview {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #475569;
}

.source-open-hint {
    font-size: 0.75rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.source-open-hint i {
    font-size: 0.75rem;
}

.logs-header {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    color: white;
    padding: 1.5rem;
}

.logs-body {
    padding: 1rem;
    max-height: 550px;
    overflow-y: auto;
}

.log-entry {
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid var(--primary-medical);
    transition: all 0.3s ease;
}

.log-entry:hover {
    background: #e3f2fd;
    transform: translateX(5px);
}

.log-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    color: #64748b;
}

.log-response-time {
    background: var(--primary-medical);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-weight: 600;
}

/* Refresh Button */
.btn-refresh {
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-refresh:hover {
    transform: rotate(180deg);
}

/* Loading Modal */
.modal-content {
    border-radius: 16px;
    border: none;
    box-shadow: var(--shadow-strong);
}

.modal-body {
    padding: 3rem 2rem;
}

.spinner-border {
    width: 4rem;
    height: 4rem;
    border-width: 0.4rem;
}

/* Avatar video container - mobile height */
.avatar-video-container {
    min-height: 280px;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 576px) {
    .avatar-video-container {
        min-height: 360px;
    }
}

@media (min-width: 768px) {
    .avatar-video-container {
        min-height: 420px;
    }
}

@media (min-width: 992px) {
    .avatar-video-container {
        min-height: 500px;
    }
}

/* Footer safe area */
.app-footer {
    padding-bottom: calc(0.5rem + var(--safe-bottom));
}

.app-footer .container {
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

.app-footer a {
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
}

/* Touch targets: buttons and clickable areas */
@media (max-width: 768px) {
    .btn:not(.btn-sm) {
        min-height: var(--touch-min);
        padding: 0.6rem 1rem;
    }

    .chat-header {
        padding: 0.75rem calc(0.75rem + var(--safe-left));
        padding-right: calc(0.75rem + var(--safe-right));
    }

    .chat-header h4 {
        font-size: 1.1rem;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-messages {
        height: 380px;
    }
    
    .welcome-icon {
        font-size: 3rem;
    }
    
    .message-user, .message-ai {
        max-width: 90%;
    }

    .container-fluid.py-4 {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
        padding-left: calc(0.5rem + var(--safe-left)) !important;
        padding-right: calc(0.5rem + var(--safe-right)) !important;
    }
}

@media (max-width: 576px) {
    .chat-messages {
        height: 280px;
    }

    .welcome-screen {
        padding: 1.5rem 1rem;
    }

    .welcome-icon {
        font-size: 2.5rem;
    }

    .message-user, .message-ai {
        max-width: 95%;
        padding: 0.65rem 1rem;
    }

    .chat-input-container {
        padding: 0.75rem;
        padding-left: calc(0.75rem + var(--safe-left));
        padding-right: calc(0.75rem + var(--safe-right));
        padding-bottom: calc(0.75rem + var(--safe-bottom));
    }

    .sources-panel .sources-header,
    .sources-panel .sources-body {
        padding-left: calc(1rem + var(--safe-left));
        padding-right: calc(1rem + var(--safe-right));
    }

    .quiz-container {
        padding: 1rem;
        margin-left: calc(-0.5rem - var(--safe-left));
        margin-right: calc(-0.5rem - var(--safe-right));
        border-radius: 0;
    }
}

/* Index: sources panel full width on mobile, collapsible hint */
@media (max-width: 991px) {
    .sources-panel {
        margin-top: 1rem;
    }

    .sources-body {
        max-height: 400px;
    }
}

/* Modals: full-width on small screens */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1.5rem 1rem;
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-medical);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Floating Action */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

.floating {
    animation: float 3s ease-in-out infinite;
}

/* Video Call Interface Styles */
.video-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 1rem 1.5rem;
    background: linear-gradient(180deg, rgba(2, 6, 23, 0.9) 0%, rgba(2, 6, 23, 0.6) 70%, transparent 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.video-header__content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.video-header__title {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.video-header__title h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
}

.video-header__status {
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.9;
}

.video-header__status--success {
    color: #10b981;
}

.video-header__status--warning {
    color: #f59e0b;
}

.video-header__status--danger {
    color: #ef4444;
}

.video-header__status--secondary {
    color: #94a3b8;
}

.video-header__timer {
    font-size: 0.9rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: white;
}

.pip-view {
    position: absolute;
    top: 3.8rem;
    right: 0.8rem;
    width: 4.9rem;
    height: 7.2rem;
    padding: 0.55rem 0.45rem;
    background:
        linear-gradient(180deg, rgba(51, 65, 85, 0.94), rgba(30, 41, 59, 0.96)),
        radial-gradient(circle at top, rgba(148, 163, 184, 0.16), transparent 58%);
    border-radius: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.24);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 14px 30px rgba(2, 6, 23, 0.32);
}

.pip-view__badge {
    align-self: flex-start;
    padding: 0.16rem 0.38rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #cbd5e1;
    font-size: 0.44rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.pip-view__avatar {
    display: grid;
    place-items: center;
    width: 100%;
    flex: 1 1 auto;
    color: rgba(203, 213, 225, 0.62);
    font-size: 1.5rem;
}

.pip-view__meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.12rem;
    width: 100%;
}

.pip-view__name {
    color: #f8fafc;
    font-size: 0.52rem;
    font-weight: 600;
}

.pip-view__status {
    color: #22c55e;
    font-size: 0.46rem;
    font-weight: 500;
}

.floating-controls {
    position: fixed;
    bottom: calc(2rem + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    box-shadow: 0 8px 32px rgba(2, 6, 23, 0.3);
}

.session-panel {
    position: fixed;
    right: 0.85rem;
    bottom: calc(1.85rem + var(--safe-bottom));
    z-index: 25;
    /* Wide enough for Claude/Local labels; cap height so Answer engine stays reachable (scroll) on short phones */
    width: min(11.5rem, calc(100vw - 4.5rem));
    max-height: min(72vh, calc(100dvh - 5.5rem - var(--safe-top) - var(--safe-bottom)));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.58rem;
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.15rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 20px 44px rgba(2, 6, 23, 0.36);
}

.session-panel__actions {
    display: block;
}

.session-panel__actions #recordButton[hidden] {
    display: none !important;
}

.session-panel .session-action--toggle {
    width: 100%;
}

.session-panel .session-action--toggle input {
    right: 0.7rem;
    top: 0.7rem;
}

.session-panel .recording-status {
    display: none !important;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.control-btn--active {
    background: #3b82f6;
    color: white;
}

.control-btn--muted {
    background: #ef4444;
    color: white;
}

.control-btn--end {
    background: #ef4444;
}

.control-btn--end:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.chat-drawer {
    position: fixed;
    left: 50%;
    bottom: calc(6.75rem + var(--safe-bottom));
    width: min(calc(100vw - 1.5rem), 20rem);
    z-index: 30;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(15, 23, 42, 0.95));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transform: translate(-50%, 1.25rem) scale(0.97);
    transform-origin: bottom center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: min(24rem, calc(100vh - 9rem));
    overflow: hidden;
    border-radius: 1.35rem;
    box-shadow: 0 20px 44px rgba(2, 6, 23, 0.4);
}

.chat-drawer--open {
    transform: translate(-50%, 0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.chat-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.95rem 1rem 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(17, 24, 39, 0.92);
}

.chat-drawer__header h4 {
    margin: 0;
    color: white;
    font-size: 1rem;
    font-weight: 700;
}

.chat-drawer__close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.chat-drawer__close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Update avatar experience for full-screen video */
.avatar-experience {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    overflow: hidden;
}

.avatar-stage {
    position: absolute;
    inset: 0;
    background: #000;
}

#avatarVideo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* Hide the old overlay structure */
.avatar-overlay {
    display: none;
}

/* Update consultation transcript for drawer */
.consultation-transcript {
    max-height: none;
    flex: 1 1 auto;
    min-height: 9rem;
    height: auto;
    margin: 0;
    padding: 0.9rem 0.95rem 0.8rem;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow-y: auto;
}

.consultation-footer {
    position: static;
    width: 100%;
    max-width: 100%;
    align-self: stretch;
    bottom: auto;
    margin: 0;
    padding: 0.75rem 0.85rem 0.85rem;
    background: rgba(17, 24, 39, 0.94);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0;
    box-shadow: none;
    flex-shrink: 0;
    box-sizing: border-box;
    overflow: visible;
}

.chat-drawer .chat-input-container {
    position: static;
    padding: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
}

.chat-drawer .transcript-placeholder,
.chat-drawer .chat-bubble-entry {
    max-width: 100%;
}

.chat-drawer .transcript-placeholder {
    max-width: 100%;
    padding: 0.95rem 3rem;
    border-radius: 1rem;
    background: rgba(51, 65, 85, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: none;
}

.chat-drawer .drawer-composer {
    display: grid;
    right: 0.5rem;
    grid-template-columns: minmax(0, 1fr) 3rem;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: visible;
    padding: 0;
}

.chat-drawer .consultation-input {
    width: 100%;
    height: 3rem;
    min-height: 3rem;
    padding-top: 0;
    padding-bottom: 0;
    border-radius: 999px;
    padding-inline: 1rem;
    line-height: 3rem;
    color: #f8fafc;
    background: rgba(51, 65, 85, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-drawer .session-action--primary {
    width: 3rem;
    height: 3rem;
    min-width: 3rem;
    min-height: 3rem;
    padding: 0;
    border-radius: 999px;
    justify-self: end;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-color: rgba(147, 197, 253, 0.35);
}

.chat-drawer .session-action--primary .session-action__icon {
    width: 100%;
    height: 100%;
    background: transparent;
}

.chat-drawer .session-action--primary .session-action__label {
    display: none;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    body:has(.avatar-experience) .app-footer {
        display: none;
    }

    .video-header {
        padding: 0.75rem 1rem;
    }
    
    .video-header__title h3 {
        font-size: 1rem;
    }
    
    .video-header__timer {
        font-size: 0.8rem;
    }
    
    .floating-controls {
        bottom: calc(1.5rem + var(--safe-bottom));
        padding: 0.6rem 1.2rem;
        gap: 0.75rem;
    }

    .session-panel {
        right: 0.6rem;
        bottom: calc(1.55rem + var(--safe-bottom));
        width: min(11rem, calc(100vw - 4rem));
        max-height: min(68vh, calc(100dvh - 5rem - var(--safe-top) - var(--safe-bottom)));
        padding: 0.5rem;
        gap: 0.42rem;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .chat-drawer {
        width: min(calc(100vw - 1rem), 19rem);
        bottom: calc(6.4rem + var(--safe-bottom));
        max-height: min(20rem, calc(100vh - 8rem));
        border-radius: 1.2rem;
    }
    
    .consultation-transcript {
        min-height: 0;
        padding: 0.8rem 0.8rem 0.65rem;
    }

    .consultation-footer {
        width: 100%;
        padding: 0.68rem 0.78rem 0.78rem;
    }

    .session-panel .session-action {
        min-height: 2.65rem;
        gap: 0.25rem;
        padding: 0.38rem 0.32rem;
    }

    .session-panel .session-action__label {
        font-size: 0.48rem;
        letter-spacing: 0.04em;
    }

    .session-panel .session-action__icon {
        width: 1.55rem;
        height: 1.55rem;
        font-size: 0.62rem;
    }

    .chat-drawer .drawer-composer {
        gap: 0.45rem;
        width: 100%;
        max-width: 100%;
        grid-template-columns: minmax(0, 1fr) 2.8rem;
        padding: 0;
    }

    .chat-drawer .consultation-input {
        height: 2.8rem;
        min-height: 2.8rem;
        padding-inline: 0.9rem;
        line-height: 2.8rem;
    }

    .session-panel .session-toggle-button {
        min-height: 2.5rem;
        font-size: 0.56rem;
        letter-spacing: 0.05em;
    }
}

/* Ameya call shell: keep dark minimal navbar (override generic "Navbar Enhancement" above) */
body.app-body--call .app-header .navbar {
    background: rgba(28, 28, 30, 0.92) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35) !important;
}
body.app-body--call .app-header .navbar-brand {
    color: #f5f5f7 !important;
}
body.app-body--call .app-header .navbar-version {
    color: rgba(255, 255, 255, 0.55) !important;
    font-size: 0.75rem;
}
