/* ==========================================================================
   AVP Tech Solution - Chat assistant widget (includes/chatbot_widget.php)
   Uses the site's Ivory & Ink tokens from main.css.
   ========================================================================== */

.chatbot {
    position: fixed;
    right: clamp(0.85rem, 2vw, 1.5rem);
    bottom: clamp(0.85rem, 2vw, 1.5rem);
    z-index: calc(var(--z-drawer) + 2);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    font-family: var(--font-body);
}
.chatbot[hidden] { display: none; }

/* Launcher: just the waving robot (no button shape) with a "Hi 👋" bubble beside it */
.chatbot-launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 76px;
    height: 76px;
    padding: 0;
    color: #fff;
    font: inherit;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast), background var(--transition-fast);
}
.chatbot-launcher:hover { transform: translateY(-3px) scale(1.04); }
.chatbot-launcher:focus-visible { outline: 3px solid var(--brand-line); outline-offset: 2px; }
.chatbot-launcher-icon { display: inline-flex; }
.chatbot-robot svg { filter: drop-shadow(0 6px 10px rgba(15, 26, 46, 0.28)); }

.chatbot-hello {
    position: absolute;
    right: calc(100% - 4px);
    top: 2px;
    padding: 0.45rem 0.8rem;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--shadow-md);
    transform-origin: 100% 100%;
    /* Visible by default; the pop-in only plays where animations run. */
    animation: chatbot-hello-pop 0.5s var(--ease), chatbot-hello-bob 3.2s ease-in-out 0.5s infinite;
}
.chatbot-hello-hand { display: inline-block; transform-origin: 70% 80%; animation: chatbot-hello-hand 3.2s ease-in-out 1.5s infinite; }
@keyframes chatbot-hello-pop {
    from { opacity: 0; transform: scale(0.6) translateY(6px); }
    to   { opacity: 1; transform: none; }
}
@keyframes chatbot-hello-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}
@keyframes chatbot-hello-hand {
    0%, 55%, 100% { transform: rotate(0deg); }
    10%, 30% { transform: rotate(18deg); }
    20%, 40% { transform: rotate(-10deg); }
}
.chatbot.is-open .chatbot-hello { display: none; }

/* Waving robot on the launcher */
.chatbot-robot svg { display: block; overflow: visible; }
.chatbot-robot .robot-arm {
    transform-box: view-box;
    transform-origin: 29.5px 35px;
    animation: robot-wave 3.2s ease-in-out infinite;
}
.chatbot-robot .robot-eye {
    transform-box: fill-box;
    transform-origin: center;
    animation: robot-blink 4.5s infinite;
}
.chatbot-robot .robot-antenna { animation: robot-glow 2.4s ease-in-out infinite; }
.chatbot-launcher:hover .robot-arm,
.chatbot-launcher:focus-visible .robot-arm { animation-duration: 1.2s; }
@keyframes robot-wave {
    0%, 55%, 100% { transform: rotate(0deg); }
    8%  { transform: rotate(-24deg); }
    16% { transform: rotate(12deg); }
    24% { transform: rotate(-24deg); }
    32% { transform: rotate(12deg); }
    40% { transform: rotate(-12deg); }
}
@keyframes robot-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}
@keyframes robot-glow {
    0%, 100% { fill: #B8893B; }
    50% { fill: #F2C46B; }
}
.chatbot-launcher-icon--close { display: none; }
.chatbot.is-open .chatbot-launcher-icon--open { display: none; }
.chatbot.is-open .chatbot-launcher-icon--close { display: inline-flex; }
/* While the chat is open the launcher becomes a round close button */
.chatbot.is-open .chatbot-launcher { width: 56px; height: 56px; background: var(--ink); box-shadow: var(--shadow-lg); }
.chatbot.is-open .chatbot-launcher:hover { background: var(--brand); }

/* Panel */
.chatbot-panel {
    display: flex;
    flex-direction: column;
    width: min(390px, calc(100vw - 1.7rem));
    height: min(600px, calc(100dvh - 7rem));
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: chatbot-in 0.25s var(--ease);
}
.chatbot-panel[hidden] { display: none; }
@keyframes chatbot-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.chatbot-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 0.75rem 0.85rem 1rem;
    color: #fff;
    background: var(--ink);
}
.chatbot-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 38px;
    height: 38px;
    color: var(--ink);
    background: var(--gold-soft);
    border-radius: 50%;
}
.chatbot-head-text { flex: 1; min-width: 0; }
.chatbot-head h2 {
    margin: 0;
    color: #fff;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
}
.chatbot-head p { margin: 0; color: rgba(255, 255, 255, 0.72); font-size: 0.78rem; }
.chatbot-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: #fff;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}
.chatbot-icon-btn:hover,
.chatbot-icon-btn:focus-visible { background: rgba(255, 255, 255, 0.14); outline: none; }

/* Messages */
.chatbot-log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    background: var(--paper);
    scroll-behavior: smooth;
}
.chatbot-log:focus-visible { outline: 2px solid var(--brand-line); outline-offset: -2px; }
.chatbot-msg { display: flex; flex-direction: column; margin-bottom: 0.75rem; }
.chatbot-msg--user { align-items: flex-end; }
.chatbot-msg--bot { align-items: flex-start; }
.chatbot-bubble {
    max-width: 88%;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px 16px 16px 4px;
    overflow-wrap: anywhere;
}
.chatbot-msg--user .chatbot-bubble {
    color: #fff;
    white-space: pre-wrap;
    background: var(--brand);
    border-color: var(--brand);
    border-radius: 16px 16px 4px 16px;
}
.chatbot-bubble p { margin: 0; }
.chatbot-bubble p + p,
.chatbot-bubble p + ul,
.chatbot-bubble ul + p { margin-top: 0.55rem; }
.chatbot-bubble ul { margin: 0.35rem 0 0; padding-left: 1.1rem; list-style: disc; }
.chatbot-bubble li + li { margin-top: 0.2rem; }
.chatbot-bubble strong { color: var(--ink); }
.chatbot-bubble a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.chatbot-sources { max-width: 88%; margin-top: 0.3rem; font-size: 0.74rem; color: var(--ink-3); }
.chatbot-sources a { color: var(--ink-3); text-decoration: underline; }

.chatbot-typing .chatbot-bubble { display: inline-flex; gap: 4px; padding: 0.8rem 0.9rem; }
.chatbot-typing span {
    width: 7px;
    height: 7px;
    background: var(--ink-4);
    border-radius: 50%;
    animation: chatbot-dot 1.2s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-dot {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40%           { opacity: 1;    transform: translateY(-3px); }
}

/* Suggested questions */
.chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 1rem 0.2rem;
    background: var(--paper);
}
.chatbot-suggestions[hidden] { display: none; }
.chatbot-chip {
    padding: 0.4rem 0.75rem;
    color: var(--brand);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: left;
    background: var(--brand-soft);
    border: 1px solid var(--brand-line);
    border-radius: var(--radius-full);
    cursor: pointer;
}
.chatbot-chip:hover,
.chatbot-chip:focus-visible { background: #fff; outline: none; border-color: var(--brand); }

/* Input */
.chatbot-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.75rem;
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.chatbot-form[hidden] { display: none; }
.chatbot-form textarea {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 0.6rem 0.8rem;
    color: var(--ink);
    font: inherit;
    font-size: 0.92rem;
    line-height: 1.4;
    background: var(--paper);
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    resize: none;
}
.chatbot-form textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chatbot-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 42px;
    height: 42px;
    color: #fff;
    background: var(--brand);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}
.chatbot-send:hover { background: var(--brand-hover); }
.chatbot-send:disabled { opacity: 0.5; cursor: wait; }
.chatbot-send:focus-visible { outline: 3px solid var(--brand-line); outline-offset: 2px; }

/* "Talk to a human" form */
.chatbot-lead {
    display: grid;
    gap: 0.45rem;
    padding: 0.8rem 1rem;
    background: var(--sand);
    border-top: 1px solid var(--line);
}
.chatbot-lead[hidden] { display: none; }
.chatbot-lead-title { margin: 0 0 0.15rem; font-size: 0.85rem; font-weight: 600; color: var(--ink); }
.chatbot-lead input,
.chatbot-lead textarea {
    width: 100%;
    padding: 0.5rem 0.7rem;
    color: var(--ink);
    font: inherit;
    font-size: 0.88rem;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
}
.chatbot-lead input:focus,
.chatbot-lead textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chatbot-lead-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.chatbot-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.6rem;
    padding: 0.5rem 1rem 0.65rem;
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--ink-3);
    background: var(--surface);
}
.chatbot-foot a { color: var(--ink-3); text-decoration: underline; }
.chatbot-human {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    color: var(--teal);
    font: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    background: var(--teal-soft);
    border: 1px solid var(--teal-line);
    border-radius: var(--radius-full);
    cursor: pointer;
}
.chatbot-human[hidden] { display: none; }

@media (max-width: 520px) {
    .chatbot-launcher { width: 66px; height: 66px; }
    .chatbot-robot svg { width: 58px; height: 58px; }
    .chatbot.is-open { left: 0.6rem; right: 0.6rem; bottom: 0.6rem; }
    .chatbot.is-open .chatbot-panel { width: 100%; height: calc(100dvh - 5.5rem); }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-panel { animation: none; }
    .chatbot-typing span { animation: none; opacity: 0.6; }
    .chatbot-robot .robot-arm,
    .chatbot-robot .robot-eye,
    .chatbot-robot .robot-antenna,
    .chatbot-hello,
    .chatbot-hello-hand { animation: none; }
    .chatbot-log { scroll-behavior: auto; }
}

@media print { .chatbot { display: none !important; } }
