/* ============================================================
   Lougha Chats — design system (2026)
   Operator-grade editorial. Geist + Fraunces. OKLCH ramps.
   Dynamic light/dark via [data-theme] on <html>.
   ============================================================ */

:root, [data-theme="light"] {
  /* ─── Brand & accent ─── */
  --wa: #25d366;
  --wa-dark: #1da851;
  --wa-soft: oklch(0.85 0.18 150 / 0.18);
  --lougha: #10b7e2;
  --lougha-soft: oklch(0.85 0.10 220 / 0.18);

  /* Single accent — electric cobalt. Used for focus, primary actions,
     active states, links. Color = affordance, not decoration. */
  --accent: oklch(0.52 0.24 264);
  --accent-hover: oklch(0.46 0.24 264);
  --accent-strong: oklch(0.42 0.24 264);
  --accent-soft: oklch(0.52 0.24 264 / 0.10);
  --accent-fg: #ffffff;

  /* ─── Surfaces (warm cream → less harsh for 8h/day operators) ─── */
  --bg: oklch(0.99 0.005 75);
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-sunken: oklch(0.97 0.006 75);
  --surface-hover: oklch(0.965 0.006 75);
  --surface-active: oklch(0.95 0.008 75);

  /* ─── Borders ─── */
  --border: oklch(0.92 0.004 250);
  --border-strong: oklch(0.86 0.005 250);
  --border-subtle: oklch(0.94 0.003 250);

  /* ─── Text ─── */
  --text: oklch(0.18 0.012 250);
  --text-secondary: oklch(0.40 0.010 250);
  --text-tertiary: oklch(0.55 0.008 250);
  --text-muted: oklch(0.65 0.006 250);
  --text-inverse: oklch(0.98 0.005 75);

  /* ─── Status (muted but legible — same hue both themes) ─── */
  --success: oklch(0.60 0.16 150);
  --success-soft: oklch(0.60 0.16 150 / 0.12);
  --warning: oklch(0.72 0.16 75);
  --warning-soft: oklch(0.72 0.16 75 / 0.14);
  --danger: oklch(0.58 0.22 25);
  --danger-soft: oklch(0.58 0.22 25 / 0.10);
  --info: oklch(0.60 0.15 230);
  --info-soft: oklch(0.60 0.15 230 / 0.12);

  /* ─── Gray ramp (back-compat — kept for the 4500-line stylesheet that
       references --gray-XXX directly. Values map to a perceptually-even
       OKLCH ramp; dark theme flips them so legacy code re-themes for free.) */
  --gray-50: oklch(0.985 0.003 75);
  --gray-100: oklch(0.965 0.005 75);
  --gray-200: oklch(0.92 0.004 250);
  --gray-300: oklch(0.85 0.005 250);
  --gray-400: oklch(0.68 0.010 250);
  --gray-500: oklch(0.55 0.010 250);
  --gray-600: oklch(0.42 0.010 250);
  --gray-700: oklch(0.30 0.012 250);
  --gray-800: oklch(0.22 0.012 250);
  --gray-900: oklch(0.15 0.012 250);

  /* ─── Legacy accent colors (kept for components that hard-code them) ─── */
  --indigo-500: #6366f1;
  --pink-500: #ec4899;
  --blue-500: #3b82f6;
  --orange-500: #f97316;
  --violet-500: #8b5cf6;
  --amber-500: #f59e0b;
  --red-500: #ef4444;
  --purple-600: #7e22ce;
  --green-500: #16a34a;
  --green-600: #15803d;

  /* ─── Avatar palette (OKLCH-balanced, equal lightness) ─── */
  --av-1: oklch(0.62 0.18 264);
  --av-2: oklch(0.62 0.18 220);
  --av-3: oklch(0.62 0.16 150);
  --av-4: oklch(0.62 0.18 310);
  --av-5: oklch(0.62 0.18 350);
  --av-6: oklch(0.65 0.16 60);
  --av-7: oklch(0.62 0.14 180);
  --av-8: oklch(0.62 0.16 200);

  /* ─── Geometry ─── */
  --sidebar-w: 360px;
  --topbar-h: 56px;
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --radius-bubble: 14px;

  /* ─── Shadows (subtle in light, pronounced in dark) ─── */
  --shadow-sm: 0 1px 2px oklch(0.15 0.012 250 / 0.04);
  --shadow: 0 1px 3px oklch(0.15 0.012 250 / 0.05), 0 4px 12px oklch(0.15 0.012 250 / 0.04);
  --shadow-lg: 0 12px 32px oklch(0.15 0.012 250 / 0.10), 0 4px 12px oklch(0.15 0.012 250 / 0.06);

  /* ─── Typography ─── */
  --font-sans: 'Geist', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, "Times New Roman", serif;
  --font-mono: 'Geist Mono', ui-monospace, Menlo, monospace;

  /* ─── Motion ─── */
  --ease: cubic-bezier(0.2, 0.0, 0.0, 1);
  --motion-fast: 120ms;
  --motion-normal: 180ms;
  --motion-slow: 280ms;
}

/* ─── Dark theme overrides ──────────────────────────────────────────────
   Same token names, different values. Manual override via the topbar
   toggle (writes data-theme + localStorage). On first load with no saved
   preference, the inline <head> script honours OS prefers-color-scheme. */
[data-theme="dark"] {
  /* Surfaces — cool charcoal, layered for depth */
  --bg: oklch(0.16 0.008 250);
  --surface: oklch(0.20 0.008 250);
  --surface-elevated: oklch(0.24 0.010 250);
  --surface-sunken: oklch(0.18 0.008 250);
  --surface-hover: oklch(0.25 0.010 250);
  --surface-active: oklch(0.28 0.012 250);

  /* Borders — visible but quiet */
  --border: oklch(0.28 0.010 250);
  --border-strong: oklch(0.38 0.012 250);
  --border-subtle: oklch(0.24 0.010 250);

  /* Text — warm whites */
  --text: oklch(0.96 0.005 75);
  --text-secondary: oklch(0.78 0.008 250);
  --text-tertiary: oklch(0.62 0.010 250);
  --text-muted: oklch(0.48 0.010 250);
  --text-inverse: oklch(0.18 0.012 250);

  /* Accent — slightly brighter for dark-bg contrast */
  --accent: oklch(0.70 0.22 264);
  --accent-hover: oklch(0.76 0.22 264);
  --accent-strong: oklch(0.62 0.22 264);
  --accent-soft: oklch(0.70 0.22 264 / 0.20);

  /* Status — brightness pivot for AA contrast on charcoal */
  --success: oklch(0.72 0.16 150);
  --success-soft: oklch(0.72 0.16 150 / 0.18);
  --warning: oklch(0.82 0.15 75);
  --warning-soft: oklch(0.82 0.15 75 / 0.18);
  --danger: oklch(0.72 0.20 25);
  --danger-soft: oklch(0.72 0.20 25 / 0.20);
  --info: oklch(0.74 0.16 230);
  --info-soft: oklch(0.74 0.16 230 / 0.18);

  /* Gray ramp — flipped so var(--gray-900) text stays light in dark mode */
  --gray-50: oklch(0.22 0.010 250);
  --gray-100: oklch(0.26 0.010 250);
  --gray-200: oklch(0.32 0.010 250);
  --gray-300: oklch(0.42 0.010 250);
  --gray-400: oklch(0.55 0.010 250);
  --gray-500: oklch(0.66 0.008 250);
  --gray-600: oklch(0.76 0.008 250);
  --gray-700: oklch(0.86 0.006 250);
  --gray-800: oklch(0.92 0.005 75);
  --gray-900: oklch(0.96 0.005 75);

  /* Brand soft tints — slightly stronger to remain visible on dark surfaces */
  --wa-soft: oklch(0.72 0.16 150 / 0.20);
  --lougha-soft: oklch(0.72 0.14 220 / 0.20);

  /* Shadows — black with more diffusion (dark surfaces eat soft shadows) */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.30);
  --shadow: 0 1px 3px oklch(0 0 0 / 0.45), 0 4px 14px oklch(0 0 0 / 0.30);
  --shadow-lg: 0 16px 40px oklch(0 0 0 / 0.55), 0 4px 14px oklch(0 0 0 / 0.40);
}

/* ─── Theme-toggle button — sun visible in dark mode, moon in light. */
.theme-toggle { color: var(--text-secondary); transition: color var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease); }
.theme-toggle:hover { color: var(--text); background: var(--surface-hover); }
.theme-toggle .theme-icon { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-dark,
:root:not([data-theme="dark"]) .theme-toggle .theme-icon-dark { display: inline-flex; }
[data-theme="dark"] .theme-toggle .theme-icon-light { display: inline-flex; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: var(--font-sans); color: var(--text); background: var(--bg); transition: background var(--motion-normal) var(--ease), color var(--motion-normal) var(--ease); }
body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--gray-500); }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.mb12 { margin-bottom: 12px; }
.mobile-only { display: none; }
@media (max-width: 768px) { .mobile-only { display: inline-flex; } }
/* Chat back button — promoted to desktop when there's a cross-chat
 * history stack to pop (set by navigateToChat in app.js). */
body.has-chat-history #chatBackBtn { display: inline-flex; }

/* ─── Lucide icon defaults ─── */
[data-lucide] { width: 18px; height: 18px; stroke-width: 2; }
.icon-btn [data-lucide] { width: 18px; height: 18px; }
.icon-btn-sm [data-lucide] { width: 14px; height: 14px; }

/* ─── Buttons (H1: 3-tier height system) ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px; font-weight: 500; cursor: pointer; transition: all 0.15s;
  background: transparent; color: var(--gray-700);
}
.btn:hover { background: var(--gray-100); }
.btn-primary { background: var(--wa); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--wa-dark); }
.btn-ghost { color: var(--gray-600); background: var(--gray-100); }
.btn-ghost:hover { background: var(--gray-200); color: var(--gray-900); }
.btn-block { width: 100%; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14px; font-weight: 600; }
.btn:disabled, .btn[disabled] {
  opacity: 0.5; cursor: not-allowed; filter: saturate(0.6); pointer-events: none;
}
.btn-primary:disabled { background: var(--gray-300); color: #fff; }
.btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; background: transparent;
  border-radius: var(--radius-sm); color: var(--gray-500); cursor: pointer;
  font-family: inherit;
  transition: all 0.15s; position: relative;
}
.icon-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.icon-btn-primary { background: var(--wa); color: #fff; }
.icon-btn-primary:hover { background: var(--wa-dark); color: #fff; }
.icon-btn-sm {
  width: 26px; height: 26px;
  border: 0; background: transparent; border-radius: 6px;
  color: var(--gray-400); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn-sm:hover { background: var(--gray-200); color: var(--gray-700); }

/* Tooltip */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--gray-900); color: #fff; padding: 4px 8px; border-radius: 6px;
  font-size: 11px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.15s; z-index: 100;
}
.tip:hover::after { opacity: 1; }

.with-badge { position: relative; }
.badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--amber-500); color: #fff;
  font-size: 9px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ─── Inputs ─── */
.input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px; color: var(--text); background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s; outline: none;
}
.input::placeholder { color: var(--text-muted); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled { background: var(--surface-sunken); color: var(--text-tertiary); cursor: not-allowed; }

/* ─── Screens / layout ─── */
.screen { width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* ─── Login screen ─── */
.login-screen {
  background: var(--bg);
  position: relative;
}
/* Editorial backdrop — soft gradient mesh that picks up the accent in
   both themes. Quiet enough that the card reads as primary; present
   enough that the page isn't a flat blank rectangle. */
.login-screen::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 22% 22%, var(--accent-soft), transparent 60%),
    radial-gradient(ellipse 50% 40% at 82% 78%, var(--wa-soft), transparent 60%);
  opacity: 0.9;
}
.login-card {
  position: relative; z-index: 1;
  width: 360px; padding: 44px 36px; background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 8px;
  background: var(--accent-soft); border-radius: var(--radius-lg);
  display: inline-flex; align-items: center; justify-content: center;
}
.login-logo [data-lucide] { width: 28px; height: 28px; color: var(--accent); }
.login-title { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 500; letter-spacing: -0.015em; color: var(--gray-900); font-variation-settings: "opsz" 144; }
.login-subtitle { margin: 0 0 16px; color: var(--gray-500); font-size: 13px; letter-spacing: 0.02em; text-transform: uppercase; }
.error-text { color: var(--red-500); font-size: 13px; margin: 4px 0 0; }

/* ─── QR screen ─── */
.qr-screen { background: var(--gray-50); }
.qr-card {
  width: 380px; padding: 32px; background: #fff;
  border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px;
}
.qr-title { margin: 0; font-size: 20px; font-weight: 700; }
.qr-subtitle { margin: 0; color: var(--gray-500); font-size: 13px; line-height: 1.5; }
.qr-loading {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 40px 0; color: var(--gray-400); font-size: 13px;
}
.qr-image { width: 280px; height: 280px; border-radius: 8px; border: 1px solid var(--gray-200); }
.qr-status { margin: 0; color: var(--gray-500); font-size: 12px; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--gray-200); border-top-color: var(--wa);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner-sm {
  width: 16px; height: 16px;
  border: 2px solid var(--gray-200); border-top-color: var(--gray-400);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── App shell ─── */
.app { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

.topbar {
  height: var(--topbar-h);
  /* 3-column grid: left toggle, centered tabs, right user pill. Each
     side track is `1fr` so they're guaranteed equal width — that
     centers `.view-tabs` in the middle of the bar regardless of how
     wide the user pill on the right ends up. The toggle and the pill
     align inside their own columns via justify-self. Ayoub asked for
     a centered topbar that stays centered as more items get added. */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.topbar-title { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }
.topbar-spacer { display: none; } /* superseded by the grid template above */
.topbar > #sidebarToggleBtn { grid-column: 1; justify-self: start; }
.topbar > .view-tabs        { grid-column: 2; justify-self: center; }
.topbar > .topbar-right     { grid-column: 3; justify-self: end; display: inline-flex; align-items: center; gap: 8px; }
/* Back-compat — if the topbar-right wrapper ever goes missing,
   fall back to placing userPill in column 3 directly. */
.topbar > #userPill         { grid-column: 3; justify-self: end; }

.main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr) 0;
  background: var(--bg);
  transition: grid-template-columns 0.2s ease;
}
.main.with-profile { grid-template-columns: var(--sidebar-w) minmax(0,1fr) 340px; }
.main.with-profile #profilePanel { display: flex; }
.main:not(.with-profile) #profilePanel { display: none; }
.main.sidebar-collapsed { grid-template-columns: 0 minmax(0,1fr) 0; }
.main.sidebar-collapsed.with-profile { grid-template-columns: 0 minmax(0,1fr) 340px; }
.main.sidebar-collapsed .sidebar { display: none; }

/* ─── Sidebar ─── */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--border); background: var(--surface);
}
.sidebar-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-sunken); flex-shrink: 0;
}
.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px; font-weight: 500;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 144;
  color: var(--text);
}

/* Tabs (channel switcher: Inbox / Groups) */
.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-sunken); border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  margin-bottom: 10px;
}
.tab {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 8px; border: 0; background: transparent;
  border-radius: var(--radius-xs); font-size: 12px; font-weight: 500;
  color: var(--text-tertiary); cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab [data-lucide] { width: 14px; height: 14px; }
.tab.tab-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.tab[data-channel="groups"].tab-active { color: var(--av-4); }
.tab[data-channel="clubs"].tab-active  { color: var(--av-5); }
.tab[data-channel="sms"].tab-active    { color: var(--av-2); }
.tab[data-channel="email"].tab-active  { color: var(--av-6); }

/* Connection bar — quiet status pill above the search.
   Connected: success-soft / success.
   Disconnected: surface-sunken / muted text.
   The "Disconnect" action uses --danger so it reads as destructive. */
.conn-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-radius: var(--radius-sm);
  margin-bottom: 10px; font-size: 12px;
}
.conn-left { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.conn-disconnected { background: var(--surface-sunken); color: var(--text-tertiary); }
.conn-connected { background: var(--success-soft); color: var(--success); }
.conn-connected .conn-dot { background: var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.conn-action {
  display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--accent);
  font-family: inherit;
}
.conn-action:hover { color: var(--accent-hover); }
.conn-connected .conn-action { color: var(--danger); }
.conn-connected .conn-action:hover { color: var(--danger); filter: brightness(0.9); }
.conn-action [data-lucide] { width: 12px; height: 12px; }

/* Filter dropdown */
.dropdown { position: relative; margin-bottom: 10px; }
.filter-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); font-size: 12px; font-weight: 500;
  color: var(--text-secondary); cursor: pointer; transition: border-color 0.15s;
  font-family: inherit;
}
.filter-btn:hover { border-color: var(--border-strong); }
.filter-btn [data-lucide] { width: 14px; height: 14px; }
/* Total-matching count pill on the right side of the filter button —
 * cobalt accent matches the rest of the design system's "selected
 * count" affordance (was indigo). */
.filter-count-pill {
  font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.filter-count-pill.hidden { display: none; }
.filter-btn .chev { margin-left: auto; transition: transform 0.15s; }
.filter-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 10;
  background: var(--surface-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  max-height: 240px; overflow-y: auto;
}
.dropdown-item {
  width: 100%; text-align: left; padding: 8px 12px;
  border: 0; background: transparent;
  font-size: 12px; color: var(--text-secondary); cursor: pointer;
  display: block;
  font-family: inherit;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.dropdown-item:hover { background: var(--surface-hover); color: var(--text); }
.dropdown-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dropdown-divider {
  height: 1px; background: var(--border);
  margin: 4px 0;
}
.dropdown-section-title {
  padding: 6px 12px 4px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-tertiary);
}

/* Pinned chat — subtle yellow tint + small icon next to the name. The
   icon is rendered inside .conv-name-wrap so it doesn't disrupt unread
   badge / time-stamp layout on the right side of the row. */
.conv-item.is-pinned { background: linear-gradient(0deg, rgba(250, 204, 21, 0.06), rgba(250, 204, 21, 0.06)); }
.conv-item.is-pinned.active { background: var(--wa-soft); }
.conv-name-wrap { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.conv-pin-icon { fill: currentColor; }
.conv-flag-icon { fill: #fef2f2; }
.conv-unread.flag-badge { background: #dc2626; }

/* Synthetic team-user rows shown under the Team filter — visually distinct
   so the agent knows clicking will route to Team chat (not WA). */
.conv-item.is-synthetic-team {
  background: linear-gradient(0deg, rgba(99, 102, 241, 0.04), rgba(99, 102, 241, 0.04));
}
.conv-item.is-synthetic-team::after {
  content: 'TEAM';
  margin-left: auto;
  font-size: 9px; font-weight: 700; letter-spacing: 0.05em;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(99, 102, 241, 0.12); color: #4f46e5;
  flex-shrink: 0;
}

/* Right-click context menu shared across the conv-list. Floating panel,
   small enough to not feel modal. Closes on outside click or scroll. */
.conv-ctx-menu {
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 4px; min-width: 160px;
}
.conv-ctx-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px; border: 0; background: transparent;
  font-size: 13px; color: var(--gray-700); cursor: pointer; text-align: left;
  border-radius: 6px;
}
.conv-ctx-item:hover { background: var(--gray-50); color: var(--gray-900); }

/* ─── Team chat view ─── two-pane layout: directory on the left, active
   conversation on the right. Mirrors the WhatsApp-web split. */
#teamchatView .bulk-body,
#teamgroupsView .bulk-body { padding: 0; flex: 1; min-height: 0; }
.teamchat-grid {
  display: grid; grid-template-columns: 320px 1fr;
  height: 100%; min-height: 0;
}
.teamchat-sidebar {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  padding: 12px;
  background: var(--surface);
}
.teamchat-tabs { display: flex; gap: 6px; }
.teamchat-tab {
  flex: 1; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-secondary);
  font-family: inherit;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.teamchat-tab:hover { background: var(--surface-hover); }
.teamchat-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.teamchat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.teamchat-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.15s;
}
.teamchat-row:hover { background: var(--surface-hover); }
.teamchat-row.active { background: var(--accent-soft); }
.teamchat-avatar-wrap { position: relative; flex-shrink: 0; }
.presence-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--text-muted);
}
.presence-dot.online { background: var(--success); }
.teamchat-row-body { flex: 1; min-width: 0; }
.teamchat-row-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.teamchat-row-tag {
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: var(--radius-xs);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.teamchat-row-tag.wa { background: var(--wa-soft); color: var(--wa-dark); }
.teamchat-row-preview {
  font-size: 12px; color: var(--text-tertiary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
.teamchat-unread {
  background: var(--wa); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: var(--radius-pill); flex-shrink: 0;
}
.teamchat-empty-row { padding: 20px; text-align: center; font-size: 12.5px; color: var(--text-tertiary); }
.teamchat-section-title {
  padding: 10px 8px 4px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-tertiary);
}
.teamchat-row-wagroup .teamchat-row-tag.wa {
  font-weight: 700;
}
.teamchat-pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg);
}
.teamchat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
}
.teamchat-active { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.teamchat-active.hidden { display: none; }
.teamchat-active-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.teamchat-active-head-info { display: flex; flex-direction: column; flex: 1; }
.teamchat-active-name { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.teamchat-active-sub { font-size: 12px; color: var(--text-tertiary); }
.teamchat-open-inbox-link {
  font-size: 12px; font-weight: 600; color: var(--wa-dark);
  text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--wa-soft);
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease);
}
.teamchat-open-inbox-link:hover { background: var(--wa-soft); filter: brightness(0.95); }
[data-theme="dark"] .teamchat-open-inbox-link { color: var(--wa); }
[data-theme="dark"] .teamchat-open-inbox-link:hover { filter: brightness(1.15); }
.teamchat-messages {
  flex: 1; overflow-y: auto; padding: 16px 24px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg);
}
.teamchat-empty-state {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px;
  color: var(--gray-600); text-align: center;
}
.teamchat-empty-bubble {
  width: 72px; height: 72px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(99, 102, 241, 0.10);
  color: #6366f1;
}
.teamchat-empty-bubble svg { width: 32px; height: 32px; }
.teamchat-empty-title { font-size: 15px; font-weight: 600; color: var(--gray-800); max-width: 360px; }
.teamchat-empty-sub { font-size: 12.5px; color: var(--gray-500); max-width: 340px; line-height: 1.45; }
.teamchat-msg {
  max-width: 60%; padding: 8px 12px; border-radius: 10px;
  font-size: 13.5px; line-height: 1.45;
  position: relative;
}
/* Team-chat bubbles — mirror the inbox bubbles' theming pattern via
   the bubble's own CSS vars so the same outbound emerald reads in
   both modes (light WA-green / dark deep emerald). */
.teamchat-msg.me {
  align-self: flex-end;
  background: #d9fdd3;
  color: oklch(0.20 0.04 150);
}
[data-theme="dark"] .teamchat-msg.me {
  background: oklch(0.32 0.08 150);
  color: oklch(0.95 0.02 150);
}
.teamchat-msg.them {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-subtle);
}
[data-theme="dark"] .teamchat-msg.them { background: var(--surface-elevated); }
.teamchat-msg-author { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.teamchat-msg-text { white-space: pre-wrap; word-wrap: break-word; }
.teamchat-msg-image { max-width: 280px; border-radius: var(--radius-sm); display: block; margin-top: 4px; }
.teamchat-msg-file {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--surface-sunken);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--text);
  text-decoration: none; margin-top: 4px; max-width: 280px;
  border: 1px solid var(--border-subtle);
  transition: background var(--motion-fast) var(--ease);
}
.teamchat-msg-file:hover { background: var(--surface-hover); }
.teamchat-msg-file svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-secondary); }
.teamchat-msg-file .doc-name {
  font-weight: 600; word-break: break-word;
}

/* Multi-select on team chat bubbles — same selection styling as inbox. */
.teamchat-msg-row { position: relative; }
.teamchat-msg-row .msg-select-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  left: 4px; z-index: 5;
}
.teamchat-msg-row.me .msg-select-btn { left: auto; right: 4px; }
.teamchat-msg-row.is-selected { background: rgba(34, 197, 94, 0.08); }
.teamchat-msg-row.selection-mode { cursor: pointer; }
.teamchat-msg-meta {
  display: flex; align-items: center; gap: 4px; justify-content: flex-end;
  font-size: 10px; color: var(--gray-500); margin-top: 2px;
}
.teamchat-tick { font-weight: 700; }
.teamchat-tick.read { color: #4ea3ff; }
.teamchat-compose {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-top: 1px solid var(--gray-200); background: #f7f7f7;
  /* Wrap so the reply-preview pill drops onto its own row above the
     buttons + textarea row, instead of competing for horizontal space
     and pushing the input off-screen on long quoted messages. */
  flex-wrap: wrap;
}
.teamchat-compose .icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--gray-600);
  background: transparent;
  transition: background 100ms ease;
}
.teamchat-compose .icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--gray-800); }
.teamchat-textarea {
  flex: 1; resize: none; max-height: 120px; padding: 9px 14px;
  border-radius: 22px; background: #fff;
  border: 1px solid var(--gray-200);
  font-size: 14px;
}
.teamchat-textarea:focus { border-color: var(--blue-400, #60a5fa); outline: none; box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15); }
.teamchat-compose { position: relative; }
.teamchat-record-overlay {
  position: absolute; inset: 0;
  background: #f7f7f7; padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
}
.teamchat-record-overlay.hidden { display: none; }
.teamroom-members { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.teamroom-member-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.teamroom-member-row:hover { background: var(--gray-50); }

/* Search */
.search { position: relative; }
.search [data-lucide] {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}
.search input {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 13px; outline: none;
  font-family: inherit;
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.search input::placeholder { color: var(--text-muted); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Conversation list */
.conv-list { flex: 1; overflow-y: auto; }
.conv-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; padding: 40px 20px; gap: 8px;
  color: var(--gray-400); font-size: 13px;
}
/* Conv rows — calmer rhythm, accent rail/active state, larger date.
   Hover uses --surface-hover for uniform feel across the app; active
   pulls --accent-soft (cobalt) and an --accent rail. Channel variants
   keep their per-channel rail colour for quick visual chunking. */
.conv-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px 14px 18px;
  cursor: pointer; transition: background 0.12s; position: relative;
}
.conv-item + .conv-item { border-top: 1px solid var(--border-subtle); }
.conv-item:hover { background: var(--surface-hover); }
.conv-item.active { background: var(--accent-soft); }
.conv-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}
.conv-item.active.channel-groups::before { background: var(--av-4); }
.conv-item.active.channel-clubs::before  { background: var(--av-5); }

.avatar {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: #fff; font-size: 14px; font-weight: 700;
  background: var(--av-1);
}
.avatar-md { width: 40px; height: 40px; font-size: 13px; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-c1 { background: var(--av-1); }
.avatar-c2 { background: var(--av-2); }
.avatar-c3 { background: var(--av-3); }
.avatar-c4 { background: var(--av-4); }
.avatar-c5 { background: var(--av-5); }
.avatar-c6 { background: var(--av-6); }
.avatar-c7 { background: var(--av-7); }
.avatar-c8 { background: var(--av-8); }

.conv-body { flex: 1; min-width: 0; }
.conv-row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-name-wrap {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; flex: 1;
}
.conv-name {
  font-size: 14.5px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-label-chip {
  display: inline-block; flex-shrink: 0;
  width: 8px; height: 8px; border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.1);
}
.conv-date {
  flex-shrink: 0; font-size: 11.5px; color: var(--gray-500);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.conv-row2 {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 3px;
}
.conv-preview {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--gray-500);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-unread {
  flex-shrink: 0;
  min-width: 20px; height: 20px; padding: 0 7px;
  border-radius: 999px;
  background: #25d366; /* WhatsApp green */
  color: #fff;
  font-size: 11.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(37, 211, 102, 0.35);
  letter-spacing: 0.2px;
}
.conv-item.active .conv-unread {
  background: #1ea952;
  box-shadow: 0 1px 2px rgba(30, 169, 82, 0.45);
}
/* When a row has unread messages, brighten the time + preview to draw the eye —
 * matches the WhatsApp pattern of "new = high-contrast, read = dimmed". */
.conv-date-unread {
  color: #25d366 !important;
  font-weight: 700;
}
.conv-preview-unread {
  color: var(--gray-900) !important;
  font-weight: 600;
}

/* ─── Chat pane ──────────────────────────────────────────────────────
   The chat canvas is the most-looked-at surface in the app. It gets
   a quietly-themed background (warm cream in light, cool charcoal in
   dark) plus a subtle dotted overlay that gives the canvas texture
   without competing with bubble content. Both layers are CSS vars so
   the same rule themes correctly across modes. */
.chat-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--bg);
}

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-tertiary); padding: 40px;
}
.empty-icon {
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.empty-icon [data-lucide] { width: 48px; height: 48px; color: var(--accent); opacity: 0.7; }
.empty-state h3 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 500; letter-spacing: -0.015em; color: var(--text); }
.empty-state p { margin: 0; font-size: 13px; max-width: 280px; text-align: center; color: var(--text-tertiary); }

.conv-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.chat-id { flex: 1; min-width: 0; }
.chat-id h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-id .muted { font-size: 12px; margin: 0; color: var(--text-tertiary); }
.chat-actions { display: flex; align-items: center; gap: 2px; }

/* Messages — clean themed canvas. The dotted pattern was dropped by
   an earlier explicit request; now the canvas is a solid surface that
   flips with the theme so bubbles read cleanly against either bg. */
.messages-area {
  flex: 1; overflow-y: auto; padding: 20px 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg);
}
.messages-empty {
  margin: auto; color: var(--text-muted); font-size: 13px;
}
.messages-top-indicator {
  text-align: center; font-size: 11px; color: var(--text-tertiary);
  padding: 8px 0; font-style: italic;
  background: var(--surface-sunken);
}

/* Date separator chip — small pill centered between days so the agent
   sees at a glance that "Today 14:30" follows "Yesterday 22:43" rather
   than two random timestamps in odd order. */
.date-separator {
  align-self: center;
  padding: 4px 12px;
  margin: 8px 0;
  border-radius: var(--radius-lg);
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  flex-shrink: 0;
}

.message-row { display: flex; }
.message-row.fromMe { justify-content: flex-end; }
.message-row.fromMe + .message-row.fromMe,
.message-row:not(.fromMe) + .message-row:not(.fromMe) { margin-top: -2px; }

.bubble {
  --bubble-bg: var(--surface);
  --bubble-text: var(--text);
  --bubble-meta: var(--text-muted);
  max-width: 65%; padding: 8px 12px;
  border-radius: var(--radius-bubble);
  font-size: 14px; color: var(--bubble-text); position: relative;
  background: var(--bubble-bg);
  box-shadow: 0 1px 1px oklch(0 0 0 / 0.06);
  border: 1px solid var(--border-subtle);
  word-wrap: break-word; overflow-wrap: anywhere;
}
[data-theme="dark"] .bubble { box-shadow: 0 1px 2px oklch(0 0 0 / 0.30); }
/* Outbound bubble keeps the WhatsApp emerald identity in light mode;
   in dark mode it pivots to a deep readable emerald that still says
   "this is your message" without glowing white against the canvas. */
.bubble.fromMe {
  --bubble-bg: #d9fdd3;
  --bubble-text: oklch(0.20 0.04 150);
  --bubble-meta: oklch(0.40 0.05 150);
  border-color: transparent;
}
[data-theme="dark"] .bubble.fromMe {
  --bubble-bg: oklch(0.32 0.08 150);
  --bubble-text: oklch(0.95 0.02 150);
  --bubble-meta: oklch(0.75 0.04 150);
}
.bubble .text { white-space: pre-wrap; }
.bubble .meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  margin-top: 3px; font-size: 11px; color: var(--bubble-meta);
}
.bubble .meta [data-lucide] { width: 14px; height: 14px; }
/* Outbound "by <agent>" label — same hue as the rest of the meta but
   weight 600 + a separating dot so the agent's name sits comfortably
   beside the timestamp without screaming. Uses currentColor with
   slightly darker hue via the bubble's CSS var chain. */
.bubble .meta .meta-sender { font-weight: 600; color: inherit; opacity: 0.85; }
.bubble .meta .meta-sender::after { content: " · "; font-weight: 400; opacity: 0.7; }
.bubble .sender-name { font-size: 12px; font-weight: 600; color: var(--av-1); margin-bottom: 2px; }
.bubble .sender-name.clickable { cursor: pointer; }
.bubble .sender-name.clickable:hover { text-decoration: underline; }
/* Wider audio player so the scrubber is actually usable — agents
   need to see where they are in the recording, scrub backward, or
   pause/resume on a known position. The default 240px crammed every
   control into a tooltip-sized strip. */
.bubble audio { width: 380px; max-width: 100%; height: 40px; }
.teamchat-msg audio { width: 380px; max-width: 100%; height: 40px; }
/* Chrome's <audio controls> shrinks to its ~50px intrinsic minimum (kebab
   + 0:00) without an explicit min-width on the wrapper. Force enough room
   for the full transport on both bubble surfaces. */
.bubble:has(audio) { max-width: min(420px, 80%); }
.teamchat-msg:has(audio) { max-width: 420px; min-width: 380px; }
/* Visible chip for messages whose media never made it to disk — Baileys
   decryption usually. Without this the bubble looked empty and agents
   thought the platform was broken; now it's an obvious "ask the sender
   to resend" prompt. */
.media-failed-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--warning-soft); color: var(--warning);
  font-size: 12.5px; font-weight: 500;
  border: 1px dashed var(--warning);
}

/* ─── Reply / quote UI ──────────────────────────────────────────────────
   Hover any message bubble to reveal the reply trigger; click sets the
   composer's reply target. The composer surfaces a green-bar preview pill
   the agent can dismiss. Replies render with a quoted block prepended
   to the bubble — mirrors WhatsApp Web. */
.message-row { position: relative; }
/* Bubble is the positioned ancestor for its hover chips so they
   anchor to the bubble's actual edge instead of the full-width row.
   Without this, fromMe chips ended up off-screen at the far left
   while the bubble sat on the far right. */
.bubble { position: relative; }
.bubble .bubble-reply-trigger {
  position: absolute; top: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: 50%;
  color: var(--text-tertiary); cursor: pointer;
  opacity: 0; transition: opacity 0.15s, transform 0.15s;
  box-shadow: var(--shadow);
  z-index: 2;
}
.bubble .bubble-reply-trigger:hover { color: var(--accent); transform: scale(1.05); }
.bubble .bubble-reply-trigger [data-lucide] { width: 14px; height: 14px; }
.bubble:not(.fromMe) .bubble-reply-trigger { right: -36px; }
.bubble.fromMe .bubble-reply-trigger        { left:  -36px; }
.message-row:hover .bubble .bubble-reply-trigger { opacity: 1; }

/* WhatsApp-style reaction chips under each bubble + quick-react bar on hover */
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
  /* Bubble width is fixed by content; chips overflow into a wrapped row. */
}
.msg-reactions.hidden { display: none; }
.msg-reaction-chip {
  display: inline-flex; align-items: center; gap: 3px;
  height: 22px; padding: 1px 7px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px; line-height: 1;
  color: var(--text);
  cursor: pointer; transition: transform 80ms ease, background 80ms;
}
.msg-reaction-chip:hover { transform: scale(1.05); background: var(--surface-hover); }
.msg-reaction-chip.is-mine {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 700;
}
.msg-reaction-chip .mrc-emoji { font-size: 14px; }
.msg-reaction-chip .mrc-count { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.msg-reaction-chip.is-mine .mrc-count { color: var(--accent); }

/* Floating quick-react bar — shows on bubble hover, hidden by default */
.bubble .msg-quick-react-bar {
  position: absolute; top: -34px;
  display: inline-flex; gap: 2px;
  padding: 4px 6px;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity 120ms ease;
  z-index: 3;
}
.bubble:not(.fromMe) .msg-quick-react-bar { left: 6px; }
.bubble.fromMe       .msg-quick-react-bar { right: 6px; }
.message-row:hover .bubble .msg-quick-react-bar { opacity: 1; pointer-events: auto; }
.msg-quick-react-bar .mqr-btn {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
  border: 0; background: transparent; cursor: pointer;
  transition: transform 80ms ease, background 80ms;
}
.msg-quick-react-bar .mqr-btn:hover { transform: scale(1.18); background: var(--gray-50); }
.msg-quick-react-bar .mqr-btn.is-mine {
  background: #dbeafe; box-shadow: 0 0 0 2px #93c5fd inset;
}

/* Edit + Delete chips next to the reply trigger — only rendered on
   own (fromMe) bubbles. Stacked outward from the reply chip at
   left: -36 / -68 / -100. */
.bubble .bubble-edit-trigger,
.bubble .bubble-delete-trigger {
  position: absolute; top: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 50%;
  color: var(--gray-500); cursor: pointer;
  opacity: 0; transition: opacity 0.15s, transform 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  z-index: 2;
}
.bubble .bubble-edit-trigger:hover { color: #128c7e; transform: scale(1.05); }
.bubble .bubble-delete-trigger { color: #b91c1c; }
.bubble .bubble-delete-trigger:hover { color: #7f1d1d; transform: scale(1.05); }
.bubble .bubble-edit-trigger [data-lucide],
.bubble .bubble-delete-trigger [data-lucide] { width: 14px; height: 14px; }
.bubble.fromMe .bubble-edit-trigger   { left: -68px; }
.bubble.fromMe .bubble-delete-trigger { left: -100px; }
.message-row:hover .bubble .bubble-edit-trigger,
.message-row:hover .bubble .bubble-delete-trigger { opacity: 1; }
.message-row.selection-mode .bubble .bubble-edit-trigger,
.message-row.selection-mode .bubble .bubble-delete-trigger { display: none !important; }

/* Inline edit form replaces the .text element while editing. Same
   shape as the team chat editor so the muscle-memory transfers. */
.inbox-edit-form { display: flex; flex-direction: column; gap: 6px; margin: 2px 0; }
.inbox-edit-textarea {
  min-width: 220px; max-width: 100%;
  padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px;
  font: inherit; resize: vertical;
  background: rgba(255,255,255,0.95); color: #111827;
}
.bubble.fromMe .inbox-edit-textarea { background: rgba(255,255,255,0.9); }
.inbox-edit-btns { display: flex; gap: 6px; justify-content: flex-end; }
.inbox-edit-btns .btn { padding: 4px 10px; font-size: 12px; }

/* "edited" indicator in the meta row beside the timestamp. Same quiet
   italic styling used in team chat for consistency. */
.bubble .meta .meta-edited {
  font-size: 10px; color: var(--gray-500, #6b7280); font-style: italic;
  margin-left: 2px;
}

/* Bot bubble header — stacks the Bot tag, the always-visible Coach
   button, and the optional 💬N badge inline INSIDE the bubble so
   nothing gets clipped by the messages-area overflow. */
.bubble.is-bot .bot-bubble-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.bot-coach-inline-btn {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600; color: #6d28d9;
  background: #ede9fe; border: 1px solid #c4b5fd; border-radius: 999px;
  padding: 1px 8px; cursor: pointer;
}
.bot-coach-inline-btn:hover { background: #ddd6fe; }

.bubble .quoted-block {
  display: flex; gap: 8px; align-items: stretch;
  padding: 6px 10px; margin-bottom: 4px;
  background: rgba(0,0,0,0.05); border-radius: 6px;
  cursor: pointer; transition: background 0.15s;
}
.bubble .quoted-block:hover { background: rgba(0,0,0,0.08); }
.bubble.fromMe .quoted-block { background: rgba(0,0,0,0.06); }
.bubble .quoted-block-bar {
  width: 3px; flex-shrink: 0; border-radius: 2px; background: #25d366;
}
.bubble .quoted-block-body { flex: 1; min-width: 0; }
.bubble .quoted-block-author { font-size: 12px; font-weight: 600; color: #128c7e; margin-bottom: 1px; }
.bubble .quoted-block-snippet {
  font-size: 12.5px; color: var(--gray-600);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Composer reply pill — sits between the message list and the textarea. */
/* Archive shortcut row in the inbox sidebar — mirrors WhatsApp's
   "Archived" tile above the conversation list. Click toggles between
   main inbox and archived-only view. */
.archive-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  user-select: none;
  background: var(--gray-50, #f9fafb);
}
.archive-row:hover { background: var(--gray-100, #f3f4f6); }
.archive-row.active {
  background: rgba(37, 211, 102, 0.08);
  border-bottom-color: rgba(37, 211, 102, 0.35);
}
.archive-row-icon { display: inline-flex; color: var(--gray-600); }
.archive-row-icon i { width: 18px; height: 18px; }
.archive-row-label { flex: 1; font-size: 13px; font-weight: 500; color: var(--gray-700); }
.archive-row-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: #25d366; color: #fff; font-size: 11px; font-weight: 600;
}
.archive-row-count.zero { background: var(--gray-400); }

/* In-chat search bar — slides between the chat-header and messages area
   when toggled via #chatSearchBtn. Compact row: icon, input, match
   counter, prev/next/close. */
.chat-search-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--gray-50, #f9fafb);
  border-top: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0; /* Don't squeeze the messages area when both this and
                     the reply-preview are visible at the same time. */
}
.chat-search-bar .chat-search-icon {
  width: 16px; height: 16px; color: var(--gray-500); flex-shrink: 0;
}
.chat-search-bar input {
  flex: 1; min-width: 0;
  padding: 6px 8px; font-size: 13px;
  background: transparent; border: none; outline: none;
}
.chat-search-bar .chat-search-count {
  font-size: 11px; color: var(--gray-500);
  white-space: nowrap; user-select: none;
}
.chat-search-bar .icon-btn { padding: 4px; }
.chat-search-bar .icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.bubble.search-match { box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.45); }
.bubble.search-match-active { box-shadow: 0 0 0 2px #25d366; }

.reply-preview {
  display: flex; align-items: stretch; gap: 8px;
  padding: 8px 12px;
  background: var(--gray-50, #f9fafb);
  border-top: 1px solid var(--gray-200);
  flex-shrink: 0; /* Mirrors .chat-search-bar — both can co-exist
                     between header and messages without crushing them. */
}
.reply-preview-bar { width: 3px; border-radius: 2px; background: #25d366; flex-shrink: 0; }
.reply-preview-body { flex: 1; min-width: 0; padding: 2px 0; }
.reply-preview-author { font-size: 12px; font-weight: 600; color: #128c7e; }
.reply-preview-snippet {
  font-size: 13px; color: var(--gray-700);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}
.reply-preview .icon-btn { align-self: center; }

/* Same UI inside the team chat / team groups composer too.
   `flex: 0 0 100%` parks the pill on its own row above the input
   (paired with `flex-wrap: wrap` on .teamchat-compose). `min-width: 0`
   is required so the nested ellipsis truncation actually kicks in —
   without it, a long quoted message pushes the parent's intrinsic
   min-width past the viewport and overflows horizontally. */
.teamchat-compose .reply-preview {
  flex: 0 0 100%;
  min-width: 0;
  border-top: none; border: 1px solid var(--gray-200); border-radius: 8px;
  margin-bottom: 6px;
}
.teamchat-msg .quoted-block {
  display: flex; gap: 8px; align-items: stretch;
  padding: 5px 8px; margin-bottom: 4px;
  background: rgba(0,0,0,0.05); border-radius: 6px;
  cursor: pointer;
}
.teamchat-msg .quoted-block-bar { width: 3px; border-radius: 2px; background: #25d366; flex-shrink: 0; }
.teamchat-msg .quoted-block-body { flex: 1; min-width: 0; }
.teamchat-msg .quoted-block-author { font-size: 11px; font-weight: 600; color: #128c7e; }
.teamchat-msg .quoted-block-snippet { font-size: 12px; color: var(--gray-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Flash a message bubble briefly when scrolled-to via a quoted-block
   click — used by both the inbox and the team chat. */
@keyframes msgFlashKf {
  0%   { background: rgba(37, 211, 102, 0.30); }
  100% { background: transparent; }
}
.msg-flash, .bubble.msg-flash {
  animation: msgFlashKf 1.2s ease-out;
  border-radius: 8px;
}
.bubble img { max-width: 280px; border-radius: 8px; display: block; }
.bubble .doc-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; background: rgba(0,0,0,0.04); border-radius: 6px;
  margin-bottom: 4px;
}
.bubble .doc-card [data-lucide] { width: 24px; height: 24px; color: var(--gray-500); flex-shrink: 0; }
.bubble .doc-name { font-size: 13px; font-weight: 500; color: var(--gray-700); word-break: break-all; }
.bubble.fromMe.is-bot { background: #ede9fe; }
.bubble .bot-tag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600; color: #6d28d9;
  background: #ddd6fe; padding: 1px 6px; border-radius: 999px;
  margin-bottom: 4px;
}
.bubble .bot-tag [data-lucide] { width: 11px; height: 11px; }

/* Coaching badge on bot bubbles (1+ corrections exist on this reply). */
.bubble .bot-coach-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600; color: #92400e;
  background: #fef3c7; padding: 1px 6px; border-radius: 999px;
  margin-left: 6px; margin-bottom: 4px; cursor: pointer;
  border: none;
}
.bubble .bot-coach-badge:hover { background: #fde68a; }
.bubble .bot-coach-badge.has-permanent { background: #fde68a; color: #78350f; }
.bubble .bot-coach-count { font-size: 10px; }

/* Floating popover anchored to the badge — lists each note with admin/author actions. */
.bot-coach-popover {
  position: fixed; z-index: 1000;
  width: 320px; max-height: 380px; overflow-y: auto;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 8px;
}
.bot-coach-popover-title {
  font-size: 12px; font-weight: 600; color: var(--gray-600);
  padding: 4px 6px 8px; border-bottom: 1px solid var(--gray-100); margin-bottom: 6px;
}
.bot-coach-popover-row {
  padding: 8px 6px; border-radius: 6px;
}
.bot-coach-popover-row:hover { background: var(--gray-50); }
.bot-coach-popover-row + .bot-coach-popover-row { border-top: 1px solid var(--gray-100); }
.bot-coach-popover-row.permanent { background: #fef9c3; }
.bot-coach-popover-meta {
  font-size: 11px; color: var(--gray-500); margin-bottom: 4px;
}
.bot-coach-popover-body {
  font-size: 13px; color: var(--gray-800); white-space: pre-wrap; word-break: break-word;
}
.bot-coach-popover-actions {
  display: flex; gap: 6px; margin-top: 6px;
}
.btn.btn-tiny {
  font-size: 11px; padding: 3px 8px; line-height: 1.2;
}

/* Bot coach modal context boxes */
.bot-coach-context {
  background: var(--gray-50); border: 1px solid var(--gray-200);
  border-radius: 8px; padding: 10px;
}
.bot-coach-context-label {
  font-size: 11px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px;
}
.bot-coach-context-box {
  padding: 6px 8px; background: #fff; border-radius: 6px;
  font-size: 13px; color: var(--gray-800); white-space: pre-wrap; word-break: break-word;
  max-height: 120px; overflow-y: auto;
}
.bot-coach-context-box.bot-coach-reply {
  background: #ede9fe; color: #4c1d95;
}

/* Bot status pill in settings modal title */
.bot-pill {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--gray-200); color: var(--gray-600);
  margin-left: 8px; vertical-align: middle; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.bot-pill.on { background: #ddd6fe; color: #6d28d9; }

/* Compose */
/* Image lightbox — click any image bubble anywhere in the platform
   (inbox 1-1/group, team chat DM, team chat WA-group inline) to open
   the full-resolution image centered over a dark backdrop. Esc /
   backdrop click / × closes. */
.image-lightbox {
  position: fixed; inset: 0;
  z-index: 250;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.image-lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}
.image-lightbox img {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  cursor: default;
}
.image-lightbox-close,
.image-lightbox-download {
  position: absolute;
  top: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  text-decoration: none;
  z-index: 1;
  transition: background 0.15s;
}
.image-lightbox-close:hover,
.image-lightbox-download:hover {
  background: rgba(255, 255, 255, 0.22);
}
.image-lightbox-close { right: 16px; }
.image-lightbox-download { right: 64px; }
.image-lightbox-close i,
.image-lightbox-download i { width: 20px; height: 20px; }

/* Image annotation editor — full-screen-ish modal with toolbar at top
   and a canvas that scales-to-fit while preserving the source image's
   internal resolution for the final blob. */
.image-editor-card {
  width: 96vw; max-width: 1100px;
  height: 92vh; max-height: 900px;
  display: flex; flex-direction: column;
  padding: 0;
}
.image-editor-card .modal-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--gray-200);
}
.image-editor-toolbar {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.image-editor-tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit; font-size: 13px;
  color: var(--gray-700);
}
.image-editor-tool i { width: 16px; height: 16px; }
.image-editor-tool:hover { background: var(--gray-100); }
.image-editor-tool.active {
  background: var(--blue-100, #dbeafe);
  color: var(--blue-700, #1d4ed8);
  border-color: var(--blue-200, #bfdbfe);
}
.image-editor-color-row {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 6px;
  padding-left: 8px;
  border-left: 1px solid var(--gray-200);
}
.image-editor-color {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.image-editor-color.active { border-color: var(--gray-700); }
.image-editor-spacer { flex: 1; }
.image-editor-body {
  flex: 1; min-height: 0;
  background: #1f2937;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  padding: 0;
}
.image-editor-canvas-wrap {
  max-width: 100%; max-height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.image-editor-canvas {
  max-width: 100%; max-height: 100%;
  background: #fff;
  display: block;
  cursor: crosshair;
  touch-action: none; /* let JS handle drag without browser scrolling */
}

/* Multi-attach preview strip — sits above the composer when at least
   one file is staged. Horizontal thumbnail strip + caption row. */
.attach-preview {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px;
  background: var(--gray-50, #f9fafb);
  border-top: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.attach-preview-strip {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.attach-preview-thumb {
  position: relative;
  width: 80px; height: 80px;
  border-radius: 8px;
  background: var(--gray-200) center/cover no-repeat;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s;
}
.attach-preview-thumb:hover { transform: scale(1.04); }
.attach-preview-thumb.edited::before {
  content: "✎";
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(37, 99, 235, 0.92); color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}
.attach-preview-thumb.video::after {
  content: "▶";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #fff; font-size: 24px;
  text-shadow: 0 0 6px rgba(0,0,0,0.6);
  pointer-events: none;
}
/* Document / audio tiles in the attach preview — same 80×80 footprint
   as image thumbnails but render an icon + truncated filename + size
   instead of a thumbnail since these have no native preview. */
.attach-preview-doc {
  background: #f3f4f6;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 6px;
  cursor: default;
}
.attach-preview-doc:hover { transform: none; }
.attach-preview-doc-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  color: #2563eb;
}
.attach-preview-doc-icon i { width: 28px; height: 28px; }
.attach-preview-doc-meta {
  width: 100%; min-width: 0;
  text-align: center;
  margin-top: 4px;
}
.attach-preview-doc-name {
  font-size: 10px; font-weight: 500; color: var(--gray-800);
  line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-preview-doc-size {
  font-size: 9px; color: var(--gray-500);
  margin-top: 1px;
}
.attach-preview-thumb-remove {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px;
  background: rgba(0,0,0,0.6); color: #fff;
  border: none; border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1;
  padding: 0;
}
.attach-preview-thumb-remove:hover { background: rgba(0,0,0,0.85); }
.attach-preview-add {
  width: 80px; height: 80px;
  border: 2px dashed var(--gray-400);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--gray-500);
}
.attach-preview-add:hover { border-color: var(--blue-500, #2563eb); color: var(--blue-500, #2563eb); }
.attach-preview-add i { width: 24px; height: 24px; }
.attach-preview-row {
  display: flex; align-items: center; gap: 6px;
}
.attach-preview-caption {
  flex: 1; min-width: 0;
  padding: 9px 14px;
  border: 0; background: var(--gray-100); border-radius: 20px;
  font-family: inherit; font-size: 14px; color: var(--gray-900);
  outline: none;
}
.attach-preview-caption:focus { background: #fff; box-shadow: 0 0 0 1px var(--gray-300); }
.attach-preview-voice-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: rgba(37, 211, 102, 0.15);
  color: #128c7e;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
}
.attach-preview-voice-pill i { width: 14px; height: 14px; }
.attach-preview-voice-discard {
  background: transparent; border: 0; cursor: pointer;
  padding: 0; display: inline-flex; color: inherit;
}
.attach-preview-voice-discard i { width: 12px; height: 12px; }
.attach-preview .attach-preview-thumb.failed { border-color: #ef4444; }
.attach-preview .attach-preview-thumb.failed::before {
  content: "⚠";
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(239, 68, 68, 0.95); color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1;
}
/* Oversize warning — file is over the 100 MB server cap and will be
   rejected on send. Red border + warning chip so the agent removes it
   before clicking ✈️. */
.attach-preview .attach-preview-thumb.oversize {
  border-color: #f97316;
  background-color: #fff7ed;
}
.attach-preview .attach-preview-thumb.oversize::before {
  content: "⚠";
  position: absolute; top: 4px; left: 4px;
  background: #f97316; color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1;
}
.attach-preview-doc-size.oversize { color: #c2410c; font-weight: 600; }

/* Will-compress hint — PDF is between 95 MB and 500 MB, server will
   run Ghostscript before sending so it lands under WhatsApp's 100 MB
   cap. Yellow (not red) so the agent knows it'll work but takes
   longer than usual. */
.attach-preview .attach-preview-thumb.will-compress {
  border-color: #eab308;
  background-color: #fefce8;
}
.attach-preview .attach-preview-thumb.will-compress::before {
  content: "⏱";
  position: absolute; top: 4px; left: 4px;
  background: #eab308; color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}
.attach-preview-doc-size.will-compress { color: #854d0e; font-weight: 600; }

/* Live status bar at the bottom of an attach-preview tile during
   send. Width animates 0% → 100% as chunks complete; status text
   replaces the size text on the same line. Stays on the tile until
   the strip is cleared so the agent always sees what's happening. */
.attach-preview-progress {
  position: absolute;
  left: 0; bottom: 0; height: 3px;
  background: var(--green-500, #22c55e);
  border-radius: 0 0 8px 8px;
  transition: width 200ms linear;
  pointer-events: none;
}
.attach-preview .attach-preview-thumb { position: relative; }

.compose {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px; border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0; position: relative;
}
/* When the multi-attach preview is active, hide the composer's regular
   controls but KEEP .compose as a structural container so #recordOverlay
   (which lives inside it) can still mount when the batch's mic button
   triggers startRecording. Without this, the agent's voice-record click
   silently did nothing. */
.compose.batching > *:not(#recordOverlay) {
  display: none;
}
.compose.batching {
  padding: 0; border-top: 0;
  /* Collapse height when nothing visible inside. */
  min-height: 0;
}
/* WhatsApp-style attach popover anchored above the paperclip button. */
.attach-menu {
  position: absolute;
  bottom: 56px;
  left: 50px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 220px;
  z-index: 200;
}
.attach-menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  color: var(--text);
  transition: background var(--motion-fast) var(--ease);
}
.attach-menu-item:hover { background: var(--surface-hover); }
.attach-menu-item i { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
/* Mic-device picker popover — same visual language as .attach-menu but
   anchored to #micDeviceBtn (right side of composer). Rows are radio +
   label; virtual devices get a red warning suffix. */
.mic-picker-popover {
  position: absolute;
  bottom: 56px;
  right: 60px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 260px;
  max-width: 340px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
}
.mic-picker-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  color: var(--text);
}
.mic-picker-row:hover { background: var(--surface-hover); }
.mic-picker-row input[type="radio"] { margin: 0; flex-shrink: 0; }
.mic-picker-row .mic-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mic-picker-row .mic-warn { color: #dc2626; font-size: 11px; margin-left: 4px; }
.mic-picker-empty { padding: 12px; color: var(--text-muted); font-size: 13px; text-align: center; }
.compose-input {
  flex: 1; min-height: 38px; max-height: 120px;
  padding: 9px 14px;
  border: 1px solid transparent;
  background: var(--surface-sunken);
  border-radius: 20px;
  font-family: inherit; font-size: 14px; color: var(--text);
  resize: none; outline: none; line-height: 1.4;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.compose-input::placeholder { color: var(--text-muted); }
.compose-input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.record-overlay {
  position: absolute; inset: 0; display: flex; align-items: center;
  gap: 10px; padding: 8px 12px;
  background: #fff;
}
.record-trash-btn {
  flex-shrink: 0;
  color: var(--gray-500);
}
.record-trash-btn:hover { color: #dc2626; background: #fef2f2; }
.record-bar {
  flex: 1; display: flex; align-items: center; gap: 12px;
  background: #f9fafb; border: 1px solid var(--gray-200);
  border-radius: 999px; padding: 6px 14px;
  min-width: 0;
}
.record-status {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 8px;
  font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600;
  color: #dc2626;
}
.record-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #dc2626; animation: pulse 1s infinite;
  flex-shrink: 0;
}
.record-waveform {
  flex: 1; height: 32px; min-width: 0;
  display: block;
}
.record-pause-btn {
  flex-shrink: 0;
  width: 36px; height: 36px;
  background: var(--gray-100); border-radius: 50%;
  color: var(--gray-700);
}
.record-pause-btn:hover { background: var(--gray-200); }
.record-pause-btn.paused {
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
}
.record-send-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  background: #25d366 !important;
  border-radius: 50% !important;
  color: #fff !important;
}
.record-send-btn:hover { background: #1ebe5a !important; }

/* ─── Profile panel ──────────────────────────────────────────────────
   Right-rail panel for Contact + Group profiles. Surface stack:
     panel = --surface (white / charcoal)
     head + body backdrop = --surface-sunken (recessed)
     each card = --surface again, separated by hairlines */
.profile-panel {
  border-left: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.profile-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-sunken); flex-shrink: 0;
}
.profile-id { flex: 1; min-width: 0; }
.profile-id h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-id .small { font-size: 11px; margin: 2px 0 0; color: var(--text-tertiary); }
.profile-body {
  flex: 1; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-sunken);
  position: relative; /* anchors the .ai-popup overlay inside the pane */
}
.profile-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden;
}
.profile-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  background: var(--surface); border-bottom: 1px solid transparent;
  transition: background 0.15s;
}
.profile-card[open] .profile-card-head { border-bottom-color: var(--border-subtle); }
.profile-card-head:hover { background: var(--surface-hover); }
.card-title { display: inline-flex; align-items: center; gap: 8px; }
.card-title [data-lucide] { width: 16px; height: 16px; color: var(--text-tertiary); }
.card-toggle {
  border: 0; background: transparent; cursor: pointer; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: var(--radius-sm);
}
.card-toggle:hover { background: var(--surface-hover); color: var(--text); }
.profile-card-body {
  padding: 10px 12px; font-size: 13px; color: var(--text-secondary);
  display: none;
}
.profile-card.open .profile-card-body { display: block; }
.profile-card.open .card-toggle { transform: rotate(180deg); }

.field-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
/* Click-to-copy affordance on profile fields. Hovering a non-editable
   value shows a `cursor: copy` so agents know it's clickable; the
   delegated click handler on #profileSections copies + toasts. Editable
   rows keep their own pointer + edit behaviour. */
#profileSections .field-val,
#profileSections .field-key,
#profileSections .li-title,
#profileSections .li-sub { user-select: text; }
#profileSections .field-row:not(.field-row-editable) .field-val:not(.empty):hover {
  cursor: copy;
}
#profileSections .li-sub:hover { cursor: copy; }

.field-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--gray-100); font-size: 13px; }
.field-row:last-child { border-bottom: 0; }
.field-key { min-width: 100px; color: var(--gray-500); font-size: 12px; flex-shrink: 0; padding-top: 1px; }
.field-val { color: var(--gray-900); flex: 1; word-break: break-word; }
.field-val.empty { color: var(--gray-300); font-style: italic; }

.list-item {
  padding: 8px 10px; border-radius: 6px; background: var(--gray-50);
  margin-bottom: 6px; font-size: 13px;
}
.list-item:last-child { margin-bottom: 0; }
.field-row-editable:hover .field-val { color: #4338ca; text-decoration: underline; text-decoration-style: dashed; text-underline-offset: 2px; }
.field-row-editable.editing { background: rgba(99, 102, 241, 0.04); border-radius: 6px; padding: 6px 8px; }
.list-item-clickable { transition: background 0.15s, border-color 0.15s; }
.list-item-clickable:hover {
  background: rgba(99, 102, 241, 0.06);
  border-color: rgba(99, 102, 241, 0.4);
}
.list-item-clickable:hover .li-title { color: #4338ca; }
/* Quick visual feedback when an "Open" click points at the chat we're
 * already viewing — pulses the conv-item's background indigo so the
 * agent knows the click registered. */
@keyframes conv-flash {
  0%   { background-color: rgba(99, 102, 241, 0.30); }
  100% { background-color: transparent; }
}
.conv-item.flash { animation: conv-flash 0.6s ease-out; }
.li-open-hint { margin-left: auto; opacity: 0.6; transition: opacity 0.15s; }
.list-item-clickable:hover .li-open-hint { opacity: 1; color: #4338ca; }
.list-item .li-title { font-weight: 600; color: var(--gray-900); }
.list-item .li-sub { font-size: 11px; color: var(--gray-500); margin-top: 2px; }
.list-item a { color: var(--blue-500); text-decoration: none; font-size: 11px; }
.list-item a:hover { text-decoration: underline; }

.empty-row { color: var(--gray-400); font-size: 12px; text-align: center; padding: 12px; }

.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border: 0; background: transparent;
  border-radius: 4px; cursor: pointer;
  font-size: 11px; font-weight: 500; color: var(--blue-500);
}
.link-btn:hover { background: var(--gray-100); }
.link-btn [data-lucide] { width: 12px; height: 12px; }

/* AI summary */
.ai-card { border: 1px solid var(--violet-500); }
.ai-card .profile-card-head { background: linear-gradient(135deg, #f5f3ff, #fff); }
.ai-card .card-title [data-lucide] { color: var(--violet-500); }
.ai-body { white-space: pre-wrap; line-height: 1.6; font-size: 12.5px; }
.ai-body.loading { color: var(--gray-400); display: flex; align-items: center; gap: 8px; }

/* ─── Modal (H4: bigger title, more padding, blurred backdrop, calmer foot) ─── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: oklch(0.10 0.012 250 / 0.55);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
}
[data-theme="dark"] .modal-backdrop { background: oklch(0 0 0 / 0.65); }
.modal-card {
  position: relative; width: 100%; max-width: 540px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; max-height: 90vh; overflow: hidden;
  color: var(--text);
}
.modal-lg { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--border-subtle);
}
.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px; font-weight: 500;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 144;
  color: var(--text);
  display: inline-flex; align-items: center; gap: 10px;
}
.modal-head h2 [data-lucide] {
  width: 18px; height: 18px; color: var(--accent); stroke-width: 2;
}
.modal-body { padding: 20px 22px; overflow-y: auto; color: var(--text-secondary); }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--border-subtle);
  background: var(--surface-elevated);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal-foot.has-hint { background: var(--surface-sunken); }

/* Documents modal */
.doc-tabs { display: flex; padding: 8px 14px 0; border-bottom: 1px solid var(--border); gap: 4px; background: var(--surface-elevated); }
.doc-tab {
  padding: 8px 14px; border: 0; background: transparent;
  border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 500; color: var(--text-tertiary); cursor: pointer;
  font-family: inherit;
  transition: color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.doc-tab:hover { color: var(--text); }
.doc-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.doc-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

.doc-items { display: flex; flex-direction: column; gap: 6px; }
.doc-item {
  display: grid; grid-template-columns: 2fr 80px 100px 28px; gap: 6px;
  align-items: center;
}
.doc-item .input { padding: 7px 10px; font-size: 13px; }
.doc-item-del {
  width: 28px; height: 28px; border: 0; background: transparent;
  border-radius: 6px; color: var(--red-500); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.doc-item-del:hover { background: #fee2e2; }
.doc-item-del [data-lucide] { width: 14px; height: 14px; }

.doc-totals {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; background: var(--gray-50); border-radius: 8px;
  font-size: 13px;
}
.doc-totals > div { display: flex; justify-content: space-between; }
.doc-totals .total {
  padding-top: 6px; border-top: 1px solid var(--gray-200);
  font-size: 14px; color: var(--gray-900);
}

/* Templates */
.template-form { display: flex; flex-direction: column; gap: 8px; }
.tpl-category-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px;
}
.tpl-cat-btn {
  padding: 5px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 12px; font-weight: 500; color: var(--text-secondary);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.tpl-cat-btn:hover { background: var(--surface-hover); }
.tpl-cat-btn.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent); font-weight: 600;
}
.tpl-cat-tag {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  margin-left: 6px;
  letter-spacing: 0.06em;
}
/* Category tags — each tied to a distinct OKLCH-balanced avatar slot
   so they stay readable in both themes and the four categories remain
   visually distinct. */
.tpl-cat-tag-student  { background: oklch(0.62 0.18 220 / 0.18); color: var(--av-2); }
.tpl-cat-tag-group    { background: oklch(0.62 0.18 350 / 0.18); color: var(--av-5); }
.tpl-cat-tag-reminder { background: var(--warning-soft);          color: var(--warning); }
.tpl-cat-tag-club     { background: oklch(0.62 0.18 310 / 0.18); color: var(--av-4); }

.reminder-tpl-picker {
  display: flex; flex-direction: column; gap: 6px;
  margin: 8px 0 12px;
}
.reminder-tpl-label { font-size: 11px; color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.reminder-tpl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.reminder-tpl-chip {
  padding: 5px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
}
.reminder-tpl-chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.reminder-tpl-empty { font-size: 12px; color: var(--text-tertiary); font-style: italic; }
.tpl-list { display: flex; flex-direction: column; gap: 8px; }
.tpl-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; background: var(--surface-sunken); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: border-color var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease);
}
.tpl-item:hover { border-color: var(--border-strong); }
.tpl-body { flex: 1; min-width: 0; }
.tpl-name { font-weight: 600; font-size: 13px; color: var(--text); }
.tpl-content { font-size: 12px; color: var(--text-secondary); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.tpl-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn-sm.tpl-send-btn {
  background: var(--success-soft); color: var(--success);
}
.icon-btn-sm.tpl-send-btn:hover { background: var(--success-soft); filter: brightness(0.96); }
[data-theme="dark"] .icon-btn-sm.tpl-send-btn:hover { filter: brightness(1.15); }

/* Inline edit — when an agent clicks the ✏️ icon on a template card,
   that card flips into a form. The info-soft tint + info border mark
   which row is being edited so the agent doesn't lose track in a long
   list. */
.tpl-item.tpl-item-editing {
  background: var(--info-soft);
  border-color: var(--info);
  flex-direction: column;
  align-items: stretch;
}
.tpl-edit-form { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.tpl-edit-form .input { font-size: 13px; }
.tpl-edit-form .tpl-edit-content { font-family: inherit; resize: vertical; min-height: 96px; }
.tpl-edit-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.tpl-edit-actions .tpl-edit-cat { max-width: 160px; }
.tpl-edit-actions .btn { padding: 6px 12px; font-size: 12px; }

/* Checkbox for multi-template select. Hidden by default; revealed
   on hover OR when the row is already selected (so the green check
   stays visible). Same green accent as message multi-select. */
.tpl-checkbox {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  display: none;
  align-items: center; justify-content: center;
  color: var(--text-tertiary);
  cursor: pointer; padding: 0; flex-shrink: 0;
  margin-top: 2px;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.tpl-checkbox svg { width: 14px; height: 14px; }
.tpl-item:hover .tpl-checkbox { display: inline-flex; }
.tpl-checkbox.selected {
  display: inline-flex;
  background: var(--success); color: #fff; border-color: var(--success);
}
.tpl-item.tpl-item-selected {
  background: var(--success-soft);
  border-color: var(--success);
}

/* Sticky footer at the bottom of the templates modal — replaces
   the per-card ✈️ for the multi-send flow. */
.tpl-multi-send-bar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-top: 12px;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.tpl-multi-send-bar.hidden { display: none; }
.tpl-multi-count { font-weight: 600; color: var(--text); font-size: 13px; }
.tpl-multi-send-bar .btn { padding: 6px 14px; font-size: 13px; }

/* ───── Multi-select / Forward / Copy ─────
   Hover a bubble to reveal the ◯ select button. In selection mode
   we still keep ◯ hover-only for unselected rows (less visual
   clutter than WA Desktop's all-rows-show approach), but selected
   rows show a permanent green check + a tinted background. */
.message-row { position: relative; }
.msg-select-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  left: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--gray-300, #d1d5db);
  display: none;
  align-items: center; justify-content: center;
  color: var(--gray-500, #6b7280);
  cursor: pointer; padding: 0;
  z-index: 5;
}
.msg-select-btn svg { width: 14px; height: 14px; }
.message-row:hover .msg-select-btn { display: flex; }
.msg-select-btn.selected {
  display: flex;  /* always visible when selected */
  background: #22c55e; color: #fff; border-color: #16a34a;
}
.message-row.fromMe .msg-select-btn { left: auto; right: 4px; }

/* Hover reply icon — sits just inside the select button. Visible
   only on hover (and not while in selection mode, where the
   ◯ takes priority). Keeps inbox + team chat in parity. */
.msg-reply-btn,
.teamchat-msg-row .msg-reply-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  left: 30px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--gray-300, #d1d5db);
  display: none;
  align-items: center; justify-content: center;
  color: var(--gray-500, #6b7280);
  cursor: pointer; padding: 0;
  z-index: 5;
}
.msg-reply-btn svg { width: 13px; height: 13px; }
.message-row:hover .msg-reply-btn,
.teamchat-msg-row:hover .msg-reply-btn { display: flex; }
.message-row.selection-mode .msg-reply-btn,
.teamchat-msg-row.selection-mode .msg-reply-btn { display: none !important; }
.message-row.fromMe .msg-reply-btn { left: auto; right: 30px; }
.teamchat-msg-row.me .msg-reply-btn { left: auto; right: 30px; }
.message-row.is-selected { background: rgba(34, 197, 94, 0.08); }
.message-row.selection-mode { cursor: pointer; }

/* Edit / Delete hover buttons on Team chat bubbles. Same circular
   chip style as msg-reply-btn so the row keeps a consistent look as
   the buttons stack. Order from right edge inward (own-row): Reply
   (30px), Edit (56px), Delete (82px). */
.teamchat-msg-row .msg-edit-btn,
.teamchat-msg-row .msg-delete-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--gray-300, #d1d5db);
  display: none;
  align-items: center; justify-content: center;
  color: var(--gray-500, #6b7280);
  cursor: pointer; padding: 0;
  z-index: 5;
}
.teamchat-msg-row .msg-edit-btn svg,
.teamchat-msg-row .msg-delete-btn svg { width: 13px; height: 13px; }
.teamchat-msg-row.me .msg-edit-btn   { right: 56px; }
.teamchat-msg-row.me .msg-delete-btn { right: 82px; color: #b91c1c; }
.teamchat-msg-row:hover .msg-edit-btn,
.teamchat-msg-row:hover .msg-delete-btn { display: flex; }
.teamchat-msg-row.selection-mode .msg-edit-btn,
.teamchat-msg-row.selection-mode .msg-delete-btn { display: none !important; }

/* Inline edit form replaces the .teamchat-msg-text while editing.
   Textarea matches the bubble width so the user can see the full line
   they're rewriting; Save / Cancel sit below on their own row. */
.teamchat-edit-form { display: flex; flex-direction: column; gap: 6px; }
.teamchat-edit-textarea {
  min-width: 220px; max-width: 100%;
  padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px;
  font: inherit; resize: vertical;
  background: rgba(255,255,255,0.95); color: #111827;
}
.teamchat-msg.me .teamchat-edit-textarea { background: rgba(255,255,255,0.85); }
.teamchat-edit-btns { display: flex; gap: 6px; justify-content: flex-end; }
.teamchat-edit-btns .btn { padding: 4px 10px; font-size: 12px; }

/* "edited" indicator next to the timestamp. Quiet styling — sits in
   the same meta row as the time + tick, doesn't compete for attention
   but tells the recipient the bubble is post-edit. */
.teamchat-msg-edited {
  font-size: 10px; color: var(--gray-500, #6b7280); font-style: italic;
  margin-left: 2px;
}

/* Bottom toolbar — replaces the composer while selection is active.
   Mounted as a sibling immediately before .compose so the agent
   sees Cancel / Copy / Forward in the exact spot they expect a
   send button. */
.msg-selection-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--gray-200);
  background: #fff; flex-shrink: 0;
}
.msg-selection-bar.hidden { display: none; }
.msg-selection-count { font-weight: 600; color: var(--gray-800, #1f2937); }
.msg-selection-bar .btn { padding: 6px 14px; font-size: 13px; }
.msg-selection-bar .icon-btn.msg-selection-x { color: var(--gray-700, #374151); }
.compose.hidden-during-selection,
.teamchat-compose.hidden-during-selection { display: none; }

/* "Forwarded" label inside a forwarded bubble */
.forwarded-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--gray-500, #6b7280);
  font-style: italic; margin-bottom: 4px;
}
.forwarded-tag svg { width: 12px; height: 12px; }

/* Forward picker modal — chat list with multi-select ticks */
.fwd-chat-list {
  max-height: 360px; overflow-y: auto;
  border: 1px solid var(--gray-200); border-radius: 8px;
}
.fwd-chat-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
}
.fwd-chat-row:last-child { border-bottom: 0; }
.fwd-chat-row:hover { background: var(--gray-50); }
.fwd-chat-row.picked { background: rgba(34, 197, 94, 0.08); }
.fwd-chat-name { flex: 1; min-width: 0; font-size: 13px; color: var(--gray-900); }
.fwd-chat-tick svg { width: 18px; height: 18px; color: var(--gray-400); }
.fwd-chat-row.picked .fwd-chat-tick svg { color: #16a34a; }

/* Section titles inside the forward picker. The "Team" title is
   meant to feel anchored — same visual rhythm as the WhatsApp
   title underneath. Both stick to the top of their respective
   sections via position:sticky so the agent always knows what
   they're scrolling through. */
.fwd-section-title {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--gray-100, #f3f4f6);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--gray-700, #374151); letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
}
.fwd-section-title svg { width: 14px; height: 14px; }

/* Sticker bubble — transparent, no background, smaller than a
   regular image. Matches WhatsApp's own sticker rendering. */
.bubble.sticker-bubble {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  box-shadow: none !important;
}
.bubble .sticker {
  max-width: 160px; max-height: 160px;
  width: auto; height: auto;
  display: block;
  background: transparent;
}
.fwd-team-row { background: rgba(99, 102, 241, 0.04); }
.fwd-team-row:hover { background: rgba(99, 102, 241, 0.08); }
.fwd-team-row.picked { background: rgba(34, 197, 94, 0.10); }
.fwd-team-row .fwd-chat-name::after {
  /* The " · Team" / " · Room" suffix is part of the text node now,
     keep the row clean */
  content: '';
}
.avatar.avatar-room { background: var(--indigo-500, #6366f1); }

/* Notes */
.notes-list { display: flex; flex-direction: column; gap: 8px; }
.note-item {
  padding: 10px; background: #fef3c7; border: 1px solid #fde68a; border-radius: 8px;
  font-size: 13px; color: var(--gray-800); position: relative;
}
.note-time { font-size: 11px; color: var(--gray-500); margin-top: 4px; }
.note-del {
  position: absolute; top: 6px; right: 6px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--gray-400); padding: 2px;
}
.note-del:hover { color: var(--red-500); }

/* Bot toggle active state */
.icon-btn.bot-on { background: #ede9fe; color: var(--violet-500); }
.icon-btn.bot-on:hover { background: #ddd6fe; color: var(--violet-500); }
.icon-btn.profile-active { background: var(--wa-soft); color: var(--wa); }

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--gray-900); color: #fff; padding: 10px 16px;
  border-radius: var(--radius-sm); font-size: 13px;
  box-shadow: var(--shadow); z-index: 200;
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red-500); }
.toast.success { background: var(--wa-dark); }

/* ─── Scrollbars ─── */
.conv-list, .messages-area, .dropdown-menu {
  scrollbar-width: thin; scrollbar-color: var(--gray-300) transparent;
}
.conv-list::-webkit-scrollbar,
.messages-area::-webkit-scrollbar,
.dropdown-menu::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb,
.dropdown-menu::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  .main { grid-template-columns: 100% 0 0; }
  .main.show-chat { grid-template-columns: 0 100% 0; }
  .main.show-chat .sidebar { display: none; }
  .main:not(.show-chat) .chat-pane { display: none; }
  .main.with-profile #profilePanel,
  .main.with-conv-details #convDetailsPanel { display: none; } /* mobile collapses both panels */
  .chat-actions .icon-btn:nth-child(n+4) { display: none; }
}

/* ─── Bulk send view ─── */
.gap8 { gap: 8px; }
/* C5: segmented-control treatment for top view-tabs */
.view-tabs {
  display: flex; gap: 2px; margin-left: 16px;
  padding: 4px;
  background: var(--gray-100); border-radius: 10px;
}
.view-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  background: transparent; border: 0; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--gray-600);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.view-tab:hover { background: rgba(255,255,255,0.6); color: var(--gray-900); }
.view-tab [data-lucide] { width: 15px; height: 15px; stroke-width: 2; }
.view-tab.view-tab-active {
  background: #fff;
  color: #0c4a6e;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 0 0 1px var(--gray-200);
}
.view-tab.view-tab-active [data-lucide] { color: #10b7e2; stroke-width: 2.25; }
.view-tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: #ef4444; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
  margin-left: 2px;
}
.view-tab-badge.hidden { display: none; }

/* Dropdown groups in the top bar. Each .view-tab-group holds a
   .view-tab-trigger button (visible in the bar) and a .view-tab-menu
   panel (anchored just below the trigger when .open is set). Reuses
   the popover look from #attachMenu so the topbar dropdowns and the
   attach (📎) popover stay visually consistent. */
.view-tab-group { position: relative; display: inline-flex; }
.view-tab-trigger .view-tab-chevron {
  width: 12px; height: 12px; opacity: 0.7;
  transition: transform 0.15s;
}
.view-tab-group.open .view-tab-trigger .view-tab-chevron { transform: rotate(180deg); }
.view-tab-menu {
  position: absolute;
  top: calc(100% + 6px); left: 0;
  z-index: 200;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 6px;
  display: none;
  flex-direction: column; gap: 2px;
}
.view-tab-group.open .view-tab-menu { display: flex; }
.view-tab-item {
  display: inline-flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 12px; border-radius: 8px;
  background: transparent; border: 0; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--gray-700);
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.view-tab-item:hover { background: var(--gray-100); color: var(--gray-900); }
.view-tab-item [data-lucide] { width: 16px; height: 16px; stroke-width: 2; flex-shrink: 0; color: var(--gray-500); }
.view-tab-item:hover [data-lucide] { color: #10b7e2; }
/* Highlight the active child inside the open menu so the user always
   knows which sub-view they're currently looking at, even with the
   parent trigger in the active state behind. */
.view-tab-item.view-tab-active {
  background: #eff6ff;
  color: #0c4a6e;
}
.view-tab-item.view-tab-active [data-lucide] { color: #10b7e2; }
/* The aggregated parent badge sits inline with the chevron — keeps
   the visual rhythm of the existing single-tab badges. */
.view-tab-trigger .view-tab-group-badge { margin-left: 2px; }

/* Phone numbers detected inside a message bubble — clickable chip that
   opens the matching 1-1 chat. Underline on hover so the affordance is
   obvious without being noisy at rest. */
.msg-phone-link {
  color: var(--wa); font-weight: 500;
  text-decoration: none; cursor: pointer;
  border-bottom: 1px dashed currentColor;
}
.msg-phone-link:hover {
  text-decoration: none;
  border-bottom-style: solid;
  background: rgba(37, 211, 102, 0.08);
  border-radius: 3px;
}
/* @-mention chip — resolved JIDs render as "@Name" with a subtle blue
   highlight so the team can tell it was tag-resolved rather than typed. */
.msg-mention-chip {
  color: #1e6fd9;
  font-weight: 600;
  background: rgba(30, 111, 217, 0.08);
  border-radius: 3px;
  padding: 0 3px;
}

/* Team-only inline timeline event ("Asmae a créé un ticket #12345").
   Centered chip row between message bubbles. Pale neutral background so
   it's clearly distinguishable from WhatsApp messages without screaming. */
.event-chip-row {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}
.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 80%;
  padding: 5px 12px;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  font-size: 12px;
  color: #475569;
  line-height: 1.3;
}
.event-chip-icon { font-size: 13px; }
.event-chip-text { font-weight: 500; }
.event-chip-time { color: #94a3b8; font-size: 11px; }

/* ─── Certificate drag-and-drop editor ───────────────────────────── */
.cert-editor {
  border: 1px solid var(--gray-200, #e5e7eb);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cert-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.cert-editor-hint {
  font-size: 12px;
  color: var(--gray-500, #6b7280);
  line-height: 1.3;
}
.cert-editor-add-btn {
  background: #142463;
  color: #fff;
  border: 0;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.cert-editor-add-btn:hover { background: #1e336f; }
.cert-editor-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 254 / 143;
  overflow: hidden;
  border-radius: 8px;
  user-select: none;
  background: #f8fafc;
  container-type: inline-size;
}
.cert-editor-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.cert-editor-layer {
  position: absolute;
  z-index: 1;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  cursor: move;
  padding: 2px 4px;
  border-radius: 4px;
  outline: 1px dashed transparent;
  outline-offset: 2px;
}
.cert-editor-layer:hover { outline-color: rgba(20, 36, 99, 0.4); background: rgba(20, 36, 99, 0.04); }
.cert-editor-layer-dragging { outline-color: #142463; outline-style: solid; background: rgba(20, 36, 99, 0.08); }
.cert-editor-layer[contenteditable="true"] { outline-color: #16a34a; outline-style: solid; background: #fff; cursor: text; }
.cert-editor-del-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #ef4444;
  background: #fff;
  color: #ef4444;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.cert-editor-layer:hover .cert-editor-del-btn { opacity: 1; }
.cert-editor-del-btn:hover { background: #ef4444; color: #fff; }
.msg-link {
  color: #1d4ed8; text-decoration: underline; word-break: break-all;
}
.msg-link:hover { color: #1e40af; background: rgba(29, 78, 216, 0.08); border-radius: 3px; }
.bubble.fromMe .msg-link { color: #065f46; }
.bubble.fromMe .msg-link:hover { color: #047857; background: rgba(6, 95, 70, 0.08); }

.bulk-view {
  flex: 1; overflow: hidden; background: var(--bg);
  display: flex; flex-direction: column;
}
.bulk-grid {
  flex: 1; display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: 16px; padding: 16px; overflow: hidden;
}
.bulk-recipients,
.bulk-composer {
  background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.bulk-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.bulk-section-head h2 {
  margin: 0; font-size: 15px; font-weight: 600; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
  letter-spacing: -0.01em;
}
.bulk-section-head h2 [data-lucide] { width: 18px; height: 18px; color: var(--text-tertiary); }

.bulk-recipients-controls {
  padding: 12px 16px; display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.bulk-search { width: 100%; }
.bulk-tag-filter {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 70px; overflow-y: auto;
}
.bulk-tag-pill {
  font-size: 11px; padding: 3px 10px; border-radius: 999px;
  background: var(--gray-100); color: var(--gray-700); border: 0;
  cursor: pointer; font-weight: 500;
}
.bulk-tag-pill.active { background: var(--wa); color: #fff; }
.bulk-count { font-size: 12px; color: var(--gray-500); margin-left: auto; }

.bulk-groups-list {
  flex: 1; overflow-y: auto; padding: 4px 4px 8px;
}
/* C1: bigger padding, real grid, cyan-tinted selected state */
.bulk-group-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  margin: 2px 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.bulk-group-row:hover { background: var(--gray-50); }
.bulk-group-row.hs-selected,
.bulk-group-row.selected { background: rgba(16,183,226,0.08); }
.bulk-group-row input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer; accent-color: #10b7e2;
  flex-shrink: 0;
}
.bulk-group-row .bulk-g-name {
  font-size: 14px; font-weight: 600; color: var(--gray-900);
  line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bulk-group-row .bulk-g-meta { font-size: 12px; color: var(--gray-500); }
.bulk-group-row .bulk-g-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.bulk-group-row .bulk-g-tag {
  font-size: 10.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  background: var(--gray-100); color: var(--gray-600);
}
.bulk-loading { padding: 24px; text-align: center; color: var(--gray-500); font-size: 13px; }

.bulk-composer-body {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
/* C6: composer textarea with subtle elevation + cyan focus */
.bulk-message-input {
  font-family: inherit; resize: vertical; min-height: 160px;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.55;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  background: #fafafa;
}
.bulk-message-input:focus {
  background: #fff;
  border-color: #10b7e2;
  box-shadow: 0 0 0 3px rgba(16,183,226,0.12);
  outline: none;
}
.bulk-attach-row {
  display: flex; align-items: center; gap: 10px;
}
/* C3: anti-ban panel — white card, calm header, auto-fit grid that fills width */
.bulk-antiban {
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: 10px; padding: 16px 18px;
}
.bulk-antiban h3 {
  margin: 0 0 12px;
  font-size: 13px; font-weight: 600; color: var(--gray-700);
  text-transform: none; letter-spacing: 0;
  display: inline-flex; align-items: center; gap: 6px;
}
.bulk-antiban h3::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #10b7e2;
}
.bulk-antiban-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.bulk-antiban-row label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--gray-600); font-weight: 500;
}
.bulk-antiban-row input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--gray-200); border-radius: 8px;
  font-size: 14px; background: #fff;
}
.bulk-antiban-row input:focus {
  border-color: #10b7e2;
  box-shadow: 0 0 0 3px rgba(16,183,226,0.15);
  outline: none;
}
.bulk-composer-foot {
  padding: 12px 16px; border-top: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}
.bulk-progress {
  padding: 12px 16px; border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.bulk-progress-bar {
  height: 8px; background: var(--gray-200); border-radius: 999px; overflow: hidden;
  margin-bottom: 6px;
}
.bulk-progress-fill {
  height: 100%; background: var(--wa); width: 0%;
  transition: width 0.3s;
}
.bulk-progress-label { font-size: 12px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.bulk-progress-log {
  font-size: 11px; color: var(--gray-500); max-height: 80px; overflow-y: auto;
  font-family: ui-monospace, Menlo, monospace;
}
.bulk-progress-log .row-fail { color: #dc2626; }
.bulk-progress-log .row-ok { color: #16a34a; }

.bulk-history-list .bulk-history-row {
  padding: 10px 0; border-bottom: 1px solid var(--gray-100);
  font-size: 13px; display: flex; gap: 10px; align-items: center;
}
.bulk-history-list .bulk-history-row:last-child { border-bottom: 0; }
.bulk-history-row .h-summary { flex: 1; color: var(--text-secondary); }
.bulk-history-row .h-success { color: var(--success); font-weight: 600; }
.bulk-history-row .h-failed { color: var(--danger); font-weight: 600; }
.bulk-history-row .h-time { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ─── User pill (topbar) ──────────────────────────────────────────────
   Operator identity card: avatar + stacked name/role + subtle logout
   tucked behind a hairline separator. Designed to read clearly even
   when the topbar gets dense; the soft surface-sunken pill bg gives
   it weight without competing with the action-bar tabs in the centre. */
.user-pill {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 3px 6px 3px 4px; border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  margin-right: 0;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.user-pill:hover { background: var(--surface-hover); border-color: var(--border); }

.user-pill-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0;
  box-shadow: 0 0 0 2px var(--surface);
  flex-shrink: 0;
}
.user-pill-info {
  display: flex; flex-direction: column;
  line-height: 1.15;
  padding: 0 2px;
  gap: 1px;
  min-width: 0;
  max-width: 140px;
}
.user-pill-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  letter-spacing: -0.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-transform: capitalize;
}
.user-pill-role {
  font-size: 9.5px; font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.12em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Admin / super-admin badge — cobalt, signals elevated privilege.
   The role text doubles as a small caps badge inside the pill so
   Ayoub immediately sees his rights at a glance. */
.user-pill-role.role-admin { color: var(--accent); }

/* Logout button — quiet by default, turns coral on hover so the
   destructive nature reads without dominating the resting state. */
.user-pill #logoutBtn {
  width: 28px; height: 28px;
  color: var(--text-muted);
  margin-left: 2px;
  position: relative;
  border-radius: 50%;
  transition: color var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease);
}
.user-pill #logoutBtn::before {
  content: ''; position: absolute; left: -6px; top: 50%;
  transform: translateY(-50%);
  height: 18px; width: 1px;
  background: var(--border);
}
.user-pill #logoutBtn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}
.user-pill #logoutBtn [data-lucide] { width: 15px; height: 15px; }

/* ─── Team view ─── */
.team-grid {
  flex: 1; display: grid;
  grid-template-columns: 1fr minmax(320px, 420px);
  gap: 16px; padding: 16px; overflow: hidden;
}
.team-users, .team-activity {
  background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.team-users-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.team-user-row {
  display: grid; grid-template-columns: 40px 1fr auto auto auto;
  align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border-subtle);
  transition: background 0.1s;
}
.team-user-row:hover { background: var(--surface-hover); }
.team-user-row:last-child { border-bottom: 0; }
/* Avatar — cobalt (consistent with the user-pill and profile avatars).
   Admin-role users keep cobalt; viewer/agent rely on the role pill for
   role signaling rather than colored avatars. */
.team-user-row .tu-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; text-transform: uppercase;
}
.team-user-row.role-admin .tu-avatar { background: var(--accent-strong); }
.team-user-row.inactive .tu-avatar { opacity: 0.4; filter: grayscale(1); }
.team-user-row.inactive .tu-name { text-decoration: line-through; color: var(--text-muted); }
.team-user-row .tu-name { font-size: 14px; font-weight: 600; color: var(--text); }
.team-user-row .tu-username { font-size: 12px; color: var(--text-tertiary); }
/* Role pills — semantic palette so dark mode pivots brightness. */
.team-user-row .tu-role-pill {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.team-user-row .tu-role-pill.role-admin  { background: var(--accent-soft);  color: var(--accent); }
.team-user-row .tu-role-pill.role-agent  { background: var(--info-soft);    color: var(--info); }
.team-user-row .tu-role-pill.role-viewer { background: var(--warning-soft); color: var(--warning); }
.team-user-row .tu-last-login { font-size: 11px; color: var(--text-muted); }
.team-user-row .tu-edit-btn {
  background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
  padding: 4px; border-radius: var(--radius-xs);
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.team-user-row .tu-edit-btn:hover { background: var(--surface-hover); color: var(--text); }

.team-activity-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.team-activity-row {
  display: grid; grid-template-columns: 28px 1fr auto;
  align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
}
.team-activity-row:last-child { border-bottom: 0; }
.team-activity-row .ta-icon {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-sunken); color: var(--text-tertiary);
  display: inline-flex; align-items: center; justify-content: center;
}
.team-activity-row .ta-icon [data-lucide] { width: 14px; height: 14px; }
.team-activity-row .ta-text { color: var(--text-secondary); }
.team-activity-row .ta-text strong { color: var(--text); font-weight: 600; }
.team-activity-row .ta-time { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.form-label input[type="checkbox"] { margin-right: 6px; vertical-align: middle; }

/* Hide elements based on role */
.role-agent [data-admin-only="true"] { display: none !important; }
/* Super-admin only gate — hides the WhatsApp Disconnect/Connect button
 * for everyone except the user(s) listed in SUPER_ADMIN_USERNAMES. */
body:not(.role-super-admin) [data-super-admin-only="true"] { display: none !important; }

/* ─── Assign-to dropdown ─── */
.assign-wrap { position: relative; display: inline-block; }
.assign-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  min-width: 260px; max-width: 320px;
  z-index: 100; overflow: hidden;
}
.assign-dropdown-head {
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  color: var(--gray-500); padding: 14px 16px 8px;
  border-bottom: 1px solid var(--gray-100);
}
.assign-dropdown-list { max-height: 320px; overflow-y: auto; padding: 4px 0; }
.assign-dropdown-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer;
  transition: background 0.1s;
  font-size: 14px;
}
.assign-dropdown-row:hover { background: var(--gray-50); }
.assign-dropdown-row.active { background: var(--wa-soft); }
.assign-dropdown-row .ad-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; text-transform: uppercase;
  flex-shrink: 0;
}
.assign-dropdown-row .ad-name { color: var(--gray-900); font-weight: 500; }
.assign-dropdown-row.unassigned { color: var(--gray-500); border-bottom: 1px solid var(--gray-100); }
.assign-dropdown-row.unassigned .ad-avatar {
  background: var(--gray-200); color: var(--gray-500);
}
.assign-dropdown-row .ad-check {
  margin-left: auto; color: var(--wa);
}

/* Assign button highlight when chat IS assigned */
#assignBtn.is-assigned { background: var(--wa-soft); color: var(--wa-dark); }
#assignBtn.is-assigned [data-lucide] { stroke: var(--wa-dark); }

/* Conversation list — small assignee indicator */
.conv-item .conv-assignee {
  position: absolute; bottom: 8px; right: 12px;
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 9px; font-weight: 700; text-transform: uppercase;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* Conversation list — assignee pill (full name visible). Inline at the
 * right end of row2 so the preview text truncates before reaching it
 * (was absolute-positioned and overlapping RTL Arabic previews). */
.conv-item .conv-assignee-pill {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1.5px 7px 1.5px 5px; border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  font-size: 9.5px; font-weight: 600; color: #4f46e5;
  max-width: 90px;
  letter-spacing: 0.15px;
}
.conv-item .conv-assignee-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.conv-item .conv-assignee-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-transform: capitalize;
}
.conv-item.active .conv-assignee-pill {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.35);
  color: #3730a3;
}

/* Tickets table — Assigned column. Reuse the conv-assignee-pill look. */
.tickets-cell.tickets-cell-assigned { display: flex; align-items: center; cursor: pointer; }
.tickets-cell.tickets-cell-assigned:hover { background: var(--surface-hover); }
.tickets-cell.tickets-cell-assigned .conv-assignee-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px 2px 6px; border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid transparent;
  font-size: 11px; font-weight: 600; color: var(--accent-strong);
  max-width: 140px;
}
[data-theme="dark"] .tickets-cell.tickets-cell-assigned .conv-assignee-pill { color: var(--accent); }
.tickets-cell.tickets-cell-assigned .conv-assignee-init {
  width: 16px; height: 16px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--accent-fg); background: var(--accent); flex-shrink: 0;
}
.tickets-cell.tickets-cell-assigned .conv-assignee-name {
  text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ticket-assignee-unmapped {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--gray-700);
}
.ticket-assignee-unmapped-name { font-weight: 500; }
.ticket-assignee-unmapped-tag {
  font-size: 9.5px; padding: 1px 6px; border-radius: 4px;
  background: var(--gray-100); color: var(--gray-500);
  text-transform: uppercase; letter-spacing: 0.3px;
}

/* Super Admin profile card — top of the Team / Super Admin view.
   Editorial card: cobalt accent backdrop, large Fraunces name, role
   badge. This is Ayoub's own card; the visual weight makes the role
   feel intentional rather than buried in a settings page. */
.superadmin-profile { padding: 0 24px; margin-bottom: 16px; }
.superadmin-profile-card {
  display: flex; align-items: center; gap: 18px;
  padding: 22px 24px;
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.superadmin-avatar {
  width: 64px; height: 64px; font-size: 22px; font-weight: 600;
  color: var(--accent-fg);
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  flex-shrink: 0;
}
.superadmin-profile-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.superadmin-profile-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.superadmin-name {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 500;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 144;
  color: var(--text); margin: 0;
}
.superadmin-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--accent-fg);
}
.superadmin-badge svg { width: 12px; height: 12px; }
.superadmin-profile-meta {
  display: flex; flex-wrap: wrap; gap: 16px;
  font-size: 12.5px; color: var(--text-secondary); margin-top: 4px;
}
.superadmin-meta-row { display: inline-flex; align-items: center; gap: 5px; }
.superadmin-meta-row svg { width: 13px; height: 13px; opacity: 0.7; }
.superadmin-system-tools { flex-shrink: 0; display: flex; gap: 8px; }
.superadmin-system-tools .btn { font-size: 12px; }

/* Super Admin — Platform mappings section */
.superadmin-mappings { padding: 0 24px; margin-bottom: 18px; }
.superadmin-mappings .bulk-section-head { margin-bottom: 10px; gap: 12px; align-items: baseline; }
.superadmin-mapping-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px;
}
.superadmin-mapping-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.superadmin-mapping-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.superadmin-mapping-card-future { opacity: 0.6; }
.superadmin-mapping-card .smc-head { display: flex; align-items: center; gap: 10px; }
.superadmin-mapping-card .smc-logo {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.superadmin-mapping-card .smc-meta { flex: 1; min-width: 0; }
.superadmin-mapping-card .smc-name { font-size: 14px; font-weight: 600; color: var(--text); }
.superadmin-mapping-card .smc-sub { font-size: 11.5px; color: var(--text-tertiary); margin-top: 1px; }
.superadmin-mapping-card .smc-count {
  font-size: 11px; padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); color: var(--text-tertiary); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Assigned filter dropdown — pill list. Each row pairs a checkbox with
   a coloured pill (initial-avatar + name) so the dropdown visually
   mirrors the Assigned-column cells. Special filters (me / unmapped /
   no owner) get distinct colours so they pop above the team members. */
.tickets-assignee-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 8px;
  cursor: pointer; transition: background 80ms ease;
}
.tickets-assignee-row:hover { background: var(--gray-50); }
.tickets-assignee-row.checked { background: rgba(59, 130, 246, 0.06); }
.tickets-assignee-row input[type="checkbox"] {
  width: 14px; height: 14px; cursor: pointer; accent-color: #3b82f6;
  flex-shrink: 0;
}
.tickets-assignee-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px 3px 4px; border-radius: 999px;
  background: rgba(99, 102, 241, 0.10);
  border: 1px solid rgba(99, 102, 241, 0.18);
  font-size: 13px; font-weight: 600; color: #4f46e5;
  max-width: 100%;
}
.tickets-assignee-pill .tap-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
  background: #6366f1; flex-shrink: 0;
}
.tickets-assignee-pill .tap-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Special-filter pill colours — me / unmapped / no-owner each stand
   out so the team list below feels grouped. */
.tickets-assignee-pill.pill-me {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.30);
  color: #047857;
}
.tickets-assignee-pill.pill-me .tap-avatar { background: #10b981; }
.tickets-assignee-pill.pill-warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.30);
  color: #b45309;
}
.tickets-assignee-pill.pill-warn .tap-avatar { background: #f59e0b; }
.tickets-assignee-pill.pill-muted {
  background: var(--gray-100);
  border-color: var(--gray-200);
  color: var(--gray-600);
}
.tickets-assignee-pill.pill-muted .tap-avatar { background: var(--gray-400); }
/* Team-member pill — purple tint matching the Assigned-column cell. */
.tickets-assignee-pill.pill-user { /* defaults above already apply */ }
.tickets-assignee-role {
  margin-left: auto; font-size: 10.5px; font-weight: 600;
  color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.4px;
}

/* Team ↔ HubSpot owner mapping modal */
.team-owner-map-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.team-owner-map-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--gray-200); border-radius: 8px; background: #fff;
}
.team-owner-map-row .tomr-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.team-owner-map-row .tomr-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: white; background: #6366f1;
  flex-shrink: 0;
}
.team-owner-map-row .tomr-user-info { min-width: 0; }
.team-owner-map-row .tomr-name { font-weight: 600; font-size: 13px; color: var(--gray-900); }
.team-owner-map-row .tomr-role { font-size: 11px; color: var(--gray-500); margin-top: 1px; }
.team-owner-map-row .tomr-select { flex: 0 0 240px; font-size: 12px; }

/* Avatar color palette by name (deterministic) */
.av-c1 { background: #16a34a; }   /* green */
.av-c2 { background: #ec4899; }   /* pink */
.av-c3 { background: #06b6d4; }   /* teal */
.av-c4 { background: #22c55e; }   /* emerald */
.av-c5 { background: #3b82f6; }   /* blue */
.av-c6 { background: #a855f7; }   /* purple */
.av-c7 { background: #f59e0b; }   /* amber */
.av-c8 { background: #ef4444; }   /* red */

/* ─── Conversation Details panel (Notes + Activity + Take over) ─── */
.main.with-conv-details { grid-template-columns: var(--sidebar-w) minmax(0,1fr) 340px; }
.main.with-conv-details #convDetailsPanel { display: flex; }
.main.with-conv-details:not(.with-profile) #profilePanel { display: none; }
.main.sidebar-collapsed.with-conv-details { grid-template-columns: 0 minmax(0,1fr) 340px; }
.main:not(.with-conv-details) #convDetailsPanel { display: none; }

.conv-details-panel { flex-direction: column; }
.conv-details-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--gray-200);
}

.conv-details-tabs {
  display: flex; border-bottom: 1px solid var(--gray-200);
  background: #fff;
}
.conv-details-tab {
  flex: 1; padding: 14px 8px;
  background: transparent; border: 0; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--gray-500);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  position: relative;
}
.conv-details-tab [data-lucide] { width: 16px; height: 16px; }
.conv-details-tab.active { color: #d97706; }
.conv-details-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 16px; right: 16px; height: 2px;
  background: #d97706;
}
.conv-tab-count {
  background: #fed7aa; color: #c2410c;
  font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  min-width: 18px; text-align: center;
}

.conv-details-pane { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

.conv-notes-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: #fffbeb; color: #b45309;
  font-size: 13px; border-bottom: 1px solid #fef3c7;
}
.conv-notes-banner [data-lucide] { width: 14px; height: 14px; flex-shrink: 0; }

.conv-notes-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.conv-note-card {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px;
  padding: 10px 12px; position: relative;
}
.conv-note-card-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.conv-note-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 700; text-transform: uppercase; flex-shrink: 0;
}
.conv-note-author { font-weight: 600; font-size: 13px; color: var(--gray-800); flex: 1; }
.conv-note-time { font-size: 11px; color: var(--gray-500); }
.conv-note-content {
  font-size: 14px; color: var(--gray-900); white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: anywhere;
}
.conv-note-delete {
  position: absolute; top: 6px; right: 6px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--gray-400); padding: 4px; border-radius: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.conv-note-card:hover .conv-note-delete { opacity: 1; }
.conv-note-delete:hover { background: rgba(0,0,0,0.05); color: #dc2626; }
.conv-note-delete [data-lucide] { width: 14px; height: 14px; }

.conv-notes-compose {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px; border-top: 1px solid var(--gray-200); background: #fff;
}
.conv-notes-compose .input { flex: 1; border-radius: 999px; border-color: #fde68a; padding: 8px 16px; }
.conv-notes-compose .input:focus { border-color: #f59e0b; box-shadow: 0 0 0 3px rgba(251,191,36,0.2); }
.conv-note-send {
  background: #fcd34d; color: #92400e; border: 0; border-radius: 50%;
  width: 36px; height: 36px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.conv-note-send:hover { background: #fbbf24; }
.conv-note-send [data-lucide] { width: 16px; height: 16px; }

.conv-activity-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.conv-activity-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--gray-100);
}
.conv-activity-row:last-child { border-bottom: 0; }
.conv-activity-row .ca-icon {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--gray-100); color: var(--gray-500);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.conv-activity-row .ca-icon [data-lucide] { width: 14px; height: 14px; }
.conv-activity-row .ca-body { flex: 1; min-width: 0; }
.conv-activity-row .ca-text { font-size: 13px; color: var(--gray-800); }
.conv-activity-row .ca-text strong { font-weight: 600; color: var(--gray-900); }
.conv-activity-row .ca-time { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* notesBtn = lock icon shows orange when notes exist */
#notesBtn.has-notes { color: #d97706; }
#notesBtn.has-notes [data-lucide] { stroke: #d97706; }

/* ─── Contact Profile v2 ─── */
.profile-head-v2 {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 14px 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  position: relative;
}
.profile-head-top {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2px;
}
.profile-head-title {
  margin: 0; font-size: 11px; font-weight: 600; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.08em;
}
/* Big avatar — now cobalt to anchor the page with the design accent
   (was orange). The colour will look uniform across both themes via
   --accent's brightness pivot. */
.profile-avatar-big {
  width: 48px; height: 48px; border-radius: 50%;
  font-size: 18px; font-weight: 600; color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
  text-transform: uppercase;
  margin-top: 0;
  box-shadow: 0 0 0 3px var(--surface-sunken);
}
/* Contact / group name — the editorial moment of the profile page.
   Fraunces gives it the editorial weight; -0.015em tracking + opsz 144
   tune it for display size. Replaces the old Geist 15px weight 700. */
.profile-name-big {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 20px; font-weight: 500;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 144;
  color: var(--text);
  text-align: center; word-break: break-word;
}
.profile-phone-big {
  margin: 0; font-size: 12px; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* Name + edit-pencil row in the Contact Profile header. Pencil is
   tucked next to the name and only flips to visible on hover so the
   layout reads as a static label until the agent reaches for it. */
.profile-name-row {
  display: inline-flex; align-items: center; gap: 4px;
  justify-content: center;
}
.profile-name-edit-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: transparent; border: 1px solid transparent;
  border-radius: 50%; color: var(--gray-400, #9ca3af);
  cursor: pointer; padding: 0;
  opacity: 0; transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.profile-name-edit-btn [data-lucide] { width: 12px; height: 12px; }
.profile-head:hover .profile-name-edit-btn,
.profile-name-row:hover .profile-name-edit-btn,
.profile-name-edit-btn:focus-visible { opacity: 1; }
.profile-name-edit-btn:hover { background: var(--surface-hover); color: var(--accent); border-color: var(--border); }

.profile-name-edit-form {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 2px 0 0; justify-content: center;
}
.profile-name-edit-input {
  font: inherit; font-family: var(--font-display); font-size: 18px; font-weight: 500;
  letter-spacing: -0.015em;
  padding: 3px 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  min-width: 0; max-width: 220px;
  outline: none;
}
.profile-name-edit-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.profile-name-edit-form .btn { padding: 3px 10px; font-size: 12px; }
/* Group the two action pills (Link to HubSpot + Lougha AI) on a single
   row so the header keeps a tight vertical footprint. */
.profile-head-pills {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  margin-top: 4px;
}
.profile-head-pills .profile-link-pill,
.profile-head-pills .profile-ai-pill { margin-top: 0; }
.profile-link-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 999px;
  background: rgba(99, 102, 241, 0.08); color: #4f46e5;
  border: 0; cursor: pointer;
  font-size: 12px; font-weight: 600;
  margin-top: 4px;
  transition: background 0.15s;
}
.profile-link-pill:hover { background: rgba(99, 102, 241, 0.15); }
.profile-link-pill [data-lucide] { width: 14px; height: 14px; }

/* ─── AI Card v2 (Lougha AI) ─── */
.ai-card-v2 {
  margin: 12px; padding: 14px 14px 12px;
  border: 1px solid #fbcfe8; border-radius: 12px;
  background: #fff;
  position: relative;
}

/* When used as a popup overlay (hidden by default, opened via the
   profile-header trigger). Floats above the accordion list, with shadow. */
.ai-popup {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  z-index: 30;
  margin: 0;
  box-shadow: 0 10px 32px rgba(168, 85, 247, 0.18), 0 2px 8px rgba(0,0,0,0.06);
}

/* Trigger pill in profile header — mirrors .profile-link-pill styling but
   wears the AI gradient so it reads as the gateway to the summary popup. */
.profile-ai-pill {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 4px; padding: 5px 12px;
  border: 0; border-radius: 999px;
  background: linear-gradient(90deg, #ec4899 0%, #a855f7 100%);
  color: #fff; font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.profile-ai-pill:hover { box-shadow: 0 4px 12px rgba(168, 85, 247, 0.3); transform: translateY(-1px); }
.profile-ai-pill [data-lucide] { width: 14px; height: 14px; stroke: #fff; }
.ai-card-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.ai-card-meta { flex: 1; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.ai-gen-label { font-size: 11px; color: var(--gray-500); }
.ai-gen-time { font-size: 11px; color: var(--gray-700); font-weight: 500; }
.ai-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  background: linear-gradient(90deg, #ec4899 0%, #a855f7 100%);
  color: #fff; font-size: 11px; font-weight: 600;
}
.ai-pill [data-lucide] { width: 12px; height: 12px; stroke: #fff; }
.ai-refresh-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--gray-400); padding: 4px; border-radius: 4px;
  display: inline-flex; align-items: center;
}
.ai-refresh-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.ai-refresh-btn [data-lucide] { width: 14px; height: 14px; }
.ai-refresh-btn.spin [data-lucide] { animation: spin 0.8s linear infinite; }
/* @keyframes spin already defined earlier in the file */

.ai-body-v2 {
  font-size: 13px; line-height: 1.6; color: var(--gray-900);
  white-space: pre-wrap; word-wrap: break-word;
  min-height: 28px;
}
.ai-actions-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid #fce7f3;
}
.ai-action-btn {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--gray-200); background: #fff;
  cursor: pointer; color: var(--gray-500);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.ai-action-btn:hover { background: var(--gray-50); color: var(--gray-700); }
.ai-action-btn.up-active { background: #dcfce7; color: #16a34a; border-color: #bbf7d0; }
.ai-action-btn.down-active { background: #fee2e2; color: #dc2626; border-color: #fecaca; }
.ai-action-btn [data-lucide] { width: 14px; height: 14px; }
.ai-ask-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 8px;
  background: rgba(236, 72, 153, 0.08); color: #db2777;
  border: 1px solid rgba(236, 72, 153, 0.2);
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.ai-ask-btn:hover { background: rgba(236, 72, 153, 0.15); }
.ai-ask-btn [data-lucide] { width: 14px; height: 14px; }

/* Section accordions: count badges + add property */
.profile-card .card-title-count {
  font-size: 12px; font-weight: 500; color: var(--gray-500);
  margin-left: 4px;
}
.profile-card-head .card-add-prop {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(99, 102, 241, 0.08); color: #4f46e5;
  border: 0; cursor: pointer;
  padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
  margin-right: 6px;
}
.profile-card-head .card-add-prop:hover { background: rgba(99, 102, 241, 0.15); }
.profile-card-head .card-add-prop [data-lucide] { width: 11px; height: 11px; }

/* Ask AI answer area inside modal */
.ask-ai-answer {
  margin-top: 14px; padding: 12px 14px;
  background: #fdf4ff; border: 1px solid #f3e8ff;
  border-radius: 8px; color: var(--gray-800);
  font-size: 13px; line-height: 1.6; white-space: pre-wrap;
}

/* ─── Custom properties ─── */
.custom-prop-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 6px; align-items: start;
  padding: 8px 10px; border-radius: 6px;
  margin-top: 4px; background: rgba(99, 102, 241, 0.04);
  position: relative;
}
.custom-prop-row:hover { background: rgba(99, 102, 241, 0.08); }
.custom-prop-row .cp-content { min-width: 0; }
.custom-prop-row .cp-key {
  font-size: 11px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: 0.4px;
  display: flex; align-items: center; gap: 6px;
}
.custom-prop-row .cp-key-edit {
  border: 0; background: transparent; padding: 0;
  font-size: 11px; font-weight: 600; color: var(--gray-700);
  text-transform: uppercase; letter-spacing: 0.4px;
  width: 100%;
}
.custom-prop-row .cp-key-edit:focus { outline: 2px solid #4f46e5; outline-offset: 2px; border-radius: 3px; }
.custom-prop-row .cp-value {
  font-size: 13px; color: var(--gray-900); white-space: pre-wrap;
  word-wrap: break-word; cursor: text;
  padding: 2px 0;
}
.custom-prop-row .cp-value-edit {
  width: 100%; border: 1px solid var(--gray-300); border-radius: 4px;
  padding: 4px 8px; font: inherit; font-size: 13px;
}
.custom-prop-row .cp-author {
  font-size: 10px; color: var(--gray-400); margin-top: 4px; font-style: italic;
}
.custom-prop-row .cp-edit-btn,
.custom-prop-row .cp-del-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--gray-400); padding: 4px; border-radius: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.custom-prop-row:hover .cp-edit-btn,
.custom-prop-row:hover .cp-del-btn { opacity: 1; }
.custom-prop-row .cp-edit-btn:hover { background: rgba(99,102,241,0.15); color: #4f46e5; }
.custom-prop-row .cp-del-btn:hover { background: rgba(220,38,38,0.1); color: #dc2626; }
.custom-prop-row .cp-edit-btn [data-lucide],
.custom-prop-row .cp-del-btn [data-lucide] { width: 13px; height: 13px; }
.custom-props-divider {
  height: 1px; background: linear-gradient(90deg, transparent, var(--gray-200), transparent);
  margin: 10px 0 6px;
}
.custom-props-label {
  font-size: 10px; font-weight: 700; color: #4f46e5;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 8px 0 4px; display: flex; align-items: center; gap: 4px;
}
.custom-props-label [data-lucide] { width: 12px; height: 12px; }

/* ─── Add Property modal — quick suggestion chips ─── */
.add-prop-templates {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 10px; background: var(--gray-50);
  border-radius: 6px; min-height: 32px;
}
.add-prop-templates:empty::after {
  content: 'No templates yet — type a name below.';
  font-size: 12px; color: var(--gray-400);
}
.add-prop-tpl {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(99, 102, 241, 0.1); color: #4f46e5;
  border: 1px solid transparent; cursor: pointer;
  font-size: 12px; font-weight: 500;
  transition: background .12s, border-color .12s, transform .08s;
}
.add-prop-tpl:hover { background: rgba(99, 102, 241, 0.2); }
.add-prop-tpl.selected {
  background: rgba(34, 197, 94, 0.14); color: #15803d;
  border-color: rgba(34, 197, 94, 0.45);
}
.add-prop-tpl.selected:hover { background: rgba(34, 197, 94, 0.22); }
.add-prop-tpl.empty-prop {
  background: rgba(148, 163, 184, 0.10); color: var(--gray-500);
}
.add-prop-tpl.empty-prop:hover { background: rgba(148, 163, 184, 0.20); }
.add-prop-tpl.empty-prop.selected {
  background: rgba(34, 197, 94, 0.14); color: #15803d;
}

/* HubSpot contact picker (duplicate-phone resolution) */
.contact-picker-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.contact-picker-row {
  display: flex; flex-direction: column; gap: 8px;
  border: 1px solid var(--gray-200); border-radius: 8px; padding: 10px 12px;
  background: #fff; cursor: pointer; transition: background 120ms, border-color 120ms;
}
.contact-picker-row:hover { background: var(--gray-50); border-color: var(--blue-300); }
.contact-picker-row.active { border-color: var(--blue-500); background: rgba(59, 130, 246, 0.06); }
.contact-picker-row .cpr-head { display: flex; align-items: center; gap: 8px; }
.contact-picker-row .cpr-name { flex: 1; font-weight: 600; font-size: 14px; color: var(--gray-900); }
.contact-picker-row .cpr-active-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--blue-500); color: #fff;
}
.contact-picker-row .cpr-score {
  font-size: 11px; padding: 2px 6px; border-radius: 6px;
  background: var(--gray-100); color: var(--gray-600);
}
.contact-picker-row .cpr-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }
.contact-picker-row .cpr-field { display: flex; justify-content: space-between; font-size: 12px; min-width: 0; }
.contact-picker-row .cpr-key { color: var(--gray-500); }
.contact-picker-row .cpr-val { color: var(--gray-900); font-weight: 500; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-prop-templates {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 220px; overflow-y: auto;
  padding: 8px; background: var(--gray-50);
  border-radius: 10px; border: 1px solid var(--gray-200);
}

/* Pinned-field row inside Student Info — same look as default rows + tiny remove button on hover */
.pinned-field-row { position: relative; padding-right: 24px; padding-left: 18px; }
.pinned-field-remove {
  position: absolute; top: 50%; right: 0; transform: translateY(-50%);
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 50%;
  color: var(--gray-400); cursor: pointer;
  opacity: 0; transition: opacity .12s, background .12s, color .12s;
}
.pinned-field-row:hover .pinned-field-remove { opacity: 1; }
.pinned-field-remove:hover { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.pinned-field-remove svg { width: 12px; height: 12px; }

/* Create Ticket modal */
.ct-section-title {
  font-size: 12px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: 0.4px;
  margin: 0 0 10px;
}
.ct-essential, .ct-advanced {
  display: flex; flex-direction: column; gap: 12px;
}
.ct-advanced-list {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 320px; overflow-y: auto;
  padding: 8px; border: 1px solid var(--gray-200); border-radius: 8px;
  background: var(--gray-50);
}
.ct-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 12px 0;
  font-size: 12px;
}
.ct-toggle svg { width: 14px; height: 14px; }
.ct-field { display: flex; flex-direction: column; gap: 4px; }
.ct-label {
  font-size: 12px; font-weight: 600; color: var(--gray-700);
}
.ct-input { width: 100%; }
.ct-field-missing { opacity: 0.85; }
.ct-field-missing .ct-label { color: var(--gray-500); }
.ct-missing-note {
  font-size: 11.5px; color: #b45309;
  background: rgba(245, 158, 11, 0.08);
  border: 1px dashed rgba(245, 158, 11, 0.35);
  border-radius: 6px; padding: 6px 8px;
}
.card-create-ticket {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(34, 197, 94, 0.10); color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-size: 11px; font-weight: 600; cursor: pointer;
}
.card-create-ticket:hover { background: rgba(34, 197, 94, 0.20); }
.card-create-ticket svg { width: 12px; height: 12px; }
.card-create-ticket span { display: inline-block; }

/* Ticket cards inside Tickets section */
.ticket-card {
  border: 1px solid var(--gray-200); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--gray-50);
}
.ticket-card-title {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}
.ticket-card-subject {
  font-weight: 600; font-size: 13px; color: var(--gray-800);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ticket-card-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px;
  color: var(--gray-400); text-decoration: none;
}
.ticket-card-link:hover { color: var(--blue-500); background: var(--gray-100); }
.ticket-card-link svg { width: 13px; height: 13px; }
.ticket-card-fields { display: flex; flex-direction: column; gap: 0; }
.ticket-card-fields .field-row { padding: 4px 0; border-bottom: 1px dashed var(--gray-200); }
.ticket-card-fields .field-row:last-child { border-bottom: 0; }

/* Drag handle for reorder — discoverable at rest, brighter on hover */
.pinned-field-drag {
  position: absolute; top: 50%; left: 0; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px;
  color: var(--gray-300); cursor: grab;
  opacity: 0.6; transition: opacity .12s, color .12s;
}
.pinned-field-row:hover .pinned-field-drag { opacity: 1; }
.pinned-field-drag:hover { color: var(--gray-600); }
.pinned-field-drag:active { cursor: grabbing; }
.pinned-field-drag svg { width: 12px; height: 12px; }
.pinned-field-row.dragging { opacity: 0.4; }
.pinned-field-row.drop-above { box-shadow: inset 0 2px 0 0 #6366f1; }
.pinned-field-row.drop-below { box-shadow: inset 0 -2px 0 0 #6366f1; }

/* ─── Note search results ─── */
.note-search-results {
  margin-top: 12px; max-height: 400px; overflow-y: auto;
}
.note-search-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; cursor: pointer; border-radius: 8px;
  border: 1px solid transparent;
  margin-bottom: 6px;
}
.note-search-row:hover { background: var(--gray-50); border-color: var(--gray-200); }
.note-search-row .nsr-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 12px; color: var(--gray-500);
}
.note-search-row .nsr-chat {
  font-weight: 700; color: var(--gray-800);
}
.note-search-row .nsr-content {
  font-size: 13px; color: var(--gray-900); line-height: 1.5;
  white-space: pre-wrap;
}
.note-search-row .nsr-content mark {
  background: #fef3c7; padding: 0 2px; border-radius: 2px;
}

/* Section drag handle */
.profile-card-head .card-drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; cursor: grab;
  color: var(--gray-300); margin-right: 4px;
  user-select: none;
}
.profile-card-head .card-drag-handle:hover { color: var(--gray-500); }
.profile-card-head .card-drag-handle [data-lucide] { width: 14px; height: 14px; }
.profile-card.dragging { opacity: 0.5; }
.profile-card.drop-target {
  border-top: 2px solid #4f46e5;
}

/* HubSpot import button */
.profile-card-head .card-hs-import {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255, 122, 89, 0.1); color: #ea580c;
  border: 0; cursor: pointer;
  padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
  margin-right: 6px;
}
.profile-card-head .card-hs-import:hover { background: rgba(255, 122, 89, 0.2); }
.profile-card-head .card-hs-import [data-lucide] { width: 11px; height: 11px; }

/* HubSpot-imported prop has subtle orange tag */
.custom-prop-row[data-source="hubspot"] {
  background: rgba(255, 122, 89, 0.05);
  border-left: 2px solid #ea580c;
}
.custom-prop-row[data-source="hubspot"] .cp-key::after {
  content: 'HUBSPOT';
  font-size: 9px; padding: 1px 6px; border-radius: 999px;
  background: #fed7aa; color: #c2410c;
  margin-left: 6px;
}

/* ─── Documents v2 (7-type picker + dynamic form) ─── */
.doc-picker-body { padding: 0 0 12px; }
.doc-contact-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #fff;
}
.doc-contact-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.15); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; text-transform: uppercase;
}
.doc-contact-name { font-size: 15px; font-weight: 700; }
.doc-contact-phone { font-size: 12px; color: rgba(255,255,255,0.7); }

.doc-picker-intro {
  margin: 16px 20px 12px; font-size: 13px; color: var(--gray-600);
}
.doc-picker-list {
  display: flex; flex-direction: column; gap: 8px;
  padding: 0 20px 20px;
}
.doc-picker-card {
  display: grid; grid-template-columns: 44px 1fr 18px;
  align-items: center; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--gray-200); border-radius: 10px;
  cursor: pointer; background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.doc-picker-card:hover {
  border-color: #f59e0b; background: #fffbeb;
  box-shadow: 0 1px 4px rgba(245,158,11,0.15);
}
.doc-picker-card .dpc-icon {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--gray-100); display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 20px;
}
.doc-picker-card .dpc-label { font-size: 14px; font-weight: 700; color: var(--gray-900); margin-bottom: 2px; }
.doc-picker-card .dpc-desc { font-size: 12px; color: var(--gray-500); line-height: 1.4; }
.doc-picker-card .dpc-arrow { color: var(--gray-300); }
.doc-picker-card:hover .dpc-arrow { color: #f59e0b; }
.doc-picker-card.accent-orange:hover { border-color: #f97316; }
.doc-picker-card.accent-cyan:hover { border-color: #06b6d4; background: #ecfeff; box-shadow: 0 1px 4px rgba(6,182,212,0.15); }
.doc-picker-card.accent-emerald:hover { border-color: #10b981; background: #ecfdf5; }
.doc-picker-card.accent-indigo:hover { border-color: #6366f1; background: #eef2ff; }
.doc-picker-card.accent-amber:hover { border-color: #f59e0b; }
.doc-picker-card.accent-sky:hover { border-color: #0ea5e9; background: #f0f9ff; }
.doc-picker-card.accent-violet:hover { border-color: #8b5cf6; background: #f5f3ff; }

/* ─── Document form (dynamically populated from registry) ─── */
.doc-form-body { padding: 16px 20px; }
.doc-form-fields { display: flex; flex-direction: column; gap: 14px; }
.doc-field {
  display: flex; flex-direction: column; gap: 4px;
}
.doc-field-label {
  font-size: 12px; font-weight: 600; color: var(--gray-700);
  display: inline-flex; align-items: center; gap: 6px;
}
.doc-field-label .doc-required { color: #dc2626; }
.doc-field-help { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.doc-field-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

.doc-items-list { display: flex; flex-direction: column; gap: 6px; }
.doc-item-row {
  display: grid; grid-template-columns: 1fr 80px 110px 30px;
  gap: 6px; align-items: center;
}
/* Receipt-specific row layout — 4 inputs (Période / Description / Mois / Montant)
   instead of the invoice's 3, plus the delete button. */
.doc-item-row.doc-receipt-row {
  grid-template-columns: 1fr 110px 70px 100px 100px 30px;
}
.doc-receipt-header {
  font-size: 11px; font-weight: 700;
  color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0 4px;
}
.doc-receipt-header > span { padding-left: 4px; }
.doc-item-row .input { padding: 8px 10px; font-size: 13px; }
.doc-item-row .doc-item-del {
  background: transparent; border: 0; cursor: pointer;
  color: var(--gray-400); padding: 4px;
  display: inline-flex; align-items: center; justify-content: center;
}
.doc-item-row .doc-item-del:hover { color: #dc2626; }
.doc-add-item {
  align-self: flex-start; padding: 6px 12px;
  background: rgba(99, 102, 241, 0.08); color: #4f46e5; border: 0;
  border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px;
}
.doc-add-item:hover { background: rgba(99, 102, 241, 0.15); }
.doc-add-item [data-lucide] { width: 12px; height: 12px; }

.doc-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.doc-toggle input[type="checkbox"] { width: 16px; height: 16px; }

.doc-months-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
}
.doc-month-pill {
  padding: 6px 4px; border: 1px solid var(--gray-200); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: 11px; font-weight: 600;
  text-align: center; user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.doc-month-pill.paid {
  background: #fef3c7; border-color: #f59e0b; color: #92400e;
}

/* ─── Document preview ─── */
.doc-preview-body { padding: 0; display: flex; flex-direction: column; }
.doc-preview-name {
  padding: 10px 20px; font-size: 12px; color: var(--gray-600);
  background: var(--gray-50); border-bottom: 1px solid var(--gray-200);
}
.doc-preview-frame {
  width: 100%; height: 60vh; border: 0; background: #fff;
}

/* ─── Documents — validation + footer hint ─── */
.doc-form-errors {
  margin: 0 0 14px; padding: 12px 14px;
  background: #fee2e2; border: 1px solid #fca5a5; border-radius: 8px;
  color: #991b1b; font-size: 13px;
}
.doc-form-errors strong { display: block; margin-bottom: 4px; }
.doc-form-errors ul { margin: 0; padding-left: 20px; }
.doc-form-errors li { line-height: 1.5; }
.doc-foot-hint {
  flex: 1; font-size: 12px; color: var(--gray-500); font-style: italic;
}
.doc-field.has-error .input,
.doc-field.has-error textarea,
.doc-field.has-error select { border-color: #dc2626; }
.doc-field.has-error .doc-field-label { color: #dc2626; }

/* ─── HubSpot Group Send (C2 — members fill column, larger type, clear no-phone state) ─── */
.hs-members-list {
  flex: 1 1 auto;
  min-height: 200px;
  max-height: none;
  border: 1px solid var(--gray-200); border-radius: 10px;
  background: #fff;
  padding: 4px;
  overflow-y: auto;
}
.hs-member-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 0;
}
.hs-member-row + .hs-member-row { border-top: 1px solid var(--gray-100); }
.hs-member-row:hover { background: var(--gray-50); }
.hs-member-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.hs-member-phone { font-size: 12px; color: var(--gray-500); font-variant-numeric: tabular-nums; }
.hs-member-row.no-phone { background: #fef2f2; }
.hs-member-row.no-phone .hs-member-phone {
  color: #b91c1c; font-style: normal; font-weight: 500;
}
.hs-member-row.no-phone::after {
  content: '⚠'; color: #b91c1c; margin-left: 6px;
}

/* ============================================================================
   AUDIT FIXES (applied 2026-05-03 — see senior frontend audit transcript)
   These rules sit at the END of the file so they cleanly override earlier
   declarations without me having to chase every original site.
   ============================================================ */

/* P6: thinner ambient icons, thicker on action buttons */
[data-lucide] { stroke-width: 1.75; }
.btn-primary [data-lucide],
.icon-btn-primary [data-lucide],
.view-tab.view-tab-active [data-lucide] { stroke-width: 2; }

/* M1: unified focus ring across interactive elements */
.btn:focus-visible,
.icon-btn:focus-visible,
.tab:focus-visible,
.view-tab:focus-visible,
.conv-item:focus-visible,
.conv-details-tab:focus-visible {
  outline: 2px solid #10b7e2; outline-offset: 2px;
}

/* H2 brand-tone color map — green only for Send + outgoing bubbles + pulse.
   Cyan elsewhere for navigation / state / focus. Override earlier per-spot rules. */
.profile-link-pill { background: rgba(16,183,226,0.08); color: #0e7490; }
.profile-link-pill:hover { background: rgba(16,183,226,0.16); }
.custom-prop-row { background: rgba(16,183,226,0.04); }
.custom-prop-row:hover { background: rgba(16,183,226,0.08); }
.custom-props-label { color: #0e7490; }
#convTakeOverBtn { color: #0e7490 !important; }

/* H3: notes amber stays (sticky-note metaphor); other tabs go neutral with cyan underline */
.conv-details-tab.active { color: var(--gray-900); }
.conv-details-tab.active::after { background: #10b7e2; }
.conv-details-tab[data-conv-tab="notes"].active { color: #b45309; }
.conv-details-tab[data-conv-tab="notes"].active::after { background: #f59e0b; }
.conv-tab-count { background: var(--gray-100); color: var(--gray-600); }
.conv-details-tab[data-conv-tab="notes"].active .conv-tab-count {
  background: #fed7aa; color: #c2410c;
}

/* M3: tone down uppercase letter-spaced micro-pills */
.bot-pill,
.team-user-row .tu-role-pill {
  text-transform: none; letter-spacing: 0; font-weight: 600;
}

/* H1: Send button is the primary action — bump it */
#bulkSendBtn,
#hsSendBtn,
#docFormPreviewBtn,
#docPreviewSendBtn,
#docFormSendBtn,
#bulkSendBtn[disabled],
#hsSendBtn[disabled] {
  height: 42px; padding: 0 18px; font-size: 14px; font-weight: 600;
}

/* H5: bulk-count as a real pill instead of bare text */
.bulk-count {
  font-size: 12px; font-weight: 600; color: var(--gray-700);
  padding: 4px 10px; border-radius: 999px;
  background: var(--gray-100);
}

/* C6 reinforcement: composer textarea base style for plain .input textareas
   inside bulk/hubspot composers */
.bulk-composer-body .input { font-size: 14px; }

/* Cancel button visibility when shown */
.bulk-composer-foot .btn-ghost,
#hsCancelBtn { color: #b91c1c; }
.bulk-composer-foot .btn-ghost:hover,
#hsCancelBtn:hover { background: #fee2e2; color: #991b1b; }

/* P3: avatar-md inconsistency fix (was 13px, smaller than base 14px) */
.avatar-md { font-size: 14px; }

/* P9: drag handle visible by default */
.profile-card-head .card-drag-handle { color: var(--gray-400); }
.profile-card-head .card-drag-handle:hover { color: var(--gray-700); }

/* P1 override (legacy): solid background on messages area — now themed
   to follow --bg so it flips between light cream and dark charcoal. */
.messages-area {
  background: var(--bg) !important;
}

/* M4: field keys with more presence */
.field-key { font-size: 12.5px; font-weight: 500; color: var(--gray-600); }

/* Inbox conv-item: drop the legacy bottom border (replaced with .conv-item + .conv-item top border in C4) */
#conversationList .conv-item { border-bottom: 0; }

/* ─── Group tracking modal ─── */
.trk-list { display: flex; flex-direction: column; gap: 10px; }
.trk-card {
  border: 1px solid var(--gray-200); border-radius: 10px;
  background: #fff; overflow: hidden;
}
.trk-card-head {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 12px 14px; cursor: pointer;
  transition: background 0.12s;
}
.trk-card-head:hover { background: var(--gray-50); }
.trk-card-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.trk-card-meta { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.trk-card-stats {
  display: inline-flex; gap: 8px; align-items: center;
  font-size: 12px; font-weight: 600;
}
.trk-stat-joined { color: #16a34a; }
.trk-stat-pending { color: #d97706; }
.trk-card-body { padding: 12px 14px; border-top: 1px solid var(--gray-100); background: var(--gray-50); display: none; }
.trk-card.expanded .trk-card-body { display: block; }
.trk-member-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
  padding: 8px 12px; border-radius: 6px; background: #fff;
  margin-bottom: 4px;
  font-size: 13px;
}
.trk-member-row .trk-status {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.trk-status.joined { background: #dcfce7; color: #166534; }
.trk-status.pending { background: #fef3c7; color: #92400e; }
.trk-resend-btn {
  background: rgba(99,102,241,0.1); color: #4f46e5; border: 0;
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
  font-size: 11px; font-weight: 600;
}
.trk-resend-btn:hover { background: rgba(99,102,241,0.2); }
.trk-resend-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Today's Classes view ─── */
/* Schedule view container: flex column with the body taking the remaining
 * height and scrolling internally. Without flex:1 + overflow:auto, the list
 * grows past the viewport and the topbar/page can't scroll to reach it. */
#scheduleView .bulk-header,
#clubsView .bulk-header { flex-shrink: 0; }
/* Editorial heading on the daily-ops + admin views — Fraunces gives
   the page-anchor heading a "newspaper of today" feel, matches the
   Tickets and Super Admin sections. */
#scheduleView .bulk-section-head h2,
#clubsView .bulk-section-head h2,
#teamView .bulk-section-head h2 {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 500;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 144;
  color: var(--text);
}
#scheduleView .bulk-section-head h2 [data-lucide],
#clubsView .bulk-section-head h2 [data-lucide],
#teamView .bulk-section-head h2 [data-lucide] { color: var(--accent); }
#scheduleView .bulk-body,
#clubsView .bulk-body {
  flex: 1; min-height: 0;
  overflow: auto;
  padding: 16px 20px;
}
.schedule-list { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.schedule-filters {
  flex-shrink: 0;
  position: sticky;
  top: -16px;
  z-index: 5;
  background: var(--surface);
  margin-top: -16px;
  margin-left: -20px;
  margin-right: -20px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.sched-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.sched-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.sched-row.cancelled { opacity: 0.55; background: var(--surface-sunken); }
.sched-row.cancelled .sched-name { text-decoration: line-through; }
.sched-row.checked { border-left: 3px solid var(--wa); }

/* Time-status row colors — only meaningful for "today" (buildScheduleRow
   sets status-upcoming for non-today dates so the list stays neutral).
   Past   = sunken bg, muted text.
   Now    = info-soft tint + pulsing info dot.
   Upcoming = default --surface card. */
.sched-row.status-past {
  background: var(--surface-sunken);
  opacity: 0.78;
}
.sched-row.status-past .sched-time { color: var(--text-tertiary); }
.sched-row.status-past .sched-name { color: var(--text-secondary); }

.sched-row.status-now {
  background: var(--info-soft);
  border-color: var(--info);
  box-shadow: 0 0 0 2px var(--info-soft);
}
.sched-row.status-now .sched-time { color: var(--info); }
.sched-row.status-now::before {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--info);
  margin-left: -16px; margin-top: 8px;
  box-shadow: 0 0 0 4px var(--info-soft);
  animation: pulseNow 1.6s ease-in-out infinite;
}
.sched-row.status-now { position: relative; }
@keyframes pulseNow {
  0%, 100% { box-shadow: 0 0 0 0 var(--info-soft); }
  50%      { box-shadow: 0 0 0 10px transparent; }
}

/* Center the schedule header — the filter row stays full-width below. */
.schedule-header-centered {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}
.schedule-header-left {
  display: flex; gap: 8px; align-items: center;
  justify-self: start;
}
.schedule-header-title {
  margin: 0;
  display: inline-flex; align-items: center; gap: 8px;
  justify-self: center; text-align: center;
}
.schedule-header-right { justify-self: end; }

.sched-time {
  font-size: 18px; font-weight: 700; color: var(--text);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.sched-time-end { font-size: 11px; font-weight: 500; color: var(--text-tertiary); font-family: var(--font-mono); }

.sched-body { min-width: 0; }
.sched-name { font-size: 14.5px; font-weight: 600; color: var(--text); margin-bottom: 2px; letter-spacing: -0.005em; }
.sched-meta { font-size: 11.5px; color: var(--text-tertiary); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sched-note-badge {
  display: inline-block;
  background: var(--warning-soft); color: var(--warning);
  padding: 1px 7px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600;
}
.sched-source-badge {
  background: var(--accent-soft); color: var(--accent);
  padding: 1px 7px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 600;
}
.sched-cancelled-badge {
  background: var(--danger-soft); color: var(--danger);
  padding: 1px 7px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
}

.sched-actions { display: flex; align-items: center; gap: 6px; }
.sched-action-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface-sunken); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.sched-action-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
/* Primary (Send via WhatsApp) keeps the WhatsApp green identity — it's
   the brand for the outbound action, not a theme variable. */
.sched-action-btn.primary { background: var(--wa); border-color: var(--wa); color: #fff; }
.sched-action-btn.primary:hover { background: var(--wa-dark); }
.sched-action-btn.checked { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.sched-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sched-action-btn i.lucide { width: 14px; height: 14px; }

.sched-auto-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-secondary);
  cursor: pointer; user-select: none;
  padding: 4px 8px; border-radius: var(--radius-sm);
}
.sched-auto-toggle input { margin: 0; accent-color: var(--accent); }
.sched-auto-toggle:hover { background: var(--surface-hover); }
.sched-auto-toggle.on { color: var(--accent); font-weight: 600; }

.schedule-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}
.sched-cfg-mapping-row {
  display: grid; grid-template-columns: 110px 1fr; gap: 10px;
  margin-bottom: 8px; align-items: center;
}
.sched-cfg-mapping-row label { font-size: 12px; color: var(--gray-700); }
/* Today's Clubs row wrapper + expansion panel. The wrapper holds the
 * compact .sched-row plus a .club-expansion that drops down on click so
 * the agent can see which member-class WA groups make up the cluster. */
.club-row-wrap { display: flex; flex-direction: column; }
.club-body-clickable { cursor: pointer; user-select: none; }
.club-body-clickable:hover .sched-name { color: var(--accent); }
.club-name-line { display: inline-flex; align-items: center; gap: 6px; }
.club-chevron {
  font-size: 11px; color: var(--text-tertiary); transition: transform 0.15s, color 0.15s;
  display: inline-block;
}
.club-row-wrap.expanded .club-chevron { color: var(--accent); }
.club-member-chip {
  font-size: 11px; padding: 2px 8px; border-radius: var(--radius-pill); font-weight: 600;
}
/* Three states tied to the foundation semantic palette so dark mode
   pivots automatically. all = success, partial = warning, none = danger. */
.club-member-chip.all     { background: var(--success-soft); color: var(--success); }
.club-member-chip.partial { background: var(--warning-soft); color: var(--warning); }
.club-member-chip.none    { background: var(--danger-soft);  color: var(--danger); }
.club-topic-chip {
  font-size: 11px; padding: 2px 8px; border-radius: var(--radius-pill); font-weight: 500;
  background: var(--accent-soft); color: var(--accent);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: help;
}

.club-expansion {
  padding: 0 14px 14px 70px;
  background: var(--surface-sunken);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  border: 1px solid var(--border); border-top: 0;
  margin-top: -8px;
}
.club-expansion.hidden { display: none; }
.club-expansion-inner { padding-top: 10px; }
.club-expansion-head {
  font-size: 13px; color: var(--gray-700); margin-bottom: 6px;
}
.club-expansion-head strong { color: var(--gray-900); margin-right: 4px; }
.club-expansion-head em { color: var(--gray-500); font-style: italic; }
.club-expansion-subtitle {
  font-size: 12px; color: var(--gray-500); margin-bottom: 8px;
}
.club-expansion-empty { font-size: 12px; color: var(--gray-500); }
.club-member-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
}
@media (max-width: 800px) { .club-member-list { grid-template-columns: 1fr; } }
.club-member-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 4px 8px; border-radius: 6px;
  background: #fff; border: 1px solid var(--gray-200);
}
.club-member-item.unresolved { background: rgba(245, 158, 11, 0.05); }
.club-member-code { font-weight: 700; color: var(--gray-900); font-variant-numeric: tabular-nums; }
.club-member-level {
  font-size: 10px; padding: 1px 6px; border-radius: 3px;
  background: var(--gray-100); color: var(--gray-600); font-weight: 500;
}
.club-member-arrow { color: var(--gray-400); }
.club-member-target { color: var(--gray-700); flex: 1; }
.club-member-target.clickable { color: #4338ca; cursor: pointer; }
.club-member-target.clickable:hover { text-decoration: underline; }
.club-member-target.warn { color: #b45309; }

/* Clubs multi-send modal — checklist of member groups + pacing knobs +
 * live progress strip. Each row shows status icon (queued/sending/sent/
 * failed), the class code, level chip, target WA group name. */
.clubs-remind-row { display: flex; align-items: center; gap: 8px; }
.clubs-remind-grouplist {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
  max-height: 240px; overflow-y: auto;
  background: rgba(99, 102, 241, 0.04);
  border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 8px;
}
@media (max-width: 760px) { .clubs-remind-grouplist { grid-template-columns: 1fr; } }
.clubs-remind-item {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 4px 8px; border-radius: 6px;
  background: #fff; border: 1px solid var(--gray-200);
}
.clubs-remind-item input[type="checkbox"] { margin: 0; }
.clubs-remind-item .clubs-remind-status-icon {
  font-size: 13px; width: 16px; text-align: center;
  display: inline-block; flex-shrink: 0;
}
.clubs-remind-item .clubs-remind-code { font-weight: 700; color: var(--gray-900); font-variant-numeric: tabular-nums; }
.clubs-remind-item .clubs-remind-target { color: var(--gray-700); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clubs-remind-item.is-sent { background: rgba(34, 197, 94, 0.06); border-color: rgba(34, 197, 94, 0.3); }
.clubs-remind-item.is-sending { background: rgba(245, 158, 11, 0.08); border-color: rgba(245, 158, 11, 0.4); }
.clubs-remind-item.is-failed { background: rgba(239, 68, 68, 0.06); border-color: rgba(239, 68, 68, 0.3); }
.clubs-remind-item.is-cancelled { background: var(--gray-100); border-color: var(--gray-300); opacity: 0.6; }

.clubs-remind-delay {
  display: flex; align-items: center; gap: 16px;
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 8px 12px;
}
.clubs-remind-delay label { font-size: 13px; color: var(--gray-700); display: inline-flex; align-items: center; gap: 6px; }

.clubs-remind-status {
  font-size: 13px; padding: 8px 12px; border-radius: 6px;
  background: rgba(99, 102, 241, 0.08); color: #4338ca;
}
.clubs-remind-status.done { background: rgba(34, 197, 94, 0.1); color: #15803d; }
.clubs-remind-status.error { background: rgba(239, 68, 68, 0.1); color: #b91c1c; }

/* Day-of-week section header used by Today's Clubs in "All" view to group
 * clusters by their meeting day. Sticky-ish look but stays inline so the
 * scroll position is predictable. */
.clubs-day-header {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #4338ca;
  background: rgba(99, 102, 241, 0.08);
  padding: 6px 12px; border-radius: 6px;
  margin: 12px 0 4px;
}
.clubs-day-header:first-child { margin-top: 0; }

.sched-filter-btn,
.clubs-filter-btn {
  padding: 6px 14px; border-radius: 999px;
  background: var(--gray-100); border: 1px solid var(--gray-200);
  color: var(--gray-700); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.sched-filter-btn:hover,
.clubs-filter-btn:hover { background: var(--gray-200); }
.sched-filter-btn.active,
.clubs-filter-btn.active {
  background: rgba(99, 102, 241, 0.15); border-color: rgba(99, 102, 241, 0.4);
  color: #4338ca;
}
.sched-filter-count,
.clubs-filter-count {
  font-size: 11px; opacity: 0.8;
  font-variant-numeric: tabular-nums;
}
.sched-row.individual .sched-name::before { content: '👤 '; }
.sched-row.group .sched-name::before { content: '👥 '; }

/* ─── Labels dropdown — rows + actions + add button ─── */
.label-row {
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.label-row:hover { background: var(--gray-50); }
.label-swatch {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0;
}
.label-name {
  flex: 1; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.label-row .label-action-btn {
  display: none;
  background: transparent; border: 0;
  padding: 4px; border-radius: 4px;
  cursor: pointer;
  color: var(--gray-500);
  align-items: center; justify-content: center;
}
.label-row:hover .label-action-btn { display: inline-flex; }
.label-row .label-action-btn:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.label-row .label-action-btn [data-lucide] { width: 14px; height: 14px; }
.label-lock {
  width: 14px; height: 14px;
  color: var(--gray-400);
  flex-shrink: 0;
}
.label-add-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0; border-top: 1px solid var(--gray-100);
  background: transparent;
  color: var(--wa-dark, #075e54);
  font-weight: 500; font-size: 13px;
  cursor: pointer; text-align: left;
  margin-top: 4px;
}
.label-add-row:hover { background: var(--gray-50); }
.label-add-row .ad-add-icon { width: 14px; height: 14px; }

/* ─── Label editor modal — color grid ─── */
.label-color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.label-color-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s, border-color 0.1s;
}
.label-color-swatch:hover { transform: scale(1.06); }
.label-color-swatch.active {
  border-color: var(--gray-900);
  transform: scale(1.04);
  box-shadow: 0 0 0 2px #fff inset;
}

/* ─── Reminder modal — templates list (mirrors templates modal layout) ─── */
.reminder-tpl-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}
.reminder-tpl-list .tpl-item.reminder-tpl-row {
  padding: 8px 10px;
}
.reminder-tpl-list .tpl-item.reminder-tpl-row .tpl-content {
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px;
}
.reminder-tpl-use-btn {
  white-space: nowrap;
}
#reminderTplCategoryTabs {
  margin-bottom: 8px;
}

/* ===== Team-chat image annotator =====
   Full-viewport overlay. Toolbar pinned to the top, canvas fits the
   remaining space. Canvas is scaled by CSS but its bitmap stays at the
   image's natural resolution so the exported PNG keeps full quality. */
body.ia-open { overflow: hidden; }
.image-annotator-overlay {
  position: fixed; inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.92);
  display: flex; flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}
.image-annotator-toolbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
.image-annotator-toolbar .ia-tool {
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.image-annotator-toolbar .ia-tool:hover { background: #f3f4f6; }
.image-annotator-toolbar .ia-tool.active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
}
.image-annotator-toolbar .ia-sep {
  width: 1px; height: 24px; background: #e5e7eb; margin: 0 2px;
}
.image-annotator-toolbar .ia-spacer { flex: 1; }
.image-annotator-toolbar .ia-swatches {
  display: flex; gap: 8px; align-items: center;
}
.image-annotator-toolbar .ia-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid #e5e7eb;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.image-annotator-toolbar .ia-swatch:hover { transform: scale(1.08); }
.image-annotator-toolbar .ia-swatch.active {
  border-color: #111827;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111827;
}
.image-annotator-toolbar .ia-icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.image-annotator-toolbar .ia-icon-btn:hover { background: #f3f4f6; }
.image-annotator-toolbar .ia-text-btn {
  border: 1px solid #d1d5db;
  background: #f3f4f6;
  color: #111827;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.image-annotator-toolbar .ia-text-btn:hover { background: #e5e7eb; }
.image-annotator-toolbar .ia-text-btn.ia-done {
  background: #22c55e; border-color: #16a34a; color: #fff;
}
.image-annotator-toolbar .ia-text-btn.ia-done:hover { background: #16a34a; }

.image-annotator-canvas-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  overflow: auto;
}
.image-annotator-canvas {
  max-width: 100%; max-height: 100%;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  cursor: crosshair;
  touch-action: none; /* prevent scroll while drawing on touch */
}

/* Inline text input that pops up over the canvas in Text mode.
   v4: now a <textarea> so multi-line wrap is visible while typing.
   Width is set inline by JS (matches either an enclosing Box op or
   the distance to the canvas right edge). Auto-grows in height as
   the user types — JS toggles `height: auto` then sets scrollHeight.
   Dashed border keeps the "still editable" affordance. */
.ia-text-input {
  position: fixed;
  font-family: sans-serif;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.94);
  border: 2px dashed #ef4444;
  border-radius: 4px;
  padding: 2px 6px;
  outline: none;
  z-index: 1300;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  resize: none;
  overflow: hidden;
  line-height: 1.2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ===== Tickets view — HubSpot-style triage table =====
   New top-bar view added 2026-05-12. Live-fetches from HubSpot, edits
   write back via PATCH. Layout: filter chips header + scrollable
   grid table + load-more pager. Pills mirror HubSpot's status colors
   so an agent's eye lands on the right rows in 0.2 s. */
#ticketsView .bulk-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 8px;
}
.tickets-filter-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 4px 20px 12px;
}
/* Filter chips — ALWAYS colored, regardless of active state.
   The chip's status color is its visual identity, so muting it on
   inactivity would erase that identity. Instead the active/inactive
   distinction is communicated by:
     • opacity (active = 100 %, inactive = ~55 % so it reads as faded
       but still clearly "blue" / "red" / etc.)
     • a 2-px ring + checkmark glyph appearing only on the active chip,
       so a quick glance tells the agent which queues feed the table
       below. */
.tickets-filter-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  background: var(--gray-100); border: 1px solid var(--gray-200);
  color: var(--gray-700);
  /* Avoid layout shift when the ::after checkmark appears. Reserve
     room for it via a zero-width placeholder span. */
  transition: opacity 0.12s, box-shadow 0.12s, transform 0.08s;
  opacity: 0.55;
  /* `filter: saturate()` is too aggressive on the pale fills already
     used by the table pills; opacity alone reads cleaner. */
}
.tickets-filter-chip:hover { opacity: 0.78; }
.tickets-filter-chip:active { transform: scale(0.97); }

/* Per-status palette — same swatches as the table pills so the
   chip and the pill on the matching row read as one.
   Themed via OKLCH foundation tokens so colors stay legible in
   both light and dark mode (each token pivots brightness across
   themes; the chip border falls through to the saturated text
   colour for a subtle ring effect on both surfaces). */
.tickets-filter-chip.tickets-pill-new        { background: var(--info-soft);    border-color: transparent; color: var(--info); }
.tickets-filter-chip.tickets-pill-waiting    { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.tickets-filter-chip.tickets-pill-attention  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.tickets-filter-chip.tickets-pill-closed     { background: var(--surface-sunken); border-color: var(--border); color: var(--text-tertiary); }

/* Dot before the label — same color as the chip text. Keeps the
   "tiny legend" feel even on faded chips. */
.tickets-filter-chip::before {
  content: ''; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

/* Active state — full opacity + a softer outer ring + checkmark
   suffix. The ring uses currentColor (the chip's text colour) so
   it picks up the status palette automatically. */
.tickets-filter-chip.active {
  opacity: 1;
  box-shadow: 0 0 0 2px currentColor inset, 0 1px 2px rgba(0,0,0,0.06);
}
.tickets-filter-chip.active::after {
  content: '✓';
  font-weight: 800; font-size: 12px;
  margin-left: 2px;
}

/* Title block — Sheet-style: editorial title (Fraunces) + subtle subtitle */
.tickets-view-header { align-items: flex-start; }
.tickets-view-header .tickets-title-block { display: flex; flex-direction: column; gap: 4px; }
.tickets-view-header h2 {
  margin-bottom: 0;
  font-family: var(--font-display);
  font-size: 22px; font-weight: 500; letter-spacing: -0.015em;
  color: var(--text);
  font-variation-settings: "opsz" 144, "SOFT" 30;
}
.tickets-view-header h2 [data-lucide] { color: var(--accent); }
.tickets-subtitle {
  margin: 0; font-size: 12px; color: var(--text-tertiary); font-weight: 400;
  letter-spacing: 0.01em;
  max-width: 600px;
}

.tickets-table-wrap {
  flex: 1; overflow: auto; padding: 0 20px 12px;
}
.tickets-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  /* Was `overflow: hidden` to clip the rounded corners — but that
     also blocked position: sticky on the header. We need the header
     row to stick to the top of the .tickets-table-wrap scroll
     container as the agent scrolls through the queue. Use
     `isolation: isolate` to keep the stacking context separate
     instead, and let the inner radius come from the first-row hack
     below. */
  overflow: visible;
  isolation: isolate;
  /* min-width: min-content forces the table to be AT LEAST as wide as
     the sum of its row's grid track minimums (≈1558 px). Default block
     behaviour still lets the table grow with .tickets-table-wrap on
     wide viewports (fr units distribute the surplus), but the table
     can never be NARROWER than its own rows. That was Ayoub's "decalage
     kamel" — rows were 1558 px while the table was clipping at 1240 px,
     so the last 3 cells protruded past the rounded border. */
  min-width: min-content;
}
/* Round the last row's bottom corners so the zebra fill respects the
   table's outer radius. .tickets-row-head already rounds the top via
   border-*-top-radius rules; without this the bottom edges showed a
   square zebra fill bleeding past the rounded border. */
.tickets-table .tickets-row:last-child {
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}
.tickets-row {
  display: grid;
  /* 11 columns — leading checkbox + 10 data columns. Sheet-style spacing.
     Agent note shares fr ratio with student feedback so wide viewports
     give them equal extra space, but the MIN widths differ — Agent
     notes are typically short ("asmae/non answer", "—"), feedback is
     usually multi-sentence. Matching min widths was visually correct
     in theory but wasted 60 px in the common case where agent_note is
     empty, pushing the total grid past 1600 px and forcing horizontal
     scroll on 1280–1440 viewports. */
  grid-template-columns:
    36px                   /* Select checkbox */
    minmax(160px, 1.2fr)   /* Ticket name */
    120px                  /* Status */
    100px                  /* Priority */
    150px                  /* Feedback Status */
    minmax(130px, 1fr)     /* Contact */
    130px                  /* Assigned */
    minmax(120px, 1fr)     /* Companies */
    minmax(220px, 2fr)     /* Student feedback */
    minmax(160px, 1.5fr)   /* Agent note — smaller min, same fr-growth */
    100px;                 /* Created */
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 80ms ease;
}
.tickets-row.is-selected { background: var(--accent-soft) !important; }
.tickets-row.is-selected:hover { background: var(--accent-soft) !important; box-shadow: inset 3px 0 0 var(--accent); }
.tickets-cell-select { display: flex; align-items: center; justify-content: center; }
.tickets-cell-select input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent);
}

/* Floating bulk-action bar — appears when ≥1 row checked. High-contrast
   command surface that flips polarity with the theme: dark slate in
   light mode, warm white in dark mode. The local --tbb-tint variable
   carries the highlight colour used for the inner buttons / separators
   so they read correctly against the inverse surface. */
/* Bulk-action bar now lives at the TOP of the tickets view, right below
   the filter chips (was sticky:bottom — moved per Ayoub's request so
   the bar lives next to the info bar instead of covering data rows).
   Slides down from the chips when ≥1 row is checked. */
.tickets-bulk-bar {
  margin: 0 20px 12px;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--text-inverse);
  --tbb-tint: rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  z-index: 3;
  animation: tbb-slide-down 140ms ease;
}
[data-theme="dark"] .tickets-bulk-bar { --tbb-tint: rgba(0, 0, 0, 0.10); }
.tickets-bulk-bar.hidden { display: none; }
@keyframes tbb-slide-down { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.tickets-bulk-bar .tbb-count { font-weight: 700; letter-spacing: 0.3px; }
.tickets-bulk-bar .tbb-sep { width: 1px; height: 18px; background: var(--tbb-tint); }
.tickets-bulk-bar .tbb-btn {
  background: var(--tbb-tint); color: inherit;
  border: 1px solid var(--tbb-tint);
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  border-radius: var(--radius-sm); cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--motion-fast) var(--ease);
}
.tickets-bulk-bar .tbb-btn:hover { background: var(--tbb-tint); filter: brightness(1.4); }
.tickets-bulk-bar .tbb-cancel { margin-left: auto; opacity: 0.85; }
.tickets-bulk-bar .tbb-cancel:hover { opacity: 1; }
.tickets-row:last-child { border-bottom: 0; }
.tickets-row-head {
  background: var(--surface-sunken);
  /* Header sticks to the top of the scrolling container so column
     labels stay visible while the agent scrolls through dozens of
     tickets. Slight shadow gives it a soft "floating" feel once the
     rows start scrolling underneath. */
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--border);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  font-size: 11px; font-weight: 600;
  color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 16px;
}
.tickets-row:not(.tickets-row-head):hover { background: var(--surface-hover); }
.tickets-row:nth-child(even):not(.tickets-row-head) { background: var(--surface-sunken); }
.tickets-row:nth-child(even):not(.tickets-row-head):hover { background: var(--surface-hover); }

/* Sortable column header — click to sort asc/desc. Arrow renders inline
   only on the active column; inactive headers stay clean and tighter. */
.tickets-cell-head {
  color: var(--text-tertiary); white-space: nowrap;
  cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color 100ms ease;
}
.tickets-cell-head:hover { color: var(--text); }
.tickets-cell-head .sort-arrow {
  display: inline-flex; opacity: 0; transition: opacity 80ms ease;
  font-size: 10px; color: var(--accent);
}
.tickets-cell-head.sort-active .sort-arrow { opacity: 1; }
.tickets-cell-head.sort-active { color: var(--text); }

.tickets-cell {
  font-size: 13px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.tickets-cell-head { color: var(--text-tertiary); white-space: nowrap; }
.tickets-cell-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.tickets-cell-date { color: var(--text-tertiary); font-size: 12px; }
.tickets-cell-text { cursor: pointer; }
/* Empty free-text cells (Agent note / Student feedback with no value) —
   mute the `—` placeholder so the eye doesn't read it as an intentional
   gap. Same trick as muted dates / counts elsewhere in the table. */
.tickets-cell-empty .tickets-cell-text-preview { color: var(--text-muted); opacity: 0.45; }
/* Dark mode: lift the muted opacity slightly so the placeholder stays
   above the AA contrast floor on dark surfaces. */
[data-theme="dark"] .tickets-cell-empty .tickets-cell-text-preview { color: var(--text-tertiary); opacity: 0.7; }
.tickets-cell-text:hover { background: var(--accent-soft); border-radius: var(--radius-xs); }
.tickets-cell-text-preview { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.tickets-open-link {
  display: inline-flex; align-items: center; color: var(--text-muted);
  text-decoration: none; opacity: 0; transition: opacity 0.12s, color 0.12s;
}
.tickets-open-link [data-lucide] { width: 12px; height: 12px; }
.tickets-row:hover .tickets-open-link { opacity: 1; }
.tickets-open-link:hover { color: var(--accent); }

.tickets-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); border: 1px solid transparent;
  font-size: 12px; font-weight: 600; color: var(--text-tertiary);
  cursor: pointer; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: inherit;
  transition: filter var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.tickets-pill:hover { filter: brightness(0.96); }
[data-theme="dark"] .tickets-pill:hover { filter: brightness(1.15); }
.tickets-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Sheet-style cell-active focus ring — matches the Teachers Sheet feel
   when an inline-editable cell is in focus. Applied via JS when an
   inline dropdown opens against a pill cell. */
.tickets-cell.is-focus,
.tickets-pill.is-focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.tickets-pill-new       { background: var(--info-soft);    color: var(--info); }
.tickets-pill-attention { background: var(--danger-soft);  color: var(--danger); }
.tickets-pill-waiting   { background: var(--warning-soft); color: var(--warning); }
.tickets-pill-closed    { background: var(--surface-sunken); border-color: var(--border); color: var(--text-tertiary); }
.tickets-pill-low       { background: var(--success-soft); color: var(--success); }
.tickets-pill-medium    { background: var(--warning-soft); color: var(--warning); }
.tickets-pill-high      { background: var(--danger-soft);  color: var(--danger); }
.tickets-pill-urgent    { background: var(--danger-soft);  color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.tickets-pill-neutral   { background: var(--surface-sunken); border-color: var(--border); color: var(--text-tertiary); }

.tickets-pill-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.tickets-pill-dot.tickets-pill-new       { background: var(--info); }
.tickets-pill-dot.tickets-pill-attention { background: var(--danger); }
.tickets-pill-dot.tickets-pill-waiting   { background: var(--warning); }
.tickets-pill-dot.tickets-pill-closed    { background: var(--text-muted); }
.tickets-pill-dot.tickets-pill-low       { background: var(--success); }
.tickets-pill-dot.tickets-pill-medium    { background: var(--warning); }
.tickets-pill-dot.tickets-pill-high      { background: var(--danger); }
.tickets-pill-dot.tickets-pill-urgent    { background: var(--danger); }

/* Inline dropdown menu — anchored at the pill's bottom by the open
   helper. Mirrors the topbar .view-tab-menu look (PR #121) so the
   visual rhythm of dropdowns across the app stays consistent. */
.tickets-inline-menu {
  position: fixed; z-index: 1100;
  min-width: 200px; max-height: 280px; overflow-y: auto;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.tickets-inline-menu-item {
  display: inline-flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 7px 10px; border-radius: var(--radius-sm);
  background: transparent; border: 0; cursor: pointer;
  font-size: 13px; color: var(--text-secondary);
  text-align: left;
  font-family: inherit;
}
.tickets-inline-menu-item:hover { background: var(--surface-hover); color: var(--text); }
.tickets-inline-menu-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tickets-inline-menu-item.disabled { color: var(--text-muted); cursor: not-allowed; font-style: italic; }
.tickets-inline-menu-item.disabled:hover { background: transparent; }

.tickets-empty {
  padding: 32px 20px; text-align: center;
  color: var(--gray-500); font-size: 13px;
}
.tickets-pager {
  padding: 12px 20px 20px;
  display: flex; justify-content: center;
}

/* Contact-cell link inside the Tickets table — click jumps the agent
   straight into the 1-1 inbox conversation with that student (handled
   in buildContactCell via openChatForPhoneNumber). */
.tickets-cell-contact .tickets-contact-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
.tickets-cell-contact .tickets-contact-link:hover {
  text-decoration: underline;
}

/* Companies cell — one or more clickable chips per ticket. Each chip
   navigates to the corresponding WhatsApp group inbox via the
   tracking-table match server-side. Disabled (gray) when no matching
   WA group exists for that HubSpot company. */
.tickets-cell-companies {
  display: flex; flex-wrap: wrap; gap: 4px;
  white-space: normal;
}
.tickets-company-link {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent;
  font-size: 12px; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tickets-company-link:hover { background: var(--accent-soft); filter: brightness(0.96); }
[data-theme="dark"] .tickets-company-link:hover { filter: brightness(1.15); }
.tickets-company-link-disabled {
  background: var(--surface-sunken); color: var(--text-tertiary);
  border-color: var(--border); cursor: default;
}
.tickets-company-link-disabled:hover { background: var(--surface-sunken); filter: none; }

/* Minimal inline spinner for the Tickets loading state. Pure CSS,
   no SVG dependency. Spins next to "Loading tickets…" so the user
   sees motion while the HubSpot round-trip resolves. */
.tickets-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(0,0,0,0.12);
  border-top-color: #3b82f6;
  border-radius: 50%;
  vertical-align: -2px;
  animation: tickets-spin 0.8s linear infinite;
}
@keyframes tickets-spin { to { transform: rotate(360deg); } }

/* ===== Tickets — Feedback Status multi-select dropdown =====
   Lives below the status chip row. Trigger button shows a label +
   count badge; click opens a panel with a searchable checkbox list
   of the 27 BOT_TICKET_CATEGORIES values. Each tick reloads the
   list with `categories=` in the query string. */
.tickets-category-filter {
  position: relative;
  padding: 0 20px 12px;
  display: flex;
  align-items: center;
}
.tickets-category-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.tickets-category-trigger:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.tickets-category-trigger [data-lucide] { width: 14px; height: 14px; stroke-width: 2; }
.tickets-category-trigger .tickets-category-chevron { transition: transform 0.15s; }
.tickets-category-filter.open .tickets-category-trigger {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.tickets-category-filter.open .tickets-category-chevron { transform: rotate(180deg); }

.tickets-category-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent); color: var(--accent-fg);
  font-size: 10px; font-weight: 700; line-height: 1;
}
.tickets-category-count.hidden { display: none; }

.tickets-category-menu {
  position: absolute;
  top: calc(100% - 8px);
  left: 20px;
  z-index: 30;
  min-width: 260px; max-width: 320px;
  max-height: 380px;
  display: flex; flex-direction: column;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.tickets-category-menu.hidden { display: none; }
.tickets-category-menu-head {
  display: flex; gap: 6px; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
}
.tickets-category-menu-head .input {
  flex: 1; padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--gray-200); border-radius: 8px;
}
.tickets-category-menu-head .btn { padding: 5px 10px; font-size: 12px; }

.tickets-category-list {
  flex: 1; overflow-y: auto;
  padding: 6px;
  display: flex; flex-direction: column; gap: 1px;
}
.tickets-category-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  font-size: 13px; color: var(--gray-800);
  cursor: pointer;
  user-select: none;
}
.tickets-category-item:hover { background: var(--gray-100); }
.tickets-category-item input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer;
  accent-color: #2563eb;
}
.tickets-category-empty {
  padding: 20px; text-align: center;
  font-size: 12px; color: var(--gray-500);
}

/* ─── Mr.Call pipeline bar — Sprint 4 Phase 1 ─────────────────────────
   Sits between .chat-header and #messagesArea. Horizontal flow of 6
   forward pills + a small side-branch chip group (no_answer, no_show,
   lost) + a right-side actions cluster (Move-to dropdown + History).
   Matches the .chat-header surface so the two read as a single header
   block. */
.pipeline-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
  flex-shrink: 0;
  min-height: 44px;
  font-size: 12px;
  color: var(--text-secondary);
}
.pipeline-bar.hidden { display: none; }

/* ─── Mr.Call AI coach banner — sits between pipeline bar and messages ──── */
.mrcall-banner {
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f5f3ff 0%, #faf9ff 100%);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-primary);
  flex-shrink: 0;
}
.mrcall-banner.hidden { display: none; }
.mrcall-row { display: flex; align-items: center; gap: 10px; }
.mrcall-row.hidden { display: none; }
.mrcall-icon { font-size: 16px; line-height: 1; }
.mrcall-score-pill {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
  background: #e0e7ff; color: #4338ca;
  white-space: nowrap;
}
.mrcall-score-pill.score-cold { background: #dbeafe; color: #1d4ed8; }
.mrcall-score-pill.score-warm { background: #fef3c7; color: #b45309; }
.mrcall-score-pill.score-hot  { background: #fee2e2; color: #b91c1c; }
.mrcall-stage {
  font-weight: 600; color: var(--text-primary);
  white-space: nowrap;
}
.mrcall-suggest {
  flex: 1; min-width: 0;
  font-style: italic; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mrcall-btn-copy {
  border: 1px solid var(--border); background: #fff;
  padding: 3px 10px; border-radius: 6px; font-size: 12px;
  cursor: pointer; font-weight: 500;
}
.mrcall-btn-copy:hover { background: #f3f4f6; }
.mrcall-btn-icon {
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 4px 6px;
  color: var(--text-secondary); border-radius: 4px;
}
.mrcall-btn-icon:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }
.mrcall-row-expanded {
  flex-direction: column; align-items: stretch; gap: 6px;
  padding-top: 8px; margin-top: 6px;
  border-top: 1px dashed var(--border);
}
.mrcall-meta {
  display: flex; gap: 18px; font-size: 12px; color: var(--text-secondary);
}
.mrcall-objs { display: flex; flex-direction: column; gap: 6px; }
.mrcall-obj {
  display: flex; flex-direction: column;
  padding: 6px 10px; border-radius: 6px;
  background: rgba(255,255,255,0.7); border: 1px solid var(--border);
}
.mrcall-obj-label { font-weight: 600; font-size: 12px; color: #b91c1c; }
.mrcall-obj-rebuttal { font-size: 12px; color: var(--text-primary); margin-top: 2px; }

.pipeline-bar-flow {
  display: flex; align-items: center; gap: 4px;
  flex-wrap: wrap;
}

.pipeline-stage {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 500;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  cursor: pointer; user-select: none;
  white-space: nowrap;
  font-family: inherit;
  transition: background var(--motion-fast, 120ms) ease,
              color var(--motion-fast, 120ms) ease,
              border-color var(--motion-fast, 120ms) ease,
              transform var(--motion-fast, 120ms) ease;
}
.pipeline-stage:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-hover); }
.pipeline-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pipeline-stage-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gray-200); color: var(--gray-600);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0;
}

/* Past = faded WhatsApp emerald — agent sees at a glance how far the
   lead has progressed without the "current" stage competing for focus. */
.pipeline-stage.past {
  background: oklch(0.85 0.18 150 / 0.18);
  border-color: oklch(0.60 0.16 150 / 0.45);
  color: oklch(0.40 0.10 150);
}
[data-theme="dark"] .pipeline-stage.past {
  background: oklch(0.32 0.08 150 / 0.45);
  border-color: oklch(0.42 0.10 150 / 0.65);
  color: oklch(0.85 0.06 150);
}
.pipeline-stage.past .pipeline-stage-num {
  background: var(--wa); color: #fff;
}

/* Active = solid WhatsApp emerald — the dominant pill in the bar. */
.pipeline-stage.active {
  background: var(--wa);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px oklch(0.60 0.16 150 / 0.30);
}
.pipeline-stage.active:hover { background: var(--wa-dark); color: #fff; }
.pipeline-stage.active .pipeline-stage-num {
  background: rgba(255, 255, 255, 0.25); color: #fff;
}

.pipeline-stage.future { color: var(--text-tertiary); }
.pipeline-stage.future:hover { color: var(--text); }

.pipeline-stage-arrow {
  color: var(--text-muted);
  font-size: 10px;
  margin: 0 -2px;
  user-select: none;
}

/* Side branch chips — visually de-emphasised; off to the right of the
   forward flow with a thin separator. Amber for transient side states
   (no_answer, no_show); red for terminal `lost`. */
.pipeline-bar-side {
  display: flex; align-items: center; gap: 4px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.pipeline-stage-side {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-tertiary);
  font-size: 11px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast, 120ms) ease,
              color var(--motion-fast, 120ms) ease;
}
.pipeline-stage-side:hover { background: var(--surface-hover); color: var(--text); }
.pipeline-stage-side.active.side-warning {
  background: var(--warning-soft); border-color: var(--warning);
  color: var(--warning); border-style: solid; font-weight: 600;
}
.pipeline-stage-side.active.side-danger {
  background: oklch(0.62 0.20 25 / 0.14); border-color: oklch(0.60 0.20 25);
  color: oklch(0.50 0.18 25); border-style: solid; font-weight: 600;
}
[data-theme="dark"] .pipeline-stage-side.active.side-danger {
  color: oklch(0.78 0.16 25);
}

.pipeline-bar-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 6px;
}
.pipeline-bar-actions .pipeline-action-btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 26px; padding: 0 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--motion-fast, 120ms) ease, color var(--motion-fast, 120ms) ease;
}
.pipeline-bar-actions .pipeline-action-btn:hover { background: var(--surface-hover); color: var(--text); }
.pipeline-bar-actions .pipeline-action-btn [data-lucide] { width: 12px; height: 12px; }

.pipeline-create-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--wa); color: #fff; border: 0;
  font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.pipeline-create-btn:hover { background: var(--wa-dark); }
.pipeline-create-btn [data-lucide] { width: 12px; height: 12px; }

.pipeline-bar-loading,
.pipeline-bar-empty {
  font-size: 12px; color: var(--text-tertiary);
  padding: 2px 4px;
}

/* Inline confirm popover anchored to the pipeline bar. Positioned
   absolutely so it doesn't push messages around when it opens. */
.pipeline-confirm {
  position: absolute;
  z-index: 50;
  min-width: 260px; max-width: 340px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, 0 8px 24px oklch(0 0 0 / 0.15));
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  font-size: 13px;
  color: var(--text);
}
.pipeline-confirm-title {
  font-weight: 600; font-size: 13px; color: var(--text);
}
.pipeline-confirm-title strong { color: var(--wa); }
.pipeline-confirm-title.is-back strong { color: var(--warning); }
.pipeline-confirm-reason {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px; font-family: inherit;
  color: var(--text);
  resize: vertical; min-height: 32px; max-height: 96px;
}
.pipeline-confirm-actions {
  display: flex; justify-content: flex-end; gap: 6px;
}
.pipeline-confirm-actions .btn {
  height: 28px; padding: 0 12px; font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent; color: var(--text);
  cursor: pointer; font-family: inherit; font-weight: 500;
}
.pipeline-confirm-actions .btn:hover { background: var(--surface-hover); }
.pipeline-confirm-actions .btn-primary {
  background: var(--wa); color: #fff; border-color: transparent;
}
.pipeline-confirm-actions .btn-primary:hover { background: var(--wa-dark); }

/* Pipeline history modal list */
.pipeline-history-list {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 60px;
}
.pipeline-history-loading,
.pipeline-history-empty {
  padding: 24px; text-align: center;
  color: var(--text-tertiary); font-size: 13px;
}
.pipeline-history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.pipeline-history-row .hist-transition {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.pipeline-history-row .hist-transition .pill {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600;
  background: var(--gray-100); color: var(--gray-700);
}
.pipeline-history-row .hist-transition .pill.to { background: var(--success-soft); color: var(--success); }
.pipeline-history-row .hist-when {
  font-size: 11px; color: var(--text-tertiary); text-align: right;
}
.pipeline-history-row .hist-meta {
  grid-column: 1 / -1;
  font-size: 11px; color: var(--text-tertiary);
}
.pipeline-history-row .hist-reason {
  grid-column: 1 / -1;
  margin-top: 2px;
  font-size: 12px; color: var(--text-secondary);
  font-style: italic;
}

/* ============================================================
   Dashboards view (Sprint 4 Feature 3) — Funnel + Agents
   Pure CSS chart, no Chart.js. Bars use width:% based on the
   tallest forward-stage cumulative reach. Arrows between stages
   show conversion %.
   ============================================================ */
.dash-subtabs {
  display: flex; gap: 8px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dash-subtab {
  background: transparent; border: 0; padding: 10px 14px;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color 120ms, border-color 120ms;
}
.dash-subtab:hover { color: var(--text); }
.dash-subtab-active { color: var(--text); border-bottom-color: var(--primary, #2563eb); }
.dash-subtab i { width: 14px; height: 14px; }

.dash-filter-row {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface, #fff);
  flex-shrink: 0;
}
.dash-filter-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; font-weight: 500; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.dash-filter-label .input { font-size: 13px; padding: 6px 8px; min-width: 140px; }
.dash-filter-row .btn { height: 32px; }

.dash-tab-body {
  flex: 1; overflow: auto; padding: 16px;
  background: var(--bg);
}

.dash-loading {
  padding: 32px; text-align: center;
  color: var(--text-secondary); font-size: 13px;
}

/* ---- Funnel chart ---- */
.dash-funnel-chart {
  display: flex; flex-direction: column; gap: 4px;
  max-width: 880px; margin: 0 auto;
  background: var(--surface, #fff);
  border: 1px solid var(--border); border-radius: var(--radius-lg, 8px);
  padding: 20px;
}
.dash-funnel-row {
  display: grid;
  grid-template-columns: 160px 1fr 80px;
  gap: 12px; align-items: center;
  min-height: 36px;
}
.dash-funnel-label {
  font-size: 13px; font-weight: 500; color: var(--text);
  text-align: right;
}
.dash-funnel-bar-track {
  background: var(--gray-100, #f3f4f6);
  border-radius: 4px; height: 28px; position: relative;
  overflow: hidden;
}
.dash-funnel-bar-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary, #2563eb), #60a5fa);
  border-radius: 4px;
  transition: width 240ms ease-out;
  display: flex; align-items: center; padding-left: 10px;
  color: #fff; font-size: 12px; font-weight: 600;
}
.dash-funnel-count {
  font-size: 13px; font-weight: 600; color: var(--text);
  text-align: left;
}
.dash-funnel-arrow-row {
  display: grid;
  grid-template-columns: 160px 1fr 80px;
  gap: 12px; align-items: center;
  min-height: 24px;
}
.dash-funnel-arrow {
  grid-column: 2 / 3;
  display: flex; align-items: center; gap: 6px;
  padding-left: 14px;
  font-size: 11px; color: var(--text-secondary);
}
.dash-funnel-arrow-bar {
  flex: 0 0 2px; height: 14px; background: var(--gray-300, #d1d5db);
  margin-right: 4px;
}
.dash-funnel-arrow-pct {
  background: var(--gray-100, #f3f4f6); padding: 2px 6px; border-radius: 4px;
  font-weight: 600; color: var(--text);
}
.dash-funnel-arrow-pct.dash-high { background: #d1fae5; color: #065f46; }
.dash-funnel-arrow-pct.dash-mid  { background: #fef3c7; color: #92400e; }
.dash-funnel-arrow-pct.dash-low  { background: #fee2e2; color: #991b1b; }

.dash-side-chips {
  display: flex; gap: 8px; flex-wrap: wrap;
  max-width: 880px; margin: 16px auto 0;
  padding: 0 4px;
}
.dash-side-chip {
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px; color: var(--text-secondary);
  display: inline-flex; align-items: center; gap: 6px;
}
.dash-side-chip strong { color: var(--text); font-weight: 600; }

/* ---- Agents table ---- */
.dash-agents-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 8px);
  overflow: hidden;
}
.dash-agents-table th,
.dash-agents-table td {
  padding: 10px 14px; font-size: 13px;
  text-align: left; border-bottom: 1px solid var(--border);
}
.dash-agents-table th {
  background: var(--gray-50, #f9fafb);
  color: var(--text-secondary);
  font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
  cursor: pointer; user-select: none;
  position: sticky; top: 0; z-index: 1;
}
.dash-agents-table th:hover { background: var(--gray-100, #f3f4f6); }
.dash-agents-table th.dash-th-active {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--primary, #2563eb);
}
.dash-agents-table th.dash-th-active::after {
  content: ' ↓'; font-weight: 700;
}
.dash-agents-table th.dash-th-active.dash-th-asc::after {
  content: ' ↑';
}
.dash-agents-table tbody tr:hover { background: var(--gray-50, #f9fafb); }
.dash-agents-table td.dash-num { font-variant-numeric: tabular-nums; }
.dash-agents-table tbody tr:last-child td { border-bottom: 0; }
/* ─── Test schedule view (Sprint 4 Phase 2) ────────────────────────── */
.ts-title-block { display: flex; flex-direction: column; gap: 2px; }
.ts-title-block h2 { margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.ts-subtitle { margin: 0; font-size: 13px; color: var(--text-tertiary); }

.ts-date-nav { display: flex; align-items: center; gap: 8px; }
.ts-date-input { width: 160px; }

.ts-stats {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
}
.ts-stat {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 6px 10px; min-width: 64px;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.ts-stat-num { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.ts-stat-lbl { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.05em; }

.ts-grid-wrap { padding: 16px 20px 24px; overflow: auto; }
.ts-grid {
  display: grid;
  gap: 4px;
  align-items: stretch;
  min-width: 720px;
}
.ts-corner {
  background: var(--surface-sunken); color: var(--text-tertiary);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  position: sticky; top: 0; left: 0; z-index: 3;
}
.ts-teacher-head {
  background: var(--surface-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  font-weight: 600; font-size: 13px;
  position: sticky; top: 0; z-index: 2;
}
.ts-teacher-color {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.ts-teacher-name { color: var(--text); }
.ts-time {
  background: var(--surface-sunken); color: var(--text-secondary);
  font-size: 12px; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  position: sticky; left: 0; z-index: 1;
}
.ts-cell {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 8px;
  min-height: 40px;
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  font-family: inherit;
  font-size: 11px; color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: transform var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.ts-cell:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.ts-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-cell-status { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.ts-cell-label  { font-size: 12px; color: var(--text); font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ts-cell-available { background: var(--success-soft); border-color: color-mix(in oklch, var(--success) 30%, transparent); color: var(--success); }
.ts-cell-available:hover { background: color-mix(in oklch, var(--success) 18%, transparent); }
.ts-cell-booked    { background: var(--accent-soft); border-color: color-mix(in oklch, var(--accent) 30%, transparent); color: var(--accent); }
.ts-cell-in-test   { background: var(--wa-soft); border-color: color-mix(in oklch, var(--wa) 30%, transparent); color: var(--wa-dark); }
.ts-cell-completed { background: var(--gray-200); border-color: var(--border); color: var(--text-secondary); }
.ts-cell-no-show   { background: var(--danger-soft); border-color: color-mix(in oklch, var(--danger) 30%, transparent); color: var(--danger); }
.ts-cell-cancelled { background: var(--surface-sunken); border-color: var(--border-subtle); color: var(--text-tertiary); text-decoration: line-through; }
.ts-cell-missing   { background: transparent; color: var(--text-tertiary); border-style: dashed; cursor: default; }

.ts-empty {
  grid-column: 1 / -1;
  padding: 40px 20px; text-align: center;
  color: var(--text-tertiary); font-size: 13px;
}
.ts-empty-error { color: var(--danger); }

/* Test schedule modals */
.ts-slot-summary {
  background: var(--surface-sunken); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 10px 12px; margin-bottom: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.ts-slot-summary-row { font-size: 13px; color: var(--text); }
.ts-slot-summary-muted { color: var(--text-tertiary); font-size: 12px; }
.ts-slot-status-pill {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.ts-book-results {
  margin-top: 10px;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 280px; overflow-y: auto;
}
.ts-book-result {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  text-align: left; cursor: pointer; font-family: inherit; color: var(--text);
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.ts-book-result:hover { background: var(--surface-hover); }
.ts-book-result.selected { border-color: var(--accent); background: var(--accent-soft); }
.ts-book-result-main { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ts-book-result-name  { font-size: 13px; font-weight: 600; }
.ts-book-result-stage { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }
.ts-book-result-phone { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.ts-book-empty { padding: 12px; text-align: center; color: var(--text-tertiary); font-size: 13px; }
.ts-book-error {
  margin-top: 10px;
  padding: 8px 12px; border-radius: var(--radius-md);
  background: var(--danger-soft); color: var(--danger);
  font-size: 12px;
