/* ==========================================================================
   Public site: the floating live-chat widget (Components/Site/LiveChatWidget.razor).

   Loaded with the site sheets (App.razor); the dark rules are in site-dark.css. Every offset and alignment uses logical
   properties, so the widget sits at the bottom right in LTR and the bottom left in RTL without a second rule set.
   ========================================================================== */

.site-chat {
    --sc-accent: #fdb900;
    --sc-accent-ink: #2b2100;
    --sc-surface: #ffffff;
    --sc-surface-2: #f2f4f7;
    --sc-border: #e3e8ef;
    --sc-text: #1f2933;
    --sc-muted: #667085;
    --sc-danger: #c62828;
    --sc-online: #22b14c;
    --sc-lift: 0rem;

    align-items: flex-end;
    color: var(--sc-text);
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    gap: 0.75rem;
    inset-block-end: calc(1.25rem + var(--sc-lift) + env(safe-area-inset-bottom, 0px));
    inset-inline-end: calc(1.25rem + env(safe-area-inset-right, 0px));
    line-height: 1.45;
    pointer-events: none; /* only the launcher and the panel catch clicks, never the empty corner around them */
    position: fixed;
    z-index: 1040;
}

html[dir="rtl"] .site-chat {
    inset-inline-end: calc(1.25rem + env(safe-area-inset-left, 0px));
}

.site-chat > * {
    pointer-events: auto;
}

/* The shop's mobile total bar (.shop-mobile-bar, fixed to the bottom below 992px) must stay reachable. */
@media (max-width: 991.98px) {
    body:has(.shop-mobile-bar) .site-chat {
        --sc-lift: 4.75rem;
    }
}

.site-chat *,
.site-chat *::before,
.site-chat *::after {
    box-sizing: border-box;
}

.site-chat button {
    font: inherit;
}

/* ---- Launcher ----------------------------------------------------------------------------------------------------- */

.site-chat-launcher {
    align-items: center;
    background: var(--sc-accent);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
    color: var(--sc-accent-ink);
    cursor: pointer;
    display: inline-flex;
    flex: none;
    height: 3.6rem;
    justify-content: center;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    width: 3.6rem;
}

.site-chat-launcher:hover {
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
    transform: translateY(-1px);
}

.site-chat-launcher:focus-visible,
.site-chat-close:focus-visible,
.site-chat-send:focus-visible,
.site-chat-primary:focus-visible,
.site-chat-secondary:focus-visible,
.site-chat-link:focus-visible,
.site-chat-pill:focus-visible {
    outline: 3px solid #1f6feb;
    outline-offset: 2px;
}

.site-chat-badge {
    background: var(--sc-danger);
    border: 2px solid var(--sc-surface);
    border-radius: 999px;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    inset-block-start: -0.25rem;
    inset-inline-start: -0.25rem;
    line-height: 1;
    min-width: 1.4rem;
    padding: 0.2rem 0.35rem;
    position: absolute;
    text-align: center;
}

.site-chat-online {
    background: var(--sc-online);
    border: 2px solid var(--sc-surface);
    border-radius: 50%;
    height: 0.95rem;
    inset-block-end: 0.1rem;
    inset-inline-end: 0.1rem;
    position: absolute;
    width: 0.95rem;
}

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

.site-chat-panel {
    background: var(--sc-surface);
    border: 1px solid var(--sc-border);
    border-radius: 14px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    height: min(560px, calc(100dvh - 7.5rem - var(--sc-lift)));
    overflow: hidden;
    position: relative;
    width: min(380px, calc(100vw - 2.5rem));
}

/* Opening: a short rise and fade; switched off for people who asked for less motion (see the end of this file). */
.site-chat-panel {
    animation: site-chat-open 0.18s ease-out;
    transform-origin: bottom;
}

@keyframes site-chat-open {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.site-chat-head {
    align-items: flex-start;
    background: var(--sc-accent);
    color: var(--sc-accent-ink);
    display: flex;
    flex: none;
    gap: 0.5rem;
    justify-content: space-between;
    padding: 0.85rem 1rem;
}

.site-chat-head-main {
    min-width: 0;
}

.site-chat-title {
    align-items: center;
    color: inherit;
    display: flex;
    font-size: 1.05rem;
    font-weight: 700;
    gap: 0.5rem;
    line-height: 1.3;
    margin: 0;
}

.site-chat-title:focus {
    outline: none;
}

.site-chat-dot {
    background: #8a6a00;
    border-radius: 50%;
    flex: none;
    height: 0.65rem;
    width: 0.65rem;
}

.site-chat-dot.is-online {
    background: var(--sc-online);
    box-shadow: 0 0 0 3px rgba(34, 177, 76, 0.28);
}

.site-chat-agents {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    margin-block-start: 0.4rem;
}

.site-chat-avatars {
    display: inline-flex;
    flex: none;
}

.site-chat-avatar {
    align-items: center;
    background: #fff;
    border: 2px solid var(--sc-accent);
    border-radius: 50%;
    color: var(--sc-accent-ink);
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 700;
    height: 1.9rem;
    justify-content: center;
    overflow: hidden;
    width: 1.9rem;
}

.site-chat-avatar + .site-chat-avatar {
    margin-inline-start: -0.5rem;
}

.site-chat-avatar img {
    height: 100%;
    object-fit: cover;
    width: 100%;
}

.site-chat-agent-names {
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-chat-sub {
    font-size: 0.8rem;
    margin: 0.3rem 0 0;
    opacity: 0.85;
}

.site-chat-close {
    align-items: center;
    background: rgba(0, 0, 0, 0.1);
    border: 0;
    border-radius: 50%;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    flex: none;
    height: 2.25rem;
    justify-content: center;
    width: 2.25rem;
}

.site-chat-close:hover {
    background: rgba(0, 0, 0, 0.2);
}

.site-chat-banner {
    background: #fff3cd;
    color: #664d03;
    flex: none;
    font-size: 0.82rem;
    padding: 0.35rem 1rem;
    text-align: center;
}

.site-chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
}

/* ---- Start screen and offline form ------------------------------------------------------------------------------- */

.site-chat-form {
    display: flex;
    flex-direction: column;
}

.site-chat-greeting {
    margin: 0 0 0.9rem;
}

.site-chat-form-title {
    font-size: 1.05rem;
    margin: 0 0 0.6rem;
}

.site-chat-label {
    color: var(--sc-muted);
    font-size: 0.8rem;
    font-weight: 600;
    margin: 0.55rem 0 0.2rem;
}

.site-chat-optional {
    font-weight: 400;
}

.site-chat-input {
    background: var(--sc-surface);
    border: 1px solid var(--sc-border);
    border-radius: 8px;
    color: var(--sc-text);
    font: inherit;
    padding: 0.55rem 0.7rem;
    width: 100%;
}

.site-chat-input:focus {
    border-color: var(--sc-accent);
    box-shadow: 0 0 0 3px rgba(253, 185, 0, 0.35);
    outline: none;
}

.site-chat-input[aria-invalid="true"] {
    border-color: var(--sc-danger);
}

.site-chat-textarea {
    resize: vertical;
}

.site-chat-error {
    color: var(--sc-danger);
    font-size: 0.82rem;
    margin: 0.35rem 0 0;
}

.site-chat-primary,
.site-chat-secondary {
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    margin-block-start: 1rem;
    padding: 0.65rem 1rem;
    width: 100%;
}

.site-chat-primary {
    background: var(--sc-accent);
    border: 1px solid var(--sc-accent);
    color: var(--sc-accent-ink);
}

.site-chat-primary:hover:not(:disabled) {
    filter: brightness(0.95);
}

.site-chat-primary:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.site-chat-secondary {
    background: transparent;
    border: 1px solid var(--sc-border);
    color: var(--sc-text);
}

/* Visually hidden but still in the DOM, so a bot fills it and a person never sees it. */
.site-chat-hp {
    height: 1px;
    inset-inline-start: -10000px;
    overflow: hidden;
    position: absolute;
    width: 1px;
}

.site-chat-done {
    align-items: center;
    color: var(--sc-text);
    display: flex;
    flex-direction: column;
    padding-block: 1.5rem;
    text-align: center;
}

.site-chat-done svg {
    color: var(--sc-online);
}

.site-chat-done h3 {
    font-size: 1.1rem;
    margin: 0.5rem 0 0.25rem;
}

/* ---- Conversation ------------------------------------------------------------------------------------------------ */

.site-chat-log {
    background: var(--sc-surface-2);
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.15rem;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.9rem;
    scroll-behavior: smooth;
}

.site-chat-log:focus-visible {
    outline: 2px solid #1f6feb;
    outline-offset: -2px;
}

.site-chat-hint {
    color: var(--sc-muted);
    font-size: 0.88rem;
    margin: auto 0.5rem;
    text-align: center;
}

.site-chat-row {
    align-items: flex-start;
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.site-chat-row.is-mine {
    align-items: flex-end;
    align-self: flex-end;
}

.site-chat-row.is-theirs {
    align-self: flex-start;
}

.site-chat-from {
    color: var(--sc-muted);
    font-size: 0.75rem;
    font-weight: 600;
    margin-block: 0.4rem 0.15rem;
}

.site-chat-bubble {
    border-radius: 14px;
    margin-block: 0.1rem;
    overflow-wrap: anywhere;
    padding: 0.5rem 0.8rem;
    white-space: pre-wrap;
}

.is-mine .site-chat-bubble {
    background: var(--sc-accent);
    border-end-end-radius: 4px;
    color: var(--sc-accent-ink);
}

.is-theirs .site-chat-bubble {
    background: var(--sc-surface);
    border: 1px solid var(--sc-border);
    border-end-start-radius: 4px;
}

.site-chat-bubble.is-failed {
    background: #fdecea;
    border: 1px solid var(--sc-danger);
    color: #7a1c1c;
}

.site-chat-meta {
    align-items: center;
    color: var(--sc-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.72rem;
    gap: 0.35rem;
    margin-block: 0.1rem 0.4rem;
}

.site-chat-failed {
    color: var(--sc-danger);
    font-weight: 600;
}

.site-chat-system {
    align-self: center;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 999px;
    color: var(--sc-muted);
    font-size: 0.78rem;
    margin-block: 0.5rem;
    padding: 0.2rem 0.75rem;
    text-align: center;
}

.site-chat-link {
    background: none;
    border: 0;
    color: #0b5cad;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.site-chat-older {
    align-self: center;
    font-size: 0.8rem;
    margin-block-end: 0.5rem;
}

.site-chat-typing {
    align-self: flex-start;
    background: var(--sc-surface);
    border: 1px solid var(--sc-border);
    border-radius: 14px;
    border-end-start-radius: 4px;
    display: inline-flex;
    gap: 4px;
    margin-block: 0.3rem;
    padding: 0.65rem 0.8rem;
}

.site-chat-typing span {
    animation: site-chat-bounce 1.2s infinite ease-in-out;
    background: var(--sc-muted);
    border-radius: 50%;
    height: 6px;
    width: 6px;
}

.site-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.site-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes site-chat-bounce {
    0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Spoken by screen readers ("Sara is typing…"); the dots above are the visual cue. */
.site-chat-live {
    height: 1px;
    overflow: hidden;
    position: absolute;
    width: 1px;
}

.site-chat-pill {
    background: #1f2933;
    border: 0;
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    color: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    inset-block-end: 4.6rem;
    inset-inline-start: 50%;
    padding: 0.3rem 0.85rem;
    position: absolute;
    transform: translateX(-50%);
}

html[dir="rtl"] .site-chat-pill {
    transform: translateX(50%);
}

.site-chat-composer {
    align-items: flex-end;
    background: var(--sc-surface);
    border-block-start: 1px solid var(--sc-border);
    display: flex;
    flex: none;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
}

.site-chat-compose-box {
    flex: 1;
    max-height: 120px;
    min-height: 2.5rem;
    min-width: 0;
    overflow-y: auto;
    resize: none;
    width: auto;
}

.site-chat-send {
    align-items: center;
    background: var(--sc-accent);
    border: 0;
    border-radius: 50%;
    color: var(--sc-accent-ink);
    cursor: pointer;
    display: inline-flex;
    flex: none;
    height: 2.5rem;
    justify-content: center;
    width: 2.5rem;
}

.site-chat-send:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

/* The paper plane points toward the inline end, so it flips with the reading direction. */
html[dir="rtl"] .site-chat-send-icon {
    transform: scaleX(-1);
}

.site-chat-counter {
    color: var(--sc-muted);
    font-size: 0.72rem;
    width: 100%;
}

.site-chat-counter.is-over {
    color: var(--sc-danger);
    font-weight: 700;
}

.site-chat-ended {
    background: var(--sc-surface);
    border-block-start: 1px solid var(--sc-border);
    flex: none;
    padding: 0.75rem 1rem;
    text-align: center;
}

.site-chat-ended p {
    color: var(--sc-muted);
    margin: 0;
}

.site-chat-ended .site-chat-primary {
    margin-block-start: 0.6rem;
}

/* ---- Small screens: a full-screen sheet --------------------------------------------------------------------------- */

@media (max-width: 575.98px) {
    .site-chat-panel {
        border: 0;
        border-radius: 0;
        height: 100dvh;
        inset: 0;
        position: fixed;
        width: 100vw;
    }

    .site-chat-head {
        padding-block-start: calc(0.85rem + env(safe-area-inset-top, 0px));
        padding-inline: calc(1rem + env(safe-area-inset-left, 0px)) calc(1rem + env(safe-area-inset-right, 0px));
    }

    .site-chat-body,
    .site-chat-log,
    .site-chat-composer,
    .site-chat-ended {
        padding-inline: calc(0.9rem + env(safe-area-inset-left, 0px)) calc(0.9rem + env(safe-area-inset-right, 0px));
    }

    .site-chat-composer,
    .site-chat-ended {
        padding-block-end: calc(0.6rem + env(safe-area-inset-bottom, 0px));
    }

    .site-chat-pill {
        inset-block-end: calc(4.8rem + env(safe-area-inset-bottom, 0px));
    }

    /* The sheet covers the page; its own close button replaces the launcher, and the page behind must not scroll. */
    .site-chat-launcher.is-open {
        display: none;
    }

    /* Prevents iOS from zooming into the fields. */
    .site-chat-input {
        font-size: 16px;
    }
}

html.site-chat-open {
    overflow: hidden;
}

@media (min-width: 576px) {
    html.site-chat-open {
        overflow: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-chat-panel {
        animation: none;
    }

    .site-chat-launcher,
    .site-chat-log {
        scroll-behavior: auto;
        transition: none;
    }

    .site-chat-typing span {
        animation: none;
    }
}

@media print {
    .site-chat {
        display: none !important;
    }
}
