/* ═══════════════════════════════════════════════════════════════════════
   DELPHOS · CHAT-STREAM.CSS
   Single, authoritative stylesheet for the whole conversation UI:
   message rows, streaming text, thinking blocks, tool calls, and the
   per-kind result cards (web / shopping / video / places / images).

   Loaded AFTER style.css so it is the one place to maintain this area.
   It intentionally overrides the older, duplicated chat rules that were
   scattered through style.css. Organised top-to-bottom:
     1. Message rows & layout
     2. Reading text (concise, Claude-like)
     3. Streaming segments (smooth append + bottom fade)
     4. Thinking block
     5. Tool call — the muted line, spinner, shimmer, skeleton
     6. Tool results panel
     7. Per-kind result cards
     8. Inline media (images / video / mermaid)
   ═══════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────
   1. MESSAGE ROWS & LAYOUT
   ───────────────────────────────────────────────────────────── */

.chat-list .message.incoming {
    margin-top: 1.5rem !important;
    /* AI content is rendered HTML — never treat source whitespace as text,
       otherwise newlines between blocks show up as big empty gaps. */
    white-space: normal !important;
}

.chat-list .message.incoming .message-content {
    display: block !important;
    width: 100%;
    font-size: 15px;
}

/* Avatar column not used for AI rows */
.chat-list .message.incoming .avatar {
    display: none !important;
}

.chat-list .message.incoming .message-actions {
    margin-left: 0 !important;
    margin-top: 0.4rem;
    display: flex;
    gap: 5px;
    align-items: center;
}

/* Outgoing user bubble keeps its own spacing + preserves typed line breaks */
.chat-list .message.outgoing {
    margin-top: 26px !important;
}

.chat-list .message.outgoing .text {
    white-space: pre-wrap;
    line-height: 1.55;
}

/* ─────────────────────────────────────────────────────────────
   2. READING TEXT — concise, Claude-like
   ───────────────────────────────────────────────────────────── */

.chat-list .message.incoming .text,
.chat-list .message.incoming .stream-shell,
.chat-list .message.incoming .stream-body {
    white-space: normal !important;
    font-size: 15px;
    line-height: 1.68;
    letter-spacing: 0.001em;
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Shell is a simple vertical stack; spacing comes from each block's margin
   (using gap here caused inconsistent rhythm with mixed block types). */
.chat-list .message.incoming .stream-shell {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    width: 100%;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
}

.stream-body {
    display: block;
    min-width: 0;
    width: 100%;
}

/* Vertical rhythm inside AI replies */
.message-content .text p {
    margin: 0 0 0.7em;
}

.message-content .text> :last-child,
.stream-body> :last-child {
    margin-bottom: 0;
}

.message-content .text> :first-child,
.stream-body> :first-child {
    margin-top: 0;
}

.message-content .text h1 {
    font-size: 1.34em;
    font-weight: 600;
    line-height: 1.3;
    margin: 0.9em 0 0.45em;
}

.message-content .text h2 {
    font-size: 1.18em;
    font-weight: 600;
    line-height: 1.3;
    margin: 0.9em 0 0.4em;
}

.message-content .text h3 {
    font-size: 1.06em;
    font-weight: 600;
    line-height: 1.3;
    margin: 0.8em 0 0.35em;
}

.message-content .text ul,
.message-content .text ol {
    margin: 0.4em 0 0.7em;
    padding-left: 1.3em;
}

.message-content .text li {
    margin: 0.2em 0;
    max-width: 75ch;
}

.message-content .text code:not(.hljs) {
    font-size: 0.88em;
}

/* ─────────────────────────────────────────────────────────────
   3. STREAMING SEGMENTS — smooth append + soft bottom fade
   ───────────────────────────────────────────────────────────── */

.streaming-segment {
    display: block;
    width: 100%;
    min-width: 0;
    contain: layout style;
}

/* Settled blocks rise gently into place */
.frozen-segment {
    animation: streamRise 0.3s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes streamRise {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* The live tail softly fades its newest (bottom) line while streaming —
   the "text is materialising" feel. Removed automatically at stream end. */
.streaming-segment.is-streaming {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.35em), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 1.35em), transparent 100%);
}

/* Stream status ("Thinking…") + loader row */
.stream-status {
    margin: 2px 0 6px;
    min-height: 1.2rem;
    align-items: center;
}

.stream-status:not(.visible) {
    display: none;
}

.stream-status.visible {
    display: inline-flex;
}

.stream-loader {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    color: var(--placeholder-color);
    font-size: 13.5px;
}

.chat-list .message.loading .stream-loader {
    display: flex;
}

.stream-loader-spinner {
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

/* ── Delphos branded mini loader (normal chat) ──────────────────────────────
   A compact 15px SVG ring that spins with a sweeping arc in the brand cyan.
   Replaces the old three-dot "typing" indicator in normal Delphos chats and no
   longer lingers/glitches when a stream never starts (server closed / reload). */
.delphos-mini-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.delphos-mini-loader .dml-svg {
    width: 15px;
    height: 15px;
    animation: dmlRotate 1.4s linear infinite;
    transform-origin: center;
}

.delphos-mini-loader .dml-track {
    fill: none;
    stroke: var(--loader-border, rgba(255, 255, 255, 0.12));
    stroke-width: 3;
}

.delphos-mini-loader .dml-arc {
    fill: none;
    stroke: var(--accent-color, #22d3ee);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 44;
    stroke-dashoffset: 34;
    animation: dmlDash 1.4s ease-in-out infinite;
}

@keyframes dmlRotate { to { transform: rotate(360deg); } }

@keyframes dmlDash {
    0%   { stroke-dashoffset: 50; }
    50%  { stroke-dashoffset: 14; }
    100% { stroke-dashoffset: 50; }
}

/* ── Character chat indicator ────────────────────────────────────────────────
   A single soft "breathing" orb with a gentle expanding halo — simpler and
   calmer than the old triple-dot bounce. */
.char-typing {
    display: inline-flex;
    align-items: center;
    padding: 6px 2px;
}

.char-typing-orb {
    position: relative;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent-color, #22d3ee);
    animation: charOrbPulse 1.3s ease-in-out infinite;
}

.char-typing-orb::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--accent-color, #22d3ee);
    opacity: 0;
    animation: charOrbHalo 1.6s ease-out infinite;
}

@keyframes charOrbPulse {
    0%, 100% { transform: scale(0.8); opacity: 0.55; }
    50%      { transform: scale(1);   opacity: 1; }
}

@keyframes charOrbHalo {
    0%   { transform: scale(0.6); opacity: 0.5; }
    70%  { opacity: 0; }
    100% { transform: scale(1.9); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .delphos-mini-loader .dml-svg,
    .delphos-mini-loader .dml-arc { animation: none; }
    .char-typing-orb { animation: none; opacity: 0.7; }
    .char-typing-orb::after { animation: none; opacity: 0; }
}

/* WhatsApp / Instagram style "someone is typing" indicator — three dots that
   bounce in sequence inside a soft chat bubble. Replaces the old spinner logo
   + "typing..." text (which also double-stacked an animated ellipsis). */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 10px 13px;
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.06));
    border-radius: 16px;
    border-bottom-left-radius: 5px;
    width: fit-content;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--placeholder-color, #9b9b9b);
    opacity: 0.4;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ── "Load older messages" sentinel ─────────────────────────────────────────
   Shown at the very top of the chat list while older history pages remain
   unrendered. Clicking (or scrolling up to) it prepends the previous page. */
.chat-load-older {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 8px auto 14px;
    padding: 6px 14px;
    width: fit-content;
    max-width: 90%;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--placeholder-color, #9b9b9b);
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--loader-border, rgba(255, 255, 255, 0.06));
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease, color 0.18s ease;
}

.chat-load-older:hover {
    color: var(--heading-color, #fff);
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.09));
}

.chat-load-older .clo-spinner {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--loader-border, rgba(255, 255, 255, 0.18));
    border-top-color: var(--placeholder-color, #9b9b9b);
    animation: cloSpin 0.7s linear infinite;
    display: none;
}

.chat-load-older.is-loading {
    cursor: default;
}

.chat-load-older.is-loading .clo-spinner { display: inline-block; }
.chat-load-older.is-loading .clo-label { opacity: 0.7; }

@keyframes cloSpin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {

    .frozen-segment {
        animation: none;
    }

    .streaming-segment.is-streaming {
        -webkit-mask-image: none;
        mask-image: none;
    }

    .typing-dot {
        animation: none;
        opacity: 0.6;
    }

    .chat-load-older .clo-spinner { animation: none; }
}

/* On mobile the bottom-fade mask forces a compositing layer that re-rasterizes
   when it's removed at stream end, producing a small (3-4px) vertical jump
   between the user bubble and the reply. Disable the mask + the rise animation
   on touch/small screens so the reply settles in place with no shift. */
@media screen and (max-width: 768px) {

    .streaming-segment.is-streaming {
        -webkit-mask-image: none !important;
        mask-image: none !important;
    }

    .frozen-segment {
        animation: none !important;
    }
}

/* ─────────────────────────────────────────────────────────────
   4. THINKING BLOCK — quiet collapsible pill
   ───────────────────────────────────────────────────────────── */

.thinking-block {
    display: block;
    width: 100%;
    margin: 6px 0 10px !important;
    border-radius: 14px !important;
    background: rgba(124, 58, 237, 0.07) !important;
    border: 1px solid rgba(167, 139, 250, 0.18) !important;
    box-shadow: none !important;
    overflow: hidden !important;
    animation: blockFadeIn 0.25s ease !important;
}

.thinking-header {
    display: flex !important;
    align-items: center;
    gap: 8px;
    width: 100% !important;
    padding: 9px 14px !important;
    cursor: pointer;
    user-select: none;
    background: transparent;
    border: none;
    border-radius: 0;
    transition: background 0.18s ease;
}

.thinking-header:hover {
    background: rgba(167, 139, 250, 0.08) !important;
}

.thinking-icon {
    font-size: 15px;
    color: rgba(196, 181, 253, 0.9);
    flex-shrink: 0;
}

.thinking-label {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: rgba(226, 232, 240, 0.88);
    letter-spacing: 0.01em;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
    animation: none !important;
}

.thinking-toggle {
    font-size: 18px;
    color: rgba(160, 140, 220, 0.7);
    flex-shrink: 0;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.thinking-block.collapsed .thinking-toggle {
    transform: rotate(-90deg) !important;
}

.thinking-content {
    padding: 2px 14px 12px !important;
    font-size: 13px;
    color: rgba(203, 213, 225, 0.82);
    line-height: 1.7;
    max-height: 380px;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent !important;
    border: 0 !important;
    opacity: 1;
    transition:
        max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.28s ease,
        padding 0.28s ease !important;
}

.thinking-block.collapsed .thinking-content {
    max-height: 0 !important;
    opacity: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    overflow: hidden !important;
    pointer-events: none;
}

.thinking-content code.inline-code {
    background: rgba(124, 58, 237, 0.14);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: rgba(200, 180, 255, 0.9);
}

/* ─────────────────────────────────────────────────────────────
   5. TOOL CALL — flat Claude-style muted line
   ───────────────────────────────────────────────────────────── */

.tool-block {
    display: block !important;
    width: 100%;
    margin: 10px 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: none !important;
    box-shadow: none !important;
    position: relative;
    overflow: visible;
    animation: blockFadeIn 0.25s ease !important;
}

@keyframes blockFadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* The single muted line — aligned with the body text (no negative margin) */
.tool-block .tool-header {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    width: auto;
    max-width: 100%;
    margin: 0 !important;
    padding: 3px 0 !important;
    background: none !important;
    border: none !important;
    border-radius: 6px;
    color: var(--subheading-color, #9b9b9b);
    user-select: none;
    cursor: default;
    line-height: 1.4;
    transition: color 0.18s ease;
}

.tool-block.has-results .tool-header {
    cursor: pointer;
    margin-left: -2px !important;
}

.tool-block.has-results .tool-header:hover {
    color: var(--text-color);
}

/* Icon: fixed square box so any rotation stays centred */
.tool-block .tool-icon {
    font-size: 16px !important;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: currentColor;
    opacity: 0.72;
    transform-origin: 50% 50%;
    transition: opacity 0.18s ease;
}

.tool-block.has-results .tool-header:hover .tool-icon {
    opacity: 0.95;
}

/* Loading: hide the (possibly non-round) glyph and paint a clean spinner
   ring instead — a rotating shopping bag / pin looks bad, a ring doesn't. */
.tool-block.loading .tool-icon {
    position: relative;
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    animation: none !important;
}

.tool-block.loading .tool-icon::before {
    content: "" !important;
    position: absolute;
    inset: 1px;
    border-radius: 50%;
    border: 2px solid rgba(148, 163, 184, 0.28);
    border-top-color: rgba(196, 181, 253, 0.98);
    animation: toolRingSpin 0.7s linear infinite;
}

@keyframes toolRingSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Label text */
.tool-block .tool-label {
    font-size: 13.5px !important;
    font-weight: 400 !important;
    line-height: 1.4;
    color: var(--subheading-color, #9b9b9b) !important;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: none;
    background: none !important;
    -webkit-text-fill-color: currentColor !important;
}

.tool-block.done .tool-label {
    white-space: normal;
}

.tool-block .tool-label .tool-query,
.tool-block .tool-label .tool-count {
    color: var(--subheading-color, #8a8a8a) !important;
    opacity: 0.62 !important;
    font-weight: 400 !important;
    font-style: normal !important;
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Shimmer sweep on the label while the tool runs */
.tool-block .tool-label.shimmer-text {
    background: linear-gradient(110deg,
            var(--subheading-color, #8a8a8a) 30%,
            rgba(255, 255, 255, 0.95) 50%,
            var(--subheading-color, #8a8a8a) 70%) !important;
    background-size: 220% 100% !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    animation: shimmer 2s linear infinite !important;
    font-weight: 400 !important;
}

/* Chevron */
.tool-block .tool-toggle {
    font-size: 16px;
    color: var(--subheading-color, #9b9b9b);
    opacity: 0.55;
    flex-shrink: 0;
    transition: transform 0.22s ease, opacity 0.18s ease;
}

.tool-block.has-results .tool-header:hover .tool-toggle {
    opacity: 0.9;
}

.tool-block.results-open .tool-toggle {
    transform: rotate(180deg);
    opacity: 0.9;
}

.tool-block .hide {
    display: none !important;
}

/* ── Shimmering skeleton "lineup" shown while a tool runs ── */
.tool-skeleton {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin: 9px 0 2px;
    padding: 10px 12px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: 12px;
    animation: blockFadeIn 0.22s ease;
}

.tool-block.done .tool-skeleton {
    display: none;
}

.tool-skeleton .sk-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-skeleton .sk-dot,
.tool-skeleton .sk-line {
    background: linear-gradient(90deg,
            rgba(148, 163, 184, 0.10) 25%,
            rgba(148, 163, 184, 0.24) 37%,
            rgba(148, 163, 184, 0.10) 63%);
    background-size: 400% 100%;
    animation: skShimmer 1.3s ease-in-out infinite;
}

.tool-skeleton .sk-dot {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    flex-shrink: 0;
}

.tool-skeleton .sk-line {
    height: 10px;
    border-radius: 6px;
    flex: 1;
}

.tool-skeleton .sk-line.short {
    max-width: 52%;
}

.tool-skeleton .sk-row:nth-child(2) .sk-dot,
.tool-skeleton .sk-row:nth-child(2) .sk-line {
    animation-delay: 0.15s;
}

.tool-skeleton .sk-row:nth-child(3) .sk-dot,
.tool-skeleton .sk-row:nth-child(3) .sk-line {
    animation-delay: 0.3s;
}

@keyframes skShimmer {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: 0 0;
    }
}

/* ─────────────────────────────────────────────────────────────
   5b. LONG-RUNNING TOOL STEPPER (rich-PDF pipeline)
   A staged checklist shown while a multi-second tool runs, so the card
   never looks frozen. Done rungs show a tick; the active rung shows a calm
   thin spinner (no accent colour, no pulse, no shimmer).
   ───────────────────────────────────────────────────────────── */
.tool-steps {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 8px 0 2px;
    padding: 8px 12px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: 12px;
    animation: blockFadeIn 0.22s ease;
}

.tool-block.done .tool-steps {
    display: none;
}

.tstep {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 3px 0;
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--text-secondary, #8b93a1);
    opacity: 0.55;
    transition: opacity 0.25s ease, color 0.25s ease;
}

.tstep-dot {
    position: relative;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Live elapsed readout on a slow step ("Checking layout · 24s"). Tabular digits
   so the width doesn't jitter as it ticks; muted so it reads as a subtle hint. */
.tstep-elapsed {
    margin-left: 2px;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
    font-size: 0.92em;
}

.tstep-tick {
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Pending → dim outline dot. Active → a calm, slow spinner in the normal text
   colour. Done → a static tick, muted. No accent/green fills, no expanding
   "repulsion" ring, no shimmering label — the only motion is one thin spinner
   on the current step, so a long render reads as working rather than frozen. */
.tstep.active {
    opacity: 1;
    color: var(--text-color, #e7eaee);
}

.tstep.active .tstep-dot {
    border-color: currentColor;
    border-top-color: transparent;
    border-right-color: transparent;
    animation: tstepSpin 0.85s linear infinite;
}

.tstep.done {
    opacity: 1;
    color: var(--text-secondary, #8b93a1);
}

.tstep.done .tstep-dot {
    background: transparent;
    border-color: currentColor;
    color: var(--text-secondary, #8b93a1);
}

.tstep.done .tstep-tick {
    opacity: 1;
    transform: scale(1);
}

.tstep.done .tstep-label {
    color: var(--text-secondary, #8b93a1);
}

@keyframes tstepSpin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .tstep.active .tstep-dot {
        animation: none;
        border-color: currentColor;
    }
}

/* ─────────────────────────────────────────────────────────────
   6. TOOL RESULTS PANEL
   ───────────────────────────────────────────────────────────── */

.tool-block .tool-results {
    display: none;
    position: static !important;
    inset: auto !important;
    margin: 6px 0 2px !important;
    padding: 4px !important;
    background: none !important;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.09)) !important;
    border-radius: 12px !important;
    /* Roomy enough that a normal result set is not clipped. */
    max-height: min(60vh, 460px) !important;
    overflow-y: auto;
    box-shadow: none !important;
    min-width: 0;
    max-width: none !important;
    width: auto !important;
    z-index: auto !important;
}

.tool-block.results-open .tool-results {
    display: block;
    animation: toolResultsIn 0.2s ease;
}

@keyframes toolResultsIn {
    from {
        opacity: 0;
        transform: translateY(-3px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tool-block .results-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.tool-block .results-grid {
    display: grid;
    gap: 8px;
    padding: 4px;
}

/* Images scraped off a page are attached inside this panel (see
   _attachToolImages), so they inherit its display:none and only appear once the
   card is expanded. Override the tall horizontal strip that .images-sources uses
   in the message body with a compact square thumbnail grid. */
.tool-block .tool-results .images-sources.tool-images {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    height: auto !important;
    gap: 6px;
    margin: 0 !important;
    padding: 4px !important;
    overflow: visible !important;
}

.tool-block .tool-results .images-sources.tool-images .images-preview {
    margin: 0;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 10px;
    border-color: var(--border-color, rgba(255, 255, 255, 0.12));
}

.tool-block .tool-results .images-sources.tool-images .images-preview img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
}

/* ─────────────────────────────────────────────────────────────
   7. PER-KIND RESULT CARDS
   ───────────────────────────────────────────────────────────── */

/* WEB */
.web-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.14s ease;
}

.web-result:hover {
    background: rgba(148, 163, 184, 0.08);
}

.web-result .tool-result-favicon {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
    opacity: 0.9;
}

.web-result .web-result-text {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
    flex: 1;
    justify-content: space-between;
}

.web-result .tool-result-title {
    font-size: 13.5px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.web-result .tool-result-domain {
    font-size: 12px;
    color: var(--subheading-color, #8a8a8a);
    flex-shrink: 0;
    white-space: nowrap;
}

/* VIDEO */
.video-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.video-result {
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
}

.video-result .video-thumb-wrap {
    position: relative;
    display: block;
    border-radius: 10px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    background: rgba(0, 0, 0, 0.35);
}

.video-result .video-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.25s ease;
}

.video-result:hover .video-thumb {
    transform: scale(1.04);
}

.video-result .video-play {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 40px;
    height: 40px;
    font-size: 40px;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.video-result .video-duration {
    position: absolute;
    right: 6px;
    bottom: 6px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 10.5px;
    padding: 1px 5px;
    border-radius: 4px;
}

.video-result .video-title {
    font-size: 12.5px;
    color: var(--text-color);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-result .video-channel {
    font-size: 11px;
    color: var(--subheading-color, #8a8a8a);
}

/* video-result.playing no longer used — videos open in modal */

/* SHOPPING */
.shop-result {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    transition: background 0.14s ease;
}

.shop-result:hover {
    background: rgba(148, 163, 184, 0.07);
}

.shop-img {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
    padding: 3px;
}

.shop-img-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: rgba(148, 163, 184, 0.1);
    color: var(--subheading-color);
}

.shop-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1;
}

.shop-name {
    font-size: 13px;
    color: var(--text-color);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.shop-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
}

.shop-rating {
    color: var(--subheading-color);
}

.shop-reviews {
    color: var(--subheading-color);
    opacity: 0.7;
}

.shop-badge {
    font-size: 10.5px;
    font-weight: 500;
    padding: 1px 8px;
    border-radius: 5px;
    background: rgba(148, 163, 184, 0.14);
    color: var(--subheading-color);
}

.shop-price-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.shop-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.shop-mrp {
    font-size: 12px;
    color: var(--subheading-color);
    opacity: 0.65;
    text-decoration: line-through;
}

.shop-buy {
    margin-left: auto;
    font-size: 12px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 7px;
    text-decoration: none;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    color: var(--text-color);
    transition: background 0.14s ease;
}

.shop-buy:hover {
    background: rgba(148, 163, 184, 0.12);
}

/* PLACES */
.place-result {
    display: flex;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 9px;
    transition: background 0.14s ease;
}

.place-result:hover {
    background: rgba(148, 163, 184, 0.07);
}

.place-pin {
    font-size: 19px;
    color: var(--subheading-color);
    opacity: 0.8;
    flex-shrink: 0;
}

.place-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.place-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-color);
}

.place-addr {
    font-size: 12px;
    color: var(--subheading-color);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.place-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 2px;
    font-size: 12px;
}

.place-rating {
    color: var(--subheading-color);
}

.place-map {
    font-weight: 500;
    color: var(--text-color);
    opacity: 0.85;
    text-decoration: none;
}

.place-map:hover {
    text-decoration: underline;
}

/* IMAGES */
.img-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
}

.img-result {
    display: block;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.25);
    /* Rendered as a <button> (opens the image lab, never a link), so strip the
       native control chrome and keep it looking like the tile it always was. */
    padding: 0;
    border: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.img-result img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
    pointer-events: none;
}

.img-result:hover img {
    transform: scale(1.05);
}

/* ─────────────────────────────────────────────────────────────
   8. INLINE MEDIA (images grid / video embed / mermaid)
   ───────────────────────────────────────────────────────────── */

.ai-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.ai-grid-img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.ai-grid-img:hover {
    transform: scale(1.03);
    opacity: 0.92;
}

/* Image-search tiles are buttons (not links): the click opens the AI Image Lab
   viewer, so no raw URL is ever exposed. A hover chip names the source site. */
.ai-grid-tile {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.ai-grid-tile .ai-grid-img {
    pointer-events: none;
    border-radius: 8px;
}

.ai-grid-cap {
    position: absolute;
    left: 6px;
    bottom: 6px;
    max-width: calc(100% - 12px);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px 2px 5px;
    font-size: 11px;
    line-height: 1.5;
    color: #fff;
    background: rgba(0, 0, 0, 0.62);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.ai-grid-tile:hover .ai-grid-cap,
.ai-grid-tile:focus-visible .ai-grid-cap {
    opacity: 1;
    transform: translateY(0);
}

.ai-grid-cap .material-symbols-rounded {
    font-size: 13px;
    line-height: 1;
}

.ai-video-embed {
    margin: 14px 0;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: #000;
    aspect-ratio: 16/9;
    width: 100%;
    max-width: 680px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.ai-video-embed iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
}

/* Sources button under a reply */
.source-button {
    margin-top: 12px;
    padding: 6px 16px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-color);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.1s ease;
}

.source-button:hover {
    background: rgba(167, 139, 250, 0.16);
    border-color: rgba(167, 139, 250, 0.4);
}

.source-button:active {
    transform: scale(0.97);
}

/* E2B sandbox execution results */
.tool-block.sandbox-delivery .tool-results {
    border-color: rgba(139, 92, 246, 0.35) !important;
    background: linear-gradient(135deg, rgba(76, 29, 149, 0.12), rgba(15, 23, 42, 0.16)) !important;
}

.sandbox-result-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 5px;
}

.sandbox-delivery-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid rgba(167, 139, 250, 0.32);
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.22), rgba(79, 70, 229, 0.10));
}

.sandbox-delivery-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 9px;
    background: rgba(196, 181, 253, 0.16);
    color: #ddd6fe;
}

.sandbox-delivery-copy {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
}

.sandbox-delivery-copy strong {
    color: var(--text-color, #f8fafc);
    font-size: 13px;
    line-height: 1.2;
}

.sandbox-delivery-copy span {
    overflow: hidden;
    color: #c4b5fd;
    font-size: 11px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sandbox-artifact-count {
    min-width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 999px;
    background: rgba(221, 214, 254, 0.18);
    color: #ede9fe;
    font-size: 12px;
    font-weight: 700;
}

.sandbox-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
    padding: 3px 6px;
    color: var(--subheading-color, #9b9b9b);
    font-size: 11px;
    text-transform: capitalize;
}

.sandbox-status .material-symbols-rounded {
    font-size: 15px;
}

.sandbox-output {
    max-height: 220px;
    margin: 0;
    padding: 10px 12px;
    overflow: auto;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 9px;
    background: rgba(2, 6, 23, 0.72);
    color: #d1d5db;
    font-size: 11.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.sandbox-artifacts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.sandbox-artifact {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(167, 139, 250, 0.20);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.36);
    transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.sandbox-artifact:hover {
    border-color: rgba(167, 139, 250, 0.48);
    background: rgba(76, 29, 149, 0.14);
    transform: translateY(-1px);
}

.sandbox-file-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 8px;
    background: rgba(124, 58, 237, 0.16);
    color: #c4b5fd;
}

.sandbox-shot {
    width: 74px;
    height: 52px;
    padding: 0;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid rgba(167, 139, 250, 0.24);
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.75);
    color: var(--subheading-color, #9b9b9b);
    cursor: pointer;
}

.sandbox-shot img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.sandbox-shot-loading {
    font-size: 9px;
}

.sandbox-artifact-info {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
}

.sandbox-artifact-name {
    overflow: hidden;
    color: var(--text-color);
    font-size: 12.5px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sandbox-artifact-meta {
    overflow: hidden;
    color: var(--subheading-color, #8a8a8a);
    font-size: 10.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sandbox-download {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0;
    padding: 0 9px;
    border: 1px solid rgba(167, 139, 250, 0.32);
    border-radius: 7px;
    background: rgba(124, 58, 237, 0.15);
    color: #ddd6fe;
    font-size: 11px;
    font-weight: 650;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.sandbox-download .material-symbols-rounded {
    font-size: 16px;
}

.sandbox-download:hover {
    border-color: rgba(196, 181, 253, 0.72);
    background: rgba(124, 58, 237, 0.34);
    color: #fff;
}

.sandbox-download:active {
    transform: scale(0.97);
}

.sandbox-download:disabled {
    cursor: wait;
    opacity: 0.45;
}

/* Live "writing files" code box (Claude-style) */
.sandbox-codebox {
    margin: 12px 0;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    background: var(--disabled-color, rgba(255, 255, 255, 0.03));
    overflow: hidden;
    animation: blockFadeIn 0.25s ease;
    transform: translateZ(0);
}

/* "Run" button in the code box header. Defined here (not injected on click) so
   it is fully styled the moment it is rendered — never a bare white rectangle. */
.sandbox-code-run {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 13px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.35);
    transition: filter 0.15s ease, transform 0.1s ease;
}

.sandbox-code-run:hover { filter: brightness(1.08); }
.sandbox-code-run:active { transform: scale(0.97); }

.sandbox-code-run .material-symbols-rounded {
    font-size: 16px;
    line-height: 1;
}

/* ── Interactive ARTIFACT box (Claude-style) — a compact card in the reply
   that opens a live, previewable app in the Canvas. ─────────────────────── */
.sandbox-codebox.sbx-artifact {
    border-color: color-mix(in srgb, var(--accent, #7c3aed) 42%, transparent);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--accent, #7c3aed) 12%, transparent), transparent 60%),
        var(--disabled-color, rgba(255, 255, 255, 0.03));
    box-shadow: 0 8px 26px -18px rgba(124, 58, 237, 0.5);
}
.sbx-artifact .sandbox-code-header {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent, #7c3aed) 20%, transparent), transparent 70%);
}
.sbx-artifact .sandbox-code-icon { color: var(--accent, #7c3aed); }
/* "Editing…" state: the leading icon spins while the change streams in. */
.sandbox-codebox.sbx-editing .sandbox-code-icon {
    color: var(--accent, #7c3aed);
    animation: sbxSpin 0.9s linear infinite;
}
@keyframes sbxSpin { to { transform: rotate(360deg); } }
/* A little "Interactive" pill next to the title. */
.sbx-artifact-tag {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 999px;
    color: var(--accent, #7c3aed);
    background: color-mix(in srgb, var(--accent, #7c3aed) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent, #7c3aed) 34%, transparent);
}
/* The primary "Open" button on an artifact card — matches the sandbox Run btn. */
.sbx-artifact-open {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 13px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.35);
    transition: filter 0.15s ease, transform 0.1s ease;
}
.sbx-artifact-open:hover { filter: brightness(1.08); }
.sbx-artifact-open:active { transform: scale(0.97); }
.sbx-artifact-open .material-symbols-rounded { font-size: 15px; line-height: 1; }

/* ── Incomplete (cut-off) artifact ── */
.sandbox-codebox.sbx-incomplete {
    border-color: color-mix(in srgb, #f59e0b 55%, transparent);
    background:
        linear-gradient(180deg, color-mix(in srgb, #f59e0b 8%, transparent), transparent 60%);
}
.sbx-incomplete .sandbox-code-header {
    background: linear-gradient(135deg, color-mix(in srgb, #f59e0b 20%, transparent), transparent 70%);
}
.sbx-incomplete .sandbox-code-icon { color: #f59e0b; }
.sbx-incomplete .sbx-artifact-tag { background: color-mix(in srgb, #f59e0b 22%, transparent); color: #f59e0b; }
/* Continue button — amber, sits just before Open on an incomplete card. */
.sbx-artifact-continue {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 13px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
    transition: filter 0.15s ease, transform 0.1s ease;
}
.sbx-artifact-continue:hover { filter: brightness(1.08); }
.sbx-artifact-continue:active { transform: scale(0.97); }
.sbx-artifact-continue .material-symbols-rounded { font-size: 15px; line-height: 1; }
/* With a Continue button present, Open loses the auto-margin (Continue owns it). */
.sbx-incomplete .sbx-artifact-continue + .sbx-artifact-open { margin-left: 6px; }
/* Retry on a patch that didn't apply — same amber treatment as Continue. */
.sbx-artifact-retry .material-symbols-rounded { font-size: 15px; line-height: 1; }

/* ── Artifact update diff bar (Accept / Reject) ── */
.dc-diff-bar {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translate(-50%, 140%);
    z-index: 2147483200;
    width: min(560px, calc(100vw - 32px));
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 14px;
    background: var(--surface-color, #16161d);
    box-shadow: 0 18px 60px -20px rgba(0, 0, 0, 0.65);
    opacity: 0;
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.24s ease;
}
.dc-diff-bar.show { transform: translate(-50%, 0); opacity: 1; }
.dc-diff-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dc-diff-head .material-symbols-rounded { font-size: 18px; color: var(--accent, #7c3aed); }
.dc-diff-title { flex: 1 1 auto; font-size: 13.5px; font-weight: 600; color: var(--text-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-diff-total, .dc-diff-nums { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; }
.dc-diff-add { color: #3fb950; font-weight: 700; }
.dc-diff-rem { color: #f85149; font-weight: 700; }
.dc-diff-files { display: flex; flex-direction: column; gap: 3px; max-height: 132px; overflow-y: auto; margin-bottom: 10px; }
.dc-diff-file {
    display: flex; align-items: center; gap: 8px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px; color: var(--subheading-color, #b8b8c0);
    padding: 2px 0;
}
.dc-diff-file em { font-style: normal; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 6px; border-radius: 5px; background: var(--accent-soft, rgba(124, 58, 237, 0.18)); color: var(--accent, #a855f7); }
.dc-diff-file .dc-diff-nums { margin-left: auto; }
.dc-diff-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dc-diff-actions button { padding: 7px 15px; border-radius: 9px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: filter 0.15s ease, background 0.15s ease; }
.dc-diff-reject { border: 1px solid var(--border-color, rgba(255, 255, 255, 0.14)); background: transparent; color: var(--subheading-color, #b8b8c0); }
.dc-diff-reject:hover { background: rgba(248, 81, 73, 0.12); color: #f85149; border-color: rgba(248, 81, 73, 0.4); }
.dc-diff-accept { border: none; background: linear-gradient(135deg, #7c3aed, #a855f7); color: #fff; }
.dc-diff-accept:hover { filter: brightness(1.08); }

/* ── Review-comment chips in the composer ── */
.dc-review-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px 2px;
    width: 100%;
    box-sizing: border-box;
}
.dc-review-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 320px;
    padding: 4px 6px 4px 9px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 9px;
    background: var(--disabled-color, rgba(255, 255, 255, 0.05));
    font-size: 12px;
    color: var(--text-color);
}
.dc-review-chip .dc-rc-ic { font-size: 15px; color: var(--accent, #7c3aed); flex: 0 0 auto; }
.dc-review-chip .dc-rc-loc {
    flex: 0 0 auto;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--accent, #a855f7);
    background: var(--accent-soft, rgba(124, 58, 237, 0.16));
    padding: 1px 6px;
    border-radius: 5px;
}
.dc-review-chip .dc-rc-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.9; }
.dc-review-chip .dc-rc-del {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: var(--subheading-color, #9a9aa2);
    font-size: 16px;
    line-height: 1;
    width: 18px; height: 18px;
    border-radius: 5px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.dc-review-chip .dc-rc-del:hover { background: rgba(248, 81, 73, 0.16); color: #f85149; }
/* When the Open button provides the primary affordance, the tag sits before it
   and the auto-margin belongs to the button. */
.sbx-artifact .sbx-artifact-tag { margin-left: 8px; }

.sandbox-code-header {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 13px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    background:
        linear-gradient(135deg, var(--accent-soft, rgba(99, 102, 241, 0.14)), transparent 70%);
    transition: background 0.18s ease;
}

.sandbox-code-header:hover {
    background:
        linear-gradient(135deg, var(--accent-soft, rgba(99, 102, 241, 0.2)), transparent 60%);
}

.sandbox-codebox.collapsed .sandbox-code-header {
    border-bottom-color: transparent;
}

.sandbox-code-icon {
    font-size: 18px;
    color: var(--accent, #6366f1);
}

.sandbox-code-label {
    flex: 1;
    min-width: 0;
    color: var(--text-color);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sandbox-code-live {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--accent-soft, rgba(99, 102, 241, 0.14));
    color: var(--accent, #6366f1);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sandbox-code-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent, #6366f1);
    animation: sandbox-code-pulse 1.3s ease-in-out infinite;
}

@keyframes sandbox-code-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.7); }
}

.sandbox-code-chevron {
    font-size: 20px;
    color: var(--subheading-color, #9b9b9b);
    transition: transform 0.2s ease;
}

.sandbox-codebox.collapsed .sandbox-code-chevron {
    transform: rotate(-90deg);
}

/* Single scroll container for all files — no nested scrollbars. */
.sandbox-code-body {
    max-height: 460px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    transition: max-height 0.22s ease;
}

.sandbox-codebox.collapsed .sandbox-code-body {
    max-height: 0;
    overflow: hidden;
}

/* ── File tab bar (switch between files, VS Code style) ── */
.sbx-tabs {
    display: flex;
    align-items: stretch;
    gap: 2px;
    padding: 6px 8px 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    background: var(--disabled-color, rgba(255, 255, 255, 0.02));
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}

.sandbox-codebox.collapsed .sbx-tabs {
    display: none;
}

.sbx-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    max-width: 220px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 6px 11px;
    cursor: pointer;
    background: transparent;
    color: var(--subheading-color, #9b9b9b);
    font-size: 11.5px;
    font-weight: 600;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.sbx-tab:hover {
    background: var(--accent-soft, rgba(99, 102, 241, 0.1));
    color: var(--text-color);
}

.sbx-tab.active {
    background: var(--disabled-color, rgba(255, 255, 255, 0.05));
    border-color: var(--border-color, rgba(255, 255, 255, 0.1));
    color: var(--text-color);
}

.sbx-tab-ic {
    font-size: 15px;
    color: var(--accent, #6366f1);
    flex-shrink: 0;
}

.sbx-tab-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sbx-tab-lang {
    flex-shrink: 0;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--accent-soft, rgba(99, 102, 241, 0.16));
    color: var(--accent, #8b8bff);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

/* ── Panes: only the active file is shown ── */
.sbx-pane { display: none; }
.sbx-pane.active { display: block; }

.sbx-editor {
    display: flex;
    align-items: flex-start;
    padding: 14px 0;
    background: rgba(0, 0, 0, 0.14);
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.65;
    tab-size: 2;
}

/* Line-number gutter (write mode). Numbers are generated from the rendered
   code, so they always match the lines they sit beside. */
.sbx-gutter {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 34px;
    padding: 0 12px 0 16px;
    text-align: right;
    color: var(--subheading-color, #6b6b6b);
    opacity: 0.5;
    user-select: none;
    border-right: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}

.sbx-gutter span {
    display: block;
    height: 21px;
    line-height: 21px;
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.sbx-pre {
    flex: 1 1 auto;
    margin: 0;
    padding: 0 16px;
    overflow-x: auto;
    background: transparent;
    white-space: pre;
    tab-size: 2;
}

.sbx-code {
    display: block;
    background: transparent !important;
    padding: 0 !important;
    color: var(--text-color);
    font-family: inherit;
    font-size: 12.5px;
    line-height: 21px;
}

/* highlight.js emits nested spans; keep them on the same 21px line grid so the
   gutter numbers line up exactly with each row of code. */
.sbx-code span { line-height: inherit; }

/* ── Diff view (edit mode) ── */
.sbx-diff { padding: 8px 0; display: block; }
.sbx-diffbody { display: block; overflow-x: auto; }

.sbx-dl {
    display: flex;
    align-items: flex-start;
    white-space: pre;
    line-height: 1.6;
}

.sbx-sign {
    flex: 0 0 auto;
    width: 22px;
    text-align: center;
    user-select: none;
    opacity: 0.8;
    font-weight: 700;
}

.sbx-dlc {
    flex: 1 1 auto;
    padding-right: 14px;
    color: var(--text-color);
}

.sbx-add { background: rgba(46, 160, 67, 0.14); }
.sbx-add .sbx-sign { color: #3fb950; }
.sbx-del { background: rgba(248, 81, 73, 0.14); }
.sbx-del .sbx-sign { color: #f85149; }

.sbx-sep {
    height: 10px;
    border-top: 1px dashed var(--border-color, rgba(255, 255, 255, 0.12));
    margin: 4px 0;
}

@media (max-width: 480px) {
    .sbx-code, .sbx-dlc, .sbx-editor { font-size: 11.5px; }

    .sandbox-artifacts {
        grid-template-columns: 1fr;
    }
    .sandbox-artifacts {
        grid-template-columns: 1fr;
    }

    .sandbox-artifact {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .sandbox-download {
        width: 100%;
        margin-left: 48px;
    }

    .sandbox-shot + .sandbox-artifact-info + .sandbox-download {
        margin-left: 84px;
    }
}

/* ── Conversation compaction marker ─────────────────────────────────────────
   Shown where a chat was compacted. The summary itself is hidden (used only
   server-side to ground the model); this is just a subtle centered italic note
   sitting between two faint divider lines. */
.compaction-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 760px;
    margin: 20px auto;
    padding: 0 8px;
    user-select: none;
    pointer-events: none;
}
.compaction-marker::before,
.compaction-marker::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border-color, rgba(140, 140, 140, 0.35)), transparent);
}
.compaction-marker-text {
    flex: 0 0 auto;
    font-style: italic;
    font-size: 12.5px;
    line-height: 1;
    white-space: nowrap;
    color: var(--subheading-color, #8a8a8a);
    opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════════════════
   9. MARKDOWN ELEMENTS — professional, Claude/ChatGPT-grade typography
   These fill the gaps that made replies look "raw": links, blockquotes,
   tables, rules, inline code chips, keyboard keys, and tidy nested lists.
   Scoped to AI (incoming) replies via `.message-content .text` so user
   bubbles and other UI are untouched.
   ═══════════════════════════════════════════════════════════════════════ */

/* Links — accent coloured, underline only on hover (calm until intentional) */
.message-content .text a {
    color: var(--accent, #b7795c);
    text-decoration: none;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    border-radius: 2px;
    transition: color 0.14s ease, text-decoration-color 0.14s ease;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message-content .text a:hover {
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--accent, #b7795c) 60%, transparent);
    color: var(--accent-strong, #975d46);
}

.message-content .text a:focus-visible {
    outline: 2px solid var(--accent-ring, rgba(183, 121, 92, 0.4));
    outline-offset: 2px;
}

/* Emphasis */
.message-content .text strong,
.message-content .text b {
    font-weight: 650;
    color: var(--text-color);
}

.message-content .text em,
.message-content .text i {
    font-style: italic;
}

.message-content .text del,
.message-content .text s {
    color: var(--subheading-color, #8a8a8a);
}

/* Inline code — subtle chip that reads as code without shouting */
.message-content .text code:not(.hljs) {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
    padding: 0.12em 0.4em;
    border-radius: 6px;
    background: color-mix(in srgb, var(--secondary-color, #2a2927) 78%, transparent);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    color: color-mix(in srgb, var(--text-color, #eee) 92%, var(--accent, #b7795c));
    word-break: break-word;
    white-space: break-spaces;
}

/* Keyboard keys */
.message-content .text kbd {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.8em;
    line-height: 1;
    padding: 0.22em 0.5em;
    border-radius: 6px;
    background: var(--secondary-color, #2a2927);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.14));
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
    color: var(--text-color);
    white-space: nowrap;
}

/* Highlight */
.message-content .text mark {
    background: color-mix(in srgb, var(--accent, #b7795c) 26%, transparent);
    color: var(--text-color);
    padding: 0.02em 0.24em;
    border-radius: 4px;
}

/* Headings — a touch more presence + a hairline under h1/h2 for structure */
.message-content .text h1,
.message-content .text h2,
.message-content .text h3,
.message-content .text h4,
.message-content .text h5,
.message-content .text h6 {
    color: var(--text-color);
    letter-spacing: -0.01em;
}

.message-content .text h1 { padding-bottom: 0.28em; border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1)); }
.message-content .text h2 { padding-bottom: 0.22em; border-bottom: 1px solid color-mix(in srgb, var(--border-color, rgba(255,255,255,0.1)) 70%, transparent); }
.message-content .text h4 { font-size: 0.98em; font-weight: 650; margin: 0.8em 0 0.3em; }
.message-content .text h5,
.message-content .text h6 { font-size: 0.9em; font-weight: 650; color: var(--subheading-color, #98a2b3); margin: 0.7em 0 0.3em; text-transform: none; }

/* Lists — comfortable markers + correct nested rhythm */
.message-content .text ul { list-style: disc; }
.message-content .text ul ul { list-style: circle; }
.message-content .text ul ul ul { list-style: square; }
.message-content .text ol { list-style: decimal; }

.message-content .text li::marker {
    color: var(--subheading-color, #98a2b3);
}

.message-content .text li > ul,
.message-content .text li > ol {
    margin: 0.25em 0 0.3em;
}

.message-content .text li > p { margin: 0 0 0.35em; }

/* GitHub-style task lists */
.message-content .text li.task-list-item,
.message-content .text li:has(> input[type="checkbox"]) {
    list-style: none;
    margin-left: -1.15em;
    padding-left: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.5em;
}

.message-content .text input[type="checkbox"] {
    margin-top: 0.32em;
    width: 15px;
    height: 15px;
    accent-color: var(--accent, #b7795c);
    flex-shrink: 0;
}

/* Blockquote — quiet left rule, softened text, subtle inset */
.message-content .text blockquote {
    margin: 0.8em 0;
    padding: 0.5em 0 0.5em 1em;
    border-left: 3px solid color-mix(in srgb, var(--accent, #b7795c) 55%, transparent);
    background: color-mix(in srgb, var(--secondary-color, #2a2927) 45%, transparent);
    border-radius: 0 10px 10px 0;
    color: color-mix(in srgb, var(--text-color, #eee) 82%, var(--subheading-color, #98a2b3));
}

.message-content .text blockquote > :first-child { margin-top: 0; }
.message-content .text blockquote > :last-child { margin-bottom: 0; }
.message-content .text blockquote blockquote {
    margin: 0.5em 0;
    border-left-color: color-mix(in srgb, var(--accent, #b7795c) 35%, transparent);
}

/* Horizontal rule — a clean divider, not a heavy black line */
.message-content .text hr {
    height: 1px;
    border: 0;
    margin: 1.35em 0;
    background: linear-gradient(to right, transparent, var(--border-color, rgba(255, 255, 255, 0.16)) 15%, var(--border-color, rgba(255, 255, 255, 0.16)) 85%, transparent);
}

/* Tables — 100% full-width, clean borders, zebra rows, elegant typography */
.message-content .text table {
    width: 100% !important;
    max-width: 100% !important;
    margin: 1em 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    font-size: 0.92em !important;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12)) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    display: table !important;
    table-layout: auto !important;
    background: var(--card-bg, rgba(255, 255, 255, 0.025)) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18) !important;
}

.message-content .text thead th {
    background: var(--light-dark-background, rgba(255, 255, 255, 0.06)) !important;
    color: var(--text-color, #fff) !important;
    font-weight: 650 !important;
    font-size: 0.92em !important;
    letter-spacing: 0.02em !important;
    text-align: left !important;
    white-space: nowrap !important;
}

.message-content .text th,
.message-content .text td {
    padding: 10px 14px !important;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.06)) !important;
    border-right: 1px solid var(--border-color, rgba(255, 255, 255, 0.04)) !important;
    vertical-align: middle !important;
    line-height: 1.5 !important;
}

.message-content .text th:last-child,
.message-content .text td:last-child { border-right: none !important; }
.message-content .text tbody tr:last-child td { border-bottom: none !important; }

.message-content .text tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.018) !important;
}

.message-content .text tbody tr:hover td {
    background: var(--accent-soft, rgba(124, 58, 237, 0.08)) !important;
}

/* A stray <pre> that isn't wrapped by .code-wrapper still needs to read as code
   (the wrapped case is styled in style.css). */
.message-content .text pre:not(.code-wrapper pre):not(.sbx-pre) {
    margin: 0.9em 0;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--disabled-color, rgba(0, 0, 0, 0.28));
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    overflow-x: auto;
    font-size: 0.86em;
    line-height: 1.6;
}

/* Images embedded in prose */
.message-content .text img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    margin: 0.5em 0;
}

/* Definition lists (rare, but render cleanly when they appear) */
.message-content .text dl { margin: 0.6em 0; }
.message-content .text dt { font-weight: 650; color: var(--text-color); margin-top: 0.5em; }
.message-content .text dd { margin: 0.1em 0 0.4em 1.1em; color: color-mix(in srgb, var(--text-color, #eee) 85%, var(--subheading-color, #98a2b3)); }

/* Footnote-style superscripts */
.message-content .text sup a { font-size: 0.8em; }

@media (max-width: 600px) {
    .message-content .text table { font-size: 0.86em; }
    .message-content .text th,
    .message-content .text td { padding: 7px 10px; }
    .message-content .text blockquote { padding-left: 0.8em; }
}
