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

:root {
    /* Warmer, more approachable color scheme */
    --primary: #2b5a8f;
    --primary-dark: #1e4270;
    --primary-light: #3d6fa3;
    --accent: #e8f2fc;
    --accent-warm: #fef6e8;
    --bg: #f8f9fb;
    --white: #ffffff;
    --text: #1a1f2e;
    --text-light: #5a6475;
    --border: #d4dbe6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --user-bg: #2b5a8f;
    --user-text: #ffffff;
    --assistant-bg: #ffffff;
    --assistant-text: #1a1f2e;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === App Layout === */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height — accounts for mobile browser chrome */
}

/* === Header === */
/* Both header variants share one definition: the header markup is identical on
   every page (static/_partials/header.html), so its styling must be too. */
.app-header,
.live-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* The title block is a link home on every page; strip the anchor defaults so it
   still reads as a heading, and give it a subtle hover affordance. */
a.header-title {
    text-decoration: none;
    color: inherit;
    border-radius: 8px;
    transition: opacity 0.15s ease;
}

a.header-title:hover { opacity: 0.75; }
a.header-title:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }

.avatar {
    font-size: 2rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.title-text h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.title-text .subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 2px;
    font-weight: 400;
}

.header-nav {
    display: flex;
    gap: 12px;
    align-items: center;
}

.nav-link {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    /* font-family/line-height set explicitly so <button> nav items match the
       <a> nav items exactly (buttons don't inherit the page font by default). */
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Nav items are a mix of <a> and <button>; kill the anchor underline for all
       of them rather than relying on a per-link rule. */
    text-decoration: none;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.35);
}

.live-link {
    text-decoration: none;
}

/* The live-connection badge ships in the shared header but is only unhidden by
   live.js on the feed page. live.css sets `.live-indicator { display: flex }`,
   which would otherwise beat the [hidden] attribute on every page loading it. */
.live-indicator[hidden] {
    display: none;
}

/* === Mobile nav drawer (hidden on desktop) === */
.hamburger-btn {
    display: none;
    font-size: 1.1rem;
    line-height: 1;
    padding: 6px 12px;
}

.mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-drawer-overlay.open {
    opacity: 1;
    visibility: visible;
}

.mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 280px;
    max-width: 80vw;
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0.25s ease;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.mobile-drawer-title {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
}

.mobile-drawer-close {
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.mobile-drawer-close:hover,
.mobile-drawer-close:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    outline: none;
}

.mobile-drawer-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
}

.mobile-drawer-link {
    display: block;
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 14px 16px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.3;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.mobile-drawer-link:hover,
.mobile-drawer-link:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    outline: none;
}

body.drawer-open {
    overflow: hidden;
}

/* === Chat Area === */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px 16px;
    background: var(--bg);
}

.chat-messages {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* === Messages === */
.message {
    display: flex;
    max-width: 85%;
}

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

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

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.95rem;
}

.user-message .message-content {
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.assistant-message .message-content {
    background: var(--assistant-bg);
    color: var(--assistant-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

/* === Message Typography === */
.message-content p {
    margin-bottom: 10px;
}

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

.message-content ul, .message-content ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Monaco', 'Cascadia Code', monospace;
}

.message-content strong {
    font-weight: 600;
}

/* === Sources === */
.sources-toggle {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: var(--primary);
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sources-toggle:hover {
    background: #d4e6fc;
    border-color: var(--primary-light);
}

.sources-list {
    display: none;
    margin-top: 10px;
    padding: 12px 14px;
    background: var(--accent);
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--text-light);
}

.sources-list.open {
    display: block;
}

.sources-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sources-list li {
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sources-list li:last-child {
    border-bottom: none;
}

/* === Status Line (streaming pipeline progress) === */
.status-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    font-size: 0.95rem;
    font-style: italic;
}

.status-line.status-warning .status-text {
    color: #a15c00;
    font-style: normal;
}

.status-dots {
    display: inline-flex;
    gap: 4px;
    flex-shrink: 0;
}

.status-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.status-dots span:nth-child(2) { animation-delay: 0.2s; }
.status-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* === Steps log (collapsible pipeline trace) === */
.steps-toggle {
    display: inline-block;
    margin-top: 12px;
    margin-right: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: var(--text-light);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.steps-toggle:hover {
    background: var(--accent);
    color: var(--primary);
}

.steps-list {
    display: none;
    margin-top: 10px;
    padding: 12px 14px;
    background: #f7f7f7;
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--text-light);
}

.steps-list.open {
    display: block;
}

.steps-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.steps-list li {
    padding: 3px 0;
}

.steps-list li.step-warning {
    color: #a15c00;
}

/* === Requery badge === */
.requery-badge {
    display: inline-block;
    margin-top: 12px;
    margin-right: 8px;
    padding: 3px 10px;
    font-size: 0.72rem;
    color: #1a5490;
    background: #e8f3fc;
    border: 1px solid #cfe4f7;
    border-radius: 10px;
    font-weight: 500;
    cursor: help;
}

/* === Input Area === */
.input-area {
    position: relative;
    padding: 16px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--white);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
}

.input-form {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
}

.input-form input {
    flex: 1;
    padding: 14px 18px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: all 0.2s ease;
    background: var(--bg);
    color: var(--text);
}

.input-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(43, 90, 143, 0.1);
    background: var(--white);
}

.input-form input::placeholder {
    color: #9aa5b8;
}

.input-form button {
    padding: 0 18px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.input-form button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.input-form button:active {
    transform: translateY(0);
}

.input-form button:disabled {
    background: #8fa3bf;
    cursor: not-allowed;
    transform: none;
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 10px;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

.version-tag {
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-light);
    opacity: 0.55;
    margin: 2px auto 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.02em;
}

/* === Markdown Content === */
.message-content h1, .message-content h2, .message-content h3 {
    margin: 14px 0 8px;
    font-weight: 700;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.2rem; }
.message-content h2 { font-size: 1.1rem; }
.message-content h3 { font-size: 1rem; }

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.875rem;
}

.message-content th, .message-content td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.message-content th {
    background: var(--accent);
    font-weight: 600;
}

.message-content pre {
    background: #f2f4f6;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 0.875rem;
}

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

.message-content blockquote {
    border-left: 4px solid var(--primary);
    padding: 6px 14px;
    margin: 10px 0;
    background: var(--accent);
    border-radius: 0 6px 6px 0;
}

.message-content a {
    color: var(--primary);
    text-decoration: underline;
}

/* === Reset Banner === */
.reset-banner {
    margin: 20px 0 10px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--accent-warm), #fff9ed);
    border: 1px solid #e8d5a6;
    border-radius: var(--radius);
    text-align: center;
}

.reset-banner-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.reset-banner-content span {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.5;
}

.reset-button {
    padding: 10px 24px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.reset-button:active {
    transform: translateY(0);
}

/* === Continuing-a-thread banner === */
.continuing-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 8px 0 16px;
    padding: 10px 16px;
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.continuing-text {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
}

.continuing-new {
    padding: 6px 16px;
    background: var(--white);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.continuing-new:hover {
    background: var(--primary);
    color: var(--white);
}

/* === Guest sign-up teaser card === */
.guest-signup-card {
    margin-top: 16px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    border-radius: var(--radius);
    text-align: center;
}

.guest-signup-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    line-height: 1.4;
    color: var(--white);
}

.guest-signup-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.guest-signup-btn {
    display: inline-block;
    padding: 9px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: var(--white);
    transition: all 0.2s ease;
}

.guest-signup-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.guest-signup-btn.primary {
    background: var(--white);
    color: var(--primary);
    border-color: var(--white);
}

.guest-signup-btn.primary:hover {
    background: var(--accent);
}

/* === Error Message === */
.error-content {
    background: #fef2f2 !important;
    border-color: #fca5a5 !important;
    color: #991b1b !important;
}

/* === Modal === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--white);
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: slideUp 0.3s ease;
}

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

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 2rem;
    color: var(--text-light);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
    line-height: 1;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-content h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text);
}

.modal-content h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.modal-content p {
    margin-bottom: 12px;
    color: var(--text);
    line-height: 1.7;
}

.modal-content ul {
    margin: 12px 0;
    padding-left: 24px;
}

.modal-content li {
    margin-bottom: 8px;
    line-height: 1.7;
}

.modal-content a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 500;
}

.modal-content a:hover {
    color: var(--primary-dark);
}

.about-section {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.about-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* === Mobile === */
@media (max-width: 768px) {
    .header-content {
        padding: 14px 16px;
        flex-direction: row;
        gap: 12px;
        align-items: center;
    }

    .header-title {
        gap: 10px;
        min-width: 0;
        flex: 1;
    }

    .avatar {
        font-size: 1.5rem;
    }

    .title-text {
        min-width: 0;
    }

    .title-text h1 {
        font-size: 1.35rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .title-text .subtitle {
        font-size: 0.8rem;
    }

    .header-nav {
        align-self: center;
        gap: 8px;
        align-items: center;
        flex-shrink: 0;
    }

    .nav-link {
        padding: 6px 14px;
        font-size: 0.8rem;
    }

    /* Collapse secondary nav items into the hamburger drawer on mobile */
    .header-nav .live-link,
    .header-nav .tools-menu,
    .header-nav .live-indicator,
    #aboutButton {
        display: none;
    }

    .hamburger-btn {
        display: inline-flex;
    }

    /* Keep the user menu reachable as a direct button; cap long usernames.
       The cap is on the name span, not the button, so the dropdown caret is
       never the thing that gets ellipsised away. */
    .user-menu-toggle {
        display: inline-flex;
        white-space: nowrap;
    }

    .user-menu-name {
        display: inline-block;
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-container {
        padding: 16px 12px 12px;
    }

    .message {
        max-width: 90%;
    }

    .message-content {
        padding: 12px 14px;
        font-size: 0.95rem;
    }

    .input-area {
        padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .input-form {
        gap: 8px;
    }

    .input-form input {
        font-size: 1rem;
        padding: 12px 14px;
    }

    .input-form button {
        padding: 0 14px;
    }

    .modal-content {
        padding: 24px;
        max-height: 85vh;
    }

    .modal-content h2 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }

    .about-section {
        margin-bottom: 24px;
        padding-bottom: 20px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 14px 8px 10px;
    }

    .message {
        max-width: 95%;
    }

    /* Smallest screens: just the title, user menu, and hamburger */
    .title-text .subtitle {
        display: none;
    }

    /* What's New is already in the hamburger drawer; keeping it in the nav here
       squeezed the title down to "How…" once the account button was present. */
    #whatsNewLink,
    #pricingLink {
        display: none;
    }

    .user-menu-name {
        max-width: 84px;
    }
}

/* === Streamed answer blocks === */
.stream-block > *:first-child { margin-top: 0; }
.stream-block > *:last-child { margin-bottom: 0; }

/* An answer Howard superseded. Kept visible so the user can see what changed,
   but pushed into the background so the live text is unmistakable. */
.stream-block.superseded {
    opacity: 0.55;
    color: var(--text-light);
    border-left: 3px solid var(--border);
    padding-left: 12px;
}

.superseded-label {
    margin-bottom: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-light);
}

/* Shown only while the user has scrolled up during a stream. */
.jump-to-latest {
    position: absolute;
    left: 50%;
    bottom: 100%;
    transform: translateX(-50%);
    margin-bottom: 12px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--white);
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    z-index: 5;
}

.jump-to-latest:hover {
    border-color: var(--primary-light);
    background: var(--bg);
}

/* Divider introducing a revised answer. The first answer stays above it. */
.revision-note {
    margin: 16px 0 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border, #e5e7eb);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted, #6b7280);
}

/* === User Menu === */
.user-menu {
    position: relative;
}

.user-menu-toggle {
    display: inline-flex;
    align-items: center;
}

/* Spaced like the Tools caret rather than butting against the username. */
.user-menu-caret {
    margin-left: 6px;
    flex-shrink: 0;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 100;
    overflow: hidden;
}

.user-menu-dropdown.open {
    display: block;
}

.user-menu-dropdown a,
.user-menu-dropdown button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text);
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    text-decoration: none;
}

.user-menu-dropdown a:last-child,
.user-menu-dropdown button:last-child {
    border-bottom: none;
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
    background: var(--accent);
}

/* === Tools Menu === */
.tools-menu {
    position: relative;
}

.tools-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 240px;
    z-index: 100;
    overflow: hidden;
}

.tools-menu-dropdown.open {
    display: block;
}

.tools-menu-dropdown a {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text);
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    text-decoration: none;
}

.tools-menu-dropdown a:last-child {
    border-bottom: none;
}

.tools-menu-dropdown a:hover {
    background: var(--accent);
}

/* "This isn't right" feedback control */
.feedback-control { margin-top: 10px; }
.answer-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-great, .btn-wrong, .btn-share {
  font-size: 0.8rem; padding: 5px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border, #e5e7eb); background: var(--white, #fff);
  font-family: inherit;
}
.btn-great { color: #15803d; border-color: #bbf7d0; }
.btn-great:hover { background: #f0fdf4; border-color: #15803d; }
.btn-wrong { color: #b91c1c; border-color: #fecaca; }
.btn-wrong:hover { background: #fef2f2; border-color: #b91c1c; }
.btn-share {
  color: #6b7280; border-color: #e5e7eb; background: none;
}
.btn-share:hover { background: #f3f4f6; border-color: #9ca3af; }
.btn-share-error { color: #b91c1c !important; }
.great-form {
  margin-top: 8px; padding: 12px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px; background: var(--bg, #f9fafb);
  display: flex; flex-direction: column; gap: 8px;
}
.great-form .great-note {
  padding: 8px 10px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px; font-size: 0.85rem; font-family: inherit; resize: vertical;
}
.feedback-form {
  margin-top: 8px; padding: 12px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px; background: var(--bg, #f9fafb); display: flex; flex-direction: column; gap: 8px;
}
.feedback-excerpt { font-size: 0.8rem; color: var(--muted, #6b7280); }
.feedback-clear { border: none; background: none; cursor: pointer; color: #b91c1c; font-size: 0.9rem; }
.feedback-whole { font-size: 0.85rem; display: flex; gap: 6px; align-items: center; }
.feedback-form input[type="text"], .feedback-form input[type="url"] {
  padding: 8px 10px; border: 1px solid var(--border, #e5e7eb); border-radius: 6px; font-size: 0.85rem;
}
.feedback-actions { display: flex; gap: 8px; justify-content: flex-end; }
.feedback-actions button { padding: 6px 14px; border-radius: 6px; font-size: 0.85rem; cursor: pointer; }
.feedback-submit { background: var(--primary, #2b5a8f); color: #fff; border: none; }
.feedback-cancel { background: none; border: 1px solid var(--border, #e5e7eb); }
.feedback-msg { font-size: 0.8rem; color: #b91c1c; }
.feedback-thanks { font-size: 0.85rem; color: #15803d; margin-top: 8px; }

.private-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted, #6b7280); cursor: pointer; margin-left: 8px; }
.private-toggle input { width: auto; cursor: pointer; }
.history-default-private { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted, #6b7280); margin: 0 auto 16px; max-width: 800px; cursor: pointer; }
.feed-item-private { margin-top: 6px; background: none; border: 1px solid var(--border, #e5e7eb); border-radius: 6px; padding: 2px 8px; font-size: 0.75rem; cursor: pointer; color: var(--muted, #6b7280); }
.feed-item-private:hover { border-color: var(--primary, #2b5a8f); color: var(--primary, #2b5a8f); }

/* "Built with love by" credit, injected via <!--HOWARD_CREDIT--> */
.site-credit {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-light);
    opacity: 0.75;
    margin: 6px auto 0;
}
.site-credit a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.site-credit a:hover {
    color: var(--primary);
    border-bottom-style: solid;
}
.live-container > .site-credit {
    margin: 24px auto 16px;
}

/* === Checker (code-claim verification persona) ===
   A second agent, visually distinct from Howard's blue: purple = the
   colleague double-checking the account codes. */
:root {
    --checker: #6b46a8;
    --checker-bg: #f5f0fc;
    --checker-border: #d9c9f2;
}

.code-checking, .code-checking-done, .code-ok, .code-flagged {
    padding: 2px 6px; border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Cascadia Code', monospace; font-size: 0.9em;
}
.code-checking { background: var(--checker-bg); border-bottom: 2px dotted var(--checker); }
.code-checking-done { background: rgba(0, 0, 0, 0.04); }
.code-ok { background: #eefbf1; border-bottom: 2px solid #34a06a; }
.code-flagged { background: #fdf1ec; border-bottom: 2px solid #cf6a34; }

.checker-avatar {
    width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
    background: var(--checker); color: #fff; display: inline-flex;
    align-items: center; justify-content: center; font-size: 11px;
}

.assistant-message { position: relative; }

.checker-bubble {
    position: absolute; right: -12px; top: -34px; z-index: 5;
    background: var(--checker-bg); border: 1px solid var(--checker-border);
    border-radius: 14px; border-bottom-left-radius: 3px;
    padding: 7px 12px; font-size: 0.83rem; color: var(--checker);
    box-shadow: var(--shadow-lg); max-width: 280px;
    display: flex; gap: 8px; align-items: center;
    animation: checker-in 0.25s ease-out;
}
@keyframes checker-in { from { opacity: 0; transform: translateY(6px); } }

.checker-card {
    /* .message is display:flex, so the card sits BESIDE the answer on wide
       screens — variant B's margin annotation. On narrow screens it wraps
       below (media query). */
    margin-left: 10px; align-self: flex-start; max-width: 240px;
    background: var(--checker-bg); border: 1px solid var(--checker-border);
    border-radius: 10px; padding: 9px 12px; font-size: 0.82rem;
    color: var(--checker); box-shadow: var(--shadow);
}
.checker-card .hdr { display: flex; gap: 7px; align-items: center; font-weight: 600; margin-bottom: 5px; }
.checker-card ul { margin: 4px 0 0; padding-left: 18px; color: #7d68a8; }
.checker-card li { margin-bottom: 3px; overflow-wrap: anywhere; }
.checker-card.collapsed { padding: 4px 10px; cursor: pointer; }
.checker-card.collapsed ul, .checker-card.collapsed div:not(.hdr) { display: none; }
.checker-card.collapsed .hdr { margin-bottom: 0; }
.checker-card.collapsed .hdr::after { content: " codes verified ✓"; font-weight: 400; }

/* Narrow screens: side-by-side would squeeze the answer to half width.
   Wrap instead — the bubble docks ABOVE the answer, the card drops BELOW. */
@media (max-width: 640px) {
    .assistant-message { flex-wrap: wrap; }
    .checker-bubble {
        position: static; order: -1; flex-basis: 100%;
        margin-bottom: 6px; max-width: none;
    }
    .checker-card {
        flex-basis: 100%; max-width: none;
        margin-left: 0; margin-top: 8px;
    }
}

.checker-history-line { font-size: 0.78rem; color: var(--checker); margin-top: 6px; }
.checker-history-line.flagged { color: #cf6a34; }

/* === Try another model (admin / allowlist only) === */
.try-models {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.6rem;
  font-size: 0.85rem;
}
.try-models-select {
  font: inherit;
  padding: 0.2rem 0.4rem;
}
.try-models-btn {
  font: inherit;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
}
.retry-message {
  border-left: 3px solid #b58900;
  padding-left: 0.5rem;
}
.retry-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #7a5c00;
  margin-bottom: 0.25rem;
}

/* === Guest preview: first few words, then blurred placeholder text === */
.guest-teaser-text { margin: 0 0 4px; }
.guest-locked { position: relative; padding-top: 4px; }
.guest-blur {
    margin: 0;
    filter: blur(5px);
    user-select: none;
    pointer-events: none;
    color: var(--text-light, #666);
    height: 11em;
    overflow: hidden;
}
/* Sits inside the blurred block, below the readable words, never over them. */
.guest-locked .guest-signup-card {
    position: absolute;
    left: 50%;
    top: 1.5em;
    transform: translateX(-50%);
    width: min(92%, 420px);
    margin: 0;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
.guest-signup-card .guest-bonus-note {
    font-size: 0.85rem;
    margin: 0 0 12px;
    color: rgba(255, 255, 255, 0.88);
}
/* .message-content a {...} would otherwise recolour these links. */
.message-content .guest-signup-card a.guest-signup-btn { color: var(--white); text-decoration: none; }
.message-content .guest-signup-card a.guest-signup-btn.primary { color: var(--primary); }
@media (max-width: 480px) {
    .guest-blur { height: 15em; }
}
