/* vigsupport admin styles — email-app feel */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-alt: #fafbfc;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #111827;
    --muted: #6b7280;
    --brand: #2563eb;
    --brand-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warn: #d97706;
    /* Keyboard-focus ring colour. Deliberately a solid, high-contrast tone
       (not the 12%-opacity wash the inputs used to carry) so it clears WCAG
       1.4.11's 3:1 against both the field and the page. See A11Y-01. */
    --focus: #1d4ed8;
    --sidebar-bg: #1f2937;
    --sidebar-text: #d1d5db;
    --sidebar-active: #374151;

    /* ── Design tokens (audit block 1) ───────────────────────────────────
       Scales, so "13 vs 13.5px" and "8 vs 10px radius" stop being invented
       per-template. New/updated code should reference these instead of raw
       values; the old inline numbers get migrated toward them over time. */
    --brand-wash:#eff4ff; --danger-wash:#fef2f2; --success-wash:#f0fdf4; --warn-wash:#fffbeb;
    --text-2:#374151;
    /* type: 6 steps */
    --fs-xs:12px; --fs-sm:13px; --fs-md:14px; --fs-lg:16px; --fs-xl:20px; --fs-2xl:26px;
    --lh-tight:1.25; --lh-normal:1.5; --lh-relaxed:1.65;
    /* spacing: 4px grid */
    --s-1:4px; --s-2:8px; --s-3:12px; --s-4:16px; --s-5:24px; --s-6:32px; --s-7:48px;
    /* radius */
    --r-sm:4px; --r-md:8px; --r-lg:12px; --r-pill:999px;
    /* elevation */
    --e-1:0 1px 2px rgba(17,24,39,.06);
    --e-2:0 2px 8px rgba(17,24,39,.08);
    --e-3:0 12px 32px -8px rgba(17,24,39,.18);
    /* z-index, named */
    --z-sticky:100; --z-dropdown:200; --z-overlay:300; --z-modal:400; --z-toast:500;
    /* motion + control sizing */
    --t-fast:120ms; --t-base:180ms; --ease:cubic-bezier(.2,0,.2,1);
    --control-h:40px; --control-h-sm:32px;
}
@media (prefers-reduced-motion:reduce){ :root{ --t-fast:1ms; --t-base:1ms; } }

/* ── Themes ───────────────────────────────────────────────────────────────
   Selectable colour variants. Each overrides the CSS variables above, so the
   accent (buttons, links, active states) and the sidebar re-tint everywhere at
   once. Applied via <html data-theme="…"> (set early in <head> from
   localStorage to avoid a flash, switched live from the Ctrl+K palette or the
   account page). 'light' is the default and needs no override. */
html[data-theme="dark"] {
    --bg:#0f141a; --surface:#1a212b; --surface-alt:#151b23;
    --border:#2a333f; --border-strong:#3a4553;
    --text:#e6e8ec; --muted:#9aa4b2;
    --brand:#3b82f6; --brand-hover:#60a5fa;
    --focus:#7fb0ff;
    --brand-wash:#16283c; --danger-wash:#3a1c19; --success-wash:#132a20; --warn-wash:#372611;
    --text-2:#c2d0d1;
    --e-1:0 1px 2px rgba(0,0,0,.4); --e-2:0 2px 8px rgba(0,0,0,.5); --e-3:0 12px 32px -8px rgba(0,0,0,.9);
    --sidebar-bg:#0b0f14; --sidebar-text:#c3ccd7; --sidebar-active:#1e2734;
    color-scheme: dark;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
/* Form controls hardcode a white background across the app; under dark that is
   an unreadable white field with light text. Pull them onto the dark surface.
   Scoped to the dark theme so the light/colour themes are untouched. */
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .reply-box textarea[name="body"] {
    background: var(--surface-alt); color: var(--text); border-color: var(--border);
}
html[data-theme="dark"] .badge { background: #2a333f; color: #c3ccd7; }
html[data-theme="dark"] ::placeholder { color: #6b7480; }
html[data-theme="red"] {
    --brand:#dc2626; --brand-hover:#b91c1c;
    --sidebar-bg:#3f1414; --sidebar-text:#f3d4d4; --sidebar-active:#5b1d1d;
}
html[data-theme="green"] {
    --brand:#16a34a; --brand-hover:#15803d;
    --sidebar-bg:#0f2e1c; --sidebar-text:#d0ead9; --sidebar-active:#17492e;
}
html[data-theme="gray"] {
    --brand:#4b5563; --brand-hover:#374151;
    --sidebar-bg:#374151; --sidebar-text:#e5e7eb; --sidebar-active:#4b5563;
}
html[data-theme="yellow"] {
    --brand:#ca8a04; --brand-hover:#a16207;
    --sidebar-bg:#3a2e0a; --sidebar-text:#f0e2b6; --sidebar-active:#54430f;
}
html[data-theme="brown"] {
    --brand:#9a6b3f; --brand-hover:#7c5532;
    --sidebar-bg:#2e2116; --sidebar-text:#e7d6c4; --sidebar-active:#43301f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* ----- App shell ----- */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }

/* The setup banner (and impersonate bar) sit in normal flow ABOVE .app, so a
   rigid `.app { height:100vh }` pushed its bottom — the sidebar footer with the
   signed-in user — below the viewport, forcing a scroll to see who you are.
   Make the shell a flex column that fills the viewport and let .app take the
   space that's actually left after the banner. Desktop only: the mobile layout
   is a drawer with a normally-scrolling page. `:has(> .app)` scopes this to the
   admin shell, never the login page. */
@media (min-width: 901px) {
    body:has(> .app) { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
    body:has(> .app) > .app { height: auto; flex: 1 1 auto; min-height: 0; }
}
.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    padding: 16px 0;
    min-width: 0;
}

/* Top bar — visible on mobile only, holds hamburger + page title */
.topbar {
    display: none;
    align-items: center; gap: 10px;
    padding: 10px 14px;
    background: var(--sidebar-bg); color: #fff;
    position: sticky; top: 0; z-index: 50;
}
.topbar .hamburger {
    background: transparent; border: 0; color: #fff;
    width: 40px; height: 40px; padding: 8px;
    cursor: pointer; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.topbar .hamburger:hover { background: rgba(255,255,255,.08); }
.topbar .hamburger svg { width: 22px; height: 22px; display: block; }
.topbar .topbar-title { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .topbar-spacer { flex: 1; }

/* Backdrop for the drawer */
.drawer-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 90;
    background: rgba(0,0,0,.45);
    opacity: 0; transition: opacity .2s ease;
}
.sidebar-close {
    display: none;
    background: transparent; border: 0; color: #fff;
    width: 36px; height: 36px; padding: 6px;
    cursor: pointer; border-radius: 6px; margin-left: auto;
    font-size: 22px; line-height: 1;
}
.sidebar-close:hover { background: rgba(255,255,255,.08); }

/* Mobile back arrow (above ticket detail) */
.mobile-back {
    display: none;
    align-items: center; gap: 8px;
    padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    color: var(--brand); font-weight: 600;
    text-decoration: none;
}
.mobile-back:hover { background: var(--surface-alt); text-decoration: none; }
.mobile-back svg { width: 18px; height: 18px; }
.brand {
    padding: 4px 14px 14px 18px;
    font-weight: 700; font-size: 16px; letter-spacing: .3px;
    display: flex; align-items: center; gap: 6px;
}
.brand a { color: #fff; text-decoration: none; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand .brand-logo { height: 22px; width: auto; max-width: 110px; border-radius: 4px; background: #fff; padding: 2px; flex-shrink: 0; }
.brand .brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
body[data-sidebar="collapsed"] .brand-text { display: none; }
body[data-sidebar="collapsed"] .brand-logo { height: 28px; max-width: 36px; }

/* Sidebar collapse toggle (desktop only) */
.sidebar-collapse {
    display: none;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 6px;
    color: #d1d5db;
    width: 28px; height: 28px;
    cursor: pointer; padding: 0;
    transition: background .14s ease, color .14s ease;
}
.sidebar-collapse svg { width: 14px; height: 14px; display: block; margin: auto; transition: transform .2s ease; }
.sidebar-collapse:hover { background: rgba(255,255,255,.12); color: #fff; }
@media (min-width: 901px) { .sidebar-collapse { display: inline-flex; align-items: center; justify-content: center; } }

/* Workspace switcher */
.ws-switcher { padding: 0 12px 14px; }
.ws-label    { display:block; color:#9ca3af; font-size:11.5px; text-transform:uppercase; letter-spacing:.6px; }
.ws-static, .ws-dropdown summary {
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 6px;
    padding: 8px 10px;
    color: #e5e7eb;
    list-style: none;
    cursor: pointer;
    display: block;
}
.ws-static strong, .ws-dropdown summary strong { display:block; font-size: 13.5px; font-weight: 600; }
.ws-dropdown summary { position: relative; padding-right: 26px; }
.ws-dropdown summary::-webkit-details-marker { display: none; }
.ws-chevron { position:absolute; right: 10px; top: 50%; transform: translateY(-30%); font-size: 14px; color:#9ca3af; }
.ws-dropdown[open] summary { border-color: rgba(255,255,255,.18); }
.ws-menu {
    background: #111827;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    margin-top: 4px;
    overflow: hidden;
}
.ws-menu-item {
    display: block; padding: 8px 12px; font-size: 13px;
    color: #d1d5db; text-decoration: none;
}
.ws-menu-item:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.ws-menu-item.active { background: var(--sidebar-active); color: #fff; }
.ws-menu-new { border-top: 1px solid rgba(255,255,255,.08); color: #93c5fd; }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.nav-section {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px;
    color: #9ca3af; padding: 16px 10px 6px;
    font-weight: 600;
}
/* Sidebar nav sections are <details class="nav-group">. On desktop the JS
   force-opens every section + the summary is hidden-style click-thru. On
   mobile each section collapses into a dropdown with a rotating chevron. */
.nav-group { display: block; }
.nav-group > summary {
    list-style: none;
    cursor: default; /* desktop: non-interactive label */
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::marker { content: ''; }
.nav-item {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px 8px 14px;
    border-radius: 8px;
    color: var(--sidebar-text); text-decoration: none;
    font-size: 13.5px;
    transition: background .14s ease, color .14s ease, padding-left .15s ease;
    margin-bottom: 2px;
}
.nav-item::before {
    /* Left accent bar (animates in on hover/active) */
    content: '';
    position: absolute; left: 4px; top: 8px; bottom: 8px;
    width: 3px; border-radius: 2px;
    background: transparent;
    transition: background .14s ease, transform .14s ease;
}
.nav-item:hover {
    background: rgba(255,255,255,.06);
    color: #fff;
    text-decoration: none;
    padding-left: 16px;
}
.nav-item:hover::before { background: rgba(255,255,255,.18); }
.nav-item:hover .nav-icon { transform: scale(1.06); }
.nav-item.active {
    background: linear-gradient(90deg, rgba(37,99,235,.18), rgba(37,99,235,.04));
    color: #fff;
}
.nav-item.active::before { background: #3b82f6; }
.nav-item.active .nav-icon { stroke: #93c5fd; }
.nav-icon {
    width: 17px; height: 17px;
    flex-shrink: 0;
    transition: transform .14s ease, stroke .14s ease;
    opacity: .9;
}
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
    padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.06);
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    background: rgba(0,0,0,.15);
}
.user {
    font-size: 12.5px; line-height: 1.3; color: #e5e7eb; min-width: 0; flex: 1;
    display: flex; align-items: center; gap: 10px; overflow: hidden;
    text-decoration: none; border-radius: 8px; padding: 4px 6px; margin: -4px -6px;
    transition: background .12s;
}
.user:hover { background: rgba(255,255,255,.07); color: #fff; }
.user.active { background: rgba(255,255,255,.10); }
.user .user-meta { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; text-transform: capitalize; }

.logout {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 8px;
    color: #d1d5db;
    flex-shrink: 0;
    transition: background .14s ease, color .14s ease, border-color .14s ease, transform .14s ease;
}
.logout:hover {
    background: rgba(220,38,38,.18);
    border-color: rgba(220,38,38,.35);
    color: #fca5a5;
    transform: translateX(2px);
    text-decoration: none;
}
.logout .nav-icon { width: 16px; height: 16px; opacity: 1; }
.main { overflow: auto; display: flex; flex-direction: column; min-width: 0; }

/* Footer at the bottom of .main */
.app-footer {
    margin-top: auto;
    padding: 12px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: center;
    font-size: 12.5px; color: var(--muted);
}
.app-footer a { color: var(--brand); }

/* ----- Flashes ----- */
.flash { padding: 10px 16px; border-bottom: 1px solid var(--border); }
/* Once toasts.js has mirrored a flash into a toast, the inline bar is hushed —
   collapsed out of view but kept in the DOM/render tree (not display:none) so
   the message text stays queryable. */
.flash-hushed { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.flash-ok    { background: #ecfdf5; color: #065f46; }
.flash-err   { background: #fef2f2; color: #991b1b; }
.flash-info  { background: #eff6ff; color: #1e40af; }

/* ----- Inbox layout (mail-style) ----- */
.inbox { display: grid; grid-template-columns: var(--inbox-list-w, 360px) 6px 1fr; flex: 1; min-height: 0; }
/* Draggable divider between the ticket list and the ticket detail. */
.inbox-resizer { cursor: col-resize; background: transparent; position: relative; }
.inbox-resizer::before {
    content: ''; position: absolute; inset: 0 2px;
    background: var(--border); transition: background .12s;
}
.inbox-resizer:hover::before, .inbox-resizer:active::before { background: var(--brand); }
.inbox-list {
    /* Tint the list column so it reads as a distinct pane from the
       (white/surface) conversation detail on its right. */
    border-right: 1px solid var(--border-strong, var(--border));
    background: var(--bg);
    display: flex; flex-direction: column; min-height: 0;
}
.inbox-toolbar {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.inbox-title { font-weight: 600; font-size: 15px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
    padding: 4px 10px; border-radius: 999px; font-size: 12px;
    color: var(--muted); background: transparent;
    border: 1px solid transparent;
}
.tab:hover { background: var(--surface-alt); text-decoration: none; }
.tab.active { background: var(--brand); color: #fff; }
.tab .count { opacity: .7; margin-left: 4px; }

.search { padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--surface-alt); }
.search input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

.ticket-list { flex: 1; overflow-y: auto; }
.ticket-item {
    display: block; padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: inherit; text-decoration: none;
}
.ticket-item:hover { background: var(--surface-alt); text-decoration: none; }
.ticket-item.active { background: #eff6ff; border-left: 3px solid var(--brand); padding-left: 11px; }
.ticket-row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ticket-from { font-weight: 600; font-size: 13.5px; }
.ticket-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ticket-subject { font-size: 13px; margin-top: 2px; }
.ticket-snippet { color: var(--muted); font-size: 12.5px; margin-top: 2px;
                  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.ticket-meta { display: flex; gap: 6px; margin-top: 6px; }

/* ───── Ticket list density modes (set on body[data-density]) ─────
   compact     → small font, no snippet, no meta-badges (max items visible)
   comfortable → default (above)
   spacious    → bigger text, two-line snippet, more padding (easier on the eyes) */
body[data-density="compact"] .ticket-item        { padding: 6px 12px; }
body[data-density="compact"] .ticket-from        { font-size: 12.5px; }
body[data-density="compact"] .ticket-subject     { font-size: 12px;  margin-top: 1px; }
body[data-density="compact"] .ticket-snippet     { display: none; }
body[data-density="compact"] .ticket-meta        { margin-top: 3px; }
body[data-density="compact"] .ticket-meta .badge { font-size: 11.5px; padding: 1px 5px; }

body[data-density="spacious"] .ticket-item        { padding: 16px 16px; }
body[data-density="spacious"] .ticket-from        { font-size: 14.5px; }
body[data-density="spacious"] .ticket-subject     { font-size: 13.5px; margin-top: 3px; }
body[data-density="spacious"] .ticket-snippet     { font-size: 13px; margin-top: 4px; -webkit-line-clamp: 2; }
body[data-density="spacious"] .ticket-meta       { margin-top: 8px; }

/* Density toggle in the inbox toolbar — segmented control look */
.density-toggle {
    display: inline-flex; border: 1px solid var(--border);
    border-radius: 6px; overflow: hidden; align-self: flex-end;
    font-size: 0;
}
.density-toggle button {
    background: var(--surface); color: var(--muted); border: 0;
    padding: 4px 8px; cursor: pointer; font-size: 11px;
    border-right: 1px solid var(--border);
    font-family: inherit; line-height: 1;
}
.density-toggle button:last-child { border-right: 0; }
.density-toggle button:hover { color: var(--text); background: var(--surface-alt); }
.density-toggle button.active { background: var(--brand); color: #fff; }

/* Prev / Next ticket navigation buttons in the ticket-detail header */
.ticket-nav { display: inline-flex; gap: 4px; margin-right: 8px; }
.ticket-nav a, .ticket-nav span {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text);
    text-decoration: none; font-size: 14px;
    transition: border-color .12s, background .12s;
}
.ticket-nav a:hover { border-color: var(--brand); color: var(--brand); background: var(--surface-alt); }
.ticket-nav span    { color: var(--muted); opacity: .45; cursor: not-allowed; }

/* ----- Ticket detail ----- */
.ticket-detail { display: flex; flex-direction: column; min-height: 0; overflow: hidden; flex: 1; }
.ticket-header {
    padding: 9px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex; gap: 12px; align-items: center; justify-content: space-between;
}
.ticket-header h1 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.25; }
.ticket-header .meta { color: var(--muted); font-size: 12px; margin-top: 1px; }
.ticket-actions { display: flex; gap: 6px; }
.ticket-actions form { display: inline; }

/* ----- Status breadcrumbs / flow ----- */
/* Ticket workflow — a clean segmented control. The old version drew a row of
   arrow "chevron tails" (rotated bordered squares) that read as a jagged green
   sawtooth. This is a single rounded track with plain segments: current is
   filled with the state colour, done states a soft tint, upcoming ones muted.
   No arrows, no overlap hacks. */
.state-flow {
    display: inline-flex; flex-wrap: wrap; gap: 0;
    margin: 6px 20px; padding: 2px;
    background: var(--surface-alt); border: 1px solid var(--border);
    border-radius: 9px;
}
.state-step { display: inline-flex; }
.state-step-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: 0; border-radius: 7px;
    padding: 4px 11px; cursor: pointer;
    font: inherit; font-size: 12px; font-weight: 500; color: var(--muted);
    transition: background .12s ease, color .12s ease;
}
.state-step .state-num {
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(125,125,125,.16); color: inherit;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 11px;
}
.state-step .state-label { white-space: nowrap; }
.state-step .state-step-btn:hover { background: rgba(125,125,125,.10); color: var(--text); }

/* done */
.state-step.past .state-step-btn { color: var(--text); }
.state-step.past .state-num {
    background: color-mix(in srgb, var(--state-color) 22%, transparent);
    color: var(--state-color);
}
/* current — the only filled segment */
.state-step.current .state-step-btn {
    background: var(--state-color); color: #fff; font-weight: 600;
}
.state-step.current .state-num { background: rgba(255,255,255,.28); color: #fff; }
/* upcoming */
.state-step.future .state-step-btn { color: var(--muted); }
.state-step.future .state-num { background: rgba(125,125,125,.12); color: var(--muted); }

@media (max-width: 700px) {
    .state-flow { margin: 8px 12px; }
    .state-step .state-label { display: none; }
    .state-step.current .state-label { display: inline; }
    .state-step-btn { padding: 6px 10px; }
}

.messages { flex: 1; overflow-y: auto; padding: 8px 16px 14px; background: var(--surface); }

/* ── Compact ticket chrome (more room for the conversation + reply) ────────
   The breadcrumb, status stepper, assignee/tags and custom-fields rows are
   supporting info; on a tall ticket they shouldn't crowd out the message
   thread. Tighten their padding and control sizes. */
.ticket-subheader, .ticket-fields { padding: 1px 20px !important; gap: 1px 6px !important; font-size: 10px !important; line-height: 1.15 !important; }
.ticket-subheader select, .ticket-fields select,
.ticket-subheader input, .ticket-fields input {
    width: auto !important; min-height: 18px; height: 18px; padding: 0 5px !important; font-size: 10px !important;
    max-width: 150px; border-radius: 4px;
}
.ticket-fields .btn { min-height: 18px; height: 18px; padding: 0 6px; font-size: 10px; }
.ticket-fields .reply-quick-add { width: 17px; height: 17px; font-size: 12px; }
/* FIELDS / label chips a touch smaller too */
.ticket-fields > strong, .ticket-subheader > strong,
.ticket-fields label, .ticket-subheader label { font-size: 10px; }

/* ----- TL;DR: slim, right-aligned; expands to a note only once a summary exists ----- */
.tldr { margin: 3px 20px 0; }
.tldr-head { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.tldr-label { color: #92400e; font-size: 12px; margin-right: auto; display: none; }
.tldr-btn { padding: 1px 8px !important; min-height: 0 !important; font-size: 11px !important; }
.tldr-body { display: none; }
.tldr.has-sum { padding: 4px 10px; background: #fef3c7; border: 1px solid #fde68a; border-radius: 7px; font-size: 12px; }
.tldr.has-sum .tldr-label { display: block; }
.tldr.has-sum .tldr-body { display: block; margin-top: 4px; color: #78350f; white-space: pre-wrap; }

/* ----- prev/next relocated into the breadcrumb bar, pushed to the right ----- */
.breadcrumbs .ticket-nav.in-crumb { margin-left: auto; margin-right: 0; }
.ticket-nav.in-crumb a, .ticket-nav.in-crumb span { width: 24px; height: 24px; font-size: 13px; border-radius: 5px; }
/* Field labels sit tight to their control. */
.ticket-fields label > span:first-child, .ticket-subheader label { color: var(--muted); }
/* On a ticket, the breadcrumb can be a touch slimmer than elsewhere. */
.ticket-detail ~ * .breadcrumbs, .main:has(.ticket-detail) .breadcrumbs { padding: 6px 20px; }
.msg {
    border: 1px solid var(--border); border-radius: 9px;
    margin-bottom: 7px; background: var(--surface);
}
.msg-head {
    padding: 5px 12px; background: var(--surface-alt);
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border); border-radius: 9px 9px 0 0;
    font-size: 12px;
}
.msg-author { font-weight: 600; }
.msg-body { padding: 9px 12px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; }
.msg-out  { background: #f0f9ff; }
.msg-out  .msg-head { background: #e0f2fe; }
.msg-note { background: #fefce8; }
.msg-note .msg-head { background: #fef9c3; }
.msg-ai-draft { border-style: dashed; border-color: #fbbf24; }

/* Reply composer — visually distinct from the message thread so the agent
   instantly knows "this is where I write" vs "this is what was sent". */
.reply-box {
    border-top: 2px solid #bfdbfe;
    padding: 6px 18px 7px;
    background: linear-gradient(180deg, #f0f7ff 0%, #f8fbff 100%);
    box-shadow: inset 0 1px 0 rgba(37, 99, 235, .08);
}
.reply-box textarea[name="body"] { background: #fff; }
/* Compact "insert canned / run macro" row — one line, small selects (the global
   select{width:100%} would otherwise stretch them full-width and stack them),
   each with a superadmin "+" jump-to-edit. */
.reply-quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.reply-quick-label { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.reply-quick-sel { width: auto !important; min-width: 150px; max-width: 240px; padding: 3px 8px !important;
                   font-size: 12px; min-height: 27px; height: 27px; }
.reply-quick-add {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 6px; flex: 0 0 auto;
    border: 1px solid var(--border-strong); color: var(--muted);
    text-decoration: none; font-size: 16px; line-height: 1;
}
.reply-quick-add:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-wash, transparent); }
.reply-box textarea { width: 100%; min-height: 82px; resize: vertical; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 7px; font: inherit; }

/* Toggle row (Internal note / Send as HTML) — clean grid, one per row */
.reply-toggles {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1px 18px;
    margin-top: 3px;
}
@media (max-width: 700px) {
    .reply-toggles { grid-template-columns: 1fr; }
}
.toggle {
    display: flex; align-items: center; gap: 7px;
    padding: 2px 6px; border-radius: 6px; cursor: pointer;
    font-size: 12px; color: var(--text);
    transition: background .12s ease;
}
.toggle:hover { background: var(--surface-alt); }
.toggle input[type=checkbox] { margin: 0; transform: scale(1.1); }
.toggle em { color: var(--muted); font-style: normal; font-size: 12px; }

.reply-toolbar {
    display: flex; flex-wrap: wrap;
    align-items: center;
    margin-top: 5px; gap: 6px;
}
/* Send sits on the SAME row as the action buttons, pushed to the right. */
.reply-toolbar .reply-send { margin-left: auto; }
/* Action row: all buttons on ONE line. They can shrink (shed padding +
   trim labels) before any wrap kicks in. Horizontal-scroll as the very
   last resort on extremely narrow widths. */
.reply-actions {
    display: flex; gap: 6px; align-items: center;
    flex-wrap: wrap; min-width: 0;
}
.reply-actions > * { flex-shrink: 0; }
.reply-actions .status-pill { white-space: normal; }
.reply-send { display: flex; }
@media (max-width: 600px) {
    .reply-toolbar { grid-template-columns: 1fr; }
    .reply-send .btn-action { width: 100%; }
}

/* Unified action button — same height, same baseline across the bar */
.btn-action {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: 600 11.5px/1 inherit;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .14s ease, border-color .14s ease, color .14s ease, transform .12s ease, box-shadow .14s ease;
}
.btn-action:hover { background: var(--surface-alt); border-color: var(--brand); color: var(--brand); transform: translateY(-1px); }
.btn-action:active { transform: translateY(0); }
.btn-action svg { flex-shrink: 0; }
.btn-action:disabled, .btn-action[data-loading="1"] {
    opacity: .65; cursor: not-allowed; pointer-events: none; transform: none;
}

/* Attach — soft slate accent */
.file-pick { position: relative; }
.file-pick input[type=file] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.file-pick:hover { color: #475569; }

/* AI — violet accent (distinct from primary/danger so agents see "smart action") */
.btn-ai {
    background: #faf5ff;
    border-color: #d8b4fe;
    color: #7c3aed;
}
.btn-ai:hover { background: #f3e8ff; border-color: #a855f7; color: #6d28d9; }
.btn-ai .spinner { border-color: #7c3aed; border-top-color: transparent; }

/* Send — primary green CTA with a touch of gradient + depth. The arrow
   slides on hover so the eye is drawn to "this is the action button." */
.btn-send {
    background: linear-gradient(180deg, #22c55e 0%, var(--success) 100%);
    border-color: #15803d;
    color: #fff;
    padding: 0 13px;
    height: 30px; min-width: 86px;
    border-radius: 8px;
    box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(22,163,74,.30);
    font-weight: 700;
    letter-spacing: .2px;
}
.btn-send:hover {
    background: linear-gradient(180deg, #16a34a 0%, #15803d 100%);
    border-color: #14532d; color: #fff;
    box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 4px 10px rgba(22,163,74,.45);
    transform: translateY(-1px);
}
.btn-send:active { transform: translateY(0); box-shadow: 0 1px 0 rgba(255,255,255,.25) inset; }
.btn-send .send-kbd { opacity: .65; font-weight: 500; font-size: 11px; padding-left: 6px; }
@media (max-width: 600px) { .btn-send .send-kbd { display: none; } }

/* Status pill — inline next to AI button */
.status-pill {
    display: inline-flex; align-items: center;
    height: 28px;
    padding: 0 10px;
    border-radius: 14px;
    background: transparent;
    font-size: 12px;
    color: var(--muted);
    transition: background .14s ease, color .14s ease;
    max-width: 320px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.status-pill:not(:empty) { background: rgba(124,58,237,.08); color: #6d28d9; }

/* Order panel above the messages */
.order-panel {
    margin: 0 24px 0 24px; padding: 0;
    background: linear-gradient(180deg, #f0f9ff 0%, #ffffff 100%);
    border: 1px solid #bae6fd; border-radius: 10px;
    overflow: hidden;
    animation: slidedown .25s ease;
}
@keyframes slidedown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.order-panel-head {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: #e0f2fe; border-bottom: 1px solid #bae6fd;
    font-size: 13px;
}
.order-panel-head strong { color: #075985; }
.order-panel-head #order-meta { flex: 1; }
.order-body {
    display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px;
    margin: 0; padding: 12px 14px;
    font-size: 12.5px;
}
.order-body dt { color: var(--muted); font-weight: 600; text-transform: capitalize; }
.order-body dd { margin: 0; color: var(--text); word-break: break-word; }
.order-body .order-empty {
    grid-column: 1 / -1; padding: 6px 0;
    color: var(--muted); font-size: 12.5px;
    text-align: center;
}
@media (max-width: 700px) {
    .order-panel { margin: 0 12px; }
    .order-body { grid-template-columns: 1fr; gap: 2px 0; }
    .order-body dt { font-size: 11px; }
}

/* ----- Empty states ----- */
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

/* ----- Generic content pages ----- */
.page { padding: 20px 28px; overflow-y: auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.page-header h1 { margin: 0; font-size: 22px; }

/* ----- Cards / forms ----- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 20px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
label { display: block; margin: 10px 0 4px; font-weight: 600; font-size: 12.5px; }
input, select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong);
    border-radius: 6px; font: inherit; background: #fff; color: var(--text);
    transition: border-color .12s, box-shadow .12s;
    box-sizing: border-box;
}
input[type=checkbox] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #9ca3af; }
input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}
/* A11Y-01: a real, high-contrast keyboard-focus indicator on EVERY interactive
   element. The old rule killed the outline and relied on a 12%-opacity glow that
   failed WCAG 1.4.11 and vanished entirely in Windows High Contrast Mode, where
   `box-shadow` is not painted but `outline` is. Scoped to :focus-visible so a
   mouse click doesn't draw a ring, only keyboard/AT navigation does. */
:where(a, button, input, select, textarea, summary, [tabindex], .btn, .nav-item,
       .settings-subnav-item, .settings-tile, .vsel-trigger):focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
/* Kill the ring only for a genuine mouse/touch focus (not keyboard). */
:where(a, button, .btn, .nav-item, summary):focus:not(:focus-visible) { outline: none; }

/* A11Y-02: screen-reader-only text + a skip-to-content link. .sr-only hides
   visually while staying in the accessibility tree; the skip link reveals itself
   on keyboard focus so someone tabbing in can jump past the 14-item sidebar. */
.sr-only {
    position: absolute !important; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}
.skip-link {
    position: fixed; top: 8px; left: 8px; z-index: 9999;
    transform: translateY(-160%); transition: transform .15s ease;
    background: var(--brand); color: #fff; padding: 10px 16px;
    border-radius: 8px; font-weight: 600; text-decoration: none;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.skip-link:focus { transform: translateY(0); outline: 2px solid #fff; outline-offset: 2px; }

input:disabled, select:disabled, textarea:disabled {
    background: #f3f4f6; color: #6b7280; cursor: not-allowed;
}
input.is-invalid, select.is-invalid, textarea.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .14);
}

/* ───── Typing-dots affordance ─────
 * Used by #visitor-typing-indicator above the reply box + reusable anywhere
 * we want "X is typing…". Three little dots bounce in sequence. */
.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-muted, #9ca3af);
    animation: typing-dot 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-dot {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40%           { opacity: 1;  transform: translateY(-2px); }
}

/* ───── Searchable <select> wrapper (vsel) ─────
 * The native <select> is visually hidden but stays in the DOM for form
 * submission + accessibility. The trigger button + dropdown panel are
 * built by admin/assets/js/enhanced-inputs.js. */
.vsel { position: relative; }
.vsel-native {
    position: absolute; opacity: 0; pointer-events: none;
    width: 100%; height: 100%; top: 0; left: 0;
}
.vsel-trigger {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 8px 32px 8px 10px;
    border: 1px solid var(--border-strong); border-radius: 6px;
    background: #fff; color: var(--text); font: inherit;
    cursor: pointer; text-align: left;
    transition: border-color .12s, box-shadow .12s;
    box-sizing: border-box; min-height: 38px;
    position: relative;
}
.vsel-trigger:hover { border-color: #9ca3af; }
.vsel.is-open .vsel-trigger,
.vsel-trigger:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.vsel-label {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.vsel-label.vsel-placeholder { color: #9ca3af; }
.vsel-chevron {
    position: absolute; right: 10px; top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 7px; height: 7px;
    border-right: 2px solid #6b7280; border-bottom: 2px solid #6b7280;
    margin-top: -3px;
    transition: transform .15s;
}
.vsel.is-open .vsel-chevron { transform: translateY(-50%) rotate(-135deg); margin-top: 0; }
.vsel-panel {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--border-strong); border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .14);
    z-index: 100; display: none; flex-direction: column;
    max-height: 320px; overflow: hidden;
}
.vsel.is-open .vsel-panel { display: flex; }
.vsel-search-wrap {
    padding: 8px; border-bottom: 1px solid #f3f4f6; background: #fafbfc;
}
.vsel-search {
    width: 100%; padding: 6px 10px; font-size: 13px;
    border: 1px solid var(--border-strong); border-radius: 4px;
}
.vsel-list {
    overflow-y: auto; max-height: 256px; padding: 4px 0;
}
.vsel-opt {
    padding: 7px 12px; cursor: pointer; font-size: 13.5px;
    border-radius: 4px; margin: 0 4px;
}
.vsel-opt:hover, .vsel-opt.is-active { background: var(--surface-alt); }
.vsel-opt.is-selected { font-weight: 600; color: var(--brand); }
.vsel-opt[hidden] { display: none; }

/* ----- Buttons ----- */
.btn {
    display: inline-block; padding: 7px 14px; border-radius: 6px;
    background: var(--brand); color: #fff; border: 0; font: inherit; cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--brand-hover); text-decoration: none; }
.btn-sm   { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border-strong); }
.btn-ghost:hover { background: var(--surface-alt); }
/* Destructive actions are secondary by shape (danger text + border on surface),
   never a big filled-red target — so Delete / Rotate key / Clear secret can't be
   fat-fingered as if they were the primary action. Audit FRM-07. */
.btn-danger { background: var(--surface); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger-wash); color: var(--danger); }
.btn-success { background: var(--success); color:#fff; }
.btn-success:hover { background: #15803d; }

/* Disabled / busy state — applies to ANY .btn while a request is in flight */
.btn:disabled,
.btn[data-loading="1"] {
    opacity: .65;
    cursor: not-allowed !important;
    filter: saturate(.7);
    pointer-events: none;
}

/* Inline spinner used inside buttons during AI calls */
.spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .65s linear infinite;
    vertical-align: -2px;
    margin-right: 4px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Form field primitive (audit FRM-01/05/06) ───────────────────────────
   One shape for a labelled field: block label bound to the input by for/id,
   a single hint slot below (wired via aria-describedby), width by intent
   rather than a blanket 100%. New forms use <div class="field">; existing
   ones migrate toward it. */
.field { display:flex; flex-direction:column; gap:var(--s-1); margin-bottom:var(--s-4); max-width:640px; }
.field > label { display:block; font-weight:600; font-size:var(--fs-sm); color:var(--text-2); white-space:normal; margin:0; }
.field-hint { font-size:var(--fs-xs); color:var(--muted); margin:0; }
.field-error { font-size:var(--fs-xs); color:var(--danger); display:flex; gap:var(--s-1); align-items:center; margin:0; }
.field .f-sm { width:10ch; } .field .f-md { width:28ch; } .field .f-lg { width:100%; }
.f-key { font-family:"IBM Plex Mono",ui-monospace,Consolas,monospace; letter-spacing:.02em; }
/* A row of checkbox + its label, where the truncation-flex actually belongs. */
.check-row { display:flex; align-items:flex-start; gap:var(--s-2); }
.check-row input { width:auto; margin-top:2px; }

/* ── Toasts (audit NOT-01/02) ────────────────────────────────────────────
   Action feedback that survives an SPA partial swap, where the old full-width
   server flash bar could vanish and leave a save looking like it did nothing.
   Fixed, bottom-right, announced to assistive tech. Persistent state (dry-run
   on, S3 not configured) still belongs in an inline banner, not here. */
.toasts {
    position: fixed; right: var(--s-5); bottom: var(--s-5);
    display: flex; flex-direction: column; gap: var(--s-2);
    z-index: var(--z-toast); max-width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}
.toast {
    display: flex; gap: var(--s-3); align-items: flex-start;
    padding: var(--s-3) var(--s-4);
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-left: 3px solid var(--muted);
    border-radius: var(--r-md); box-shadow: var(--e-3);
    pointer-events: auto;
    animation: toast-in var(--t-base) var(--ease);
}
.toast.is-leaving { animation: toast-out var(--t-base) var(--ease) forwards; }
/* A server .flash gets the .toast class added in place; neutralise its old
   full-bleed bar look (hardcoded light backgrounds that broke in dark mode) so
   the neutral toast card + coloured left border carries the meaning. */
.toast.flash { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.toast.flash { border-left-width: 3px; }
.toast--ok  { border-left-color: var(--success); }
.toast--err { border-left-color: var(--danger); }
.toast--warn{ border-left-color: var(--warn); }
.toast-ico { font-size: 15px; line-height: 1.3; }
.toast-body { flex: 1; min-width: 0; font-size: var(--fs-sm); line-height: 1.4; }
.toast-close {
    background: transparent; border: 0; color: var(--muted); cursor: pointer;
    font-size: 16px; line-height: 1; padding: 0 2px; margin: -2px -4px 0 0;
}
.toast-close:hover { color: var(--text); }
@keyframes toast-in  { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform:none; } }
@keyframes toast-out { to { opacity:0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .toast, .toast.is-leaving { animation: none; } }
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 1.6s; }
}

/* Form action footer — Back left, Save right, separated from danger zone */
.form-actions {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 22px; padding-top: 16px;
    border-top: 1px solid var(--border);
}
.form-danger-zone {
    margin-top: 28px; padding-top: 14px;
    border-top: 1px dashed var(--border);
    text-align: center;
}
.link-danger {
    background: none; border: 0; padding: 4px 8px;
    color: var(--danger); font-size: 12px;
    text-decoration: underline; cursor: pointer;
    font-family: inherit;
}
.link-danger:hover { color: #b91c1c; text-decoration: none; }

/* ----- Badges ----- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge-open     { background: #dcfce7; color: #166534; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-closed   { background: #e5e7eb; color: #374151; }
.badge-archived { background: #f3f4f6; color: #6b7280; }

/* Delivery-status badges (shown on outbound messages) */
.delivery-badge {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 600;
    letter-spacing: .2px;
    margin-left: 6px;
    border: 1px solid transparent;
    transition: background .15s ease, transform .15s ease;
}
.delivery-badge:hover { transform: translateY(-1px); }
.delivery-queued    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.delivery-sent      { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.delivery-delivered { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.delivery-opened    { background: #cffafe; color: #155e75; border-color: #a5f3fc; }
.delivery-bounced   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.delivery-failed    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.delivery-dryrun    { background: #f1f5f9; color: #475569; border-color: #cbd5e1; font-style: italic; }

/* ----- Errors ----- */
.err {
    background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
    padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: 13px;
}
/* Informational banner (session expired, session revoked) — same shape as .err
   but neutral/blue, so it reads as "here's what happened" not "you did wrong". */
.notice {
    background: var(--brand-wash, #eff4ff); border: 1px solid #bfdbfe; color: #1e40af;
    padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: 13px;
}
html[data-theme="dark"] .notice { background: #16283c; border-color: #24405f; color: #bcd4f5; }

/* ----- Tables ----- */
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
table.t th { background: var(--surface-alt); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
table.t tr:hover td { background: var(--surface-alt); }

/* ----- Login page ----- */
.login-body { display: grid; place-items: center; height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); padding: 32px; border-radius: 12px; border: 1px solid var(--border); width: 360px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card button[type="submit"] { width: 100%; padding: 10px; margin-top: 14px; font-size: 14px; background: var(--brand); color: #fff; border: 0; border-radius: 6px; cursor: pointer; }

/* Password field with a reveal toggle. The input keeps room on the right so the
   eye never sits on top of typed characters. */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 40px; }
.pw-eye {
    position: absolute; top: 0; right: 0; height: 100%; width: 38px;
    display: grid; place-items: center;
    background: transparent; border: 0; margin: 0; padding: 0;
    font-size: 16px; line-height: 1; cursor: pointer; opacity: .55;
}
.pw-eye:hover, .pw-eye.on { opacity: 1; }
.login-card label.remember {
    display: flex; align-items: center; gap: 8px; margin-top: 12px;
    font-size: 13px; color: var(--muted); cursor: pointer; font-weight: 400;
}
.login-card label.remember input { width: auto; margin: 0; }

/* Single sign-on button under the password form. Deliberately NOT styled like
   the primary submit — the password form stays the main path, and an identical
   pair of full-width buttons makes people guess which one is theirs. The 48px
   height is the touch-target floor, not decoration. */
.sso-sep {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 0 12px; color: var(--muted); font-size: 12px;
}
.sso-sep::before, .sso-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-sso {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 48px; padding: 0 18px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-sso:hover { border-color: var(--brand); color: var(--brand); }

/* ── Breadcrumbs ──────────────────────────────────────────────────────────
   A slim trail at the very top of the content, sticky so it stays reachable
   while the page scrolls. Answers "where am I / how do I get back" that the app
   had no answer for on any sub-page. */
.breadcrumbs {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
    padding: 7px 20px; font-size: 12.5px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.breadcrumbs .crumb { color: var(--muted); text-decoration: none; padding: 2px 4px; border-radius: 4px; }
.breadcrumbs .crumb:hover { color: var(--brand); text-decoration: underline; }
.breadcrumbs .crumb-current { color: var(--text); font-weight: 600; padding: 2px 4px; }
.breadcrumbs .crumb-sep { color: var(--border-strong); margin: 0 2px; }
@media (max-width: 900px) { .breadcrumbs { padding: 8px 12px; } }

/* ── Settings sub-navigation ─────────────────────────────────────────────
   A second, page-local left rail shown only on settings-family pages, so the
   settings sections are reachable from inside one another. Sticky within the
   scrolling .main so it "always holds" while the content scrolls past it. */
.settings-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    padding: 16px 20px;
}
.settings-subnav {
    position: sticky;
    /* Sit below the sticky breadcrumb bar (≈41px) so the two don't overlap. */
    top: 53px;
    align-self: start;
    max-height: calc(100vh - 69px);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 8px;
    font-size: 13px;
}
.settings-subnav-head {
    font-weight: 700; font-size: 12px; letter-spacing: .4px;
    text-transform: uppercase; color: var(--muted);
    padding: 6px 10px 8px;
}
.settings-subnav-section {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px;
    color: var(--muted); padding: 10px 10px 4px; font-weight: 600;
}
.settings-subnav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px; border-radius: 8px;
    color: var(--text); text-decoration: none; line-height: 1.2;
}
.settings-subnav-item:hover { background: var(--surface-alt, rgba(127,127,127,.08)); }
.settings-subnav-item.is-active {
    background: color-mix(in srgb, var(--brand) 14%, transparent);
    color: var(--brand); font-weight: 600;
}
.settings-subnav-ico { width: 18px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.settings-subnav-item.is-active .settings-subnav-ico { color: var(--brand); }
.ui-icon { display: block; }
.settings-shell-body { min-width: 0; }
/* The pages already cap their own width; inside the shell let them use the column. */
.settings-shell-body .page { max-width: none !important; }

/* Settings card anchors: land below any sticky offset and flash the card so the
   jump from Ctrl+K is obvious. */
.cfg-anchor { display: block; position: relative; top: -12px; scroll-margin-top: 16px; }
@keyframes cfg-flash {
    0%   { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 55%, transparent); }
    100% { box-shadow: 0 0 0 3px transparent; }
}
.card.cfg-hit { animation: cfg-flash 1.6s ease-out 1; }

/* Collapsible config sections (audit SET-01/FRM-08): the header shows the title
   + a status chip; the body folds away so the settings page stops being an
   endless scroll. JS adds .cfg-collapsed and the toggle affordance. */
.cfg-h2 { display: flex; align-items: center; gap: 10px; }
.cfg-h2 .chip { margin-left: auto; }
.card.cfg-collapsible > .cfg-h2 { cursor: pointer; user-select: none; }
.card.cfg-collapsible > .cfg-h2::before {
    content: "▾"; font-size: 12px; color: var(--muted); transition: transform var(--t-fast) var(--ease); flex: 0 0 auto;
}
.card.cfg-collapsed > .cfg-h2::before { transform: rotate(-90deg); }
/* !important because many field rows carry an inline style="display:flex",
   which would otherwise win over a plain display:none and stay visible. */
.card.cfg-collapsed > :not(.cfg-h2):not(.cfg-anchor) { display: none !important; }
.card.cfg-collapsed { padding-bottom: 14px; }

@media (max-width: 900px) {
    .settings-shell { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
    .settings-subnav { position: static; max-height: none; }
}

/* Build badge in the app footer — pushed to the far end, monospace so the
   version reads as an identifier rather than prose. */
.app-footer-build {
    margin-left: auto;
    font-family: ui-monospace, Consolas, monospace;
    white-space: nowrap;
}

/* Account page: use the width instead of a tall 560px column. Cards flow into
   two columns on a wide screen (Profile beside Avatar, API beside demo), which
   also roughly halves the scroll height. */
.account-page { max-width: 1040px; }
.account-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px; align-items: start;
}
.account-grid > .card { margin: 0; }

/* ----- Widget snippet box ----- */
.snippet {
    background: #0f172a; color: #e2e8f0; padding: 12px 14px;
    border-radius: 8px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
    overflow-x: auto; white-space: pre;
}

/* =================================================================
   MOBILE — tablet and below
   ================================================================= */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
        position: fixed; inset: 0 auto 0 0;
        width: 280px; max-width: 85vw;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform .22s cubic-bezier(.4, 0, .2, 1);
        box-shadow: 0 0 24px rgba(0,0,0,.25);
    }
    body[data-drawer="open"] .sidebar { transform: translateX(0); }
    body[data-drawer="open"] .drawer-backdrop { display: block; opacity: 1; }

    .sidebar-close { display: flex; }
    .brand { display: flex; align-items: center; padding: 4px 18px 14px; }

    /* Top bar appears */
    .topbar { display: flex; }
    .main { height: auto; }

    /* Inbox stacks list above detail; we toggle via body attribute */
    .inbox { display: block; height: auto; }
    .inbox-resizer { display: none; }
    .inbox-list { border-right: 0; border-bottom: 1px solid var(--border); }
    .ticket-list { max-height: none; }

    /* Mobile: hide list when a ticket is selected; hide empty detail when nothing selected */
    body[data-view="ticket"] .inbox-list { display: none; }
    body[data-view="list"]   .ticket-detail { display: none; }
    body[data-view="ticket"] .mobile-back { display: flex; }

    /* Reply box & messages get tighter padding */
    .ticket-header { padding: 12px 16px; }
    .ticket-header h1 { font-size: 16px; }
    .ticket-actions { flex-wrap: wrap; }
    .messages { padding: 12px 16px 20px; }
    .reply-box { padding: 12px 16px; }
    .reply-toolbar { flex-wrap: wrap; gap: 8px; }
    .reply-toolbar .left { flex-wrap: wrap; }

    /* Forms collapse 2-col / 3-col to 1-col */
    .row, .row3 { grid-template-columns: 1fr; }

    /* Generic page padding shrinks */
    .page { padding: 16px; }
    .page-header { flex-wrap: wrap; gap: 10px; }
    .page-header h1 { font-size: 18px; }

    /* Tables become cards (no horizontal scroll on mobile).
       Requires each <td> to have data-label="Column" — see CLAUDE.md. */
    .card { padding: 14px; }
    .card table.t,
    .card table.t thead,
    .card table.t tbody,
    .card table.t tr,
    .card table.t td { display: block; width: 100%; }
    .card table.t { border-collapse: separate; }
    .card table.t thead { display: none; }
    .card table.t tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 4px 12px;
    }
    .card table.t tr:hover td { background: transparent; }
    .card table.t td {
        border: 0;
        padding: 9px 0;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
        font-size: 13px;
        text-align: right;
        min-width: 0;
    }
    .card table.t td:not(:last-child) { border-bottom: 1px solid var(--border); }
    .card table.t td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: .4px;
        font-weight: 600;
        flex-shrink: 0;
        text-align: left;
    }
    /* Cells WITHOUT data-label (typically action buttons) span full width, no label */
    .card table.t td:not([data-label])::before,
    .card table.t td[data-label=""]::before { content: none; }
    .card table.t td:not([data-label]),
    .card table.t td[data-label=""] {
        justify-content: flex-end;
        padding-top: 10px;
    }
    /* Long values wrap inside the right-aligned area */
    .card table.t td > * { min-width: 0; word-break: break-word; }

    /* Key/value tables: hide the literal "key" cell on mobile because the
       paired value cell already carries data-label="<key>". Tables opt-in
       via class="t kv" + class="kv-key" on the label <td>. */
    .card table.t.kv td.kv-key { display: none; }
    /* The remaining value cell becomes a block — make sure long content
       (file paths, code blocks, badges with text) wraps instead of pushing
       the table wider than the card. */
    .card table.t.kv td:not(.kv-key) {
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .card table.t.kv td:not(.kv-key) code { word-break: break-all; }

    /* Code & monospaced runs (URLs, secrets, etc.) wrap instead of forcing
       a horizontal scrollbar at narrow widths. */
    .card code, .card pre, .source-context code, .visitor-meta code {
        white-space: pre-wrap;
        word-break: break-all;
        overflow-wrap: anywhere;
    }
    /* Readonly inputs full-width so long webhook URLs don't push the form */
    .card input[readonly] { max-width: 100%; }

    .impersonate-bar { font-size: 12px; flex-direction: column; align-items: flex-start; gap: 8px; }

    /* ─── Mobile alignment: everything in a clean grid ─────────────────
       Notifications, info strips, badge clusters and banners all collapse
       to a 2-column auto-fit grid so the page reads cleanly on phones
       instead of ragged flex-wrap output. */

    /* Top-of-page flash messages — each becomes a full-width card with a
       left-edge accent so they stack as a vertical grid. */
    .flash {
        margin: 8px 12px;
        padding: 12px 14px;
        border: 0; border-left: 4px solid currentColor;
        border-radius: 8px;
        font-size: 13.5px;
        display: grid; grid-template-columns: 1fr;
        gap: 4px;
    }
    .flash + .flash { margin-top: 0; }
    .flash-ok   { background: #ecfdf5; color: #065f46; }
    .flash-err  { background: #fef2f2; color: #991b1b; }
    .flash-info { background: #eff6ff; color: #1e40af; }

    /* Info strips above the ticket detail: visitor IP / country / language,
       marketplace thread context, channel thread context. Switch from
       flex-wrap (ragged) to auto-fit grid (aligned columns). */
    .visitor-meta,
    .source-context {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 8px 12px;
        padding: 10px 16px !important;
        align-items: start;
    }
    .visitor-meta > *,
    .source-context > * {
        min-width: 0; word-break: break-word;
    }
    /* Right-aligned action ("Open in marketplace ↗") spans across all
       columns on mobile so it lines up below the IDs cleanly. */
    .source-context > a.btn { grid-column: 1 / -1; justify-self: end; margin-left: 0 !important; }

    /* Single-line banners (lang banner, viewers banner) collapse to a
       vertical grid so their CTA button stacks below the text instead of
       fighting for horizontal space. */
    #lang-banner,
    #viewers-banner {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 10px 16px !important;
    }
    #lang-banner > span:last-child { display: flex; gap: 6px; flex-wrap: wrap; }

    /* Badge clusters in ticket-detail header — when multiple badges sit
       inline, mobile gets a tidy auto-fit grid instead of flex-wrap. */
    .ticket-header .meta {
        display: grid;
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .ticket-header .meta > .badge,
    .ticket-header .meta > span { white-space: normal; }

    /* Ticket-action buttons (Re-open / Pending / Close / Archive) in a
       proper 2-up grid instead of wrap-flex with uneven last-row gaps. */
    .ticket-actions {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        width: 100%;
    }
    .ticket-actions form { display: contents; }
    .ticket-actions form button,
    .ticket-actions > a { width: 100%; }
}

/* Visible focus ring on every focusable element. Replaces the browser default
   that some custom button styles inadvertently override with outline:none. */
*:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-radius: 3px;
}
button:focus-visible, .btn:focus-visible, a.btn:focus-visible {
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .15);
}

/* Settings landing — categorized grid of icon tiles. Replaces the flat
   row of ghost-buttons. Auto-fit so tiles stay legible on every viewport. */
.settings-section { margin-bottom: 22px; }
.settings-section-title {
    font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
    color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}
.settings-tile {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .05s;
}
.settings-tile:hover {
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .08);
}
.settings-tile:active { transform: scale(.99); }
.settings-tile-icon {
    line-height: 1; flex-shrink: 0;
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand-wash, var(--surface-alt));
    color: var(--brand);
    border-radius: 8px;
}
.settings-tile-body { min-width: 0; flex: 1; }
.settings-tile-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.settings-tile-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

/* ── Status chips (audit SET-04) ──────────────────────────────────────────
   One coloured pill that says a component's operational state — Active, Not
   set, Dry-run, Error — so state is glanceable instead of buried in prose. */
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: var(--r-pill);
    font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
    background: var(--surface-alt); color: var(--muted);
    border: 1px solid var(--border);
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-ok    { color: var(--success); background: var(--success-wash); border-color: transparent; }
.chip-warn  { color: var(--warn);    background: var(--warn-wash);    border-color: transparent; }
.chip-err   { color: var(--danger);  background: var(--danger-wash);  border-color: transparent; }
.chip-info  { color: var(--brand);   background: var(--brand-wash);   border-color: transparent; }
.chip-muted { color: var(--muted);   background: var(--surface-alt); }
.chip-plain::before { display: none; }

/* Tile chip sits top-right of the tile. */
.settings-tile { position: relative; }
.settings-tile .chip { position: absolute; top: 10px; right: 10px; }
.settings-tile-name { padding-right: 68px; }

/* Environment badge strip — the operational state at a glance (dry-run!, delivery,
   storage, 2FA). Especially: dry-run means customers receive nothing. NOT-03. */
.env-strip {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    margin: 0 0 16px; padding: 10px 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.env-strip-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 2px; }

/* ── Onboarding panel (audit ONB-02/03/04) ───────────────────────────────
   Collapsible; progress bar in the summary; blocking tasks always shown,
   recommended ones folded; each item a row, not a table cell. */
.onb-panel { padding: 0; }
.onb-summary { list-style: none; cursor: pointer; padding: 14px 16px; }
.onb-summary::-webkit-details-marker { display: none; }
.onb-summary-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 15px; }
.onb-progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-alt); margin-top: 10px; overflow: hidden; }
.onb-progress-fill { height: 100%; background: var(--success); border-radius: var(--r-pill); transition: width var(--t-base) var(--ease); }
.onb-body { padding: 4px 16px 16px; }
.onb-group-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; margin: 12px 0 6px; }
.onb-group-toggle { cursor: pointer; list-style: none; }
.onb-group-toggle::-webkit-details-marker { display: none; }
.onb-group-toggle::before { content: "▸ "; }
.onb-recommend[open] .onb-group-toggle::before { content: "▾ "; }
.onb-item { display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.onb-item:first-child { border-top: 0; }
.onb-item-main { flex: 1; min-width: 0; }
.onb-item-label { font-weight: 600; }
.onb-item-detail { margin-top: 2px; }
.onb-item-act { flex: 0 0 auto; }

@media (max-width: 480px) {
    .settings-grid { grid-template-columns: 1fr; }
}

/* ───────────────────────────────────────────────────────────────────
   Custom scrollbar styling for the admin area. Subtle by default,
   highlighted on hover. WebKit + Firefox both supported.
   Skips system overlay scrollbars (touch devices) which look fine
   as-is.
   ─────────────────────────────────────────────────────────────────── */
@media (hover: hover) and (pointer: fine) {
    * { scrollbar-color: rgba(100, 116, 139, .35) transparent; scrollbar-width: thin; }
    *:hover { scrollbar-color: rgba(100, 116, 139, .6) transparent; }

    *::-webkit-scrollbar { width: 10px; height: 10px; }
    *::-webkit-scrollbar-track { background: transparent; }
    *::-webkit-scrollbar-thumb {
        background: rgba(100, 116, 139, .35);
        border-radius: 6px;
        border: 2px solid transparent;
        background-clip: padding-box;
        min-height: 40px;
    }
    *::-webkit-scrollbar-thumb:hover {
        background: rgba(100, 116, 139, .6);
        background-clip: padding-box;
        border: 2px solid transparent;
    }
    *::-webkit-scrollbar-corner { background: transparent; }

    /* Sidebar lives on a dark background — needs a light scrollbar */
    .sidebar, .sidebar * { scrollbar-color: rgba(255, 255, 255, .18) transparent; }
    .sidebar:hover, .sidebar:hover * { scrollbar-color: rgba(255, 255, 255, .32) transparent; }
    .sidebar *::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); background-clip: padding-box; border: 2px solid transparent; }
    .sidebar *::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .32); background-clip: padding-box; border: 2px solid transparent; }
}

/* ───────────────────────────────────────────────────────────────────
   Bulk-action toolbar (inbox list). Hidden by default — JS removes
   the [hidden] attribute when a selection exists. Styled to read well
   on its dark background.
   ─────────────────────────────────────────────────────────────────── */
.bulk-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #1f2937;
    color: #fff;
    position: sticky; top: 0; z-index: 10;
    overflow: hidden; /* never let the bar itself acquire a scrollbar */
}
.bulk-toolbar[hidden] { display: none !important; }
.bulk-toolbar .bulk-count-label {
    font-size: 12.5px;
    margin-right: 4px;
    white-space: nowrap;
}
/* All buttons on the dark bar use a unified solid look. The original
   btn-ghost was light-on-light and unreadable on #1f2937. */
.bulk-toolbar .btn {
    background: #2563eb;
    color: #fff;
    border: 1px solid #2563eb;
    white-space: nowrap;
}
.bulk-toolbar .btn:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}
/* "Clear" gets a translucent look so it visually de-emphasises vs the
   action buttons but stays readable on dark. */
.bulk-toolbar .bulk-clear {
    background: transparent;
    color: #cbd5e1;
    border: 1px solid rgba(255, 255, 255, .25);
}
.bulk-toolbar .bulk-clear:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

/* Ticket-detail header action buttons (Pending / Close / Archive /
   Merge into… etc.) must never wrap their text — "Merge into..." was
   breaking onto two lines on narrow desktop widths. */
.ticket-actions .btn,
.ticket-actions button { white-space: nowrap; }

/* ───────────────────────────────────────────────────────────────────
   Custom tooltip — fired from data-tip="..." (or [title]) on hover/focus.
   A single floating div is reused across the page (driven by JS in
   _layout.php). Styled to be readable, dark, with a soft drop shadow
   and an arrow.
   ─────────────────────────────────────────────────────────────────── */
.tt-bubble {
    position: fixed;
    background: #0f172a; color: #fff;
    padding: 7px 11px;
    border-radius: 6px;
    font-size: 12.5px; line-height: 1.4;
    max-width: 280px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
    pointer-events: none;
    z-index: 9999;
    opacity: 0; transform: translateY(2px);
    transition: opacity .12s, transform .12s;
}
.tt-bubble.is-visible { opacity: 1; transform: translateY(0); }
.tt-bubble::after {
    content: ''; position: absolute;
    left: 50%; transform: translateX(-50%);
    border: 5px solid transparent;
}
.tt-bubble[data-side="top"]::after    { bottom: -10px; border-top-color: #0f172a; }
.tt-bubble[data-side="bottom"]::after { top: -10px;    border-bottom-color: #0f172a; }
.tt-bubble[data-side="left"]::after   { right: -10px; left: auto; top: 50%; transform: translateY(-50%); border-left-color: #0f172a; }
.tt-bubble[data-side="right"]::after  { left: -10px;  top: 50%; transform: translateY(-50%); border-right-color: #0f172a; }

/* Spinner for async-loaded card content (health preflight, etc.) */
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #e5e7eb; border-top-color: #3b82f6;
    border-radius: 50%; animation: spin .8s linear infinite;
    vertical-align: middle; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────────────────────────────────────────────────
   AI Extend — universal "rewrite this field with AI" modal.
   Trigger button sits inline next to the host textarea / input. Modal
   covers the screen on mobile, centered card on desktop.
   ─────────────────────────────────────────────────────────────────── */
.aix-trigger {
    display: inline-flex; align-items: center; gap: 4px;
    margin: 4px 0 0;
    padding: 4px 10px;
    background: linear-gradient(135deg, #ede9fe, #fce7f3);
    color: #6b21a8;
    border: 1px solid #ddd6fe; border-radius: 6px;
    font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
    transition: background .12s, border-color .12s;
}
.aix-trigger:hover { background: linear-gradient(135deg, #ddd6fe, #fbcfe8); border-color: #c4b5fd; }
.aix-trigger:focus-visible { outline: 2px solid #7c3aed; outline-offset: 2px; }

.aix-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .55);
    z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.aix-overlay[hidden] { display: none !important; }
.aix-card {
    background: var(--surface); color: var(--text);
    border-radius: 12px; max-width: 720px; width: 100%;
    max-height: 90vh; display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.aix-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    font-size: 16px;
}
.aix-head .aix-x {
    background: transparent; border: 0; cursor: pointer;
    font-size: 24px; line-height: 1; color: var(--muted);
}
.aix-head .aix-x:hover { color: var(--text); }
.aix-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.aix-body label {
    display: block; font-size: 12px; font-weight: 600; color: var(--text);
    margin: 12px 0 4px;
}
.aix-body textarea, .aix-body input {
    width: 100%; padding: 10px 12px; font: inherit;
    border: 1px solid var(--border); border-radius: 6px;
    box-sizing: border-box;
}
.aix-body .aix-content { background: var(--surface-alt); color: var(--text); resize: vertical; }
.aix-body .aix-result  { resize: vertical; min-height: 140px; }
.aix-run-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.aix-foot {
    padding: 12px 18px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
}
@media (max-width: 600px) {
    .aix-overlay { padding: 0; }
    .aix-card    { max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
    .aix-foot    { flex-direction: column-reverse; }
    .aix-foot .btn { width: 100%; }
}

/* ───────────────────────────────────────────────────────────────────
   Searchable select widget. The underlying <select> is hidden so screen
   readers + form serialisation still work; the trigger + panel above it
   handle the visible UI.
   ─────────────────────────────────────────────────────────────────── */
.sr-wrap { position: relative; }
.sr-orig {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
    margin: -1px; padding: 0; border: 0;
}
.sr-trigger {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; min-height: 40px;
    padding: 8px 32px 8px 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    font: inherit; text-align: left; cursor: pointer;
    position: relative;
}
.sr-trigger::after {
    content: '▾'; position: absolute; right: 10px; top: 50%;
    transform: translateY(-50%); color: var(--muted); font-size: 12px;
    transition: transform .12s;
}
.sr-trigger.is-open::after { transform: translateY(-50%) rotate(180deg); }
.sr-trigger:hover { border-color: var(--brand); }

.sr-panel {
    position: absolute; left: 0; right: 0; top: 100%;
    margin-top: 4px; z-index: 60;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 12px 28px rgba(0,0,0,.12);
    padding: 6px; max-height: 320px; display: flex; flex-direction: column;
}
/* `display: flex` above overrides the user-agent [hidden] { display: none },
   so make the hidden state explicit. */
.sr-panel[hidden] { display: none !important; }

/* Same trap, one that actually shipped: #visitor-typing-indicator carries the
   `hidden` attribute AND an inline `display:flex`. Inline styles beat the user
   agent rule, so every ticket permanently showed "<customer> is typing…" over
   the message list — for tickets nobody had open. Only !important in a
   stylesheet outranks an inline declaration. */
#visitor-typing-indicator[hidden] { display: none !important; }
.sr-search {
    border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 10px; font: inherit; margin-bottom: 4px;
    font-size: 14px;
}
.sr-list { overflow-y: auto; min-height: 0; }
.sr-row {
    display: block; width: 100%;
    padding: 8px 10px; text-align: left;
    background: transparent; color: var(--text); border: 0;
    border-radius: 6px; font: inherit; cursor: pointer; font-size: 13.5px;
    min-height: 36px;
}
.sr-row:hover { background: var(--surface-alt); }
.sr-row.is-selected {
    background: rgba(37, 99, 235, .12); color: var(--brand); font-weight: 600;
}
.sr-empty { padding: 10px; color: var(--muted); font-size: 13px; text-align: center; }

/* ───────────────────────────────────────────────────────────────────
   Skeleton loaders — pulsing shimmer cards that fill async-loaded
   areas so the user never sees a blank panel.
   Usage:
     <div class="skeleton skeleton-line"></div>
     <div class="skeleton skeleton-card"></div>     (whole row)
   ─────────────────────────────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #e5e7eb 0%, #f3f4f6 40%, #e5e7eb 80%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 6px;
    color: transparent !important;
}
@keyframes skeleton-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}
.skeleton-line       { height: 12px; margin: 6px 0; }
.skeleton-line.short { width: 40%; }
.skeleton-line.long  { width: 80%; }
.skeleton-card {
    height: 56px; margin: 8px 0;
    border-radius: 8px;
}
.skeleton-table { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.skeleton-pill  { height: 22px; width: 80px; border-radius: 999px; display: inline-block; margin-right: 6px; }

/* ───────────────────────────────────────────────────────────────────
   Setup-progress banner. Thin sticky strip at the top of every page
   while the workspace isn't fully configured. Shows a progress bar +
   one-click jump to the next missing step.
   ─────────────────────────────────────────────────────────────────── */
.setup-banner {
    background: linear-gradient(180deg, #eef2ff 0%, #e0e7ff 100%);
    border-bottom: 1px solid #c7d2fe;
    color: #3730a3;
    font-size: 12.5px;
    padding: 6px 14px;
    position: relative;
    z-index: 40;
}
.setup-banner[hidden] { display: none !important; }
.setup-banner-inner {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    max-width: 1200px; margin: 0 auto;
}
.setup-banner-bar {
    flex: 0 0 120px; height: 6px;
    background: #fff; border: 1px solid #c7d2fe; border-radius: 4px;
    overflow: hidden;
}
.setup-banner-bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width .3s ease; }
.setup-banner-text { flex: 1; min-width: 200px; }
.setup-banner-text a { color: #1e1b4b; font-weight: 600; }
.setup-banner-cta {
    background: #4f46e5; color: #fff !important;
    padding: 4px 10px; border-radius: 6px; font-weight: 600;
    text-decoration: none; font-size: 12px;
}
.setup-banner-cta:hover { background: #4338ca; }
.setup-banner-x {
    background: transparent; border: 0; color: #6366f1; font-size: 20px; line-height: 1;
    cursor: pointer; padding: 0 4px;
}
@media (max-width: 700px) {
    .setup-banner-bar { flex: 0 0 80px; }
    .setup-banner-text { font-size: 12px; }
}

/* "Show all (N more)" toggle in the sidebar — visually subtle so it sits
   alongside nav items without claiming the eye. */
.nav-more-toggle {
    background: transparent; border: 0; color: #9ca3af;
    padding: 7px 12px; width: 100%; text-align: left;
    cursor: pointer; font: inherit; font-size: 12.5px;
    display: flex; align-items: center; gap: 10px;
}
.nav-more-toggle:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-more[hidden] { display: none !important; }

/* Impersonation banner — always visible across all viewports when active */
.impersonate-bar {
    background: linear-gradient(90deg, #f59e0b, #d97706);
    color: #fff;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,.15);
    z-index: 50;
}

/* Tab strip wrapped in <details class="tabs-dropdown"> for mobile collapse.
   Desktop: <summary> hidden, the .tabs strip shows inline normally.
   Mobile (≤700px): <summary> shows the current tab; the .tabs strip is
   absolutely positioned below as a dropdown menu, hidden until opened. */
.tabs-dropdown { display: contents; }
.tabs-dropdown > summary { display: none; }
.tabs-dropdown > summary::-webkit-details-marker { display: none; }
.tabs-dropdown > summary::marker { content: ''; }

@media (max-width: 900px) {

    /* Sidebar sections become tappable accordion headers on mobile.
       Chevron rotates to indicate state. */
    .nav-group > summary {
        cursor: pointer;
        position: relative;
        padding-right: 28px;
    }
    .nav-group > summary::after {
        content: '▾';
        position: absolute; right: 12px; top: 50%;
        transform: translateY(-50%);
        color: #9ca3af; font-size: 11px;
        transition: transform .15s;
    }
    .nav-group[open] > summary::after { transform: translateY(-50%) rotate(180deg); }
    .nav-group:hover > summary { background: rgba(255,255,255,.04); }

    /* Mobile-only: turn the wrapper into a real, positioned container so the
       menu can hang below the summary. */
    .tabs-dropdown { display: block; position: relative; }
    .tabs-dropdown > summary {
        display: flex; align-items: center; justify-content: space-between;
        padding: 4px 8px; cursor: pointer; gap: 8px;
        list-style: none;
    }
    .tabs-dropdown > summary .tab { pointer-events: none; }
    .tabs-dropdown-chevron {
        color: var(--muted); font-size: 13px;
        transition: transform .15s;
    }
    .tabs-dropdown[open] .tabs-dropdown-chevron { transform: rotate(180deg); }

    /* The actual menu — absolutely positioned so it doesn't push layout. */
    .tabs-dropdown > .tabs {
        position: absolute; left: 0; right: 0; top: 100%;
        display: flex; flex-direction: column; gap: 0;
        background: var(--surface); border: 1px solid var(--border);
        border-radius: 8px; padding: 4px;
        box-shadow: 0 8px 24px rgba(0,0,0,.12);
        z-index: 40;
        margin-top: 4px;
        overflow: visible; /* override the original overflow-x: auto */
    }
    .tabs-dropdown > .tabs .tab {
        display: flex; justify-content: space-between; align-items: center;
        padding: 10px 12px; border-radius: 6px;
    }
    .tabs-dropdown > .tabs .tab.active { background: var(--surface-alt); }

    /* Close the dropdown on outside-click — handled in JS in _layout.php */

    .snippet { font-size: 11px; }
}

/* =================================================================
   PHONE — small screens
   ================================================================= */
@media (max-width: 480px) {
    .login-card { width: 100%; max-width: 360px; padding: 24px; border-radius: 10px; margin: 16px; }
    .ticket-item { padding: 10px 12px; }
    .ticket-from { font-size: 13px; }
    .ticket-subject { font-size: 12.5px; }
    .ticket-snippet { font-size: 12px; }
    .reply-box textarea { min-height: 100px; }
}

/* Larger tap targets across the board for touch */
@media (hover: none) and (pointer: coarse) {
    .btn { padding: 10px 16px; }
    .btn-sm { padding: 7px 12px; font-size: 12.5px; }
    .nav-item { padding: 11px 12px; }
    .ticket-item { padding: 14px; }
    .tab { padding: 6px 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .drawer-backdrop { transition: none; }
}

/* =================================================================
   DESKTOP — sidebar collapsed to icons-only rail (data-sidebar="collapsed")
   ================================================================= */
@media (min-width: 901px) {
    /* Smooth width transition */
    .app { transition: grid-template-columns .18s ease; }
    .sidebar { transition: width .18s ease; overflow-x: hidden; }

    body[data-sidebar="collapsed"] .app { grid-template-columns: 64px 1fr; }
    body[data-sidebar="collapsed"] .sidebar { width: 64px; }

    /* Hide text content, keep icons */
    body[data-sidebar="collapsed"] .nav-label,
    body[data-sidebar="collapsed"] .nav-section,
    body[data-sidebar="collapsed"] .brand-name,
    body[data-sidebar="collapsed"] .ws-switcher,
    body[data-sidebar="collapsed"] .user,
    body[data-sidebar="collapsed"] .brand { /* whole brand minus the collapse button */
        /* keep visible only the toggle */
    }
    body[data-sidebar="collapsed"] .brand-name,
    body[data-sidebar="collapsed"] .nav-label,
    body[data-sidebar="collapsed"] .nav-section,
    body[data-sidebar="collapsed"] .ws-switcher,
    body[data-sidebar="collapsed"] .user { display: none; }

    body[data-sidebar="collapsed"] .brand { padding: 4px 8px 14px; justify-content: center; }
    body[data-sidebar="collapsed"] .sidebar-collapse svg { transform: rotate(180deg); }

    /* Nav items become square icon buttons */
    body[data-sidebar="collapsed"] .nav-item {
        justify-content: center;
        padding: 10px 0;
        margin: 2px 8px;
    }
    body[data-sidebar="collapsed"] .nav-item::before { display: none; }
    body[data-sidebar="collapsed"] .nav-item:hover { padding-left: 0; }
    body[data-sidebar="collapsed"] .nav-item.active {
        background: rgba(59,130,246,.22);
    }
    body[data-sidebar="collapsed"] .nav-icon { width: 19px; height: 19px; }

    /* Footer: hide user info, center logout */
    body[data-sidebar="collapsed"] .sidebar-footer { justify-content: center; padding: 10px 8px; }
}

/* Reply-box textarea — better default height + smoother autoresize */
.reply-box textarea {
    min-height: 140px;
    max-height: 600px;
    transition: height .08s ease, border-color .14s ease;
    line-height: 1.55;
}
.reply-box textarea:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ---------- Integration apps (sidebar cards + action buttons) ---------- */
.app-cards {
    padding: 8px 24px 4px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.app-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
}
.app-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
}
.app-card-title { font-weight: 600; }
.app-card-open { text-decoration: none; color: var(--muted); font-size: 14px; }
.app-card-open:hover { color: var(--text); }
.app-card-body { padding: 12px; }
.app-run-result {
    margin: 8px 24px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12.5px;
    background: var(--surface);
}
.app-run-result.ok  { border-color: #86efac; background: rgba(220,252,231,.5); }
.app-run-result.err { border-color: #fca5a5; background: rgba(254,226,226,.5); }
.app-run-head { margin-bottom: 4px; }
.app-run-body {
    margin: 6px 0 0;
    max-height: 240px;
    overflow: auto;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    font-family: var(--mono, ui-monospace, Consolas, monospace);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Deflection citation links in the agent ticket view (KB#id / TERMS §x). */
.msg-body .cite-link {
    display: inline-block;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--chip-bg, #eef2ff);
    color: var(--link, #3730a3);
    font-weight: 600;
    font-size: 0.92em;
    text-decoration: none;
    white-space: nowrap;
}
.msg-body .cite-link:hover { text-decoration: underline; }
