/* =====================================================================
   TAHDCO AI ASSISTANT — CHATBOT STYLES
   File: public/assets/css/ai-assistant/chatbot.css
   ---------------------------------------------------------------------
   ADDITIVE stylesheet. Scoped under .tahdco-ai / .tahdco-ai-* classes so
   it cannot affect existing site styles. Uses the site's design tokens
   (with hard fallbacks) so it matches the TAHDCO blue/gold identity even
   on the standalone admin page where variables.css may be absent.
   ===================================================================== */

.tahdco-ai,
.tahdco-ai * { box-sizing: border-box; }

.tahdco-ai {
    --tai-primary: var(--color-primary, #1565C0);
    --tai-primary-dark: var(--color-primary-dark, #0D47A1);
    --tai-primary-light: var(--color-primary-light, #4A90D9);
    --tai-accent: var(--color-accent, #D99C2B);
    --tai-surface: #ffffff;
    --tai-bg: #f3f6fb;
    --tai-text: #1f2733;
    --tai-muted: #6b7686;
    --tai-bot-bubble: #eef3fb;
    --tai-user-bubble: var(--color-primary, #1565C0);
    --tai-radius: 18px;
    --tai-shadow: 0 18px 48px rgba(13, 71, 161, 0.28);
    --tai-font-head: var(--font-heading, 'Plus Jakarta Sans', system-ui, sans-serif);
    --tai-font-body: var(--font-body, 'Poppins', system-ui, sans-serif);
    --tai-z: 1000000;

    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: var(--tai-z);
    font-family: var(--tai-font-body);
    line-height: 1.5;
}

/* ---- Floating action button (AI-robot icon) ---------------------- */
.tahdco-ai-fab {
    position: relative;
    width: 72px; height: 72px;
    border: none;
    border-radius: 26px;                 /* squircle — distinct from a plain circle */
    cursor: pointer;
    color: #fff;
    background: linear-gradient(150deg, var(--tai-primary-light) 0%, var(--tai-primary) 48%, var(--tai-primary-dark) 100%);
    box-shadow: var(--tai-shadow);
    display: flex; align-items: center; justify-content: center;
    overflow: visible;
    transition: transform .22s cubic-bezier(.2,.8,.2,1), box-shadow .22s ease, border-radius .22s ease;
}
.tahdco-ai-fab:hover {
    transform: translateY(-3px) scale(1.05);
    border-radius: 22px;
}
.tahdco-ai-fab:focus-visible { outline: 3px solid var(--tai-accent); outline-offset: 3px; }
.tahdco-ai-fab.is-hidden { display: none; }

.tahdco-ai-fab__ring {
    position: absolute; inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--tai-primary-light);
    opacity: .65;
    z-index: 0;
    animation: tahdco-ai-pulse 2.2s ease-out infinite;
}
@keyframes tahdco-ai-pulse {
    0%   { transform: scale(1);   opacity: .6; }
    70%  { transform: scale(1.5); opacity: 0; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* soft glow ring, sits BEHIND the fab, not a filled backdrop circle */
.tahdco-ai-fab__glow {
    position: absolute;
    inset: -10px;
    border-radius: 30px;
    background: transparent;
    box-shadow: 0 0 0 0 rgba(217,156,43,0.5);
    z-index: 0;
    animation: tahdco-ai-glow 2.6s ease-in-out infinite;
    pointer-events: none;
}
@keyframes tahdco-ai-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217,156,43,.35); }
    50%       { box-shadow: 0 0 18px 4px rgba(217,156,43,.45); }
}

/* the robot-face SVG — much larger, no separate background disc */
.tahdco-ai-fab__icon {
    width: 42px;
    height: 42px;
    color: #fff;
    position: relative;
    z-index: 3;
    filter: drop-shadow(0 2px 5px rgba(0,0,0,.3));
}

/* antenna dot pulses — "receiving a signal" cue */
.tahdco-ai-fab__antenna-dot {
    animation: tahdco-ai-antenna 1.8s ease-in-out infinite;
    transform-origin: center;
}
@keyframes tahdco-ai-antenna {
    0%, 100% { opacity: 1;  transform: scale(1); }
    50%       { opacity: .5; transform: scale(1.35); }
}

/* eyes blink occasionally so the icon feels alive, not static */
.tahdco-ai-fab__eye {
    animation: tahdco-ai-blink 4.5s ease-in-out infinite;
    transform-origin: center;
}
@keyframes tahdco-ai-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    96%            { transform: scaleY(.15); }
}

/* small rotating sparkle badge — the universal "AI-powered" cue */
.tahdco-ai-fab__spark {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd166, var(--tai-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #fff;
    box-shadow: 0 2px 7px rgba(217,156,43,.5);
    z-index: 4;
    animation: tahdco-ai-spark-spin 3.2s linear infinite;
}
@keyframes tahdco-ai-spark-spin {
    0%   { transform: rotate(0deg)   scale(1); }
    50%  { transform: rotate(180deg) scale(1.15); }
    100% { transform: rotate(360deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .tahdco-ai-fab__antenna-dot,
    .tahdco-ai-fab__eye,
    .tahdco-ai-fab__glow,
    .tahdco-ai-fab__spark { animation: none; }
}

/* ---- Panel ------------------------------------------------------- */
.tahdco-ai-panel {
    position: absolute;
    right: 0; bottom: 78px;        /* sit ABOVE the FAB so the icon stays visible and clickable */
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    height: min(560px, calc(100dvh - 118px));
    max-height: calc(100vh - 118px);
    max-height: calc(100dvh - 118px);
    background: var(--tai-bg);
    border-radius: var(--tai-radius);
    box-shadow: var(--tai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tahdco-ai-in .26s cubic-bezier(.2,.8,.2,1);
}
.tahdco-ai-panel.is-expanded {
    width: 520px;
    height: min(720px, calc(100dvh - 118px));
}
/* CRITICAL: a styled element's display:flex overrides the UA [hidden] rule,
   so the panel would never hide on close. This restores hide-on-close. */
.tahdco-ai-panel[hidden] { display: none !important; }
@keyframes tahdco-ai-in {
    from { opacity: 0; transform: translateY(18px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Header ------------------------------------------------------ */
.tahdco-ai-panel__head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--tai-primary) 0%, var(--tai-primary-dark) 100%);
    position: relative; z-index: 30;   /* so the language dropdown shows ABOVE the chat log */
}
.tahdco-ai-panel__brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.tahdco-ai-panel__avatar {
    width: 38px; height: 38px; flex: 0 0 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.tahdco-ai-panel__titles { display: flex; flex-direction: column; min-width: 0; }
.tahdco-ai-panel__titles strong {
    font-family: var(--tai-font-head);
    font-size: 15px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tahdco-ai-panel__titles small { font-size: 11px; opacity: .85; }

.tahdco-ai-panel__langs { display: flex; gap: 4px; }
.tahdco-ai-lang {
    border: 1px solid rgba(255,255,255,.4);
    background: transparent;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 7px;
    border-radius: 20px;
    cursor: pointer;
    max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: background .15s ease;
}
.tahdco-ai-lang:hover { background: rgba(255,255,255,.18); }
.tahdco-ai-lang.is-active { background: var(--tai-accent); border-color: var(--tai-accent); color: #1f2733; }

.tahdco-ai-panel__close,
.tahdco-ai-panel__expand {
    border: none; background: transparent; color: #fff;
    font-size: 16px; cursor: pointer; padding: 4px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
}
.tahdco-ai-panel__close:hover,
.tahdco-ai-panel__expand:hover { background: rgba(255,255,255,.18); }

/* voice on/off toggle in the header (mirrors the close button) */
.tahdco-ai-panel__voice {
    border: none; background: transparent; color: #fff;
    font-size: 16px; cursor: pointer; padding: 4px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s ease, opacity .15s ease;
}
.tahdco-ai-panel__voice:hover { background: rgba(255,255,255,.18); }
.tahdco-ai-panel__voice:focus-visible { outline: 2px solid var(--tai-accent); outline-offset: 2px; }
.tahdco-ai-panel__voice.is-off { opacity: .55; }

/* ---- Message log ------------------------------------------------- */
.tahdco-ai-log {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 6px;
    display: flex; flex-direction: column; gap: 12px;
    scroll-behavior: smooth;
}
.tahdco-ai-log::-webkit-scrollbar { width: 7px; }
.tahdco-ai-log::-webkit-scrollbar-thumb { background: #c5d2e6; border-radius: 4px; }

.tahdco-ai-msg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.tahdco-ai-msg--user { flex-direction: row-reverse; }
.tahdco-ai-msg__avatar {
    width: 30px; height: 30px; flex: 0 0 30px;
    border-radius: 50%;
    background: var(--tai-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
}
.tahdco-ai-msg__bubble {
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 14px;
    max-width: 78%;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.tahdco-ai-msg--bot .tahdco-ai-msg__bubble {
    background: var(--tai-bot-bubble);
    color: var(--tai-text);
    border-bottom-left-radius: 5px;
}
.tahdco-ai-msg--user .tahdco-ai-msg__bubble {
    background: var(--tai-user-bubble);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.tahdco-ai-msg__bubble em { color: var(--tai-primary-dark); font-style: normal; font-weight: 600; }
.tahdco-ai-msg--bot .tahdco-ai-msg__bubble i.bi { color: var(--tai-primary); margin-right: 2px; }

/* typing indicator */
.tahdco-ai-typing { display: inline-flex; gap: 4px; align-items: center; }
.tahdco-ai-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--tai-primary-light);
    display: inline-block;
    animation: tahdco-ai-bounce 1.2s infinite ease-in-out;
}
.tahdco-ai-typing span:nth-child(2) { animation-delay: .15s; }
.tahdco-ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tahdco-ai-bounce { 0%,80%,100% { transform: scale(.6); opacity:.5;} 40% { transform: scale(1); opacity:1;} }

/* ---- Summary card (form completion) ------------------------------ */
.tahdco-ai-summary { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.tahdco-ai-summary__row {
    display: flex; justify-content: space-between; gap: 10px;
    font-size: 13px;
    padding: 6px 9px;
    background: #fff;
    border-radius: 9px;
    border: 1px solid #e1e8f2;
}
.tahdco-ai-summary__row span { color: var(--tai-muted); }
.tahdco-ai-summary__row b { color: var(--tai-text); text-align: right; }

/* ---- Quick-action chips ------------------------------------------ */
.tahdco-ai-quick {
    display: flex; flex-wrap: wrap; gap: 7px;
    padding: 4px 14px 10px;
    max-height: 168px; overflow-y: auto;
}
.tahdco-ai-quick:empty { display: none; }
.tahdco-ai-chip {
    border: 1px solid var(--tai-primary-light);
    background: #fff;
    color: var(--tai-primary-dark);
    font-family: var(--tai-font-body);
    font-size: 12.5px;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: var(--radius-pill, 50px);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .1s ease;
    display: inline-flex; align-items: center; gap: 5px;
}
.tahdco-ai-chip:hover { background: var(--tai-primary); color: #fff; transform: translateY(-1px); }
.tahdco-ai-chip:focus-visible { outline: 2px solid var(--tai-accent); outline-offset: 2px; }

/* ---- Input row --------------------------------------------------- */
.tahdco-ai-input {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    background: var(--tai-surface);
    border-top: 1px solid #e3e9f2;
}
.tahdco-ai-input__field {
    flex: 1;
    border: 1px solid #d4deec;
    border-radius: var(--radius-pill, 50px);
    padding: 10px 15px;
    font-size: 14px;
    font-family: var(--tai-font-body);
    color: var(--tai-text);
    outline: none;
    background: #fff;
}
.tahdco-ai-input__field:focus { border-color: var(--tai-primary); box-shadow: 0 0 0 3px rgba(21,101,192,.12); }
.tahdco-ai-input__mic,
.tahdco-ai-input__send {
    width: 42px; height: 42px; flex: 0 0 42px;
    border: none; border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px;
    transition: transform .12s ease, background .15s ease;
}
.tahdco-ai-input__mic { background: #eef3fb; color: var(--tai-primary); }
.tahdco-ai-input__mic:hover { background: #e0e9f7; }
.tahdco-ai-input__mic.is-listening { background: #e53935; color: #fff; animation: tahdco-ai-mic 1s infinite; }
.tahdco-ai-input__mic.is-hidden { display: none; }
@keyframes tahdco-ai-mic { 0%,100%{ box-shadow:0 0 0 0 rgba(229,57,53,.5);} 50%{ box-shadow:0 0 0 8px rgba(229,57,53,0);} }
.tahdco-ai-input__send { background: linear-gradient(135deg, var(--tai-primary), var(--tai-primary-dark)); color: #fff; }
.tahdco-ai-input__send:hover { transform: scale(1.06); }
.tahdco-ai-input__mic:focus-visible,
.tahdco-ai-input__send:focus-visible { outline: 2px solid var(--tai-accent); outline-offset: 2px; }

/* ---- Responsiveness ---------------------------------------------- */

/* Tablets & large phones: a bit narrower margin, slightly taller panel */
@media (max-width: 768px) and (min-width: 481px) {
    .tahdco-ai { right: 18px; bottom: 18px; }
    .tahdco-ai-panel {
        width: min(400px, calc(100vw - 28px));
        height: min(600px, calc(100dvh - 36px));
    }
    .tahdco-ai-panel.is-expanded {
        width: min(520px, calc(100vw - 28px));
        height: min(720px, calc(100dvh - 36px));
    }
}

/* Phones: full-screen sheet, respecting notch / home-indicator safe areas */
@media (max-width: 480px) {
    .tahdco-ai { right: 14px; bottom: 14px; }
    .tahdco-ai-panel {
        position: fixed;
        right: 0; left: 0; bottom: 0; top: 0;
        width: 100vw; height: 100vh;
        width: 100vw; height: 100dvh;
        max-width: 100vw; max-height: 100dvh;
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .tahdco-ai-fab { width: 62px; height: 62px; border-radius: 22px; }
    .tahdco-ai-panel__expand { display: none; }
    .tahdco-ai-panel__head { padding-top: max(14px, env(safe-area-inset-top, 0)); }
}

/* Short / landscape screens: keep the panel from overflowing vertically */
@media (max-height: 520px) {
    .tahdco-ai-panel { height: calc(100dvh - 16px); max-height: calc(100dvh - 16px); }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .tahdco-ai-fab__ring,
    .tahdco-ai-typing span,
    .tahdco-ai-input__mic.is-listening { animation: none; }
    .tahdco-ai-panel { animation: none; }
}

/* ---- Teaser popup (appears beside the FAB on first visit) -------- */
.tahdco-ai-teaser {
    position: absolute;
    right: 4px;
    bottom: 80px;                 /* just above the FAB; FAB stays visible */
    max-width: 250px;
    background: #fff;
    color: var(--tai-text);
    border: 1px solid rgba(13, 71, 161, .12);
    border-radius: 14px;
    box-shadow: var(--tai-shadow);
    padding: 12px 30px 12px 14px;
    font-size: 13.5px;
    line-height: 1.45;
    cursor: pointer;
    animation: tahdco-ai-teaser-in .3s ease both;
}
.tahdco-ai-teaser[hidden] { display: none !important; }
.tahdco-ai-teaser::after {        /* tail pointing down toward the FAB */
    content: ''; position: absolute; right: 24px; bottom: -7px;
    width: 14px; height: 14px; background: #fff;
    border-right: 1px solid rgba(13, 71, 161, .12);
    border-bottom: 1px solid rgba(13, 71, 161, .12);
    transform: rotate(45deg);
}
.tahdco-ai-teaser__text { display: block; }
.tahdco-ai-teaser__close {
    position: absolute; top: 3px; right: 3px;
    border: none; background: transparent; color: var(--tai-muted);
    cursor: pointer; font-size: 15px; line-height: 1; padding: 3px; border-radius: 6px;
}
.tahdco-ai-teaser__close:hover { background: rgba(0, 0, 0, .06); }
@keyframes tahdco-ai-teaser-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* On phones the panel is full-screen; keep the teaser compact */
@media (max-width: 480px) {
    .tahdco-ai-teaser { max-width: min(250px, calc(100vw - 90px)); }
}

/* ---- Language dropdown (chat header) ----------------------------- */
.tahdco-ai-langwrap { position: relative; flex: 0 0 auto; }
.tahdco-ai-langtoggle {
    display: inline-flex; align-items: center; gap: 5px;
    border: 1px solid rgba(255, 255, 255, .45);
    background: rgba(255, 255, 255, .12);
    color: #fff; font-size: 12px; font-weight: 600;
    padding: 5px 8px; border-radius: 10px; cursor: pointer;
    font-family: var(--tai-font-body); line-height: 1; white-space: nowrap;
}
.tahdco-ai-langtoggle:hover { background: rgba(255, 255, 255, .22); }
.tahdco-ai-langtoggle:focus-visible { outline: 2px solid var(--tai-accent); outline-offset: 2px; }
.tahdco-ai-langtoggle .tahdco-ai-langcaret { font-size: 9px; opacity: .85; }
.tahdco-ai-langmenu {
    position: absolute; top: calc(100% + 6px); right: 0;
    margin: 0; padding: 6px; list-style: none;
    background: #fff; color: var(--tai-text);
    border-radius: 12px; box-shadow: 0 14px 36px rgba(13, 71, 161, .28);
    min-width: 150px; z-index: 5;
}
.tahdco-ai-langmenu[hidden] { display: none; }
.tahdco-ai-langitem {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px; border-radius: 8px; cursor: pointer;
    font-size: 14px; font-weight: 500;
}
.tahdco-ai-langitem:hover { background: var(--tai-bot-bubble); }
.tahdco-ai-langitem.is-active { background: var(--tai-bot-bubble); color: var(--tai-primary-dark); font-weight: 700; }
.tahdco-ai-langitem .bi-check2 { color: var(--tai-primary); font-size: 16px; }

/* =====================================================================
   FIX: site top-header language dropdown (#thLang) would not open.
   Cause: two site stylesheets style .th-lang-drop differently —
   inner-hero.css sets `display:none` and only shows it via
   `.th-lang-drop.open`, but navbar.js adds `.open` to the PARENT
   (.th-lang / #thLang), so that selector never matched and the
   `display:none` overrode top-header.css's visibility-based show rule.
   This additive rule (loaded after the site CSS) forces the list visible
   when the switcher is open. No site files are modified.
   ===================================================================== */
/* Lift the whole top-header (a direct child of <body>) above the navbar.
   The navbar carries a high z-index (up to 9999) which was painting over the
   dropdown; the top-header was only 2000. This puts it — and its dropdown —
   on top. (Top-header sits at the very top and never overlaps page content,
   so a high z-index here is safe.) */
#topHeader,
.top-header { z-index: 1000000 !important; }

#thLang.open .th-lang-drop,
.th-lang.open .th-lang-drop {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: auto !important;
    z-index: 1000001 !important;
}
/* same fix for the main navbar's language dropdown, if present */
#langSwitch.open #langDropdown,
.lang-switch.open .lang-dropdown {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: auto !important;
    z-index: 1000001 !important;
}
