/* ============================================
   The app shell: header bar, sidebar support, support panel.

   Three things that belong to the application rather than to any page, so
   they live together and outside pages.css.
   ============================================ */

/* --------------------------------------------------------------- header */

/* Fixed, because the controls on it are app-level and should not scroll away
   with the page. The inbox-feed button used to be position:fixed on its own
   and consequently sat on top of the content as soon as anything scrolled --
   which is the problem this bar exists to solve. */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: var(--topbar-height);
    padding: 0 clamp(20px, 3vw, 44px);
    background: color-mix(in srgb, var(--bg-topbar) 88%, transparent);
    border-bottom: 1px solid var(--border-color);
    /* The blur is what keeps content legible as it passes underneath. Where
       it is unsupported the colour above is already near-opaque. */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: right var(--slow) var(--ease);
}

.rail-open .topbar { right: var(--rail-width); }

.topbar-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.topbar-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color var(--fast) var(--ease),
                border-color var(--fast) var(--ease),
                color var(--fast) var(--ease);
}

.topbar-btn svg { width: 17px; height: 17px; }

.topbar-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-dark);
    color: var(--text-primary);
}

.topbar-btn.active {
    background: var(--green-deep);
    border-color: var(--green-accent);
    color: var(--green-bright);
}

.topbar-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* The page starts below the bar. */
.main-content { padding-top: calc(var(--topbar-height) + 24px); }

/* Setup owns the whole window and has its own header. */
body.onboarding-active .topbar { display: none; }
body.onboarding-active .main-content { padding-top: 0; }

/* ------------------------------------------------------- sidebar support */

/* Set apart from the nav above it, because it is not another place to go --
   it opens a chat over whatever you are already doing. */
.sidebar-support {
    margin-top: auto;
    padding: 12px 12px 0;
    border-top: 1px solid var(--border-color);
}

.sidebar-support-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--fast) var(--ease),
                border-color var(--fast) var(--ease),
                color var(--fast) var(--ease);
}

.sidebar-support-btn:hover {
    background: var(--bg-hover);
    border-color: var(--green-accent);
    color: var(--text-primary);
}

.sidebar-support-btn .nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-support-unread {
    margin-left: auto;
    min-width: 18px;
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: var(--green-accent);
    color: var(--on-accent);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
}

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

body:not(.signed-in) #support-widget { display: none; }

/* No floating launcher. Support opens from the sidebar entry and closes from
   its own header -- nothing sits over the app waiting to be noticed. The
   panel is anchored bottom-right because that is where a chat belongs, not
   because something was there to grow out of. */
.support-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 130;
    display: flex;
    flex-direction: column;
    width: min(390px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 130px));
    background: var(--bg-primary);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-3);
    overflow: hidden;
    animation: support-in 0.18s var(--ease) both;
    transition: right var(--slow) var(--ease);
}

.rail-open .support-panel { right: calc(var(--rail-width) + 20px); }

.support-panel[hidden] { display: none; }

@keyframes support-in {
    from { opacity: 0; transform: translateY(10px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

.support-panel-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 15px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.support-panel-top h2 { margin: 0; font-size: 14px; }
.support-sub { margin: 2px 0 0; font-size: 11px; color: var(--text-muted); }
.support-panel-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Past conversations as a strip rather than a rail: there is no width to
   spare in a 390px panel. */
.support-history {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 9px 15px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    scrollbar-width: none;
}

.support-history::-webkit-scrollbar { display: none; }
.support-history[hidden] { display: none; }

.support-history-item {
    flex: 0 0 auto;
    max-width: 150px;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.support-history-item.active {
    background: var(--green-deep);
    border-color: var(--green-accent);
    color: var(--green-bright);
}

.support-history-item.unread { color: var(--green-bright); }

.support-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.support-stream {
    display: grid;
    gap: 14px;
    padding: 16px 15px;
}

.support-empty {
    display: grid;
    gap: 9px;
    justify-items: center;
    align-content: center;
    min-height: 260px;
    text-align: center;
}

.support-empty h3 { margin: 0; font-size: 16px; }

.support-empty p {
    margin: 0;
    max-width: 34ch;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
}

.support-suggestions {
    display: grid;
    gap: 6px;
    width: 100%;
    margin-top: 6px;
}

.support-suggestion {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.support-suggestion:hover {
    border-color: var(--green-accent);
    color: var(--green-bright);
}

.support-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 15px 4px;
    flex-shrink: 0;
}

.support-composer textarea {
    flex: 1 1 auto;
    min-height: 38px;
    max-height: 140px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
}

.support-composer textarea:focus {
    outline: none;
    border-color: var(--green-accent);
}

.support-send {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #A9C6BB 0%, #86A79B 100%);
    border: 1px solid rgba(0, 0, 0, 0.25);
    border-radius: 50%;
    color: var(--on-accent);
    cursor: pointer;
    transition: filter var(--fast) var(--ease);
}

.support-send svg { width: 15px; height: 15px; }
.support-send:hover { filter: brightness(1.08); }

.support-send:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.support-foot {
    margin: 0;
    padding: 0 15px 10px;
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
}

@media (max-width: 560px) {
    .topbar { left: 0; padding: 0 16px; }
    .support-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: 78px;
        height: min(70vh, calc(100vh - 120px));
    }
    .support-bubble { right: 14px; bottom: 14px; }
}

/* ------------------------------------------------------------ guest seats */
/* A client let in to watch one agent (app.js applyGuestShell). The API
   refuses everything below anyway; this keeps the refused things off the
   screen. Sidebar items a guest keeps carry data-guest in index.html. */
body.is-guest .nav-menu > li:not([data-guest]),
body.is-guest .sidebar-support,
body.is-guest #replay-tour-btn,
body.is-guest #topbar-settings,
body.is-guest #newEmailBtn,
body.is-guest #add-mailbox-btn,
body.is-guest #mailbox-count,
body.is-guest #rename-agent-btn,
body.is-guest #mb-delete-btn,
body.is-guest [data-toggle="an-goal-form"],
body.is-guest [data-toggle="an-trigger-form"],
body.is-guest .rule-side .switch,
body.is-guest .rule-side [data-del],
body.is-guest #an-needs-snippet {
    display: none !important;
}

.user-role {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    color: var(--primary);
}

/* ------------------------------------------------------- the offer button */
/* "Set it up for me", beside the help button. A solid button, not a chip:
   it is the one thing in the bar that is an offer rather than a control. */
.topbar-offer {
    height: 34px;
    padding: 0 16px;
    margin-right: 6px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--on-accent);
    background: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 70%, black);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-1);
    cursor: pointer;
    white-space: nowrap;
    transition: filter var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.topbar-offer:hover { filter: brightness(1.06); transform: translateY(-1px); }
.topbar-offer:active { transform: none; }
.topbar-offer:focus-visible { outline: none; box-shadow: var(--focus-ring); }
body.is-guest .topbar-offer { display: none; }
@media (max-width: 560px) { .topbar-offer { display: none; } }

/* --------------------------------------------------------- the offer modal */
.offer-kicker {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--green-bright);
}
.offer-title { margin: 0 0 8px; font-size: 22px; line-height: 1.25; letter-spacing: -0.01em; }
.offer-sub { margin: 0 0 18px; color: var(--text-muted); line-height: 1.55; }
.offer-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.offer-list li { display: flex; gap: 10px; align-items: flex-start; }
.offer-list svg { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 2px; color: var(--green-bright); }
.offer-list b { display: block; font-size: 13.5px; }
.offer-list span { display: block; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.offer-price {
    display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}
.offer-amount { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-right: 10px; }
.offer-terms { font-size: 12px; color: var(--text-muted); }
.offer-note { font-size: 12px; color: var(--text-muted); max-width: 240px; line-height: 1.4; }
/* The dialog's steps are the same modal-body/modal-footer pair three times
   over; those classes set display, which would beat the hidden attribute. */
#setup-offer-modal [hidden] { display: none !important; }
.offer-foot .spacer { flex: 1; }
.offer-done { min-height: 160px; display: flex; flex-direction: column; justify-content: center; }
#setup-offer-form .form-group { margin-bottom: 14px; }

/* ============================================================ phones */
/* Below 768px the app is a phone app: a header with the logo and a menu
   button, a bottom tab bar with the four places you go all day, the
   sidebar as a drawer for the rest, and everything sized for a thumb. */
.topbar-menu, .topbar-logo, .tabbar, .drawer-backdrop, .nav-phone { display: none; }

@media (max-width: 768px) {
    :root { --topbar-height: 56px; --tabbar-height: 62px; }

    /* --- header: menu · logo (centred) · inbox feed. Settings moves to the
       drawer; the two ends are the same width so the logo sits dead centre. */
    .topbar { left: 0; padding: 0 6px; gap: 0; display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; }
    .topbar-menu {
        display: grid; place-items: center; flex: 0 0 auto;
        width: 44px; height: 44px; border: 0; border-radius: var(--radius-md);
        background: transparent; color: var(--text-primary); cursor: pointer;
    }
    .topbar-menu svg { width: 24px; height: 24px; }
    .topbar-menu:active { background: var(--bg-hover); }
    .topbar-logo { display: block; height: 22px; width: auto; max-width: 170px; justify-self: center; object-fit: contain; }
    /* Every page carries its own heading; up here the logo is the identity. */
    .topbar-title { display: none; }
    .topbar-actions { gap: 0; justify-self: end; }
    .topbar-btn { width: 44px; height: 44px; }
    .topbar-btn svg { width: 22px; height: 22px; }
    .topbar-offer, #replay-tour-btn, #topbar-settings { display: none; }
    .nav-phone { display: list-item; }
    [data-theme="daylight"] .topbar-logo, [data-theme="standard"] .topbar-logo { filter: brightness(0) opacity(0.82); }

    /* --- the sidebar becomes a drawer */
    .sidebar {
        width: min(300px, 84vw);
        transform: translateX(-100%);
        transition: transform 0.22s var(--ease, ease);
        box-shadow: none; z-index: 140;
    }
    body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 1px var(--border-color), 24px 0 60px rgba(0,0,0,0.35); }
    .drawer-backdrop {
        position: fixed; inset: 0; z-index: 130;
        background: rgba(0,0,0,0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    }
    .drawer-backdrop:not([hidden]) { display: block; }
    .sidebar .nav-link { min-height: 48px; font-size: 15px; }
    .sidebar .nav-icon { width: 22px; height: 22px; }
    .sidebar-footer .btn { min-height: 44px; }

    /* --- bottom tab bar */
    body.signed-in .tabbar {
        display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: color-mix(in srgb, var(--bg-topbar) 92%, transparent);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
        border-top: 1px solid var(--border-color);
    }
    .tabbar .tab {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
        position: relative; min-height: var(--tabbar-height); padding: 6px 4px 8px;
        font: inherit; font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
        color: var(--text-muted); background: transparent; border: 0; text-decoration: none; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .tabbar .tab svg { width: 24px; height: 24px; }
    .tabbar .tab.active { color: var(--green-bright); }
    .tabbar .tab.active svg { color: var(--green-bright); }
    .tabbar .tab:active { color: var(--text-primary); }
    .tab-badge {
        position: absolute; top: 6px; left: calc(50% + 6px);
        min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
        font-size: 10px; line-height: 16px; text-align: center;
        color: var(--on-accent); background: var(--primary);
    }
    body.is-guest .tabbar .tab:not([data-guest]) { display: none; }

    /* --- the page sits between the bars */
    .main-content { margin-left: 0; padding: calc(var(--topbar-height) + 14px) 14px calc(var(--tabbar-height) + 20px + env(safe-area-inset-bottom)); }
    .support-bubble, .rail-toggle-mobile { bottom: calc(var(--tabbar-height) + 14px + env(safe-area-inset-bottom)) !important; }
    .support-panel { bottom: calc(var(--tabbar-height) + 76px + env(safe-area-inset-bottom)) !important; }

    /* --- sturdier controls: 44px targets, 16px inputs (no iOS zoom) */
    .btn { min-height: 44px; padding: 10px 16px; font-size: 15px; }
    .btn-sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }
    .btn-icon { min-width: 40px; min-height: 40px; }
    .btn-block { width: 100%; }
    input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea, .form-control {
        font-size: 16px; min-height: 46px;
    }
    textarea { min-height: 100px; }
    input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
    .switch, .check-row, .vx-switch, .pill { min-height: 44px; align-items: center; }
    .day-pills .pill { padding: 8px 14px; font-size: 14px; }
    .seg-btn { min-height: 40px; padding: 8px 12px; }
    .count-badge { display: none; }

    /* --- page headers stack; actions wrap to full width */
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .page-header h1 { font-size: 24px; }
    .header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
    .header-actions .btn { flex: 1 1 auto; }
    .inbox-header-top { flex-wrap: wrap; gap: 10px; }
    .inbox-actions { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .inbox-actions .inbox-btn { min-height: 44px; justify-content: center; }
    .card-body { padding: 16px 14px; }
    .card-h-row { flex-wrap: wrap; gap: 8px; }

    /* --- an agent's tabs: one scrolling strip, never three rows */
    .mb-tabs {
        flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; scroll-snap-type: x proximity;
        margin-left: -14px; margin-right: -14px; padding: 0 14px;
    }
    .mb-tabs::-webkit-scrollbar { display: none; }
    .mb-tab { flex: 0 0 auto; min-height: 46px; padding: 12px 14px; font-size: 14px; scroll-snap-align: start; white-space: nowrap; }
    .mb-crumbs .fback { min-height: 40px; }
    .agent-grid { grid-template-columns: 1fr; }
    .campaign-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; width: 100%; }
    .campaign-actions .btn { min-height: 42px; }
    .campaign-header { flex-wrap: wrap; }
    .member-row { grid-template-columns: 1fr; }

    /* --- dialogs become full-screen sheets */
    .modal { align-items: stretch; }
    .modal-content, .modal-content.modal-lg {
        max-width: none; width: 100%; max-height: none; height: 100%;
        border-radius: 0; border: 0;
        padding-top: env(safe-area-inset-top);
    }
    .modal-header { min-height: 56px; }
    .modal-close { width: 44px; height: 44px; }
    .modal-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
    .modal-footer .btn { flex: 1 1 auto; }
}
