/* ============================================================================
   59-support-chat.css - the in-app support chat and the admin inbox.

   Mobile first: the base rules ARE the phone layout (a full-screen sheet with Back) and the
   1024px query turns them into the desktop one (a floating button, a 380x560 panel above it,
   the inbox as a large fixed-height dialog). The floating button is DESKTOP ONLY: the board
   fits one screen on a phone and carries no floating clutter, so the settings row
   (.settings-support-row) is the phone's only entry.

   NOTHING RESIZES. The panel and the dialog have fixed sizes; the list scrolls inside itself
   (a column-reverse scroller, so it opens at the bottom and stays there as lines arrive); the
   input row sits in a fixed-height slot and the field grows UPWARD over the list.

   Every colour is a token, so the dark theme needs no rule here. Logical properties throughout
   (Hebrew is right to left); the two arrow glyphs are mirrored at the end.
   Sits before 95-rtl and the dark theme like every component sheet.
   ============================================================================ */

:root {
    --support-slot: 60px;
    --support-fab: 48px;
    --support-edge: 20px;
    --support-z: 1250;
}

/* ---------- the floating button (desktop only) ---------- */

.support-fab { display: none; }

.support-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--chronos-red);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 2px var(--chronos-card-bg);
}

.support-fab .support-badge {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
}

.support-badge.is-inline {
    margin-inline-start: auto;
    box-shadow: none;
}

/* ---------- the panel (phone: a sheet; desktop: above the button) ---------- */

.support-panel,
.support-inbox {
    position: fixed;
    inset: 0;
    z-index: var(--support-z);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--chronos-card-bg);
    color: var(--chronos-fg-primary);
    overflow: hidden;
}

.support-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--chronos-outline);
    background: var(--chronos-card-bg);
}

.support-head-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.2;
}

.support-head-text strong { font-size: 15px; }
.support-head-text span { font-size: 12px; color: var(--chronos-fg-muted); }

.support-mark {
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    object-fit: cover;
    background: var(--chronos-chip-bg);
}

.support-back,
.support-close {
    flex: none;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--chronos-fg-secondary);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.support-back:hover,
.support-close:hover { background: var(--chronos-hover-bg); }

.support-close { display: none; }

/* ---------- the conversation ---------- */

.support-conv {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.support-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column-reverse;
}

.support-stream {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 14px 12px;
}

.support-empty {
    margin: auto;
    padding: 24px 22px;
    max-width: 30ch;
    text-align: center;
    color: var(--chronos-fg-muted);
    font-size: 14px;
    line-height: 1.5;
}

.support-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
}

.support-msg.is-mine { align-self: flex-end; flex-direction: row-reverse; }
.support-msg.is-theirs { align-self: flex-start; }

.support-msg .support-mark { width: 26px; height: 26px; }

.support-bubble {
    min-width: 0;
    padding: 8px 12px 9px;
    border-radius: 14px;
    background: var(--chronos-chip-bg);
    color: var(--chronos-fg-primary);
}

.support-msg.is-mine .support-bubble {
    background: color-mix(in srgb, var(--chronos-violet) 16%, var(--chronos-card-bg));
    border-end-end-radius: 4px;
}

.support-msg.is-theirs .support-bubble { border-end-start-radius: 4px; }

.support-who {
    margin-bottom: 2px;
    font-size: 11px;
    font-weight: 700;
    color: var(--chronos-fg-muted);
}

.support-when { margin-inline-start: 6px; font-weight: 400; font-variant-numeric: tabular-nums; }

/* The line is plain text: breaks kept, long words and links wrapped, never turned into markup. */
.support-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.45;
}

/* ---------- the input row: a fixed slot, the field grows upward ---------- */

.support-slot {
    flex: none;
    position: relative;
    height: calc(var(--support-slot) + env(safe-area-inset-bottom, 0px));
}

.support-compose {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
}

.support-field {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 4px;
    padding-inline: 6px 4px;
    border: 1px solid var(--chronos-outline);
    border-radius: var(--radius-card, 14px);
    background: var(--chronos-card-bg);
    box-shadow: 0 1px 3px rgba(17, 24, 39, 0.06);
    transition: border-color 0.15s, box-shadow 0.22s ease;
}

.support-field:focus-within {
    border-color: var(--chronos-violet);
    box-shadow:
        0 0 0 3px rgba(124, 58, 237, 0.15),
        0 10px 26px rgba(17, 24, 39, 0.14);
}

.support-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 34px;
    max-height: 150px;
    padding: 8px 6px;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--chronos-fg-primary);
    font: inherit;
    font-size: 14px;
    line-height: 18px;
    field-sizing: content;
}

.support-input::placeholder { color: var(--chronos-fg-muted); }

.support-send {
    flex: none;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--chronos-violet);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

.support-send-glyph { display: inline-block; }
.support-send:disabled { opacity: 0.4; cursor: default; }
.support-send.is-loading::after { border-color: #fff; border-top-color: transparent; }

.support-note {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 11px;
    border-radius: 10px;
    background: var(--chronos-chip-bg);
    color: var(--chronos-fg-secondary);
    font-size: 13px;
    line-height: 1.35;
}

.support-note.is-error {
    background: color-mix(in srgb, var(--chronos-red) 12%, var(--chronos-card-bg));
    color: var(--chronos-red);
}

.support-retry {
    flex: none;
    padding: 3px 10px;
    border: 1px solid currentColor;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

/* ---------- the admin inbox ---------- */

.support-scrim { display: none; }

.support-inbox-title { margin: 0; flex: 1 1 auto; font-size: 17px; font-weight: 600; }

.support-inbox-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

/* Phone: two screens. The list until a thread is picked, then the conversation. */
.support-inbox-list,
.support-pane {
    flex: 1 1 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.support-inbox:not(.is-conv) .support-pane { display: none; }
.support-inbox.is-conv .support-inbox-list { display: none; }

.support-filter {
    flex: none;
    display: flex;
    gap: 6px;
    padding: 10px 12px;
}

.support-filter-btn {
    padding: 5px 12px;
    border: 1px solid var(--chronos-outline);
    border-radius: 999px;
    background: var(--chronos-card-bg);
    color: var(--chronos-fg-secondary);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.support-filter-btn.is-active {
    border-color: var(--chronos-violet);
    background: color-mix(in srgb, var(--chronos-violet) 12%, var(--chronos-card-bg));
    color: var(--chronos-violet);
}

.support-threads {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
}

.support-thread {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 0;
    border-bottom: 1px solid var(--chronos-outline);
    background: transparent;
    color: inherit;
    text-align: start;
    cursor: pointer;
}

.support-thread:hover { background: var(--chronos-hover-bg); }
.support-thread.is-selected { background: color-mix(in srgb, var(--chronos-violet) 10%, var(--chronos-card-bg)); }

.support-thread .friend-avatar { width: 38px; height: 38px; flex: none; }

.support-thread-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.support-thread-name,
.support-thread-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.support-thread-name { font-size: 14px; font-weight: 600; }
.support-thread.is-unread .support-thread-name { font-weight: 800; }
.support-thread-preview { font-size: 13px; color: var(--chronos-fg-muted); }
.support-thread.is-unread .support-thread-preview { color: var(--chronos-fg-primary); }

.support-thread-meta {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    min-width: 40px;
}

.support-thread-time { font-size: 11px; color: var(--chronos-fg-muted); font-variant-numeric: tabular-nums; }

.support-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--chronos-violet);
}

.support-pane-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--chronos-outline);
}

.support-pane-head .friend-avatar { width: 30px; height: 30px; }

/* ---------- the settings row ---------- */

.settings-support-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 8px 11px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--chronos-violet) 10%, var(--chronos-chip-bg));
    color: var(--chronos-fg-primary);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.settings-support-row:hover { background: color-mix(in srgb, var(--chronos-violet) 18%, var(--chronos-chip-bg)); }
.settings-support-icon { font-size: 20px; color: var(--chronos-violet); }

/* ============================================================================
   Desktop, 1024px and up.
   ============================================================================ */

@media (min-width: 1024px) {
    /* Bottom-right, level with the compose bar's row: the compose bar is centred (a 560px field
       plus its "new task" button), so the corner beside it is free at 1024 and wider. */
    .support-fab {
        position: fixed;
        inset-inline-end: var(--support-edge);
        bottom: max(14px, env(safe-area-inset-bottom, 0px));
        z-index: var(--support-z);
        width: var(--support-fab);
        height: var(--support-fab);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: var(--chronos-violet);
        color: #fff;
        box-shadow: 0 6px 18px rgba(124, 58, 237, 0.35), 0 2px 6px rgba(17, 24, 39, 0.18);
        cursor: pointer;
        transition: transform 0.15s ease, filter 0.15s ease;
    }

    .support-fab:hover { filter: brightness(1.08); transform: translateY(-1px); }
    .support-fab-icon { font-size: 24px; }

    .support-panel {
        inset: auto;
        inset-inline-end: var(--support-edge);
        bottom: calc(max(14px, env(safe-area-inset-bottom, 0px)) + var(--support-fab) + 12px);
        width: 380px;
        height: min(560px, calc(100dvh - 110px));
        border: 1px solid var(--chronos-outline);
        border-radius: 16px;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
    }

    .support-head { padding-top: 10px; }
    .support-back { display: none; }
    .support-close { display: inline-flex; }

    .support-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: calc(var(--support-z) - 1);
        background: rgba(0, 0, 0, 0.55);
    }

    .support-inbox {
        inset: 50% auto auto 50%;
        transform: translate(-50%, -50%);
        width: min(980px, calc(100vw - 48px));
        height: min(680px, calc(100dvh - 48px));
        border: 1px solid var(--chronos-outline);
        border-radius: 16px;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
    }

    /* Two panes side by side; both always visible. */
    .support-inbox-list {
        flex: 0 0 320px;
        border-inline-end: 1px solid var(--chronos-outline);
    }

    .support-pane { flex: 1 1 auto; }
    .support-inbox:not(.is-conv) .support-pane,
    .support-inbox.is-conv .support-inbox-list { display: flex; }

    .support-pane > .support-empty { margin: auto; }
}

/* ---------- /studio: the same components in fixed frames ---------- */

.studio-support-frame {
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: 100%;
    height: 560px;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--chronos-outline);
    border-radius: 16px;
    background: var(--chronos-card-bg);
    color: var(--chronos-fg-primary);
}

.studio-support-frame.is-wide { width: 860px; height: 520px; }
.studio-support-frame.is-phone { width: 375px; height: 640px; }

.studio-support-frame .support-back { display: inline-flex; }

.studio-support-frame .support-inbox-body { flex: 1 1 auto; min-height: 0; }
.studio-support-frame .support-inbox-list { flex: 0 0 300px; border-inline-end: 1px solid var(--chronos-outline); }
.studio-support-frame .support-pane { flex: 1 1 auto; }
.studio-support-frame .support-pane > .support-empty { margin: auto; }

/* ---------- right-to-left layouts: the two arrows point the other way ---------- */

[dir="rtl"] .support-send-glyph,
[dir="rtl"] .support-back { transform: scaleX(-1); }
