/* =========================================================================
   Woodlam Agent Operations Console — Design System
   Mint / Teal HR-SaaS direction · soft cards · high whitespace · calm + premium
   Vanilla CSS, zero build step. Tokens derived from design.md.
   ========================================================================= */

:root {
  /* ---- Brand ---- */
  --primary: #2fc5a5;
  --primary-dark: #087e6b;
  --primary-light: #ddf7ec;
  --primary-tint: #f0faf6;
  /* Accent FOREGROUND (links, chips, tags, pills). Same as primary-dark in light,
     but flips light in dark so it stays readable on the dark primary tint.
     Use --accent for text/icons; keep --primary-dark for fills/gradients. */
  --accent: #087e6b;

  /* ---- Surfaces ---- */
  --bg: #e7f2ee;
  --bg-deep: #dcebe5;
  --surface: #f8fbfa;
  --white: #ffffff;
  --border: #e5efea;
  --border-strong: #d4e6df;
  --sidebar-bg: #e4eee9;
  --sidebar-border: #dce8e3;

  /* ---- Text ---- */
  /* Greys tuned to clear WCAG AA (>=4.5:1) for normal text on white/surface
     while preserving the three-level hierarchy (main > muted > soft). */
  --text-main: #1d2b2a;
  --text-muted: #586a65;
  /* Nudged from #647570: that value cleared AA on white/surface only and dipped
     below 4.5:1 on the mint canvas tones (--bg 4.24, --bg-deep 3.95, --border
     4.14, --neutral-bg 4.28). #5d6e69 clears bg/surface/primary-tint/border/
     neutral-bg while keeping the soft<muted hierarchy gap. (WCAG 1.4.3) */
  --text-soft: #5d6e69;
  --text-inverse: #f3fbf8;

  /* ---- Status ---- */
  --success: #23b26d;
  --success-bg: #ddf7ec;
  --success-text: #06705e;
  --warning: #f4b740;
  --warning-bg: #fff5d9;
  --warning-text: #8a6200;
  --danger: #ef5b5b;
  --danger-bg: #ffe4e4;
  --danger-text: #b62d2d;
  --info: #3b9ed6;
  --info-bg: #e1f0f9;
  --info-text: #1d6a96;
  --neutral-bg: #eef1f0;
  --neutral-text: #6e7f7b;

  /* ---- Mobile glass chrome (bottom nav + sticky top bar). Token-ised so they
     follow the theme; only referenced by the mobile rules, so desktop is unaffected. */
  --nav-glass-bg: rgba(255, 255, 255, 0.88);
  --nav-glass-border: rgba(212, 230, 223, 0.82);
  --topbar-glass-bg: rgba(231, 242, 238, 0.88);

  /* ---- Chart palette ---- */
  --chart-primary: #2fc5a5;
  --chart-dark: #087e6b;
  --chart-soft: #bdefd9;
  --chart-pale: #e7f8da;
  --chart-yellow: #f3d98b;
  --chart-track: #eaf4ef;

  /* ---- Radius ---- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-card: 12px;
  --radius-xl: 16px;
  --radius-panel: 14px;
  --radius-full: 999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 2px 8px rgba(20, 80, 70, 0.05);
  --shadow-card: 0 4px 14px rgba(20, 80, 70, 0.05);
  --shadow-floating: 0 14px 44px rgba(20, 80, 70, 0.12);
  /* Button drop-shadows follow the active theme; scoped views can tune them
     without changing the shared green brand language. */
  --btn-shadow: 0 6px 14px rgba(47, 197, 165, 0.24);
  --btn-shadow-hover: 0 10px 22px rgba(47, 197, 165, 0.32);
  /* Perceptible focus halo: white spacer + solid 2px primary ring reads >=3:1
     on any surface (WCAG 2.4.11). Per-theme overrides flip --primary/--white. */
  --ring: 0 0 0 2px var(--white), 0 0 0 4px var(--primary);

  /* ---- Layout ---- */
  --sidebar-w: 268px;
  --sidebar-collapsed-w: 76px;
  --rightpanel-w: 332px;
  --header-h: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --font-sans: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent 300ms tap delay and remove grey tap highlight on touch devices */
button,
a,
.data-card,
.metric-card,
.lm-toggle-switch,
.ac-tab,
.icon-btn,
.nav button,
.ac-icon,
.ac-close,
.ac-expand,
.lm-toggle input,
.t-actions .btn,
.modal-close,
.lm-switch-slider,
.file-row button,
.run-item summary,
.lm-toggle-switch {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 88% -8%, #f1fbf6 0, rgba(241, 251, 246, 0) 60%),
    radial-gradient(900px 600px at -6% 4%, #eef7f1 0, rgba(238, 247, 241, 0) 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: 0;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
a {
  color: inherit;
  text-decoration: none;
}
::selection {
  background: var(--primary-light);
  color: var(--accent);
}

/* ---- Skip link (a11y) ---- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-dark);
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  font-weight: 700;
  font-size: 14px;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top 0.2s var(--ease);
}
.skip-link:focus {
  top: 0;
  outline: none;
  box-shadow: var(--ring);
}

/* Screen-reader-only utility: present in the accessibility tree (e.g. the route
   announcer live region) but visually hidden, without display:none which would
   stop screen readers from reading it. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Focus-visible (a11y) ---- */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.nav button:focus-visible {
  box-shadow: inset var(--ring);
}
.ac-tab:focus-visible {
  box-shadow: var(--ring);
}

/* ---- Forced colors / Windows High Contrast (a11y) ----
   Box-shadows are dropped in forced-colors mode, so restore a real outline
   so keyboard focus stays visible (WCAG 2.4.7 / 2.4.11). */
@media (forced-colors: active) {
  :focus-visible,
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible,
  .nav button:focus-visible,
  .ac-tab:focus-visible,
  .skip-link:focus {
    outline: 2px solid CanvasText;
    outline-offset: 2px;
  }
}

/* ---- Touch targets (mobile a11y) ---- */
.icon-btn,
.nav button,
.ac-icon,
.ac-close,
.ac-expand,
.lm-toggle input,
.t-actions .btn,
.modal-close,
.lm-switch-slider,
.file-row button,
.run-item summary,
.lm-toggle-switch {
  min-width: 44px;
  min-height: 44px;
}
/* Increase switch hit area */
.lm-toggle-switch {
  position: relative;
}
.lm-toggle-switch::before {
  content: '';
  position: absolute;
  inset: -12px;
}

/* ---- Scrollbar ---- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-soft);
  background-clip: padding-box;
}

/* =========================================================================
   Skeleton screens (loading placeholders)
   ========================================================================= */
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-deep) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
}
.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 60%; }
.skeleton-text.long { width: 85%; }
.skeleton-title {
  height: 18px;
  width: 50%;
  margin-bottom: 12px;
}
.skeleton-card {
  padding: 18px;
  border-radius: var(--radius-card);
  background: var(--white);
  border: 1px solid var(--border);
}
.skeleton-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* =========================================================================
   Form validation & feedback
   ========================================================================= */
.field-error {
  color: var(--danger-text);
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-error::before {
  content: "⚠";
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 91, 91, 0.18);
}
input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 91, 91, 0.25);
}
/* The asterisk must ride on the caption, not become its own grid row.
   Required fields wrap their caption in a <span>; mark that span. */
label.field.required > span:first-child::after {
  content: " *";
  color: var(--danger);
  font-weight: 700;
}

/* =========================================================================
   Button loading state
   ========================================================================= */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.btn.secondary.btn-loading::after,
.btn.ghost.btn-loading::after {
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* =========================================================================
   Page transitions
   ========================================================================= */
.page-transition {
  animation: page-in 0.35s var(--ease) both;
}
@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    /* Must end at `none`: a retained translateY(0) (fill-mode both) makes this
       section the containing block for position:fixed descendants, so in-view
       modal overlays size to the section instead of the viewport and the
       mobile bottom nav paints over them. */
    transform: none;
  }
}

/* =========================================================================
   Toast improvements
   ========================================================================= */
.toast-stack {
  position: fixed;
  right: 20px;
  /* Clear the "Ask an agent" launcher parked in the same corner, so toast
     action buttons (e.g. Undo) stay clickable. */
  bottom: 88px;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}
@media (max-width: 640px) {
  .toast-stack {
    left: 14px;
    right: 14px;
    /* Above the bottom nav (~80px) AND the agent launcher parked at 88px. */
    bottom: calc(158px + var(--safe-bottom));
    max-width: none;
  }
}

/* =========================================================================
   Modal transitions
   ========================================================================= */
.modal-overlay {
  opacity: 0;
  animation: modal-fade-in 0.2s var(--ease) forwards;
}
.modal-overlay.closing {
  animation: modal-fade-out 0.2s var(--ease) forwards;
}
.modal {
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  animation: modal-scale-in 0.25s var(--ease) 0.05s forwards;
}
@keyframes modal-fade-in {
  to { opacity: 1; }
}
@keyframes modal-fade-out {
  to { opacity: 0; }
}
@keyframes modal-scale-in {
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* =========================================================================
   Empty state improvements
   ========================================================================= */
.empty-action {
  margin-top: 16px;
}

/* =========================================================================
   Boot loader
   ========================================================================= */
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.boot-orbit {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 420px at 30% 30%, rgba(47, 197, 165, 0.16), transparent 70%),
    radial-gradient(520px 520px at 72% 70%, rgba(8, 126, 107, 0.12), transparent 70%);
  animation: float 9s var(--ease) infinite alternate;
}
@keyframes float {
  to {
    transform: translate3d(0, -18px, 0) scale(1.04);
  }
}
.loader-card {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  padding: 40px 44px;
  width: min(420px, calc(100vw - 32px));
  text-align: center;
}
.loader-card h1 {
  font-size: 21px;
  margin: 18px 0 6px;
  letter-spacing: 0;
}
.loader-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
}
.boot-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--chart-track);
  overflow: hidden;
}
.boot-bar span {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  animation: indeterminate 1.4s var(--ease) infinite;
}
@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* ---- Brand mark ---- */
.mark {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0;
  background: linear-gradient(150deg, #34d6b3 0%, var(--primary) 42%, var(--primary-dark) 100%);
  box-shadow: 0 8px 20px rgba(8, 126, 107, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* =========================================================================
   Login
   ========================================================================= */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 1.1fr;
  overflow: hidden;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  animation: rise 0.6s var(--ease) both;
}
.login-hero {
  position: relative;
  padding: 52px 48px;
  color: var(--text-inverse);
  background:
    radial-gradient(640px 360px at 110% -10%, rgba(52, 214, 179, 0.55), transparent 60%),
    linear-gradient(155deg, #0b5f52 0%, #087e6b 48%, #0a4f44 100%);
  overflow: hidden;
}
.login-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, transparent, #000 40%);
  opacity: 0.6;
}
.login-hero > * {
  position: relative;
  z-index: 1;
}
.login-hero .mark {
  margin: 0;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: none;
}
.mark.logo-mark {
  background: #181c1a url("/icons/woodlam-logo.png") center / cover no-repeat;
  color: transparent;
  font-size: 0;
  line-height: 0;
  overflow: hidden;
}
.login-hero h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.02;
  margin: 26px 0 16px;
  letter-spacing: 0;
}
.login-hero p {
  color: rgba(243, 251, 248, 0.82);
  font-size: 15px;
  line-height: 1.65;
  max-width: 46ch;
}
.login-hero .hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}
.hero-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: rgba(243, 251, 248, 0.92);
}
/* Agent stat-chip: light-surface variant for .hero-chip reused on white .data-card
   (the rgba-white hero styling above is for the dark login hero only and is
   invisible on light cards). Dark teal on light mint clears WCAG AA >=4.5:1. */
.data-card .hero-chip {
  background: var(--primary-light);
  border-color: transparent;
  color: var(--accent);
}
.login-form {
  padding: 48px 44px;
}
.login-form h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 0;
}
.login-form > p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}
.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}
.demo-user {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 14px 13px;
  text-align: left;
  transition: all 0.18s var(--ease);
  display: flex;
  gap: 11px;
  align-items: center;
}
.demo-user:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: var(--white);
  box-shadow: var(--shadow-card);
}
.demo-user .avatar {
  flex: 0 0 auto;
}
.demo-user b {
  display: block;
  font-size: 14px;
  font-weight: 700;
}
.demo-user span {
  color: var(--text-muted);
  font-size: 12px;
}
.login-pass {
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.login-pass code {
  font-family: var(--font-mono);
  background: var(--primary-light);
  color: var(--accent);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}

/* =========================================================================
   App shell — three-zone layout
   ========================================================================= */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  contain: layout paint;
  transition: grid-template-columns 0.2s var(--ease);
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 88px;
  padding: 18px 6px 20px;
}
.brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
}
.brand .mark {
  margin: 0;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 19px;
}
.brand b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}
.brand span {
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 500;
}
.brand-text {
  min-width: 0;
}
.sidebar-collapse {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--white) 72%, transparent);
  box-shadow: var(--shadow-sm);
  transition: background 0.16s var(--ease), color 0.16s var(--ease), transform 0.16s var(--ease);
}
.sidebar-collapse svg {
  width: 17px;
  height: 17px;
  transform: rotate(180deg);
  transition: transform 0.2s var(--ease);
}
.sidebar-collapse:hover {
  color: var(--accent);
  background: var(--primary-tint);
}
.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 4px 12px;
  margin: 6px 0 4px;
}
.nav {
  display: grid;
  gap: 3px;
}
/* Scrollable nav region — long owner/admin navs scroll here instead of
   overflowing the rail; brand stays pinned outside it. */
.nav-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.nav-scroll::-webkit-scrollbar {
  width: 8px;
}
.nav-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
.nav-section + .nav-section {
  margin-top: 2px;
}
/* Section header is a real disclosure button; strip native chrome and reuse the
   .nav-label type styling for the text. */
.nav-section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  cursor: pointer;
}
.nav-section-toggle .nav-label {
  flex: 1 1 auto;
}
.nav-chevron {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-right: 12px;
  color: var(--text-soft);
  opacity: 0.7;
  transition: transform 0.18s var(--ease);
}
@media (min-width: 921px) {
  .sidebar.rail .nav-chevron {
    display: none;
  }
}
/* Collapsed = chevron points right (down-chevron rotated). */
.nav-section.collapsed .nav-chevron {
  transform: rotate(-90deg);
}
.nav button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  gap: 11px;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  position: relative;
  transition: all 0.16s var(--ease);
}
.nav button svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  stroke-width: 1.9;
  opacity: 0.78;
}
.nav button:hover {
  background: var(--primary-tint);
  color: var(--accent);
}
.nav button:hover svg {
  opacity: 1;
}
.nav button.active {
  background: var(--primary-light);
  color: var(--accent);
  box-shadow: none;
}
.nav button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: var(--radius-full);
  background: var(--primary);
}
.nav button.active svg {
  opacity: 1;
}
.nav button .nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--danger-bg);
  color: var(--danger-text);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}
.nav button.active .nav-count {
  background: var(--white);
  color: var(--accent);
}

.upsell {
  margin-top: 18px;
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  color: var(--text-inverse);
  background:
    radial-gradient(360px 180px at 120% -20%, rgba(52, 214, 179, 0.6), transparent 60%),
    linear-gradient(160deg, #0b5f52, #087e6b);
  position: relative;
  overflow: hidden;
}
.upsell h4 {
  margin: 0 0 6px;
  font-size: 14px;
  letter-spacing: 0;
}
.upsell p {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(243, 251, 248, 0.82);
}
.upsell .btn {
  width: 100%;
  justify-content: center;
  background: #fff;
  color: var(--primary-dark);
}
.upsell .btn:hover {
  background: #fff;
  filter: brightness(0.97);
}

@media (min-width: 921px) {
  .layout.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-w) 1fr;
  }
  .layout.sidebar-collapsed .sidebar {
    padding-inline: 10px;
  }
  .layout.sidebar-collapsed .brand {
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    min-height: 110px;
    padding: 16px 0 14px;
  }
  .layout.sidebar-collapsed .brand-lockup {
    flex: 0 0 auto;
    justify-content: center;
  }
  .layout.sidebar-collapsed .brand-text,
  .layout.sidebar-collapsed .nav-label,
  .layout.sidebar-collapsed .nav-text,
  .layout.sidebar-collapsed .nav-count {
    display: none;
  }
  .layout.sidebar-collapsed .sidebar-collapse svg {
    transform: rotate(0deg);
  }
  .layout.sidebar-collapsed .nav-scroll {
    padding-top: 2px;
  }
  .layout.sidebar-collapsed .nav-section-toggle {
    display: none;
  }
  .layout.sidebar-collapsed .nav-section + .nav-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid color-mix(in srgb, var(--sidebar-border) 72%, transparent);
  }
  .layout.sidebar-collapsed .nav {
    gap: 6px;
  }
  .layout.sidebar-collapsed .nav button {
    justify-content: center;
    gap: 0;
    min-height: 44px;
    padding: 11px;
  }
  .layout.sidebar-collapsed .nav button.active::before {
    left: -4px;
    top: 10px;
    bottom: 10px;
  }
  .layout.sidebar-collapsed .nav button svg {
    margin: 0;
  }
}
/* ---- Main column ---- */
.content {
  min-width: 0;
  /* Tail padding clears the fixed "Ask an agent" launcher (bottom: 22px + 48px
     pill) so it never covers the last interactive element on a page. */
  padding: 22px 26px 96px;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  min-height: var(--header-h);
}
.topbar .crumbs {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 5px;
}
.topbar .crumbs svg {
  width: 13px;
  height: 13px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 30px);
  letter-spacing: 0;
  font-weight: 800;
}
.topbar p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 13px;
  width: 17px;
  height: 17px;
  color: var(--text-soft);
  pointer-events: none;
}
.search-box input {
  width: 240px;
  height: 42px;
  padding: 0 14px 0 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 14px;
  transition: all 0.16s var(--ease);
}
.search-box input::placeholder {
  color: var(--text-soft);
}
.search-box.is-searching::after {
  content: "";
  position: absolute;
  right: 13px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

/* ---- Global search results dropdown (anchored under the topbar search box) ---- */
.gs-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 95;
  width: 380px;
  max-width: calc(100vw - 24px);
  max-height: min(70vh, 460px);
  overflow-y: auto;
  padding: 6px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-floating);
  transform-origin: top right;
  animation: um-pop 0.14s var(--ease);
}
.gs-results[hidden] {
  display: none;
}
.gs-group {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  padding: 9px 10px 4px;
}
.gs-group:first-child {
  padding-top: 4px;
}
.gs-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.gs-item .gs-ic {
  width: 18px;
  height: 18px;
  color: var(--text-soft);
  flex: none;
}
.gs-text {
  min-width: 0;
  flex: 1;
  line-height: 1.3;
}
.gs-title {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gs-sub {
  display: block;
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gs-item:hover,
.gs-item.active {
  background: var(--primary-tint);
}
.gs-item.active .gs-ic {
  color: var(--primary);
}
.gs-empty {
  padding: 18px 12px;
  font-size: 13px;
  color: var(--text-soft);
  text-align: center;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--white);
  padding: 5px 10px 5px 6px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease), background 0.16s var(--ease);
}
.user-pill:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-card);
}
.user-pill:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.user-pill .um-caret {
  width: 15px;
  height: 15px;
  color: var(--text-soft);
  transition: transform 0.18s var(--ease);
}
.user-pill[aria-expanded="true"] .um-caret {
  transform: rotate(180deg);
}
.user-pill .meta {
  line-height: 1.2;
}
.user-pill .meta b {
  font-size: 13px;
  display: block; /* stack name above timezone (was running together) */
}
.user-pill .meta span {
  font-size: 11px;
  color: var(--text-soft);
  display: block;
}

/* ---- Profile dropdown (anchored popover off the user pill) ---- */
.user-menu {
  position: relative;
}
.user-menu-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 90;
  width: 264px;
  max-width: calc(100vw - 24px);
  padding: 6px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-floating);
  display: flex;
  flex-direction: column;
  gap: 1px;
  transform-origin: top right;
  animation: um-pop 0.14s var(--ease);
}
.user-menu-pop[hidden] {
  display: none;
}
@keyframes um-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.um-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 10px;
}
.um-head .meta {
  line-height: 1.25;
  min-width: 0;
}
.um-head .meta b {
  font-size: 13px;
  display: block;
  color: var(--text-main);
}
.um-head .meta span {
  font-size: 11px;
  color: var(--text-soft);
  display: block;
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.um-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}
.um-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s var(--ease);
}
.um-item svg.ic {
  width: 18px;
  height: 18px;
  color: var(--text-soft);
  flex: none;
}
.um-item > span:first-of-type {
  flex: 1;
}
.um-item:hover,
.um-item:focus-visible {
  outline: none;
  background: var(--primary-tint);
}
.um-item.danger {
  color: var(--danger-text);
}
.um-item.danger svg.ic {
  color: var(--danger-text);
}
.um-item.danger:hover,
.um-item.danger:focus-visible {
  background: var(--danger-bg);
}
/* Dark-mode toggle row: a pill switch on the trailing edge. */
.um-switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 0.16s var(--ease);
}
.um-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease);
}
.um-toggle[aria-checked="true"] .um-switch {
  background: var(--primary);
}
.um-toggle[aria-checked="true"] .um-switch::after {
  transform: translateX(14px);
}

/* ---- Help & Support page ---- */
.help-page {
  display: grid;
  gap: 18px;
}
.help-page .panel {
  overflow: hidden;
}
.help-page .panel-head {
  align-items: flex-start;
}
.help-page .panel-head h3 {
  font-weight: 800;
}
.help-section-note {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.help-page a:not(.btn):hover {
  color: var(--accent);
}
.help-page .btn {
  white-space: nowrap;
}
.help-page .btn.secondary {
  width: fit-content;
}
.help-page .btn.secondary svg {
  width: 15px;
  height: 15px;
}
.help-page .empty-state {
  margin: 0;
}
.help-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 22px;
  align-items: stretch;
  padding: clamp(22px, 3vw, 34px);
  background:
    radial-gradient(520px 240px at 8% 0%, var(--primary-tint), transparent 72%),
    linear-gradient(135deg, var(--white), var(--surface));
}
.help-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
.help-kicker svg {
  width: 15px;
  height: 15px;
}
.help-hero h2 {
  max-width: 760px;
  margin: 18px 0 10px;
  font-size: clamp(30px, 4.2vw, 52px);
  line-height: 0.98;
  letter-spacing: -0.04em;
  text-wrap: balance;
}
.help-hero p {
  max-width: 64ch;
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.65;
}
.help-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}
/* Static facts, not controls — no chip/button affordance. */
.help-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
}
.help-chip + .help-chip { margin-left: 14px; }
.help-chip svg {
  width: 14px;
  height: 14px;
  color: var(--accent);
}
.help-hero-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--primary-tint);
  border: 1px solid var(--primary-light);
}
.help-hero-card b {
  font-size: 14px;
}
.help-hero-card ol {
  margin: 0;
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}
.help-hero-card li + li {
  margin-top: 8px;
}
.help-quick-grid,
.help-troubles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.help-action-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 136px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: inherit;
  transition: transform 0.16s var(--ease), border-color 0.16s var(--ease), background 0.16s var(--ease);
}
.help-action-card:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--white);
}
.help-action-card b,
.help-troubles b {
  display: block;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.35;
}
.help-action-card small {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.help-action-icon {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  color: var(--accent);
}
.help-areas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
/* Grouped help areas mirror the sidebar IA (Work / Intelligence / Admin). */
.help-area-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.help-area-group > .nav-label {
  padding: 0 2px;
  margin: 0 0 8px;
}
.help-area {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-height: 104px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: transform 0.16s var(--ease), border-color 0.16s var(--ease), background 0.16s var(--ease);
}
.help-area:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--white);
}
.help-area svg.ic {
  flex: none;
  margin-top: 1px;
  color: var(--accent);
}
.help-area b {
  display: block;
  font-size: 14px;
  color: var(--text-main);
}
.help-area .muted {
  font-size: 12px;
  line-height: 1.55;
}
.help-shortcut-list.help-shortcut-list > div {
  align-items: baseline;
}
.help-shortcut-list dt {
  min-width: 64px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.help-shortcut-list dd {
  text-align: right;
}
.help-flow {
  counter-reset: help-step;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.help-flow li {
  counter-increment: help-step;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.help-flow li::before {
  content: counter(help-step);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
}
.help-flow b {
  grid-column: 2;
  display: block;
  color: var(--text-main);
  font-size: 13.5px;
}
.help-flow span {
  grid-column: 2;
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.help-troubles {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.help-troubles article {
  padding: 15px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}
.help-troubles p {
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.help-contact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 18px;
  align-items: start;
}
.help-contact-main p {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.6;
}
.help-contact-main a:not(.btn) {
  color: var(--accent);
  font-weight: 800;
}
.help-support-card {
  padding: 16px;
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-lg);
  background: var(--primary-tint);
}
.help-support-card h4 {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.35;
}
.help-support-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.help-support-card li + li {
  margin-top: 7px;
}
@media (max-width: 1100px) {
  .help-quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 760px) {
  .help-hero,
  .help-contact {
    grid-template-columns: 1fr;
  }
  .help-quick-grid,
  .help-troubles {
    grid-template-columns: 1fr;
  }
  .help-hero {
    padding: 20px;
  }
  .help-hero h2 {
    font-size: clamp(28px, 10vw, 40px);
  }
  .help-chip-row {
    flex-direction: column;
  }
  .help-chip {
    width: 100%;
  }
  .help-shortcut-list.help-shortcut-list > div {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
  }
}

/* Tablet / small-laptop band: condense the dense topbar action cluster so it
   keeps the calm, premium spacing instead of crowding. Narrow global search,
   tighten the gap, and collapse the user-pill to just its avatar. Bounded to
   >=921px, where the sidebar rail still shows the user's name (so no identity
   is lost — the pill also carries a title tooltip). Below 921px the bottom-nav
   layout takes over and the <=640px block fully hides the pill. */
@media (min-width: 921px) and (max-width: 1100px) {
  .topbar-actions {
    gap: 8px;
  }
  .search-box input {
    width: 168px;
  }
  .user-pill {
    padding: 4px;
  }
  .user-pill .meta,
  .user-pill .um-caret {
    display: none;
  }
}

/* ---- Avatars ---- */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
}
/* Contact photo overlays the initials; if it fails to load the delegated error
   listener removes it and the initials show through. */
.avatar .avatar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}
.avatar.sm {
  width: 30px;
  height: 30px;
  font-size: 12px;
}
.avatar.lg {
  width: 76px;
  height: 76px;
  font-size: 28px;
  border-radius: 24px;
}
.avatar.a1 { background: linear-gradient(140deg, #34d6b3, #087e6b); }
.avatar.a2 { background: linear-gradient(140deg, #6fd0e8, #2b7fa8); }
.avatar.a3 { background: linear-gradient(140deg, #f6c66b, #d68a1f); }
.avatar.a4 { background: linear-gradient(140deg, #e98aa0, #c0455f); }
.avatar.a5 { background: linear-gradient(140deg, #9bc36b, #4f8a2f); }
.avatar.a6 { background: linear-gradient(140deg, #a99af0, #5e4cc0); }

/* ---- Notification dropdown (anchored popover off the topbar bell) ---- */
.notif-menu {
  position: relative;
}
.notif-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 90;
  width: 340px;
  max-width: calc(100vw - 24px);
  padding: 6px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-floating);
  transform-origin: top right;
  animation: um-pop 0.14s var(--ease);
}
.notif-pop[hidden] {
  display: none;
}
.notif-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 6px;
}
.notif-head b {
  font-size: 13px;
  color: var(--text-main);
}
.notif-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
.notif-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 60vh;
  overflow-y: auto;
}
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s var(--ease);
}
.notif-item:hover,
.notif-item:focus-visible {
  outline: none;
  background: var(--primary-tint);
}
.notif-ic {
  width: 30px;
  height: 30px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--primary-tint);
  color: var(--accent);
}
.notif-ic svg {
  width: 16px;
  height: 16px;
}
.notif-ic.incident {
  background: var(--danger-bg);
  color: var(--danger-text);
}
.notif-text {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}
.notif-text b {
  display: block;
  font-size: 13px;
  color: var(--text-main);
}
.notif-text span {
  display: block;
  font-size: 12px;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notif-item time {
  flex: none;
  font-size: 11px;
  color: var(--text-soft);
}
.notif-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 22px 16px;
  color: var(--text-soft);
}
.notif-empty svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}
.notif-empty b {
  color: var(--text-main);
  font-size: 13px;
}
.notif-empty span {
  font-size: 12px;
}
.notif-foot {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 4px;
}

/* ---- Icon buttons ---- */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--white);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: all 0.16s var(--ease);
  position: relative;
  flex: 0 0 auto;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--primary);
  background: var(--primary-tint);
}
.icon-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--white);
}

/* =========================================================================
   Grids & cards
   ========================================================================= */
.grid {
  display: grid;
  gap: 18px;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rightpanel-w);
  gap: 18px;
  align-items: start;
}
.page-grid > *,
.split > *,
.grid > *,
aside.rail > * {
  min-width: 0;
}
.split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

.panel,
.card,
.metric-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: none;
  min-width: 0;
}
.panel {
  padding: 20px;
}
.panel > h2,
.panel > h3 {
  margin-top: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
}
.panel-head .sub {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}
.panel-head .spacer {
  flex: 1;
}
.panel-head svg.pi {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex: 0 0 auto;
  stroke-width: 2;
}
h2 {
  font-size: 18px;
  letter-spacing: 0;
}
h3 {
  font-size: 16px;
  letter-spacing: 0;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Above the FAB stack (1180), bottom nav (1000) and bottom-sheet scrim (1390). */
  z-index: 1500;
  padding: 24px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-floating);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 0;
}
.modal-header h3 {
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-soft);
  border-radius: 6px;
}
.modal-close:hover {
  background: var(--surface);
  color: var(--text-main);
}
.modal-body {
  padding: 16px 22px 22px;
}

/* ---- Stat / metric cards ---- */
.metric-card {
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 118px;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease);
}
.metric-card:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.metric-card .label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}
.metric-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary-light);
  color: var(--accent);
  flex: 0 0 auto;
}
.metric-icon svg {
  width: 19px;
  height: 19px;
}
.metric-icon.amber { background: var(--warning-bg); color: var(--warning-text); }
.metric-icon.red { background: var(--danger-bg); color: var(--danger-text); }
.metric-icon.blue { background: var(--info-bg); color: var(--info-text); }
.metric-card .value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.metric-card .value.sm {
  font-size: 24px;
}
.metric-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-soft);
}
.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}
.trend svg {
  width: 13px;
  height: 13px;
}
.trend.up { color: var(--success-text); background: var(--success-bg); }
.trend.down { color: var(--danger-text); background: var(--danger-bg); }
.trend.flat { color: var(--text-muted); background: var(--neutral-bg); }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  /* Filled primary uses the accessible brand teal (--primary-dark #087e6b):
     white text on it clears WCAG AA at ~5:1, whereas white on the bright mint
     --primary (#2fc5a5) is only ~2.2:1. Bright mint is reserved for decoration
     (rings, chart fills, nav tints), never as a background under white text. */
  background: var(--primary-dark);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0;
  transition: all 0.16s var(--ease);
  box-shadow: var(--btn-shadow);
}
/* Base size for all icon() SVGs. Single-class selector keeps this
   low-specificity so any context-specific `... svg` rule overrides it;
   it only fills in for icons in unstyled contexts (e.g. inline notes). */
.ic {
  width: 16px;
  height: 16px;
  flex: none;
  vertical-align: -0.18em;
}
.btn svg {
  width: 16px;
  height: 16px;
}
.btn:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
  box-shadow: var(--btn-shadow-hover);
}
.btn:active {
  transform: translateY(0);
}
.btn.secondary {
  background: var(--primary-light);
  color: var(--accent);
  box-shadow: none;
}
.btn.secondary:hover {
  background: color-mix(in srgb, var(--primary-light) 86%, var(--primary));
}
.btn.ghost {
  background: var(--white);
  color: var(--text-main);
  border-color: var(--border);
  box-shadow: none;
}
.btn.ghost:hover {
  border-color: var(--primary);
  color: var(--accent);
  background: var(--primary-tint);
}
.btn.danger {
  background: var(--danger);
  box-shadow: 0 6px 14px rgba(239, 91, 91, 0.24);
}
/* Primary-fill semantics: the .btn is the local / navigational primary
   (e.g. + New lead, Run workflow, Ask an agent). .btn.green is the COMMIT role
   for actions that submit or fire an external / AI side-effect (Sign in, Send
   inbound, Research, Draft message). Both now share the
   accessible teal fill (white text on bright --success #23b26d was only ~2.9:1);
   the commit role is carried by placement and label, and a slightly warmer
   shadow, rather than an inaccessible brighter green. Pick by meaning, not view. */
.btn.green {
  background: var(--primary-dark);
  box-shadow: 0 6px 14px rgba(8, 126, 107, 0.26);
}
/* The inbox keeps the Woodlam green brand while using a slightly tighter
   workspace shadow recipe. */
body.wa-view {
  --btn-shadow: 0 6px 14px rgba(47, 197, 165, 0.22);
  --btn-shadow-hover: 0 10px 22px rgba(47, 197, 165, 0.30);
}
/* Inbox commit controls use the accessible teal fill so white text clears AA,
   matching the rest of the console (bright mint --primary failed at ~2.2:1). */
body.wa-view .btn.green {
  background: var(--primary-dark);
  box-shadow: var(--btn-shadow);
}
body.wa-view .btn.secondary:hover {
  background: color-mix(in srgb, var(--primary-light) 86%, var(--primary));
}
.btn.small {
  padding: 7px 11px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.btn.small:hover {
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* =========================================================================
   Inputs
   ========================================================================= */
.input,
input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0 14px;
  height: 42px;
  color: var(--text-main);
  font-size: 14px;
  transition: all 0.16s var(--ease);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-soft);
}
textarea {
  min-height: 92px;
  padding: 11px 14px;
  height: auto;
  resize: vertical;
  line-height: 1.55;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236e7f7b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 36px;
}
.input:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
label.field {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
/* Inline "(optional)" marker inside a field label — quieter than the label. */
.field-opt {
  font-weight: 500;
  color: var(--text-soft);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow {
  flex: 1;
  min-width: 160px;
}
.followup-actions .btn[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--accent);
}
.task-filter-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(5, minmax(132px, 1fr));
  gap: 10px;
  align-items: end;
  margin: 0 0 16px;
}
.task-filter-bar .field {
  min-width: 0;
}
.task-filter-bar .task-search {
  min-width: 180px;
}
@media (max-width: 1180px) {
  .task-filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 720px) {
  .task-filter-bar {
    grid-template-columns: 1fr;
  }
  .task-filter-bar .task-search {
    min-width: 0;
  }
}
/* Leads filter bar packs PIC / Source / Sort (search lives in the page toolbar),
   so it uses a 3-up grid instead of the 6-up task/incident layout. */
.lead-filter-bar {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}
@media (max-width: 1180px) {
  .lead-filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 720px) {
  .lead-filter-bar {
    grid-template-columns: 1fr;
  }
}
/* Past-due tasks: tint the Due cell red and tag it so lateness is legible in
   the time column itself, not only via the Status pill. */
td.cell-due.is-overdue {
  color: var(--danger-text);
  font-weight: 700;
}
.due-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  vertical-align: middle;
}
/* Follow-Up filters: a plain bar on desktop, a collapsible 'Filters (N)'
   disclosure on mobile so the six controls don't stack into a tall column. */
.task-filters {
  margin: 0 0 16px;
}
.task-filters > .task-filter-bar {
  margin: 0;
}
.task-filters-summary {
  display: none;
}
@media (max-width: 720px) {
  .task-filters-summary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--white);
    font-weight: 700;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
  }
  .task-filters-summary::-webkit-details-marker {
    display: none;
  }
  .task-filters[open] > .task-filters-summary {
    margin-bottom: 12px;
  }
  .task-filter-count {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 8px;
    border-radius: var(--radius-full);
    background: var(--primary-light);
    color: var(--accent);
    font-size: 11.5px;
    text-align: center;
  }
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .wide {
  grid-column: 1 / -1;
}
.grid.form {
  gap: 12px;
}
.form-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-soft);
}

/* =========================================================================
   Badges / status pills
   ========================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: capitalize;
  white-space: nowrap;
  background: var(--info-bg);
  color: var(--info-text);
  line-height: 1.4;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.badge.hot,
.badge.high,
.badge.critical,
.badge.overdue,
.badge.rejected,
.badge.failed,
.badge.error,
.badge.stalled {
  background: var(--danger-bg);
  color: var(--danger-text);
}
.badge.warm,
.badge.medium,
.badge.pending_approval,
.badge.requires_review,
.badge.pending,
.badge.warn,
.badge.candidate {
  background: var(--warning-bg);
  color: var(--warning-text);
}
.badge.technical,
.badge.connected,
.badge.success,
.badge.done,
.badge.sent,
.badge.approved,
.badge.active,
.badge.qualified,
.badge.ok,
.badge.completed,
.badge.verified {
  background: var(--success-bg);
  color: var(--success-text);
}
.badge.cold,
.badge.resolved,
.badge.disabled,
.badge.inactive,
.badge.closed,
.badge.archived {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}
/* Live Map construction-progress states (non-terminal): explicit info-blue so
   they read as "in flight" rather than silently inheriting the default, and
   stay distinct from completed (green) / stalled (red) / candidate (amber). */
.badge.planned,
.badge.under_construction,
.badge.topping_out {
  background: var(--info-bg);
  color: var(--info-text);
}
.badge.email,
.badge.agent,
.badge.website,
.badge.qontak,
.badge.openclaw,
.badge.whatsapp {
  background: var(--info-bg);
  color: var(--info-text);
}
/* Lifecycle status (non-terminal): outlined neutral so it reads distinct from
   the filled severity pills (amber/red) and the filled terminal states
   (resolved/closed). This also gives 'in_progress' an explicit rule instead of
   silently inheriting the Source info-blue above. */
.badge.open,
.badge.in_progress {
  background: var(--neutral-bg);
  color: var(--text-muted);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
/* Lead classification 'partner' (reseller tier): brand-accent pill, distinct
   from hot/warm/cold/technical and from the Source info-blue it used to fall
   back to. */
.badge.partner {
  background: var(--primary-light);
  color: var(--accent);
}
/* No-signal enum value: muted neutral instead of the accidental info-blue. */
.badge.unknown {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}
/* Agent Command resting / offline states: calm neutral instead of the default
   info-blue dot, so an idle agent or a down gateway reads on-palette rather
   than like an informational highlight on the otherwise all-mint screen. */
.badge.idle,
.badge.offline,
.badge.unavailable,
.badge.gateway_down,
.badge.not_linked,
.badge.plugin_missing,
.badge.runtime_off,
.badge.cli_missing {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
}
.table-caption {
  caption-side: top;
  padding: 12px 16px 0;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th,
td {
  padding: 13px 16px;
  text-align: left;
  vertical-align: middle;
}
thead th {
  background: var(--primary-tint);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* Clickable sort headers (leads / follow-ups / incidents). The ↑/↓/↕ glyph is a
   ::after so it never leaks into the data-label enhanceMobileTables() derives
   from each <th>. Direction is driven by aria-sort on the <th>. */
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}
.th-sort::after {
  content: "↕";
  font-size: 10px;
  color: var(--text-soft);
  opacity: 0.5;
}
.th-sort:hover {
  color: var(--text-main);
}
.th-sort.active {
  color: var(--text-main);
}
th[aria-sort="ascending"] .th-sort::after {
  content: "↑";
  color: var(--accent);
  opacity: 1;
}
th[aria-sort="descending"] .th-sort::after {
  content: "↓";
  color: var(--accent);
  opacity: 1;
}
tbody td {
  border-bottom: 1px solid var(--border);
}
tbody tr {
  transition: background 0.14s var(--ease);
}
tbody tr:hover {
  background: var(--primary-tint);
}
/* Clickable lead rows: signal interactivity and keep the keyboard focus visible. */
tr.lead-row { cursor: pointer; }
tr.lead-row:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
/* Knowledge Hub preview: YAML frontmatter rendered as metadata, not body text. */
.kh-frontmatter {
  background: var(--primary-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 12.5px;
}
tbody tr:last-child td {
  border-bottom: 0;
}
.cell-lead {
  display: flex;
  align-items: center;
  gap: 11px;
}
.cell-lead .meta b {
  font-size: 13.5px;
  font-weight: 700;
}
.cell-lead .meta span {
  color: var(--text-soft);
  font-size: 12px;
}
.cell-lead .meta {
  display: flex;
  flex-direction: column;
}
.badge--pri {
  min-width: 34px;
  justify-content: center;
}
.t-actions {
  display: flex;
  gap: 7px;
  justify-content: flex-end;
}

/* =========================================================================
   Card lists, data cards, notes, documents
   ========================================================================= */
.card-list {
  display: grid;
  gap: 12px;
}
/* Single source of truth for .data-card (was previously also pulled into the
   grouped panel/card/metric-card block above, causing conflicting radius +
   shadow). This is the intentional lighter, interactive card-list item:
   resting --shadow-sm + --radius-lg, lifting to --shadow-card on hover. */
.data-card {
  background: var(--white);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: var(--radius-md);
  box-shadow: none;
  min-width: 0;
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease);
}
.data-card:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.data-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}
.data-card p {
  color: var(--text-muted);
  margin: 8px 0;
  font-size: 13.5px;
  line-height: 1.55;
}
.data-card small {
  font-size: 12px;
}
.dc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.dc-head .spacer {
  flex: 1;
}

/* incident-style left accent */
.note-card {
  border-left: 3px solid var(--primary);
}
.note-card.warn { border-left-color: var(--warning); }
.note-card.danger { border-left-color: var(--danger); }
.note-card.info { border-left-color: var(--info); }

/* =========================================================================
   Omnichannel Inbox
   ========================================================================= */
.omni-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.omni-thread-panel,
.omni-stage {
  min-height: 620px;
}
.omni-search {
  margin-bottom: 10px;
}
.omni-channel-bar {
  margin-bottom: 14px;
  gap: 7px;
}
.omni-channel-bar .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
}
.omni-channel-bar svg {
  width: 14px;
  height: 14px;
  position: static;
  flex: 0 0 auto;
}
.omni-thread-list {
  display: grid;
  gap: 10px;
  max-height: 620px;
  overflow: auto;
  padding-right: 3px;
}
.omni-thread {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-main);
  border-radius: var(--radius-lg);
  padding: 13px 14px;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease), transform 0.16s var(--ease);
}
.omni-thread:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
  transform: translateY(-1px);
}
.omni-thread.active {
  border-color: var(--primary);
  background: var(--primary-light);
}
.omni-thread-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.omni-thread-title {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.omni-thread-title b,
.omni-thread-title small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.omni-thread-title small {
  color: var(--text-soft);
  font-size: 12px;
}
.omni-thread time {
  margin-left: auto;
  color: var(--text-soft);
  font-size: 11px;
  white-space: nowrap;
}
.omni-thread p {
  margin: 10px 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.omni-thread-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 700;
}
.omni-thread-foot .spacer {
  flex: 1;
}
.omni-thread-foot .warn {
  color: var(--warning-text);
}
.omni-mini-channel {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  padding: 2px 7px;
}
.omni-agent-ico {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--info-bg);
  color: var(--info-text);
  flex: 0 0 auto;
}
.omni-agent-ico svg {
  width: 16px;
  height: 16px;
}
.omni-stage-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 16px;
}
.omni-stage-head .meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.omni-stage-head .meta b {
  font-size: 15px;
}
.omni-stage-head .meta span {
  color: var(--text-soft);
  font-size: 12px;
}
.omni-stage-actions {
  margin: 12px 0 0;
}
.omni-timeline {
  display: grid;
  gap: 14px;
  max-height: 660px;
  overflow: auto;
  padding-right: 4px;
}
.omni-event {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.omni-event-pin {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
}
.omni-event-pin svg {
  width: 16px;
  height: 16px;
}
.omni-bubble {
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-lg);
  background: var(--white);
  padding: 14px 15px;
  min-width: 0;
}
.omni-event.inbound .omni-bubble {
  border-left-color: var(--info);
}
.omni-event.internal .omni-bubble {
  border-left-color: var(--warning);
}
.omni-event-head {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.omni-event-head .spacer {
  flex: 1;
}
.omni-event-head time {
  color: var(--text-soft);
  font-size: 11px;
}
.omni-event-meta {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 5px;
}
.omni-bubble p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 9px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.55;
}
.omni-reply {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}
.omni-reply b {
  font-size: 12px;
}
.omni-reply p {
  margin-top: 4px;
}
.omni-event-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

/* =========================================================================
   WhatsApp Inbox
   ========================================================================= */
.badge.needs_reply,
.badge.needs_review,
.badge.qontak_pending,
.badge.waiting {
  background: var(--warning-bg);
  color: var(--warning-text);
}
.badge.ready,
.badge.suggested,
.badge.mapped,
.badge.received {
  background: var(--success-bg);
  color: var(--success-text);
}
.badge.intake,
.badge.pricing,
.badge.catalog,
.badge.urgent,
.badge.ai {
  background: var(--primary-light);
  color: var(--accent);
}
.wa-page {
  gap: 18px;
}
.wa-shell {
  display: grid;
  grid-template-columns: minmax(292px, 360px) minmax(0, 1fr) minmax(300px, 400px);
  gap: 18px;
  align-items: start;
}
.wa-inbox-panel,
.wa-chat-panel,
.wa-ai-panel {
  min-height: min(720px, calc(100dvh - 210px));
}
.wa-inbox-panel {
  padding: 16px;
}
.wa-thread-foot,
.wa-intent,
.wa-message-meta,
.wa-quick-replies button,
.wa-composer,
.wa-status-bar {
  display: flex;
  align-items: center;
}
.wa-search {
  margin: 12px 0 10px;
  gap: 8px;
}
.wa-search .search-box {
  min-width: 0;
}
.wa-status-bar {
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.wa-thread-list {
  display: grid;
  gap: 8px;
  max-height: min(600px, calc(100dvh - 350px));
  overflow: auto;
  padding-right: 3px;
}
.wa-thread {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: grid;
  gap: 8px;
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease), transform 0.16s var(--ease);
}
.wa-thread:hover,
.wa-thread.active {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.wa-thread.active {
  box-shadow: inset 3px 0 0 var(--primary);
}
.wa-thread-main {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
}
.wa-thread-title {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.wa-thread-title b,
.wa-thread-title small,
.wa-thread p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-thread-title b {
  font-size: 13.5px;
}
.wa-thread-title small,
.wa-thread-main time,
.wa-thread-foot,
.wa-message-meta,
.wa-bubble time,
.wa-intent span {
  color: var(--text-soft);
  font-size: 11.5px;
}
.wa-thread p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12.5px;
}
.wa-thread-foot {
  gap: 6px;
  flex-wrap: wrap;
}
.wa-dot {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 800;
  background: var(--neutral-bg);
  color: var(--text-muted);
}
.wa-dot.warn {
  background: var(--warning-bg);
  color: var(--warning-text);
}
.wa-dot.info {
  background: var(--primary-light);
  color: var(--accent);
}
.wa-chat-panel {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.wa-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.wa-chat-head .meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.wa-chat-head .meta b,
.wa-chat-head .meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-chat-head .meta b {
  font-size: 14px;
}
.wa-chat-head .meta span {
  color: var(--text-soft);
  font-size: 12px;
}
.wa-chat-scroll {
  flex: 1;
  min-height: 420px;
  max-height: min(620px, calc(100dvh - 360px));
  overflow: auto;
  padding: 18px;
  background-color: #efeae2;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.42)),
    radial-gradient(rgba(31, 78, 66, 0.10) 1px, transparent 1px);
  background-size: auto, 18px 18px;
}
.wa-day {
  display: grid;
  gap: 9px;
}
.wa-day + .wa-day {
  margin-top: 14px;
}
.wa-date {
  justify-self: center;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.78);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
}
.wa-message {
  display: flex;
}
.wa-message.inbound {
  justify-content: flex-start;
}
.wa-message.outbound {
  justify-content: flex-end;
}
.wa-bubble {
  width: fit-content;
  max-width: min(72%, 620px);
  border: 1px solid rgba(22, 56, 46, 0.08);
  border-radius: 12px;
  padding: 8px 10px 7px;
  background: var(--white);
  box-shadow: 0 5px 12px rgba(41, 62, 55, 0.08);
}
.wa-message.outbound .wa-bubble {
  background: #d9fdd3;
}
.wa-message-meta {
  gap: 5px;
  margin-bottom: 4px;
  font-weight: 800;
}
.wa-bubble p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  color: var(--text-main);
  font-size: 13.5px;
  line-height: 1.5;
}
.wa-bubble time {
  display: block;
  text-align: right;
  margin-top: 4px;
}
.wa-quick-replies {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.wa-quick-replies button {
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  padding: 8px 10px;
  text-align: left;
  color: var(--text-main);
}
.wa-quick-replies button:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.wa-quick-replies button span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}
.wa-quick-replies button b,
.wa-quick-replies button kbd,
.wa-confidence {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
}
.wa-quick-replies button kbd {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--primary-light);
  font-family: var(--font-mono);
}
.wa-composer {
  gap: 9px;
  padding: 13px 14px;
  border-top: 1px solid var(--border);
  background: var(--white);
}
.wa-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 128px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: var(--surface);
}
.wa-ai-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  max-height: min(720px, calc(100dvh - 210px));
  overflow: auto;
}
.wa-ai-summary,
.wa-ai-card,
.wa-note-box,
.wa-step {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--white);
  padding: 13px;
}
.wa-ai-summary {
  background: linear-gradient(180deg, var(--primary-tint), var(--white));
}
.wa-ai-summary p,
.wa-ai-card p,
.wa-note-box p,
.wa-step p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.wa-intent {
  gap: 7px;
  margin-top: 10px;
}
.wa-ai-list {
  display: grid;
  gap: 9px;
}
.wa-ai-card details {
  margin: 9px 0;
}
.wa-ai-card summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
.wa-note-box .btn {
  margin-top: 10px;
}
.wa-workflow {
  display: grid;
  gap: 8px;
}
.wa-step {
  display: grid;
  gap: 5px;
}
.wa-step b {
  font-size: 13px;
}

/* Native WhatsApp Web direction: the inbox is a product surface, not a KPI dashboard. */
.wa-page-native {
  --wa-bg: var(--bg-deep);
  --wa-panel: var(--white);
  --wa-panel-raised: var(--surface);
  --wa-panel-hover: var(--primary-tint);
  --wa-selected: var(--primary-light);
  --wa-border: var(--border);
  --wa-text: var(--text-main);
  --wa-muted: var(--text-soft);
  --wa-accent: var(--accent);
  --wa-outbound: var(--primary-light);
  height: min(760px, calc(100dvh - 152px));
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  background: var(--wa-bg);
  box-shadow: none;
}
.wa-page-native .wa-shell {
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 0;
  height: 100%;
  align-items: stretch;
}
.wa-page-native .wa-inbox-panel,
.wa-page-native .wa-chat-panel {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.wa-page-native .wa-inbox-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--wa-panel);
  border-right: 1px solid var(--wa-border);
}
.wa-side-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--wa-panel-raised);
  color: var(--wa-text);
}
.wa-side-head h3 {
  margin: 0;
  font-size: 18px;
}
.wa-side-head p {
  margin: 3px 0 0;
  color: var(--wa-muted);
  font-size: 12px;
}
.wa-page-native .badge {
  border: 0;
  background: rgba(0, 168, 132, 0.14);
  color: #7ee0c4;
}
.wa-page-native .badge.needs_review,
.wa-page-native .badge.needs_reply,
.wa-page-native .badge.qontak_pending {
  background: rgba(255, 191, 85, 0.15);
  color: #f0c56d;
}
.wa-page-native .wa-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  padding: 10px 12px 8px;
  margin: 0;
  background: var(--wa-panel);
}
.wa-page-native .wa-search .search-box {
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--wa-panel-raised);
  color: var(--wa-text);
}
.wa-page-native .wa-search .search-box svg {
  color: var(--wa-muted);
}
.wa-page-native .wa-search input {
  color: var(--wa-text);
}
.wa-page-native .wa-search input::placeholder {
  color: var(--wa-muted);
}
.wa-page-native .wa-search .icon-btn {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  border-color: transparent;
  background: var(--wa-panel-raised);
  color: var(--wa-muted);
}
.wa-page-native .wa-status-bar {
  flex-wrap: nowrap;
  gap: 6px;
  margin: 0;
  padding: 0 12px 10px;
  overflow-x: auto;
  background: var(--wa-panel);
  scrollbar-width: none;
}
.wa-page-native .wa-status-bar::-webkit-scrollbar {
  display: none;
}
.wa-page-native .wa-status-bar .chip {
  flex: 0 0 auto;
  min-height: 32px;
  border: 1px solid var(--wa-border);
  background: transparent;
  color: var(--wa-muted);
  font-size: 12px;
}
.wa-page-native .wa-status-bar .chip.active {
  border-color: rgba(0, 168, 132, 0.42);
  background: rgba(0, 168, 132, 0.16);
  color: #d9fff3;
}
.wa-page-native .wa-thread-list {
  flex: 1;
  display: block;
  max-height: none;
  padding: 0;
  overflow-y: auto;
}
.wa-page-native .wa-thread {
  border: 0;
  border-bottom: 1px solid rgba(134, 150, 160, 0.14);
  border-radius: 0;
  background: transparent;
  color: var(--wa-text);
  padding: 13px 14px;
  gap: 7px;
  box-shadow: none;
}
.wa-page-native .wa-thread:hover {
  background: var(--wa-panel-hover);
  border-color: rgba(134, 150, 160, 0.14);
  transform: none;
}
.wa-page-native .wa-thread.active {
  background: var(--wa-selected);
  border-color: rgba(134, 150, 160, 0.14);
  box-shadow: none;
}
.wa-page-native .wa-thread .avatar,
.wa-page-native .wa-chat-head .avatar {
  border-radius: 50%;
}
.wa-page-native .wa-thread-title b {
  color: var(--wa-text);
  font-size: 14px;
}
.wa-page-native .wa-thread-title small,
.wa-page-native .wa-thread-main time,
.wa-page-native .wa-thread-foot,
.wa-page-native .wa-thread p {
  color: var(--wa-muted);
}
.wa-page-native .wa-thread p {
  font-size: 12.5px;
}
.wa-page-native .wa-thread-foot .spacer,
.wa-page-native .wa-thread-foot span:not(.badge):not(.wa-dot) {
  display: none;
}
.wa-page-native .wa-dot {
  height: 20px;
  background: rgba(0, 168, 132, 0.14);
  color: #7ee0c4;
}
.wa-page-native .wa-dot.warn {
  background: rgba(255, 191, 85, 0.15);
  color: #f0c56d;
}
.wa-page-native .wa-chat-panel {
  background: var(--wa-bg);
  color: var(--wa-text);
}
.wa-page-native .wa-chat-head {
  min-height: 72px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--wa-border);
  background: var(--wa-panel-raised);
  color: var(--wa-text);
}
.wa-page-native .wa-chat-head .meta b {
  color: var(--wa-text);
  font-size: 14.5px;
}
.wa-page-native .wa-chat-head .meta span {
  color: var(--wa-muted);
}
.wa-page-native .wa-chat-head .icon-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  border-color: transparent;
  background: transparent;
  color: var(--wa-muted);
}
.wa-page-native .wa-chat-head .icon-btn:hover {
  background: rgba(134, 150, 160, 0.12);
}
.wa-page-native .wa-chat-scroll {
  min-height: 0;
  max-height: none;
  background-color: var(--wa-bg);
  background-image:
    linear-gradient(rgba(11, 20, 26, 0.84), rgba(11, 20, 26, 0.84)),
    radial-gradient(rgba(134, 150, 160, 0.16) 1px, transparent 1px);
  background-size: auto, 20px 20px;
}
.wa-page-native .wa-date {
  background: rgba(32, 44, 51, 0.92);
  color: var(--wa-muted);
  box-shadow: none;
}
.wa-page-native .wa-bubble {
  max-width: min(68%, 560px);
  border: 0;
  border-radius: 8px;
  background: var(--wa-panel-raised);
  color: var(--wa-text);
  box-shadow: none;
}
.wa-page-native .wa-message.outbound .wa-bubble {
  background: var(--wa-outbound);
}
.wa-page-native .wa-message-meta,
.wa-page-native .wa-bubble time {
  color: rgba(233, 237, 239, 0.58);
}
.wa-page-native .wa-bubble p {
  color: var(--wa-text);
}
.wa-page-native .wa-ai-panel {
  min-height: 0;
  max-height: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 260px) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--wa-border);
  background: var(--wa-panel);
  color: var(--wa-text);
  overflow: visible;
}
.wa-page-native .wa-ai-summary {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}
.wa-page-native .wa-ai-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--wa-text);
  font-size: 12.5px;
}
.wa-page-native .wa-ai-title svg {
  width: 15px;
  height: 15px;
  color: var(--wa-accent);
}
.wa-page-native .wa-ai-title span {
  color: var(--wa-muted);
  font-size: 11.5px;
}
.wa-page-native .wa-ai-summary p {
  max-width: 100%;
  margin: 4px 0 0;
  color: var(--wa-muted);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-page-native .wa-ai-primary {
  min-width: 0;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(0, 168, 132, 0.28);
  border-radius: 999px;
  background: rgba(0, 168, 132, 0.12);
  color: #d9fff3;
  padding: 0 12px;
  text-align: left;
}
.wa-page-native .wa-ai-primary span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}
.wa-page-native .wa-ai-primary b {
  color: #7ee0c4;
  font-size: 11px;
}
.wa-page-native .wa-ai-details {
  position: relative;
  color: var(--wa-muted);
  font-size: 12px;
}
.wa-page-native .wa-ai-details summary {
  cursor: pointer;
  list-style: none;
  border: 1px solid var(--wa-border);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--wa-text);
}
.wa-page-native .wa-ai-details summary::-webkit-details-marker {
  display: none;
}
.wa-page-native .wa-ai-details[open] {
  grid-column: 1 / -1;
}
.wa-page-native .wa-note-box,
.wa-page-native .wa-step {
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  background: var(--wa-panel-raised);
  padding: 11px;
}
.wa-page-native .wa-note-box {
  margin-top: 10px;
}
.wa-page-native .wa-note-box p,
.wa-page-native .wa-step p {
  color: var(--wa-muted);
}
.wa-page-native .wa-workflow {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 8px;
}
.wa-page-native .wa-quick-replies {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--wa-border);
  background: var(--wa-panel);
  overflow-x: auto;
  scrollbar-width: none;
}
.wa-page-native .wa-quick-replies::-webkit-scrollbar {
  display: none;
}
.wa-page-native .wa-quick-replies button {
  flex: 0 0 auto;
  max-width: 320px;
  min-height: 34px;
  border: 1px solid var(--wa-border);
  border-radius: 999px;
  background: var(--wa-panel-raised);
  color: var(--wa-text);
  padding: 7px 10px;
}
.wa-page-native .wa-quick-replies button:hover {
  border-color: rgba(0, 168, 132, 0.42);
  background: var(--wa-selected);
}
.wa-page-native .wa-quick-replies button span {
  font-size: 12px;
}
.wa-page-native .wa-quick-replies button b {
  color: #7ee0c4;
}
.wa-page-native .wa-quick-replies button kbd {
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 168, 132, 0.18);
  color: #7ee0c4;
}
.wa-page-native .wa-composer {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--wa-border);
  background: var(--wa-panel-raised);
}
.wa-page-native .wa-composer .icon-btn,
.wa-send-btn {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--wa-muted);
  display: grid;
  place-items: center;
}
.wa-page-native .wa-composer textarea {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--wa-panel);
  color: var(--wa-text);
  resize: none;
}
.wa-page-native .wa-composer textarea::placeholder {
  color: var(--wa-muted);
}
.wa-send-btn {
  background: var(--wa-accent);
  color: #061a15;
}
.wa-send-btn svg {
  width: 18px;
  height: 18px;
}
.wa-chat-empty {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  background: var(--wa-bg);
}
.wa-page-native .empty {
  border-color: var(--wa-border);
  background: var(--wa-panel);
  color: var(--wa-muted);
}
.wa-page-native .empty h4 {
  color: var(--wa-text);
}

/* file rows */
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  transition: all 0.14s var(--ease);
}
.file-row:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.file-ico {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  color: #fff;
  flex: 0 0 auto;
}
.file-ico.pdf { background: #e2574c; }
.file-ico.doc { background: #2b7fa8; }
.file-ico.xls { background: #1f9d5b; }
.file-ico.img { background: #d68a1f; }
.file-ico.zip { background: #7a6cc0; }
.file-row .meta b {
  font-size: 13.5px;
  display: block;
}
.file-row .meta span {
  font-size: 12px;
  color: var(--text-soft);
}
.file-row .spacer {
  flex: 1;
}

/* =========================================================================
   Knowledge Hub
   ========================================================================= */
.kh-grid {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) minmax(280px, 332px);
  gap: 18px;
  align-items: start;
}
.kh-list-panel,
.kh-editor-col,
.kh-editor-panel,
.kh-rail {
  min-width: 0;
}
.kh-editor-col {
  display: grid;
  gap: 18px;
  align-items: start;
}
.kh-toolbar {
  margin-bottom: 12px;
}
.kh-page-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 272px);
  overflow: auto;
  padding-right: 2px;
}
.kh-page {
  width: 100%;
  min-height: 66px;
  display: grid;
  gap: 5px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  padding: 12px 13px;
  color: var(--text-main);
  transition: all 0.16s var(--ease);
}
.kh-page:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.kh-page.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--accent);
}
.kh-page-title {
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.kh-page-meta {
  min-width: 0;
  color: var(--text-soft);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kh-meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}
.kh-meta-strip span {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--primary-tint);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kh-editor-fields textarea {
  min-height: 54vh;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}
.kh-actions {
  margin: 12px 0 0;
}
.kh-preview {
  max-height: 52vh;
  overflow: auto;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}
.kh-preview-panel {
  margin-top: 0;
}
.kh-page-empty {
  font-size: 13px;
  padding: 8px 2px 2px;
  margin: 0;
}
.kh-editing-file {
  font-family: var(--font-mono);
  font-weight: 700;
}
/* Rendered-markdown styling for the Knowledge Hub preview (khMarkdown output). */
.kh-preview {
  white-space: normal;
}
.kh-preview h1,
.kh-preview h2,
.kh-preview h3 {
  margin: 14px 0 6px;
  line-height: 1.3;
  color: var(--text-main);
  font-weight: 800;
}
.kh-preview h1:first-child,
.kh-preview h2:first-child,
.kh-preview h3:first-child { margin-top: 0; }
.kh-preview h1 { font-size: 19px; }
.kh-preview h2 { font-size: 16px; }
.kh-preview h3 { font-size: 14px; }
.kh-preview p { margin: 0 0 9px; }
.kh-preview ul,
.kh-preview ol { margin: 0 0 9px; padding-left: 20px; }
.kh-preview li { margin: 2px 0; }
.kh-preview a { color: var(--accent); }
.kh-preview code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--primary-tint);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}
.kh-preview pre {
  margin: 0 0 9px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.kh-preview pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}
.kh-preview blockquote {
  margin: 0 0 9px;
  padding: 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.kh-preview hr {
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--border);
}
.kh-path {
  word-break: break-all;
  font-size: 12px;
  margin-bottom: 0;
}
.kh-kv {
  margin-bottom: 10px;
}

/* =========================================================================
   Right utility panel
   ========================================================================= */
aside.rail {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 22px;
}

/* =========================================================================
   Charts (inline SVG)
   ========================================================================= */
.chart {
  width: 100%;
  display: block;
}

/* ring (circular progress) */
.ring {
  display: grid;
  place-items: center;
  text-align: center;
}
.ring svg {
  transform: rotate(-90deg);
}
.ring .ring-val {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
}
.ring .ring-label {
  font-size: 12px;
  color: var(--text-soft);
}
/* Zero-state: a legitimately-empty (0%) ring should read as an intentional, fully
   drawn track with a centered label — not a broken/blank widget. Strengthens the
   otherwise near-invisible track and tones the value down to a muted '0%'. */
.ring.is-zero svg circle:first-of-type {
  stroke: var(--border-strong);
  opacity: 0.6;
}
.ring.is-zero .ring-val {
  color: var(--text-soft);
}

/* mini bars */
.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 34px;
}
.spark i {
  flex: 1;
  background: var(--chart-soft);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
}
.spark i.hot {
  background: var(--primary);
}

/* progress bar */
.progress {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--chart-track);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  transition: width 0.6s var(--ease);
}
.progress.warn span { background: linear-gradient(90deg, #f7cf72, var(--warning)); }
.progress.danger span { background: linear-gradient(90deg, #f48484, var(--danger)); }

/* bar chart rows */
.barlist {
  display: grid;
  gap: 14px;
}
.barlist .row {
  display: grid;
  gap: 7px;
}
.barlist .row .top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.barlist .row .top b {
  font-weight: 600;
}
.barlist .row .top .v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Key-value lists, misc
   ========================================================================= */
.kv {
  display: grid;
  gap: 0;
  font-size: 13.5px;
}
.kv > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.kv > div:last-child {
  border-bottom: 0;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.markdown {
  word-wrap: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--text-main);
  line-height: 1.65;
  font-size: 13.5px;
}
/* Standalone <pre> blocks keep the monospace, pre-wrapped, boxed treatment.
   (.markdown no longer needs pre-wrap now that md() emits real block elements.) */
pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--primary-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
  line-height: 1.6;
}
.markdown b,
.markdown strong {
  color: var(--text-main);
  font-weight: 700;
}
/* Rendered-markdown blocks (research notes via md() -> khMarkdown). Mirrors the
   Knowledge Hub preview. */
.markdown h1,
.markdown h2,
.markdown h3 {
  margin: 14px 0 6px;
  line-height: 1.3;
  color: var(--text-main);
  font-weight: 700;
}
.markdown h1:first-child,
.markdown h2:first-child,
.markdown h3:first-child { margin-top: 0; }
.markdown h1 { font-size: 17px; }
.markdown h2 { font-size: 15px; }
.markdown h3 { font-size: 13.5px; }
.markdown p { margin: 0 0 9px; }
.markdown > :last-child { margin-bottom: 0; }
.markdown ul,
.markdown ol { margin: 0 0 9px; padding-left: 20px; }
.markdown li { margin: 2px 0; }
.markdown a { color: var(--accent); }
.markdown code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--primary-tint);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--accent);
}
.markdown pre { margin: 0 0 9px; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote {
  margin: 0 0 9px;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
/* Box-in-box guard: a .data-card already provides a padded, shadowed container,
   so a .markdown rendered as its direct child drops its own border/surface/padding
   to avoid a redundant nested box. Scoped to the direct child so nested markdown
   (research .mkt-sec, knowledge-hub preview) keeps its framed treatment. */
.data-card > .markdown {
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.muted {
  color: var(--text-muted);
}
.soft {
  color: var(--text-soft);
}
hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.empty {
  padding: 36px 24px;
  text-align: center;
  color: var(--text-muted);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty .empty-ico {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  background: var(--primary-light);
  color: var(--accent);
}
.empty .empty-ico svg {
  width: 24px;
  height: 24px;
}
.empty h4 {
  margin: 0 0 6px;
  color: var(--text-main);
  font-size: 15px;
}
.empty p {
  margin: 0 0 16px;
  font-size: 13.5px;
}

.profile-card {
  text-align: center;
  padding: 26px 22px;
}
.profile-card .avatar.lg {
  margin: 0 auto 14px;
}
.profile-card h3 {
  margin: 0 0 2px;
  font-size: 19px;
}
.profile-card .role {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.profile-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* mini calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-grid.head {
  margin-bottom: 6px;
}
.cal-grid.head span {
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-soft);
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 9px;
  color: var(--text-main);
  cursor: default;
  transition: background 0.14s var(--ease);
}
.cal-day:hover {
  background: var(--primary-tint);
}
.cal-day.today {
  background: var(--primary-dark);
  color: #fff;
}

/* toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--text-main);
  color: #fff;
  padding: 13px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-floating);
  z-index: 200;
  max-width: 420px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.32s var(--ease) both;
}
.toast-action {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  min-height: 34px;
}
.toast svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex: 0 0 auto;
}
.toast.err svg { color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
}

.cached-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--neutral-bg);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}
.cached-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
}

.offline-banner {
  position: fixed;
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  top: calc(12px + var(--safe-top));
  z-index: 1600;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(244, 183, 64, 0.38);
  border-radius: var(--radius-md);
  background: rgba(255, 245, 217, 0.96);
  color: var(--warning-text);
  padding: 11px 14px;
  box-shadow: var(--shadow-floating);
  font-size: 13px;
  font-weight: 700;
}
.offline-banner svg {
  width: 17px;
  height: 17px;
  flex: none;
}
.offline-banner[hidden] {
  display: none;
}

/* =========================================================================
   Mobile nav
   ========================================================================= */
.scrim {
  display: none;
}
.mobile-bottom-nav {
  display: none;
}

/* =========================================================================
   Entrance animations
   ========================================================================= */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
/* Entrance animation for view content. Exclude modal overlays: they are
   direct children of #view but manage their own fade/scale animation, and
   `rise` (which has no `to` keyframe) would otherwise pin them to the base
   opacity:0 and make every in-view modal invisible. */
#view > *:not(.modal-overlay) {
  animation: rise 0.45s var(--ease) both;
}
.stagger > * {
  animation: rise 0.5s var(--ease) both;
}
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.1s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 1280px) {
  /* The dashboard keeps its two-column page-grid (main + sticky rail) down to
     1080px so common 1280px laptops still see Budget / Ask / Incidents in the
     rail instead of buried below a full scroll. The collapse now lives in the
     1080px block below. */
  .wa-shell {
    grid-template-columns: minmax(292px, 360px) minmax(0, 1fr);
  }
  .wa-ai-panel {
    grid-column: 1 / -1;
    min-height: 0;
    max-height: none;
  }
  .wa-ai-list,
  .wa-workflow {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kh-grid {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }
  .kh-rail {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kh-preview-panel {
    margin-top: 0;
  }
}
@media (max-width: 1080px) {
  /* Below 1080px the rail can no longer hold a 332px track beside the main
     column, so collapse to one column and lay the rail out as a 2-up row below. */
  .page-grid { grid-template-columns: 1fr; }
  aside.rail {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .omni-shell { grid-template-columns: 1fr; }
  .wa-shell { grid-template-columns: 1fr; }
  .omni-thread-panel,
  .omni-stage,
  .wa-inbox-panel,
  .wa-chat-panel,
  .wa-ai-panel { min-height: 0; }
  .omni-thread-list { max-height: 360px; }
  .wa-thread-list { max-height: 340px; }
  .wa-chat-scroll {
    min-height: 420px;
    max-height: 560px;
  }
  .wa-ai-list,
  .wa-workflow {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .kh-grid,
  .kh-rail {
    grid-template-columns: 1fr;
  }
  .kh-rail {
    display: grid;
  }
  .kh-page-list {
    max-height: 280px;
  }
  .kh-editor-fields textarea {
    min-height: 340px;
  }
  .kh-preview {
    max-height: 300px;
  }
  .table-wrap.mobile-card-table {
    border: 0;
    background: transparent;
    overflow: visible;
    box-shadow: none;
  }
  .table-wrap.mobile-card-table table,
  .table-wrap.mobile-card-table thead,
  .table-wrap.mobile-card-table tbody,
  .table-wrap.mobile-card-table tr,
  .table-wrap.mobile-card-table th,
  .table-wrap.mobile-card-table td {
    display: block;
    width: 100%;
  }
  .table-wrap.mobile-card-table thead {
    /* Fully removed (not just clipped): the th-sort buttons inside were still
       focusable/clickable 13px-tall targets on the card layout. Sorting stays
       available through the Sort select in each view's Filters panel. */
    display: none;
  }
  .table-wrap.mobile-card-table tbody {
    display: grid;
    gap: 10px;
  }
  .table-wrap.mobile-card-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow-sm);
    padding: 10px 12px;
  }
  .table-wrap.mobile-card-table td {
    border: 0;
    padding: 8px 0;
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    word-break: break-word;
  }
  .table-wrap.mobile-card-table td + td {
    border-top: 1px solid var(--border);
  }
  .table-wrap.mobile-card-table td::before {
    content: attr(data-label);
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }
  .table-wrap.mobile-card-table .cell-lead {
    min-width: 0;
  }
  .table-wrap.mobile-card-table td.t-actions-cell {
    display: block;
    margin-top: 4px;
    padding-top: 12px;
  }
  .table-wrap.mobile-card-table td.t-actions-cell::before {
    content: none;
  }
  .table-wrap.mobile-card-table .t-actions {
    justify-content: stretch;
    gap: 10px;
  }
  .table-wrap.mobile-card-table .t-actions .btn {
    flex: 1 1 0;
    min-height: 42px;
  }
  /* Settings · Users — condense the mobile card so each user reads as a
     compact summary (name/email prominent, role/status/login tight) instead
     of a tall four-label key/value block. */
  .table-wrap.mobile-card-table.users-table tr {
    padding: 12px;
  }
  .table-wrap.mobile-card-table.users-table td {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 6px 0;
    min-height: 0;
  }
  .table-wrap.mobile-card-table.users-table td:first-child {
    padding-top: 0;
  }
  .table-wrap.mobile-card-table.users-table td:first-child::before {
    display: none;
  }
  .table-wrap.mobile-card-table.users-table .cell-lead b {
    font-size: 14px;
  }
  .table-wrap.mobile-card-table.users-table td.user-actions {
    text-align: left;
  }
  .table-wrap.mobile-card-table.users-table td.user-actions .btn {
    width: 100%;
  }
  /* Empty-state colspan row (Users / Audit logs) — drop the stray uppercase
     data-label and the reserved label gutter so the empty card centres cleanly. */
  .table-wrap.mobile-card-table td[colspan] {
    grid-template-columns: 1fr;
  }
  .table-wrap.mobile-card-table td[colspan]::before {
    display: none;
  }
}

/* Tablet & mobile: collapse sidebar to a drawer */
@media (max-width: 920px) {
  :root {
    --sidebar-w: 0px;
  }
  .layout {
    grid-template-columns: 1fr;
    contain: none;
  }
  .sidebar {
    position: fixed;
    top: auto;
    left: calc(8px + var(--safe-left));
    right: calc(8px + var(--safe-right));
    bottom: 0;
    width: auto;
    max-width: 560px;
    height: min(78dvh, 720px);
    margin: 0 auto;
    z-index: 1310;
    transform: translateY(calc(100% + 24px));
    transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-floating);
    border-right: 0;
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding-bottom: calc(20px + var(--safe-bottom));
    will-change: transform;
  }
  .sidebar-collapse {
    display: none;
  }
  .sidebar::before {
    content: "";
    width: 42px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--border-strong);
    align-self: center;
    margin: 0 0 8px;
  }
  /* Drawer: render each nav group as a collapsible accordion so owner/admin
     roles aren't a wall of links. Non-active sections start collapsed (set in
     renderShell); tapping the header toggles. */
  .nav-section.collapsed .nav {
    display: none;
  }
  .nav-section-toggle {
    min-height: 44px;
    padding: 4px 4px;
    border-radius: var(--radius-md);
  }
  .nav-section-toggle:hover {
    background: var(--primary-tint);
  }
  .nav-section-toggle .nav-label {
    margin: 0;
  }
  /* Comfortable tap targets for the nav rows themselves. */
  .nav button {
    min-height: 44px;
  }
  .layout.drawer-open .sidebar,
  .sidebar.open {
    transform: translateY(0) !important;
  }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 50, 44, 0.42);
    backdrop-filter: blur(2px);
    z-index: 1300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease);
  }
  .layout.drawer-open .scrim,
  .scrim.open {
    opacity: 1 !important;
    pointer-events: auto;
  }
  .content {
    /* Bottom nav (~80px) + the agent launcher parked above it (~64px). */
    padding: calc(18px + var(--safe-top)) 18px calc(156px + var(--safe-bottom));
  }
  /* iOS Safari zooms the page when a focused field's font-size is under 16px.
     Guard the whole mobile shell (not just ≤640px — landscape phones and small
     tablets hit this breakpoint too). Later sheets must not undercut this. */
  input,
  textarea,
  select,
  .search-box input {
    font-size: 16px;
  }
  /* The agent-chat launcher parks bottom-right; the base .content tail padding
     already clears it together with the bottom nav. */
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mobile-bottom-nav {
    position: fixed;
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
    bottom: calc(10px + var(--safe-bottom));
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--nav-glass-border);
    border-radius: 22px;
    background: var(--nav-glass-bg);
    backdrop-filter: blur(18px) saturate(1.25);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    box-shadow: 0 18px 44px rgba(20, 80, 70, 0.16);
  }
  .mobile-bottom-nav button {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    min-width: 0;
    min-height: 52px;
    border-radius: 17px;
    display: grid;
    place-items: center;
    gap: 2px;
    padding: 6px 2px;
    font-size: 10.5px;
    font-weight: 800;
    transition: background 0.16s var(--ease), color 0.16s var(--ease), transform 0.16s var(--ease);
  }
  .mobile-bottom-nav button:active {
    transform: scale(0.96);
  }
  .mobile-bottom-nav svg {
    width: 19px;
    height: 19px;
  }
  .mobile-bottom-nav button.active {
    background: var(--primary-light);
    color: var(--accent);
  }
  body.omni-view .agent-chat:not(.open) {
    display: none;
  }
  /* Ask-agent launcher ducks while scrolling down (wireHeaderCollapse toggles
     fab-hidden) so it stops covering trailing row actions near the fold. */
  .agent-chat {
    transition: transform 0.22s var(--ease), opacity 0.22s var(--ease);
  }
  .agent-chat.fab-hidden:not(.open) {
    transform: translateY(140px);
    opacity: 0;
    pointer-events: none;
  }
}
@media (max-width: 640px) {
  .grid-2,
  .grid-3,
  .form-grid,
  .demo-grid,
  .login-card,
  aside.rail {
    grid-template-columns: 1fr;
  }
  /* On phones the dashboard's most useful controls (Budget ring + Ask-assistant,
     the rail's first two panels) must not sit below the long Priority Leads list:
     lift the whole rail above the main column at this breakpoint. */
  .page-grid > .rail {
    order: -1;
  }
  /* KPI stat cards stay 2-up on phones: compact, far more scannable than a
     single tall column, and halves the scroll to reach content below. */
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .metric-card {
    min-height: 104px;
    padding: 15px 15px 13px;
    gap: 9px;
  }
  .metric-card .value {
    font-size: 27px;
  }
  .login-hero {
    padding: 26px 24px;
  }
  /* On phones the hero is a brand strip, not a landing page — tighten it so
     the role cards / sign-in form arrive on the first screen. */
  .login-hero p,
  .login-hero .hero-chips {
    display: none;
  }
  .login-hero h1 {
    font-size: 24px;
    margin-bottom: 0;
  }
  .login-form {
    padding: 32px 24px;
  }
  .topbar {
    flex-wrap: wrap;
    position: sticky;
    top: var(--safe-top);
    z-index: 70;
    margin: 0 -6px 18px;
    padding: 10px 6px 12px;
    background: var(--topbar-glass-bg);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-bottom: 1px solid var(--nav-glass-border);
  }
  .topbar-actions {
    width: 100%;
    margin-left: 0;
  }
  /* The user identity is already shown in the drawer; hiding the menu here
     stops it crowding the toolbar so global search gets a usable width.
     Settings / theme / install / log out stay reachable via the drawer +
     Settings page, and Help via the mobile "More" sheet and Settings row. */
  .user-menu {
    display: none;
  }
  .search-box {
    flex: 1;
  }
  .search-box input {
    width: 100%;
  }
  .content {
    padding: calc(14px + var(--safe-top)) 14px calc(156px + var(--safe-bottom));
  }
  body {
    font-size: 15px;
  }
  .metric-card .value {
    font-size: 26px;
  }
  .topbar h1 {
    font-size: 22px;
  }
  .btn,
  .btn.small,
  .btn.ghost,
  .btn.secondary,
  .toast-action,
  .toolbar .btn,
  .t-actions .btn,
  .demo-user,
  .ac-tab {
    min-height: 44px;
  }
  .toolbar {
    align-items: stretch;
  }
  .toolbar .search-box.grow,
  .toolbar .search-box.grow input {
    min-width: 0;
  }
  .agent-chat {
    right: calc(14px + var(--safe-right));
    bottom: calc(88px + var(--safe-bottom));
  }
  .ac-panel {
    max-width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    /* dvh tracks iOS Safari's collapsing toolbar; the vh line above is the
       fallback for older engines. */
    height: calc(100dvh - 100px);
  }
  .omni-channel-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  .omni-stage-actions .btn,
  .omni-event-actions .btn {
    flex: 1 1 120px;
  }
  .omni-event {
    grid-template-columns: 28px minmax(0, 1fr);
  }
  .omni-event-pin {
    width: 28px;
    height: 28px;
    border-radius: 9px;
  }
  .omni-thread time {
    display: none;
  }
  body.omni-view .metric-card {
    min-height: 90px;
    padding: 13px;
    gap: 7px;
  }
  body.omni-view #view > .grid > .grid-4 {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  body.omni-view #view > .grid > .grid-4::-webkit-scrollbar {
    display: none;
  }
  body.omni-view #view > .grid > .grid-4 .metric-card {
    flex: 0 0 154px;
  }
  body.omni-view .metric-card .value {
    font-size: 24px;
  }
  body.omni-view .metric-foot {
    display: none;
  }
  body.omni-view .omni-thread-panel,
  body.omni-view .omni-stage {
    padding: 16px;
  }
  body.omni-view .omni-search,
  body.omni-view .toolbar {
    margin-bottom: 10px;
  }
  body.omni-view .omni-channel-bar .chip {
    padding: 6px 10px;
    font-size: 12.5px;
  }
  body.wa-view .metric-card {
    min-height: 90px;
    padding: 13px;
    gap: 7px;
  }
  body.wa-view #view > .grid > .grid-4 {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  body.wa-view #view > .grid > .grid-4::-webkit-scrollbar {
    display: none;
  }
  body.wa-view #view > .grid > .grid-4 .metric-card {
    flex: 0 0 154px;
  }
  body.wa-view .metric-card .value {
    font-size: 24px;
  }
  body.wa-view .metric-foot {
    display: none;
  }
  body.wa-view .wa-inbox-panel,
  body.wa-view .wa-ai-panel {
    padding: 14px;
  }
  .wa-search {
    display: grid;
    grid-template-columns: 1fr;
  }
  .wa-status-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  .wa-status-bar .chip {
    flex: 0 0 auto;
  }
  .wa-thread-main {
    grid-template-columns: 34px minmax(0, 1fr);
  }
  .wa-thread-main time {
    display: none;
  }
  .wa-chat-head {
    padding: 13px;
    flex-wrap: wrap;
  }
  .wa-chat-head .meta {
    flex: 1 1 180px;
  }
  .wa-chat-scroll {
    min-height: 360px;
    max-height: 520px;
    padding: 12px;
  }
  .wa-bubble {
    max-width: 88%;
  }
  .wa-composer {
    align-items: stretch;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
  }
  .wa-composer .btn {
    grid-column: 1 / -1;
  }
  .wa-quick-replies button span {
    white-space: normal;
  }
}

@media (max-width: 1080px) {
  .wa-page-native {
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .wa-page-native .wa-shell {
    grid-template-columns: 1fr;
  }
  .wa-page-native .wa-inbox-panel {
    height: min(430px, 58dvh);
    border-right: 0;
    border-bottom: 1px solid var(--wa-border);
  }
  .wa-page-native .wa-chat-panel {
    height: min(700px, 74dvh);
  }
  .wa-page-native .wa-ai-panel {
    grid-template-columns: 1fr;
  }
  .wa-page-native .wa-ai-primary {
    width: 100%;
  }
  .wa-page-native .wa-workflow {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .wa-page-native {
    border-radius: 0;
    margin: 0 -14px;
    border-left: 0;
    border-right: 0;
  }
  .wa-page-native .wa-side-head,
  .wa-page-native .wa-chat-head {
    min-height: 62px;
    padding: 10px 12px;
  }
  .wa-page-native .wa-inbox-panel {
    height: 390px;
  }
  .wa-page-native .wa-chat-panel {
    height: 620px;
  }
  .wa-page-native .wa-bubble {
    max-width: 86%;
  }
  .wa-page-native .wa-ai-panel {
    padding: 9px 10px;
  }
  .wa-page-native .wa-quick-replies {
    padding: 8px 10px;
  }
  .wa-page-native .wa-quick-replies button {
    max-width: 260px;
  }
  .wa-page-native .wa-composer {
    display: flex;
    align-items: center;
    grid-template-columns: none;
    padding: 9px 10px;
  }
  .wa-page-native .wa-composer .btn {
    grid-column: auto;
  }
}

/* Recent-conversations history items (Agent Command page) */
.run-item { cursor: pointer; }
.run-item summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.run-item summary::-webkit-details-marker { display: none; }
.run-item[open] > div { border-top: 1px solid var(--border); padding-top: 8px; color: var(--text-main); }

/* Agent Command: give the view a bottom tail so the bottom-right cards (result
   slot + history) always scroll clear of the fixed "Ask an agent" launcher. */
.split.agent-cmd { padding-bottom: 72px; }
/* Shared result slot: placement-cue placeholder + inline composer + readable
   result, with raw JSON tucked behind a small <details>. */
.agent-result-empty { border: 1px dashed var(--border-strong); border-radius: var(--radius-md); padding: 14px 16px; color: var(--text-muted); font-size: 13px; background: var(--surface); }
.agent-result-title { display: block; font-size: 12px; font-weight: 700; color: var(--text-soft); margin-bottom: 8px; }
.agent-compose { display: grid; gap: 10px; }
.agent-compose textarea { width: 100%; resize: vertical; min-height: 64px; }
.agent-compose-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agent-result-bits { margin: 4px 0 0; padding-left: 18px; }
.agent-result-bits li { margin: 2px 0; }
.agent-raw { margin-top: 10px; }
.agent-raw summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-soft); list-style: none; }
.agent-raw summary::-webkit-details-marker { display: none; }
.agent-raw summary::before { content: "\203A  "; }
.agent-raw[open] summary::before { content: "\2304  "; }
.agent-raw pre { margin-top: 8px; max-height: 280px; overflow: auto; }

/* ============================ Agent chat (sticky) ============================ */
.agent-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1200;
  font-family: inherit;
}
.ac-launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--text-inverse);
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-floating);
  transition: transform 0.15s ease;
}
.ac-launcher:hover { transform: translateY(-1px); }
.ac-launcher svg { width: 18px; height: 18px; stroke: currentColor; }
.agent-chat.open .ac-launcher { display: none; }
/* While the on-screen keyboard is up on phones, get the launcher out of the way
   of the field being edited (body.kb-open is toggled by a focusin tracker). */
@media (max-width: 920px) {
  body.kb-open .agent-chat:not(.open) { display: none; }
}

.ac-panel {
  display: none;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 28px);
  height: 560px;
  max-height: calc(100vh - 110px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  overflow: hidden;
}
.agent-chat.open .ac-panel { display: flex; }

.ac-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  flex: none;
}
.ac-head .ac-title { display: flex; flex-direction: column; line-height: 1.2; }
.ac-head .ac-title b { font-size: 14px; color: var(--text-main); }
.ac-head .ac-status { font-size: 11px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.ac-head .spacer { flex: 1; }
.ac-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-soft); flex: none; }
.ac-dot.on { background: var(--success); }
.ac-dot.idle { background: var(--warning); }
.ac-dot.off { background: var(--danger); }
.ac-close { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-close:hover { background: var(--neutral-bg); }
.ac-close svg { width: 16px; height: 16px; stroke: currentColor; transform: rotate(90deg); }
.ac-expand { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-expand:hover { background: var(--neutral-bg); }
.ac-expand svg { width: 15px; height: 15px; stroke: currentColor; }

/* Maximized: panel grows to nearly fill the viewport instead of cramped internal scroll */
.agent-chat.maximized .ac-panel {
  width: 920px;
  max-width: calc(100vw - 44px);
  height: calc(100vh - 44px);
  max-height: calc(100vh - 44px);
}

.ac-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  overflow-x: auto;
  flex: none;
  scrollbar-width: none;
}
.ac-tabs::-webkit-scrollbar { display: none; }
.ac-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s var(--ease);
}
.ac-tab:hover { border-color: var(--primary); color: var(--text-main); }
.ac-tab.active { background: var(--primary-light); border-color: var(--primary); color: var(--accent); }

.ac-msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.ac-msg {
  max-width: 86%;
  width: fit-content;
  padding: 9px 12px;
  border-radius: 15px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ac-msg.user { align-self: flex-end; background: var(--primary); color: var(--text-inverse); border-bottom-right-radius: 5px; }
.ac-msg.agent { align-self: flex-start; background: var(--white); border: 1px solid var(--border); color: var(--text-main); border-bottom-left-radius: 5px; }
.ac-msg.system { align-self: center; background: var(--neutral-bg); color: var(--text-muted); font-size: 12px; text-align: center; max-width: 100%; border-radius: 10px; }
.ac-msg.typing { color: var(--text-muted); font-style: italic; }
.ac-msg.streaming::after { content: '▋'; margin-left: 1px; color: var(--primary); animation: ac-blink 1s steps(2) infinite; }
@keyframes ac-blink { 50% { opacity: 0; } }

/* Rendered markdown inside agent replies */
.ac-msg.agent.md { max-width: 94%; overflow-x: auto; }
.ac-msg.md > :first-child { margin-top: 0; }
.ac-msg.md > :last-child { margin-bottom: 0; }
.ac-msg.md p { margin: 6px 0; }
.ac-msg.md h3, .ac-msg.md h4, .ac-msg.md h5, .ac-msg.md h6 { margin: 10px 0 4px; font-size: 13.5px; font-weight: 700; color: var(--text-main); }
.ac-msg.md ul, .ac-msg.md ol { margin: 6px 0; padding-left: 18px; }
.ac-msg.md li { margin: 2px 0; }
.ac-msg.md code { background: var(--neutral-bg); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.ac-msg.md hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.ac-msg.md a { color: var(--accent); }
.ac-tbl { border-collapse: collapse; margin: 6px 0; font-size: 12.5px; }
.ac-tbl th, .ac-tbl td { border: 1px solid var(--border); padding: 5px 7px; text-align: left; vertical-align: top; }
.ac-tbl th { background: var(--primary-tint); font-weight: 700; white-space: nowrap; }
.ac-chip { display: inline-flex; align-items: center; gap: 3px; background: var(--primary-light); color: var(--accent); border: 1px solid var(--primary); border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.ac-chip:hover { background: var(--primary); color: var(--text-inverse); }

/* Structured lead result cards (action buttons) */
.lead-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lead-card { background: var(--white); border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 10px 12px; }
.lc-head { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.lc-head b { color: var(--text-main); }
.lc-tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0; color: var(--accent); background: var(--primary-light); border-radius: 999px; padding: 1px 8px; }
.lc-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.lc-why { font-size: 12.5px; color: var(--text-main); margin-top: 5px; }
.lc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.lc-btn { border: 1px solid var(--primary); background: var(--primary); color: var(--text-inverse); border-radius: var(--radius-sm); padding: 5px 10px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.lc-btn.ghost { background: var(--surface); color: var(--accent); }
.lc-btn:hover:not(:disabled) { filter: brightness(1.05); }
.lc-btn:disabled { opacity: .5; cursor: default; }
.lc-status { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; min-height: 0; }
.lc-status b { color: var(--accent); }

.ac-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--white);
  flex: none;
}
/* Beat the global input/textarea rules (width:100%, height:42px, min-height:92px). */
.agent-chat .ac-input textarea {
  flex: 1 1 auto;
  width: auto;
  min-height: 0;
  height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  resize: none;
  color: var(--text-main);
  background: var(--surface);
}
.agent-chat .ac-input textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.ac-send {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ac-send svg { width: 17px; height: 17px; }

/* New-conversation button (matches the expand/close icons) */
.ac-icon { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-icon:hover { background: var(--neutral-bg); }
.ac-icon svg { width: 15px; height: 15px; stroke: currentColor; }

/* Launcher unread badge */
.ac-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; }
.ac-badge[hidden] { display: none; }

/* Tab status dot (busy = pulsing amber, unread = solid teal) */
.ac-tdot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-left: 2px; background: transparent; }
.ac-tdot.unread { background: var(--primary); }
.ac-tdot.busy { background: var(--warning); animation: ac-pulse 1s ease-in-out infinite; }
@keyframes ac-pulse { 50% { opacity: 0.3; } }

/* Message rows wrap a bubble + its meta (copy button + timestamp) */
.ac-row { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.ac-row.user { align-self: flex-end; align-items: flex-end; }
.ac-row.agent { align-self: flex-start; align-items: flex-start; }
.ac-row.system { align-self: center; align-items: center; max-width: 100%; }
.ac-row .ac-msg { align-self: auto; }
.ac-meta { display: flex; align-items: center; gap: 6px; padding: 0 4px; font-size: 10.5px; color: var(--text-soft); }
.ac-row.user .ac-meta { flex-direction: row-reverse; }
.ac-time { font-variant-numeric: tabular-nums; }
.ac-copy { border: none; background: none; padding: 2px; border-radius: 4px; cursor: pointer; color: var(--text-soft); opacity: 0; transition: opacity 0.12s; display: inline-flex; }
.ac-row:hover .ac-copy, .ac-copy:focus-visible { opacity: 1; }
.ac-copy:hover { color: var(--accent); background: var(--neutral-bg); }
.ac-copy svg { width: 13px; height: 13px; }
.ac-retry { margin-left: 6px; border: 1px solid var(--primary); background: var(--surface); color: var(--accent); border-radius: 6px; padding: 1px 8px; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; }
.ac-retry:hover { background: var(--primary); color: #fff; }

/* Starter-prompt chips on an empty thread */
.ac-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; background: var(--bg); flex: none; }
.ac-suggest[hidden] { display: none; }
.ac-sg { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted); border-radius: 999px; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; text-align: left; }
.ac-sg:hover { border-color: var(--primary); color: var(--accent); background: var(--primary-light); }

/* Stop button replaces Send while a turn is in flight */
.ac-stop { flex: none; width: 42px; height: 42px; padding: 0; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; background: var(--danger); border-color: var(--danger); color: #fff; }
.ac-stop svg { width: 16px; height: 16px; }
.ac-stop[hidden], .ac-send[hidden] { display: none; }
.agent-chat .ac-input textarea:disabled { opacity: 0.6; cursor: not-allowed; }

/* Attach button + pending text-attachment chips */
.ac-attach-btn { flex: none; width: 42px; height: 42px; padding: 0; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-md); color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ac-attach-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--accent); }
.ac-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ac-attach-btn svg { width: 17px; height: 17px; stroke: currentColor; }
.ac-attach { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; background: var(--bg); flex: none; }
.ac-attach[hidden] { display: none; }
.ac-att { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; background: var(--primary-light); border: 1px solid var(--primary); color: var(--accent); border-radius: 999px; padding: 3px 6px 3px 9px; font-size: 11.5px; font-weight: 600; }
.ac-att svg { width: 12px; height: 12px; stroke: currentColor; flex: none; }
.ac-att-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-att-x { border: none; background: none; padding: 1px; margin: 0; color: var(--accent); cursor: pointer; display: inline-flex; border-radius: 50%; flex: none; }
.ac-att-x:hover { background: var(--primary); color: #fff; }

@media (max-width: 520px) {
  .agent-chat {
    right: calc(16px + var(--safe-right));
    bottom: calc(88px + var(--safe-bottom));
    left: auto;
  }
  .ac-launcher {
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  .ac-launcher span:not(.ac-badge) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .agent-chat.open {
    left: 0;
    right: 0;
    bottom: 0;
  }
  .ac-panel {
    width: 100%;
    max-width: none;
    height: min(78dvh, calc(100dvh - 72px));
    max-height: calc(100dvh - 28px);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding-bottom: var(--safe-bottom);
  }
  .agent-chat.maximized .ac-panel {
    width: 100%;
    max-width: none;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .ac-tabs {
    padding-bottom: 12px;
  }
  .ac-tab {
    padding: 7px 12px;
  }
}

/* Market intelligence reports (Research view + Overview card). */
.mkt-highlights { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.mkt-hl { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; line-height: 1.4; }
.mkt-hl .ic { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; color: var(--warning-text); }
.mkt-hl a { color: var(--accent); text-decoration: none; }
.mkt-details { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.mkt-details > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); }
.mkt-sec { margin: 8px 0; }
.mkt-sec > b { display: block; margin-bottom: 2px; }
.mkt-src { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.mkt-src li { margin: 3px 0; }
.mkt-src a { color: var(--accent); }

/* WhatsApp Connection panel — QR matrix rendered client-side from the parsed ANSI grid. */
.wa-qr { display: grid; width: 220px; max-width: 100%; aspect-ratio: 1; gap: 0; background: #fff; padding: 8px; border-radius: 8px; }
.wa-qr i { display: block; width: 100%; aspect-ratio: 1; }
.wa-qr i.d { background: #000; }
.wa-qr i.l { background: #fff; }

@media (max-width: 920px) {
  nav.sidebar.open {
    transform: none !important;
  }
  div.scrim.open {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* =========================================================================
   Pull-to-refresh
   ========================================================================= */
.ptr-wrap {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ptr-indicator {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: 50%;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-floating);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  z-index: 1300;
  pointer-events: none;
}
.ptr-indicator.active {
  opacity: 1;
}
.ptr-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

/* =========================================================================
   Floating controls — the agent-chat launcher is the only floating control.
   Tuck it away under an open modal so it never sits over dialog fields.
   (.modal-open is toggled in app.js.)
   ========================================================================= */
body.modal-open .agent-chat:not(.open) {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

/* =========================================================================
   Bottom Sheet
   ========================================================================= */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  box-shadow: var(--shadow-floating);
  z-index: 1400;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.bottom-sheet.open {
  transform: translateY(0);
  transition: transform 0.36s var(--ease-spring);
}
.bottom-sheet .bs-grip {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
  padding-top: calc(10px + var(--safe-top, 0px));
}
.bottom-sheet .bs-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  flex-shrink: 0;
}
.bottom-sheet .bs-content {
  overflow-y: auto;
  padding: 0 20px calc(20px + var(--safe-bottom));
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.bottom-sheet .bs-title {
  font-size: 17px;
  font-weight: 800;
  margin: 4px 0 12px;
  padding: 0 20px;
}
.bs-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 50, 44, 0.42);
  z-index: 1390;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.bs-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

/* =========================================================================
   Touch ripple press effect
   ========================================================================= */
.press-effect {
  position: relative;
  overflow: hidden;
}
.press-effect::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--px, 50%) var(--py, 50%), rgba(255,255,255,0.25) 10%, transparent 10%);
  background-repeat: no-repeat;
  transform: scale(4);
  opacity: 0;
  transition: transform 0.5s, opacity 0.5s;
  pointer-events: none;
}
.press-effect.is-pressed::after {
  transform: scale(0);
  opacity: 1;
  transition: 0s;
}

/* =========================================================================
   Swipe actions on list items
   ========================================================================= */
.swipe-row {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}
.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  z-index: 0;
}
.swipe-actions button {
  height: 100%;
  padding: 0 20px;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.swipe-actions .swipe-primary { background: var(--primary); }
.swipe-actions .swipe-danger { background: var(--danger); }
.swipe-actions .swipe-ghost { background: var(--text-soft); }
.swipe-content {
  position: relative;
  z-index: 1;
  background: var(--white);
  transition: transform 0.25s var(--ease);
}

/* =========================================================================
   View content fade-in
   ========================================================================= */
.view-content {
  animation: fade-in 0.3s var(--ease);
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Spring physics easing
   ========================================================================= */
:root {
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal {
  animation: modal-scale-in 0.35s var(--ease-spring) forwards;
}

/* =========================================================================
   Dark mode
   ========================================================================= */
/* Dark palette. Defined once via a custom-property recipe so the system (auto)
   and forced (html.dark) paths can never drift apart. Forced light (html.light)
   must beat the system-dark media query, so the auto path is scoped to
   html:not(.light) rather than a bare :root. */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --bg: #0f1f1c;
    --bg-deep: #0a1715;
    --surface: #162b27;
    --white: #1a302b;
    --border: #23423a;
    --border-strong: #2d5248;
    --sidebar-bg: #0a1715;
    --sidebar-border: #23423a;
    --text-main: #e1f0ec;
    --text-muted: #8a9e98;
    --text-soft: #84968e;
    --text-inverse: #0a1715;
    --primary-light: #1a4a3f;
    --primary-tint: #122e28;
    --chart-track: #1a302b;
    --success-bg: #1a4a3f;
    --danger-bg: #4a1f1f;
    --warning-bg: #4a3a1a;
    --info-bg: #1a3a4a;
    /* Status text must be LIGHT in dark mode (it rides on the dark tints above). */
    --success-text: #5fd3b0;
    --warning-text: #ecc25e;
    --danger-text: #f29393;
    --info-text: #76c4ec;
    --neutral-bg: #283a35;
    --neutral-text: #9fb3ad;
    --accent: #5fe0c2;
    --nav-glass-bg: rgba(22, 43, 39, 0.9);
    --nav-glass-border: rgba(45, 82, 72, 0.7);
    --topbar-glass-bg: rgba(15, 31, 28, 0.85);
  }
}
html.dark {
  --bg: #0f1f1c;
  --bg-deep: #0a1715;
  --surface: #162b27;
  --white: #1a302b;
  --border: #23423a;
  --border-strong: #2d5248;
  --sidebar-bg: #0a1715;
  --sidebar-border: #23423a;
  --text-main: #e1f0ec;
  --text-muted: #8a9e98;
  --text-soft: #84968e;
  --text-inverse: #0a1715;
  --primary-light: #1a4a3f;
  --primary-tint: #122e28;
  --chart-track: #1a302b;
  --success-bg: #1a4a3f;
  --danger-bg: #4a1f1f;
  --warning-bg: #4a3a1a;
  --info-bg: #1a3a4a;
  --success-text: #5fd3b0;
  --warning-text: #ecc25e;
  --danger-text: #f29393;
  --info-text: #76c4ec;
  --neutral-bg: #283a35;
  --neutral-text: #9fb3ad;
  --accent: #5fe0c2;
  --nav-glass-bg: rgba(22, 43, 39, 0.9);
  --nav-glass-border: rgba(45, 82, 72, 0.7);
  --topbar-glass-bg: rgba(15, 31, 28, 0.85);
}

/* =========================================================================
   Chip filter bar
   ========================================================================= */
.chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chip-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--white);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.16s;
}
.chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--accent);
}

/* =========================================================================
   Settings: Device & app preference rows
   ========================================================================= */
.set-rows {
  display: flex;
  flex-direction: column;
}
.set-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.set-row:first-child {
  border-top: 0;
}
.set-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 220px;
}
.set-row-text b {
  font-size: 14px;
}
.set-row-text .muted {
  font-size: 12.5px;
}
.set-row .chip-bar {
  flex: 0 1 auto;
}
/* Settings · Users panel — compact inline role editor + activation control */
.panel-head #inviteUserBtn {
  flex: 0 0 auto;
}
select.user-role {
  height: 34px;
  font-size: 12.5px;
  padding: 0 30px 0 10px;
  max-width: 168px;
  background-position: right 9px center;
}
td.user-actions {
  white-space: nowrap;
  text-align: right;
}

/* =========================================================================
   Settings — two-pane layout (left rail + content panes)
   ========================================================================= */
.settings-shell {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.settings-rail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 16px;
}
.srail-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  position: relative;
  transition: all 0.16s var(--ease);
}
.srail-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke-width: 1.9;
  opacity: 0.78;
}
.srail-label {
  flex: 1;
  min-width: 0;
}
.srail-item:hover {
  background: var(--primary-tint);
  color: var(--accent);
}
.srail-item:hover svg {
  opacity: 1;
}
.srail-item.active {
  background: var(--primary-light);
  color: var(--accent);
}
.srail-item.active svg {
  opacity: 1;
}
.srail-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: var(--radius-full);
  background: var(--primary);
}
.srail-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--neutral-bg);
  color: var(--text-muted);
  padding: 1px 8px;
  border-radius: var(--radius-full);
}
.srail-item.active .srail-count {
  background: var(--white);
  color: var(--accent);
}

.settings-content {
  min-width: 0;
}
.settings-pane {
  min-width: 0;
}
.settings-pane[hidden] {
  display: none !important;
}

/* Pane header — concise title + description + right-aligned action */
.spane-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.spane-head .spacer {
  flex: 1;
}
.spane-head-text h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.spane-head-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
}
.spane-head .btn {
  flex: 0 0 auto;
}

/* Preferences rows — leading icon for scannability */
.set-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--primary-tint);
  color: var(--accent);
}
.set-ic svg {
  width: 17px;
  height: 17px;
}

/* Integrations — status summary chips + responsive card grid */
.set-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.set-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--white);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: var(--radius-full);
}
.set-stat b {
  color: var(--text-main);
  font-weight: 700;
}
.set-stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.set-stat.ok {
  color: var(--success-text);
}
.set-stat.info {
  color: var(--info-text);
}
.set-integrations {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(264px, 1fr));
  gap: 14px;
}

/* Audit action filter — auto width inside the toolbar + subtle mono tag */
.set-select {
  width: auto;
  min-width: 168px;
  flex: 0 0 auto;
}
/* Audit log — plain-English rows with an expandable "what changed" detail */
.audit-row { cursor: pointer; }
.audit-row:hover,
.audit-row[aria-expanded="true"] { background: var(--surface); }
.audit-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.audit-time { white-space: nowrap; }
.audit-row .cell-lead { align-items: center; gap: 9px; }
.audit-row .cell-lead .meta b { font-weight: 600; }
.audit-row .cell-lead .meta span { color: var(--text-soft); font-size: 12px; }
.audit-avatar.sys {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
}
.audit-avatar.sys svg { width: 15px; height: 15px; }
/* verb chip — neutral by default, tinted green/red for create/destroy actions */
.audit-act {
  display: inline-block; white-space: nowrap;
  font-size: 12.5px; font-weight: 600; line-height: 1.4;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-main);
}
.audit-act.pos { background: var(--success-bg); border-color: transparent; color: var(--success-text); }
.audit-act.neg { background: var(--danger-bg); border-color: transparent; color: var(--danger-text); }
.audit-item-name { font-weight: 500; color: var(--text-main); }
.audit-item-id { font-family: var(--font-mono); font-size: 11.5px; }
.audit-caret {
  width: 15px; height: 15px; margin-left: 8px; vertical-align: middle;
  color: var(--text-soft); transition: transform 0.15s var(--ease, ease);
}
.audit-row[aria-expanded="true"] .audit-caret { transform: rotate(180deg); }
/* detail row — the diff of what actually changed */
.audit-detail > td { background: var(--surface); padding: 2px 16px 0; }
.audit-changes { padding: 12px 2px 16px; }
.audit-changes-head {
  margin: 0 0 9px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-soft);
}
.audit-change-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.audit-change-list li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; font-size: 13px;
}
.ac-field { min-width: 130px; font-weight: 600; color: var(--text-main); }
.ac-from { color: var(--text-soft); text-decoration: line-through; }
.ac-arrow { color: var(--text-soft); }
.ac-to { font-weight: 500; color: var(--text-main); }
.audit-more { margin: 9px 0 0; font-size: 12px; }

/* Filtered tables: keep hidden rows hidden even under the mobile card-table
   display override (which sets tr { display: grid }). */
.set-table tr[hidden] {
  display: none !important;
}

/* Responsive — rail collapses to a horizontal scroll bar above the content */
@media (max-width: 860px) {
  .settings-shell {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .settings-rail {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .settings-rail::-webkit-scrollbar {
    display: none;
  }
  .srail-item {
    flex: 0 0 auto;
    width: auto;
    border-radius: var(--radius-full);
    background: var(--white);
    border: 1px solid var(--border);
    padding: 8px 14px;
  }
  .srail-item.active {
    border-color: var(--primary);
  }
  .srail-item.active::before {
    display: none;
  }
}

/* =========================================================================
   Operations workspace consistency pass
   ========================================================================= */
.grid,
.page-grid,
.split {
  gap: 14px;
}
.panel-head {
  margin-bottom: 12px;
}
.toolbar {
  gap: 8px;
  margin-bottom: 12px;
}
.metric-card {
  min-height: 104px;
  padding: 15px;
}
.metric-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
}
.metric-card .value {
  font-size: 28px;
}
.data-card .hero-chip {
  border-radius: var(--radius-sm);
}
.set-row {
  padding: 12px 0;
}
.set-row .chip {
  border-radius: var(--radius-sm);
}
.kh-grid {
  gap: 12px;
  align-items: stretch;
}
.kh-editor-col {
  gap: 12px;
}
/* Wide monitors: sit the Markdown editor and its live preview side-by-side so the
   rendered output is co-visible with the cursor instead of stacked off-screen
   below the tall textarea. Narrower viewports keep the single-column stack
   (editor first), and the <=1080px block already forces one column. */
@media (min-width: 1440px) {
  .kh-editor-col {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: stretch;
  }
  .kh-editor-panel,
  .kh-preview-panel { min-width: 0; }
}
.kh-list-panel,
.kh-editor-panel,
.kh-preview-panel,
.kh-rail {
  box-shadow: none;
}
.kh-list-panel {
  padding: 14px;
}
.kh-page-list {
  gap: 0;
  max-height: calc(100vh - 240px);
  padding-right: 0;
  margin: 0 -6px;
}
.kh-page {
  min-height: 58px;
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  padding: 11px 10px;
}
.kh-page:hover {
  border-left-color: var(--primary);
  background: var(--primary-tint);
}
.kh-page.active {
  border-left-color: var(--primary);
  border-bottom-color: var(--border);
  background: var(--primary-light);
  color: var(--text-main);
}
.kh-page.active .kh-page-meta {
  color: var(--accent);
}
.kh-editor-fields textarea {
  min-height: calc(100vh - 360px);
}
.split.agent-cmd {
  gap: 14px;
  align-items: stretch;
}
.split.agent-cmd > .panel {
  padding: 18px;
}
#waPanelSection .data-card,
#agentsPanelSection .data-card,
.agent-compose {
  padding: 14px;
}
.agent-result-empty {
  background: var(--primary-tint);
}

/* =========================================================================
   OpenClaw Configuration view — Configure / Test / Activity
   Reuses the house tokens so light + dark themes are inherited.
   ========================================================================= */
/* (agent-launcher clearance now lives on .content's tail padding) */
/* JS toggles `.hidden` on .btn / .oc-switch controls (WhatsApp connect/unlink/auto-reply
   and the tab panels). Author `display` on those classes outranks the UA [hidden] rule,
   so force it within this view. */
.oc-config [hidden] { display: none !important; }

/* Status bar: always-visible runtime health + the one action-required queue */
.oc-statusbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.oc-rt-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; padding: 8px 14px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); }
.oc-rt-chip svg { width: 15px; height: 15px; }
.oc-rt-chip.is-on { color: var(--success-text); background: var(--success-bg); border-color: transparent; }
.oc-rt-chip.is-idle { color: var(--warning-text); background: var(--warning-bg); border-color: transparent; }
.oc-rt-chip.is-off { color: var(--neutral-text); background: var(--neutral-bg); border-color: transparent; }
.oc-attn { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; padding: 8px 14px; border-radius: var(--radius-full); border: 1px solid var(--warning); background: var(--warning-bg); color: var(--warning-text); transition: all 0.16s var(--ease); }
.oc-attn svg { width: 15px; height: 15px; }
.oc-attn:hover { transform: translateY(-1px); filter: brightness(0.99); }

/* Segmented tab control */
.oc-tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 18px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.oc-tabs::-webkit-scrollbar { display: none; }
.oc-tab { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; border: none; background: transparent; color: var(--text-muted); font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: var(--radius-sm); transition: all 0.16s var(--ease); }
.oc-tab svg { width: 16px; height: 16px; }
.oc-tab:hover { color: var(--text-main); }
.oc-tab.active { background: var(--white); color: var(--accent); box-shadow: var(--shadow-sm); }
.oc-tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); margin-left: 1px; flex: none; }

/* Tab panels + layout grids */
.oc-tabpanel { animation: oc-fade 0.2s var(--ease); }
.oc-tabpanel[hidden] { display: none; }
@keyframes oc-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.oc-config-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.oc-test-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.oc-test-grid .oc-span { grid-column: 1 / -1; }
.oc-activity-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }

/* Runtime meta strip */
.oc-rt-line { margin: -6px 0 12px; }
.oc-meta { display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 0 0 16px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius-md); }
.oc-meta-item { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.oc-meta-item span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-soft); font-weight: 700; }
.oc-meta-item b { font-size: 13px; color: var(--text-main); font-weight: 700; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Agent roster cards */
.oc-agents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.oc-agent .dc-head { display: flex; align-items: center; gap: 9px; }
.oc-agent-ic, .oc-run-ic { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--primary-light); color: var(--accent); flex: none; }
.oc-agent-ic { width: 30px; height: 30px; }
.oc-agent-ic svg { width: 16px; height: 16px; }
.oc-run-ic { width: 24px; height: 24px; }
.oc-run-ic svg { width: 13px; height: 13px; }
.oc-agent-chips { margin-top: 8px; }
.oc-agent-chips .hero-chip svg { width: 12px; height: 12px; vertical-align: -0.12em; }
.oc-agent .oc-test-agent { margin-top: 10px; }

/* Form helpers */
.oc-panel-sub { margin: -8px 0 14px; font-size: 13px; }
.oc-form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Accessible toggle switch (replaces the raw, distorted checkbox) */
.oc-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text-main); }
.oc-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; margin: 0; }
.oc-switch-track { position: relative; width: 42px; height: 24px; border-radius: var(--radius-full); background: var(--border-strong); transition: background 0.18s var(--ease); flex: none; }
.oc-switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--white); box-shadow: var(--shadow-sm); transition: transform 0.18s var(--ease); }
.oc-switch input:checked + .oc-switch-track { background: var(--primary-dark); }
.oc-switch input:checked + .oc-switch-track::after { transform: translateX(18px); }
.oc-switch input:focus-visible + .oc-switch-track { box-shadow: var(--ring); }

/* Responsive */
@media (max-width: 980px) {
  .oc-config-grid, .oc-test-grid, .oc-activity-grid { grid-template-columns: 1fr; }
  .oc-test-grid .oc-span { grid-column: auto; }
}
@media (max-width: 640px) {
  .oc-agents { grid-template-columns: 1fr; }
  .oc-tabs { width: 100%; }
  .oc-tab { flex: 1 1 0; justify-content: center; padding: 11px 8px; min-height: 44px; }
  .oc-config .btn, .oc-config input, .oc-config select, .oc-config textarea, .oc-config .btn.small { min-height: 44px; }
  .oc-statusbar { gap: 8px; }
  .oc-rt-chip, .oc-attn { flex: 1 1 auto; justify-content: center; }
}


/* =========================================================================
   Dark mode polish — neutralise the light decorative gradients and keep
   contrast on the accent chips / floating surfaces.
   ========================================================================= */
/* The forced light/dark marker classes live on <html>, so scope around them. */
@media (prefers-color-scheme: dark) {
  html:not(.light) body {
    background-image:
      radial-gradient(1100px 520px at 88% -8%, rgba(26, 74, 63, 0.35) 0, rgba(10, 23, 21, 0) 60%),
      radial-gradient(900px 600px at -6% 4%, rgba(18, 46, 40, 0.4) 0, rgba(10, 23, 21, 0) 55%);
  }
  html:not(.light) { color-scheme: dark; }
}
html.dark body {
  background-image:
    radial-gradient(1100px 520px at 88% -8%, rgba(26, 74, 63, 0.35) 0, rgba(10, 23, 21, 0) 60%),
    radial-gradient(900px 600px at -6% 4%, rgba(18, 46, 40, 0.4) 0, rgba(10, 23, 21, 0) 55%);
}
html.dark { color-scheme: dark; }
/* Forced-light beats the system-dark media query. */
html.light { color-scheme: light; }

/* =========================================================================
   === Unified Inbox redesign ===  (Qontak-style omnichannel, Woodlam brand)
   This view keeps both theme modes and the Woodlam green accent. Light follows
   the Qontak reference layout; dark reuses the same green information hierarchy.
   ========================================================================= */

body.wa-view {
  --primary: #2fc5a5;
  --primary-dark: #087e6b;
  --primary-light: #ddf7ec;
  --primary-tint: #f0faf6;
  --accent: #087e6b;
  --bg: #edf4f1;
  --bg-deep: #e4eee9;
  --surface: #f7fbfa;
  --white: #ffffff;
  --border: #dce8e3;
  --border-strong: #c9ddd5;
  --text-main: #1d2b2a;
  --text-muted: #586a65;
  --text-soft: #5d6e69;
  --shadow-card: 0 4px 14px rgba(20, 80, 70, 0.05);
  --shadow-floating: 0 16px 42px rgba(20, 80, 70, 0.12);
  --ring: 0 0 0 2px var(--white), 0 0 0 4px var(--primary);
  background: var(--bg);
  background-image: none;
}
@media (prefers-color-scheme: dark) {
  html:not(.light) body.wa-view {
    --primary: #2fc5a5;
    --primary-dark: #5fe0c2;
    --primary-light: #1a4a3f;
    --primary-tint: #122e28;
    --accent: #5fe0c2;
    --bg: #0f1f1c;
    --bg-deep: #0a1715;
    --surface: #162b27;
    --white: #1a302b;
    --border: #23423a;
    --border-strong: #2d5248;
    --text-main: #e1f0ec;
    --text-muted: #8a9e98;
    --text-soft: #84968e;
    --shadow-card: 0 12px 28px rgba(0, 0, 0, 0.22);
    --shadow-floating: 0 22px 54px rgba(0, 0, 0, 0.34);
    --ring: 0 0 0 2px var(--white), 0 0 0 4px var(--primary);
    background: var(--bg);
    background-image: none;
  }
}
html.dark body.wa-view {
  --primary: #2fc5a5;
  --primary-dark: #5fe0c2;
  --primary-light: #1a4a3f;
  --primary-tint: #122e28;
  --accent: #5fe0c2;
  --bg: #0f1f1c;
  --bg-deep: #0a1715;
  --surface: #162b27;
  --white: #1a302b;
  --border: #23423a;
  --border-strong: #2d5248;
  --text-main: #e1f0ec;
  --text-muted: #8a9e98;
  --text-soft: #84968e;
  --shadow-card: 0 12px 28px rgba(0, 0, 0, 0.22);
  --shadow-floating: 0 22px 54px rgba(0, 0, 0, 0.34);
  --ring: 0 0 0 2px var(--white), 0 0 0 4px var(--primary);
  background: var(--bg);
  background-image: none;
}


/* ----------------------------------------------------------------------- */
/* Inbox shell — claim the full content height (reuse the wa-view full-bleed). */
/* ----------------------------------------------------------------------- */
body.wa-view .content {
  height: 100vh;
  padding: 0;
  min-height: 0;
  overflow: hidden;
}
body.wa-view .topbar {
  flex: 0 0 auto;
  min-height: 68px;
  margin: 0;
  padding: 10px 22px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
body.wa-view .topbar h1 {
  font-size: 22px;
  letter-spacing: 0;
}
body.wa-view .topbar p {
  max-width: 560px;
  margin-top: 2px;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.wa-view .topbar .crumbs {
  margin-bottom: 2px;
  letter-spacing: 0;
}
body.wa-view .topbar-actions .search-box input {
  width: 270px;
  height: 40px;
  border-radius: var(--radius-sm);
}
body.wa-view #view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}
body.wa-view #view > .ix {
  animation: none;
}
.ix {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  width: 100%;
}
.ix-grid {
  display: grid;
  grid-template-columns: 340px minmax(420px, 1fr) 332px;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--white);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}
.ix-grid > * {
  min-height: 0;
  min-width: 0;
}

/* ----------------------------------------------------------------------- */
/* Column 1 — thread list                                                  */
/* ----------------------------------------------------------------------- */
.ix-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.ix-list-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 14px 16px 10px;
  flex: 0 0 auto;
}
.ix-list-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text-main);
}
.ix-list-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ix-sort {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 11px;
  cursor: pointer;
}
.ix-sort svg {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}
.ix-sort select {
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  appearance: none;
  cursor: pointer;
}
.ix-search {
  padding: 0 16px 10px;
  flex: 0 0 auto;
}
.ix-search .search-box {
  width: 100%;
}
.ix-search .search-box input {
  width: 100%;
  border-radius: var(--radius-full);
  background: var(--white);
}
.ix-filters {
  display: flex;
  /* One horizontally scrollable row — .chip-bar's wrap would otherwise stack
     the six status chips into two rows on phones. */
  flex-wrap: nowrap;
  gap: 7px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  /* Same scroll affordance as the AI chips: fade the clipped edge. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.ix-filters::-webkit-scrollbar { display: none; }
.ix-filters .chip {
  flex: 0 0 auto;
  padding: 5px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}
.ix-threads {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
/* Rows must never flex-shrink to fit the viewport — the list scrolls instead.
   Critical for the mobile swipe wrapper: its overflow:hidden zeroes the
   automatic minimum size, so with enough chats every row collapsed to ~0px
   and the list looked empty. */
.ix-threads > .ix-thread,
.ix-threads > .ix-thread-swipe,
.ix-threads > .ix-empty {
  flex: 0 0 auto;
}
.ix-threads::-webkit-scrollbar { width: 8px; }
.ix-threads::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

/* ---- Thread card ---- */
.ix-thread {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  cursor: pointer;
  position: relative;
  transition: background 0.16s var(--ease);
  overflow: visible;
}
.ix-thread:hover {
  background: var(--primary-tint);
}
.ix-thread.is-active {
  background: var(--primary-light);
}
.ix-thread.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: var(--radius-full);
  background: var(--primary);
}
.ix-thread:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
/* Avatar with channel ring */
.ix-avatar {
  position: relative;
  flex: 0 0 auto;
  border-radius: var(--radius-full);
}
.ix-avatar .avatar {
  display: block;
}
.ix-avatar.ch-whatsapp { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px #25d366; }
.ix-avatar.ch-qontak   { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--primary); }
.ix-avatar.ch-default  { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--border-strong); }
.ix-avatar.ch-instagram {
  box-shadow: 0 0 0 2px var(--white);
  outline: 2px solid transparent;
  background:
    linear-gradient(var(--white), var(--white)) padding-box,
    linear-gradient(45deg, #f9ce34, #ee2a7b 45%, #6228d7) border-box;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
}
.ix-thread-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ix-thread-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.ix-thread-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ix-thread-time {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}
.ix-thread-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.ix-reply-arrow {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--accent);
}
.ix-reply-arrow svg {
  width: 13px;
  height: 13px;
}
.ix-thread-sub {
  font-size: 11.5px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ix-thread-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}
.ix-unread {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  flex: 0 0 auto;
}

/* ---- Status pill (tone-* built from the existing status tokens) ---- */
.ix-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.ix-status::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.ix-status.tone-info     { background: var(--info-bg);    color: var(--info-text); }
.ix-status.tone-warning  { background: var(--warning-bg); color: var(--warning-text); }
.ix-status.tone-success  { background: var(--success-bg); color: var(--success-text); }
.ix-status.tone-danger   { background: var(--danger-bg);  color: var(--danger-text); }
.ix-status.tone-neutral  { background: var(--neutral-bg); color: var(--neutral-text); }
.ix-provider-status {
  color: var(--text-muted);
  font-weight: 700;
  text-transform: capitalize;
}

/* ----------------------------------------------------------------------- */
/* Column 2 — stage (conversation)                                          */
/* ----------------------------------------------------------------------- */
.ix-stage {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  min-width: 0;
}
/* Action labels collapse to icons on narrow screens (see media query). */
.ix-stage-actions .btn { white-space: nowrap; }
.ix-stage-id { min-width: 0; }
.ix-stage-id b,
.ix-stage-id span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ix-stage-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 18px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
.ix-stage-head > .avatar {
  flex: 0 0 auto;
}
.ix-back {
  display: none;
  flex: 0 0 auto;
}
.ix-stage-id {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ix-stage-id b {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ix-stage-id span {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}
.ix-stage-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ix-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--border) 70%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    var(--surface);
}
.ix-scroll::-webkit-scrollbar { width: 8px; }
.ix-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
/* Centered date pill */
.ix-daydiv {
  align-self: center;
  margin: 10px 0;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  background: var(--white);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}
/* Message row + bubbles */
.ix-msg {
  display: flex;
  max-width: 74%;
}
.ix-msg.inbound {
  align-self: flex-start;
}
.ix-msg.outbound {
  align-self: flex-end;
  justify-content: flex-end;
}
.ix-bubble {
  position: relative;
  padding: 8px 12px 6px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.ix-msg.inbound .ix-bubble {
  background: var(--white);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-top-left-radius: var(--radius-sm);
}
.ix-msg.outbound .ix-bubble {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-top-right-radius: var(--radius-sm);
}
.ix-bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}
.ix-bubble-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.ix-bubble-time {
  display: block;
  margin-top: 2px;
  text-align: right;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-soft);
}
.ix-msg.outbound .ix-bubble-time {
  color: var(--primary-dark);
  opacity: 0.7;
}
.ix-tick {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 3px;
  color: var(--accent);
}
.ix-tick svg {
  width: 14px;
  height: 14px;
}
/* Document / file bubble */
.ix-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  padding: 9px 11px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}
.ix-doc-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--primary-tint);
  color: var(--accent);
}
.ix-doc-icon svg { width: 18px; height: 18px; }
.ix-doc-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ix-doc-dl {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  transition: background 0.16s;
}
.ix-doc-dl:hover { background: var(--primary-tint); }
.ix-doc-dl svg { width: 16px; height: 16px; }

/* Image / media bubble */
.ix-media {
  display: grid;
  gap: 7px;
  margin-top: 5px;
}
.ix-media-link {
  display: block;
  max-width: min(320px, 62vw);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.ix-media-link:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.ix-media-img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}
.ix-media-caption {
  margin-top: 0;
}
.ix-admin-panel {
  display: grid;
  gap: 8px;
  margin: 10px 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.ix-admin-head,
.ix-merge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ix-admin-head {
  justify-content: space-between;
}
.ix-admin-head b {
  font-size: 12px;
}
.ix-admin-head > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}
/* (The inbox Qontak sync panel and its .ix-sync-* styles were removed — the
   server auto-syncs; manual pulls live in Settings → Integrations.) */
.ix-merge-row {
  min-width: 0;
  justify-content: space-between;
}
.ix-merge-row > div {
  min-width: 0;
  display: grid;
}
.ix-merge-row b,
.ix-merge-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ix-merge-row span {
  font-size: 11.5px;
  color: var(--text-muted);
}
.ix-attachments {
  display: grid;
  gap: 8px;
  margin-top: 5px;
}
.ix-attach-card {
  max-width: min(340px, 66vw);
}
.ix-attach-video-card {
  display: grid;
  gap: 7px;
}
.ix-attach-video {
  display: block;
  width: min(340px, 66vw);
  aspect-ratio: 16 / 9;
  max-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #101918;
}
.ix-attach-audio-card {
  display: grid;
  gap: 8px;
  width: min(340px, 66vw);
}
.ix-attach-audio {
  width: 100%;
  min-width: 220px;
}
.ix-attach-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* ---- Composer ---- */
.ix-compose {
  border-top: 1px solid var(--border);
  background: var(--white);
  padding: 10px 14px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  /* Stretch children to full width. The shared .wa-composer sets
     align-items:center; without this the column children (AI-chip row + the
     compose bar) shrink to content and sit centered, leaving the message input
     far narrower than the stage. */
  align-items: stretch;
  gap: 8px;
}
.ix-ai-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
  /* Fade the right edge so a partially visible chip reads as scrollable. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.ix-ai-chips::-webkit-scrollbar { display: none; }
.ix-ai-chips:empty { display: none; }
.ix-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary-tint);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.ix-chip:hover {
  background: var(--primary-light);
}
.ix-chip > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ix-chip-conf {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--primary-dark);
  background: var(--white);
  border-radius: var(--radius-full);
  padding: 1px 6px;
}
.ix-compose-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.ix-compose-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  padding-bottom: 3px;
}
.ix-compose-tools .icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--text-soft);
}
.ix-compose-tools .icon-btn:hover {
  background: var(--primary-tint);
  color: var(--accent);
}
.ix-compose-input {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  min-height: 44px;
  height: 44px;
  max-height: 108px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 22px;
  color: var(--text-main);
  transition: border-color 0.16s, box-shadow 0.16s;
}
.ix-compose-input::placeholder { color: var(--text-soft); }
.ix-compose-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.ix-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: transform 0.14s var(--ease), filter 0.14s;
}
.ix-send:hover { filter: brightness(1.03); }
.ix-send:active { transform: scale(0.94); }
.ix-send:focus-visible { outline: none; box-shadow: var(--ring); }
.ix-send svg { width: 19px; height: 19px; }

/* ----------------------------------------------------------------------- */
/* Column 3 — context panel                                                 */
/* ----------------------------------------------------------------------- */
.ix-context {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}
.ix-context::-webkit-scrollbar { width: 8px; }
.ix-context::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
.ix-context-head {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.ix-context-head .avatar { flex: 0 0 auto; }
.ix-context-head .ix-id {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ix-context-head b {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ix-context-head span {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}
.ix-more {
  margin-left: auto;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}
.ix-more:hover { background: var(--primary-tint); color: var(--accent); }
.ix-more svg { width: 18px; height: 18px; }

.ix-ai-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}
.ix-ai-title svg {
  width: 16px;
  height: 16px;
}
.ix-ai-title .badge {
  margin-left: auto;
}

/* AI assist card */
.ix-ai-card {
  margin: 14px 16px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--primary-tint);
  border: 1px solid var(--primary-light);
}
.ix-ai-card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}
.ix-ai-card-head svg { width: 16px; height: 16px; }
.ix-ai-card-head .spacer { flex: 1 1 auto; }
.ix-ai-card p {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-muted);
}
.ix-ai-card .btn { width: 100%; justify-content: center; }
.ix-ai-card .btn + .btn { margin-top: 8px; }

/* Provenance tag: real agent draft vs instant rule-based suggestion. */
.ix-ai-src {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  white-space: nowrap;
}
.ix-ai-src.is-agent {
  color: var(--primary-dark);
  border-color: var(--primary-light);
  background: var(--white);
}
html.dark .ix-ai-src.is-agent { color: var(--accent); }
/* The agent-written reply preview inside the card. */
.ix-ai-card .ix-ai-draft {
  margin: 0 0 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--white);
  border: 1px solid var(--primary-light);
  color: var(--text-main);
  font-size: 12.5px;
  line-height: 1.55;
}
.ix-ai-drafting { display: flex; align-items: center; gap: 6px; }
.ix-ai-drafting svg { width: 13px; height: 13px; animation: ix-ai-spin 1.2s linear infinite; }
@keyframes ix-ai-spin { to { transform: rotate(360deg); } }
.ix-chip-conf.is-agent { color: var(--primary-dark); }
html.dark .ix-chip-conf.is-agent { color: var(--accent); }

/* Collapsible sections */
.ix-section {
  border-top: 1px solid var(--border);
}
.ix-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 13px 16px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--text-soft);
}
.ix-section-head:hover { color: var(--accent); }
.ix-section-head .ix-chev {
  margin-left: auto;
  display: inline-flex;
  color: var(--text-soft);
  transition: transform 0.2s var(--ease);
}
.ix-section-head .ix-chev svg { width: 16px; height: 16px; }
.ix-section.is-open .ix-section-head .ix-chev {
  transform: rotate(180deg);
}
.ix-section-body {
  display: none;
  padding: 0 16px 14px;
}
.ix-section.is-open .ix-section-body {
  display: block;
}
/* Key/value rows */
.ix-kv {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.ix-kv > div {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  align-items: baseline;
}
.ix-kv dt {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}
.ix-kv dd {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-word;
}
.ix-kv dd .badge { vertical-align: middle; }
/* SLA line / generic body text inside a section */
.ix-section-body > p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-muted);
}
/* Tags */
.ix-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.ix-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  background: var(--primary-tint);
  border: 1px solid var(--primary-light);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
}
/* Assignee row */
.ix-assignee {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}
.ix-assignee .avatar { flex: 0 0 auto; }
.ix-context-foot {
  margin-top: auto;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}
.ix-context-foot .btn { width: 100%; justify-content: center; }

/* Empty state wrapper */
.ix-empty {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 32px;
  background: var(--surface);
}

/* ----------------------------------------------------------------------- */
/* Responsive                                                              */
/* ----------------------------------------------------------------------- */
/* ≤1200px — drop the context panel (2-column: list + stage). */
@media (max-width: 1200px) {
  .ix-grid {
    grid-template-columns: 320px minmax(0, 1fr);
  }
  .ix-context {
    display: none;
  }
}
/* ≤860px — collapse to a single column so it fits the existing mobile shell.
   Show the stage when a thread is open (.ix-grid.has-active), else the list. */
@media (max-width: 860px) {
  body.wa-view .content {
    height: 100dvh;
    padding: 0 0 calc(86px + var(--safe-bottom));
    overflow: hidden;
  }
  body.wa-view .topbar {
    min-height: 60px;
    padding: 9px 14px;
  }
  body.wa-view .topbar p,
  body.wa-view .topbar .crumbs {
    display: none;
  }
  body.wa-view .topbar-actions .search-box {
    display: none;
  }
  .ix {
    display: block;
  }
  .ix-grid {
    grid-template-columns: 1fr;
    height: 100%;
    min-height: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }
  .ix-list {
    border-right: 0;
  }
  /* Match the app-wide 16px zoom-prevention guard so tapping the reply field
     does not auto-zoom on iOS Safari (the .ix-compose-input class out-specifies
     the global element selector at desktop, so re-assert it here for mobile). */
  .ix-compose-input {
    font-size: 16px;
  }
  .ix-compose {
    padding: 8px 10px calc(10px + var(--safe-bottom));
    gap: 7px;
  }
  .ix-ai-chips {
    gap: 6px;
  }
  .ix-compose-bar {
    gap: 6px;
  }
  .ix-compose-tools {
    gap: 0;
    padding-bottom: 4px;
  }
  .ix-compose-tools .icon-btn {
    /* Comfortable touch targets (was 32x36). */
    width: 40px;
    height: 44px;
  }
  .ix-send {
    width: 46px;
    height: 46px;
  }
  /* The page header already says "Inbox" — drop the duplicate list title and
     tighten the row so chats start a full row earlier. */
  .ix-list-head {
    min-height: 0;
    padding: 4px 16px 8px;
  }
  .ix-list-head .ix-list-title {
    display: none;
  }
  .ix-list-tools {
    width: 100%;
    justify-content: flex-end;
  }
  /* Icon-only Assign/Resolve keep the contact name readable. */
  .ix-stage-actions .ix-action-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .ix-stage-actions .btn {
    padding-inline: 10px;
  }
  .ix-chip {
    max-width: 72vw;
  }
  .ix-grid.has-active .ix-list {
    display: none;
  }
  .ix-grid:not(.has-active) .ix-stage {
    display: none;
  }
  .ix-back {
    display: grid;
  }
  .ix-back svg {
    transform: rotate(180deg);
  }
  .ix-msg {
    max-width: 86%;
  }
  .ix-context {
    display: none;
  }
}

/* ----------------------------------------------------------------------- */
/* Dark-mode tweaks — tokens already cascade; only the hard-coded channel    */
/* rings need a darker inner halo so they read against the dark panel.       */
/* ----------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  html:not(.light) .ix-avatar.ch-whatsapp { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px #1f9d52; }
  html:not(.light) .ix-chip-conf { color: var(--accent); }
  html:not(.light) .ix-msg.outbound .ix-bubble { color: var(--text-main); }
  html:not(.light) .ix-msg.outbound .ix-bubble-time { color: var(--text-main); }
}
html.dark .ix-avatar.ch-whatsapp { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px #1f9d52; }
html.dark .ix-chip-conf { color: var(--accent); }
html.dark .ix-msg.outbound .ix-bubble { color: var(--text-main); }
html.dark .ix-msg.outbound .ix-bubble-time { color: var(--text-main); }

/* =========================================================================
   Outbound Sales — full-width queue, segment chips, filter bar, draft clamp
   ========================================================================= */
.outbound-head { align-items: center; }
.outbound-head .sub { font-weight: 600; }
.outbound-seg { margin: 4px 0 12px; }
.outbound-filter-bar {
  grid-template-columns: minmax(200px, 1.8fr) repeat(2, minmax(150px, 1fr));
}
.outbound-table table {
  table-layout: fixed;
  width: 100%;
  min-width: 0;
}
.outbound-table th:nth-child(1) { width: 17%; }
.outbound-table th:nth-child(2) { width: 12%; }
.outbound-table th:nth-child(3) { width: 14%; }
.outbound-table th:nth-child(4) { width: 28%; }
.outbound-table th:nth-child(5) { width: 10%; }
.outbound-table th:nth-child(6) { width: 19%; }
.outbound-sort-head {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}
.outbound-sort-head::after {
  content: "↕";
  color: var(--text-soft);
  font-size: 10px;
}
.outbound-sort-head.active {
  color: var(--text-main);
}
.outbound-sort-head.active::after {
  content: "↓";
  color: var(--accent);
}
.outbound-lead-cell .nv-ico {
  flex: 0 0 auto;
}
.outbound-stage {
  text-transform: capitalize;
}
.outbound-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.outbound-draft-cell {
  min-width: 0;
}
.outbound-date-cell {
  white-space: nowrap;
}
.outbound-table td.t-actions-cell {
  padding-inline: 3px;
}
.outbound-actions {
  display: grid;
  grid-template-columns: 64px repeat(3, 30px);
  align-items: center;
  justify-content: end;
  gap: 3px;
  white-space: nowrap;
}
.outbound-actions .btn.small {
  min-height: 32px;
  padding-inline: 8px;
}
.outbound-actions .ic {
  width: 14px;
  height: 14px;
}
.outbound-action-primary {
  inline-size: auto;
  min-inline-size: 64px;
  min-width: 64px !important;
  white-space: nowrap;
}
.outbound-action-icon {
  inline-size: 30px;
  min-inline-size: 30px;
  min-width: 30px !important;
  padding-inline: 0 !important;
  justify-content: center;
}
.outbound-action-label {
  display: none;
}
.outbound-delete-btn {
  color: var(--danger);
}
html.dark .outbound-delete-btn {
  color: #ff9c9c;
}
@media (max-width: 1180px) {
  .outbound-filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .outbound-filter-bar { grid-template-columns: 1fr; }
  .mobile-card-table.outbound-table table {
    min-width: 0;
    table-layout: auto;
  }
  .mobile-card-table.outbound-table tbody {
    gap: 12px;
  }
  .mobile-card-table.outbound-table tr {
    padding: 14px;
  }
  .mobile-card-table.outbound-table td {
    display: block;
    min-height: 0;
    padding: 5px 0;
  }
  .mobile-card-table.outbound-table td::before {
    content: none;
  }
  .mobile-card-table.outbound-table td + td {
    border-top: 0;
  }
  .mobile-card-table.outbound-table .outbound-lead-cell {
    align-items: flex-start;
  }
  .mobile-card-table.outbound-table td:nth-child(4) {
    border-top: 1px solid var(--border);
    margin-top: 6px;
    padding-top: 12px;
  }
  .mobile-card-table.outbound-table .outbound-date-cell {
    color: var(--text-soft);
    font-size: 12px;
  }
  .mobile-card-table.outbound-table td.t-actions-cell {
    padding-top: 10px;
  }
  .mobile-card-table.outbound-table .outbound-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: stretch;
    white-space: normal;
  }
  .mobile-card-table.outbound-table .outbound-actions .btn {
    flex: 1 1 128px;
  }
  .mobile-card-table.outbound-table .outbound-action-icon {
    inline-size: auto;
    min-inline-size: 44px;
    min-width: 44px !important;
    gap: 6px;
    padding-inline: 10px !important;
  }
  .mobile-card-table.outbound-table .outbound-action-label {
    display: inline;
  }
  .btn.small { min-height: 40px; }
}
.draft-preview {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  margin: 0 0 4px;
}
.draft-preview.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.draft-toggle {
  border: none;
  background: none;
  padding: 0;
  margin: 0 0 6px;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.draft-toggle:hover { text-decoration: underline; }
.draft-safety { font-size: 12px; }
.dc-actions { margin: 10px 0 0; }
.skeleton-card .sk-line,
.skeleton-card .sk-block,
.skeleton-card .sk-btn { border-radius: var(--radius-sm); margin-bottom: 10px; }
.skeleton-card .sk-line { height: 12px; }
.skeleton-card .sk-block { height: 54px; }
.skeleton-card .sk-btn { height: 30px; }

/* =========================================================================
   MOBILE-NATIVE OVERHAUL (2026-06-07)
   Each concern owns one banner sub-section below. Mobile-only rules belong
   inside the @media (max-width: 920px) block already present above; the
   sub-sections here are for net-new selectors so parallel edits never collide.
   ========================================================================= */

/* ----- core (shell: header collapse, single FAB, More sheet) ----- */
/* Kill the 300ms tap delay + grey tap flash on interactive elements (native feel). */
button, a, [role="button"], .data-card, .metric-card, .ix-thread, .ms-row, .chip, .nav button, .mobile-bottom-nav button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Settings section strip: fade the right edge on phones to signal it scrolls. */
@media (max-width: 860px) {
  .settings-rail {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }
}
/* Desktop keeps the always-on search box; the mobile-only controls stay hidden. */
.search-toggle,
.header-action { display: none; }

@media (max-width: 920px) {
  /* Breadcrumb is redundant on phones (the bottom nav + title already locate you). */
  .topbar .crumbs { display: none; }

  /* Global search collapses to a magnifier; it expands on tap (.search-active). */
  .topbar .search-toggle { display: inline-flex; }
  .topbar .header-action { display: inline-flex; }
  .topbar .search-box { display: none; }
  .topbar.search-active .topbar-actions { flex-wrap: wrap; row-gap: 10px; }
  .topbar.search-active .search-box {
    display: flex;
    order: 9;          /* drop the expanded field onto its own full-width row */
    flex: 1 1 100%;
    min-width: 0;
  }
  .topbar.search-active .search-box input { width: 100%; min-width: 0; }
  .topbar.search-active .search-toggle[aria-expanded="true"] {
    background: var(--primary-light);
    color: var(--accent);
  }

  /* Large-title -> condensed bar on scroll: drop the subtitle, shrink the title,
     and let the title share one compact row with the action icons. */
  .topbar.is-condensed { min-height: 0; margin-bottom: 12px; }
  .topbar.is-condensed > div { flex: 1 1 auto; min-width: 0; }
  .topbar.is-condensed h1 {
    font-size: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar.is-condensed p { display: none; }
  .topbar.is-condensed .topbar-actions { width: auto; }
}

/* Mobile "More" nav sheet: grouped, compact rows. */
.ms-group { margin-bottom: 10px; }
.ms-group-label {
  margin: 4px 4px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.ms-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.ms-row svg { width: 19px; height: 19px; flex: none; color: var(--text-muted); }
.ms-row:active { background: var(--surface-2, rgba(0,0,0,0.05)); }
.ms-row.active { background: var(--primary-light); color: var(--accent); }
.ms-row.active svg { color: var(--accent); }
.ms-full { margin-top: 4px; color: var(--text-muted); }
/* Sheet header: who is signed in (the topbar profile pill is hidden ≤640px). */
.ms-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.ms-identity .ms-id-meta {
  min-width: 0;
  display: grid;
  gap: 1px;
}
.ms-identity b {
  font-size: 15px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ms-identity span {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: capitalize;
}
/* Dark-mode row reuses the profile-menu switch visuals. */
.ms-toggle .um-switch { margin-left: auto; }
.ms-toggle[aria-checked="true"] .um-switch { background: var(--primary-dark); }
.ms-toggle[aria-checked="true"] .um-switch::after { transform: translateX(14px); }

/* ----- filters (followups / incidents / outbound filter sheet) ----- */

@media (min-width: 921px) {
  details.task-filters > summary.task-filters-summary { display: none; }
  details.task-filters:not([open]) > .task-filter-bar { display: grid; }
}

@media (max-width: 920px) {
  details.task-filters > summary.task-filters-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--white);
    color: var(--text-muted);
    font-weight: 700;
    cursor: pointer;
    list-style: none;
  }

  details.task-filters > summary.task-filters-summary::-webkit-details-marker {
    display: none;
  }

  details.task-filters:not([open]) > .task-filter-bar {
    display: none;
  }
}

/* ----- lists (swipe actions, pull-to-refresh) -----
   The old #leadTable compact-row layer lived here; it has been removed. Its
   ID-level specificity silently overrode the native.css leads card design
   (forcing td:display:block, killing the data-label rows, hiding PIC/Sync),
   which produced the truncated hybrid the 2026-06-12 mobile audit flagged.
   public/native.css >>> PAGE: leads <<< owns the mobile leads layout now. */

@media (max-width: 920px) {
  .ix-threads .ix-thread-swipe {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
    touch-action: pan-y;
  }

  .ix-threads .ix-thread-swipe .swipe-content {
    width: 100%;
    border-radius: inherit;
    /* The .ix-thread button is transparent; give the sliding layer an opaque
       surface so the actions stay hidden behind it until swiped. */
    background: var(--surface);
  }
  .ix-threads .ix-thread-swipe .swipe-content.is-active { background: var(--primary-light); }

  .ix-threads .ix-thread-swipe .swipe-actions {
    border-radius: inherit;
    overflow: hidden;
  }

  .ix-threads .ix-thread-swipe .swipe-actions button {
    width: 60px;
    min-width: 0;
    padding: 0 8px;
    justify-content: center;
    white-space: nowrap;
  }

  .ix-threads .ix-thread-swipe .swipe-actions button:only-child {
    width: 120px;
  }
}

/* ===== WhatsApp-native chat list (mobile) ===========================
   Flat full-width rows with an indented divider, a large circular avatar,
   a 2-line name/preview layout, WhatsApp-green unread badges, and a relative
   timestamp. Status pills are decluttered to the actionable states only
   (Needs reply / Review / Syncing) — assigned/unassigned/resolved drop the
   pill the way WhatsApp shows no chrome for a normal chat. Desktop (the
   3-column workspace) is untouched. */
@media (max-width: 920px) {
  .ix-threads {
    padding: 8px 12px calc(12px + var(--safe-bottom));
    gap: 4px;
  }
  .ix-thread-swipe { border-radius: var(--radius-sm); }

  .ix-thread {
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    gap: 13px;
    align-items: center;
  }
  .ix-thread:hover,
  .ix-thread.is-active { background: transparent; }
  .ix-thread.is-active::before { display: none; }
  /* Hairline divider, indented past the avatar (WhatsApp style). */
  .ix-thread::after {
    content: "";
    position: absolute;
    left: 65px;
    right: 0;
    bottom: 0;
    height: 1px;
    background: var(--border);
  }

  /* Larger circular avatar. */
  .ix-thread .ix-avatar .avatar {
    width: 52px;
    height: 52px;
    font-size: 18px;
    line-height: 52px;
    display: grid;
    place-items: center;
  }

  /* Two-line grid: name | time  /  preview | (status + unread). */
  .ix-thread-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name time" "preview foot";
    column-gap: 10px;
    row-gap: 3px;
    align-items: center;
    max-width: 100%;
  }
  .ix-thread-top { display: contents; }
  .ix-thread-name { grid-area: name; font-size: 16px; font-weight: 600; }
  .ix-thread-time { grid-area: time; justify-self: end; font-size: 12px; }
  .ix-thread-preview { grid-area: preview; font-size: 13.5px; }
  .ix-thread-sub { display: none; }
  .ix-thread-foot { grid-area: foot; justify-self: end; margin-top: 0; gap: 6px; }

  /* Declutter: only actionable status keeps a (small) pill. */
  .ix-thread.st-neutral .ix-thread-foot .ix-status,
  .ix-thread.st-success .ix-thread-foot .ix-status { display: none; }
  .ix-thread-foot .ix-status { font-size: 10.5px; padding: 1px 7px; }

  /* WhatsApp-green unread badge; unread rows get a green time + bolder text. */
  .ix-thread .ix-unread {
    margin-left: 0;
    background: #25d366;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
  }
  .ix-thread.is-unread .ix-thread-name { font-weight: 700; }
  .ix-thread.is-unread .ix-thread-time { color: #1fa855; font-weight: 700; }
  .ix-thread.is-unread .ix-thread-preview { color: var(--text-main); }

  /* Email rows carry a subject line plus a status/counts cluster — give each
     its own full row so the meta stops colliding with the preview text. */
  .em-thread .ix-thread-main {
    grid-template-areas: "name time" "subject subject" "preview preview" "foot foot";
  }
  .em-thread .em-subject { grid-area: subject; }
  .em-thread .ix-thread-preview { grid-area: preview; }
  .em-thread .ix-thread-foot { grid-area: foot; justify-self: start; }
  .em-thread .em-thread-counts { margin-left: 0; }
}

/* Immersive full-screen chat on phones: when a thread is open the global topbar,
   bottom nav, and agent launcher step aside so the conversation owns the screen.
   (body.wa-thread-open is only set in compact mode — see renderInbox.) */
@media (max-width: 860px) {
  body.wa-thread-open .topbar,
  body.wa-thread-open .mobile-bottom-nav,
  body.wa-thread-open .agent-chat { display: none; }
  body.wa-thread-open.wa-view .content { padding-bottom: 0; }
  body.wa-thread-open .ix-stage-head { padding-top: calc(12px + var(--safe-top)); }
}

/* =========================================================================
   Overview dashboard — chat-activity home. Full-width stacked rows: KPI tiles,
   two charts, then recent conversations beside quick actions, channel status,
   and the assistant. (Replaces the old KPI + rail + briefing layout.)
   ========================================================================= */
.overview-home {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.overview-metrics {
  display: grid;
  /* Auto-fit: 6-up on wide screens, 3+3 when cards would otherwise cramp and
     wrap their labels (e.g. "Messages Today" at 1280px). */
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
}
.overview-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.overview-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.overview-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* charts */
.ov-chart-panel { display: flex; flex-direction: column; }
.ov-chart { margin-top: 4px; width: 100%; }
.ch-svg { width: 100%; height: auto; display: block; overflow: visible; }
.ch-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.ch-axis { fill: var(--text-soft); font-size: 11px; font-family: var(--font-sans); }
.ch-bar { transition: opacity 0.16s var(--ease); }
.ov-chart-panel:hover .ch-bar { opacity: 0.9; }
.ch-legend { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.ch-legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.ch-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* recent conversations */
.ov-conv-list { display: flex; flex-direction: column; }
.ov-conv {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  padding: 12px 4px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.14s var(--ease);
}
.ov-conv:first-child { border-top: 0; }
.ov-conv:hover { background: var(--surface); }
.ov-conv .avatar { flex: none; }
.ov-conv-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 3px; }
.ov-conv-top { display: flex; align-items: baseline; gap: 8px; }
.ov-conv-top b { font-size: 14px; color: var(--text-main); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-conv-top time { margin-left: auto; flex: none; font-size: 11.5px; color: var(--text-soft); }
.ov-conv-sub { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ov-conv-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex: none; }
.ov-conv-preview { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ov-conv-chan {
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: capitalize;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 9px;
}

/* quick actions */
.ov-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.ov-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-main);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s var(--ease), border-color 0.14s var(--ease), background 0.14s var(--ease);
}
.ov-action:hover { transform: translateY(-2px); border-color: var(--primary); background: var(--primary-tint); }
.ov-action-ic {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--accent);
}
.ov-action-ic svg { width: 18px; height: 18px; }

/* channel status */
.ov-channels { display: flex; flex-direction: column; gap: 4px; }
.ov-channel { display: flex; align-items: center; gap: 11px; padding: 10px 4px; border-top: 1px solid var(--border); }
.ov-channel:first-child { border-top: 0; }
.ov-channel-ic {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
}
.ov-channel-ic svg { width: 17px; height: 17px; }
.ov-channel-ic.on { background: var(--primary-light); color: var(--accent); }
.ov-channel-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
.ov-channel-main b { font-size: 13.5px; color: var(--text-main); font-weight: 700; }
.ov-channel-main span { font-size: 11.5px; color: var(--text-soft); text-transform: capitalize; }
.ov-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.ov-dot.on { background: var(--success-text, #16a34a); }
.ov-dot.off { background: var(--warning-text, #b45309); }

@media (max-width: 1080px) {
  .overview-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
  .overview-home { gap: 12px; overflow-x: clip; }
  .overview-charts { grid-template-columns: 1fr; gap: 12px; }
  .overview-bottom { grid-template-columns: 1fr; gap: 12px; }
  .overview-side { gap: 12px; }
  .overview-home .panel { padding: 14px; }
  .overview-home .panel-head { gap: 8px; margin-bottom: 8px; }
  .overview-home .metric-card { min-height: 84px; padding: 12px; gap: 8px; }
  .overview-home .metric-card .value { font-size: 24px; }
  .overview-home .metric-icon { width: 32px; height: 32px; }
}
@media (max-width: 560px) {
  .overview-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ov-action { padding: 13px 8px; }
}

/* =========================================================================
   Live Map — full-bleed, Google-Maps-style shell. The map module claims the
   whole content area under a slim topbar (mirrors the wa-view full-bleed).
   ========================================================================= */
body.live-map-view .content {
  height: 100vh;
  height: 100dvh;
  padding: 0;
  min-height: 0;
  overflow: hidden;
}
body.live-map-view .topbar {
  flex: 0 0 auto;
  min-height: 0;
  margin: 0;
  padding: 10px 22px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
body.live-map-view .topbar h1 {
  font-size: 19px;
  letter-spacing: 0;
  line-height: 1.2;
}
body.live-map-view .topbar p { display: none; }
body.live-map-view .topbar .crumbs { margin-bottom: 1px; }
body.live-map-view #view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 0;
}
body.live-map-view #view > * {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  animation: none;
}

@media (max-width: 920px) {
  /* Immersive on phones — the map fills the viewport and the floating bottom
     nav / search sit over it (Google-Maps style). The duplicated header text is
     dropped so the canvas gets the full height. */
  body.live-map-view .content {
    padding: 0;
  }
  body.live-map-view .topbar {
    padding: 8px 14px;
  }
  body.live-map-view .topbar > div:first-child { display: none; }
  body.live-map-view .topbar-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }
}

/* === Analytics === */
.analytics-page {
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
  overflow-x: clip;
}

.analytics-page .an-range {
  display: inline-flex;
  gap: 4px;
  width: max-content;
  max-width: 100%;
  padding: 4px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.analytics-page .an-range::-webkit-scrollbar {
  display: none;
}
.analytics-page .an-range-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.analytics-page .an-range-btn:hover {
  color: var(--text-main);
  background: var(--primary-tint);
}
.analytics-page .an-range-btn.active,
.analytics-page .an-range-btn[aria-pressed="true"] {
  background: var(--primary);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}
.analytics-page .an-range-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
@media (prefers-color-scheme: dark) {
  html:not(.light) .analytics-page .an-range-btn.active,
  html:not(.light) .analytics-page .an-range-btn[aria-pressed="true"] {
    color: var(--text-inverse);
  }
}
html.dark .analytics-page .an-range-btn.active,
html.dark .analytics-page .an-range-btn[aria-pressed="true"] {
  color: var(--text-inverse);
}

.analytics-page .an-tabs {
  display: inline-flex;
  gap: 4px;
  width: max-content;
  max-width: 100%;
  margin-bottom: 0;
  padding: 4px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.analytics-page .an-tabs::-webkit-scrollbar {
  display: none;
}
/* Phones: tabs are primary navigation — wrap into rows instead of hiding the
   tail of the strip behind an invisible horizontal scroll. */
@media (max-width: 920px) {
  .analytics-page .an-tabs {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    overflow-x: visible;
  }
  .analytics-page .an-tab {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 44px;
  }
}
.analytics-page .an-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.analytics-page .an-tab svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.analytics-page .an-tab:hover {
  color: var(--text-main);
}
.analytics-page .an-tab.active,
.analytics-page .an-tab[aria-selected="true"] {
  background: var(--white);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.analytics-page .an-tab:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.analytics-page .an-panel {
  display: grid;
  gap: 18px;
  min-width: 0;
  animation: an-fade 0.2s var(--ease);
}
.analytics-page .an-panel[hidden] {
  display: none;
}
@keyframes an-fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.analytics-page .an-metrics {
  gap: 14px;
  align-items: stretch;
}
.analytics-page .an-metrics .metric-card {
  min-width: 0;
}

.analytics-page .an-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
  min-width: 0;
}
.analytics-page .an-grid > .panel,
.analytics-page .an-panel > .panel {
  min-width: 0;
  overflow: hidden;
}
.analytics-page .an-grid .barlist,
.analytics-page .an-panel .barlist {
  min-width: 0;
}
.analytics-page .an-grid .barlist .row,
.analytics-page .an-panel .barlist .row {
  min-width: 0;
}
.analytics-page .an-grid .chart,
.analytics-page .an-panel .chart {
  min-height: 150px;
  margin-top: 6px;
}

@media (max-width: 900px) {
  .analytics-page .an-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

@media (max-width: 480px) {
  .analytics-page {
    gap: 14px;
  }
  .analytics-page .an-range,
  .analytics-page .an-tabs {
    width: 100%;
  }
  .analytics-page .an-range-btn,
  .analytics-page .an-tab {
    min-height: 44px;
    padding-inline: 12px;
  }
  .analytics-page .an-metrics {
    gap: 8px;
  }
  .analytics-page .an-grid > .panel,
  .analytics-page .an-panel > .panel {
    padding: 14px;
  }
}


/* =========================================================================
   Email page — reuses the .ix inbox 3-pane grid; the full-height shell mirrors
   body.wa-view (without the WhatsApp mint theme). Only .em-* element styles are
   email-specific.
   ========================================================================= */
body.email-view .content {
  height: 100vh;
  padding: 0;
  min-height: 0;
  overflow: hidden;
}
body.email-view .topbar {
  flex: 0 0 auto;
  min-height: 68px;
  margin: 0;
  padding: 10px 22px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
body.email-view #view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}
body.email-view #view > .ix {
  animation: none;
}
.em-subject {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 1px 0;
}
.em-thread .ix-thread-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.em-thread-counts {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}
.em-msg-subject {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--text-main);
}
.em-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.em-reply {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.em-reply-subject {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-main);
}
.em-reply-subject::placeholder { color: var(--text-soft); }
/* The subject is auto-derived ("Re: …"); keep it one collapsed line until the
   sender actually wants to change it. */
.em-reply-subject-wrap summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.em-reply-subject-wrap[open] summary { margin-bottom: 6px; }
.em-reply-subject:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.em-compose-fields textarea {
  resize: vertical;
  min-height: 120px;
}
.em-send-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 600;
}
.draft-subject {
  margin: 0 0 2px;
  font-size: 13px;
}
.draft-subject b { color: var(--text-main); }
@media (max-width: 860px) {
  body.email-view .content {
    height: 100dvh;
    padding: 0 0 calc(86px + var(--safe-bottom));
    overflow: hidden;
  }
  body.email-view .topbar {
    min-height: 60px;
    padding: 9px 14px;
  }
  body.email-view .topbar p,
  body.email-view .topbar .crumbs {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (display-mode: window-controls-overlay) {
  .topbar,
  body.wa-view .topbar,
  body.live-map-view .topbar,
  body.email-view .topbar {
    padding-top: calc(10px + env(titlebar-area-height, 0px));
    padding-left: calc(6px + env(titlebar-area-x, 0px));
    padding-right: max(6px, calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw)));
    max-width: env(titlebar-area-width, 100%);
  }
}

@media (display-mode: window-controls-overlay) and (max-width: 920px) {
  .topbar {
    top: calc(var(--safe-top) + env(titlebar-area-height, 0px));
  }
}

/* Landscape phones (~390px tall): the large-title header + labelled bottom nav
   were eating ~40% of the height. Condense the chrome; nav goes icon-only
   (buttons keep aria-labels). */
@media (max-width: 920px) and (max-height: 500px) {
  .topbar h1 {
    font-size: 18px;
  }
  .topbar p {
    display: none;
  }
  .mobile-bottom-nav button {
    min-height: 44px;
  }
  .mobile-bottom-nav button span {
    display: none;
  }
  .mobile-bottom-nav svg {
    width: 22px;
    height: 22px;
  }
  .content {
    padding-bottom: calc(76px + var(--safe-bottom));
  }
}

/* Short phone screens: drop the decorative hero chips so "Choose a demo role"
   is reachable without scrolling. */
@media (max-width: 920px) and (max-height: 740px) {
  .login-hero .hero-chips {
    display: none;
  }
}
