/* Local Bonsai chat. */
.ai-fab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 24px;
    font-size: 12px;
    white-space: nowrap;
    transition: border-color 0.2s;
}
.ai-fab:hover {
    border-color: var(--accent);
}
.ai-fab.hidden {
    display: none;
}
.ai-ico {
    width: 17px;
    height: 17px;
    flex: none;
    stroke-width: 1.6;
}
.ai-fab .ai-ico,
.ai-panel-title .ai-ico {
    color: var(--accent);
}
html.ai-chat-open {
    overflow: hidden;
}
.ai-panel {
    position: fixed;
    inset: 0 0 0 auto;
    margin: 0;
    width: min(460px, 100%);
    height: 100dvh;
    max-height: 100dvh;
    max-width: 100%;
    padding: 0;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    background: var(--panel);
    color: var(--fg);
    overflow: hidden;
    box-shadow: -20px 0 100px #0003;
}
.ai-panel[open] {
    display: flex;
    flex-direction: column;
    animation: ai-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.ai-panel::backdrop {
    background: #0009;
    backdrop-filter: blur(5px);
}
.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 24px 26px 10px;
    flex: none;
}
.ai-panel-title {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 22px;
    letter-spacing: -0.04em;
}
.ai-panel-close {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    font-size: 27px;
    line-height: 1;
    color: var(--muted);
    border-radius: 50%;
}
.ai-panel-close:hover {
    color: var(--fg);
    background: var(--soft);
}
.ai-context {
    padding: 10px 26px 19px;
    flex: none;
}
.ai-context-date {
    font: 10px/1.5 var(--mono);
    color: var(--muted);
    margin-bottom: 7px;
}
.ai-context-title {
    font-size: 14px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.ai-header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 8px 26px;
    border-block: 1px solid var(--line);
    flex: none;
}
.ai-model-label {
    font: 10px/1.4 var(--mono);
    color: var(--muted);
}
.ai-header-buttons {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.ai-agent-copy,
.ai-think-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 7px 9px;
    font-size: 10px;
    color: var(--muted);
}
.ai-think-toggle.on {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
    color: var(--fg);
}
.ai-agent-copy:hover,
.ai-agent-copy:focus-visible {
    color: var(--fg);
}
.ai-agent-copy .ai-ico,
.ai-think-toggle .ai-ico {
    width: 14px;
    height: 14px;
}
.ai-messages {
    display: flex;
    flex-direction: column;
    gap: 22px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 28px 26px;
    scroll-behavior: auto;
}
.ai-empty {
    margin: auto 0;
    max-width: 320px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--muted);
}
.ai-empty .ai-empty-title {
    color: var(--fg);
    font-size: 25px;
    letter-spacing: -0.04em;
    line-height: 1.2;
    margin-bottom: 12px;
}
.ai-empty .ai-empty-sub {
    font-size: 11px;
    line-height: 1.7;
    margin-top: 24px;
    max-width: 270px;
}
.ai-msg {
    font-size: 14px;
    line-height: 1.7;
    overflow-wrap: anywhere;
    flex: none;
}
.ai-msg-user {
    align-self: flex-end;
    max-width: 88%;
    border-radius: 14px 14px 3px 14px;
    background: var(--soft);
    padding: 12px 16px;
    white-space: pre-wrap;
}
.ai-msg-assistant {
    align-self: stretch;
    padding: 0;
}
.ai-answer p {
    margin: 0 0 12px;
}
.ai-answer > :last-child {
    margin-bottom: 0;
}
.ai-answer h1,
.ai-answer h2,
.ai-answer h3 {
    font-size: 17px;
    margin: 18px 0 9px;
}
.ai-answer ul,
.ai-answer ol {
    padding-left: 20px;
    margin: 8px 0 14px;
}
.ai-answer pre {
    max-width: 100%;
    padding: 12px;
    overflow: auto;
    background: var(--soft);
    border-radius: 8px;
}
.ai-answer code {
    font-family: var(--mono);
    font-size: 12px;
}
.ai-answer a {
    color: var(--accent);
}
.ai-answer table {
    display: block;
    overflow-x: auto;
    border-collapse: collapse;
}
.ai-answer td,
.ai-answer th {
    padding: 6px;
    border: 1px solid var(--line);
}
.ai-answer img {
    max-width: 100%;
}
.ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex: none;
    margin: 0;
    padding: 18px 22px max(20px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
}
.ai-input {
    display: block;
    min-width: 0;
    min-height: 46px;
    flex: 1;
    resize: none;
    max-height: 140px;
    padding: 11px 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--fg);
    font: 16px/1.5 var(--font);
    outline: none;
}
.ai-input:focus-visible {
    box-shadow: 0 1px var(--accent);
}
.ai-input::placeholder {
    color: var(--muted);
    font-size: 14px;
}
.ai-input:disabled {
    opacity: 0.45;
}
.ai-send {
    flex: none;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--fg);
}
.ai-send:not(:disabled):hover {
    background: var(--fg);
    color: var(--bg);
}
.ai-send .ai-ico {
    width: 20px;
    height: 20px;
}
.ai-send-stop .ai-ico {
    fill: currentColor;
    stroke: none;
}
.ai-progress {
    flex: none;
    padding: 15px 26px 0;
}
.ai-progress-track {
    height: 3px;
    overflow: hidden;
    border-radius: 3px;
    background: var(--line);
}
.ai-progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.25s;
}
.ai-progress-label {
    margin-top: 7px;
    font: 10px/1.5 var(--mono);
    color: var(--muted);
}
.ai-think {
    margin-bottom: 14px;
    border-left: 1px solid var(--line);
    padding-left: 12px;
    color: var(--muted);
}
.ai-think-summary {
    cursor: pointer;
    font-size: 11px;
    list-style: none;
}
.ai-think-summary::-webkit-details-marker {
    display: none;
}
.ai-think-summary::after {
    content: " +";
    margin-left: 8px;
}
.ai-think[open] .ai-think-summary::after {
    content: " −";
}
.ai-think-label .ai-ico {
    width: 13px;
    height: 13px;
    vertical-align: -2px;
    margin-right: 4px;
}
.ai-think-body {
    font-size: 12px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: 12px;
}
.ai-caret {
    display: inline-block;
    width: 5px;
    height: 1em;
    background: var(--accent);
    margin-left: 3px;
    vertical-align: text-bottom;
    animation: ai-caret 1s steps(2, start) infinite;
}
.ai-dots::after {
    content: "…";
}
/* Retain the live engine's memory-saving mode on lower-capacity GPUs. */
html.ai-engine-lite *,
html.ai-engine-lite *::before,
html.ai-engine-lite *::after {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    filter: none !important;
    will-change: auto !important;
}
@keyframes ai-in {
    from {
        opacity: 0;
        transform: translateX(35px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
@keyframes ai-caret {
    50% {
        opacity: 0;
    }
}
@media (max-width: 700px) {
    .topbar nav {
        gap: 9px;
    }
    .ai-fab {
        padding: 8px 10px;
        font-size: 11px;
    }
    .ai-fab .ai-ico {
        width: 15px;
        height: 15px;
    }
    .ai-panel {
        border-left: 0;
    }
    .ai-panel-header {
        padding: 20px 22px 8px;
    }
    .ai-context {
        padding-inline: 22px;
    }
    .ai-header-actions {
        padding-inline: 22px;
    }
    .ai-messages {
        padding: 24px 22px;
    }
    .ai-input-row {
        padding-inline: 22px;
    }
}
