/* ============================================================
   Bot Dynamics AI - Client Portal Design System (Phase 6a)
   ============================================================
   Reference quality: Stripe Dashboard, Vercel, Linear.
   Inter via Google Fonts; tokens on :root used by every component.

   Layer order:
     1. Tokens
     2. Reset + base
     3. Typography
     4. Components (button, input, badge, card, stat-card, skeleton,
        table, empty-state, avatar, dropdown, toast, modal)
     5. Login screen
     6. App shell (sidebar + topbar + main)
     7. Dashboard page
     8. Placeholder ("coming soon") pages
     9. Mobile / motion preferences
   ============================================================ */


/* ---------------------------------------------------------- 1. TOKENS */
:root {
  /* Colors */
  --bg-page: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f2f6;
  --bg-hover: #f7f8fa;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-inverse: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --brand: #6366f1;
  --brand-hover: #4f46e5;
  --brand-soft: #eef2ff;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Spacing scale (4px base) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --space-12: 48px; --space-16: 64px;

  /* Radius */
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows (subtle, layered) */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.06);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06);
  --shadow-glow: 0 0 0 4px rgb(99 102 241 / 0.12);

  /* Transitions */
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 60px;
}


/* ---------------------------------------------------------- 2. RESET + BASE */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; padding: 0; cursor: pointer; }

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--brand-hover); }

:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
  border-radius: var(--radius-sm);
}

::selection { background: var(--brand-soft); color: var(--text-primary); }

img, svg { display: block; max-width: 100%; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}


/* ---------------------------------------------------------- 3. TYPOGRAPHY */
.h1 { font-size: 30px; font-weight: 700; line-height: 1.2;  letter-spacing: -0.02em; color: var(--text-primary); margin: 0; }
.h2 { font-size: 24px; font-weight: 600; line-height: 1.25; letter-spacing: -0.015em; color: var(--text-primary); margin: 0; }
.h3 { font-size: 20px; font-weight: 600; line-height: 1.3;  letter-spacing: -0.01em; color: var(--text-primary); margin: 0; }
.h4 { font-size: 18px; font-weight: 600; line-height: 1.4; color: var(--text-primary); margin: 0; }

.body    { font-size: 14px; line-height: 1.5; color: var(--text-primary); }
.body-lg { font-size: 16px; line-height: 1.55; color: var(--text-primary); }
.body-sm { font-size: 13px; line-height: 1.45; color: var(--text-secondary); }
.caption { font-size: 12px; line-height: 1.4; color: var(--text-tertiary); }

.text-muted { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.tabular { font-variant-numeric: tabular-nums; }


/* ---------------------------------------------------------- 4. COMPONENTS */

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
  white-space: nowrap;
  user-select: none;
  border: 1px solid transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-block { width: 100%; }

.btn-primary {
  background: var(--brand);
  color: var(--text-inverse);
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:focus-visible { box-shadow: var(--shadow-glow); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
}
.btn-danger:hover { background: #dc2626; }

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon svg { width: 18px; height: 18px; }

/* Spinning icon - used inline on Refresh button */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-icon.is-spinning svg { animation: spin 600ms cubic-bezier(0.4, 0, 0.2, 1); }

/* Input */
.input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font-sans);
}
.input::placeholder { color: var(--text-tertiary); }
.input:hover { border-color: var(--border-strong); }
.input:focus, .input:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--shadow-glow);
  outline: none;
}
.input.has-error {
  border-color: var(--danger);
}
.input.has-error:focus {
  box-shadow: 0 0 0 4px rgb(239 68 68 / 0.12);
}
.input-mono { font-family: var(--font-mono); }

.label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-error {
  margin-top: var(--space-3);
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-error::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  line-height: 1.6;
}
.badge-brand   { background: var(--brand-soft);   color: var(--brand-hover); }
.badge-success { background: var(--success-soft); color: #047857; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger  { background: var(--danger-soft);  color: #b91c1c; }

/* Delta chip (KPI cards) */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.delta-up   { background: var(--success-soft); color: #047857; }
.delta-down { background: var(--danger-soft);  color: #b91c1c; }
.delta-flat { background: var(--bg-subtle);    color: var(--text-secondary); }
.delta::before { font-weight: 600; }
.delta-up::before   { content: '↑'; }
.delta-down::before { content: '↓'; }
.delta-flat::before { content: '·'; }
.delta-new { background: var(--brand-soft); color: var(--brand-hover); }
.delta-new::before { content: '✦'; }

/* Card */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-body { padding: var(--space-6); }
.card-head {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.card-head h3 { font-size: 15px; font-weight: 600; margin: 0; }

/* Stat card */
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: box-shadow var(--transition), border-color var(--transition),
              transform var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.stat-card .label {
  margin: 0 0 var(--space-3) 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.stat-card .value-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
}
.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-card .sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-tertiary);
  min-height: 16px;
}
.stat-card .spark-wrap {
  margin-top: var(--space-4);
  height: 32px;
  position: relative;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg-subtle);
}
.table tr:hover td { background: var(--bg-hover); }
.table tr:last-child td { border-bottom: none; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-secondary);
}
.empty-state .illustration {
  width: 80px; height: 80px;
  margin-bottom: var(--space-4);
  color: var(--text-tertiary);
  opacity: 0.65;
}
.empty-state h4 {
  color: var(--text-primary);
  margin: 0 0 var(--space-2) 0;
  font-size: 16px;
  font-weight: 600;
}
.empty-state p {
  margin: 0;
  max-width: 320px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Skeleton (shimmer) */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 0%,
    var(--bg-hover) 50%,
    var(--bg-subtle) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
}
.skeleton-line { height: 12px; width: 100%; }
.skeleton-line.sm { height: 10px; }
.skeleton-line.lg { height: 18px; }
.skeleton-text-block .skeleton-line + .skeleton-line { margin-top: 8px; }
.skeleton-value { height: 36px; width: 80px; border-radius: var(--radius-sm); }
.skeleton-spark { height: 32px; width: 100%; border-radius: var(--radius-sm); }
.skeleton-avatar { width: 32px; height: 32px; border-radius: var(--radius-full); }

/* Avatar */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}
.avatar-lg { width: 40px; height: 40px; font-size: 16px; }
.avatar-source {
  background: var(--brand-soft);
  color: var(--brand-hover);
}
.avatar-source.voice    { background: #fef3c7; color: #b45309; }
.avatar-source.widget   { background: var(--brand-soft); color: var(--brand-hover); }
.avatar-source.api      { background: #f1f5f9; color: #475569; }
.avatar-source.whatsapp { background: #dcfce7; color: #15803d; }
.avatar-source.telegram { background: #dbeafe; color: #1d4ed8; }
.avatar-source.ig       { background: #fce7f3; color: #be185d; }
.avatar-source svg { width: 16px; height: 16px; }

/* ---- Unified channel icons (bdChannelIcon) -------------------------------
   One SVG glyph per channel, used everywhere a channel is shown. Inside an
   .avatar-source chip the glyph inherits the chip's text color (currentColor),
   so the chip background + glyph already match the palette. The per-channel
   rules below colorize a bare .bd-ch-ico (icon shown WITHOUT a colored chip,
   e.g. inline next to a label) using the canonical brand palette. */
.bd-ch-ico { display: inline-block; vertical-align: middle; }
.bd-ch-ico-whatsapp  { color: #25D366; }
.bd-ch-ico-telegram  { color: #229ED9; }
.bd-ch-ico-widget    { color: var(--brand); }
.bd-ch-ico-voice     { color: #8b5cf6; }
.bd-ch-ico-instagram { color: #E1306C; }
.bd-ch-ico-messenger { color: #0084FF; }
.bd-ch-ico-api       { color: #94a3b8; }
.bd-ch-ico-generic   { color: #94a3b8; }
/* When wrapped in a colored .avatar-source chip, the chip's own color wins so
   the glyph reads against the tinted background (don't double-apply brand). */
.avatar-source .bd-ch-ico { color: currentColor; }
/* Inline icon chips next to filter/label text. */
.chip-chico { display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 5px; margin-right: 6px; flex: none; }
.chip-chico svg { width: 12px; height: 12px; }
.ov-chan-ico, .bd-chanbar-ico { display: inline-flex; align-items: center;
  justify-content: center; width: 18px; height: 18px; border-radius: 5px;
  margin-right: 6px; flex: none; vertical-align: middle; }
.ov-chan-ico svg, .bd-chanbar-ico svg { width: 12px; height: 12px; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 50;
}
.dropdown.is-open .dropdown-menu {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-subtle); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
  pointer-events: none;
  max-width: 360px;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text-primary);
  pointer-events: auto;
  animation: toast-in var(--transition-slow) both;
  max-width: 360px;
}
.toast.is-leaving { animation: toast-out var(--transition) both; }
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.info    { border-left-color: var(--brand); }
.toast .toast-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--danger); }
.toast.info    .toast-icon { color: var(--brand); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* Tall modals need room: drop the 80px top inset to --space-8 (32px) so a
     wizard can use most of the viewport height. */
  padding: var(--space-8) var(--space-4) var(--space-4);
  z-index: 200;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  /* Every modal is now a flex column capped to the viewport with an internal
     scroll, so no wizard can overflow off-screen with its buttons unreachable
     (the owner's "opens too small but crammed" complaint). The body scrolls;
     the head stays pinned. */
  max-height: calc(100vh - var(--space-8) * 2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head { flex: none; }
.modal-body { flex: 1 1 auto; overflow-y: auto; }

/* Global scroll-lock companion: keep a wheel/touch gesture that reaches the
   end of an overlay's own scroll area from chaining through to the page
   behind it. Paired with the JS body{overflow:hidden} lock (see app.js
   initScrollLock) so the popup scrolls without moving the main page. Covers
   every scrollable overlay surface: modals, the conversation/contacts detail
   panel, and the voice transcript drawer + detail body. */
.modal-body,
.detail-body,
.voice-drawer-body,
.vp-detail-body {
  overscroll-behavior: contain;
}


/* ---------------------------------------------------------- 5. BRAND BAR (sticky, both states) */

:root {
  --brandbar-h: 64px;
}

.brand-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--brandbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand-bar-left,
.brand-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}
.brand-bar-right[hidden] { display: none; }

.brand-bar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
}
.brand-bar-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
  flex-shrink: 0;
}
.brand-bar-divider {
  display: inline-block;
  width: 1px;
  height: 22px;
  background: var(--border);
}
.brand-bar-divider[hidden] { display: none; }

.brand-bar-workspace {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
}
.brand-bar-workspace[hidden] { display: none; }
.brand-bar-workspace span:first-child {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-bar-workspace .badge { font-size: 10px; }


/* ---------------------------------------------------------- 6. LOGIN SCREEN */

.login-screen {
  min-height: calc(100vh - var(--brandbar-h));
  padding: 0 var(--space-6) var(--space-12);
  background:
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.06), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(99, 102, 241, 0.08), transparent 45%),
    linear-gradient(135deg, var(--bg-page) 0%, var(--brand-soft) 100%);
}

/* Card is anchored toward the top - NOT vertically centered. On tall
   screens the empty space falls below the card. */
.login-wrap {
  max-width: 440px;
  margin: 0 auto;
  padding-top: 80px;
}

.login-card {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.login-heading {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.login-heading h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin: 0;
}
.login-heading p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Password input wrapper: relative, eye toggle absolutely positioned */
.password-input {
  position: relative;
}
.password-input .input {
  padding-right: 44px;
}
.password-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}
.password-toggle-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-subtle);
}
.password-toggle-btn:focus-visible { box-shadow: var(--shadow-glow); }
.password-toggle-btn svg { width: 16px; height: 16px; }

.login-foot {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}
.login-foot a {
  color: var(--text-tertiary);
  text-decoration: underline;
  text-decoration-color: var(--border);
}
.login-foot a:hover { color: var(--text-secondary); }


/* ---------------------------------------------------------- 7. APP SHELL */

/* The app shell sits BELOW the sticky brand bar. No separate topbar grid
   row anymore - the brand bar absorbed it. */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas: "sidebar main";
  min-height: calc(100vh - var(--brandbar-h));
}

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3);
  position: sticky;
  top: var(--brandbar-h);
  height: calc(100vh - var(--brandbar-h));
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  position: relative;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}
.nav-item.is-active {
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-weight: 600;
}
.nav-item.is-active .nav-icon { color: var(--brand-hover); }
.nav-item.is-disabled {
  color: var(--text-tertiary);
  cursor: not-allowed;
}
.nav-item.is-disabled:hover { background: transparent; }
.nav-icon {
  width: 18px; height: 18px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: color var(--transition);
}
.nav-item:hover .nav-icon { color: var(--text-secondary); }
.nav-label { flex: 1; }
.nav-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  padding: 2px 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.sidebar-foot {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-tertiary);
  padding-left: 12px;
}

/* Sidebar toggle lives in the brand bar (mobile only) */
.sidebar-toggle {
  display: none;
  width: 36px; height: 36px;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
}
.sidebar-toggle:hover { background: var(--bg-subtle); color: var(--text-primary); }
.sidebar-toggle svg { width: 20px; height: 20px; }

/* Main */
.main {
  grid-area: main;
  padding: var(--space-8) var(--space-10);
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  /* Grid children default to min-width:auto, so wide tables inside a page
     used to force .main (and the whole viewport) past the screen width on
     mobile. min-width:0 lets .main shrink and inner overflow-x wraps kick in. */
  min-width: 0;
}
.page { display: none; animation: page-fade var(--transition-slow); }
.page.is-active { display: block; }
@keyframes page-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ---------------------------------------------------------- 7. DASHBOARD */

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}
.hero-text h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.hero-text p {
  margin: 0;
  font-size: 15px;
  color: var(--text-secondary);
}
.hero-actions { display: flex; gap: var(--space-2); }

/* KPI grid. auto-fit (not a hardcoded repeat(4,...)) so a 5th card (W4-d:
   first-contact resolution, capability-gated) lays out cleanly instead of
   orphaning at 25% width in its own row; 4 cards still fill the row evenly
   since minmax(180px,1fr) lets each column stretch to fill remaining space. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-10);
}

/* Section */
.section {
  margin-top: var(--space-10);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}
.section-head h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.section-head a {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Recent conversations list */
.activity-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.activity-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: var(--bg-hover); }
.activity-meta {
  min-width: 0;
}
.activity-preview {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
  margin: 0 0 2px 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.activity-preview.empty {
  color: var(--text-tertiary);
  font-style: italic;
  font-weight: 400;
}
.activity-sub {
  font-size: 12px;
  color: var(--text-tertiary);
}
.activity-time {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}


/* ---------------------------------------------------------- 8. COMING SOON */
.coming-soon {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-16) var(--space-6);
}
.coming-soon-inner {
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}
.coming-soon-icon {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-5);
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.coming-soon-icon svg { width: 28px; height: 28px; }
.coming-soon h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0 0 var(--space-3) 0;
}
.coming-soon p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.coming-soon .badge {
  display: inline-flex;
  margin-bottom: var(--space-5);
}


/* ---------------------------------------------------------- 9. MOBILE / MOTION */

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: var(--space-6) var(--space-5); }
  .hero-text h1 { font-size: 24px; }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  /* On mobile the sidebar becomes an off-canvas drawer that slides in
     from the left and sits underneath the brand bar. */
  .sidebar {
    position: fixed;
    top: var(--brandbar-h);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--brandbar-h));
    z-index: 90;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    box-shadow: var(--shadow-lg);
  }
  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-toggle { display: inline-flex; }
  .nav-item { padding: 12px; min-height: 44px; }
  .brand-bar-workspace .badge { display: none; }
  .brand-bar-workspace span:first-child { max-width: 140px; }
  .brand-bar { padding: 0 var(--space-4); }

  .kpi-grid { grid-template-columns: 1fr; }
  .main { padding: var(--space-5) var(--space-4); }

  /* Backdrop when sidebar is open on mobile */
  .app-shell.sidebar-open::before {
    content: '';
    position: fixed;
    top: var(--brandbar-h); left: 0; right: 0; bottom: 0;
    background: rgb(15 23 42 / 0.4);
    z-index: 80;
    animation: fade-in var(--transition);
  }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
}

@media (max-width: 480px) {
  .login-wrap { padding-top: 40px; }
  .login-card { padding: var(--space-6); }
  .login-heading h1 { font-size: 20px; }
  .hero-text h1 { font-size: 22px; }
  .stat-card { padding: var(--space-5); }
  .stat-card .value { font-size: 26px; }
}

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


/* ============================================================
   10. CONVERSATIONS PAGE (Phase 6c)
   ============================================================ */

.conv-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.conv-head-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}
.conv-head-text h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.conv-head-text p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}
.conv-count {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  align-self: center;
}

/* Filters */
.conv-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.filter-row-custom {
  padding: var(--space-3);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.filter-row-custom .caption {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.chip-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition);
}
.chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.chip.is-active {
  background: var(--brand-soft);
  color: var(--brand-hover);
  border-color: var(--brand);
  font-weight: 600;
}
.chip-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
  flex-shrink: 0;
}

.filter-search {
  position: relative;
  margin-left: auto;
  width: 320px;
  max-width: 100%;
}
.filter-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.filter-search .input {
  padding-left: 36px;
  height: 38px;
  font-size: 13px;
}
.input-sm {
  padding: 6px 10px;
  font-size: 13px;
  height: 34px;
  width: auto;
  min-width: 140px;
}
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* Conversation list (card-wrapped table) */
.conv-list-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.conv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.conv-table thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  text-align: left;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.conv-table tbody tr {
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.conv-table tbody tr:hover {
  background: var(--bg-hover);
}
.conv-table tbody tr:hover .conv-cell-preview {
  color: var(--text-primary);
}
.conv-table tbody td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.conv-table tbody tr:last-child td { border-bottom: none; }

.conv-cell-source {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  white-space: nowrap;
}
.conv-cell-source-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.conv-cell-preview {
  color: var(--text-primary);
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 480px;
}
.conv-cell-preview.is-synthetic {
  color: var(--text-secondary);
  font-style: italic;
  font-weight: 400;
}
.conv-cell-count {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}
.conv-cell-time {
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  font-size: 13px;
  white-space: nowrap;
}

/* Skeleton rows */
.conv-skeleton {
  padding: var(--space-2);
}
.conv-skel-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.conv-skel-row:last-child { border-bottom: none; }

.conv-empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.conv-empty .empty-illu {
  width: 64px; height: 64px;
  margin: 0 auto var(--space-4);
  color: var(--text-tertiary);
  opacity: 0.65;
}
.conv-empty h3 {
  margin: 0 0 var(--space-2) 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.conv-empty p {
  margin: 0 0 var(--space-4) 0;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.conv-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: var(--space-5);
}
/* display:flex above beats the UA stylesheet's [hidden]{display:none};
   restore the hidden contract (same pattern as the modal fixes). */
.conv-more-wrap[hidden] { display: none; }


/* ============================================================
   11. SLIDE-IN DETAIL PANEL (Phase 6c)
   ============================================================ */

.detail-backdrop {
  position: fixed;
  top: var(--brandbar-h);
  left: 0; right: 0; bottom: 0;
  background: rgb(15 23 42 / 0.12);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 0;
  transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.detail-backdrop[hidden] { display: none; }
.detail-backdrop.is-open { opacity: 1; }

.detail-panel {
  position: fixed;
  top: var(--brandbar-h);
  right: 0;
  bottom: 0;
  width: 640px;
  max-width: 100vw;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--border);
  z-index: 160;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.detail-panel[hidden] { display: none; }
.detail-panel.is-open { transform: translateX(0); }

.detail-head {
  padding: var(--space-5) var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 1;
}
.detail-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.detail-head-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}
.detail-head-meta { min-width: 0; }
.detail-head-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-head-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
  max-width: 360px;
}
.detail-head-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: var(--space-3);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
}
.pill strong {
  font-weight: 600;
  color: var(--text-primary);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.detail-skel { display: flex; flex-direction: column; }

.detail-section-head {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 0 0 var(--space-3) 0;
}

/* Voice transcript */
.voice-transcript {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.voice-turn {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: var(--space-3);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.voice-turn:last-child { border-bottom: none; }
.voice-speaker {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.voice-speaker.is-agent { color: var(--brand-hover); }
.voice-speaker.is-caller { color: #b45309; }
.voice-text {
  color: var(--text-primary);
  word-break: break-word;
}

/* Message bubbles */
.msg-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  max-width: 100%;
}
.msg-row.is-user {
  justify-content: flex-end;
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  user-select: none;
}
.msg-avatar.is-user {
  background: var(--brand);
  color: var(--text-inverse);
}
.msg-avatar.is-assistant {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}
.msg-row.is-user .msg-bubble {
  background: var(--brand-soft);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}
.msg-row.is-assistant .msg-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-row.is-system .msg-bubble,
.msg-row.is-tool .msg-bubble {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  font-style: italic;
}
.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: rgba(99, 102, 241, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg-bubble a {
  color: var(--brand-hover);
  text-decoration: underline;
  text-decoration-color: rgba(99, 102, 241, 0.3);
}
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-meta {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 4px;
  white-space: nowrap;
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 6px;
}
.msg-row.is-user .msg-meta { text-align: right; }
.latency-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.detail-foot {
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
}
.detail-foot[hidden] { display: none; }

.detail-error {
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-secondary);
}
.detail-error svg {
  width: 32px; height: 32px;
  margin: 0 auto var(--space-3);
  color: var(--text-tertiary);
}


/* Mobile: slide-up sheet from bottom, full width */
@media (max-width: 768px) {
  .detail-panel {
    width: 100vw;
    top: auto;
    bottom: 0;
    left: 0; right: 0;
    height: 90vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
  }
  .detail-panel.is-open { transform: translateY(0); }
  .detail-backdrop { top: 0; }
  .detail-head-id { max-width: 200px; }

  .filter-search {
    width: 100%;
    margin-left: 0;
  }
  .conv-table thead { display: none; }
  .conv-table, .conv-table tbody, .conv-table tr, .conv-table td { display: block; width: 100%; }
  .conv-table tbody tr {
    padding: var(--space-3) var(--space-4);
    display: grid;
    grid-template-columns: 32px 1fr auto;
    grid-template-areas:
      "src contact time"
      "src meta time";
    gap: 4px var(--space-3);
  }
  .conv-table tbody td { padding: 0; border: none; }
  /* Bulk-select checkboxes are a desktop affordance; hiding them keeps the
     card grid coherent (rows still open the detail panel on tap). */
  .conv-table tbody td.cell-select { display: none; }
  .conv-table tbody td.cell-source { grid-area: src; align-self: center; }
  .conv-table tbody td.cell-contact { grid-area: contact; min-width: 0; }
  .conv-table tbody td.cell-count { grid-area: meta; font-size: 12px; }
  .conv-table tbody td.cell-time { grid-area: time; align-self: center; }
  .conv-table tbody td.cell-started { display: none; }
  .conv-cell-source-label { display: none; }
}


/* ============================================================
   12. ANALYTICS PAGE (Phase 6d)
   ============================================================ */

.an-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.an-head-text h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.an-head-text p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.an-head-text p strong {
  color: var(--text-primary);
  font-weight: 600;
}
.an-head-actions { display: flex; gap: var(--space-2); align-items: center; }

.an-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

/* KPI strip */
.an-kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.an-kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  transition: box-shadow var(--transition), border-color var(--transition),
              transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 132px;
}
.an-kpi:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.an-kpi .label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.an-kpi .value-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.an-kpi .value {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.an-kpi .sub {
  font-size: 12px;
  color: var(--text-tertiary);
  min-height: 16px;
}
.an-kpi .sub strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* Chart grid: 2 columns top, full-width bottom */
.an-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.an-chart-grid .chart-card-wide { grid-column: 1 / -1; }

.an-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
}

/* Generic chart card */
.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}
.chart-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 0 0 var(--space-4) 0;
}
.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 280px;
}

/* Donut + legend */
.donut-wrap {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-5);
  align-items: center;
}
.donut-canvas {
  width: 200px;
  height: 200px;
  position: relative;
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.donut-legend-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-primary);
  cursor: default;
  border-bottom: 1px dashed transparent;
  transition: border-color var(--transition), color var(--transition);
}
.donut-legend-item:hover { border-bottom-color: var(--border); }
.donut-legend-item.is-zero { color: var(--text-tertiary); }
.donut-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.donut-legend-name {
  font-weight: 500;
}
.donut-legend-value {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  font-size: 12px;
}

.donut-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: var(--space-6);
}

/* Top conversations card list (compact variant of Conversations rows) */
#an-top-conv {
  display: flex;
  flex-direction: column;
}
.an-top-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: var(--space-3);
  padding: 10px 0;
  align-items: center;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.an-top-row:hover { background: var(--bg-hover); margin: 0 calc(-1 * var(--space-3)); padding-left: var(--space-3); padding-right: var(--space-3); border-radius: var(--radius-sm); }
.an-top-row:last-child { border-bottom: none; }
.an-top-meta { min-width: 0; }
.an-top-preview {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  margin: 0 0 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.an-top-preview.is-synthetic {
  color: var(--text-secondary);
  font-style: italic;
  font-weight: 400;
}
.an-top-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.an-top-cost {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
.an-top-skel { display: flex; flex-direction: column; gap: var(--space-3); }
.an-top-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: var(--space-6);
}

/* Responsive */
@media (max-width: 1100px) {
  .an-kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .an-chart-grid { grid-template-columns: 1fr; }
  .an-bottom-grid { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut-legend { width: 100%; max-width: 360px; }
}
@media (max-width: 640px) {
  .an-kpi-strip { grid-template-columns: 1fr; }
  .chart-canvas-wrap { height: 220px; }
}


/* ============================================================
   13. KNOWLEDGE BASE PAGE (Phase 6e)
   ============================================================ */

.kb-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.kb-head-text h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.kb-head-text p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.kb-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: var(--space-5);
  align-items: flex-start;
}

.kb-upload-card,
.kb-docs-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: var(--space-6);
}
.kb-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-4) 0;
  letter-spacing: -0.005em;
}
.kb-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 var(--space-4) 0;
}
.kb-card-head .kb-card-title { margin: 0; }

.kb-upload-tabs {
  margin-bottom: var(--space-4);
}
.kb-upload-pane { display: none; }
.kb-upload-pane.is-active { display: block; animation: page-fade var(--transition-slow); }

.kb-text-area {
  display: block;
  width: 100%;
  min-height: 140px;
  margin-top: var(--space-3);
  padding: var(--space-3);
  font-family: inherit;
  font-size: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-primary);
  resize: vertical;
  box-sizing: border-box;
}
.kb-text-area:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-faint, rgba(99,102,241,.12));
}

.kb-help {
  margin: var(--space-2) 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.kb-help strong { color: var(--text-secondary); font-weight: 600; }

/* Data export modal: a column of full-width download buttons. */
.export-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.export-list .btn { justify-content: flex-start; width: 100%; }

/* Subtle source tag on a contact row (manual / imported contacts). */
.bd-contact-srctag {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: rgba(127, 127, 127, .14);
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* Drag-and-drop zone (file tab) */
.kb-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  cursor: pointer;
  text-align: center;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}
.kb-drop:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
}
.kb-drop.is-dragover {
  background: var(--brand-soft);
  border-color: var(--brand);
  border-style: solid;
}
.kb-drop.has-file {
  background: var(--brand-soft);
  border-color: var(--brand);
}
.kb-drop-icon {
  width: 32px; height: 32px;
  color: var(--brand);
  margin-bottom: 4px;
}
.kb-drop-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
  max-width: 100%;
}
.kb-drop-link {
  color: var(--brand-hover);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(99, 102, 241, 0.3);
}
.kb-drop-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Documents list */
.kb-docs-wrap {
  margin: 0 calc(-1 * var(--space-6));
  border-top: 1px solid var(--border);
}
.kb-docs-list {
  display: flex;
  flex-direction: column;
}
.kb-doc-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto auto auto;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
/* Edit (conditional) + delete live in one cell so the grid track count is
   stable whether or not the doc is editable. */
.kb-doc-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: end;
}
.kb-doc-row:last-child { border-bottom: none; }
.kb-doc-row:hover { background: var(--bg-hover); }

.kb-doc-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand-hover);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.kb-doc-icon.kb-fmt-csv      { background: #dcfce7; color: #15803d; }
.kb-doc-icon.kb-fmt-xlsx     { background: #dcfce7; color: #15803d; }
.kb-doc-icon.kb-fmt-pdf      { background: #fee2e2; color: #b91c1c; }
.kb-doc-icon.kb-fmt-url      { background: #dbeafe; color: #1d4ed8; }
.kb-doc-icon.kb-fmt-gdoc     { background: #dbeafe; color: #1d4ed8; }
.kb-doc-icon.kb-fmt-json     { background: #fef3c7; color: #b45309; }
.kb-doc-icon.kb-fmt-text     { background: var(--brand-soft); color: var(--brand-hover); }
.kb-doc-icon.kb-fmt-other    { background: var(--bg-subtle); color: var(--text-secondary); }

.kb-doc-meta { min-width: 0; }
.kb-doc-name {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-doc-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.kb-fmt-pill {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}

.kb-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}
.kb-status.is-completed { background: var(--success-soft); color: #047857; }
.kb-status.is-error     { background: var(--danger-soft);  color: #b91c1c; }
.kb-status.is-indexing  { background: var(--warning-soft); color: #b45309; }
.kb-status.is-waiting   { background: var(--bg-subtle);    color: var(--text-secondary); }
.kb-status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.kb-status.is-indexing .kb-status-dot {
  animation: kb-pulse 1.2s ease-in-out infinite;
}
@keyframes kb-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.kb-doc-size {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kb-doc-delete {
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.kb-doc-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.kb-doc-delete svg { width: 16px; height: 16px; }
.kb-doc-delete:disabled { opacity: 0.4; cursor: wait; }

.kb-skel { padding: var(--space-3) 0; }
.kb-skel-row {
  display: grid;
  grid-template-columns: 36px 1fr 60px 80px;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.kb-skel-row:last-child { border-bottom: none; }

.kb-empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.kb-empty .empty-illu {
  width: 64px; height: 64px;
  margin: 0 auto var(--space-4);
  color: var(--text-tertiary);
  opacity: 0.65;
}
.kb-empty h3 {
  margin: 0 0 var(--space-2) 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.kb-empty p {
  margin: 0 0 var(--space-4) 0;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* Drag overlay (page-wide, only when KB tab is active) */
.kb-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(99, 102, 241, 0.18);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: fade-in 120ms ease-out;
}
.kb-drop-overlay[hidden] { display: none; }
.kb-drop-overlay-inner {
  background: var(--bg-elevated);
  border: 2px dashed var(--brand);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--brand-hover);
  font-size: 18px;
  font-weight: 600;
}
.kb-drop-overlay svg {
  width: 40px; height: 40px;
  color: var(--brand);
}

@media (max-width: 900px) {
  .kb-layout {
    grid-template-columns: 1fr;
  }
  .kb-doc-row {
    grid-template-columns: 36px 1fr auto auto;
  }
  .kb-doc-row .kb-fmt-pill,
  .kb-doc-row .kb-doc-size { display: none; }
  .kb-doc-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}


/* ============================================================
   14. DARK MODE (Phase 6f)
   ============================================================ */

/* Smooth theme transition (kept short so it doesn't drag during route
   changes). Theme attribute is set before first paint by an inline
   script in <head>; this block only handles in-app toggling. */
html {
  transition: background-color 200ms cubic-bezier(0.4, 0, 0.2, 1),
              color 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
body,
.brand-bar,
.sidebar,
.card, .stat-card, .activity-list, .chart-card, .conv-list-wrap,
.kb-upload-card, .kb-docs-card, .an-kpi, .settings-card,
.modal, .dropdown-menu, .toast, .detail-panel, .cmdk-wrap,
.input, .chip {
  transition: background-color 200ms cubic-bezier(0.4, 0, 0.2, 1),
              border-color 200ms cubic-bezier(0.4, 0, 0.2, 1),
              color 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Token overrides - the inline boot script applies the attribute to
   <html> before first paint, so there's no FOUC. */
html[data-theme="dark"] {
  --bg-page: #0f1419;
  --bg-elevated: #1a1f2e;
  --bg-subtle: #232938;
  --bg-hover: #2a3142;
  --text-primary: #e6e8eb;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --text-inverse: #0f172a;
  --border: #2a3142;
  --border-strong: #3a4358;
  --brand: #818cf8;          /* slightly brighter for contrast on dark */
  --brand-hover: #a5b4fc;
  --brand-soft: #1e1b4b;
  --success: #34d399;
  --success-soft: #064e3b;
  --warning: #fbbf24;
  --warning-soft: #451a03;
  --danger: #f87171;
  --danger-soft: #450a0a;

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --shadow-glow: 0 0 0 4px rgb(129 140 248 / 0.18);

  color-scheme: dark;
}

/* Brand bar uses a translucent fill - needs theme-aware background */
html[data-theme="dark"] .brand-bar {
  background: rgba(15, 20, 25, 0.85);
}

/* Login screen background - radial gradients tuned for dark */
html[data-theme="dark"] .login-screen {
  background:
    radial-gradient(circle at 0% 0%, rgba(129, 140, 248, 0.08), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(129, 140, 248, 0.10), transparent 45%),
    linear-gradient(135deg, var(--bg-page) 0%, #1a1f3a 100%);
}

/* Skeletons shimmer over darker bg */
html[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg,
    var(--bg-subtle) 0%, var(--bg-hover) 50%, var(--bg-subtle) 100%);
  background-size: 200% 100%;
}

/* Modal backdrop slightly darker */
html[data-theme="dark"] .modal-backdrop {
  background: rgb(0 0 0 / 0.65);
}

/* Detail panel backdrop in dark mode */
html[data-theme="dark"] .detail-backdrop {
  background: rgb(0 0 0 / 0.3);
}

/* Chart card grid lines + tick labels need theme-aware overrides - see
   makeLineChart in app.js which reads --text-tertiary at render time. */


/* ============================================================
   15. SETTINGS PAGE (Phase 6f)
   ============================================================ */

.settings-head { margin-bottom: var(--space-6); }
.settings-head h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.settings-head p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
}
.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}
.settings-card.is-wide { grid-column: 1 / -1; }
.settings-card h3 {
  margin: 0 0 var(--space-4) 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Phase 13a FR-013: getting-started checklist that sits between hero and
   KPI grid on a brand-new tenant. Hidden by default in HTML; JS un-hides
   only when activity is zero AND at least one step is pending. */
.onboarding-checklist {
  margin: 0 0 var(--space-6) 0;
  padding: var(--space-5) var(--space-6);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(168, 85, 247, 0.06));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-lg);
}
.onboarding-checklist .oc-head { margin-bottom: var(--space-4); }
.onboarding-checklist .oc-head h2 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
}
.onboarding-checklist .oc-head p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.oc-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.oc-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
}
.oc-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--text-tertiary);
  background: transparent;
}
.oc-item.is-done .oc-dot {
  background: #10b981;
  border-color: #10b981;
}
.oc-text { display: flex; flex-direction: column; gap: 2px; }
.oc-text strong { font-size: 14px; font-weight: 600; }
.oc-text span { font-size: 12px; color: var(--text-secondary); }
.oc-item.is-done .oc-text strong { text-decoration: line-through; opacity: 0.65; }

/* Phase 13b FR-013-ext: dormant-tenant placeholder link under the
   checklist. Only shown when tenant age ≥ 7d AND activity is zero. */
.oc-foot {
  margin-top: var(--space-3);
  text-align: right;
}
.oc-foot a {
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
}
.oc-foot a:hover { color: var(--brand-strong, #6366f1); }

/* Phase 13a FR-006: yellow inline warning, scoped to settings cards so it
   doesn't compete with .form-error (red) elsewhere. */
.settings-warning {
  margin: 0 0 var(--space-4) 0;
  padding: 12px 14px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid #f4c772;
  background: #fff7e0;
  color: #6b4a00;
  font-size: 13px;
  line-height: 1.45;
}
.settings-warning code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 4px;
  border-radius: 3px;
}
[data-theme="dark"] .settings-warning {
  background: #3a2c00;
  border-color: #7a5c10;
  color: #ffd980;
}
[data-theme="dark"] .settings-warning code {
  background: rgba(255, 255, 255, 0.08);
}

.settings-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-4);
}
.settings-field:last-child { border-bottom: none; }
.settings-field .key {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.settings-field .val {
  font-size: 14px;
  color: var(--text-primary);
  text-align: right;
  word-break: break-word;
  max-width: 60%;
}
.settings-field .val.mono { font-family: var(--font-mono); font-size: 12px; }
/* Long mono values (webhook URLs in Connected tools) on phones: break
   anywhere and read from the start instead of pushing the card wide. */
@media (max-width: 768px) {
  [data-page="settings"] .settings-field .val.mono {
    word-break: break-all;
    text-align: start;
  }
}

.settings-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.settings-chips .chip-static {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-hover);
}

.channel-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.channel-row:last-child { border-bottom: none; }
.channel-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.channel-name {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}
.channel-sub {
  font-size: 11px;
  color: var(--text-tertiary);
}
.channel-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}
.channel-status.is-connected { background: var(--success-soft); color: #047857; }
.channel-status.is-coming-soon { background: var(--warning-soft); color: #b45309; }
html[data-theme="dark"] .channel-status.is-connected { color: #6ee7b7; }
html[data-theme="dark"] .channel-status.is-coming-soon { color: #fbbf24; }

/* Appearance segmented control */
.segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  background: transparent;
  border: none;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button.is-active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}
.segmented button svg { width: 14px; height: 14px; }

/* AI Model card */
.settings-ai {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}
.ai-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-icon svg { width: 20px; height: 20px; }
.ai-meta { flex: 1; }
.ai-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.ai-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.ai-link {
  display: inline-block;
  margin-top: var(--space-3);
  font-size: 13px;
  color: var(--brand);
  font-weight: 500;
}

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


/* ============================================================
   16. MODAL EXTENSIONS (Phase 6f)
   ============================================================ */

.modal.modal-sm { max-width: 420px; }
.modal.modal-md { max-width: 520px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-body {
  padding: var(--space-5) var(--space-6) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.confirm-backdrop { z-index: 300; }
.confirm-title {
  margin: 0 0 var(--space-2) 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.confirm-body {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
}


/* ============================================================
   17. CMD+K COMMAND PALETTE (Phase 6f)
   ============================================================ */

.cmdk-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 400;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  animation: fade-in var(--transition);
}
.cmdk-backdrop[hidden] { display: none; }
html[data-theme="dark"] .cmdk-backdrop { background: rgb(0 0 0 / 0.6); }

.cmdk-wrap {
  width: 100%;
  max-width: 600px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

.cmdk-input-wrap {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.cmdk-icon {
  width: 18px; height: 18px;
  color: var(--text-tertiary);
}
#cmdk-input {
  background: transparent;
  border: none;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  font-family: var(--font-sans);
}
#cmdk-input::placeholder { color: var(--text-tertiary); }

.cmdk-kbd {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-tertiary);
  background: var(--bg-subtle);
}

.cmdk-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}
.cmdk-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-5);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 14px;
  color: var(--text-primary);
  transition: background var(--transition);
}
.cmdk-item:hover, .cmdk-item.is-active {
  background: var(--brand-soft);
  color: var(--brand-hover);
}
.cmdk-item-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cmdk-item-icon svg { width: 14px; height: 14px; }
.cmdk-item.is-active .cmdk-item-icon {
  background: var(--brand);
  color: var(--text-inverse);
}
.cmdk-item-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cmdk-section {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 8px var(--space-5) 4px;
}
.cmdk-empty {
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

.cmdk-foot {
  display: flex;
  gap: var(--space-4);
  padding: 8px var(--space-5);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-subtle);
}
.cmdk-foot kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 3px;
}


/* ============================================================
   18. COPY-ID BUTTON (Phase 6f)
   ============================================================ */

.detail-head-id-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.detail-head-id-row .detail-head-id { flex: 1; min-width: 0; }

.copy-id-btn {
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.copy-id-btn:hover { background: var(--bg-subtle); color: var(--text-secondary); }
.copy-id-btn svg { width: 13px; height: 13px; }
.copy-id-btn.is-copied { color: var(--success); }
.copy-id-btn.is-copied:hover { background: var(--success-soft); }


/* ============================================================
   19. KEYBOARD NAV (Phase 6f) - Conversations table
   ============================================================ */

.conv-table tbody tr.is-kbd-selected {
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 0 var(--brand);
}
.conv-table tbody tr.is-kbd-selected td {
  color: var(--text-primary);
}
.conv-table tbody tr.is-kbd-selected .conv-cell-preview { color: var(--text-primary); }


/* ============================================================
   20. MARKDOWN INSIDE .msg-bubble (Phase 6f)
   ============================================================ */

.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 8px; }
.msg-bubble ul,
.msg-bubble ol {
  margin: 6px 0;
  padding-left: 22px;
}
.msg-bubble li { margin: 2px 0; }
.msg-bubble li::marker { color: var(--text-tertiary); }
.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3,
.msg-bubble h4 {
  margin: 10px 0 6px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  letter-spacing: -0.005em;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 15px; }
.msg-bubble h4 { font-size: 14px; }
.msg-bubble pre {
  margin: 8px 0;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}
.msg-bubble pre code {
  background: transparent;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  border-radius: 0;
}
.msg-bubble blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-secondary);
  font-style: italic;
}
.msg-bubble hr {
  margin: 10px 0;
  border: none;
  border-top: 1px solid var(--border);
}
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
}
.msg-bubble th, .msg-bubble td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   21. WHATSAPP CONNECT WIZARD (Phase 7a-2)
   ============================================================ */

.wa-backdrop .wa-modal {
  /* Step 1 alone is a 6-field credentials form; give it room so the fields +
     help text aren't crammed into a narrow column. The global modal
     max-height rule scrolls the body if it's still tall. */
  max-width: 680px;
}

/* Brand-coloured icon strip in modal head */
.wa-head { align-items: flex-start; }
.wa-head-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wa-brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #25d366; /* WhatsApp green */
  color: #fff;
  box-shadow: 0 4px 12px -2px rgba(37, 211, 102, .35);
}
.wa-brand-mark svg { width: 22px; height: 22px; }
.wa-head-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Step progress indicator */
.wa-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 18px 22px 14px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}
.wa-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  position: relative;
  font-size: 12.5px;
  color: var(--text-tertiary);
  transition: color .2s ease;
}
.wa-step + .wa-step::before {
  content: "";
  position: absolute;
  left: -8px;
  right: calc(100% - 14px);
  top: 14px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.wa-step:last-child { flex: 0 0 auto; }
.wa-step-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all .2s ease;
}
.wa-step-num { line-height: 1; }
.wa-step.is-active {
  color: var(--text-primary);
  font-weight: 600;
}
.wa-step.is-active .wa-step-dot {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.wa-step.is-complete .wa-step-dot {
  background: #25d366;
  color: #fff;
  border-color: #25d366;
}
.wa-step.is-complete .wa-step-num { display: none; }
.wa-step.is-complete .wa-step-dot::after {
  content: "✓";
  font-size: 14px;
  font-weight: 700;
}
.wa-step.is-complete + .wa-step::before { background: #25d366; }
.wa-step.is-complete { color: var(--text-secondary); }

/* Step panes (vertically scrollable when long) */
.wa-pane {
  padding: 18px 22px 20px;
  max-height: calc(80vh - 180px);
  overflow-y: auto;
}
.wa-pane[hidden] { display: none; }
.wa-intro {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.wa-intro-tight { margin: 14px 0 12px; }
.wa-intro a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}
.wa-intro a:hover { text-decoration: underline; }
.wa-intro code,
.wa-help code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Form fields */
.wa-form { display: flex; flex-direction: column; gap: 14px; }
.wa-field { display: flex; flex-direction: column; gap: 6px; }
.wa-field .label { font-size: 12.5px; font-weight: 600; }
.wa-help {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.wa-input-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}
.wa-input-wrap .input { padding-right: 38px; flex: 1; }
.wa-mask {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
}
.wa-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wa-eye:hover { color: var(--text-primary); background: var(--bg-subtle); }
.wa-eye::before {
  content: "";
  display: block;
  width: 18px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 0 75% 0 75%;
  position: relative;
}
.wa-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.wa-eye[data-on="1"]::before { border-style: dashed; opacity: .5; }
.wa-eye[data-on="1"]::after  { opacity: .5; }

/* Copy boxes (step 2) */
.wa-copy-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.wa-copy-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.wa-copy-box {
  display: flex;
  align-items: stretch;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.wa-copy-value {
  flex: 1;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-primary);
  background: transparent;
  word-break: break-all;
  display: flex;
  align-items: center;
  min-height: 38px;
}
.wa-copy-btn {
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 0 12px;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.wa-copy-btn svg { width: 14px; height: 14px; }
.wa-copy-btn:hover { color: var(--brand); background: var(--bg-elevated); }
.wa-copy-btn.is-copied {
  color: #25d366;
}
.wa-copy-btn.is-copied .wa-copy-label-text::before {
  content: "✓ ";
}

/* Polling status card */
.wa-status-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 6px;
}
.wa-status-card.is-warning {
  background: rgba(245, 158, 11, .08);
  border-color: rgba(245, 158, 11, .35);
}
.wa-poll-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.wa-poll-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  line-height: 1.45;
}
.wa-poll-spinner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.wa-poll-spinner span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: wa-bounce 1.2s infinite ease-in-out;
}
.wa-poll-spinner span:nth-child(2) { animation-delay: .15s; }
.wa-poll-spinner span:nth-child(3) { animation-delay: .3s; }
@keyframes wa-bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40%           { transform: scale(1);  opacity: 1;  }
}

.wa-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  padding: 6px 4px;
  font-size: 13px;
  cursor: pointer;
}
.btn-link:hover { color: var(--brand); }

/* Success pane */
.wa-pane-success {
  text-align: center;
  padding: 28px 32px 22px;
}
.wa-check-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}
.wa-check {
  width: 72px;
  height: 72px;
  color: #25d366;
}
.wa-check-circle {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: wa-check-circle .55s ease-out forwards;
}
.wa-check-tick {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: wa-check-tick .35s ease-out .45s forwards;
}
@keyframes wa-check-circle {
  to { stroke-dashoffset: 0; }
}
@keyframes wa-check-tick {
  to { stroke-dashoffset: 0; }
}
.wa-success-title {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.wa-success-body {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.wa-success-body strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
}
.wa-success-hint {
  display: inline-block;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  max-width: 380px;
  line-height: 1.45;
}
.wa-actions-success {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.wa-actions-right {
  display: flex;
  gap: 8px;
}
.wa-disconnect-link {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 12.5px;
  padding: 4px 6px;
}
.wa-disconnect-link:hover { color: var(--danger); }

/* -- Channels card: WhatsApp state badges (Phase 7a-2) -- */
.channel-row[data-channel="whatsapp"] .channel-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wa-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.wa-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.wa-badge-connected {
  color: #15803d;
  background: rgba(34, 197, 94, .12);
}
.wa-badge-connected::before { background: #22c55e; }
.wa-badge-pending {
  color: #b45309;
  background: rgba(245, 158, 11, .14);
}
.wa-badge-pending::before {
  background: #f59e0b;
  animation: wa-bounce 1.4s infinite ease-in-out;
}
.wa-channel-meta {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  font-family: var(--font-mono);
}

/* Dark-mode tweaks */
html[data-theme="dark"] .wa-badge-connected {
  color: #4ade80;
  background: rgba(34, 197, 94, .15);
}
html[data-theme="dark"] .wa-badge-pending {
  color: #fbbf24;
  background: rgba(245, 158, 11, .18);
}
html[data-theme="dark"] .wa-status-card.is-warning {
  background: rgba(245, 158, 11, .12);
}

/* =================================================================
   Section 22 - WhatsApp Cloud API registration (Phase 7c-1)
   ================================================================= */

/* Secondary help line under the PIN field */
.wa-help-secondary {
  margin-top: 4px;
  color: var(--text-tertiary);
  font-size: 12px;
  font-style: italic;
}

/* Registration pill at top of step 2 */
.wa-reg-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}
.wa-reg-pill-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}
.wa-reg-pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}
.wa-reg-pill[data-status="connected"] {
  background: rgba(34, 197, 94, .08);
  border-color: rgba(34, 197, 94, .35);
}
.wa-reg-pill[data-status="connected"] .wa-reg-pill-dot { background: #22c55e; }
.wa-reg-pill[data-status="connected"] .wa-reg-pill-label { color: #15803d; }
.wa-reg-pill[data-status="offline"] {
  background: rgba(245, 158, 11, .10);
  border-color: rgba(245, 158, 11, .35);
}
.wa-reg-pill[data-status="offline"] .wa-reg-pill-dot {
  background: #f59e0b;
  animation: wa-bounce 1.4s infinite ease-in-out;
}
.wa-reg-pill[data-status="offline"] .wa-reg-pill-label { color: #b45309; }

html[data-theme="dark"] .wa-reg-pill[data-status="connected"] .wa-reg-pill-label { color: #4ade80; }
html[data-theme="dark"] .wa-reg-pill[data-status="offline"] .wa-reg-pill-label { color: #fbbf24; }

/* Inline register-now form */
.wa-reg-form {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}
.wa-reg-form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.wa-reg-form-row .input {
  flex: 0 0 140px;
  font-family: var(--font-mono);
  letter-spacing: 0.15em;
  text-align: center;
}

/* Success-step status badge (next to phone number) */
.wa-phone-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  vertical-align: middle;
}
.wa-phone-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.wa-phone-badge[data-status="connected"] {
  color: #15803d;
  background: rgba(34, 197, 94, .12);
}
.wa-phone-badge[data-status="connected"]::before { background: #22c55e; }
.wa-phone-badge[data-status="offline"] {
  color: #b45309;
  background: rgba(245, 158, 11, .14);
}
.wa-phone-badge[data-status="offline"]::before { background: #f59e0b; }
.wa-phone-badge[data-status="unknown"] {
  color: var(--text-tertiary);
  background: var(--bg-subtle);
}
.wa-phone-badge[data-status="unknown"]::before { background: #94a3b8; }

html[data-theme="dark"] .wa-phone-badge[data-status="connected"] {
  color: #4ade80;
  background: rgba(34, 197, 94, .15);
}
html[data-theme="dark"] .wa-phone-badge[data-status="offline"] {
  color: #fbbf24;
  background: rgba(245, 158, 11, .18);
}

/* Troubleshooting accordion */
.wa-trouble {
  margin-top: 20px;
  border-top: 1px dashed var(--border-color);
  padding-top: 14px;
  text-align: left;
}
.wa-trouble > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  list-style: none;
  user-select: none;
  padding: 4px 0;
}
.wa-trouble > summary::-webkit-details-marker { display: none; }
.wa-trouble > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform .15s ease;
}
.wa-trouble[open] > summary::before { transform: rotate(90deg); }
.wa-trouble-list {
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.wa-trouble-list li { margin: 6px 0; }
.wa-trouble-list code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Channels card - cloud-api sub-line under WhatsApp connected state */
.wa-cloud-substate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.wa-cloud-substate::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
}
.wa-cloud-substate[data-status="connected"]::before { background: #22c55e; }
.wa-cloud-substate[data-status="connected"] { color: #15803d; }
.wa-cloud-substate[data-status="offline"]::before { background: #f59e0b; }
.wa-cloud-substate[data-status="offline"] { color: #b45309; }
.wa-cloud-substate-link {
  margin-left: 4px;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
}

html[data-theme="dark"] .wa-cloud-substate[data-status="connected"] { color: #4ade80; }
html[data-theme="dark"] .wa-cloud-substate[data-status="offline"]   { color: #fbbf24; }

/* ============================================================
   22. TELEGRAM CONNECT WIZARD (Phase 8a-2)
   ============================================================ */

.tg-backdrop .tg-modal { max-width: 520px; }

.tg-head { align-items: flex-start; }
.tg-head-title { display: flex; align-items: center; gap: 12px; }
.tg-brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(180deg, #2aabee 0%, #229ed9 100%);
  color: #fff;
  box-shadow: 0 4px 12px -2px rgba(34, 158, 217, .35);
}
.tg-brand-mark svg { width: 22px; height: 22px; }
.tg-head-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Steps */
.tg-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 18px 22px 14px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}
.tg-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  position: relative;
  font-size: 12.5px;
  color: var(--text-tertiary);
  transition: color .2s ease;
}
.tg-step + .tg-step::before {
  content: "";
  position: absolute;
  left: -8px;
  right: calc(100% - 14px);
  top: 14px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.tg-step:last-child { flex: 0 0 auto; }
.tg-step-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all .2s ease;
}
.tg-step-num { line-height: 1; }
.tg-step.is-active { color: var(--text-primary); font-weight: 600; }
.tg-step.is-active .tg-step-dot {
  background: #229ed9;
  color: #fff;
  border-color: #229ed9;
  box-shadow: 0 0 0 4px rgba(34, 158, 217, .18);
}
.tg-step.is-complete .tg-step-dot {
  background: #229ed9;
  color: #fff;
  border-color: #229ed9;
}
.tg-step.is-complete .tg-step-num { display: none; }
.tg-step.is-complete .tg-step-dot::after { content: "✓"; font-size: 14px; font-weight: 700; }
.tg-step.is-complete + .tg-step::before { background: #229ed9; }
.tg-step.is-complete { color: var(--text-secondary); }

/* Panes */
.tg-pane {
  padding: 18px 22px 20px;
  max-height: calc(80vh - 180px);
  overflow-y: auto;
}
.tg-pane[hidden] { display: none; }
.tg-intro {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.tg-intro code,
.tg-help code,
.tg-steplist code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Numbered BotFather instructions */
.tg-steplist {
  margin: 0 0 18px;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.tg-steplist li { margin: 4px 0; }
.tg-steplist li strong { color: var(--text-primary); }

/* Form */
.tg-form { display: flex; flex-direction: column; gap: 14px; }
.tg-field { display: flex; flex-direction: column; gap: 6px; }
.tg-field .label { font-size: 12.5px; font-weight: 600; }
.tg-help {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.tg-input-wrap { position: relative; display: flex; align-items: stretch; }
.tg-input-wrap .input { padding-right: 38px; flex: 1; }
.tg-mask { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em; }
.tg-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tg-eye:hover { color: var(--text-primary); background: var(--bg-subtle); }
.tg-eye::before {
  content: "";
  display: block;
  width: 18px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 0 75% 0 75%;
  position: relative;
}
.tg-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.tg-eye[data-on="1"]::before { border-style: dashed; opacity: .5; }
.tg-eye[data-on="1"]::after  { opacity: .5; }

/* Success pane */
.tg-pane-success { text-align: center; padding: 28px 32px 22px; }
.tg-check-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.tg-check { width: 72px; height: 72px; color: #229ed9; }
.tg-check-circle {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: tg-check-circle .55s ease-out forwards;
}
.tg-check-tick {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: tg-check-tick .35s ease-out .45s forwards;
}
@keyframes tg-check-circle { to { stroke-dashoffset: 0; } }
@keyframes tg-check-tick   { to { stroke-dashoffset: 0; } }
.tg-success-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.tg-bot-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 0 0 16px;
  text-align: left;
}
.tg-bot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
  font-size: 13px;
}
.tg-bot-row + .tg-bot-row {
  border-top: 1px dashed var(--border);
}
.tg-bot-label {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
}
.tg-bot-username {
  color: #229ed9;
  font-family: var(--font-mono);
  font-weight: 600;
  text-decoration: none;
}
.tg-bot-username:hover { text-decoration: underline; }
.tg-bot-firstname { color: var(--text-primary); font-weight: 500; }
.tg-bot-meta { color: var(--text-secondary); font-size: 12.5px; }

.tg-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #229ed9;
  border-color: #229ed9;
  color: #fff;
  text-decoration: none;
  margin-bottom: 14px;
}
.tg-open-btn:hover {
  background: #1e8ec3;
  border-color: #1e8ec3;
  color: #fff;
}
.tg-open-icon { width: 14px; height: 14px; }

.tg-success-hint {
  display: inline-block;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  max-width: 380px;
  line-height: 1.45;
}

.tg-pending-card {
  background: rgba(245, 158, 11, .08);
  border: 1px solid rgba(245, 158, 11, .35);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  color: #92400e;
  margin: 0 0 16px;
  text-align: left;
}
html[data-theme="dark"] .tg-pending-card { color: #fcd34d; }

.tg-actions-success {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.tg-actions-right { display: flex; gap: 8px; }
.tg-disconnect-link {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 12.5px;
  padding: 4px 6px;
}
.tg-disconnect-link:hover { color: var(--danger); }

/* -- Channels card: Telegram state badges (Phase 8a-2) -- */
.channel-row[data-channel="telegram"] .channel-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tg-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.tg-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.tg-badge-connected {
  color: #075985;
  background: rgba(34, 158, 217, .14);
}
.tg-badge-connected::before { background: #229ed9; }
.tg-badge-pending {
  color: #b45309;
  background: rgba(245, 158, 11, .14);
}
.tg-badge-pending::before { background: #f59e0b; }
html[data-theme="dark"] .tg-badge-connected { color: #7dd3fc; }
html[data-theme="dark"] .tg-badge-pending   { color: #fbbf24; }

.tg-channel-meta {
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

/* ============================================================
   23. INSTAGRAM CONNECT WIZARD (Phase 8b-2)
   ============================================================ */

.ig-backdrop .ig-modal { max-width: 560px; }

.ig-head { align-items: flex-start; }
.ig-head-title { display: flex; align-items: center; gap: 12px; }
.ig-brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
  color: #fff;
  box-shadow: 0 4px 12px -2px rgba(253, 29, 29, .35);
}
.ig-brand-mark svg { width: 22px; height: 22px; }
.ig-head-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Step indicator */
.ig-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 18px 22px 14px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}
.ig-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  position: relative;
  font-size: 12.5px;
  color: var(--text-tertiary);
  transition: color .2s ease;
}
.ig-step + .ig-step::before {
  content: "";
  position: absolute;
  left: -8px;
  right: calc(100% - 14px);
  top: 14px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.ig-step:last-child { flex: 0 0 auto; }
.ig-step-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all .2s ease;
}
.ig-step-num { line-height: 1; }
.ig-step.is-active { color: var(--text-primary); font-weight: 600; }
.ig-step.is-active .ig-step-dot {
  background: #d6249f;
  color: #fff;
  border-color: #d6249f;
  box-shadow: 0 0 0 4px rgba(214, 36, 159, .18);
}
.ig-step.is-complete .ig-step-dot {
  background: #d6249f;
  color: #fff;
  border-color: #d6249f;
}
.ig-step.is-complete .ig-step-num { display: none; }
.ig-step.is-complete .ig-step-dot::after { content: "✓"; font-size: 14px; font-weight: 700; }
.ig-step.is-complete + .ig-step::before { background: #d6249f; }
.ig-step.is-complete { color: var(--text-secondary); }

/* Panes */
.ig-pane {
  padding: 18px 22px 20px;
  max-height: calc(80vh - 180px);
  overflow-y: auto;
}
.ig-pane[hidden] { display: none; }
.ig-intro {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.ig-intro-tight { margin: 0 0 10px; }
.ig-intro a {
  color: #d6249f;
  text-decoration: none;
  font-weight: 500;
}
.ig-intro a:hover { text-decoration: underline; }
.ig-intro code,
.ig-help code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Generate-webhook card (step 1, initial) */
.ig-generate-card {
  background: var(--bg-subtle);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin: 0 0 18px;
  text-align: center;
}
.ig-generate-text {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Generated webhook card */
.ig-webhook-card { margin: 0 0 16px; }
.ig-copy-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.ig-copy-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.ig-copy-box {
  display: flex;
  align-items: stretch;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.ig-copy-value {
  flex: 1;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-primary);
  background: transparent;
  word-break: break-all;
  display: flex;
  align-items: center;
  min-height: 38px;
}
.ig-copy-btn {
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 0 12px;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.ig-copy-btn svg { width: 14px; height: 14px; }
.ig-copy-btn:hover { color: #d6249f; background: var(--bg-elevated); }
.ig-copy-btn.is-copied { color: #d6249f; }
.ig-copy-btn.is-copied .ig-copy-label-text::before { content: "✓ "; }

.ig-help {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.ig-help-quiet { font-size: 11.5px; color: var(--text-tertiary); }
.ig-regen-btn {
  margin: 4px 0 0;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
}
.ig-regen-btn:hover { color: #d6249f; }

/* Form */
.ig-form { display: flex; flex-direction: column; gap: 14px; }
.ig-field { display: flex; flex-direction: column; gap: 6px; }
.ig-field .label { font-size: 12.5px; font-weight: 600; }
.ig-input-wrap { position: relative; display: flex; align-items: stretch; }
.ig-input-wrap .input { padding-right: 38px; flex: 1; }
.ig-mask { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em; }
.ig-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ig-eye:hover { color: var(--text-primary); background: var(--bg-subtle); }
.ig-eye::before {
  content: "";
  display: block;
  width: 18px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 0 75% 0 75%;
  position: relative;
}
.ig-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.ig-eye[data-on="1"]::before { border-style: dashed; opacity: .5; }
.ig-eye[data-on="1"]::after  { opacity: .5; }

.ig-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ig-actions-right { display: flex; gap: 8px; }

/* Success pane */
.ig-pane-success { text-align: center; padding: 28px 32px 22px; }
.ig-check-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.ig-check {
  width: 72px;
  height: 72px;
  color: #d6249f;
}
.ig-check-circle {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: ig-check-circle .55s ease-out forwards;
}
.ig-check-tick {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: ig-check-tick .35s ease-out .45s forwards;
}
@keyframes ig-check-circle { to { stroke-dashoffset: 0; } }
@keyframes ig-check-tick   { to { stroke-dashoffset: 0; } }
.ig-success-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.ig-bot-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 0 0 16px;
  text-align: left;
}
.ig-bot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
  font-size: 13px;
}
.ig-bot-row + .ig-bot-row { border-top: 1px dashed var(--border); }
.ig-bot-label {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
}
.ig-bot-username {
  color: #d6249f;
  font-family: var(--font-mono);
  font-weight: 600;
  text-decoration: none;
}
.ig-bot-username:hover { text-decoration: underline; }
.ig-bot-firstname { color: var(--text-primary); font-weight: 500; }
.ig-bot-meta { color: var(--text-secondary); font-size: 12.5px; }

.ig-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
  border-color: #d6249f;
  color: #fff;
  text-decoration: none;
  margin-bottom: 14px;
}
.ig-open-btn:hover {
  filter: brightness(1.05);
  color: #fff;
}
.ig-open-icon { width: 14px; height: 14px; }

.ig-success-hint {
  display: inline-block;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  max-width: 380px;
  line-height: 1.45;
}

.ig-actions-success {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.ig-disconnect-link {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 12.5px;
  padding: 4px 6px;
}
.ig-disconnect-link:hover { color: var(--danger); }

/* -- Channels card: Instagram state badges (Phase 8b-2) -- */
.channel-row[data-channel="instagram"] .channel-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.ig-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.ig-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.ig-badge-connected {
  color: #a21caf;
  background: rgba(214, 36, 159, .12);
}
.ig-badge-connected::before { background: #d6249f; }
.ig-badge-pending {
  color: #b45309;
  background: rgba(245, 158, 11, .14);
}
.ig-badge-pending::before { background: #f59e0b; }
html[data-theme="dark"] .ig-badge-connected { color: #f0abfc; }
html[data-theme="dark"] .ig-badge-pending   { color: #fbbf24; }

.ig-channel-meta {
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

/* ============================================================
   24. FACEBOOK MESSENGER CONNECT WIZARD (Phase 8c-2)
   ============================================================
   Brand: solid Messenger blue (#1877F2) for state colour;
   gradient (#00B2FF → #006AFF) reserved for brand mark + primary
   "Open Facebook Page" CTA only (surgical gradient - lesson from
   8b-2 self-rating). */

.mg-backdrop .mg-modal { max-width: 560px; }

.mg-head { align-items: flex-start; }
.mg-head-title { display: flex; align-items: center; gap: 12px; }
.mg-brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #00B2FF 0%, #006AFF 100%);
  color: #fff;
  box-shadow: 0 4px 12px -2px rgba(0, 106, 255, .35);
}
.mg-brand-mark svg { width: 22px; height: 22px; }
.mg-head-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Step indicator */
.mg-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 18px 22px 14px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}
.mg-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  position: relative;
  font-size: 12.5px;
  color: var(--text-tertiary);
  transition: color .2s ease;
}
.mg-step + .mg-step::before {
  content: "";
  position: absolute;
  left: -8px;
  right: calc(100% - 14px);
  top: 14px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.mg-step:last-child { flex: 0 0 auto; }
.mg-step-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all .2s ease;
}
.mg-step-num { line-height: 1; }
.mg-step.is-active { color: var(--text-primary); font-weight: 600; }
.mg-step.is-active .mg-step-dot {
  background: #1877F2;
  color: #fff;
  border-color: #1877F2;
  box-shadow: 0 0 0 4px rgba(24, 119, 242, .18);
}
.mg-step.is-complete .mg-step-dot {
  background: #1877F2;
  color: #fff;
  border-color: #1877F2;
}
.mg-step.is-complete .mg-step-num { display: none; }
.mg-step.is-complete .mg-step-dot::after { content: "✓"; font-size: 14px; font-weight: 700; }
.mg-step.is-complete + .mg-step::before { background: #1877F2; }
.mg-step.is-complete { color: var(--text-secondary); }

/* Panes */
.mg-pane {
  padding: 18px 22px 20px;
  max-height: calc(80vh - 180px);
  overflow-y: auto;
}
.mg-pane[hidden] { display: none; }
.mg-intro {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.mg-intro-tight { margin: 0 0 10px; }
.mg-intro a {
  color: #1877F2;
  text-decoration: none;
  font-weight: 500;
}
.mg-intro a:hover { text-decoration: underline; }
.mg-intro code,
.mg-help code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Generate-webhook card (step 1, initial) */
.mg-generate-card {
  background: var(--bg-subtle);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin: 0 0 18px;
  text-align: center;
}
.mg-generate-text {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Generated webhook card */
.mg-webhook-card { margin: 0 0 16px; }
.mg-copy-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.mg-copy-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.mg-copy-box {
  display: flex;
  align-items: stretch;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.mg-copy-value {
  flex: 1;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-primary);
  background: transparent;
  word-break: break-all;
  display: flex;
  align-items: center;
  min-height: 38px;
}
.mg-copy-btn {
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 0 12px;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.mg-copy-btn svg { width: 14px; height: 14px; }
.mg-copy-btn:hover { color: #1877F2; background: var(--bg-elevated); }
.mg-copy-btn.is-copied { color: #1877F2; }
.mg-copy-btn.is-copied .mg-copy-label-text::before { content: "✓ "; }

.mg-help {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.mg-help-quiet { font-size: 11.5px; color: var(--text-tertiary); }
.mg-regen-btn {
  margin: 4px 0 0;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
}
.mg-regen-btn:hover { color: #1877F2; }

/* Form */
.mg-form { display: flex; flex-direction: column; gap: 14px; }
.mg-field { display: flex; flex-direction: column; gap: 6px; }
.mg-field .label { font-size: 12.5px; font-weight: 600; }
.mg-input-wrap { position: relative; display: flex; align-items: stretch; }
.mg-input-wrap .input { padding-right: 38px; flex: 1; }
.mg-mask { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em; }
.mg-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mg-eye:hover { color: var(--text-primary); background: var(--bg-subtle); }
.mg-eye::before {
  content: "";
  display: block;
  width: 18px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 0 75% 0 75%;
  position: relative;
}
.mg-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.mg-eye[data-on="1"]::before { border-style: dashed; opacity: .5; }
.mg-eye[data-on="1"]::after  { opacity: .5; }

.mg-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.mg-actions-right { display: flex; gap: 8px; }

/* Success pane */
.mg-pane-success { text-align: center; padding: 28px 32px 22px; }
.mg-check-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.mg-check {
  width: 72px;
  height: 72px;
  color: #1877F2;
}
.mg-check-circle {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: mg-check-circle .55s ease-out forwards;
}
.mg-check-tick {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: mg-check-tick .35s ease-out .45s forwards;
}
@keyframes mg-check-circle { to { stroke-dashoffset: 0; } }
@keyframes mg-check-tick   { to { stroke-dashoffset: 0; } }
.mg-success-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.mg-bot-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 0 0 16px;
  text-align: left;
}
.mg-bot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
  font-size: 13px;
}
.mg-bot-row + .mg-bot-row { border-top: 1px dashed var(--border); }
.mg-bot-label {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
}
.mg-bot-pagename { color: var(--text-primary); font-weight: 600; }
.mg-bot-mono { font-family: var(--font-mono); font-size: 12px; }
.mg-bot-meta { color: var(--text-secondary); font-size: 12.5px; }

.mg-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #00B2FF 0%, #006AFF 100%);
  border-color: #006AFF;
  color: #fff;
  text-decoration: none;
  margin-bottom: 14px;
}
.mg-open-btn:hover {
  filter: brightness(1.05);
  color: #fff;
}
.mg-open-icon { width: 14px; height: 14px; }

.mg-success-hint {
  display: inline-block;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  max-width: 380px;
  line-height: 1.45;
}

.mg-actions-success {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.mg-disconnect-link {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 12.5px;
  padding: 4px 6px;
}
.mg-disconnect-link:hover { color: var(--danger); }

/* -- Channels card: Messenger state badges (Phase 8c-2) -- */
.channel-row[data-channel="messenger"] .channel-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.mg-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.mg-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.mg-badge-connected {
  color: #0b5cd6;
  background: rgba(24, 119, 242, .12);
}
.mg-badge-connected::before { background: #1877F2; }
.mg-badge-pending {
  color: #b45309;
  background: rgba(245, 158, 11, .14);
}
.mg-badge-pending::before { background: #f59e0b; }
html[data-theme="dark"] .mg-badge-connected { color: #93c5fd; }
html[data-theme="dark"] .mg-badge-pending   { color: #fbbf24; }

.mg-channel-meta {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* Channel-icon avatar for Messenger */
.avatar-source.messenger { background: #dbeafe; color: #1877F2; }
html[data-theme="dark"] .avatar-source.messenger { background: rgba(24, 119, 242, .18); color: #93c5fd; }

/* ============================================================
   25. CROSS-LINK CARD (Phase 8d-1)
   Shared by IG ↔ Messenger wizard success panes. Subtle border,
   neutral palette - the cross-link is an "additional offer", not
   the headline action.
   ============================================================ */
.xlink-card {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  text-align: left;
}
.xlink-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.xlink-card-text { flex: 1; min-width: 0; }
.xlink-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.xlink-card-title-success {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.xlink-checkmark {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #10b981;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.xlink-card-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.xlink-card-sub strong { color: var(--text-secondary); font-weight: 600; }
.xlink-card-sub em { font-style: normal; color: var(--text-secondary); }
.xlink-card-sub code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 4px;
}
.xlink-card-success {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.xlink-card-success .mg-copy-row { margin-bottom: 10px; }
.xlink-card-success .mg-copy-row:last-child { margin-bottom: 0; }
.xlink-card-error {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #b91c1c;
  font-size: 12.5px;
  line-height: 1.4;
}
html[data-theme="dark"] .xlink-card-error { color: #fca5a5; }

/* ============================================================
   UNIFIED META WIZARD (Phase 8e)
   One wizard for Facebook Messenger + Instagram. Dual-accent -
   FB blue (#1877F2) and IG gradient - applied surgically:
   brand mark blends both, step dots blue→magenta, success
   check IG-gradient (the "both connected" feel).
   ============================================================ */

.meta-backdrop .meta-modal { max-width: 580px; }

.meta-head { align-items: flex-start; }
.meta-head-title { display: flex; align-items: center; gap: 12px; }
.meta-brand-mark {
  width: 56px;
  height: 38px;
  flex: 0 0 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.meta-brand-mark-fb,
.meta-brand-mark-ig {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: #fff;
}
.meta-brand-mark-fb {
  background: linear-gradient(135deg, #00B2FF 0%, #006AFF 100%);
  box-shadow: 0 3px 8px -2px rgba(0, 106, 255, .35);
}
.meta-brand-mark-fb svg { width: 16px; height: 16px; }
.meta-brand-mark-ig {
  background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
  box-shadow: 0 3px 8px -2px rgba(253, 29, 29, .35);
}
.meta-brand-mark-ig svg { width: 16px; height: 16px; }
.meta-head-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Step indicator (2 steps - simpler than 3-step IG/MG) */
.meta-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 18px 22px 14px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}
.meta-step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  position: relative;
  font-size: 12.5px;
  color: var(--text-tertiary);
  transition: color .2s ease;
}
.meta-step + .meta-step::before {
  content: "";
  position: absolute;
  left: -8px;
  right: calc(100% - 14px);
  top: 14px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.meta-step:last-child { flex: 0 0 auto; }
.meta-step-dot {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all .2s ease;
}
.meta-step-num { line-height: 1; }
.meta-step.is-active { color: var(--text-primary); font-weight: 600; }
.meta-step.is-active .meta-step-dot {
  background: linear-gradient(135deg, #1877F2 0%, #d6249f 100%);
  border-color: transparent;
  color: #fff;
}
.meta-step.is-complete .meta-step-dot {
  background: linear-gradient(135deg, #1877F2 0%, #d6249f 100%);
  border-color: transparent;
  color: #fff;
}
.meta-step.is-complete .meta-step-num { display: none; }
.meta-step.is-complete .meta-step-dot::after { content: "✓"; font-size: 14px; font-weight: 700; }
.meta-step.is-complete + .meta-step::before {
  background: linear-gradient(90deg, #1877F2, #d6249f);
}
.meta-step.is-complete { color: var(--text-secondary); }

/* Panes */
.meta-pane {
  padding: 18px 22px 20px;
  max-height: calc(85vh - 160px);
  overflow-y: auto;
}
.meta-pane[hidden] { display: none; }
.meta-intro {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.meta-intro a {
  color: #1877F2;
  text-decoration: none;
  font-weight: 500;
}
.meta-intro a:hover { text-decoration: underline; }
.meta-intro code,
.meta-help code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-subtle);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Form */
.meta-form { display: flex; flex-direction: column; gap: 14px; }
.meta-field { display: flex; flex-direction: column; gap: 6px; }
.meta-field .label { font-size: 12.5px; font-weight: 600; }
.meta-input-wrap { position: relative; display: flex; align-items: stretch; }
.meta-input-wrap .input { padding-right: 38px; flex: 1; }
.meta-mask { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.02em; }
.meta-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.meta-eye:hover { color: var(--text-primary); background: var(--bg-subtle); }
.meta-eye::before {
  content: "";
  display: block;
  width: 18px;
  height: 12px;
  border: 1.6px solid currentColor;
  border-radius: 0 75% 0 75%;
  position: relative;
}
.meta-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.meta-eye[data-on="1"]::before { border-style: dashed; opacity: .5; }
.meta-eye[data-on="1"]::after  { opacity: .5; }

.meta-help {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}

/* Channel toggles (FB Messenger / Instagram on/off) */
.meta-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-top: 2px;
}
.meta-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.meta-toggle input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.meta-toggle-mark {
  flex: 0 0 36px;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background .18s ease;
  margin-top: 2px;
}
.meta-toggle-mark::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.meta-toggle input:checked + .meta-toggle-mark {
  background: linear-gradient(135deg, #1877F2 0%, #d6249f 100%);
}
.meta-toggle input:checked + .meta-toggle-mark::after { transform: translateX(16px); }
.meta-toggle-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}
.meta-toggle-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.meta-toggle-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Success pane */
.meta-pane-success { text-align: center; padding: 28px 32px 22px; }
.meta-check-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.meta-check {
  width: 72px;
  height: 72px;
  color: #d6249f;
}
.meta-check-circle {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: meta-check-circle .55s ease-out forwards;
}
.meta-check-tick {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: meta-check-tick .35s ease-out .45s forwards;
}
@keyframes meta-check-circle { to { stroke-dashoffset: 0; } }
@keyframes meta-check-tick   { to { stroke-dashoffset: 0; } }
.meta-success-title {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.meta-success-sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Result cards (FB + IG outcomes stacked) */
.meta-result-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 16px;
  text-align: left;
}
.meta-result-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: border-color .2s ease;
}
.meta-result-card.is-connected { border-color: rgba(34, 197, 94, .35); }
.meta-result-card.is-skipped   { opacity: .85; }
.meta-result-card.is-failed    { border-color: rgba(239, 68, 68, .35); }
.meta-result-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.meta-result-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #fff;
}
.meta-result-icon-mg {
  background: linear-gradient(135deg, #00B2FF 0%, #006AFF 100%);
}
.meta-result-icon-mg svg { width: 18px; height: 18px; }
.meta-result-icon-ig {
  background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
}
.meta-result-icon-ig svg { width: 18px; height: 18px; }
.meta-result-card-text { flex: 1; min-width: 0; }
.meta-result-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.meta-result-card-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.meta-result-badge {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-tertiary);
  border: 1px solid var(--border);
}
.meta-result-badge.is-connected {
  background: rgba(34, 197, 94, .12);
  color: #15803d;
  border-color: rgba(34, 197, 94, .35);
}
html[data-theme="dark"] .meta-result-badge.is-connected { color: #86efac; }
.meta-result-badge.is-skipped  { background: var(--bg-elevated); color: var(--text-tertiary); }
.meta-result-badge.is-failed   {
  background: rgba(239, 68, 68, .12);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, .35);
}
html[data-theme="dark"] .meta-result-badge.is-failed { color: #fca5a5; }

.meta-warnings {
  background: rgba(234, 179, 8, .08);
  border: 1px solid rgba(234, 179, 8, .3);
  color: #92400e;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12.5px;
  text-align: left;
  margin-bottom: 14px;
  line-height: 1.45;
}
html[data-theme="dark"] .meta-warnings { color: #fde68a; }

.meta-actions-success {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

/* Disabled toggle visual - used when one channel is already connected
   so the wizard doesn't accidentally rewrite working creds. */
.meta-toggle:has(input:disabled) { cursor: not-allowed; opacity: .7; }
.meta-toggle:has(input:disabled) .meta-toggle-mark { background: var(--border); }
.meta-toggle:has(input:disabled) .meta-toggle-title::after {
  content: " · already connected";
  font-weight: 400;
  color: var(--text-tertiary);
  font-size: 11.5px;
}

/* ====================================================================== */
/* ============================ BILLING (Phase 11-2) ==================== */
/* ====================================================================== */

/* ---- Lapse banner (suspended workspace) ---- */
.bl-lapse {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  margin: 0 0 var(--space-5) 0;
  background: linear-gradient(135deg, var(--danger-soft) 0%, #fff5f5 100%);
  border: 1px solid var(--danger);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 12px rgba(239,68,68,0.10);
}
.bl-lapse-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  background: var(--danger);
  color: #fff;
}
.bl-lapse-icon svg { width: 22px; height: 22px; }
.bl-lapse-text { flex: 1 1 auto; min-width: 0; }
.bl-lapse-title {
  font-size: 15px;
  font-weight: 600;
  color: #7f1d1d;
  margin-bottom: 2px;
}
.bl-lapse-sub {
  font-size: 13px;
  color: #991b1b;
}
.bl-lapse[hidden] { display: none; }

/* ---- Dashboard mini-lapse banner ---- */
.bl-lapse-mini {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 13px;
  color: #7f1d1d;
}
.bl-lapse-mini-close {
  margin-left: auto;
  background: none;
  border: 0;
  padding: 4px;
  cursor: pointer;
  color: #991b1b;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
.bl-lapse-mini-close:hover { background: rgba(239,68,68,0.10); }

/* ---- Top grid: plan + meter, 2-col desktop ---- */
.billing-top-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

/* ---- Cards (shared) ---- */
.billing-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6) var(--space-6);
  box-shadow: 0 1px 2px rgba(15,23,42,0.03);
}
.billing-section {
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
}
.bl-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.bl-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bl-card-sub {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---- Plan card body ---- */
.bl-plan-body { min-height: 110px; }
.bl-plan-skel { display: flex; flex-direction: column; }
.bl-plan-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.bl-plan-included {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}
.bl-plan-detail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.bl-plan-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}
.bl-plan-detail-row .label { color: var(--text-tertiary); }
.bl-plan-detail-row .val { color: var(--text-primary); font-weight: 500; }
.bl-plan-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--space-5) var(--space-4) var(--space-3);
  color: var(--text-secondary);
}
.bl-plan-empty svg { width: 36px; height: 36px; color: var(--text-tertiary); margin-bottom: var(--space-3); }
.bl-plan-empty p { margin: 0; font-size: 13px; }

/* ---- Status pill ---- */
.bl-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}
.bl-status-pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.bl-status-pill.s-active        { background: var(--success-soft); color: #047857; }
.bl-status-pill.s-past_due      { background: var(--warning-soft); color: #b45309; }
.bl-status-pill.s-canceled,
.bl-status-pill.s-pending_payment { background: var(--bg-subtle); color: var(--text-secondary); }
.bl-status-pill.s-suspended     { background: var(--danger-soft); color: #b91c1c; }

/* ---- Meter card body ---- */
.bl-meter-body { display: flex; flex-direction: column; gap: var(--space-5); }

.bl-quota-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-2);
}
.bl-quota-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.bl-quota-pct {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Progress bar with three color thresholds + overflow lane */
.bl-progress {
  position: relative;
  width: 100%;
  height: 10px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.bl-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  background: linear-gradient(90deg, #34d399, #10b981);
  border-radius: var(--radius-full);
  transition: width 320ms ease-out, background 240ms;
}
.bl-progress-fill.is-warn  { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.bl-progress-fill.is-danger { background: linear-gradient(90deg, #f87171, #ef4444); }

/* Striped overage lane that visually overflows past the included quota */
.bl-progress-over {
  position: absolute;
  inset: 0 0 0 auto;
  height: 100%;
  background: repeating-linear-gradient(
    45deg,
    var(--danger),
    var(--danger) 6px,
    #fca5a5 6px,
    #fca5a5 12px
  );
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}
.bl-progress-over[hidden] { display: none; }
.bl-quota-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* ---- Credit row ---- */
.bl-credit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-4);
  background: var(--bg-subtle);
  border-radius: var(--radius-lg);
}
.bl-credit-block { display: flex; flex-direction: column; }
.bl-credit-amount {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.bl-credit-amount.is-zero { color: var(--text-secondary); }
.bl-credit-amount.is-negative { color: var(--danger); }
.bl-credit-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.bl-topup-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.bl-topup-btn svg { width: 16px; height: 16px; }

.bl-overage-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---- Tables (activity + invoices) ---- */
.bl-table-wrap {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-2));
}
.bl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.bl-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bl-table td {
  padding: 12px var(--space-3);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.bl-table tr:last-child td { border-bottom: 0; }
.bl-table tr:hover td { background: var(--bg-hover); }
.bl-table .bl-skel-row td { padding: 14px var(--space-3); }
.bl-table .bl-skel-row:hover td { background: transparent; }

.bl-col-amount { text-align: right; font-variant-numeric: tabular-nums; }
.bl-col-actions { text-align: right; white-space: nowrap; }
.bl-col-date { color: var(--text-secondary); }
.bl-col-period { color: var(--text-secondary); font-size: 12px; }

.bl-amount-pos { color: #047857; font-weight: 500; }
.bl-amount-neg { color: var(--text-primary); }

/* Type badges (activity table) */
.bl-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}
.bl-type-badge.t-topup      { background: var(--success-soft); color: #047857; }
.bl-type-badge.t-adjustment { background: var(--brand-soft); color: var(--brand-hover); }
.bl-type-badge.t-refund     { background: #f1f5f9; color: var(--text-secondary); }

/* Status badges (invoice table) */
.bl-inv-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.bl-inv-status.s-paid          { background: var(--success-soft); color: #047857; }
.bl-inv-status.s-open          { background: var(--warning-soft); color: #b45309; }
.bl-inv-status.s-void,
.bl-inv-status.s-uncollectible { background: var(--bg-subtle); color: var(--text-secondary); }
.bl-inv-status.s-draft         { background: var(--bg-subtle); color: var(--text-tertiary); }

.bl-inv-actions {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
}
.bl-inv-actions a {
  color: var(--brand);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.bl-inv-actions a:hover { background: var(--brand-soft); color: var(--brand-hover); }
.bl-inv-actions svg { width: 14px; height: 14px; }

/* Empty states */
.bl-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--space-8) var(--space-4) var(--space-6);
  color: var(--text-secondary);
}
.bl-empty[hidden] { display: none; }
.bl-empty svg {
  width: 32px; height: 32px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
.bl-empty p { margin: 0; font-size: 13px; }

/* ---- Modal extras ---- */
/* Phase 18: removed a duplicate `.modal.modal-md { max-width: 440px }` that
   lived here - it silently overrode the canonical 520px (see the "MODAL
   EXTENSIONS" block above) and left WhatsApp Connect, the widest .modal-md
   form, narrower than its 520-580px channel-modal siblings (tg/ig/mg/meta).
   520px is now the single source of truth for .modal-md. */
.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  background: none;
  border: 0;
  padding: 6px;
  cursor: pointer;
  color: var(--text-tertiary);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--bg-subtle); color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.topup-body { padding: var(--space-5) var(--space-6) var(--space-6); }
.topup-blurb {
  margin: 0 0 var(--space-4);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.topup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--space-4);
}
.topup-chip { font-variant-numeric: tabular-nums; }

.topup-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-3);
}
.topup-input-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.topup-input-row {
  position: relative;
  display: flex;
  align-items: stretch;
}
.topup-input-prefix {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  pointer-events: none;
}
.topup-input {
  padding-left: 28px;
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  width: 100%;
}
.topup-input-help {
  font-size: 12px;
  color: var(--text-tertiary);
}
.btn-arrow { width: 14px; height: 14px; margin-left: 6px; }

/* ---- Suspended global lockdown ---- */
.app-shell.is-suspended [data-route="channels"],
.app-shell.is-suspended [data-route="knowledge-base"] {
  /* Sidebar entries remain visible + clickable so user can navigate,
     but the per-action buttons inside are disabled below. */
}
.app-shell.is-suspended .channel-row .btn:not(.bl-topup-btn),
.app-shell.is-suspended .channel-card .btn:not(.bl-topup-btn),
.app-shell.is-suspended .kb-upload-card,
.app-shell.is-suspended .kb-doc-actions {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.app-shell.is-suspended .channel-row,
.app-shell.is-suspended .channel-card {
  position: relative;
}

/* ---- Responsive ---- */
@media (max-width: 880px) {
  .billing-top-grid { grid-template-columns: 1fr; }
  .bl-credit-row { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  .bl-credit-amount { font-size: 24px; }
  .bl-topup-btn { width: 100%; justify-content: center; }
}
@media (max-width: 520px) {
  .billing-card { padding: var(--space-4); }
  .bl-table th, .bl-table td { padding: 10px var(--space-2); }
  .bl-col-period { display: none; }
  .bl-lapse { flex-wrap: wrap; }
  .bl-lapse-text { width: 100%; }
  .bl-lapse #bl-lapse-topup { width: 100%; }
}

/* FR-23: clickable description cell with copy affordance */
.bl-desc-cell {
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bl-desc-cell:hover { color: var(--brand); }
.bl-desc-copy {
  width: 12px; height: 12px;
  color: var(--text-tertiary);
  opacity: 0.7;
  flex: 0 0 auto;
  transition: opacity 0.15s, color 0.15s;
}
.bl-desc-cell:hover .bl-desc-copy { opacity: 1; color: var(--brand); }
.bl-desc-cell.is-copied { color: var(--success); }
.bl-desc-cell.is-copied .bl-desc-copy { color: var(--success); }

/* ─────────────────────────────────────────────────────────────────
   Phase 9-2 - Voice page + impersonation banner
   ───────────────────────────────────────────────────────────────── */
.impersonation-banner {
  background: rgba(245, 180, 40, 0.18);
  border: 1px solid rgba(245, 180, 40, 0.45);
  color: #8a6a16;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.impersonation-banner[hidden] { display: none; }
.impersonation-banner .ib-icon { font-size: 16px; }
.impersonation-banner .ib-text { flex: 1; }
.impersonation-banner .ib-return {
  font-weight: 500; color: #8a6a16; text-decoration: underline;
}

.voice-empty {
  text-align: center;
  padding: 64px 24px;
  background: var(--bg-card, #fff);
  border-radius: 12px;
  border: 1px solid var(--border, #e5e7eb);
}
.voice-empty-icon { font-size: 48px; opacity: 0.4; margin-bottom: 12px; }
.voice-empty h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.voice-empty p  { margin: 0; color: var(--text-muted, #6b7280); }

.voice-active { display: flex; flex-direction: column; gap: 16px; }
.voice-empty-row { padding: 12px 0; color: var(--text-muted, #6b7280); font-size: 13px; }

.voice-drawer {
  position: fixed; inset: 0;
  z-index: 50;
}
.voice-drawer[hidden] { display: none; }
.voice-drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.35);
}
.voice-drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(480px, 100%);
  background: var(--bg-card, #fff);
  box-shadow: -10px 0 28px rgba(0,0,0,0.18);
  display: flex; flex-direction: column;
}
.voice-drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--border, #e5e7eb);
}
.voice-drawer-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.voice-drawer-close {
  background: transparent; border: none; font-size: 22px;
  color: var(--text-muted, #6b7280); cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 4px;
}
.voice-drawer-close svg { width: 18px; height: 18px; }
.voice-drawer-meta { padding: 10px 18px; font-size: 11.5px; color: var(--text-muted, #6b7280); }
.voice-drawer-body { padding: 8px 18px 18px; flex: 1; overflow-y: auto; }
.voice-drawer-body .vd-turn {
  padding: 6px 0; font-size: 13px; line-height: 1.5;
  border-bottom: 1px solid var(--border, #f3f4f6);
}
.voice-drawer-body .vd-turn[data-role="ai"]       .vd-role { color: var(--brand,  #2563eb); }
.voice-drawer-body .vd-turn[data-role="customer"] .vd-role,
.voice-drawer-body .vd-turn[data-role="user"]     .vd-role { color: var(--success,#10b981); }
.vd-role {
  font-weight: 600; margin-right: 8px;
  font-size: 11px; text-transform: uppercase;
}
