/* =====================================================================
   Switch&Save AI Chat — self-contained widget styles
   All rules are scoped under .sas-chat so nothing leaks to/from the theme.
   ===================================================================== */

.sas-chat,
.sas-chat *,
.sas-chat *::before,
.sas-chat *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.sas-chat {
    position: fixed;
    bottom: 22px;
    z-index: 2147483000; /* above sticky headers, popups, etc. */
    direction: ltr;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #1f2937;
    -webkit-font-smoothing: antialiased;
}
.sas-chat--right { right: 22px; }
.sas-chat--left  { left: 22px; }

/* ---- Launcher button (FAB) ---- */
.sas-chat__launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 58px;
    padding: 0 22px 0 18px;
    border: 0;
    cursor: pointer;
    border-radius: 999px;
    background: linear-gradient(135deg, #2b8aff 0%, #0a58c2 100%);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(10, 88, 194, 0.4);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.sas-chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(10, 88, 194, 0.5); }
.sas-chat__launcher:active { transform: translateY(0); }
.sas-chat__launcher svg { width: 24px; height: 24px; flex-shrink: 0; }
.sas-chat__launcher::after {
    /* gentle attention pulse */
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 999px;
    box-shadow: 0 0 0 0 rgba(43, 138, 255, 0.5);
    animation: sasPulse 2.6s infinite;
    pointer-events: none;
}
@keyframes sasPulse { 0% { box-shadow: 0 0 0 0 rgba(43,138,255,0.45); } 70% { box-shadow: 0 0 0 16px rgba(43,138,255,0); } 100% { box-shadow: 0 0 0 0 rgba(43,138,255,0); } }
.sas-chat.is-open .sas-chat__launcher { display: none; }

/* Unread badge on the launcher */
.sas-chat__badge {
    position: absolute;
    top: -5px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.sas-chat--left .sas-chat__badge { right: auto; left: -3px; }
.sas-chat.is-open .sas-chat__badge { display: none; }

/* "New reply" preview bubble above the launcher when the chat is closed */
.sas-chat__nudge {
    position: absolute;
    bottom: 74px;
    max-width: 270px;
    border: 1px solid #eceff3;
    background: #fff;
    color: #1f2937;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    text-align: left;
    padding: 12px 14px;
    border-radius: 16px;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.24);
    cursor: pointer;
    animation: sasIn 0.2s ease;
}
.sas-chat__nudge::before {
    content: 'New reply';
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #2b8aff;
    margin-bottom: 3px;
}
.sas-chat--right .sas-chat__nudge { right: 0; }
.sas-chat--left  .sas-chat__nudge { left: 0; }
.sas-chat.is-open .sas-chat__nudge { display: none; }

/* ---- Panel ---- */
.sas-chat__panel {
    position: absolute;
    bottom: 0;
    width: 396px;
    max-width: calc(100vw - 32px);
    height: 624px;
    max-height: calc(100vh - 112px);
    display: none; /* shown via .is-open — do NOT rely on the [hidden] attr, author display wins over it */
    flex-direction: column;
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.32);
    transform-origin: bottom right;
    animation: sasIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.sas-chat--right .sas-chat__panel { right: 0; transform-origin: bottom right; }
.sas-chat--left  .sas-chat__panel { left: 0;  transform-origin: bottom left; }
@keyframes sasIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.sas-chat.is-open .sas-chat__panel { display: flex; } /* the only thing that shows the panel */

/* ---- Header ---- */
.sas-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 18px;
    background: linear-gradient(135deg, #2b8aff 0%, #0a58c2 100%);
    color: #fff;
}
.sas-chat__brand { display: flex; align-items: center; gap: 12px; }
.sas-chat__avatar {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 16px; letter-spacing: 0.5px;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
}
.sas-chat__brand-text { display: flex; flex-direction: column; }
.sas-chat__brand-text strong { font-size: 15px; font-weight: 700; }
.sas-chat__status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; opacity: 0.9; margin-top: 1px; }
.sas-chat__dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); animation: sasBlink 2s infinite; }
@keyframes sasBlink { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,0.6); } 70% { box-shadow: 0 0 0 6px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }
.sas-chat__close {
    width: 34px; height: 34px; flex-shrink: 0;
    border: 0; cursor: pointer;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff; font-size: 22px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s ease;
}
.sas-chat__close:hover { background: rgba(255, 255, 255, 0.32); }

/* ---- Messages ---- */
.sas-chat__messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f5f7fb;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.sas-chat__messages::-webkit-scrollbar { width: 8px; }
.sas-chat__messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }

.sas-chat__msg {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.sas-chat__msg--bot   { align-self: flex-start; background: #fff; color: #1f2937; border: 1px solid #eceff3; border-bottom-left-radius: 5px; }
.sas-chat__msg--user  { align-self: flex-end; background: linear-gradient(135deg, #2b8aff, #1877f2); color: #fff; border-bottom-right-radius: 5px; }
.sas-chat__msg--agent { align-self: flex-start; background: #eaf7ee; color: #14532d; border: 1px solid #bbe6c9; border-bottom-left-radius: 5px; }
.sas-chat__msg--error { align-self: center; max-width: 92%; text-align: center; background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; font-size: 13px; }
.sas-chat__msg-label { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.75; margin-bottom: 3px; }
.sas-chat__msg--agent .sas-chat__msg-label { color: #15803d; }
.sas-chat__msg-body { display: block; }
.sas-chat__time { display: block; margin-top: 4px; font-size: 10px; line-height: 1; text-align: right; opacity: 0.7; }
.sas-chat__msg--user .sas-chat__time { color: rgba(255, 255, 255, 0.85); }
.sas-chat__msg--bot .sas-chat__time, .sas-chat__msg--agent .sas-chat__time { color: #8a93a3; }
.sas-chat__daydiv { align-self: center; margin: 4px 0 2px; }
.sas-chat__daydiv span { display: inline-block; background: #e6e9ef; color: #5b6472; font-size: 11px; font-weight: 600; padding: 3px 11px; border-radius: 999px; }
.sas-chat__receipt { display: block; margin-top: 3px; font-size: 10px; line-height: 1; text-align: right; color: rgba(255, 255, 255, 0.85); }
.sas-chat__receipt.is-seen { color: #dbeafe; font-weight: 600; }

/* ---- Typing indicator ---- */
.sas-chat__typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: 13px 15px; background: #fff; border: 1px solid #eceff3; border-radius: 16px; border-bottom-left-radius: 5px; }
.sas-chat__typing span { width: 7px; height: 7px; border-radius: 50%; background: #9aa5b4; animation: sasBounce 1.3s infinite ease-in-out; }
.sas-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.sas-chat__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sasBounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---- Post-chat rating ---- */
.sas-chat__rate { align-self: center; display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; padding: 8px 14px; background: #fff; border: 1px solid #e3e8ef; border-radius: 22px; box-shadow: 0 2px 6px rgba(16,24,40,.06); font-size: 13.5px; color: #1f2937; }
.sas-chat__rate-q { font-weight: 600; }
.sas-chat__rate-btn { border: 1px solid #e3e8ef; background: #f7f9fc; border-radius: 50%; width: 34px; height: 34px; font-size: 16px; line-height: 1; cursor: pointer; transition: transform .12s ease, background .12s ease; }
.sas-chat__rate-btn:hover { background: #eef4ff; transform: scale(1.1); }

/* ---- Quick-reply chips ---- */
.sas-chat__chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; background: #f5f7fb; }
.sas-chat__chip {
    border: 1px solid #cfdbf0;
    background: #fff;
    color: #0a58c2;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 13px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.sas-chat__chip:hover { background: #eef4ff; border-color: #2b8aff; }

/* In-chat appointment form (no AI) */
.sas-chat__apptform {
    align-self: stretch;
    background: #fff;
    border: 1px solid #eceff3;
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.sas-chat__appt-intro { margin: 0 0 2px; font-size: 13.5px; color: #475569; }
.sas-chat__appt-in {
    width: 100%;
    border: 1px solid #d6dce5;
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 14px;
    font-family: inherit;
    color: #1f2937;
    background: #fff;
    outline: none;
}
.sas-chat__appt-in:focus { border-color: #2b8aff; box-shadow: 0 0 0 3px rgba(43, 138, 255, 0.15); }
.sas-chat__appt-submit {
    margin-top: 4px;
    border: 0;
    border-radius: 11px;
    padding: 11px;
    background: linear-gradient(135deg, #2b8aff, #0a58c2);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}
.sas-chat__appt-submit:hover { filter: brightness(1.07); }
.sas-chat__appt-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.sas-chat__appt-msg { margin: 2px 0 0; font-size: 12.5px; color: #b91c1c; min-height: 1px; }

/* ---- Composer ---- */
.sas-chat__turnstile {
    padding: 8px 12px 0;
    border-top: 1px solid #eceff3;
    background: #fff;
    min-height: 1px;
}
.sas-chat__turnstile[hidden] { display: none; }
.sas-chat__hp {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}
.sas-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #eceff3;
    background: #fff;
}
.sas-chat__input {
    flex: 1;
    border: 1px solid #d6dce5;
    border-radius: 14px;
    padding: 11px 14px;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.4;
    color: #1f2937;
    background: #fff;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sas-chat__input::placeholder { color: #9aa5b4; }
.sas-chat__input:focus { border-color: #2b8aff; box-shadow: 0 0 0 3px rgba(43, 138, 255, 0.16); }
.sas-chat__send {
    flex-shrink: 0;
    width: 44px; height: 44px;
    border: 0; border-radius: 13px;
    background: linear-gradient(135deg, #2b8aff, #0a58c2);
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: filter 0.15s ease, transform 0.1s ease;
}
.sas-chat__send svg { width: 20px; height: 20px; }
.sas-chat__send:hover { filter: brightness(1.08); }
.sas-chat__send:active { transform: scale(0.95); }
.sas-chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Footer ---- */
.sas-chat__footer {
    margin: 0;
    padding: 9px 14px 12px;
    font-size: 11px;
    color: #9aa5b4;
    text-align: center;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sas-chat__footer a { color: #0a58c2; text-decoration: none; font-weight: 600; }
.sas-chat__privacy { color: #7b8796; line-height: 1.35; }
.sas-chat__status.is-closed .sas-chat__dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.sas-chat__status.is-live { opacity: 1; font-weight: 600; }
.sas-chat__status.is-live .sas-chat__dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25); }

/* ---- Mobile ---- */
@media (max-width: 600px) {
    /* The theme applies translateZ(0) to almost every mobile element. A transformed
       widget root becomes the containing block for the fixed full-screen panel. */
    .sas-chat {
        bottom: 14px;
        -webkit-transform: none !important;
        transform: none !important;
    }
    .sas-chat--right { right: 14px; }
    .sas-chat--left  { left: 14px; }
    .sas-chat__launcher-text { display: none; }
    .sas-chat__launcher { padding: 0; width: 56px; height: 56px; justify-content: center; }
    .sas-chat__launcher svg { width: 26px; height: 26px; }

    /* Full-screen chat on phones — fills the visible viewport, no overflow. */
    .sas-chat.is-open .sas-chat__panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;        /* avoids the mobile address-bar gap */
        max-width: none;
        max-height: none;
        border-radius: 0;
    }
    .sas-chat__header {
        padding: calc(13px + env(safe-area-inset-top)) 14px 13px;
    }
    .sas-chat__messages { padding: 14px 12px; }
    .sas-chat__msg { max-width: 90%; font-size: 14px; }
    .sas-chat__chips { padding: 0 12px 10px; }
    .sas-chat__turnstile { padding-left: 10px; padding-right: 10px; }
    .sas-chat__form {
        padding: 10px;
    }
    .sas-chat__input {
        min-height: 46px;
        font-size: 16px;
    }
    .sas-chat__send { width: 46px; height: 46px; }
    .sas-chat__footer { padding: 7px 12px calc(9px + env(safe-area-inset-bottom)); }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .sas-chat__panel,
    .sas-chat__launcher::after,
    .sas-chat__dot,
    .sas-chat__typing span { animation: none !important; }
}
