/* ── MSK Triage Assistant — Consumer Health-Tech UI ──────────────────────────
   Design tokens first; everything else derives from them. */

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

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
    color-scheme: dark;

    /* Color — neutrals */
    --canvas: #0f1519;
    --surface: #171f26;
    --surface-2: #1f2a33;
    --ink: #e8eef2;
    --ink-2: #a7b6c2;
    --ink-3: #73838f;
    --line: #29343e;
    --line-soft: #222c35;

    /* Color — brand (calm clinical teal) */
    --brand: #17897c;
    --brand-strong: #1ca293;
    --brand-ink: #7bd8cb;
    --brand-soft: #14302d;
    --brand-line: #23514a;
    --focus-ring: rgba(43, 178, 162, 0.35);

    /* Color — user message */
    --user-bubble: #1d4a44;

    /* Color — status */
    --green: #62cf95;
    --green-bg: #142a1e;
    --green-line: #234a34;
    --amber: #e2a55e;
    --amber-bg: #2c2113;
    --amber-line: #4d3b1f;
    --red: #e57d75;
    --red-bg: #301a17;
    --red-line: #56302b;

    /* Typography */
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --fs-xs: 0.72rem;
    --fs-sm: 0.8rem;
    --fs-md: 0.9rem;
    --fs-body: 0.94rem;

    /* Radius */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-full: 999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

    /* Spacing rhythm */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    /* Layout */
    --content-width: 780px;
    --sidebar-width: 272px;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--canvas);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow: hidden;
}

body {
    display: flex;
    height: 100vh;
}

button {
    font-family: inherit;
}

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
    z-index: 60;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1rem 1rem 0.85rem;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    border-radius: var(--r-sm);
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-xs);
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.brand-name {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.brand-tag {
    font-size: 0.68rem;
    color: var(--ink-3);
    margin-top: 1px;
}

.sidebar-collapse {
    border: none;
    background: transparent;
    color: var(--ink-3);
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.sidebar-collapse:hover {
    background: var(--surface-2);
    color: var(--ink-2);
}

.sidebar-top {
    padding: 0 0.85rem 0.85rem;
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.62rem 0.85rem;
    background: var(--brand);
    border: 1px solid var(--brand);
    border-radius: var(--r-md);
    color: #fff;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow-xs);
}

.new-chat-btn:hover {
    background: var(--brand-strong);
}

.sidebar-section-label {
    padding: 0.25rem 1.1rem 0.35rem;
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
}

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.6rem;
}

.sidebar-empty {
    color: var(--ink-3);
    font-size: 0.76rem;
    line-height: 1.5;
    padding: 0.75rem 0.5rem;
}

.sidebar-chat-item {
    display: block;
    width: 100%;
    padding: 0.55rem 0.7rem;
    background: none;
    border: none;
    border-radius: var(--r-sm);
    color: var(--ink-2);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-chat-item:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.sidebar-bottom {
    padding: 0.85rem;
    border-top: 1px solid var(--line-soft);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
}

.sidebar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-email {
    flex: 1;
    color: var(--ink-2);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    background: none;
    border: none;
    color: var(--ink-3);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
}

.sidebar-logout:hover {
    color: var(--ink);
    background: var(--surface-2);
}

.sidebar-signin {
    width: 100%;
    padding: 0.55rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    color: var(--ink-2);
    font-size: 0.76rem;
    cursor: pointer;
    transition: background 0.15s;
}

.sidebar-signin:hover {
    background: var(--line-soft);
}

.sidebar-guest-note {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--r-md);
    background: var(--brand-soft);
    border: 1px solid var(--brand-line);
    color: var(--brand-ink);
    font-size: 0.7rem;
    line-height: 1.45;
}

.sidebar-guest-note svg {
    flex-shrink: 0;
    margin-top: 1px;
}

/* Toggle + scrim */
.sidebar-toggle {
    position: fixed;
    top: 0.7rem;
    left: 0.7rem;
    z-index: 85;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
    width: 38px;
    height: 38px;
    border-radius: var(--r-md);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s;
}

.sidebar-toggle:hover {
    background: var(--surface-2);
}

.sidebar.collapsed~.sidebar-toggle {
    display: flex;
}

.sidebar-scrim {
    display: none;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    background: var(--canvas);
    position: relative;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    min-width: 0;
}

.header-title h1 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--ink);
    white-space: nowrap;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.24rem 0.6rem;
    border-radius: var(--r-full);
    background: var(--brand-soft);
    border: 1px solid var(--brand-line);
    color: var(--brand-ink);
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.evidence-pill {
    font-size: 0.7rem;
    color: var(--ink-3);
    white-space: nowrap;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.68rem;
    font-weight: 500;
    padding: 0.3rem 0.65rem;
    border-radius: var(--r-full);
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink-2);
    white-space: nowrap;
}

.conn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #3ddc97;
    box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.18);
}

/* ── Chat area ─────────────────────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

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

.chat-area::-webkit-scrollbar-thumb {
    background: #37444f;
    border-radius: var(--r-full);
}

/* ── Welcome / hero ────────────────────────────────────────────────────────── */
.welcome {
    width: 100%;
    max-width: var(--content-width);
    display: flex;
    flex-direction: column;
    gap: 2.25rem;
    padding: 1.5rem 0 1rem;
    animation: welcomeIn 0.5s ease;
}

.welcome.hidden {
    display: none;
}

@keyframes welcomeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.85rem;
    padding: 1rem 0 0.25rem;
}

.hero-eyebrow {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand);
}

.hero h2 {
    font-size: clamp(1.55rem, 3.4vw, 2.15rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--ink);
    max-width: 560px;
}

.hero-sub {
    font-size: 0.92rem;
    color: var(--ink-2);
    line-height: 1.65;
    max-width: 580px;
}

.hero-trust {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.trust-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.32rem 0.75rem;
    border-radius: var(--r-full);
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
    font-size: 0.74rem;
    font-weight: 500;
    box-shadow: var(--shadow-xs);
}

.trust-item svg {
    color: var(--brand);
    flex-shrink: 0;
}

/* Region shortcuts */
.region-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7rem;
}

.region-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
}

.region-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    max-width: 620px;
}

.region-chip {
    padding: 0.42rem 0.9rem;
    border-radius: var(--r-full);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow-xs);
}

.region-chip:hover {
    border-color: var(--brand-line);
    background: var(--brand-soft);
    color: var(--brand-ink);
}

/* Topics library */
.topics-library {
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--line-soft);
}

.topics-head {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding-top: 0.75rem;
}

.topics-heading {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.topics-sub {
    font-size: 0.78rem;
    color: var(--ink-3);
}

.topic-category {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.category-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
}

.scenario-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.scenario-chip {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 0.95rem;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
    box-shadow: var(--shadow-xs);
}

.scenario-chip:hover {
    border-color: var(--brand-line);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.scenario-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    background: var(--brand-soft);
    color: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s;
}

.scenario-text {
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
    min-width: 0;
}

.scenario-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.005em;
}

.scenario-desc {
    font-size: 0.72rem;
    color: var(--ink-3);
    line-height: 1.45;
}

/* ── Messages ──────────────────────────────────────────────────────────────── */
.message {
    display: flex;
    gap: 0.7rem;
    width: 100%;
    max-width: var(--content-width);
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

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

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

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--user-bubble);
    color: #fff;
}

.message.assistant .message-avatar {
    background: var(--brand-soft);
    color: var(--brand);
    border: 1px solid var(--brand-line);
}

.message-bubble {
    padding: 0.8rem 1.05rem;
    border-radius: var(--r-lg);
    line-height: 1.65;
    font-size: var(--fs-body);
    word-wrap: break-word;
    min-width: 0;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    color: #f2f6f9;
    border-bottom-right-radius: 6px;
    max-width: 78%;
    margin-left: auto;
    box-shadow: var(--shadow-sm);
}

.message.assistant .message-bubble {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
    flex: 1;
    box-shadow: var(--shadow-sm);
}

/* Markdown */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 0.85rem 0 0.3rem 0;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.message-bubble h1 {
    font-size: 1.08rem;
}

.message-bubble h2 {
    font-size: 1rem;
}

.message-bubble h3 {
    font-size: 0.92rem;
}

.message-bubble p {
    margin: 0.4rem 0;
}

.message-bubble p:first-child {
    margin-top: 0;
}

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

.message-bubble ul,
.message-bubble ol {
    padding-left: 1.2rem;
    margin: 0.4rem 0;
}

.message-bubble li {
    margin: 0.22rem 0;
}

.message-bubble strong {
    font-weight: 600;
    color: var(--ink);
}

.message-bubble code {
    background: var(--brand-soft);
    padding: 0.12rem 0.32rem;
    border-radius: 4px;
    font-size: 0.83em;
    font-family: 'SF Mono', Consolas, monospace;
    color: var(--brand-ink);
}

.message-bubble pre {
    background: var(--brand-soft);
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    margin: 0.5rem 0;
    overflow-x: auto;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble blockquote {
    border-left: 3px solid var(--line);
    margin: 0.5rem 0;
    padding: 0.1rem 0 0.1rem 0.75rem;
    color: var(--ink-soft, var(--ink));
}

.message-bubble table {
    border-collapse: collapse;
    margin: 0.6rem 0;
    width: 100%;
    display: block;
    overflow-x: auto;
    font-size: 0.88em;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--line);
    padding: 0.35rem 0.55rem;
    text-align: left;
    vertical-align: top;
}

.message-bubble th {
    background: var(--brand-soft);
    font-weight: 600;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--line);
    margin: 0.75rem 0;
}

/* ── Typing indicator ──────────────────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 6px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--brand);
    border-radius: 50%;
    animation: typeDot 1.4s ease-in-out infinite;
}

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

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

@keyframes typeDot {

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

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

/* ── Evidence drawers (Sources / Evidence used / Mechanism graph) ──────────── */
.citations {
    margin-top: 0.8rem;
    border-top: none;
    padding-top: 0;
}

.source-details {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--canvas);
    overflow: hidden;
}

.source-details summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    padding: 0.55rem 0.8rem;
    color: var(--ink-2);
    font-size: 0.74rem;
    font-weight: 600;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}

.source-details summary::-webkit-details-marker {
    display: none;
}

.source-details summary::before {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 1.8px solid currentColor;
    border-bottom: 1.8px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.18s ease;
    flex-shrink: 0;
    margin-left: 1px;
}

.source-details[open] summary::before {
    transform: rotate(45deg) translateY(-2px);
}

.source-details summary:hover {
    color: var(--brand-ink);
    background: var(--brand-soft);
}

.source-details[open] summary {
    border-bottom: 1px solid var(--line-soft);
}

.source-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.6rem 0.8rem 0.75rem;
    margin-top: 0;
}

.source-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
    background: var(--surface);
}

.source-path {
    color: var(--brand-ink);
    font-size: 0.72rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.source-section {
    color: var(--ink-2);
    font-size: 0.7rem;
    line-height: 1.5;
}

/* ── Telemetry ("Why this answer?") ────────────────────────────────────────── */
.telemetry-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.65rem;
    padding: 0.28rem 0.65rem;
    border-radius: var(--r-full);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-3);
    font-size: 0.68rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.telemetry-toggle:hover {
    color: var(--brand-ink);
    border-color: var(--brand-line);
    background: var(--brand-soft);
}

.telemetry-panel {
    display: none;
    margin-top: 0.5rem;
    padding: 0.7rem 0.85rem;
    border-radius: var(--r-md);
    background: var(--canvas);
    border: 1px solid var(--line);
    font-size: 0.7rem;
    color: var(--ink-2);
}

.telemetry-panel.open {
    display: block;
    animation: msgIn 0.2s ease;
}

.telemetry-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.4rem;
}

.stat-badge {
    display: inline-block;
    padding: 0.16rem 0.5rem;
    border-radius: var(--r-full);
    font-size: 0.66rem;
    font-weight: 500;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
}

.stat-badge.confidence-high {
    border-color: var(--green-line);
    color: var(--green);
    background: var(--green-bg);
}

.stat-badge.confidence-mid {
    border-color: var(--amber-line);
    color: var(--amber);
    background: var(--amber-bg);
}

.stat-badge.confidence-low {
    border-color: var(--red-line);
    color: var(--red);
    background: var(--red-bg);
}

/* Degraded / fallback mode (BM25-only retrieval, evidence-only or free-provider
   generation). Amber to signal "working, but not the full-quality path". */
.stat-badge.mode-degraded {
    border-color: var(--amber-line);
    color: var(--amber);
    background: var(--amber-bg);
}

.telemetry-detail {
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--line-soft);
    font-size: 0.68rem;
    color: var(--ink-3);
    line-height: 1.6;
}

.telemetry-detail strong {
    color: var(--ink-2);
    font-weight: 600;
}

/* ── Feedback (local-only) ─────────────────────────────────────────────────── */
.feedback-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line-soft);
}

.feedback-label {
    color: var(--ink-3);
    font-size: 0.68rem;
    font-weight: 600;
}

.feedback-btn {
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    font-size: 0.66rem;
    font-weight: 500;
    padding: 0.22rem 0.6rem;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.feedback-btn:hover,
.feedback-btn.selected {
    border-color: var(--brand-line);
    background: var(--brand-soft);
    color: var(--brand-ink);
}

.mechanics-runtime-note {
    margin-top: 0.55rem;
    color: var(--ink-3);
    font-size: 0.68rem;
}

/* ── Input area / composer ─────────────────────────────────────────────────── */
.input-area {
    padding: 0.5rem 1.25rem 0.7rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: var(--canvas);
}

.composer {
    width: 100%;
    max-width: var(--content-width);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    padding: 0.75rem 0.9rem 0.6rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.composer:focus-within {
    border-color: var(--brand-line);
    box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow-md);
}

.composer textarea {
    display: block;
    width: 100%;
    resize: none;
    min-height: 26px;
    max-height: 120px;
    padding: 0.15rem 0.1rem;
    border: none;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 0.94rem;
    line-height: 1.55;
    outline: none;
}

.composer textarea::placeholder {
    color: var(--ink-3);
}

.composer-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--line-soft);
}

/* Generation model picker */
.model-picker {
    margin-left: auto;   /* groups the picker + key btn + send to the right */
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--ink-2);
    white-space: nowrap;
}

.model-picker-label { color: var(--ink-2); }

#model-select {
    max-width: 12rem;
    padding: 0.26rem 0.5rem;
    font-size: 0.72rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    cursor: pointer;
}

#model-select:hover { border-color: var(--line-strong, var(--line)); }

.model-custom {
    width: 9rem;
    padding: 0.26rem 0.5rem;
    font-size: 0.72rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
}

/* Bring-your-own-key controls */
.key-btn {
    padding: 0.28rem 0.6rem;
    font-size: 0.72rem;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    cursor: pointer;
    white-space: nowrap;
}

.key-btn:hover { color: var(--ink); border-color: var(--line-strong, var(--line)); }
.key-btn.key-active { color: var(--green); border-color: var(--green-line); background: var(--green-bg); }

.key-panel {
    margin-bottom: 0.6rem;
    padding: 0.7rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md, 10px);
}

.key-panel-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.key-panel-row input[type="password"] {
    flex: 1 1 220px;
    min-width: 0;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--bg, var(--surface));
    border: 1px solid var(--line);
    border-radius: var(--r-sm, 8px);
}

.key-action {
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
    color: var(--ink);
    background: var(--accent-bg, var(--surface));
    border: 1px solid var(--line);
    border-radius: var(--r-sm, 8px);
    cursor: pointer;
}

.key-action-ghost { color: var(--ink-2); }
.key-action:hover { border-color: var(--green-line); }

/* Interruption notice appended below a partially-streamed answer. Must read as a
   warning, not as part of the clinical content above it. */
.stream-error {
    margin-top: 0.75rem;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    color: var(--ink);
    background: rgba(180, 83, 9, 0.10);
    border: 1px solid rgba(180, 83, 9, 0.45);
    border-radius: var(--r-sm, 8px);
}

.stream-error small { color: var(--ink-2); }

.key-remember {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    font-size: 0.76rem;
    color: var(--ink-2);
    cursor: pointer;
}

.key-disclaimer {
    margin: 0.5rem 0 0;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--ink-3, var(--ink-2));
}

.key-status {
    margin: 0.4rem 0 0;
    font-size: 0.74rem;
    color: var(--green);
    min-height: 1em;
}

/* Mechanics Study — real mode switch */
.mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.mode-toggle input {
    appearance: none;
    -webkit-appearance: none;
    width: 34px;
    height: 20px;
    border-radius: var(--r-full);
    background: #3a4854;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    margin: 0;
}

.mode-toggle input::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(20, 34, 47, 0.25);
    transition: transform 0.2s ease;
}

.mode-toggle input:checked {
    background: var(--brand);
}

.mode-toggle input:checked::after {
    transform: translateX(14px);
}

.mode-toggle input:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.mode-name {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ink-2);
}

.mode-toggle input:checked~.mode-name {
    color: var(--brand-ink);
}

.mode-hint {
    color: var(--ink-3);
    font-size: 0.7rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
    margin-left: auto;
    box-shadow: var(--shadow-xs);
}

.send-btn:hover:not(:disabled) {
    background: var(--brand-strong);
    transform: scale(1.04);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

/* Safety note — visible, calm fine print */
.safety-note {
    width: 100%;
    max-width: var(--content-width);
    font-size: 0.68rem;
    line-height: 1.5;
    color: var(--ink-3);
    text-align: center;
    padding: 0 0.5rem;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
.footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 1.5rem;
    font-size: 0.63rem;
    color: var(--ink-3);
    border-top: 1px solid var(--line-soft);
    background: var(--canvas);
}

/* ── Auth modal (guest-only) ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 2rem;
    width: 90%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.modal-sub {
    font-size: 0.8rem;
    color: var(--ink-3);
    margin-bottom: 1.25rem;
}

.google-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.65rem;
    border-radius: var(--r-md);
    border: 1.5px solid var(--line);
    background: var(--surface);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.google-btn:hover {
    border-color: #4285F4;
    background: var(--surface-2);
}

.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    color: var(--ink-3);
    font-size: 0.72rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#auth-form input {
    padding: 0.6rem 0.75rem;
    border-radius: var(--r-sm);
    border: 1.5px solid var(--line);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
    color: var(--ink);
}

#auth-form input:focus {
    border-color: var(--brand);
}

.auth-submit {
    padding: 0.65rem;
    border-radius: var(--r-md);
    border: none;
    background: var(--brand);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 0.25rem;
}

.auth-submit:hover {
    background: var(--brand-strong);
}

.auth-error {
    color: var(--red);
    font-size: 0.78rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

.auth-switch {
    font-size: 0.78rem;
    color: var(--ink-3);
    margin-top: 0.75rem;
    text-align: center;
}

.auth-switch a {
    color: var(--brand);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.skip-btn {
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--r-sm);
    border: none;
    background: transparent;
    color: var(--ink-3);
    font-size: 0.75rem;
    cursor: pointer;
    transition: color 0.15s;
}

.skip-btn:hover {
    color: var(--ink-2);
}

/* ── Reduced motion ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .chat-area {
        scroll-behavior: auto;
    }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 90;
        box-shadow: var(--shadow-lg);
    }

    .sidebar-toggle,
    .sidebar~.sidebar-toggle {
        display: flex;
    }

    .sidebar:not(.collapsed)~.sidebar-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 80;
        background: rgba(0, 0, 0, 0.55);
        animation: fadeIn 0.2s ease;
    }

    .header {
        padding: 0.65rem 1rem 0.65rem 3.6rem;
    }

    .header-title h1 {
        font-size: 0.92rem;
    }

    .evidence-pill {
        display: none;
    }

    .chat-area {
        padding: 1rem 0.85rem 0.75rem;
    }

    .welcome {
        gap: 1.75rem;
        padding-top: 0.75rem;
    }

    .hero h2 {
        font-size: 1.45rem;
    }

    .hero-sub {
        font-size: 0.86rem;
    }

    .scenario-chips {
        grid-template-columns: 1fr;
    }

    .message.user .message-bubble {
        max-width: 88%;
    }

    .input-area {
        padding: 0.4rem 0.75rem 0.55rem;
    }

    .composer {
        border-radius: var(--r-lg);
        padding: 0.6rem 0.7rem 0.5rem;
    }

    .mode-hint {
        display: none;
    }

    .safety-note {
        font-size: 0.64rem;
        text-align: left;
    }

    .footer-bar {
        padding: 0.3rem 0.85rem;
    }

    .modal {
        width: 95%;
        padding: 1.5rem;
    }
}
