:root {
    --bg: #f4f1ea;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-strong: #ffffff;
    --surface-muted: #f7f4ef;
    --text: #1c1b18;
    --text-soft: #60584d;
    --border: rgba(72, 57, 37, 0.12);
    --accent: #8b2332;
    --accent-strong: #6c1322;
    --accent-soft: rgba(139, 35, 50, 0.1);
    --bg-gradient:
        radial-gradient(circle at top left, rgba(139, 35, 50, 0.14), transparent 30%),
        radial-gradient(circle at bottom right, rgba(183, 135, 66, 0.14), transparent 25%),
        linear-gradient(180deg, #efe7dc 0%, #f7f3ec 50%, #ede7df 100%);
    --header-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 244, 239, 0.86));
    --composer-surface: rgba(255, 255, 255, 0.92);
    --notice-error-bg: rgba(159, 36, 53, 0.08);
    --notice-error-border: rgba(159, 36, 53, 0.18);
    --notice-info-border: rgba(139, 35, 50, 0.15);
    --toggle-track: rgba(28, 27, 24, 0.14);
    --toggle-track-active: rgba(216, 109, 123, 0.4);
    --toggle-thumb-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    --inline-code-bg: rgba(28, 27, 24, 0.08);
    --user-code-bg: rgba(255, 255, 255, 0.18);
    --link: #1a56a4;
    --success: #1f6b46;
    --error: #9f2435;
    --shadow: 0 22px 60px rgba(53, 40, 24, 0.12);
    --radius-lg: 28px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --max-width: 1180px;
    --sidebar-width: 300px;
    --sidebar-collapsed-width: 52px;
    --font-display: "Georgia", "Times New Roman", serif;
    --font-body: "Segoe UI", "Helvetica Neue", sans-serif;
}

body[data-theme="dark"] {
    --bg: #171716;
    --surface: rgba(30, 31, 32, 0.9);
    --surface-strong: #222426;
    --surface-muted: #2b2e31;
    --text: #f1ede5;
    --text-soft: #b9b1a3;
    --border: rgba(241, 237, 229, 0.12);
    --accent: #d86d7b;
    --accent-strong: #f08d9a;
    --accent-soft: rgba(216, 109, 123, 0.16);
    --bg-gradient:
        radial-gradient(circle at top left, rgba(216, 109, 123, 0.14), transparent 28%),
        radial-gradient(circle at bottom right, rgba(87, 118, 160, 0.14), transparent 22%),
        linear-gradient(180deg, #111214 0%, #16181b 55%, #111315 100%);
    --header-surface: linear-gradient(180deg, rgba(34, 36, 38, 0.98), rgba(28, 30, 32, 0.92));
    --composer-surface: rgba(34, 36, 38, 0.94);
    --notice-error-bg: rgba(255, 139, 152, 0.12);
    --notice-error-border: rgba(255, 139, 152, 0.22);
    --notice-info-border: rgba(216, 109, 123, 0.2);
    --toggle-track: rgba(241, 237, 229, 0.14);
    --toggle-track-active: rgba(216, 109, 123, 0.4);
    --toggle-thumb-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    --inline-code-bg: rgba(241, 237, 229, 0.1);
    --user-code-bg: rgba(255, 255, 255, 0.18);
    --link: #7bb3f0;
    --success: #5bb886;
    --error: #ff8b98;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-gradient);
    color: var(--text);
    font-family: var(--font-body);
}

/* ─── App shell: full-viewport flex ─────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
    width: 100%;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    flex-shrink: 0;
    overflow: hidden;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 24px rgba(53, 40, 24, 0.08);
    backdrop-filter: blur(16px);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

body[data-theme="dark"] .sidebar {
    box-shadow: 2px 0 24px rgba(0, 0, 0, 0.22);
}

.sidebar.is-collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Hide body content when collapsed — only the collapse button stays visible */
#sidebar-conversations,
.sidebar-panel-session,
#sidebar-brand,
.sidebar-settings-btn {
    transition: opacity 0.2s ease;
}

.sidebar.is-collapsed #sidebar-conversations,
.sidebar.is-collapsed .sidebar-panel-session,
.sidebar.is-collapsed #sidebar-brand,
.sidebar.is-collapsed .sidebar-settings-btn {
    opacity: 0;
    pointer-events: none;
}

/* ─── Flip animation ─────────────────────────────────────────────────────── */
.sidebar-perspective {
    flex: 1;
    min-height: 0;
    perspective: 1400px;
    overflow: hidden;
}

.sidebar-flipper {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-flipper.is-flipped {
    transform: rotateY(180deg);
}

.sidebar-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Fixed width so content doesn't reflow during collapse animation */
    width: var(--sidebar-width);
    /* Solid background prevents content from showing through during flip */
    background: var(--surface-strong);
}

.sidebar-back {
    transform: rotateY(180deg);
}

/* ─── Sidebar top bar ─────────────────────────────────────────────────────── */
.sidebar-top-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 10px 8px;
    flex-shrink: 0;
}

.sidebar-icon-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background 120ms ease, color 120ms ease;
}

.sidebar-icon-btn:hover {
    background: var(--surface-muted);
    color: var(--text);
}

#sidebar-brand {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
}

.sidebar-collapse-icon {
    transition: transform 0.3s ease;
}

.sidebar.is-collapsed .sidebar-collapse-icon {
    transform: rotate(180deg);
}

.sidebar-settings-title {
    flex: 1;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
    padding-left: 4px;
}

/* ─── Sidebar panels ─────────────────────────────────────────────────────── */
.sidebar-panel {
    padding: 0;
    background: transparent;
    border: none;
}

#sidebar-conversations {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0 8px;
}

.sidebar-panel-session {
    flex-shrink: 0;
    padding: 2px 10px 8px;
    border-top: 1px solid var(--border);
}

/* ─── Brand ──────────────────────────────────────────────────────────────── */
.brand-home {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
}

.brand-home img {
    display: block;
    max-height: 32px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.brand-home-copy p {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Settings panel ─────────────────────────────────────────────────────── */
.sidebar-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-group {
    padding: 10px 4px 6px;
    border-bottom: 1px solid var(--border);
}

.settings-group:last-child {
    border-bottom: none;
}

.settings-label {
    margin: 0 0 10px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.settings-hint {
    margin: 8px 0 0;
    font-size: 0.78rem;
    color: var(--text-soft);
    line-height: 1.4;
}

/* ─── Segment control ────────────────────────────────────────────────────── */
.segment-control {
    display: flex;
    gap: 4px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.segment-btn {
    flex: 1;
    padding: 7px 10px;
    border: none;
    border-radius: calc(var(--radius-sm) - 3px);
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
    white-space: nowrap;
}

.segment-btn:hover:not(.is-active) {
    color: var(--text);
    background: rgba(255, 255, 255, 0.4);
}

body[data-theme="dark"] .segment-btn:hover:not(.is-active) {
    background: rgba(255, 255, 255, 0.08);
}

.segment-btn.is-active {
    background: var(--surface-strong);
    color: var(--text);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}

body[data-theme="dark"] .segment-btn.is-active {
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

/* ─── Main panel ─────────────────────────────────────────────────────────── */
.main-panel {
    flex: 1;
    min-width: 0;
    padding: 24px;
    min-height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen.hidden,
.hidden {
    display: none;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.content-card,
.hero-card,
.chat-layout {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.hero-card,
.content-card,
.chat-layout {
    border-radius: var(--radius-lg);
}

.hero-card,
.content-card {
    padding: 56px 64px;
    width: 100%;
}

.hero-card {
    flex: 1;
    min-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.content-card {
    max-width: 900px;
    align-self: flex-start;
}

.card-header {
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 0.78rem;
    color: var(--text-soft);
}

h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(2.1rem, 4vw, 3.5rem);
    line-height: 1.02;
}

.lead {
    margin: 18px 0 0;
    max-width: 64ch;
    color: var(--text-soft);
    font-size: 1.02rem;
    line-height: 1.65;
}

.field {
    display: grid;
    gap: 10px;
    font-weight: 600;
    margin-top: 18px;
    max-width: 480px;
}

select,
textarea,
.button {
    font: inherit;
}

select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    background: var(--surface-strong);
    color: var(--text);
}

textarea {
    resize: vertical;
    min-height: 56px;
    max-height: 180px;
}

.actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
}

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

.button.primary {
    background: var(--accent);
    color: #fff;
}

.button.primary:hover {
    background: var(--accent-strong);
}

.button.secondary {
    background: var(--surface-muted);
    color: var(--text);
    border: 1px solid var(--border);
}

.button.compact {
    padding: 8px 14px;
}

.button:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
}

.notice {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.notice.error {
    background: var(--notice-error-bg);
    border-color: var(--notice-error-border);
    color: var(--error);
}

.notice.info {
    background: var(--accent-soft);
    border-color: var(--notice-info-border);
}

/* ─── Theme toggle (used in chat popover + settings) ─────────────────────── */
.theme-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    transition: background 120ms ease;
}

.theme-toggle:hover {
    background: var(--surface-muted);
}

.icon-button {
    min-width: 48px;
    padding-inline: 14px;
}

.theme-toggle-track {
    width: 52px;
    height: 30px;
    padding: 3px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: var(--toggle-track);
    transition: background 140ms ease;
    flex-shrink: 0;
}

.theme-toggle-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface-strong);
    box-shadow: var(--toggle-thumb-shadow);
    transition: transform 140ms ease;
}

.theme-toggle.is-active .theme-toggle-track {
    background: var(--toggle-track-active);
}

.theme-toggle.is-active .theme-toggle-thumb {
    transform: translateX(22px);
}

/* ─── Sidebar text labels ─────────────────────────────────────────────────── */
.meta-label {
    margin: 0 0 6px;
    font-size: 0.76rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.meta-value {
    margin: 0;
    font-size: 0.95rem;
    word-break: break-word;
}

.session-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.session-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-soft);
    font-size: 0.83rem;
    min-width: 0;
}

.button-link {
    background: none;
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    padding: 0;
    white-space: nowrap;
    font: inherit;
    font-size: 0.82rem;
    text-decoration: underline;
    flex-shrink: 0;
}

.button-link:hover {
    color: var(--text);
}

.nav-section-label {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-soft);
}

.sidebar-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 6px 4px;
    margin-bottom: 0;
}

/* ─── Conversation list ───────────────────────────────────────────────────── */
.sidebar-conversations {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: none;
    flex: 1;
    min-height: 0;
}

.conversation-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow-y: auto;
    padding-right: 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 2px;
    padding-right: 4px;
}

.conversation-link {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 10px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text);
    transition: background 120ms ease;
}

.conversation-link:hover {
    background: var(--surface-muted);
}

.conversation-item.is-active .conversation-link {
    background: var(--accent-soft);
}

.conversation-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-menu-trigger {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 1rem;
    line-height: 1;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, background 120ms ease;
}

.conversation-item:hover .conversation-menu-trigger,
.conversation-menu-trigger:focus-visible,
.conversation-menu-trigger[aria-expanded="true"] {
    opacity: 1;
    pointer-events: auto;
}

.conversation-menu-trigger:hover,
.conversation-menu-trigger[aria-expanded="true"] {
    background: var(--border);
}

.conversation-title {
    font-weight: 400;
    font-size: 0.9rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    display: none;
}

.conversation-menu {
    position: fixed;
    min-width: 188px;
    padding: 8px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    box-shadow: var(--shadow);
    display: grid;
    gap: 4px;
    z-index: 9999;
}

.conversation-menu.hidden {
    display: none;
}

.conversation-menu-item {
    width: 100%;
    padding: 13px 16px;
    text-align: left;
    cursor: pointer;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    border-radius: 16px;
}

.conversation-menu-item:hover {
    background: var(--accent-soft);
}

.conversation-menu-item.danger {
    color: #ff7f8b;
}

/* ─── Chat layout ─────────────────────────────────────────────────────────── */
.chat-layout {
    flex: 1;
    min-height: calc(100vh - 48px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
}

.chat-header {
    padding: 28px 48px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--header-surface);
}

.chat-subtitle {
    margin-top: 10px;
}

.messages {
    padding: 24px 48px;
    overflow-y: auto;
    display: grid;
    gap: 16px;
    align-items: start;
}

.message {
    width: fit-content;
    max-width: min(86%, 780px);
    padding: 16px 18px;
    border-radius: 22px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    justify-self: start;
}

.message.user {
    justify-self: end;
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.message.user a {
    color: #fff;
}

.message-body a,
.prose a {
    color: var(--link);
    overflow-wrap: break-word;
    word-break: break-word;
}

.message.assistant {
    justify-self: start;
}

.message-feedback {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}

.feedback-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px 8px;
    font-size: 0.95rem;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s;
}

.feedback-btn:hover:not(:disabled) {
    opacity: 1;
    background: var(--surface-strong);
}

.feedback-btn.feedback-selected {
    opacity: 1;
    background: var(--surface-strong);
}

.feedback-btn:disabled {
    cursor: default;
}

.message-role {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.message.user .message-role {
    color: rgba(255, 255, 255, 0.76);
}

.message-timestamp {
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    text-transform: none;
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
}

.message:hover .message-timestamp {
    opacity: 1;
}

/* ─── Composer ────────────────────────────────────────────────────────────── */
.composer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px 48px 28px;
    border-top: 1px solid var(--border);
    background: var(--composer-surface);
}

.composer-input-wrap {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 5px 5px 5px 10px;
    border: 1px solid var(--border);
    border-radius: 26px;
    background: var(--surface-strong);
    transition: border-color 140ms ease;
}

.composer-input-wrap:focus-within {
    border-color: var(--accent);
}

.composer-menu {
    position: relative;
    flex-shrink: 0;
    margin-bottom: 3px;
}

.composer-menu-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0;
    transition: color 140ms ease;
}

.composer-menu-btn:hover {
    color: var(--text);
}

.composer-input-wrap textarea {
    flex: 1;
    border: none;
    background: transparent;
    border-radius: 0;
    padding: 7px 20px 7px 8px;
    margin-right: 15px;
    min-height: 36px;
    max-height: 180px;
    resize: none;
    outline: none;
    box-shadow: none;
    color: var(--text);
}

.composer-input-wrap textarea::-webkit-scrollbar {
    width: 5px;
}

.composer-input-wrap textarea::-webkit-scrollbar-track {
    background: transparent;
    margin-bottom: 44px;
    margin-top: 4px;
}

.composer-input-wrap textarea::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.composer-send-btn {
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 140ms ease, opacity 140ms ease;
}

.composer-send-btn:hover {
    background: var(--accent-strong);
}

.composer-send-btn:disabled {
    opacity: 0.35;
    cursor: wait;
}

.composer-popover {
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    min-width: 210px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-strong);
    box-shadow: var(--shadow);
    z-index: 10;
}

.popover-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text);
}

.popover-toggle input {
    width: 18px;
    height: 18px;
}

/* ─── Suggested prompts ───────────────────────────────────────────────────── */
.suggested-prompts {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.suggested-prompts:empty {
    display: none;
}

.suggested-prompt-btn {
    background: var(--accent-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font: inherit;
    font-size: 0.83rem;
    color: var(--text);
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease;
    text-align: left;
}

.suggested-prompt-btn:hover {
    background: var(--surface-muted);
    border-color: var(--accent);
}

/* ─── Prose & message body ────────────────────────────────────────────────── */
.prose,
.message-body {
    line-height: 1.7;
    overflow-wrap: break-word;
    word-break: break-word;
}

.prose p:first-child,
.message-body p:first-child {
    margin-top: 0;
}

.prose p:last-child,
.message-body p:last-child {
    margin-bottom: 0;
}

.prose code,
.message-body code {
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    background: var(--inline-code-bg);
    font-size: 0.92em;
}

/* ─── Thinking animation ──────────────────────────────────────────────────── */
.thinking-indicator {
    color: var(--text-soft);
    font-style: italic;
    white-space: nowrap;
}

@keyframes thinking-dots {
    0%   { content: "."; }
    33%  { content: ".."; }
    66%  { content: "..."; }
    100% { content: "."; }
}

.thinking-dots::after {
    content: ".";
    animation: thinking-dots 1.2s steps(1, end) infinite;
    display: inline-block;
    width: 1.4ch;
    text-align: left;
}

.message.user .message-body code {
    background: var(--user-code-bg);
}

/* ─── Rename modal ────────────────────────────────────────────────────────── */
.rename-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
}

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

.rename-modal-box {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    padding: 28px 28px 24px;
    width: min(400px, calc(100vw - 40px));
    display: grid;
    gap: 16px;
}

.rename-modal-heading {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    font-family: var(--font-display);
}

.rename-modal-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1rem;
    outline: none;
    transition: border-color 150ms ease;
    box-sizing: border-box;
}

.rename-modal-input:focus {
    border-color: var(--accent);
}

.rename-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ─── Mobile sidebar backdrop ─────────────────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(2px);
    z-index: 999;
    animation: backdrop-in 0.2s ease forwards;
}

.sidebar-backdrop.is-visible {
    display: block;
}

@keyframes backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Mobile hamburger button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1002;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: transparent;
    box-shadow: none;
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: opacity 150ms ease;
}

.mobile-menu-btn:hover {
    opacity: 0.7;
}

/* Hide hamburger while the sidebar drawer is open */
body.mobile-sidebar-open .mobile-menu-btn {
    opacity: 0;
    pointer-events: none;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

/* Tablet: tighten padding, keep sidebar visible */
@media (max-width: 980px) {
    .main-panel {
        padding: 16px;
    }

    .chat-header {
        padding: 20px 24px 16px;
    }

    .messages {
        padding: 20px 24px;
    }

    .composer {
        padding: 16px 24px 20px;
    }

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

/* Mobile: full-screen content, sidebar as overlay drawer */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }

    body,
    .app-shell {
        min-height: 100dvh;
    }

    /* Sidebar becomes a fixed overlay drawer */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh !important;
        height: 100dvh !important;
        width: var(--sidebar-width) !important;
        transform: translateX(calc(-1 * var(--sidebar-width)));
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 1000;
        border-right: 1px solid var(--border);
    }

    .sidebar.is-mobile-open {
        transform: translateX(0) !important;
    }

    /* Main panel fills entire viewport */
    .main-panel {
        width: 100%;
        min-width: 0;
        padding: 0;
        min-height: 100vh;
        min-height: 100dvh;
    }

    /* ── Fix 2: give the chat layout a definite height so the grid
       rows calculate correctly and the messages area scrolls ── */
    #screen-chat {
        min-height: 0;
    }

    .chat-layout {
        height: 100dvh;
        min-height: unset;
        border-radius: 0;
    }

    .chat-header {
        padding: 16px 20px 14px 60px; /* left gap clears the hamburger */
        border-radius: 0;
    }

    .messages {
        padding: 16px;
        justify-items: start; /* ensure bubbles don't stretch full-width */
    }

    .composer {
        padding: 12px 16px 20px;
        border-radius: 0;
    }

    .message {
        max-width: 90%;
    }

    /* ── Fix 1: non-chat screens flush to edges, hamburger sits inside
       the card top just like it does in the chat header ── */
    #screen-login,
    #screen-eula,
    #screen-course {
        padding: 0;
    }

    .hero-card {
        border-radius: 0;
        padding: 64px 28px 36px; /* top padding clears the hamburger */
        min-height: 100dvh;
    }

    .content-card {
        border-radius: 0;
        padding: 64px 28px 36px;
        min-height: 100dvh;
        align-self: stretch;
        max-width: 100%;
    }

    /* ── Fix 3: course dropdown ── */
    select {
        font-size: 16px; /* prevent iOS auto-zoom on focus */
        padding: 14px 12px;
    }

    .field {
        max-width: 100%; /* fill the card on mobile */
    }

    .conversation-menu-trigger {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ─── Login page spacing ──────────────────────────────────────────────────── */
body[data-stage="login"] .hero-card > h1 {
    margin-top: 20px;
    margin-bottom: 0;
}

body[data-stage="login"] .hero-card > .lead {
    margin-top: 32px;
    line-height: 1.75;
    font-size: 1.08rem;
}

body[data-stage="login"] .hero-card > .notice {
    margin-top: 28px;
}

body[data-stage="login"] .hero-card > .button.primary {
    margin-top: 52px;
    align-self: flex-start;
    padding: 15px 40px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
