/* ============================================================================
   Site chatbot widget — floating launcher + panel. Mobile-first.
   Uses the design tokens defined in styles.css (--brand, --accent, --s*, …).
   ========================================================================== */

.chatw {
    --chatw-size: 60px;
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 9998;
    font-family: 'Inter', system-ui, sans-serif;
}

/* The panel, intro and conversation areas set `display`, which would otherwise
   override the [hidden] attribute the JS toggles — force hidden to win. */
.chatw [hidden] { display: none !important; }

/* ---- Circular launcher ---- */
.chatw__launcher {
    width: var(--chatw-size);
    height: var(--chatw-size);
    border-radius: 50%;
    border: none;
    background: var(--brand, #0D2F92);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(13, 47, 146, 0.35);
    transition: transform .2s ease, background .2s ease;
    position: relative;
}
.chatw__launcher:hover { background: var(--accent-hover, #1531A0); transform: translateY(-2px); }
.chatw__launcher:focus-visible { outline: 3px solid var(--accent-glow, rgba(26,61,181,.4)); outline-offset: 2px; }

.chatw__icon { position: absolute; transition: opacity .2s ease, transform .2s ease; }
.chatw__icon--close { opacity: 0; transform: scale(.6) rotate(-45deg); }
.chatw.is-open .chatw__icon--open { opacity: 0; transform: scale(.6) rotate(45deg); }
.chatw.is-open .chatw__icon--close { opacity: 1; transform: scale(1) rotate(0); }

/* Subtle attention pulse until first opened. */
.chatw__launcher::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(13, 47, 146, 0.5);
    animation: chatwPulse 2.4s infinite;
}
.chatw.is-open .chatw__launcher::after,
.chatw.is-seen .chatw__launcher::after { animation: none; }
@keyframes chatwPulse {
    0% { box-shadow: 0 0 0 0 rgba(13,47,146,.45); }
    70% { box-shadow: 0 0 0 16px rgba(13,47,146,0); }
    100% { box-shadow: 0 0 0 0 rgba(13,47,146,0); }
}

/* ---- Panel ---- */
.chatw__panel {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(var(--chatw-size) + 24px + env(safe-area-inset-bottom));
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - var(--chatw-size) - 48px);
    background: var(--bg, #fff);
    border-radius: var(--radius-lg, 16px);
    box-shadow: 0 20px 60px rgba(10, 31, 68, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line, #E2E8F0);
    animation: chatwIn .22s ease;
}
@keyframes chatwIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.chatw__head {
    background: linear-gradient(135deg, var(--brand, #0D2F92), var(--accent, #1A3DB5));
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.chatw__head-info { display: flex; flex-direction: column; line-height: 1.3; }
.chatw__head-info strong { font-size: 15px; }
.chatw__status { font-size: 12px; opacity: .85; }
.chatw__status.is-online::before {
    content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    background: #2ecc71; margin-right: 6px; vertical-align: middle;
}
.chatw__min {
    background: none; border: none; color: #fff; font-size: 26px; line-height: 1;
    cursor: pointer; padding: 0 4px; opacity: .9;
}
.chatw__min:hover { opacity: 1; }

/* ---- Intro form ---- */
.chatw__intro { padding: 20px 16px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.chatw__intro-lead { font-size: 14px; color: var(--ink-soft, #4A4A6A); margin: 0 0 4px; }
.chatw__intro input {
    padding: 11px 12px; border: 1px solid var(--line-2, #CBD5E1); border-radius: var(--radius-sm, 8px);
    font: inherit; font-size: 14px; color: var(--ink, #1A1A2E); width: 100%;
}
.chatw__intro input:focus { outline: none; border-color: var(--accent, #1A3DB5); box-shadow: 0 0 0 3px var(--accent-glow, rgba(26,61,181,.15)); }
.chatw__hp { position: absolute; left: -9999px; width: 1px; height: 1px; }
.chatw__err { color: #c0392b; font-size: 13px; margin: 0; }
.chatw__start {
    margin-top: 4px; padding: 12px; border: none; border-radius: var(--radius-sm, 8px);
    background: var(--accent, #1A3DB5); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.chatw__start:hover { background: var(--accent-hover, #1531A0); }
.chatw__start:disabled { opacity: .6; cursor: default; }
.chatw__consent { font-size: 11px; color: var(--ink-muted, #94A3B8); margin: 2px 0 0; text-align: center; }

/* ---- Conversation ---- */
.chatw__conv { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chatw__messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
    background: var(--bg-alt, #F5F7FA);
}
.chatw__msg { max-width: 85%; display: flex; flex-direction: column; gap: 6px; }
.chatw__bubble {
    padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45;
    white-space: pre-wrap; word-wrap: break-word;
}
.chatw__msg--bot, .chatw__msg--agent { align-self: flex-start; }
.chatw__msg--bot .chatw__bubble { background: #fff; color: var(--ink, #1A1A2E); border: 1px solid var(--line, #E2E8F0); border-bottom-left-radius: 4px; }
.chatw__msg--agent .chatw__bubble { background: #E8F0FE; color: var(--brand-dark, #0A1F44); border: 1px solid #C7D9F7; border-bottom-left-radius: 4px; }
.chatw__msg--visitor { align-self: flex-end; }
.chatw__msg--visitor .chatw__bubble { background: var(--accent, #1A3DB5); color: #fff; border-bottom-right-radius: 4px; }
.chatw__bubble strong { font-weight: 700; }
.chatw__who { font-size: 10px; color: var(--ink-muted, #94A3B8); padding: 0 4px; }
.chatw__msg--visitor .chatw__who { text-align: right; }

/* Quick-reply chips */
.chatw__chips { display: flex; flex-wrap: wrap; gap: 6px; align-self: flex-start; max-width: 100%; }
.chatw__chip {
    border: 1px solid var(--accent, #1A3DB5); color: var(--accent, #1A3DB5); background: #fff;
    border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 13px; cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.chatw__chip:hover { background: var(--accent, #1A3DB5); color: #fff; }

/* Typing indicator */
.chatw__typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 13px; background: #fff; border: 1px solid var(--line,#E2E8F0); border-radius: 14px; }
.chatw__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted, #94A3B8); animation: chatwBlink 1.2s infinite; }
.chatw__typing span:nth-child(2) { animation-delay: .2s; }
.chatw__typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatwBlink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* Composer */
.chatw__compose { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line, #E2E8F0); background: var(--bg, #fff); }
.chatw__compose input {
    flex: 1; padding: 11px 14px; border: 1px solid var(--line-2, #CBD5E1); border-radius: 999px;
    font: inherit; font-size: 14px;
}
.chatw__compose input:focus { outline: none; border-color: var(--accent, #1A3DB5); box-shadow: 0 0 0 3px var(--accent-glow, rgba(26,61,181,.15)); }
.chatw__compose button {
    flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: none;
    background: var(--accent, #1A3DB5); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.chatw__compose button:hover { background: var(--accent-hover, #1531A0); }

/* ---- Mobile: full-screen sheet ---- */
@media (max-width: 600px) {
    .chatw__panel {
        right: 0; left: 0; bottom: 0; top: 0;
        width: 100%; max-width: 100%; height: 100%; max-height: 100%;
        border-radius: 0; border: none;
    }
    .chatw__head { padding-top: max(14px, env(safe-area-inset-top)); }
    .chatw__compose { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .chatw { --chatw-size: 56px; }
}

@media (prefers-reduced-motion: reduce) {
    .chatw__launcher::after { animation: none; }
    .chatw__panel { animation: none; }
}
