/* ============================================================
   chat.css — the floating "ask the site" widget.
   Warm paper panel, ink text, one signal-orange accent.
   Markup is injected by chat.js, so everything is namespaced
   under .chat- to stay clear of the page.
   ============================================================ */

.chat-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 17px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: transform .16s ease, border-color .16s ease;
}
.chat-fab:hover { transform: translateY(-2px); border-color: var(--accent); }
.chat-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.chat-fab-icon {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    line-height: 1;
}

.chat-fab[aria-expanded="true"] { transform: translateY(4px); opacity: 0; pointer-events: none; }

/* ---------- panel ---------- */

.chat-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 901;
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 32px));
    height: min(620px, calc(100vh - 48px));
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--paper);
    box-shadow: var(--shadow-lg);
    transform-origin: bottom right;
    animation: chat-in .18s ease;
}
.chat-panel[hidden] { display: none; }

@keyframes chat-in {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- header ---------- */

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--paper-2);
}

.chat-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }

.chat-orb {
    position: relative;
    flex: none;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--accent);
}
.chat-orb::after {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 3px;
    background: var(--paper);
    opacity: .85;
}

.chat-titles { min-width: 0; }
.chat-titles b { display: block; font-size: 14px; letter-spacing: .01em; }
.chat-titles small {
    display: block;
    overflow: hidden;
    color: var(--muted);
    font-size: 11.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-head-actions { display: flex; gap: 4px; flex: none; }

.chat-icon-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.chat-icon-btn:hover { border-color: var(--line); background: var(--paper-3); color: var(--ink); }
.chat-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- messages ---------- */

.chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}
.chat-msgs::-webkit-scrollbar { width: 8px; }
.chat-msgs::-webkit-scrollbar-thumb { border-radius: 8px; background: var(--line-strong); }

.chat-msg { display: flex; margin-bottom: 12px; }
.chat-msg.user { justify-content: flex-end; }

.chat-bubble {
    max-width: 86%;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper-2);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.chat-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.chat-bubble code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--paper-3);
    font-family: var(--mono);
    font-size: 12.5px;
}
.chat-bubble pre { margin: 8px 0; padding: 10px 12px; overflow-x: auto; border-radius: 8px; background: var(--screen); color: var(--screen-text); }
.chat-bubble pre code { padding: 0; background: none; color: inherit; }

.chat-bubble.error { border-color: var(--red); background: var(--red-soft); color: #7c1f1c; }

.chat-caret {
    display: inline-block;
    width: 7px;
    height: 14px;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--accent);
    animation: chat-blink 1s steps(2, start) infinite;
}
@keyframes chat-blink { 50% { opacity: 0; } }

/* ---------- starters ---------- */

.chat-starters { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 4px; }

.chat-starter {
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper-2);
    color: var(--muted);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}
.chat-starter:hover { border-color: var(--line-strong); color: var(--ink); }

/* ---------- composer ---------- */

.chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 11px 12px;
    border-top: 1px solid var(--line);
    background: var(--paper-2);
}

.chat-input {
    flex: 1;
    max-height: 140px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    line-height: 1.45;
    resize: none;
    transition: border-color .15s ease;
}
.chat-input::placeholder { color: var(--muted); }
.chat-input:focus { outline: none; border-color: var(--accent); }

.chat-send {
    display: grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    transition: filter .15s ease, opacity .15s ease;
}
.chat-send:hover:not(:disabled) { filter: brightness(1.1); }
.chat-send:disabled { opacity: .45; cursor: not-allowed; }
.chat-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- settings ---------- */

.chat-settings {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
    background: var(--paper);
}
.chat-settings[hidden] { display: none; }

.chat-settings h3 { margin-bottom: 4px; font-size: 15px; }

.chat-settings-note { margin-bottom: 14px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.chat-field { margin-bottom: 12px; }
.chat-field label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
}
.chat-field select,
.chat-field input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 13.5px;
}
.chat-field select:focus,
.chat-field input:focus { outline: none; border-color: var(--accent); }

.chat-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
}
.chat-check input { width: auto; accent-color: var(--accent); }

.chat-settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.chat-btn {
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.chat-btn:hover { border-color: var(--line-strong); background: var(--paper-2); }

.chat-btn.primary { border-color: transparent; background: var(--accent); color: #fff; }
.chat-btn.primary:hover { background: var(--accent-strong); }

.chat-key-link { display: inline-block; margin-top: 8px; color: var(--accent); font-size: 12.5px; }

.chat-status { margin-top: 12px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ---------- mobile ---------- */

@media (max-width: 520px) {
    .chat-fab { right: 16px; bottom: 16px; }
    .chat-panel {
        right: 0; bottom: 0; left: 0;
        width: 100%;
        height: 88vh;
        height: 88dvh;
        border-radius: 14px 14px 0 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-fab, .chat-panel, .chat-bubble, .chat-caret { transition: none; animation: none; }
}
