/* ============================================
   AI ASSISTANT WIDGET
   Theme-aware: uses the same tokens as the rest
   of the site, so it flips with dark mode.
   ============================================ */

.ai-launcher {
    position: fixed;
    left: 24px;
    bottom: 24px;
    z-index: 990;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 13px 20px 13px 16px;
    border: 1px solid var(--border-strong);
    border-radius: 100px;
    background: var(--surface);
    color: var(--text-strong);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: var(--transition);
}

.ai-launcher:hover {
    background: var(--surface-navy);
    border-color: var(--surface-navy);
    color: var(--gold);
    transform: translateY(-2px);
}

.ai-launcher .ai-launcher-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: var(--ink-on-gold);
    flex-shrink: 0;
}

.ai-launcher:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
}

/* ---------- Panel ---------- */
.ai-panel {
    position: fixed;
    left: 24px;
    bottom: 24px;
    z-index: 991;
    width: min(400px, calc(100vw - 32px));
    height: min(580px, calc(100vh - 48px));
    display: none;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

.ai-panel.is-open {
    display: flex;
    flex-direction: column;
    animation: aiRise 0.24s ease;
}

@keyframes aiRise {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ai-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: var(--surface-navy);
    color: var(--ink-on-navy);
    flex-shrink: 0;
}

.ai-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: var(--ink-on-gold);
    flex-shrink: 0;
    font-family: var(--font-serif);
    font-weight: 700;
}

.ai-head-titles { min-width: 0; }

.ai-head-name {
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.2;
}

.ai-head-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.72);
}

.ai-head-status .ai-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6ee7a8;
    flex-shrink: 0;
}

.ai-close {
    margin-left: auto;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-close:hover { background: rgba(255, 255, 255, 0.24); }
.ai-close:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Log ---------- */
.ai-log {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg);
    scrollbar-width: thin;
}

.ai-msg {
    max-width: 88%;
    padding: 11px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ai-msg-bot {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text);
}

.ai-msg-me {
    align-self: flex-end;
    background: var(--surface-navy);
    color: var(--ink-on-navy);
    border-bottom-right-radius: 4px;
}

.ai-msg strong { color: inherit; font-weight: 700; }

.ai-msg-error {
    align-self: flex-start;
    background: var(--red-light);
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: 14px;
}

/* Shown on answers served from the local responder while the daily free
   quota is empty, so nobody mistakes a canned reply for the full assistant. */
.ai-note {
    display: block;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    font-size: 11px;
    font-style: italic;
    font-weight: 400;
    line-height: 1.4;
    color: var(--text-faint);
}

.ai-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-faint);
    animation: aiBlink 1.2s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.18s; }
.ai-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes aiBlink {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- Suggestions ---------- */
.ai-suggest {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 18px 12px;
    background: var(--bg);
    flex-shrink: 0;
}

.ai-suggest button {
    padding: 7px 13px;
    border-radius: 100px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.ai-suggest button:hover {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--ink-on-gold);
}

/* ---------- Composer ---------- */
.ai-form {
    display: flex;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-strong);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    resize: none;
    max-height: 110px;
    outline: none;
}

.ai-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ai-send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: var(--radius);
    background: var(--gold);
    color: var(--ink-on-gold);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.ai-send:hover { filter: brightness(1.06); }
.ai-send:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ai-footnote {
    padding: 0 18px 12px;
    font-size: 0.6875rem;
    color: var(--text-faint);
    background: var(--surface);
    flex-shrink: 0;
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
    .ai-launcher { left: 16px; bottom: 16px; padding: 11px 16px 11px 12px; }
    .ai-launcher .ai-launcher-text { display: none; }
    .ai-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 88vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-panel.is-open { animation: none; }
    .ai-typing span { animation: none; }
}
