/* Customer support chat widget (templates/components/cs_chat.html).
   Every rule is scoped under .cs-chat so the site's global resets in base.css don't leak in or out. */

.cs-chat {
    --cs-primary: #054086;
    --cs-primary-hover: #04336b;
    --cs-primary-ring: rgba(5, 64, 134, 0.18);
    --cs-accent: #fbbf22;
    --cs-online: #10b981;
    --cs-text: #0f172a;
    --cs-muted: #64748b;
    --cs-border: #e2e8f0;
    --cs-thread-bg: #f4f7fb;
    position: fixed;
    right: 16px;
    bottom: 160px; /* above the WhatsApp pill (base*.html: bottom 90px, 60px tall) so the teaser never covers it */
    z-index: 2147483000;
    font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--cs-text);
    -webkit-font-smoothing: antialiased;
}

.cs-chat[hidden],
.cs-chat [hidden] {
    display: none !important;
}

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

.cs-chat svg {
    display: block;
}

.cs-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- launcher */

.cs-launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--cs-primary);
    color: #fff;
    box-shadow: 0 14px 32px -10px rgba(5, 64, 134, 0.85), 0 2px 5px rgba(15, 23, 42, 0.15), 0 0 0 4px var(--cs-primary-ring);
    transition: background-color 0.2s, transform 0.15s;
}

.cs-launcher::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: 50%;
    background: rgba(5, 64, 134, 0.45);
    pointer-events: none;
    animation: cs-ping 1.5s cubic-bezier(0, 0, 0.2, 1) 4;
}

.cs-launcher:hover {
    background: var(--cs-primary-hover);
}

.cs-launcher:active {
    transform: scale(0.95);
}

.cs-launcher:focus-visible {
    outline: 3px solid var(--cs-accent);
    outline-offset: 2px;
}

.cs-launcher svg {
    width: 26px;
    height: 26px;
}

.cs-launcher__badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--cs-online);
}

.cs-chat .cs-launcher__close,
.cs-chat.is-open .cs-launcher__chat,
.cs-chat.is-open .cs-launcher__badge,
.cs-chat.is-open .cs-launcher::before {
    display: none;
}

.cs-chat.is-open .cs-launcher__close {
    display: block;
}

@keyframes cs-ping {
    75%, 100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

/* ---------------------------------------------------------------- teaser */

.cs-teaser {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: min(330px, calc(100vw - 32px));
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.cs-teaser[data-shown] {
    opacity: 1;
    transform: none;
}

.cs-chat.is-open .cs-teaser {
    display: none;
}

.cs-teaser__card {
    position: relative;
    overflow: hidden;
    padding: 16px;
    border: 1px solid #dbe5f3;
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 28px 70px -20px rgba(5, 64, 134, 0.5), 0 4px 14px rgba(15, 23, 42, 0.1);
}

.cs-teaser__card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 32px;
    right: 32px;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--cs-accent), transparent);
}

.cs-teaser__head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.cs-teaser__text {
    flex: 1;
    min-width: 0;
}

.cs-teaser__title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
}

.cs-teaser__body {
    margin-top: 10px;
    font-size: 13.5px;
    line-height: 1.45;
    color: #475569;
}

.cs-teaser__cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 14px;
    padding: 12px 16px;
    border-radius: 999px;
    background: var(--cs-primary);
    color: #fff;
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    transition: background-color 0.15s;
}

.cs-teaser__cta:hover {
    background: var(--cs-primary-hover);
}

.cs-teaser__cta:focus-visible,
.cs-teaser__close:focus-visible {
    outline: 3px solid var(--cs-accent);
    outline-offset: 2px;
}

.cs-teaser__cta svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.cs-teaser__close {
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border: 1px solid var(--cs-border);
    border-radius: 50%;
    background: #fff;
    color: var(--cs-muted);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

.cs-teaser__close:hover {
    color: var(--cs-text);
}

.cs-teaser__close svg {
    width: 14px;
    height: 14px;
}

/* ---------------------------------------------------------------- shared */

.cs-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    padding: 5px;
    border: 1px solid var(--cs-border);
    border-radius: 50%;
    background: #fff;
    object-fit: contain;
}

.cs-avatar--lg {
    width: 44px;
    height: 44px;
    padding: 6px;
}

.cs-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.35;
    color: #047857;
}

.cs-status__dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--cs-online);
}

/* ---------------------------------------------------------------- panel */

.cs-panel {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    visibility: hidden;
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0s linear 0.2s;
}

.cs-chat.is-open .cs-panel {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.cs-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(12px + env(safe-area-inset-top)) 8px 12px 14px;
    background: var(--cs-primary);
    color: #fff;
}

.cs-panel__header .cs-avatar {
    border-color: transparent;
}

.cs-panel__header .cs-status {
    color: #a7f3d0;
}

.cs-panel__heading {
    flex: 1;
    min-width: 0;
}

.cs-panel__title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
}

.cs-icon-btn {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    transition: background-color 0.15s, color 0.15s;
}

.cs-icon-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.cs-icon-btn:focus-visible {
    outline: 2px solid var(--cs-accent);
    outline-offset: 1px;
}

.cs-icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent;
}

.cs-icon-btn svg {
    width: 19px;
    height: 19px;
}

/* ---------------------------------------------------------------- thread */

.cs-thread {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 18px 14px 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--cs-thread-bg);
}

.cs-row {
    display: flex;
}

.cs-row--user {
    justify-content: flex-end;
}

.cs-bubble {
    max-width: 86%;
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.cs-bubble--user {
    border-top-right-radius: 6px;
    background: var(--cs-primary);
    color: #fff;
    white-space: pre-wrap;
}

.cs-bubble--user[data-pending] {
    opacity: 0.7;
}

.cs-bubble--agent {
    border: 1px solid var(--cs-border);
    border-top-left-radius: 6px;
    background: #fff;
    color: #1e293b;
}

.cs-bubble--agent > * + * {
    margin-top: 8px;
}

.cs-bubble--agent a {
    display: inline;
    color: var(--cs-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cs-bubble--agent strong {
    font-weight: 600;
}

.cs-bubble--agent code {
    padding: 1px 6px;
    border-radius: 6px;
    background: #f1f5f9;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.88em;
}

.cs-bubble--agent ul,
.cs-bubble--agent ol {
    padding-left: 20px;
}

.cs-bubble--agent ul {
    list-style: disc;
}

.cs-bubble--agent ol {
    list-style: decimal;
}

.cs-bubble--agent li + li {
    margin-top: 4px;
}

.cs-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px;
    border: 1px solid var(--cs-border);
    border-radius: 16px;
    border-top-left-radius: 6px;
    background: #fff;
}

.cs-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: cs-bounce 1s infinite;
}

.cs-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.cs-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cs-bounce {
    0%, 100% {
        transform: translateY(-25%);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: none;
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

.cs-note {
    align-self: center;
    max-width: 92%;
    padding: 8px 12px;
    border-radius: 10px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 12.5px;
    line-height: 1.4;
    text-align: center;
}

/* ---------------------------------------------------------------- composer */

.cs-composer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--cs-border);
    background: #fff;
}

.cs-composer__box {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 5px 5px 5px 12px;
    border: 1px solid var(--cs-border);
    border-radius: 16px;
    background: var(--cs-thread-bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cs-composer__box:focus-within {
    border-color: var(--cs-primary);
    box-shadow: 0 0 0 4px var(--cs-primary-ring);
}

.cs-composer__input {
    flex: 1;
    min-width: 0;
    max-height: 132px;
    padding: 7px 0;
    border: 0;
    outline: none;
    background: transparent;
    box-shadow: none;
    resize: none;
    font: inherit;
    font-size: 16px; /* below 16px iOS zooms the page on focus */
    line-height: 1.45;
    color: var(--cs-text);
}

.cs-composer__input::placeholder {
    color: var(--cs-muted);
}

.cs-composer__send {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--cs-primary);
    color: #fff;
    transition: background-color 0.15s;
}

.cs-composer__send:hover {
    background: var(--cs-primary-hover);
}

.cs-composer__send:focus-visible {
    outline: 2px solid var(--cs-accent);
    outline-offset: 2px;
}

.cs-composer__send:disabled {
    background: var(--cs-border);
    color: #94a3b8;
    cursor: not-allowed;
}

.cs-composer__send svg {
    width: 18px;
    height: 18px;
}

.cs-composer__count {
    padding: 6px 4px 0;
    font-size: 12px;
    color: var(--cs-muted);
    text-align: right;
}

.cs-composer__count[data-limit] {
    font-weight: 600;
    color: #dc2626;
}

/* ---------------------------------------------------------------- breakpoints */

@media (max-width: 768px) {
    .cs-chat.is-open .cs-launcher {
        display: none;
    }
}

@media (min-width: 769px) {
    .cs-chat {
        right: 24px;
    }

    .cs-panel {
        position: absolute;
        inset: auto 0 72px auto;
        width: min(384px, calc(100vw - 40px));
        /* opens above the launcher: 160px offset + 72px gap + 24px top margin */
        height: min(620px, calc(100vh - 256px));
        height: min(620px, calc(100dvh - 256px));
        border: 1px solid var(--cs-border);
        border-radius: 20px;
        box-shadow: 0 24px 60px -18px rgba(15, 23, 42, 0.35), 0 2px 8px rgba(15, 23, 42, 0.08);
        transform: translateY(12px) scale(0.98);
        transform-origin: bottom right;
    }

    .cs-panel__header {
        padding-top: 12px;
    }

    .cs-composer {
        padding-bottom: 12px;
    }

    .cs-composer__input {
        font-size: 14.5px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cs-launcher,
    .cs-teaser,
    .cs-panel,
    .cs-chat.is-open .cs-panel {
        transition: none;
    }

    .cs-launcher::before,
    .cs-typing span {
        animation: none;
    }
}

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