/* Cabsol shared base styles — included by all pages */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:           #B82420;
  --red-dark:      #8f1c19;
  --red-light:     #fbe9e8;
  --red-text:      var(--red);
  --text:          #3a3a3a;
  --text-strong:   #1f1f1f;
  --text-muted:    #6b6b6b;
  --text-light:    #9b9b9b;
  --bg-soft:       #f6f6f7;
  --surface:       #ffffff;
  --border:        #e5e5e7;
  --border-strong: #d1d1d4;
  --success:       #2d8a4e;
  --success-light: #e8f5ec;
  --success-text:  var(--success);
  --success-border:#b7e0c9;
  --warning:       #c47a00;
  --warning-light: #fdf3e0;
  --warning-text:  var(--warning);
  --warning-border:#f0dcac;
  --danger:        #c93b3b;
  --danger-light:  #fbe7e7;
  --danger-text:   var(--danger);
  --danger-border: #f5c6c6;
  --info:          #2563b8;
  --info-light:    #e6eef9;
  --info-text:     var(--info);
  --info-border:   #bdd4f0;
  --purple:        #7c3aed;
  --purple-light:  #f0e8f8;
  --purple-text:   var(--purple);
  --purple-border: #ddc8f0;
  --shadow-soft:   rgba(0,0,0,0.10);
  --shadow-strong: rgba(0,0,0,0.1);
  /* Tooltip chips stay a fixed dark chip in both themes (not page-background-relative). */
  --tooltip-bg:    #1f1f1f;
  --tooltip-text:  #ffffff;
}

/* ── Dark theme ──
   Background/text/border tokens shift with the theme. The accent colors
   themselves (--red/--success/--warning/--danger/--info/--purple) stay
   identical in both modes on purpose — they're the ones used as *solid*
   fills with white text (buttons, solid badges) and changing them would
   break that contrast. Only the paired "-light" fill tokens (filled boxes:
   alerts, tags, badges) and their "-text"/"-border" companions (the text/
   border color used *on top of* that fill) get dark-mode overrides, since a
   pastel light-mode fill with dark accent text has no readable dark-mode
   equivalent unless the fill itself darkens and the text lightens together. */
[data-theme="dark"] {
  --text:          #e8e8e8;
  --text-strong:   #f5f5f5;
  --text-muted:    #999999;
  --text-light:    #777777;
  --bg-soft:       #121212;
  --surface:       #1e1e1e;
  --border:        #2e2e2e;
  --border-strong: #3d3d3d;
  --shadow-soft:   rgba(0,0,0,0.45);
  --shadow-strong: rgba(0,0,0,0.5);

  --red-light:      rgba(184, 36, 32, 0.18);
  --red-text:       #ff8a80;
  --success-light:  rgba(45, 138, 78, 0.20);
  --success-text:   #6fcf97;
  --success-border: rgba(45, 138, 78, 0.45);
  --warning-light:  rgba(196, 122, 0, 0.20);
  --warning-text:   #f5b642;
  --warning-border: rgba(196, 122, 0, 0.45);
  --danger-light:   rgba(201, 59, 59, 0.18);
  --danger-text:    #ff6b6b;
  --danger-border:  rgba(201, 59, 59, 0.45);
  --info-light:     rgba(37, 99, 184, 0.20);
  --info-text:      #6ea8fe;
  --info-border:    rgba(37, 99, 184, 0.45);
  --purple-light:   rgba(124, 58, 237, 0.20);
  --purple-text:    #c4a4f5;
  --purple-border:  rgba(124, 58, 237, 0.45);
}

body {
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  border-bottom: 1px solid var(--border);
  padding: 0;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: min(95vw, 1800px);
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: stretch;
  height: 60px;
}
.logo-wrap {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; text-decoration: none;
  margin-right: 32px; flex-shrink: 0;
}
.logo { height: 32px; width: auto; display: block; }
/* The real cabsol logo is brand-red on a transparent background. It reads well on
   the light surface; on the dark surface (#1e1e1e) the red is a little dim, so we
   lift it slightly. NOT filter:invert() — the logo is coloured, and inverting a
   red mark would turn it cyan and destroy the brand. brightness() keeps the hue. */
[data-theme="dark"] .logo,
[data-theme="dark"] .error-logo { filter: brightness(1.15); }
.logo-text { font-weight: 700; font-size: 26px; letter-spacing: -0.02em; color: var(--text-strong); }
.topbar-nav { display: flex; align-items: stretch; gap: 0; flex: 1; justify-content: center; }
.nav-link {
  display: flex; align-items: center;
  padding: 0 18px;
  font-size: 14px; font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text-strong); }
.nav-link.active { color: var(--red); border-bottom-color: var(--red); }
.topbar-right { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.topbar-user { font-size: 13px; color: var(--text-muted); }
.topbar-user strong { color: var(--text-strong); font-weight: 600; }
.btn-link {
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--text-muted);
  text-decoration: underline; padding: 0;
}
.btn-link:hover { color: var(--red); }
.pilot-tag {
  background: var(--red-light); color: var(--red-text);
  padding: 5px 12px; border-radius: 3px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ── Alerts ── */
.alert {
  padding: 12px 16px; border-radius: 4px;
  font-size: 13px; margin-bottom: 16px; display: none;
}
.alert.show { display: block; }
.alert-error   { background: var(--danger-light);  color: var(--danger-text);  border: 1px solid var(--danger-border); }
.alert-success { background: var(--success-light); color: var(--success-text); border: 1px solid var(--success-border); }
.alert-warning { background: var(--warning-light); color: var(--warning-text); border: 1px solid var(--warning-border); }
.alert-info    { background: var(--info-light);    color: var(--info-text);    border: 1px solid var(--info-border); }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner-sm { width: 12px; height: 12px; border-width: 2px; }

/* ── User menu dropdown ── */
.topbar-user-menu { position: relative; display: flex; align-items: center; }
.btn-user-menu {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--red); color: white;
  border: none; border-radius: 4px;
  padding: 7px 14px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.2s;
  white-space: nowrap;
}
.btn-user-menu:hover { background: var(--red-dark); }
.user-menu-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; min-width: 180px;
  box-shadow: 0 4px 16px var(--shadow-soft);
  z-index: 200; display: none; overflow: hidden;
}
.user-menu-dropdown.open { display: block; }
.user-menu-item {
  display: block; width: 100%;
  padding: 10px 16px;
  font-family: inherit; font-size: 14px; font-weight: 500;
  color: var(--text); text-decoration: none;
  background: none; border: none; border-radius: 0;
  text-align: left; cursor: pointer;
  transition: background 0.12s;
  box-sizing: border-box;
}
.user-menu-item:hover { background: var(--bg-soft); color: var(--text-strong); }
.user-menu-item-logout {
  border-top: 1px solid var(--border);
  color: var(--danger-text);
}
.user-menu-item-logout:hover { background: var(--danger-light); }

/* ── Theme toggle ── */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: none; border: 1px solid var(--border-strong); border-radius: 6px;
  cursor: pointer; color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--bg-soft); color: var(--text-strong); }
.theme-toggle svg { width: 20px; height: 20px; display: block; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Checkboxes ── */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin: 0;
  vertical-align: middle;
  transition: background 0.15s, border-color 0.15s;
}
input[type="checkbox"]:hover { border-color: var(--red); }
input[type="checkbox"]:checked {
  background: var(--red);
  border-color: var(--red);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ── Customer/site entity badges + autocomplete picker (upload.html, generate.html) ── */
.entity-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: 10px; vertical-align: middle; white-space: nowrap; flex-shrink: 0;
  background: var(--info-light); color: var(--info-text); border: 1px solid var(--info-border);
}
.entity-badge-site      { background: var(--purple-light); color: var(--purple-text); border: 1px solid var(--purple-border); }
.entity-badge-unmatched { background: var(--bg-soft); color: var(--text-muted); border: 1px solid var(--border-strong); }
.btn-edit-entity {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 1px 3px; display: inline-flex; align-items: center; vertical-align: middle;
}
.btn-edit-entity:hover { color: var(--text); }

.picker-field { margin-bottom: 12px; position: relative; }
.picker-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.picker-field input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 4px; font-family: inherit; font-size: 15px;
  color: var(--text); background: var(--surface);
  transition: border-color 0.15s; outline: none;
}
.picker-field input:focus { border-color: var(--red); }
.picker-field input:disabled { background: var(--bg-soft); color: var(--text-light); }
.picker-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 12px var(--shadow-strong);
  max-height: 180px; overflow-y: auto; z-index: 50; display: none;
}
.picker-suggestions.show { display: block; }
.picker-suggestion-item { padding: 8px 10px; font-size: 13px; cursor: pointer; }
.picker-suggestion-item:hover { background: var(--bg-soft); }

/* ── Undo toast (soft-delete "Rückgängig") ──────────────────────────────────────
   Stacking toasts anchored bottom-right. Slide up in, right-to-left progress bar,
   slide down out. Colours are entirely theme-variable-driven, so light + dark
   both work via the [data-theme] attribute — no hard-coded hex values. */
.undo-toast-container {
  /* Lifted clear of the app-wide help-chat floating button (bottom-right, ~44px
     tall at bottom:24px) so the two never overlap — the toasts stack ABOVE it. */
  position: fixed; bottom: 88px; right: 24px; z-index: 600;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none;
}
.undo-toast {
  pointer-events: auto;
  min-width: 280px; max-width: 380px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px var(--shadow-strong);
  overflow: hidden;
  transform: translateY(140%); opacity: 0;
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.28s ease-out;
}
.undo-toast.show { transform: translateY(0); opacity: 1; }
.undo-toast.hide {
  transform: translateY(140%); opacity: 0;
  transition: transform 0.2s ease-in, opacity 0.2s ease-in;
}
.undo-toast-body { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.undo-toast-message { flex: 1; font-size: 13px; font-weight: 500; line-height: 1.35; }
.undo-toast-btn {
  flex-shrink: 0; background: transparent; border: none;
  color: var(--info-text); font-weight: 700; font-size: 13px; font-family: inherit;
  cursor: pointer; padding: 5px 8px; border-radius: 4px; transition: background 0.15s;
}
.undo-toast-btn:hover { background: var(--info-light); }
.undo-toast-btn:focus-visible { outline: 2px solid var(--info); outline-offset: 1px; }
/* Thin bar along the bottom edge; shrinks right→left over the toast's lifetime. */
.undo-toast-progress {
  height: 3px; background: var(--info);
  transform: scaleX(1); transform-origin: right;
}
.undo-toast.running .undo-toast-progress {
  transition: transform 5000ms linear; /* transitionDuration overridden inline in JS */
  transform: scaleX(0);
}

/* CA-A1: visually hidden but exposed to assistive tech — used for the shared
   aria-live status region (Cabsol.a11y.announce) driving throttled SSE-generation
   announcements. Standard clip-rect technique so screen readers still read it. */
.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;
}

/* .icon-btn — icon-only row action button. Previously copy-pasted inline into
   admin.html/components.html; hoisted here so offers-in-progress.html (undo-toast
   delete button) and any future page share one definition. Identical rules, so
   the existing inline copies (which still win by source order) render the same. */
.icon-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 4px; padding: 5px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: border-color 0.15s, color 0.15s, background 0.15s;
  line-height: 0;
}
.icon-btn:hover { border-color: var(--text-muted); color: var(--text-strong); background: var(--bg-soft); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn:disabled:hover { border-color: var(--border); color: var(--text-muted); background: none; }

/* Auth-code modal (Step 54) — shared by the login second factor and step-up
   confirmation (Cabsol.promptAuthCode). Built dynamically in shared.js; theme-variable
   driven so light + dark both work. z-index above the undo toast (600). */
.authcode-overlay {
  position: fixed; inset: 0; z-index: 700;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.45); padding: 20px;
}
.authcode-modal {
  width: 100%; max-width: 380px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px var(--shadow-strong);
  padding: 22px;
}
.authcode-title { font-size: 17px; font-weight: 700; color: var(--text-strong); margin-bottom: 8px; }
.authcode-desc  { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 14px; }
.authcode-error { margin-bottom: 12px; }
.authcode-input {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px; letter-spacing: 0.3em; text-align: center;
  color: var(--text-strong); background: var(--surface);
  outline: none; transition: border-color 0.15s;
}
.authcode-input:focus { border-color: var(--red); }
.authcode-actions { display: flex; gap: 10px; margin-top: 16px; }
.authcode-actions button {
  flex: 1; padding: 11px 16px; border-radius: 6px;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.authcode-cancel { background: transparent; color: var(--text-muted); border: 1px solid var(--border-strong); }
.authcode-cancel:hover:not(:disabled) { border-color: var(--text-muted); color: var(--text-strong); }
.authcode-submit { background: var(--red); color: #fff; border: 1px solid var(--red); }
.authcode-submit:hover:not(:disabled) { background: var(--red-dark); }
.authcode-actions button:disabled { opacity: 0.6; cursor: not-allowed; }

/* In-app help (?) icon (Cabsol.helpIcon) — mounted next to a tab/section heading
   (declaratively via data-help-topic, or by a page's JS). Opens the help page at
   the matching section in a new tab. Theme-variable driven → light + dark both work. */
.help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle; margin-left: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  color: var(--text-light); text-decoration: none; flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.help-icon:hover { color: var(--red); background: var(--red-light); }
.help-icon svg { display: block; }
.help-icon:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ── Grouped sidebar navigation (shared: help page + admin multi-page area) ───
   The distinctive visual language — uppercase category labels, and a red
   left-border + tint on the active entry — lives here so BOTH the in-app help
   sidebar (help-*.html) and the admin-area sidebar (admin-*.html) render
   identically. Only the positioning/collapse of the containing <aside> stays
   per-context (.help-sidebar / .admin-nav-sidebar). Theme-variable driven, so
   light and dark both work.

   Step 72 compacted the spacing (denser rows/labels) and made each category
   group COLLAPSIBLE: .sidebar-nav-group-title is now a full-width toggle button
   with a chevron; Cabsol.initSidebarCollapse (shared.js) sets the initial state
   (only the group containing the active link is expanded) and wires the toggle.
   Both renderHelpSidebar() and renderAdminSidebar() emit this same structure. */
.sidebar-nav-group { margin-bottom: 4px; }
.sidebar-nav-group-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%;
  margin: 0; padding: 6px 12px;
  background: none; border: none; border-radius: 6px;
  font-family: inherit;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted);
  cursor: pointer; text-align: left;
  transition: color 0.12s, background 0.12s;
}
.sidebar-nav-group-title:hover { color: var(--text-strong); background: var(--surface); }
.sidebar-nav-group-title:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }
.sidebar-nav-chevron {
  flex-shrink: 0; width: 12px; height: 12px;
  transition: transform 0.15s ease;
}
/* Collapsed: hide the links and rotate the chevron from "down" to "right". */
.sidebar-nav-group[data-collapsed="true"] .sidebar-nav-group-items { display: none; }
.sidebar-nav-group[data-collapsed="true"] .sidebar-nav-chevron { transform: rotate(-90deg); }
.sidebar-nav-group-items { padding-top: 1px; }
.sidebar-nav-link {
  display: block;
  padding: 5px 12px 5px 14px;
  border-radius: 8px;
  border-left: 2px solid transparent;
  font-size: 13.5px; line-height: 1.3;
  color: var(--text); text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sidebar-nav-link:hover { background: var(--surface); color: var(--text-strong); }
.sidebar-nav-link.is-active {
  background: var(--red-light);
  color: var(--red-text);
  border-left-color: var(--red);
  font-weight: 600;
}

/* Collapse toggle — hidden on wide viewports; each context's own responsive
   block flips it to inline-flex when its sidebar collapses. */
.sidebar-nav-toggle {
  display: none;
  align-items: center; gap: 8px;
  margin: 16px 24px 0;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text); cursor: pointer;
}
.sidebar-nav-toggle:hover { border-color: var(--red); color: var(--red-text); }

/* ── Page-transition affordances (Step 72, shared.js Part B) ──────────────────
   Purely cosmetic; real browser navigation is unchanged (no SPA routing). Two
   pieces, both wired centrally in shared.js so every page gets them for free:
     • .cabsol-progress — a thin top loading bar shown on every page load (and on
       click-triggered internal navigation), trickling toward 90% then completing
       to 100% + fading out once the page is ready (DOMContentLoaded).
     • body.cabsol-leaving — a brief fade-out of the current page when the user
       clicks an internal link, before the browser navigates.
   Theme-accent driven (--red); honours prefers-reduced-motion (both disabled). */
.cabsol-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--red);
  box-shadow: 0 0 8px 0 var(--red);
  border-radius: 0 2px 2px 0;
  z-index: 2147483000;
  opacity: 1; pointer-events: none;
  transition: width 0.2s ease-out, opacity 0.35s ease 0.1s;
}
.cabsol-progress.is-done { opacity: 0; }

body { transition: opacity 0.16s ease-out; }
body.cabsol-leaving { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .cabsol-progress { display: none; }
  body { transition: none; }
  body.cabsol-leaving { opacity: 1; }
}

/* ── In-app help chat widget (help-chat.js) ──────────────────────────────────────
   A floating, collapsible Q&A panel present on EVERY authenticated page (mounted
   centrally by shared.js once a role-bearing session exists). Fully theme-variable
   driven → correct in light & dark. Anchored bottom-right, above page content but
   BELOW the undo-toast (600) / auth-code overlay (700) / modals; the button + panel
   are hidden while a modal is open (body.cabsol-modal-open). Radius/shadow/spacing
   mirror the app's card + modal components so it doesn't read as a foreign widget. */
.help-chat-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 500;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px; border: none; border-radius: 999px;
  background: var(--red); color: #fff; cursor: pointer;
  font-size: 14px; font-weight: 600; line-height: 1;
  box-shadow: 0 4px 16px var(--shadow-strong);
  transition: background 0.14s, transform 0.14s, box-shadow 0.14s;
}
.help-chat-fab:hover { background: var(--red-dark); transform: translateY(-1px); box-shadow: 0 6px 20px var(--shadow-strong); }
.help-chat-fab:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.help-chat-fab svg { width: 18px; height: 18px; }
.help-chat-fab.is-hidden { display: none; }
/* While any modal is open, keep the floating chat (and its backdrop) out of the way. */
body.cabsol-modal-open .help-chat-fab,
body.cabsol-modal-open .help-chat-panel,
body.cabsol-modal-open .help-chat-backdrop { display: none !important; }

/* Subtle backdrop behind the open panel: dims the page just enough to read the panel
   as a floating overlay layer (not a second layout block awkwardly overlapping the
   page), while the page stays visible underneath so it can still be referenced.
   Clicking it closes the panel. */
.help-chat-backdrop {
  position: fixed; inset: 0; z-index: 499;
  background: rgba(0, 0, 0, 0.15);
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease;
}
.help-chat-backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ── Panel container ──────────────────────────────────────────────────────────
   Built as a SIBLING of the app's floating dialogs, not a bespoke widget. Every
   value below is taken from an existing app component (see the reference table in
   CLAUDE.md, build step "help-chat design alignment"), never invented:
     • radius  10px  ← .authcode-modal (the app's floating-dialog radius)
     • shadow         ← .authcode-modal  (0 12px 40px var(--shadow-strong))
     • border  1px var(--border) ← .modal / .authcode-modal
   Width sits inside the app's modal width range (authcode 380 → admin modal 480).
   Height is capped so the panel is always fully visible; the message list scrolls,
   not the panel. overflow:hidden clips the red header to the panel radius, so the
   header is rounded on top and square where it meets the body (standard pattern). */
.help-chat-panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 501;
  display: none; flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 120px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px var(--shadow-strong);
  overflow: hidden;
}
.help-chat-panel.is-open { display: flex; }

/* Header — brand-red accent tying the panel to its button. Horizontal padding 16px
   is the shared panel gutter (used by header, messages and form alike); vertical 12px
   is on the app spacing scale. Title 14px/600 matches the app's compact heading weight. */
.help-chat-head {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; background: var(--red); color: #fff;
}
.help-chat-head-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.help-chat-head-title svg { width: 16px; height: 16px; }
.help-chat-head-actions { display: flex; align-items: center; gap: 4px; }
/* Icon button radius 6px ← .theme-toggle / .modal-close family (icon-control radius). */
.help-chat-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 6px;
  background: transparent; color: #fff; cursor: pointer; opacity: 0.9;
  transition: background 0.12s, opacity 0.12s;
}
.help-chat-icon-btn:hover { background: rgba(255,255,255,0.18); opacity: 1; }
.help-chat-icon-btn svg { width: 16px; height: 16px; }
/* On-red variant of the app focus ring (2px accent, offset) — a light ring so it
   stays visible against the red header, mirroring the header's white-on-red hover. */
.help-chat-icon-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.9); outline-offset: 1px; }

/* Messages: same 16px gutter as header/form. margin-top:auto on the first child
   anchors a short conversation to the BOTTOM (no dead space above the input); once
   the log overflows, the auto margin collapses and normal scrolling resumes — the
   robust CSS-only chat-anchor pattern (no cutoff, unlike justify-content:flex-end). */
.help-chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.help-chat-messages > :first-child { margin-top: auto; }
/* ── Chat bubbles: user right / assistant left. Radius 8px ← .feedback-chat-msg
   (the app's existing chat bubble) / .card; padding 10px 14px ← .field input. The
   tail corner (3px) points the bubble at its sender. */
.help-chat-msg {
  max-width: 85%; padding: 10px 14px; border-radius: 8px;
  font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: anywhere;
}
.help-chat-msg-user { align-self: flex-end; background: var(--red-light); color: var(--text-strong); border-bottom-right-radius: 3px; }
.help-chat-msg-bot  { align-self: flex-start; background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.help-chat-msg-error { align-self: flex-start; background: var(--danger-light); color: var(--danger-text); border: 1px solid var(--danger-border); }
.help-chat-typing { color: var(--text-light); font-style: italic; }
/* Once an answer is rendered from Markdown it contains block elements, so it must
   NOT preserve the source whitespace (pre-wrap) — the blocks handle spacing. */
.help-chat-msg.is-rendered { white-space: normal; }
.help-chat-msg-bot p { margin: 0 0 8px; }
.help-chat-msg-bot p:last-child { margin-bottom: 0; }
.help-chat-msg-bot ul { margin: 6px 0; padding-left: 18px; }
.help-chat-msg-bot li { margin: 2px 0; }
.help-chat-msg-bot li::marker { color: var(--red); }
.help-chat-msg strong { font-weight: 600; }
.help-chat-msg code {
  background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
}
[data-theme="dark"] .help-chat-msg code { background: rgba(255, 255, 255, 0.12); }
/* A subtle pulsing caret trailing the answer while it is still streaming in. */
.help-chat-streaming::after {
  content: ''; display: inline-block; vertical-align: text-bottom;
  width: 7px; height: 15px; margin-left: 3px; border-radius: 1px;
  background: var(--text-muted);
  animation: helpChatCaret 1s steps(2, start) infinite;
}
@keyframes helpChatCaret { 0%, 100% { opacity: 0.15; } 50% { opacity: 0.9; } }

/* ── Greeting / start screen: a short assistant bubble + clickable suggestion chips.
   Chip radius 20px + font 11px ← .badge / .status-badge (the app's pill badges, incl.
   the upload PDF/DOCX/EML file-type badges); padding is a touch larger (6px 12px) so
   the chips stay comfortable tap targets. */
.help-chat-greeting { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.help-chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.help-chat-chip {
  padding: 6px 12px; border: 1px solid var(--border-strong); border-radius: 20px;
  background: var(--surface); color: var(--text); font-size: 11px; font-weight: 600; font-family: inherit;
  line-height: 1.3; text-align: left; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.help-chat-chip:hover { background: var(--red-light); border-color: var(--red); color: var(--red-text); }
.help-chat-chip:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* Input area — same 16px gutter as header/messages; 14px vertical is on the app scale. */
.help-chat-form {
  flex-shrink: 0;
  border-top: 1px solid var(--border); padding: 14px 16px; background: var(--surface);
}
.help-chat-input-row { display: flex; align-items: flex-end; gap: 10px; }
/* Input radius 4px + border-color-only focus ← .field input / .picker-field input
   (every text field in the app). The previous 10px radius + box-shadow ring were
   bespoke — no other app input uses them — so both are dropped for consistency. */
.help-chat-input {
  flex: 1; resize: none; min-height: 40px; max-height: 120px;
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--text); font-size: 13.5px; font-family: inherit; line-height: 1.4;
  transition: border-color 0.15s; outline: none;
}
.help-chat-input:focus { border-color: var(--red); }
/* Send button radius 4px ← .btn-user-menu / modal action buttons (the app's solid
   red buttons). Focus ring = the app button pattern (2px accent, offset 2px). */
.help-chat-send {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; border-radius: 4px;
  background: var(--red); color: #fff; cursor: pointer;
  transition: background 0.12s;
}
.help-chat-send:hover:not(:disabled) { background: var(--red-dark); }
.help-chat-send:disabled { opacity: 0.45; cursor: not-allowed; }
.help-chat-send:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.help-chat-send svg { width: 17px; height: 17px; }
/* Footer row under the input: the privacy note is a de-emphasised caption here, next
   to the counter. Both at 11px ← .pilot-tag (the app's smallest type step). */
.help-chat-form-foot {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-top: 8px;
}
.help-chat-note-inline { font-size: 11px; line-height: 1.35; color: var(--text-light); }
.help-chat-counter { font-size: 11px; color: var(--text-light); text-align: right; flex-shrink: 0; }
.help-chat-counter.is-limit { color: var(--danger-text); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .help-chat-fab { transition: none; }
  .help-chat-fab:hover { transform: none; }
  .help-chat-streaming::after { animation: none; opacity: 0.6; }
  .help-chat-backdrop { transition: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE & TABLET SUPPORT
   ───────────────────────────────────────────────────────────────────────────────
   The app was originally desktop-only. These rules add clean phone/tablet layouts
   WITHOUT touching the desktop design: pure @media WIDTH detection (no device / UA
   sniffing), and every rule lives below a breakpoint, so at normal window widths
   nothing here applies and the desktop layout is byte-for-byte unchanged.

   Breakpoint convention (used consistently across shared.css / admin.css / pages):
     • tablet-and-below : max-width 1024px   (phones + tablets, portrait & landscape)
     • mobile           : max-width 480px    (phones)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Phase 1 — never let a stray wide element scroll the WHOLE page sideways.
   overflow-x: clip (not hidden) is used where supported so it does NOT create a
   scroll container that would break the sticky topbar; hidden is the fallback.
   Targeted horizontal scrolling INSIDE a component (.table-wrap, .usage-chart)
   stays allowed — those set their own overflow-x: auto. */
html { max-width: 100%; }
body { max-width: 100%; overflow-x: hidden; }
@supports (overflow-x: clip) { body { overflow-x: clip; } }
img, svg, video, canvas { max-width: 100%; }

/* ── Phase 2 — Hamburger toggle for the main topbar nav.
   Injected by shared.js (mountMobileNav) into .topbar-right, once a session is
   active. Hidden on desktop; revealed at tablet width. Sized like .theme-toggle. */
.nav-toggle {
  display: none;               /* desktop: the inline nav is shown instead */
  align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: none; border: 1px solid var(--border-strong); border-radius: 6px;
  cursor: pointer; color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-toggle:hover { background: var(--bg-soft); color: var(--text-strong); }
.nav-toggle svg { width: 20px; height: 20px; display: block; }
.nav-toggle .icon-close { display: none; }
.nav-toggle.open .icon-menu { display: none; }
.nav-toggle.open .icon-close { display: block; }

@media (max-width: 1024px) {
  /* Keep logo · hamburger · theme · PILOT · user-menu on ONE tidy row. */
  .topbar-inner { padding: 0 16px; }
  .logo-wrap { margin-right: 12px; }
  .topbar-nav { gap: 0; }
  .topbar-right { gap: 10px; }
  .nav-toggle { display: inline-flex; }
  /* A long e-mail must not blow out the row — cap it with an ellipsis. */
  #topbarEmail {
    display: inline-block; max-width: 34vw;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
  }

  /* The app nav collapses into a full-width dropdown UNDER the topbar. !important
     is required: the pages set an inline display:flex/none on #mainNav, and only
     !important in a stylesheet beats an inline style. */
  .topbar-nav {
    display: none !important;
    position: fixed; top: 60px; left: 0; right: 0; z-index: 150;
    flex-direction: column; align-items: stretch;
    background: var(--surface);
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    box-shadow: 0 10px 28px var(--shadow-strong);
    padding: 6px 0;
    max-height: calc(100vh - 60px); overflow-y: auto;
  }
  .topbar-nav.mobile-open { display: flex !important; }
  .nav-link {
    padding: 0 20px; min-height: 48px;         /* comfortable touch row */
    font-size: 15px;
    border-bottom: none; border-left: 3px solid transparent;
  }
  .nav-link:hover { background: var(--bg-soft); }
  .nav-link.active {
    border-bottom-color: transparent;
    border-left-color: var(--red);
    background: var(--red-light);
  }

  /* Phase 4 — touch targets: bump the topbar icon controls to ≥44px. */
  .theme-toggle, .nav-toggle { width: 44px; height: 44px; }
}

/* ── Phase 4 — touch targets on touch-primary devices (no fine pointer). Applies
   regardless of width, so a large touchscreen also gets comfortable hit areas. */
@media (hover: none) and (pointer: coarse) {
  .icon-btn { min-width: 40px; min-height: 40px; }
  .btn-user-menu, .user-menu-item { min-height: 40px; }
}

/* ── Phase 2.4 — Help-chat panel goes (near-)fullscreen on phones so the answer
   area is comfortable to read/type in; the floating button (top-right hamburger is
   far away) never collides with it. Same visual language as the desktop panel. */
@media (max-width: 480px) {
  .help-chat-panel {
    right: 8px; left: 8px; bottom: 8px;
    width: auto; height: min(80vh, calc(100vh - 76px));
    border-radius: 10px;
  }
  .help-chat-fab { right: 14px; bottom: 14px; padding: 12px 18px; }
  /* On phones the panel already fills most of the screen, so a dimmed page behind it
     is emphasised further — keep it, but a touch darker reads better against a
     (near-)fullscreen sheet. */
  .help-chat-backdrop { background: rgba(0, 0, 0, 0.28); }
}
