/* chat-modern split: tokens, conversation canvas, message bubbles,
   hover actions and timestamps. Loaded first. */

/* Modern chat surface — loaded after the chat partial so these rules win.
   Deliberately theme-independent: a calm neutral canvas + brand green accent.
   Scoped to #chat-app (conversation) and the rail/window shell around it. */

#chat-app,
.chat-sidebar {
    --gb-bg: #fafafa;
    --gb-surface: #ffffff;
    --gb-surface-muted: #f4f4f5;
    --gb-text: #18181b;
    --gb-muted: #71717a;
    /* Borders are true grays, never black and never a black alpha: a 8%
       black alpha still reads as a hard line on white. */
    --gb-border: #e4e4e7;
    --gb-border-soft: #ececef;
    --gb-border-strong: #d4d4d8;
    --gb-accent: #16a34a;
    --gb-accent-soft: rgba(22, 163, 74, 0.10);
    --gb-shadow-bubble: 0 1px 2px rgba(16, 24, 40, 0.04);
    --gb-shadow-raised: 0 8px 24px rgba(16, 24, 40, 0.07);
    --gb-focus-ring: 0 0 0 3px rgba(22, 163, 74, 0.14);
}

#chat-app {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
        "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    color: var(--gb-text);
    background: var(--gb-bg);
    /* One accent for the whole conversation. The legacy chat styles still
       read --accent/--primary, which used to resolve to the suite blue while
       the modern chrome was green — two brands in one window. */
    --accent: var(--gb-accent);
    --primary: var(--gb-accent);
    --suggestion-color: var(--gb-accent);
    /* Markdown tables read this theme variable, which stays suite-blue
       globally; inside the conversation it must follow the chat accent. */
    --chat-color1: var(--gb-accent);
}

/* ── Conversation canvas ───────────────────────────────────────────── */

#chat-app #messages {
    padding: 26px 30px 18px;
    gap: 14px;
    background: var(--gb-bg);
    scrollbar-color: rgba(24, 24, 27, 0.2) transparent;
}

#chat-app #messages::-webkit-scrollbar-thumb {
    background: rgba(24, 24, 27, 0.18) !important;
    border-radius: 3px;
}

#chat-app .message {
    max-width: min(760px, 78%);
    position: relative;
    animation: gbMsgIn 180ms ease-out;
}

/* Conversation rhythm: a new speaker starts a new group. Messages from the
   same speaker stay close together, which is what makes a transcript read as
   a conversation instead of a list. */
#chat-app .message + .message { margin-top: 2px; }
#chat-app .message.user + .message.bot,
#chat-app .message.bot + .message.user { margin-top: 14px; }

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

#chat-app .message-content {
    padding: 13px 17px;
    border-radius: 18px;
    font-size: 14.5px;
    line-height: 1.58;
    letter-spacing: 0.003em;
}

/* User bubble: neutral surface with an explicit gray border. The saturated
   accent fill made every message shout and dated the surface. */
#chat-app .user-message {
    background: var(--gb-surface-muted);
    color: var(--gb-text);
    border: 1px solid var(--gb-border);
    border-radius: 18px 18px 6px 18px;
    box-shadow: none;
}

#chat-app .user-message a,
#chat-app .user-message strong,
#chat-app .user-message code {
    color: var(--gb-text);
}

#chat-app .bot-message {
    background: var(--gb-surface);
    border: 1px solid var(--gb-border-soft);
    border-radius: 18px 18px 18px 6px;
    box-shadow: var(--gb-shadow-bubble);
}

/* Hover timestamp: quiet, secondary metadata that appears only when the
   reader is looking at a specific message. */
#chat-app .message::after {
    content: attr(data-time);
    position: absolute;
    top: -15px;
    left: 4px;
    font-size: 10.5px;
    line-height: 1;
    color: #a1a1aa;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 140ms ease, transform 140ms ease;
    pointer-events: none;
    white-space: nowrap;
}
#chat-app .message.user::after {
    left: auto;
    right: 4px;
}
#chat-app .message:hover::after { opacity: 1; transform: translateY(0); }

/* The listen action belongs to the message, not to the transcript: keep it
   beside the bubble and reveal it on hover/focus instead of parking a gray
   pill below every answer. */
#chat-app .message.bot {
    flex-direction: row;
    /* #1693 — the live preview is its own row; without wrapping it competes
       with the bubble for horizontal space and collapses to a sliver. */
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 6px;
}

/* #1693 — a generated drawing previews under the bubble, never beside it. */
#chat-app .gb-live-artifact {
    order: 4;
    flex: 1 0 100%;
    min-width: 0;
}
#chat-app .tts-speak-btn,
#chat-app .copy-msg-btn {
    order: 2;
    margin: 0 0 4px 0;
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--gb-border);
    border-radius: 50%;
    background: var(--gb-surface);
    color: var(--gb-muted);
    cursor: pointer;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 140ms ease, transform 140ms ease,
        color 140ms ease, border-color 140ms ease,
        background 140ms ease;
}
#chat-app .copy-msg-btn { order: 3; }
#chat-app .message.bot:hover .tts-speak-btn,
#chat-app .message.bot:hover .copy-msg-btn,
#chat-app .tts-speak-btn:focus-visible,
#chat-app .copy-msg-btn:focus-visible {
    opacity: 1;
    transform: translateX(0);
}
#chat-app .tts-speak-btn:hover,
#chat-app .copy-msg-btn:hover {
    color: var(--gb-accent);
    border-color: rgba(22, 163, 74, 0.45);
    background: var(--gb-surface);
}
#chat-app .copy-msg-btn.copied {
    color: var(--gb-accent);
    border-color: rgba(22, 163, 74, 0.45);
}
@media (hover: none) {
    #chat-app .tts-speak-btn,
    #chat-app .copy-msg-btn { opacity: 1; transform: none; }
}

/* Neutral transcript text: the theme's green-tinted body text made the
   conversation look like a different product from the gray user bubble. */
#chat-app .bot-message,
#chat-app .bot-message p,
#chat-app .bot-message span,
#chat-app .bot-message li,
#chat-app .bot-message strong,
#chat-app .bot-message em,
#chat-app .bot-message h1,
#chat-app .bot-message h2,
#chat-app .bot-message h3,
#chat-app .bot-message h4 {
    color: var(--gb-text) !important;
}

#chat-app .bot-message a {
    color: #15803d !important;
}

/* Historical reasoning-only completions were persisted as empty bot
   messages; an empty bordered bubble collapses to a 1px horizontal line.
   Hide the message entirely instead of painting that artifact. */
#chat-app .message.bot:has(> .bot-message:empty) { display: none; }

#chat-app .bot-message > *:first-child { margin-top: 0; }
#chat-app .bot-message > *:last-child { margin-bottom: 0; }

#chat-app .bot-message pre {
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12.5px;
    background: #f4f4f5;
    color: #27272a;
}

#chat-app .bot-message code { font-size: 12.5px; }

/* #1693 — a bare <svg> answer (no fence, so no live preview) must fit the
   bubble instead of forcing a 512px drawing. Markdown wraps it in a <p>.
   Icons live inside buttons/cards, not in these positions. */
#chat-app .bot-message > svg,
#chat-app .bot-message > p > svg {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 6px 0;
}


/* ── Thinking block: part of the bubble, not a white card inside it ─── */

#chat-app .thinking-section {
    background: #f7f7f8;
    border: 1px solid var(--gb-border-soft);
    border-radius: 12px;
    margin-bottom: 10px;
}

#chat-app .thinking-section summary {
    color: var(--gb-muted);
    font-weight: 500;
    font-size: 12px;
    padding: 7px 11px;
}

#chat-app .thinking-section .thinking-content {
    color: #52525b;
    border-top: 1px solid var(--gb-border-soft);
}

[data-color-scheme="dark"] #chat-app .thinking-section {
    background: #202025;
    border-color: #313138;
}

[data-color-scheme="dark"] #chat-app .thinking-section summary {
    color: #a1a1aa;
}

[data-color-scheme="dark"] #chat-app .thinking-section .thinking-content {
    color: #c4c4cc;
    border-top-color: #313138;
}
