/* ---------------------------------------------------------------------------
   Live chat widget.
   --------------------------------------------------------------------------- */

.chat-widget {
    --chat-brand:  #06BBCC;
    --chat-accent: #F57905;
    --chat-navy:   #10233f;
    --chat-line:   #e2e8f2;
    --chat-muted:  #64708a;

    position: fixed;
    /* Bottom-left, so it never collides with the back-to-top button that sits
       bottom-right in this template. */
    left: 24px;
    bottom: 24px;
    z-index: 1080;               /* above .back-to-top (99) and the footer */
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* --- Launcher bubble ------------------------------------------------------
   Icon only: a round 60px button. The label appears as a tooltip on hover and
   focus, so the control still announces itself without occupying the corner. */

.chat-launcher {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--chat-brand);
    color: #fff;
    font: inherit;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(6, 187, 204, .42);
    transition: transform .25s cubic-bezier(.34, 1.56, .64, 1),
                background-color .25s ease,
                box-shadow .25s ease;
}

.chat-launcher:hover,
.chat-launcher:focus-visible {
    background: #049aa8;
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 14px 34px rgba(6, 187, 204, .5);
}
.chat-launcher:active { transform: scale(.96); }
.chat-launcher:focus-visible { outline: 3px solid rgba(6, 187, 204, .45); outline-offset: 3px; }

.chat-launcher__icon {
    font-size: 1.45rem;
    line-height: 1;
    transition: transform .3s cubic-bezier(.34, 1.56, .64, 1), opacity .2s ease;
}

/* The icon flips to a close mark while the panel is open. */
.chat-launcher__icon--close { position: absolute; opacity: 0; transform: rotate(-90deg) scale(.5); }
.chat-launcher[aria-expanded="true"] .chat-launcher__icon--open  { opacity: 0; transform: rotate(90deg) scale(.5); }
.chat-launcher[aria-expanded="true"] .chat-launcher__icon--close { opacity: 1; transform: rotate(0) scale(1); }
.chat-launcher[aria-expanded="true"] { background: var(--chat-navy); box-shadow: 0 10px 28px rgba(16, 35, 63, .45); }

/* Attention ring — a slow outward pulse while the chat has never been opened.
   Purely decorative, and it stops as soon as the visitor engages. */
.chat-launcher::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--chat-brand);
    opacity: 0;
    pointer-events: none;
}
.chat-widget:not(.chat-widget--engaged) .chat-launcher::after {
    animation: chat-pulse 2.6s ease-out infinite;
}

@keyframes chat-pulse {
    0%   { transform: scale(1);    opacity: .7; }
    70%  { transform: scale(1.55); opacity: 0; }
    100% { transform: scale(1.55); opacity: 0; }
}

/* Tooltip label, shown on hover/focus only.
   Positioned ABOVE the launcher, not beside it: the translate button now sits
   immediately to the right, and a sideways tooltip would open straight across
   it. */
.chat-launcher__label {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%) translateY(6px);
    padding: .45rem .8rem;
    border-radius: .45rem;
    background: var(--chat-navy);
    color: #fff;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.chat-launcher__label::before {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--chat-navy);
}
.chat-launcher:hover .chat-launcher__label,
.chat-launcher:focus-visible .chat-launcher__label {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.chat-launcher[aria-expanded="true"] .chat-launcher__label { display: none; }

.chat-launcher__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: var(--chat-accent);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
}
.chat-launcher__badge.is-visible {
    display: inline-flex;
    animation: chat-pop .4s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes chat-pop {
    0%   { transform: scale(0); }
    100% { transform: scale(1); }
}

/* --- Panel ---------------------------------------------------------------- */

.chat-panel {
    position: absolute;
    left: 0;
    bottom: calc(100% + 14px);
    width: 370px;
    transform-origin: bottom left;
    animation: chat-panel-in .22s cubic-bezier(.34, 1.56, .64, 1);
    max-width: calc(100vw - 32px);
    max-height: min(560px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--chat-line);
    border-radius: 1rem;
    box-shadow: 0 24px 60px rgba(16, 35, 63, .28);
}
.chat-panel.is-open { display: flex; }

@keyframes chat-panel-in {
    from { opacity: 0; transform: scale(.92) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.1rem;
    background: var(--chat-navy);
    color: #fff;
}
.chat-head__avatar {
    width: 40px; height: 40px; flex: 0 0 40px;
    border-radius: 50%;
    background: var(--chat-brand);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem;
}
.chat-head__title { font-weight: 600; font-size: .98rem; line-height: 1.2; }
.chat-head__status { font-size: .78rem; color: rgba(255, 255, 255, .7); display: flex; align-items: center; gap: .35rem; }
.chat-head__dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa5bd; }
.chat-head__dot.is-online { background: #35c759; }
.chat-head__close {
    margin-left: auto;
    background: none; border: 0; color: #fff;
    font-size: 1.5rem; line-height: 1; cursor: pointer; opacity: .75;
    padding: 0 .25rem;
}
.chat-head__close:hover { opacity: 1; }

/* --- Body ----------------------------------------------------------------- */

/* flex-basis 0 + min-height 0 lets this shrink when the intake form needs the
   room. Without min-height:0 a flex child refuses to go below its content size,
   which is what pushes the form's lower fields out of the panel. */
.chat-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 1.1rem;
    background: #f7f9fc;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.chat-intro {
    background: #fff;
    border: 1px solid var(--chat-line);
    border-radius: .75rem;
    padding: .85rem 1rem;
    font-size: .88rem;
    color: var(--chat-muted);
    line-height: 1.6;
}

.chat-msg { max-width: 82%; display: flex; flex-direction: column; gap: .2rem; }
.chat-msg--visitor { align-self: flex-end; align-items: flex-end; }
.chat-msg--staff   { align-self: flex-start; align-items: flex-start; }

.chat-msg__bubble {
    padding: .6rem .9rem;
    border-radius: 1rem;
    font-size: .9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-msg--visitor .chat-msg__bubble { background: var(--chat-brand); color: #fff; border-bottom-right-radius: .3rem; }
.chat-msg--staff   .chat-msg__bubble { background: #fff; color: #2b3448; border: 1px solid var(--chat-line); border-bottom-left-radius: .3rem; }

.chat-msg__meta { font-size: .7rem; color: var(--chat-muted); padding: 0 .35rem; }

.chat-note {
    text-align: center;
    font-size: .8rem;
    color: var(--chat-muted);
    padding: .35rem 0;
}
.chat-note--error { color: #b3261e; }

/* --- Pre-chat form and composer -------------------------------------------- */

/* The intake form is taller than the composer that replaces it, so this pane
   scrolls in its own right. On a short screen the visitor can always reach the
   message box and the Start chat button rather than having them clipped by the
   panel's overflow:hidden. */
.chat-foot {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 70%;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid var(--chat-line);
    background: #fff;
    padding: .85rem 1rem;
}

/* A slim scrollbar, so the panel does not look like a browser window. */
.chat-body,
.chat-foot {
    scrollbar-width: thin;
    scrollbar-color: #c3cede transparent;
}
.chat-body::-webkit-scrollbar,
.chat-foot::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-track,
.chat-foot::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb,
.chat-foot::-webkit-scrollbar-thumb {
    background: #c3cede;
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.chat-body::-webkit-scrollbar-thumb:hover,
.chat-foot::-webkit-scrollbar-thumb:hover { background: #9fadc4; background-clip: content-box; }

.chat-field { margin-bottom: .55rem; }
.chat-field label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: var(--chat-navy);
    margin-bottom: .2rem;
}
.chat-field input,
.chat-field textarea {
    width: 100%;
    padding: .5rem .65rem;
    border: 1px solid var(--chat-line);
    border-radius: .45rem;
    font: inherit;
    font-size: .88rem;
    color: #2b3448;
    background: #fff;
}
.chat-field input:focus,
.chat-field textarea:focus {
    outline: none;
    border-color: var(--chat-brand);
    box-shadow: 0 0 0 3px rgba(6, 187, 204, .16);
}
.chat-field textarea { resize: vertical; min-height: 66px; }

.chat-submit {
    width: 100%;
    padding: .6rem;
    border: 0;
    border-radius: .45rem;
    background: var(--chat-accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.chat-submit:hover { background: #d66703; }
.chat-submit:disabled { opacity: .6; cursor: not-allowed; }

.chat-composer { display: flex; gap: .5rem; align-items: flex-end; }
.chat-composer textarea {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: .55rem .7rem;
    border: 1px solid var(--chat-line);
    border-radius: .6rem;
    font: inherit;
    font-size: .9rem;
    resize: none;
}
.chat-composer textarea:focus { outline: none; border-color: var(--chat-brand); }
.chat-send {
    width: 42px; height: 42px; flex: 0 0 42px;
    border: 0; border-radius: 50%;
    background: var(--chat-brand); color: #fff;
    cursor: pointer; font-size: .95rem;
}
.chat-send:hover { background: #049aa8; }
.chat-send:disabled { opacity: .55; cursor: not-allowed; }

.chat-legal { font-size: .7rem; color: var(--chat-muted); margin: .5rem 0 0; text-align: center; line-height: 1.5; }
.chat-legal a { color: var(--chat-muted); }

.chat-hidden { display: none !important; }

/* --- Responsive ------------------------------------------------------------ */

@media (max-width: 480px) {
    .chat-widget { left: 14px; bottom: 14px; }
    .chat-panel {
        width: calc(100vw - 28px);
        max-height: calc(100vh - 96px);
    }
    .chat-launcher { width: 54px; height: 54px; }
    .chat-launcher__icon { font-size: 1.3rem; }
    /* No room for a tooltip beside a full-width panel on a phone. */
    .chat-launcher__label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-launcher,
    .chat-launcher__icon,
    .chat-launcher__label,
    .chat-panel { transition: none; animation: none; }
    .chat-launcher:hover,
    .chat-launcher:focus-visible,
    .chat-launcher:active { transform: none; }
    .chat-widget:not(.chat-widget--engaged) .chat-launcher::after { animation: none; }
    .chat-launcher__badge.is-visible { animation: none; }
}
