/* ==========================================================================
   AtListen site assistant — the floating support chat on the home page.

   Paired with scripts/site-chat.js, which builds all of the markup. Kept in its own
   stylesheet rather than inlined into the module (the notify.js / paywall.js pattern)
   because those modules must survive on pages that never load design-system.css, and
   therefore hardcode brand hexes. This widget is a page feature: it can rely on the
   tokens, which means one place to change if the brand ever moves.

   Everything is namespaced `.atl-sc-*`. z-index sits at 900/901 — above the fixed nav
   (300) and the mobile menu (500), below the opening sequence (9999) and notify.js's
   toasts/modals (100000+), so an error toast still lands on top of the panel.
   ========================================================================== */

.atl-sc-root {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 900;
    font-family: var(--font-sans);
    /* The launcher fades up once the opening sequence is out of the way (JS adds
       .is-ready), so it never pops in over the intro. */
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--duration-slower) var(--ease-out),
                transform var(--duration-slower) var(--ease-spring);
}

.atl-sc-root.is-ready {
    opacity: 1;
    transform: none;
}

/* --------------------------------------------------------------------------
   Launcher
   A pill while closed (icon + label, so it reads as a big obvious affordance)
   that morphs into a circle while the panel is open.
   -------------------------------------------------------------------------- */
.atl-sc-launcher {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 60px;
    padding: 0 24px 0 18px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    background-size: 160% 160%;
    color: var(--color-white);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    letter-spacing: -0.01em;
    cursor: pointer;
    box-shadow: 0 10px 30px -6px rgba(139, 92, 246, 0.45),
                0 2px 6px rgba(23, 23, 23, 0.12);
    transition: transform var(--duration-normal) var(--ease-spring),
                box-shadow var(--duration-normal) var(--ease-out),
                padding var(--duration-normal) var(--ease-in-out),
                background-position var(--duration-slower) var(--ease-in-out);
}

.atl-sc-launcher:hover {
    transform: translateY(-2px);
    background-position: 100% 0;
    box-shadow: 0 16px 38px -8px rgba(139, 92, 246, 0.55),
                0 3px 8px rgba(23, 23, 23, 0.14);
}

.atl-sc-launcher:active {
    transform: translateY(0) scale(0.97);
}

/* Soft brand halo, sitting behind the button. */
.atl-sc-launcher::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: inherit;
    background: var(--gradient-brand);
    filter: blur(16px);
    opacity: 0.35;
    z-index: -1;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.atl-sc-launcher:hover::before { opacity: 0.55; }

/* One-shot attention ring — a few pulses on first load, then it stops for good. */
.atl-sc-launcher::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--color-purple);
    opacity: 0;
    pointer-events: none;
}

.atl-sc-root.is-nudging .atl-sc-launcher::after {
    animation: atlScPulse 2.4s var(--ease-out) 3;
}

@keyframes atlScPulse {
    0%   { opacity: 0.55; transform: scale(1); }
    70%  { opacity: 0;    transform: scale(1.22); }
    100% { opacity: 0;    transform: scale(1.22); }
}

.atl-sc-launcher-icon {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    flex: none;
}

.atl-sc-launcher-icon svg {
    grid-area: 1 / 1;
    width: 24px;
    height: 24px;
    transition: opacity var(--duration-fast) var(--ease-out),
                transform var(--duration-normal) var(--ease-spring);
}

.atl-sc-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

.atl-sc-launcher-label {
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    transition: max-width var(--duration-normal) var(--ease-in-out),
                opacity var(--duration-fast) var(--ease-out),
                margin var(--duration-normal) var(--ease-in-out);
}

/* Open state: collapse to a circle and swap the glyph. */
.atl-sc-root.is-open .atl-sc-launcher { padding: 0 18px; }
.atl-sc-root.is-open .atl-sc-launcher-label {
    max-width: 0;
    opacity: 0;
    margin-left: -10px;
}
.atl-sc-root.is-open .atl-sc-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}
.atl-sc-root.is-open .atl-sc-icon-close {
    opacity: 1;
    transform: none;
}

/* --------------------------------------------------------------------------
   Panel
   -------------------------------------------------------------------------- */
.atl-sc-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 14px);
    z-index: 901;
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 32px));
    height: min(620px, calc(100vh - 132px));
    height: min(620px, calc(100dvh - 132px));
    overflow: hidden;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-3xl);
    box-shadow: 0 32px 70px -18px rgba(23, 23, 23, 0.32),
                0 10px 24px -12px rgba(23, 23, 23, 0.18);
    transform-origin: bottom right;
    opacity: 0;
    transform: translateY(14px) scale(0.94);
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--duration-normal) var(--ease-out),
                transform var(--duration-slow) var(--ease-spring),
                visibility 0s linear var(--duration-slow);
}

.atl-sc-root.is-open .atl-sc-panel {
    opacity: 1;
    transform: none;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}

/* Header ---------------------------------------------------------------- */
.atl-sc-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 14px 16px 18px;
    background: var(--gradient-brand);
    color: var(--color-white);
    overflow: hidden;
    flex: none;
}

/* Slow diagonal sheen so the header doesn't read as a flat block of gradient. */
.atl-sc-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 30%,
                rgba(255, 255, 255, 0.22) 48%, transparent 66%);
    transform: translateX(-100%);
    animation: atlScSheen 7s var(--ease-in-out) 1.5s infinite;
    pointer-events: none;
}

@keyframes atlScSheen {
    0%   { transform: translateX(-100%); }
    45%  { transform: translateX(100%); }
    100% { transform: translateX(100%); }
}

.atl-sc-avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.atl-sc-avatar svg { width: 26px; height: 13px; }

.atl-sc-heading {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.atl-sc-title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    letter-spacing: -0.01em;
}

.atl-sc-status {
    display: flex;
    align-items: center;
    /* 8px, not 6px: the pulse ring below expands 6px past the dot, and at a 6px gap
       its peak washed over the "R" of "Ready". Keep gap > ring peak. */
    gap: 8px;
    margin-top: 3px;
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.85);
}

.atl-sc-status-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: #6EE7B7;
    box-shadow: 0 0 0 0 rgba(110, 231, 183, 0.7);
    animation: atlScLive 2.6s var(--ease-out) infinite;
    /* align-items:center centres the dot in the 18px LINE BOX, but the text's ink sits
       lower than that box's middle (the half-leading above the cap line is bigger than
       the descender space below it). Measured from the rendered pixels: the dot landed
       1px above the x-height centre of "Ready to help". Nudge it back down so the dot
       reads as sitting on the same optical line as the words. */
    position: relative;
    top: 1px;
}

@keyframes atlScLive {
    0%   { box-shadow: 0 0 0 0 rgba(110, 231, 183, 0.65); }
    70%  { box-shadow: 0 0 0 6px rgba(110, 231, 183, 0); }
    100% { box-shadow: 0 0 0 0 rgba(110, 231, 183, 0); }
}

.atl-sc-header-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    position: relative;
    z-index: 1;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-white);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out);
}

.atl-sc-header-btn:hover { background: rgba(255, 255, 255, 0.18); }
.atl-sc-header-btn:focus-visible { outline-color: var(--color-white); }
.atl-sc-header-btn svg { width: 20px; height: 20px; }

/* Message list ---------------------------------------------------------- */
.atl-sc-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    padding: 20px 18px 8px;
    background: linear-gradient(180deg, var(--color-gray-50) 0%, var(--color-white) 140px);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Element-scoped scrollbar: more specific than the site-wide gradient bar, and a thin
   neutral track reads better inside a small panel. */
.atl-sc-body::-webkit-scrollbar { width: 8px; }
.atl-sc-body::-webkit-scrollbar-track { background: transparent; }
.atl-sc-body::-webkit-scrollbar-thumb {
    background: var(--color-gray-300);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: content-box;
}
.atl-sc-body::-webkit-scrollbar-thumb:hover { background-color: var(--color-gray-400); }
.atl-sc-body { scrollbar-width: thin; scrollbar-color: var(--color-gray-300) transparent; }

/* Empty state ----------------------------------------------------------- */
.atl-sc-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 14px 4px 4px;
}

.atl-sc-intro-mark {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    box-shadow: var(--shadow-brand);
    margin-bottom: 14px;
}

.atl-sc-intro-mark svg { width: 34px; height: 17px; color: var(--color-white); }

.atl-sc-intro-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

.atl-sc-intro-text {
    margin-top: 6px;
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--color-text-secondary);
    max-width: 30ch;
}

.atl-sc-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-top: 18px;
}

.atl-sc-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 11px 14px;
    text-align: left;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out),
                background var(--duration-fast) var(--ease-out);
}

.atl-sc-chip:hover {
    border-color: var(--color-purple-light);
    background: rgba(139, 92, 246, 0.04);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.atl-sc-chip svg {
    width: 15px;
    height: 15px;
    flex: none;
    color: var(--color-purple);
    opacity: 0.55;
    transition: transform var(--duration-fast) var(--ease-out),
                opacity var(--duration-fast) var(--ease-out);
}

.atl-sc-chip:hover svg { transform: translateX(2px); opacity: 1; }

/* Messages -------------------------------------------------------------- */
.atl-sc-msg {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    max-width: 100%;
    animation: atlScMsgIn var(--duration-slow) var(--ease-out) both;
}

@keyframes atlScMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.atl-sc-msg-avatar {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    margin-bottom: 2px;
}

.atl-sc-msg-avatar svg { width: 17px; height: 9px; color: var(--color-white); }

.atl-sc-bubble {
    padding: 11px 14px;
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    max-width: 86%;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.atl-sc-msg.is-bot .atl-sc-bubble {
    background: var(--color-white);
    color: var(--color-text-primary);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-2xl) var(--radius-2xl) var(--radius-2xl) 6px;
    box-shadow: var(--shadow-sm);
}

/* row-reverse + justify-content:flex-start packs the bubble against the right edge while the
   ROW stays full width. `align-self: flex-end` would shrink-wrap the row instead, and the
   bubble's `max-width: 86%` would then resolve against that shrunken row — which made short
   questions wrap onto two lines for no reason. */
.atl-sc-msg.is-user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.atl-sc-msg.is-user .atl-sc-bubble {
    background: var(--gradient-brand);
    color: var(--color-white);
    border-radius: var(--radius-2xl) var(--radius-2xl) 6px var(--radius-2xl);
    box-shadow: 0 4px 14px -4px rgba(139, 92, 246, 0.5);
}

.atl-sc-msg.is-error .atl-sc-bubble {
    background: var(--color-danger-bg);
    border-color: rgba(220, 38, 38, 0.25);
    color: var(--color-danger-dark);
}

/* Rendered markdown subset inside a bot bubble. One universal sibling rule rather than
   per-pair margins — `p + p` alone left a list running straight into the paragraph after it. */
.atl-sc-bubble > * + * { margin-top: 9px; }
.atl-sc-bubble strong { font-weight: var(--font-semibold); }

.atl-sc-bubble ul {
    padding-left: 18px;
    list-style: disc;
}

.atl-sc-bubble li { margin-top: 4px; }
.atl-sc-bubble li::marker { color: var(--color-purple); }

.atl-sc-bubble a {
    color: var(--color-purple-dark);
    font-weight: var(--font-medium);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
}

.atl-sc-bubble a:hover { color: var(--color-blue-dark); }

.atl-sc-bubble code {
    font-size: 0.92em;
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: var(--color-gray-100);
    color: var(--color-gray-800);
}

/* Typing indicator ------------------------------------------------------ */
.atl-sc-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 19px;
}

.atl-sc-typing span {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--color-gray-400);
    animation: atlScTyping 1.1s var(--ease-in-out) infinite;
}

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

@keyframes atlScTyping {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Composer -------------------------------------------------------------- */
.atl-sc-footer {
    flex: none;
    padding: 12px 14px 10px;
    background: var(--color-white);
    border-top: 1px solid var(--color-gray-200);
}

.atl-sc-composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.atl-sc-input-wrap {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 14px;
    background: var(--color-gray-100);
    border: 1px solid transparent;
    border-radius: var(--radius-3xl);
    transition: background var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.atl-sc-input-wrap:focus-within {
    background: var(--color-white);
    border-color: var(--color-purple-light);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14);
}

.atl-sc-input {
    width: 100%;
    max-height: 104px;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
}

.atl-sc-input::placeholder { color: var(--color-text-light); }

.atl-sc-send {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: none;
    border-radius: var(--radius-full);
    background: var(--gradient-brand);
    color: var(--color-white);
    cursor: pointer;
    box-shadow: 0 4px 14px -4px rgba(139, 92, 246, 0.55);
    transition: transform var(--duration-fast) var(--ease-spring),
                opacity var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.atl-sc-send:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 6px 18px -4px rgba(139, 92, 246, 0.7);
}

.atl-sc-send:active:not(:disabled) { transform: scale(0.94); }

.atl-sc-send:disabled {
    opacity: 0.4;
    cursor: default;
    box-shadow: none;
}

.atl-sc-send svg { width: 19px; height: 19px; }

.atl-sc-disclaimer {
    margin-top: 9px;
    text-align: center;
    font-size: 11px;
    line-height: var(--leading-normal);
    color: var(--color-text-tertiary);
}

.atl-sc-disclaimer a {
    color: var(--color-text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.atl-sc-disclaimer a:hover { color: var(--color-purple-dark); }

/* --------------------------------------------------------------------------
   Mobile — the panel becomes a bottom sheet and the launcher drops its label.
   -------------------------------------------------------------------------- */
@media (max-width: 540px) {
    .atl-sc-root {
        right: 16px;
        /* Clear the home indicator on a notched phone. env() resolves to 0 everywhere
           else, so this is identical to the old 16px on a normal viewport. */
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .atl-sc-launcher {
        height: 58px;
        padding: 0 17px;
    }

    .atl-sc-launcher-label {
        max-width: 0;
        opacity: 0;
        margin-left: -10px;
    }

    .atl-sc-panel {
        position: fixed;
        inset: auto 0 0 0;
        width: 100%;
        height: 86vh;
        height: 86dvh;
        border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
        border-bottom: none;
        transform-origin: bottom center;
        transform: translateY(24px);
    }

    .atl-sc-bubble { max-width: 90%; }

    /* iOS Safari auto-zooms the whole page when a focused field is under 16px and
       never zooms back out, so the composer is 16px on a phone. Desktop keeps 14px. */
    .atl-sc-input { font-size: var(--text-base); }

    /* 11px is below the project's 12px floor once it is on a phone screen. */
    .atl-sc-disclaimer { font-size: var(--text-xs); }

    /* The sheet is flush with the bottom edge, so its own padding is what keeps the
       composer clear of the home indicator. */
    .atl-sc-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* --------------------------------------------------------------------------
   Reduced motion — drop every decorative loop and every entrance transform,
   keeping only opacity so state changes are still perceivable.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .atl-sc-root,
    .atl-sc-launcher,
    .atl-sc-launcher svg,
    .atl-sc-launcher-label,
    .atl-sc-panel,
    .atl-sc-chip,
    .atl-sc-chip svg,
    .atl-sc-send,
    .atl-sc-input-wrap {
        transition-duration: 0.01ms;
    }

    .atl-sc-root { transform: none; }
    .atl-sc-panel { transform: none; }
    .atl-sc-root.is-open .atl-sc-panel { transform: none; }
    .atl-sc-body { scroll-behavior: auto; }

    .atl-sc-header::after,
    .atl-sc-status-dot,
    .atl-sc-root.is-nudging .atl-sc-launcher::after {
        animation: none;
    }

    .atl-sc-msg { animation: none; }
    .atl-sc-typing span { animation: none; opacity: 0.7; }

    .atl-sc-launcher:hover,
    .atl-sc-send:hover:not(:disabled),
    .atl-sc-chip:hover { transform: none; }
}

/* Printing a chat widget is never wanted. */
@media print {
    .atl-sc-root { display: none; }
}
