/* ────────────────────────────────────────────────────────────────────────────
   Skipper — shared chat widget styles (pairs with /chat.js).
   Loaded AFTER each page's inline <style>, so these rules take precedence over
   the per-page base .chat-* styles.
──────────────────────────────────────────────────────────────────────────── */

/* Height-bounded popover: the log flexes, header + input always stay on screen */
#chat-pop .chat-panel {
    display: flex; flex-direction: column;
    max-height: min(680px, calc(100vh - 116px));
    max-height: min(680px, calc(100dvh - 116px));
}
#chat-pop .chat-head, #chat-pop .chat-input-row, #chat-pop .chat-hint, #chat-pop .chat-note { flex: 0 0 auto; }
#chat-pop .chat-log {
    flex: 1 1 auto; min-height: min(120px, 22vh); max-height: none;
    overscroll-behavior: contain; scroll-padding-top: 10px;
}
#chat-pop .chat-log:focus-visible { outline: 2px solid var(--accent-dim); outline-offset: -2px; }

/* Messages */
.chat-msg.bot { max-width: 90%; }
.chat-msg.bot.rich { white-space: normal; }
.chat-msg.bot.rich p { margin: 0; }
.chat-msg.bot.rich p + p, .chat-msg.bot.rich p + ul, .chat-msg.bot.rich p + ol,
.chat-msg.bot.rich ul + p, .chat-msg.bot.rich ol + p { margin-top: 0.6em; }
.chat-msg.bot.rich ul, .chat-msg.bot.rich ol { margin: 0; padding-left: 1.15em; }
.chat-msg.bot.rich li + li { margin-top: 0.25em; }
.chat-msg.bot.rich strong { color: var(--text); font-weight: 600; }
.chat-msg a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.chat-msg.user.failed { opacity: 0.7; }
.chat-sr {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.chat-retry {
    display: inline-block; margin-top: 0.6rem;
    font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
    padding: 0.35rem 0.85rem; border-radius: 20px; cursor: pointer;
    background: var(--accent-faint); border: 1px solid var(--accent); color: var(--accent);
}
.chat-retry:hover { background: var(--accent); color: #210D02; }

/* Suggested-question chips (starter + follow-ups) */
#chat-pop .chat-chips {
    flex: 0 0 auto;                 /* never shrink: every suggestion stays visible; the log gives way */
    gap: 0.45rem; padding: 0.55rem 1.4rem 0.8rem; align-items: center;
    border-top: 1px solid var(--line);
}
#chat-pop .chat-chips[hidden] { display: none; }
.chat-chips-label {
    flex-basis: 100%; font-family: var(--font-mono); font-size: 0.62rem;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim);
}
#chat-pop .chat-chip { text-align: left; line-height: 1.35; padding: 0.38rem 0.8rem; font-size: 0.7rem; }
.chat-chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-faint); }
.chat-chip:disabled { opacity: 0.45; cursor: default; }
.chat-chip:disabled:hover { border-color: var(--line-strong); color: var(--muted); background: transparent; }
.chat-chips.chat-fresh .chat-chip { animation: chatChipIn 0.28s ease both; }
.chat-chips.chat-fresh .chat-chip:nth-of-type(2) { animation-delay: 0.05s; }
.chat-chips.chat-fresh .chat-chip:nth-of-type(3) { animation-delay: 0.1s; }
@keyframes chatChipIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Keyboard hint under the input */
.chat-hint {
    font-family: var(--font-mono); font-size: 0.64rem; color: var(--dim);
    letter-spacing: 0.02em; padding: 0 1.4rem 0.45rem; margin-top: -0.4rem; min-height: 1.1em;
}
.chat-hint[hidden] { display: none; }
.chat-hint kbd {
    font-family: inherit; font-size: inherit; color: var(--muted);
    border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px;
    padding: 0 0.3em; margin-right: 0.15em;
}

/* Header: compact tech tag so title + New-chat + close fit on one row */
#chat-pop .chat-head { padding-top: 0.85rem; padding-bottom: 0.85rem; }
#chat-pop .chat-head h3 { white-space: nowrap; }
#chat-pop .chat-head .chat-stack { font-size: 0.6rem; line-height: 1.35; text-align: right; min-width: 0; }
/* Once a conversation exists the New-chat button takes the tag's slot (keeps close on-screen at 400px). */
#chat-pop .chat-head:has(.chat-reset:not([hidden])) .chat-stack { display: none; }
#chat-pop .chat-head:has(.chat-reset:not([hidden])) .chat-reset { margin-left: auto; }

/* Header: New-chat button */
.chat-reset {
    margin-left: 0.6rem; width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface-2); border: 1px solid var(--line-strong);
    color: var(--muted); cursor: pointer; transition: all 0.15s;
}
.chat-reset[hidden] { display: none; }
.chat-reset svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-reset:hover { color: var(--text); border-color: var(--accent); }
.chat-reset + .chat-pop-close { margin-left: 0.45rem; }

/* Visible keyboard focus */
.chat-chip:focus-visible, .chat-retry:focus-visible, .chat-reset:focus-visible,
.chat-pop-close:focus-visible, .chat-input-row button:focus-visible, #chat-fab:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
.chat-input-row input:focus { box-shadow: 0 0 0 3px var(--accent-faint); }

/* Unread reply indicator on the launcher */
#chat-fab.unread::before {
    content: ''; position: absolute; top: 1px; right: 1px; width: 13px; height: 13px;
    border-radius: 50%; background: #F3EDE7; border: 2px solid var(--accent); z-index: 1;
}

/* Short desktop viewports: suggestions collapse to one scrollable row */
@media (max-height: 700px) and (min-width: 601px) {
    #chat-pop .chat-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
    #chat-pop .chat-chips .chat-chips-label { display: none; }
    #chat-pop .chat-chip { flex: 0 0 auto; white-space: nowrap; }
}

/* Compact mode (JS toggles .chat-compact when the visual viewport is < 560px tall):
   one-row suggestion strip, no footnote, smaller log minimum — input always fits. */
#chat-pop.chat-compact .chat-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-top: 0.4rem; padding-bottom: 0.5rem; }
#chat-pop.chat-compact .chat-chips .chat-chips-label, #chat-pop.chat-compact .chat-note { display: none; }
#chat-pop.chat-compact .chat-chip { flex: 0 0 auto; white-space: nowrap; }
#chat-pop.chat-compact .chat-log { min-height: 64px; padding-top: 0.7rem; padding-bottom: 0.7rem; }
#chat-pop.chat-compact .chat-input-row { padding-top: 0.6rem; padding-bottom: 0.6rem; }

/* Mobile: true full-screen sheet sized to the visual viewport (keyboard-aware);
   hide the launcher so it can't cover Send, and lock page scroll behind. */
@media (max-width: 600px) {
    body.chat-open { overflow: hidden; }
    body.chat-open #chat-launcher, body.chat-open #fab-nudge { display: none !important; }
    #chat-pop.open {
        inset: auto; top: var(--chat-vt, 0px); left: 0; right: 0;
        height: 100vh; height: var(--chat-vh, 100dvh);
    }
    #chat-pop .chat-panel { max-height: none; height: 100%; }
    .chat-input-row input { font-size: 16px; }   /* prevents iOS focus-zoom */
    .chat-msg.bot { max-width: 94%; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-chips.chat-fresh .chat-chip { animation: none; }
}
