/*
 * Site assistant widget (templates/components/_chatbot.html.twig).
 * Theme variables only (theme.css): violet on goodloss, amber on ranked/oriana.
 * Bottom right, above the page and below the mobile menu (9999), the cookie
 * banner (9998) and the replay modal (10000); chatbot.js lifts it above the
 * cookie banner while that one is shown (--chatbot-lift).
 */
.chatbot {
    --chatbot-lift: 0px;
    position: fixed;
    right: 20px;
    bottom: calc(20px + var(--chatbot-lift));
    z-index: 9990;
    font-family: var(--font-body);
    transition: bottom .2s ease;
}

.chatbot .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ─── Launcher ─── */
.chatbot-launcher {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 18px 0 14px;
    border: 1px solid var(--accent-hover);
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: var(--on-accent);
    font: 700 0.95rem/1 var(--font-display);
    box-shadow: var(--shadow-accent);
    cursor: pointer;
    transition: transform .15s ease, background .15s ease;
}
.chatbot-launcher:hover { background: var(--accent-hover); transform: translateY(-1px); }
.chatbot-launcher:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 3px; }
.chatbot-launcher__icon { width: 22px; height: 22px; flex: none; }
.chatbot.is-open .chatbot-launcher { display: none; }

/* ─── Panel ─── */
.chatbot-panel {
    display: flex;
    flex-direction: column;
    width: 380px;
    height: min(600px, calc(100vh - 40px - var(--chatbot-lift)));
    background: var(--bg-sidebar);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    overflow: hidden;
}
.chatbot-panel[hidden] { display: none; }

.chatbot-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 10px 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.chatbot-head__avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent);
}
.chatbot-head__avatar svg { width: 20px; height: 20px; }
.chatbot-head__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chatbot-head__text strong { color: var(--text-primary); font: 700 1rem/1.2 var(--font-display); }
.chatbot-head__text span { color: var(--text-faint); font-size: 0.75rem; }

.chatbot-icon-btn {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: none;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}
.chatbot-icon-btn[hidden] { display: none; }
.chatbot-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.chatbot-icon-btn svg { width: 20px; height: 20px; }

.chatbot-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}
.chatbot-lang { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.chatbot-lang svg { width: 16px; height: 16px; flex: none; }
.chatbot-lang select {
    max-width: 150px;
    padding: 4px 6px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-raised);
    color: var(--text-primary);
    font: inherit;
}
.chatbot-lang select:disabled { opacity: .6; cursor: not-allowed; }
.chatbot-support { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-light); text-decoration: none; white-space: nowrap; }
.chatbot-support:hover { text-decoration: underline; }
.chatbot-support svg { width: 16px; height: 16px; }

/* ─── Messages ─── */
.chatbot-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.chatbot-msg {
    max-width: 86%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.chatbot-msg--bot {
    align-self: flex-start;
    background: var(--bg-raised);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.chatbot-msg--user {
    align-self: flex-end;
    background: var(--accent);
    color: var(--on-accent);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}
.chatbot-msg--error {
    align-self: stretch;
    max-width: none;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 0.85rem;
}
.chatbot-msg p { margin: 0; }
.chatbot-msg p + p, .chatbot-msg p + ul, .chatbot-msg ul + p { margin-top: 6px; }
.chatbot-msg ul, .chatbot-msg ol { margin: 4px 0 0; padding-left: 18px; }
.chatbot-msg a { color: var(--accent-light); text-decoration: underline; }
.chatbot-msg code { font-family: var(--font-mono); font-size: 0.85em; background: var(--bg-subtle); padding: 0 3px; border-radius: 4px; }
/* Pre-filled support ticket (prepare_support_ticket) */
.chatbot-ticket {
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 86%;
    padding: 12px;
    border: 1px solid var(--accent);
    border-radius: 14px;
    background: var(--accent-subtle);
    font-size: 0.85rem;
}
.chatbot-ticket__label { color: var(--accent-light); font-size: 0.7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.chatbot-ticket strong { color: var(--text-primary); line-height: 1.3; }
.chatbot-ticket__subject { color: var(--text-muted); font-size: 0.8rem; }
.chatbot-ticket__open {
    align-self: flex-start;
    margin-top: 6px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
    text-decoration: none;
}
.chatbot-ticket__open:hover { background: var(--accent-hover); }

.chatbot-status { align-self: flex-start; color: var(--text-faint); font-size: 0.8rem; font-style: italic; }
.chatbot-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.chatbot-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: chatbot-dot 1s infinite ease-in-out; }
.chatbot-typing i:nth-child(2) { animation-delay: .15s; }
.chatbot-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chatbot-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ─── Composer ─── */
.chatbot-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
}
.chatbot-form textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 9px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.9rem;
    resize: none;
}
.chatbot-form textarea:focus { outline: none; border-color: var(--accent); }
.chatbot-send {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-accent);
    cursor: pointer;
}
.chatbot-send:hover { background: var(--accent-hover); }
.chatbot-send:disabled { opacity: .5; cursor: not-allowed; }
.chatbot-send svg { width: 20px; height: 20px; }
[dir="rtl"] .chatbot-send svg { transform: scaleX(-1); }

.chatbot-note {
    margin: 0;
    padding: 0 14px 10px;
    color: var(--text-faint);
    font-size: 0.7rem;
    line-height: 1.35;
}
.chatbot-note a { color: var(--text-muted); }

/* ─── Mobile: launcher as a round button, panel full screen ─── */
@media (max-width: 768px) {
    .chatbot { right: 14px; bottom: calc(14px + var(--chatbot-lift)); }
    .chatbot-launcher { width: 52px; height: 52px; padding: 0; justify-content: center; }
    .chatbot-launcher__label { display: none; }
    /* Full screen once open: above the cookie banner (9998), like the mobile menu. */
    .chatbot.is-open { inset: 0; right: 0; bottom: 0; z-index: 9999; }
    .chatbot-panel { width: 100%; height: 100%; height: 100dvh; border: 0; border-radius: 0; }
    .chatbot-form textarea { font-size: 16px; } /* no zoom on iOS focus */
}

@media (prefers-reduced-motion: reduce) {
    .chatbot, .chatbot-launcher { transition: none; }
    .chatbot-typing i { animation: none; }
}
