/* ==========================================================================
   Support chat widget
   --------------------------------------------------------------------------
   Loaded on pages that already carry shop.css AND on the landing page that
   carries home-shop.css (a hard `* { margin:0; padding:0 }` reset). Every rule
   is therefore scoped under #cs-root, and every box is re-declared explicitly
   so no inherited value from either reset can leak in.

   Load-bearing rules — do not delete without re-testing:
     · #cs-root[hidden] / [hidden]  — several children declare `display:flex`,
       which beats the UA's `[hidden]{display:none}`. `hidden` is the widget's
       ONLY visibility switch, so it has to be authoritative.
     · body.nav-open #cs-root       — the nav drawer is the other overlay on
       these pages; never stack the panel on top of it.
   ========================================================================== */

#cs-root {
    /* Palette. A warm neutral body against the store's own accent, so the widget
       reads as part of the site rather than a bolted-on third-party blob. */
    --cs-brand: #1f2937;
    --cs-brand-2: #334155;
    --cs-accent: #a56565;
    --cs-accent-2: #8f5252;
    --cs-ink: #16202b;
    --cs-muted: #68758a;
    --cs-line: #e3e8ef;
    --cs-soft: #f6f8fb;
    --cs-online: #22c55e;
    --cs-shadow: 0 22px 60px rgba(15, 23, 42, .26), 0 4px 12px rgba(15, 23, 42, .10);

    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    margin: 0;
    padding: 0;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cs-ink);
    text-align: left;
    -webkit-font-smoothing: antialiased;
}

/* box-sizing stays id-scoped: we want border-box unconditionally and no
   .cs-* rule ever redeclares it, so nothing needs to outrank this. */
#cs-root *,
#cs-root *::before,
#cs-root *::after {
    box-sizing: border-box;
}

/* margin/padding are reset inside :where() so this rule contributes ZERO
   specificity.

   As an id-scoped `#cs-root *` it was (1,0,0) — and an id cannot be beaten
   by a class. Every `.cs-*` rule below declares (0,1,0), so the reset was
   silently wiping the padding on every single element in the widget: the
   header computed to 0px 0px despite `.cs-head { padding: 15px 16px }`,
   buttons collapsed to their UA height, and fields sat flush against their
   labels. :where() matches exactly the same elements while handing the
   cascade back to the widget's own rules. */
:where(#cs-root *),
:where(#cs-root *::before),
:where(#cs-root *::after) {
    margin: 0;
    padding: 0;
}

#cs-root[hidden],
#cs-root [hidden] {
    display: none !important;
}

body.nav-open #cs-root {
    display: none !important;
}

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

#cs-launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cs-accent), var(--cs-accent-2));
    color: #fff;
    font-size: 23px;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(143, 82, 82, .42);
    transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Idle ring: a slow breathing halo so the entry point is findable on a long
   page without being obnoxious. Removed on hover so the button stays crisp. */
#cs-launcher::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--cs-accent);
    opacity: 0;
    animation: cs-ring 3.2s ease-out infinite;
    pointer-events: none;
}

@keyframes cs-ring {
    0%   { opacity: .55; transform: scale(.86); }
    70%  { opacity: 0;   transform: scale(1.24); }
    100% { opacity: 0;   transform: scale(1.24); }
}

#cs-launcher:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 18px 38px rgba(143, 82, 82, .5);
}

#cs-launcher:hover::before { animation: none; opacity: 0; }

#cs-launcher:active { transform: translateY(-1px) scale(1.0); }

#cs-launcher:focus-visible {
    outline: 3px solid #ffb020;
    outline-offset: 3px;
}

.cs-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 23px;
    height: 23px;
    padding: 0 6px;
    border: 2px solid #fff;
    border-radius: 12px;
    background: #e5484d;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 19px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
}

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

.cs-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: min(578px, calc(100vh - 130px));
    overflow: hidden;
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: 20px;
    background: #fff;
    box-shadow: var(--cs-shadow);
    transform-origin: bottom right;
    animation: cs-pop .24s cubic-bezier(.22, 1, .36, 1);
}

@keyframes cs-pop {
    from { opacity: 0; transform: translateY(14px) scale(.96); }
    to   { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------------- head */

.cs-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 16px;
    background: linear-gradient(140deg, var(--cs-brand-2), var(--cs-brand));
    color: #fff;
    flex: 0 0 auto;
}

/* A 2px accent rule along the bottom of the header. It is the one place the
   store's own colour meets the dark bar, and it is what stops the panel
   reading as a generic third-party chat bubble. */
.cs-head::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--cs-accent), var(--cs-accent-2) 55%, transparent);
    opacity: .95;
}

.cs-head-l { display: flex; align-items: center; gap: 11px; min-width: 0; }

/* Agent avatar with a live presence dot — the single change that makes the
   widget read as "a person will answer" rather than "a form". */
.cs-avatar {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cs-accent), var(--cs-accent-2));
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .02em;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .22);
}

.cs-avatar i { font-size: 15px; }

.cs-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border: 2px solid var(--cs-brand);
    border-radius: 50%;
    background: var(--cs-online);
}

.cs-head-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cs-head strong { font-size: 15px; font-weight: 650; letter-spacing: .005em; }

.cs-sub {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    opacity: .84;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cs-sub::before {
    content: '';
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cs-online);
}

#cs-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: background .16s ease, transform .16s ease;
}

#cs-close:hover { background: rgba(255, 255, 255, .26); transform: rotate(90deg); }

/* ----------------------------------------------------------------- body */

.cs-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--cs-soft);
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.cs-body::-webkit-scrollbar { width: 7px; }
.cs-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.cs-view { display: flex; flex-direction: column; min-height: 100%; padding: 15px; gap: 10px; }

.cs-greet {
    font-size: 14.5px;
    font-weight: 650;
    color: var(--cs-ink);
    line-height: 1.35;
}

.cs-note {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 9px 11px;
    border-radius: 10px;
    background: #fdf3f3;
    border: 1px solid #f2dede;
    color: #7d4747;
    font-size: 12.5px;
}

.cs-empty {
    padding: 13px;
    border: 1px dashed var(--cs-line);
    border-radius: 12px;
    background: #fff;
    color: var(--cs-muted);
    font-size: 12.5px;
    line-height: 1.55;
}

/* list ------------------------------------------------------------------ */

.cs-list { display: flex; flex-direction: column; gap: 8px; list-style: none; }

.cs-item {
    display: block;
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--cs-line);
    border-radius: 12px;
    background: #fff;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.cs-item:hover {
    border-color: var(--cs-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, .07);
}

.cs-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cs-item-sub {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cs-item-body {
    margin-top: 3px;
    color: var(--cs-muted);
    font-size: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cs-item-meta { margin-top: 6px; color: #94a3b8; font-size: 11px; }

/* status chips (mirrors the admin panel's vocabulary) */
.cs-chip {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10.5px;
    font-weight: 650;
    text-transform: capitalize;
}
.cs-chip-open     { background: #fff3d6; color: #8a5a00; }
.cs-chip-answered { background: #e2f0ff; color: #0d5596; }
.cs-chip-resolved { background: #e4f7e8; color: #1c6b33; }
.cs-chip-closed   { background: #eceff4; color: #5c6675; }

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

.cs-back {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--cs-accent-2);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}
.cs-back:hover { background: #f2e6e6; }

.cs-thread-title {
    font-size: 13.5px;
    font-weight: 650;
    color: var(--cs-ink);
    overflow-wrap: anywhere;
}

.cs-thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 4px; }

.cs-msg {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.cs-msg-admin {
    align-self: flex-start;
    border: 1px solid var(--cs-line);
    border-bottom-left-radius: 5px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.cs-msg-customer {
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    background: linear-gradient(145deg, var(--cs-accent), var(--cs-accent-2));
    color: #fff;
    box-shadow: 0 2px 8px rgba(143, 82, 82, .24);
}

.cs-msg-meta {
    margin-top: 4px;
    font-size: 10.5px;
    color: #94a3b8;
}
.cs-msg-customer + .cs-msg-meta { align-self: flex-end; }

.cs-typing { align-self: flex-start; color: var(--cs-muted); font-size: 12px; font-style: italic; }

/* composer + forms ------------------------------------------------------ */

.cs-composer {
    position: sticky;
    bottom: -15px;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 9px;
    margin: auto -15px -15px;
    padding: 11px 15px 15px;
    border-top: 1px solid var(--cs-line);
    background: #fff;
}

/* The textarea takes the row; the send button parks on the baseline beside
   it. Sending a message is the one thing people do here, so it never sits
   below the fold or behind a scroll. */
.cs-composer textarea { flex: 1 1 auto; min-width: 0; }
.cs-composer .cs-row { flex: 0 0 auto; align-items: center; }

.cs-fld { display: flex; flex-direction: column; gap: 5px; }
.cs-fld label { font-size: 12px; font-weight: 650; color: var(--cs-ink); }

.cs-fld input,
.cs-fld textarea,
.cs-composer textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--cs-line);
    border-radius: 11px;
    background: #fff;
    color: var(--cs-ink);
    font: inherit;
    font-size: 13px;
    line-height: 1.45;
    resize: vertical;
    transition: border-color .16s ease, box-shadow .16s ease;
}

.cs-fld input::placeholder,
.cs-fld textarea::placeholder,
.cs-composer textarea::placeholder { color: #9aa6b6; }

.cs-fld input:focus,
.cs-fld textarea:focus,
.cs-composer textarea:focus {
    outline: 0;
    border-color: var(--cs-accent);
    box-shadow: 0 0 0 3px rgba(165, 101, 101, .15);
}

.cs-fld.has-err input,
.cs-fld.has-err textarea { border-color: #d9383d; }

.cs-err { min-height: 0; color: #c62828; font-size: 11.5px; }
.cs-fld.has-err .cs-err { min-height: 15px; }

.cs-row { display: flex; align-items: center; gap: 8px; }
.cs-hint { color: var(--cs-muted); font-size: 11.5px; }

.cs-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 17px;
    border: 0;
    border-radius: 11px;
    background: var(--cs-accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    transition: background .15s ease, transform .12s ease, opacity .15s ease;
}
.cs-btn:hover { background: var(--cs-accent-2); transform: translateY(-1px); }
.cs-btn:active { transform: none; }
.cs-btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.cs-btn-wide { width: 100%; margin-top: 2px; }

.cs-btn-ghost {
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: var(--cs-muted);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.cs-btn-ghost:hover { color: var(--cs-ink); }

/* inline alert inside the panel */
.cs-alert {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 9px 11px;
    border-radius: 10px;
    font-size: 12.5px;
}
.cs-alert-bad { background: #fdecec; color: #a32226; }
.cs-alert-ok  { background: #e4f7e8; color: #1c6b33; }

/* ---------------------------------------------------------------- footer */

.cs-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    padding: 9px 15px;
    border-top: 1px solid var(--cs-line);
    background: #fff;
    color: var(--cs-muted);
    font-size: 11px;
}
.cs-foot span { display: flex; align-items: center; gap: 5px; }
.cs-foot a { color: var(--cs-accent-2); font-weight: 650; text-decoration: none; }
.cs-foot a:hover { text-decoration: underline; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 560px) {
    #cs-root { right: 12px; bottom: 12px; }

    /* Full-bleed sheet on phones — a 380px card floating over a catalogue grid
       leaves no room to actually read the thread. */
    .cs-panel {
        right: -8px;
        bottom: 68px;
        width: calc(100vw - 16px);
        height: min(528px, calc(100vh - 100px));
        border-radius: 18px;
    }

    #cs-launcher { width: 52px; height: 52px; font-size: 21px; }
    #cs-launcher::before { display: none; }
    .cs-msg { max-width: 90%; }
    .cs-avatar { width: 34px; height: 34px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    #cs-launcher, #cs-launcher::before, .cs-panel, #cs-close { transition: none; animation: none; }
}

/* ==========================================================================
   UI refinement
   --------------------------------------------------------------------------
   Appended rather than interleaved so the original rules above stay readable
   as written. Same specificity, later in the file, so these win.
   ========================================================================== */

/* ------------------------------------------------------------- send button */

/* The send control is a circle now, not a padded rectangle: it is a single
   unambiguous verb, and a round target is the convention every messaging app
   has already taught the user. The label stays in the DOM for screen readers
   and is hidden visually — no aria-label needed, nothing is lost. */
.cs-send {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cs-accent), var(--cs-accent-2));
    box-shadow: 0 3px 10px rgba(143, 82, 82, .30);
}
.cs-send span {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.cs-send i { font-size: 13px; transform: translateX(-.5px); }
.cs-send:hover { filter: brightness(1.06); }
.cs-send:active { transform: scale(.94); }
.cs-send[disabled] { opacity: .45; box-shadow: none; cursor: not-allowed; }

/* The compose view keeps Cancel beside Send, so that row must not be squeezed
   into the circle. */
#cs-form .cs-row { justify-content: flex-start; }
#cs-form .cs-send { width: auto; height: auto; padding: 9px 16px; border-radius: 11px; }
#cs-form .cs-send span {
    position: static;
    width: auto; height: auto;
    clip-path: none;
}

/* ----------------------------------------------------------- presence dot */

/* The header promises "a human replies here". The dot earns that: a slow
   outward pulse, the shared grammar for "someone is on the other end". */
/* The base .cs-dot is declared once at line ~208; only the pulse is new. */
.cs-dot::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--cs-online);
    animation: cs-pulse 2.4s ease-out infinite;
}
@keyframes cs-pulse {
    0%   { transform: scale(1);   opacity: .7; }
    70%  { transform: scale(2.6); opacity: 0;  }
    100% { transform: scale(2.6); opacity: 0;  }
}

/* ------------------------------------------------------------ ticket cards */

/* A status pill so an open thread is distinguishable from a closed one at a
   glance, without reading the body text. */
.cs-pill {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--cs-soft);
    color: var(--cs-muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: capitalize;
    white-space: nowrap;
}
.cs-pill[data-status="open"]     { background: #dcfce7; color: #15803d; }
.cs-pill[data-status="answered"] { background: #dbeafe; color: #1d4ed8; }
.cs-pill[data-status="resolved"] { background: var(--cs-soft); color: var(--cs-muted); }
.cs-pill[data-status="closed"]   { background: #f1f5f9; color: #94a3b8; }

.cs-item:active { transform: translateY(0) scale(.995); }

/* --------------------------------------------------------- empty state */

/* A visitor with no conversations yet gets three short elements — a greeting,
   a dashed note and a button — inside a panel that is still a full 578px
   tall. Top-aligned, they sat in the top fifth and left ~400px of dead white
   beneath, which reads as a rendering fault rather than a choice.

   Centre the group instead, so the slack divides above and below it. The
   selector keys off #cs-empty becoming visible (chat.js only un-hides it when
   the list is genuinely empty), so a real conversation list stays anchored to
   the top where a list belongs and still scrolls normally.

   :has() is progressive enhancement: browsers without it simply keep the
   previous top-aligned layout. */
.cs-view[data-view="list"]:has(#cs-empty:not([hidden])) {
    justify-content: center;
}

/* The button should sit a touch tighter under the note than the default 10px
   flex gap, so the three read as one block rather than three loose rows. */
.cs-view[data-view="list"]:has(#cs-empty:not([hidden])) .cs-empty {
    margin-bottom: 2px;
}

/* ------------------------------------------------------------ focus states */

/* The widget is reachable by keyboard, and a browser's default ring is
   invisible against the dark header. One ring everywhere keeps it honest. */
#cs-root :focus-visible {
    outline: 2px solid var(--cs-accent);
    outline-offset: 2px;
    border-radius: 6px;
}
.cs-head :focus-visible,
.cs-send:focus-visible { outline-color: #fff; }

/* ------------------------------------------------------------ phone sheet */

/* Below 420px a floating card leaves too little room to read a thread or type
   into it. The panel becomes a proper sheet: pinned to the viewport, sized
   with the safe-area inset so it clears the iPhone home indicator, and the
   launcher tucked out of the way above it. */
@media (max-width: 420px) {
    #cs-root { right: 0; bottom: 0; left: 0; }

    .cs-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: none;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .cs-head { padding-top: calc(15px + env(safe-area-inset-top)); }
    .cs-composer { padding-bottom: calc(15px + env(safe-area-inset-bottom)); }

    /* The launcher would float over the sheet's own controls. */
    #cs-launcher { display: none; }
}

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
    .cs-dot::after { animation: none; }
    .cs-send:active { transform: none; }
    .cs-item:active { transform: none; }
}
