/* Chat UI */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* When inside sidebar layout, account for sidebar */
.main-content .chat-container {
    height: 100vh;
    max-height: 100vh;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages .load-more {
    text-align: center;
    padding: 12px;
}

.chat-messages .load-more button {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.15s, color 0.15s;
}

.chat-messages .load-more button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Message rows */
.message-row {
    display: flex;
    gap: 12px;
    /* Cap to the container width. The row uses align-self:flex-start/flex-end,
       so it sizes to its CONTENT, not stretched — a bare 800px cap never limits
       it on a phone, letting a wide child (audio player, calendar card) push the
       row past the viewport and scroll the chat sideways. min(800px,100%) keeps
       the desktop readability cap AND fits mobile. */
    max-width: min(800px, 100%);
    min-width: 0;
    animation: fadeIn 0.2s ease;
}

/* Let the flex chain shrink below content min-width. The proof/calendar card
   lives in an unclassed flex child; its title is white-space:nowrap, so without
   this the title's intrinsic min-width forces the card wider than a phone screen
   and it overflows off the right edge. */
.message-row > * { min-width: 0; max-width: 100%; }

/* The daily-brief <audio controls> player has a native intrinsic width; clamp it
   so it shrinks to the bubble and can't widen the row / scroll the chat. */
.block-audio { min-width: 0; max-width: 100%; overflow: hidden; }
.block-audio audio { width: 100%; min-width: 0; }

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

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

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

.message-row.assistant .message-avatar { background: transparent; }
.message-row.user .message-avatar { background: #444; }
.message-avatar img { width: 100%; height: 100%; object-fit: contain; display: block; }

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 680px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    user-select: text;
    -webkit-user-select: text;
    position: relative;
}

/* Copy button on hover */
.message-copy-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--bg-secondary, #2a2a2a);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 4px;
}
.message-bubble:hover .message-copy-btn { opacity: 1; }
.message-copy-btn:hover { color: var(--text-primary); background: var(--bg-hover, #333); }
.message-copy-btn.copied { color: #4ade80; }

/* Code block copy */
.code-block-wrapper {
    position: relative;
}
.code-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    opacity: 0;
    transition: opacity 0.15s;
}
.code-block-wrapper:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: #fff; }
.code-copy-btn.copied { color: #4ade80; }

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

.message-row.assistant .message-bubble {
    background: var(--assistant-bubble);
    color: var(--assistant-text);
    border-bottom-left-radius: 4px;
}

/* Markdown in assistant messages */
.message-bubble h2 { font-size: 18px; margin: 12px 0 8px; }
.message-bubble h3 { font-size: 16px; margin: 10px 0 6px; }
.message-bubble h4 { font-size: 14px; font-weight: 600; margin: 8px 0 4px; }

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

.message-bubble ul, .message-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-bubble li { margin: 4px 0; }

.message-bubble a {
    color: #60a5fa;
    text-decoration: none;
}
.message-bubble a:hover { text-decoration: underline; }

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

.message-bubble .inline-code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
}

.message-row.user .message-bubble .inline-code {
    background: rgba(255,255,255,0.2);
}

.message-bubble .code-block {
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin: 10px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.message-bubble .code-block code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: #e5e5e5;
}

.message-bubble img {
    display: block;
    max-width: min(360px, 100%);
    max-height: 240px;
    height: auto;
    width: auto;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

/* Inline image inside a list item — keep flow tight and cap a bit smaller */
.message-bubble li img {
    max-width: min(320px, 100%);
    max-height: 200px;
    margin: 6px 0 4px;
}

.message-timestamp {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message-row.user .message-timestamp { text-align: right; }

/* Typing indicator */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--assistant-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
    max-width: 80px;
}

.typing-indicator.show { display: flex; }

/* Elapsed-time label inside the indicator. Crew chat posts a blocking
 * POST /v1/crew/agents/<id>/chat (no /v1/chat/stream), so a 40s tool-heavy
 * turn otherwise renders as three static dots for 40s — indistinguishable
 * from a dead session. The label is the one honest progress signal the
 * client actually has. Only crew.html sets .with-status, so the main chat
 * page keeps the original 80px pill. */
.typing-indicator.with-status { max-width: none; }

.typing-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 4px;
    white-space: nowrap;
}

.typing-status:empty { display: none; }

.typing-dot {
    width: 8px; height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat images — DATA_FORMAT.md Pilot 7 improvement:
 * 300px was too aggressive for chart/card images from the agent — it
 * shrank them to thumbnail size making inline text unreadable. The
 * "Takeaway text outside card frame" issue from the 2026-04-20 prod
 * feedback was caused by this under-sizing combined with the image's
 * own near-edge text. Let images render at a readable width, capped at
 * the bubble's max-width for containment, and max-height so a tall
 * image can't dominate the chat. Lightbox zoom preserved for detail. */
.message-images {
    margin-top: 8px;
    /* Flex wrap lets multiple images stack vertically for readability
     * instead of squeezing into a single row. */
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.message-images img {
    /* Fit the message bubble / container width; never overflow. */
    max-width: 100%;
    /* Reasonable visible height cap; lightbox shows full size on click. */
    max-height: 600px;
    width: auto;
    height: auto;
    /* Preserve aspect ratio; contain inside the visible box. */
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    background: var(--bg-card-alt, rgba(255, 255, 255, 0.02));
    cursor: zoom-in;
    transition: opacity 0.15s, transform 0.15s;
}
.message-images img:hover {
    opacity: 0.92;
}
@media (hover: hover) and (pointer: fine) {
    .message-images img:hover { transform: translateY(-1px); }
}

/* Attachment preview */
.attachment-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 32px 0;
    max-width: 800px;
    margin: 0 auto;
}
.attachment-preview img {
    width: 60px; height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.attachment-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
}
.attachment-remove:hover { color: var(--danger, #f44); }
/* Several pending attachments per send: thumbs and file labels wrap, each with its own remove. */
.attachment-list { flex-wrap: wrap; }
.attachment-item { position: relative; display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.attachment-item .attachment-label {
    font-size: 13px; color: var(--text-secondary); padding: 6px 10px;
    background: var(--bg-primary); border-radius: 6px;
    max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attachment-item .attachment-remove { padding: 4px 6px; }

/* Suggest button */
.chat-suggest-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    flex-shrink: 0;
    transition: opacity 0.15s;
    opacity: 0.7;
}
.chat-suggest-btn:hover { opacity: 1; }

/* Suggestions panel */
.suggestions-panel {
    position: fixed;
    width: 320px;
    max-width: calc(100vw - 32px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: fadeIn 0.15s ease;
}
.suggestions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}
.suggestions-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
}
.suggestions-header button:hover { color: var(--text-primary); }
.suggestions-list { display: flex; flex-direction: column; gap: 4px; }
.suggestion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.1s;
}
.suggestion-item:hover { background: var(--bg-hover, rgba(255,255,255,0.05)); }
.suggestion-item .prompt-icon { font-size: 18px; flex-shrink: 0; }

/* Attach button */
.chat-attach-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 4px 4px 0;
    flex-shrink: 0;
    transition: color 0.15s;
}
.chat-attach-btn:hover { color: var(--text-primary); }

/* Image lightbox */
.image-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.image-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
}

/* Chat input */
.chat-input-area {
    position: relative;
    padding: 16px 32px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 12px;
    transition: border-color 0.15s;
}

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

.chat-input-wrapper.has-command {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(232, 82, 46, 0.15);
}

.chat-input-wrapper.has-command-blocked {
    border-color: #f87171;
    box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.15);
}

/* Discord-style command pill — shown above the textarea when the input
   starts with a recognized slash command. Anchored to the input wrapper
   so it sits visually inside the same chrome. */
.cmd-pill {
    display: none;
    align-items: center;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto 6px;
    padding: 6px 10px 6px 8px;
    border-radius: 8px;
    background: rgba(232, 82, 46, 0.10);
    color: var(--accent);
    border: 1px solid rgba(232, 82, 46, 0.45);
    font-size: 13px;
    font-weight: 500;
}
.cmd-pill.show { display: inline-flex; }
.cmd-pill.blocked {
    background: rgba(248, 113, 113, 0.10);
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.45);
}
.cmd-pill .cmd-name {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 5px;
    font-weight: 600;
    font-size: 12px;
}
.cmd-pill.blocked .cmd-name { background: #f87171; }
.cmd-pill .cmd-desc { color: var(--text-secondary); font-weight: 400; }

/* Inline highlight of a recognized command — the textarea draws the text, so
   color the textarea itself. When the wrapper has .has-command, the user
   types `/mode ...` and the whole string goes orange. */
.chat-input-wrapper.has-command .chat-input {
    color: var(--accent);
    -webkit-text-fill-color: var(--accent);
}
.chat-input-wrapper.has-command-blocked .chat-input {
    color: #f87171;
    -webkit-text-fill-color: #f87171;
}

/* Autocomplete picker — shown when input is just "/" or starts with
   "/<partial>" that hasn't formed a full command yet. Sits above the
   input, vertical list of options. Click to fill the textarea. */
.cmd-autocomplete {
    display: none;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto 6px;
    padding: 6px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.cmd-autocomplete.show { display: flex; }
.cmd-autocomplete-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 10px 4px;
}
.cmd-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.cmd-autocomplete-item:hover,
.cmd-autocomplete-item.active {
    background: rgba(232, 82, 46, 0.10);
}
.cmd-autocomplete-item.blocked:hover,
.cmd-autocomplete-item.blocked.active {
    background: rgba(248, 113, 113, 0.10);
}
.cmd-autocomplete-item .ac-name {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 5px;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}
.cmd-autocomplete-item.blocked .ac-name { background: #f87171; }
.cmd-autocomplete-item .ac-desc {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
}
.cmd-autocomplete-item.blocked .ac-desc { color: #f87171; opacity: 0.85; }

/* Mention picker — visually parallel to .cmd-autocomplete but keyed off "@".
   Items have an extra emoji column (the agent's avatar emoji). Selection
   pushes a structured mention into the send body. */
.mention-autocomplete {
    display: none;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto 6px;
    padding: 6px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    max-height: 320px;
    overflow-y: auto;
}
.mention-autocomplete.show { display: flex; }
.mention-autocomplete-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 10px 4px;
}
.mention-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.mention-autocomplete-item:hover,
.mention-autocomplete-item.active {
    background: rgba(232, 82, 46, 0.10);
}
.mention-autocomplete-item .ac-emoji {
    font-size: 16px;
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}
.mention-autocomplete-item .ac-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}
.mention-autocomplete-item .ac-desc {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Highlight-within-textarea: the textarea draws its own text and caret, and
   a backdrop BEHIND it repeats the text in transparent ink with each
   @AgentName token wrapped in a tinted span. Text and caret come from the
   same element, so they cannot drift apart; if the backdrop's wrapping ever
   differs (scrollbar, font fallback) only a mention tint shifts. The inverse
   (transparent textarea over visible backdrop) let the visible text slide
   away from the caret on long pasted messages (2026-09-25). */
.chat-input-stack {
    flex: 1;
    position: relative;
    display: flex;
    align-items: stretch;
    min-height: 24px;
    box-sizing: border-box;
}
.mention-highlight-backdrop {
    position: absolute;
    inset: 0;
    margin: 0;
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
    /* MUST match .chat-input exactly so glyphs land on the same x/y as
       the underlying textarea — any drift here = double-rendered text. */
    box-sizing: border-box;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    padding: 4px 0;
    color: transparent;
    /* Don't break a long unbroken token off-screen; let the textarea's
       wrapping decide. */
    word-break: break-word;
}
/* Highlight CANNOT change glyph width or font weight — those alter the
   metrics the textarea uses to position the caret, and the visible text
   drifts away from the cursor. So:
   - no horizontal padding/margin (would push trailing text)
   - no font-weight change (changes glyph advance widths)
   The "pill" effect comes from box-shadow which sits outside the box and
   doesn't participate in layout. */
.mention-highlight {
    color: transparent;
    background: rgba(232, 82, 46, 0.18);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(232, 82, 46, 0.18);
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    caret-color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
    position: relative;
    z-index: 1;
}

.chat-input::placeholder {
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
}

.chat-send-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s, opacity 0.15s;
}

.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* End of history marker */
.end-of-history {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Starter prompts (empty chat state) */
.starter-prompts {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 48px 24px;
    max-width: 600px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}
.starter-prompts .welcome-emoji { font-size: 40px; margin-bottom: 12px; }
.starter-prompts img.welcome-emoji { width: 72px; height: 72px; object-fit: contain; display: block; margin: 0 auto 12px; }
.starter-prompts h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px;
    text-align: center;
}
.starter-prompts p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 24px;
}
.prompt-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}
.prompt-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    text-align: left;
}
.prompt-card:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}
.prompt-card .prompt-icon { font-size: 18px; flex-shrink: 0; }

@media (max-width: 768px) {
    .prompt-grid { grid-template-columns: 1fr; }
    .starter-prompts { padding: 80px 16px 24px; }
}

/* Upgrade dialog */
.upgrade-dialog {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    max-width: 380px;
    text-align: center;
}
.upgrade-dialog::backdrop { background: rgba(0,0,0,0.6); }
.upgrade-dialog h3 { margin: 0 0 8px; font-size: 18px; }
.upgrade-dialog p { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; }
.upgrade-actions { display: flex; gap: 10px; justify-content: center; }
.upgrade-actions button {
    padding: 8px 20px; border-radius: 8px; border: 1px solid var(--border);
    background: none; color: var(--text-primary); cursor: pointer; font-family: inherit; font-size: 14px;
}
.upgrade-actions button:hover { background: var(--bg-hover); }
.upgrade-btn {
    padding: 8px 20px; border-radius: 8px; background: var(--accent); color: #fff;
    text-decoration: none; font-size: 14px; font-weight: 500;
}
.upgrade-btn:hover { opacity: 0.9; }

/* Rate limit banner */
.rate-limit-banner {
    text-align: center; padding: 8px 16px; font-size: 13px;
    background: var(--bg-secondary); border-top: 1px solid var(--border);
    color: var(--text-muted);
}
.rate-limit-banner a { color: var(--accent); text-decoration: none; margin-left: 8px; }
.rate-limit-banner a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
    .chat-messages { padding: 68px 12px 12px; }
    .chat-input-area { padding: 12px; }
    .message-bubble { max-width: calc(100vw - 80px); }
}

/* File chip — clickable attachment pill (PDF / TXT / MD / CSV / JSON). */
.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-primary, #ee6c4d);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.15s, opacity 0.15s;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-chip:hover:not(:disabled) { filter: brightness(1.05); }
.file-chip:disabled { opacity: 0.7; cursor: progress; }
.file-chip i { font-size: 14px; }
/* Trailing arrow on chips that save instead of opening a preview. */
.file-chip-download { font-size: 12px !important; opacity: 0.85; }

/* File preview modal — backdrop + framed body. */
.file-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.file-lightbox-inner {
    width: 90vw;
    height: 90vh;
    background: var(--bg-primary, #fff);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: default;
}
.file-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border, #e5e5e5);
    font-size: 14px;
    font-weight: 500;
}
.file-lightbox-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted, #888);
    padding: 0 4px;
}
.file-lightbox-close:hover { color: var(--text-primary, #000); }
.file-lightbox-body {
    flex: 1;
    overflow: auto;
    background: var(--bg-secondary, #f5f5f5);
}
.file-lightbox-body iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
.file-lightbox-body pre {
    margin: 0;
    padding: 16px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Live tool-progress line above the streaming bubble ("Searching the web…") */
.stream-progress {
    font-size: 12px;
    font-style: italic;
    color: #999;
    padding: 4px 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stream-progress::before {
    content: '';
    width: 10px;
    height: 10px;
    border: 2px solid #666;
    border-top-color: transparent;
    border-radius: 50%;
    flex-shrink: 0;
    animation: stream-progress-spin 0.9s linear infinite;
}
@keyframes stream-progress-spin {
    to { transform: rotate(360deg); }
}

/* Named-session chip bar (Discord-thread style) above the message list */
.session-bar {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
}
.session-chip {
    background: #1c1c1c;
    color: #ccc;
    border: 1px solid #2a2a2a;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.session-chip:hover { border-color: #444; }
.session-chip.active {
    background: #FF6B35;
    border-color: #FF6B35;
    color: #fff;
}
.session-chip-new { font-weight: 700; }

/* Survey sheet (js/survey.js) — Formbricks link survey in an iframe. */
.survey-overlay { position: fixed; inset: 0; z-index: 1200; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.survey-sheet { position: relative; width: min(560px, 100%); height: min(640px, 90vh); background: var(--bg, #fff); border-radius: 16px 16px 0 0; overflow: hidden; box-shadow: 0 -8px 32px rgba(0,0,0,.3); }
.survey-close { position: absolute; top: 8px; right: 10px; z-index: 1; width: 32px; height: 32px; border: none; border-radius: 50%; background: rgba(0,0,0,.08); color: inherit; font-size: 20px; line-height: 1; cursor: pointer; }
.survey-frame { width: 100%; height: 100%; border: 0; }
@media (min-width: 720px) { .survey-overlay { align-items: center; } .survey-sheet { border-radius: 16px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
