/* ============================================================
 * user_ui — Help / Support chrome (Phase 7 Package H + II).
 * ============================================================
 *
 * Package H shipped the floating FAB + a small theme-aware
 * "coming soon" popover. Package II (7.35) repurposes the
 * SAME surface into the live support-ticket widget: the FAB
 * is unchanged in position/role, the panel grows into a
 * chat-style widget (header bar + list / new / thread views,
 * or a signed-out Steam-login view).
 *
 * Everything is section-local (the landing-page mockup does
 * not spec a help/support widget). The widget-internal class
 * vocabulary (`.tk-*`) is taken verbatim from the Support
 * mockup (`Support(claude).html`) and scoped under
 * `.site-help-panel` so it can't leak into page content.
 *
 * Z-index budget (cross-chrome contract):
 *   - .site-help-button         100
 *   - .site-help-panel          110   (anchored, desktop/tablet)
 *   - .site-help-panel (phone)  140   (full-screen cover; still
 *                                      below the mobile drawer,
 *                                      and the Component hides
 *                                      help while a drawer is open)
 *   - .mobile-menus-backdrop    150 (Package G — wins)
 *   - .mobile-drawer            200 (Package G — wins)
 *
 * Loaded by base.html after menus/mobile_menus.css, before
 * `{% block extra_css %}`. No base.html change in Package II —
 * the <link> already exists.
 * ============================================================ */

/* ============================================================
 * 1. Container — logical group only, no visual effect.
 * ============================================================ */
.site-help {
    /* No layout — children are position:fixed. */
}

/* ============================================================
 * 2. Floating action button (FAB).
 *    Unchanged from Package H: 56x56 circle, --orange, fixed
 *    bottom-right. Package II adds the chat <-> X icon swap
 *    on `.is-open` (pure CSS — no JS needed for the swap).
 * ============================================================ */
.site-help-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--orange);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: background 120ms ease-out, transform 120ms ease-out;
}
.site-help-button:hover {
    background: var(--orange-2);
    transform: translateY(-1px);
}
.site-help-button:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 4px;
}
.site-help-button svg {
    width: 26px;
    height: 26px;
}
/* Support-FAB pass: the closed-state face is now the
   support-question.webp brand badge (img/user_ui/shared/) — an <img>
   cover-cropped to the full 56px circle. The orange button fill
   stays underneath as the paint fallback and remains the visible
   face in the open state (X icon). */
.site-help-button .sh-fab-chat {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Unread dot (support-unread pass) — "support answered you".
   Sits on the FAB's top-right corner, anchored against the button
   itself (position:fixed is already a containing block, so no extra
   position:relative is needed). Red, NOT --orange: the button face
   is orange, and the bell's --orange badge would vanish into it.
   #E0533B is the same red the toast's error border uses. The ring
   is --bg so the dot separates from the button on both themes. */
.site-help-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #E0533B;
    border: 2px solid var(--bg);
    box-sizing: border-box;
    pointer-events: none;
}
.site-help-dot[hidden] {
    display: none;
}
/* Open panel = the user is looking at support, so the dot has
   nothing left to say on top of the X icon. */
.site-help.is-open .site-help-dot {
    display: none;
}

/* Icon swap — badge face when closed, X when open. */
.site-help-button .sh-fab-x {
    display: none;
}
.site-help.is-open .site-help-button .sh-fab-chat {
    display: none;
}
.site-help.is-open .site-help-button .sh-fab-x {
    display: block;
}

/* ============================================================
 * 3. Widget panel — theme-aware, themed background image.
 *    Anchored bottom-right above the FAB (desktop + tablet).
 *    Closed state hides via opacity + pointer-events (NOT
 *    display:none) so the open/close transition can play.
 *
 *    The background is a translucent gradient over the themed
 *    support art, falling back to --surface (so the panel is
 *    readable even before / without the image).
 * ============================================================ */
.site-help-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 110;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 132px);
    overflow: hidden;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
    background:
        linear-gradient(rgba(20, 27, 38, 0.88), rgba(20, 27, 38, 0.88)),
        url("/static/img/user_ui/support-bg-dark.2dd80fb81c02.webp") center / cover no-repeat,
        var(--surface);
    opacity: 0;
    transform: scale(0.97) translateY(10px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 180ms ease-out, transform 180ms ease-out;
}
html[data-theme="light"] .site-help-panel {
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
    background:
        linear-gradient(rgba(246, 248, 250, 0.85), rgba(246, 248, 250, 0.85)),
        url("/static/img/user_ui/support-bg-light.e35d33a1522e.webp") center / cover no-repeat,
        var(--surface);
}
.site-help.is-open .site-help-panel {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ============================================================
 * 4. Header bar — back / title+sub / close.
 *    Opaque --surface-2 strip so it reads over the bg image.
 * ============================================================ */
.tk-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}
.tk-back,
.site-help-close {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    transition: color 120ms ease-out, background 120ms ease-out;
}
.tk-back:hover,
.site-help-close:hover {
    color: var(--text);
    background: var(--chip);
}
.tk-back:focus-visible,
.site-help-close:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
}
.tk-back[hidden] {
    display: none;
}
.tk-back svg,
.site-help-close svg {
    width: 17px;
    height: 17px;
}
.tk-head-main {
    flex: 1;
    min-width: 0;
}
.tk-title {
    display: block;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 17px;
    line-height: 1.25;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tk-sub {
    display: block;
    font-size: 12px;
    color: var(--text-mute);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
 * 5. Views — one visible at a time. JS toggles `.is-active`.
 *    Each fills the remaining panel height as a flex column.
 * ============================================================ */
.tk-view {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}
.tk-view.is-active {
    display: flex;
}
.tk-view[hidden] {
    display: none;
}

/* ============================================================
 * 6. List view — ticket cards + New-ticket button.
 * ============================================================ */
.tk-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--orange) transparent;
}
.tk-list::-webkit-scrollbar {
    width: 6px;
}
.tk-list::-webkit-scrollbar-thumb {
    background: var(--orange);
    border-radius: 6px;
}
.tk-list-empty,
.tk-list-error {
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
    padding: 32px 8px;
    line-height: 1.5;
}
.tk-card {
    text-align: left;
    cursor: pointer;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--text);
    padding: 13px 15px;
    width: 100%;
    transition: border-color 140ms ease-out;
}
.tk-card:hover {
    border-color: var(--text-mute);
}
.tk-card:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 1px;
}
.tk-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.tk-card-subj {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 15px;
    /* Absorbs the row's free space so the trailing children stay
       packed on the right. Load-bearing since the support-unread
       pass: with a third child (`.tk-card-unread`) the parent's
       `space-between` would otherwise split the slack on BOTH sides
       of the dot and park it mid-card instead of beside the badge.
       `min-width: 0` below keeps the ellipsis working. */
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tk-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}
.tk-card-id {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-mute);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tk-card-time {
    font-size: 11.5px;
    color: var(--text-mute);
    flex: 0 0 auto;
}

/* Per-card unread dot (support-unread pass) — the FAB dot says
   "you have an answer", this one says WHICH ticket it is on, so the
   user is not left opening threads at random. Same red as
   `.site-help-dot` but smaller (8px vs 14px) and inline, with no
   ring: it sits on the card surface, not on the orange button. */
.tk-card-unread {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #E0533B;
}

/* Status badge — maps the backend's open/pending/resolved/closed. */
.tk-badge {
    flex: 0 0 auto;
    padding: 3px 9px;
    border-radius: 7px;
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.tk-badge.is-open {
    background: color-mix(in srgb, var(--blue) 24%, transparent);
    color: #84A9FF;
}
.tk-badge.is-pending {
    background: color-mix(in srgb, var(--orange) 20%, transparent);
    color: var(--orange-3);
}
.tk-badge.is-resolved {
    background: color-mix(in srgb, #3FB27F 20%, transparent);
    color: #5BD3A0;
}
.tk-badge.is-closed {
    background: color-mix(in srgb, #8A93A4 24%, transparent);
    color: #AEB7C6;
}

/* Cap notice — shown when open_count >= cap. */
.tk-cap {
    flex: 0 0 auto;
    margin: 0 14px;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--orange) 40%, var(--line));
    border-radius: 11px;
    background: color-mix(in srgb, var(--orange) 10%, transparent);
    color: var(--text-dim);
    font-size: 12.5px;
    line-height: 1.45;
}
.tk-cap[hidden] {
    display: none;
}

.tk-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
    margin: 12px 14px 14px;
    height: 46px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    background: var(--orange);
    color: #fff;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 15px;
    transition: background 120ms ease-out, opacity 120ms ease-out;
}
.tk-new-btn:hover:not(:disabled) {
    background: var(--orange-2);
}
.tk-new-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.tk-new-btn svg {
    width: 17px;
    height: 17px;
}

/* ============================================================
 * 7. New-ticket form.
 * ============================================================ */
.tk-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.tk-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.tk-field > span {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-dim);
}
.tk-field input,
.tk-field select,
.tk-field textarea {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 12px 13px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
}
.tk-field select {
    appearance: none;
    cursor: pointer;
    color-scheme: dark;
}
html[data-theme="light"] .tk-field select {
    color-scheme: light;
}
.tk-field input:focus,
.tk-field select:focus,
.tk-field textarea:focus {
    outline: 2px solid var(--orange);
    outline-offset: -1px;
    border-color: transparent;
}
.tk-field-grow {
    flex: 1;
    min-height: 0;
}
.tk-field-grow textarea {
    resize: none;
    height: 100%;
    min-height: 120px;
}
.tk-submit {
    flex: 0 0 auto;
    height: 48px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    background: var(--orange);
    color: #fff;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 15px;
    transition: background 120ms ease-out, opacity 120ms ease-out;
}
.tk-submit:hover:not(:disabled) {
    background: var(--orange-2);
}
.tk-submit:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ============================================================
 * 8. Thread view — message bubbles + reply bar.
 * ============================================================ */
.tk-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--orange) transparent;
}
.tk-thread::-webkit-scrollbar {
    width: 6px;
}
.tk-thread::-webkit-scrollbar-thumb {
    background: var(--orange);
    border-radius: 6px;
}
.tk-day {
    text-align: center;
    font-size: 11px;
    color: var(--text-mute);
    font-family: var(--font-mono);
    margin: 2px 0;
}
.tk-agent {
    display: flex;
    align-items: center;
    gap: 7px;
    align-self: flex-start;
    font-size: 11.5px;
    color: var(--text-mute);
}
.tk-agent-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #5BD3A0;
    flex: 0 0 auto;
}
.tk-msg {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.tk-msg .tk-msg-time {
    display: block;
    font-size: 10.5px;
    color: var(--text-mute);
    margin-top: 5px;
    font-family: var(--font-mono);
}
.tk-msg.is-them {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-bottom-left-radius: 5px;
}
.tk-msg.is-me {
    align-self: flex-end;
    background: var(--orange);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.tk-msg.is-me .tk-msg-time {
    color: rgba(255, 255, 255, 0.7);
}
.tk-closed-note {
    text-align: center;
    font-size: 12px;
    color: var(--text-mute);
    padding: 8px;
    background: var(--chip);
    border-radius: 10px;
}
.tk-thread-error {
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
    padding: 24px 8px;
}

.tk-reply {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
}
.tk-reply input {
    flex: 1;
    min-width: 0;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 12px 14px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
}
.tk-reply input:focus {
    outline: 2px solid var(--orange);
    outline-offset: -1px;
    border-color: transparent;
}
.tk-reply input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.tk-send {
    width: 46px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    background: var(--orange);
    color: #fff;
    display: grid;
    place-items: center;
    transition: background 120ms ease-out, opacity 120ms ease-out;
}
.tk-send:hover:not(:disabled) {
    background: var(--orange-2);
}
.tk-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.tk-send svg {
    width: 18px;
    height: 18px;
}
/* Reply bar hidden on a closed ticket (the closed-note replaces it). */
.tk-reply[hidden] {
    display: none;
}

/* ============================================================
 * 9. Signed-out view — Steam login (anonymous visitors).
 * ============================================================ */
.tk-signedout {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 14px;
    padding: 32px 28px;
}
.tk-signedout-icon {
    width: 44px;
    height: 44px;
    color: var(--orange-3);
}
.tk-signedout-title {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 19px;
    color: var(--text);
    margin: 0;
}
.tk-signedout-body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-dim);
    margin: 0;
    max-width: 280px;
}
.tk-signedout-login {
    display: inline-flex;
    line-height: 0;
    margin-top: 4px;
    border-radius: 999px;
}
.tk-signedout-login img {
    height: 40px;
    width: auto;
    display: block;
    border-radius: 999px;
}
.tk-signedout-login:hover img {
    filter: brightness(1.08);
}
.tk-signedout-login:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 3px;
}

/* ============================================================
 * 10. Toast — transient success / error feedback.
 *     Floats over the panel bottom; JS toggles `.is-show`.
 * ============================================================ */
.tk-toast {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%) translateY(16px);
    max-width: calc(100% - 32px);
    padding: 11px 18px;
    border-radius: 11px;
    background: #1B2230;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    z-index: 5;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.tk-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.tk-toast.is-ok {
    border-color: var(--orange);
}
.tk-toast.is-error {
    border-color: #E0533B;
}

/* ============================================================
 * 11. Hidden by drawer (Package H — unchanged).
 *     Pulls the FAB + panel out of view while a mobile drawer
 *     is open so they never overlap the drawer.
 * ============================================================ */
.site-help.is-hidden-by-drawer .site-help-button,
.site-help.is-hidden-by-drawer .site-help-panel {
    display: none;
}

/* ============================================================
 * 12. Reduced motion — disable open/close + toast animation.
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .site-help-button,
    .site-help-panel,
    .tk-toast {
        transition: none;
    }
}

/* ============================================================
 * 13. Phone — full-screen widget (<=760px, the site's mobile
 *     breakpoint). Desktop + tablet keep the anchored panel.
 *     The FAB stays visible (overridden vs. the mockup, which
 *     hid it) so the widget can be reopened after closing.
 * ============================================================ */
@media (max-width: 760px) {
    .site-help-button {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
    .site-help-button svg {
        width: 24px;
        height: 24px;
    }
    .site-help-panel {
        inset: 0;
        z-index: 140;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border: 0;
        border-radius: 0;
        transform: translateY(100%);
        transform-origin: center;
        box-shadow: none;
    }
    .site-help.is-open .site-help-panel {
        transform: translateY(0);
    }
    /* While the full-screen widget is open the FAB sits under it;
       the header back/close handles dismissal. */
}

/* ============================================================
 * Peek-a-boo mascot (support-peek gag — Package II follow-up).
 * ============================================================
 * `[data-tk-peek]` sits absolutely at the panel's bottom edge,
 * pushed fully below it (translateY 105%) and clipped by the
 * panel's overflow:hidden. When SiteHelp adds `is-peeking` to
 * the root (10 s after open), the mascot slides up over 2 s
 * until the head rises BEHIND the "New ticket" button (the
 * button is lifted above it via its own stacking level).
 *
 * Tuning knobs: `width` (mascot size), the shown translateY
 * percentage (how much cat is visible — smaller = more cat),
 * and `bottom` (vertical anchor vs the button).
 * pointer-events:none — the button underneath stays fully
 * clickable even while overlapped.
 * ============================================================ */

/* Asymmetric slide: up in 4 s (the .is-peeking transition), down in
   1 s (this base transition) — the fast retract fires when the user
   enters the new-ticket view and the class is removed. */
.site-help-panel .tk-peek {
    position: absolute;
    left: 50%;
    bottom: -6px;
    width: 150px;
    height: auto;
    transform: translateX(-50%) translateY(105%);
    transition: transform 1s ease-in;
    pointer-events: none;
    z-index: 1;
    display: block;
}

.site-help.is-peeking .tk-peek {
    transform: translateX(-50%) translateY(30%);
    transition: transform 4s ease-out;
}

/* Speech bubble — typed into by SiteHelp ("Need help??") after the
   slide-up completes; list / signed-out views only. Tuning knobs:
   `bottom` (height beside the cat's head) and the `left` offset
   (horizontal distance from the cat). pointer-events:none. */
.site-help-panel .tk-peek-bubble {
    position: absolute;
    left: calc(50% + 52px);
    bottom: 66px;
    max-width: 150px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    border-bottom-left-radius: 3px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    color: var(--text);
    min-height: 1.3em;
    min-width: 40px;
    opacity: 0;
    transform: translateY(6px) scale(.92);
    transform-origin: bottom left;
    transition: opacity .18s ease-out, transform .18s ease-out;
    pointer-events: none;
    z-index: 3;
}

.site-help-panel .tk-peek-bubble.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Bubble tail pointing down-left toward the cat's head. */
.site-help-panel .tk-peek-bubble::after {
    content: "";
    position: absolute;
    left: -5px;
    bottom: 6px;
    width: 10px;
    height: 10px;
    background: var(--surface-2);
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    transform: rotate(45deg);
}

/* Every view's content stacks ABOVE the peeking mascot — the cat
   always rises BEHIND the list cards, the new-ticket form, the
   thread bubbles / closed-note / reply bar, and the New-ticket
   button; only its head shows through the gaps. One rule covers
   all views (replaces the earlier button-only lift). */
.site-help-panel .tk-view {
    position: relative;
    z-index: 2;
}

@media (prefers-reduced-motion: reduce) {
    .site-help-panel .tk-peek {
        transition: none;
    }
}
