/* ==========================================================================
   Twine Lead Agent — design system
   Sections: tokens · base · buttons · pills · cards · forms · segmented ·
   switches · chips · table · stepper · banner · toast · skeleton · empty ·
   drawer · modal · avatar · shell · views · overview · leads · messages ·
   activity · settings · connect · responsive · motion
   ========================================================================== */

/* --- tokens --------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* neutrals */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f4f8;
  --border: #e5e8ee;
  --border-strong: #d3d9e2;
  --text: #16181d;
  --text-secondary: #5b6472;
  --text-tertiary: #8a93a2;
  --text-inverse: #ffffff;

  /* shell */
  --sidebar-w: 236px;
  /* the leads grid's checkbox gutter; mirrored by SELECT_COLUMN_WIDTH in grid.js */
  --select-col-w: 38px;

  /* accent */
  --accent: #3f68f5;
  --accent-hover: #2f58df;
  --accent-active: #2549c8;
  --accent-soft: #eef2ff;
  --accent-border: #c7d5ff;

  /* semantic */
  --success: #177a50;
  --success-soft: #e9f7f0;
  --success-border: #b5e3cd;
  --warning: #9a6700;
  --warning-soft: #fff5e0;
  --warning-border: #f0d597;
  --danger: #cf3f3f;
  --danger-hover: #b93131;
  --danger-soft: #fdf0f0;
  --danger-border: #f2c4c4;
  --info: #2f5fd0;
  --info-soft: #ecf1ff;
  --info-border: #c3d2f7;
  --violet: #6d4fc4;
  --violet-soft: #f1edfb;
  --violet-border: #d6cbf0;
  --teal: #0f766e;
  --teal-soft: #e6f5f3;
  --teal-border: #b2ddd8;

  /* focus */
  --focus-ring: 0 0 0 3px rgba(63, 104, 245, 0.32);

  /* radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  /* shadows */
  --shadow-xs: 0 1px 2px rgba(23, 29, 41, 0.05);
  --shadow-sm: 0 1px 2px rgba(23, 29, 41, 0.05), 0 2px 8px rgba(23, 29, 41, 0.05);
  --shadow-md: 0 2px 4px rgba(23, 29, 41, 0.05), 0 8px 24px rgba(23, 29, 41, 0.08);
  --shadow-lg: 0 4px 8px rgba(23, 29, 41, 0.06), 0 20px 48px rgba(23, 29, 41, 0.16);

  /* type */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;

  /* motion */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 260ms;

  /* chat */
  --bubble-out: #e7edff;

  /* logs */
  --log-bg: #0d1117;
  --log-text: #c9d4e3;
}

/* --- base ----------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  src: url("/fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("/fonts/InterVariable-Italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.015em;
}

h2 {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h3 {
  font-size: var(--fs-base);
  font-weight: 600;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  color: inherit;
}

::selection {
  background: rgba(63, 104, 245, 0.18);
}

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

.hidden {
  display: none !important;
}

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

.kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

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

/* --- buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
  -webkit-user-select: none;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.btn:focus-visible {
  box-shadow: var(--focus-ring);
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: #bfc7d4;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
  box-shadow: var(--shadow-xs);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger-outline {
  background: var(--surface);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn .btn-count {
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.24);
  font-size: var(--fs-xs);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-top-color: rgba(0, 0, 0, 0.55);
  animation: spin 700ms linear infinite;
}

.btn-primary.is-loading::after,
.btn-danger.is-loading::after {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.btn-icon:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* --- pills ---------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  font-weight: 550;
  line-height: 1.6;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex: none;
}

.pill.success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.pill.success::before {
  background: var(--success);
}

.pill.danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.pill.danger::before {
  background: var(--danger);
}

.pill.warning {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning);
}

.pill.warning::before {
  background: var(--warning);
}

.pill.info {
  background: var(--info-soft);
  border-color: var(--info-border);
  color: var(--info);
}

.pill.info::before {
  background: var(--info);
}

.pill.violet {
  background: var(--violet-soft);
  border-color: var(--violet-border);
  color: var(--violet);
}

.pill.violet::before {
  background: var(--violet);
}

.pill.teal {
  background: var(--teal-soft);
  border-color: var(--teal-border);
  color: var(--teal);
}

.pill.teal::before {
  background: var(--teal);
}

.pill.neutral::before {
  background: var(--text-tertiary);
}

/* muted-red dot on a gray pill: dismissed, not alarming */
.pill.dismissed::before {
  background: #d99e9e;
}

.pill.is-live::before {
  animation: pulse 1.6s var(--ease) infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

/* --- cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-header .card-sub {
  margin-top: 2px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.card--danger {
  border-color: var(--danger-border);
}

/* --- stat cards ----------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
}

.stat {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.stat strong {
  display: block;
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat span {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-xs);
  font-weight: 550;
  color: var(--text-tertiary);
}

.stat.wide {
  grid-column: 1 / -1;
}

/* --- forms ---------------------------------------------------------------- */

input[type="text"],
input[type="search"],
input[type="number"],
input[type="password"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  min-height: 38px;
  padding: 7px 11px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

input:hover,
select:hover,
textarea:hover {
  border-color: #bfc7d4;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

label {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
}

.field-row + .field-row {
  border-top: 1px solid var(--border);
}

.field-row input[type="number"] {
  width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- segmented control ---------------------------------------------------- */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-3);
  border-radius: var(--r-md);
}

.segmented button {
  border: none;
  background: transparent;
  border-radius: 7px;
  padding: 5px 12px;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.segmented button:hover:not(:disabled) {
  color: var(--text);
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.segmented button:disabled {
  opacity: 0.55;
  cursor: default;
}

.segmented .seg-count {
  margin-left: 5px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* --- switches ------------------------------------------------------------- */

.switch {
  position: relative;
  display: inline-flex;
  width: 40px;
  height: 24px;
  flex: none;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch .switch-track {
  width: 100%;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background-color var(--dur) var(--ease);
}

.switch .switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  box-shadow: var(--focus-ring);
}

.switch input:disabled + .switch-track {
  opacity: 0.5;
}

/* the Safe→Submit switch reads as dangerous when on */
.switch--danger input:checked + .switch-track {
  background: var(--danger);
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
}

/* --- filter chips ---------------------------------------------------------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-full);
  padding: 4px 12px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
}

.chip .chip-count {
  margin-left: 5px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.chip.active .chip-count {
  color: var(--accent);
  opacity: 0.75;
}

/* --- data table ----------------------------------------------------------- */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  max-height: calc(100vh - 320px);
  min-height: 200px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 9px 14px;
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.data-table th.sortable {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.data-table th.sortable:hover {
  color: var(--text-secondary);
}

.data-table th .sort-arrow {
  margin-left: 4px;
  font-size: 9px;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr.row-click {
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.data-table tbody tr.row-click:hover {
  background: var(--surface-2);
}

.data-table tbody tr[aria-selected="true"],
.data-table tbody tr[aria-selected="true"]:hover {
  background: var(--accent-soft);
}

/* --- pipeline stepper ------------------------------------------------------ */

.pipeline-steps {
  display: flex;
  flex-direction: column;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
}

.pipeline-step + .pipeline-step {
  border-top: 1px solid var(--border);
}

.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  position: relative;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.pipeline-step[data-step-state="active"] .step-dot {
  border-color: var(--accent);
  color: transparent;
}

.pipeline-step[data-step-state="active"] .step-dot::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 2px solid var(--accent-border);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}

.pipeline-step[data-step-state="done"] .step-dot {
  border-color: var(--success);
  background: var(--success);
  color: transparent;
}

.pipeline-step[data-step-state="done"] .step-dot::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
}

.pipeline-step[data-step-state="failed"] .step-dot {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: transparent;
}

.pipeline-step[data-step-state="failed"] .step-dot::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 12px;
}

.step-body {
  flex: 1;
  min-width: 0;
}

.step-body strong {
  display: block;
  font-size: var(--fs-base);
  font-weight: 600;
}

.step-body small {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.step-tag {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 1px 8px;
  background: var(--surface-2);
}

/* danger zone (apply) */
.danger-zone {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--r-md);
  background: var(--danger-soft);
}

.danger-zone strong {
  font-size: var(--fs-base);
  font-weight: 600;
}

.danger-zone p {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

/* --- banner ---------------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  margin-bottom: 14px;
}

.banner-warning {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  color: var(--warning);
}

/* inline warning inside cards */
.warning-note {
  padding: 9px 12px;
  border-radius: var(--r-md);
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  color: var(--warning);
  font-size: var(--fs-sm);
  font-weight: 500;
  margin-bottom: 12px;
}

/* --- toasts ---------------------------------------------------------------- */

/* --- command bar ------------------------------------------------------------- */

/* Docked to the viewport, not the view, so the pipeline is reachable from every
   screen. Centred over the content column rather than the window, so it does not
   drift left of the thing it acts on. */
.command-bar {
  position: fixed;
  bottom: 18px;
  left: calc(50% + (var(--sidebar-w) / 2));
  transform: translateX(-50%);
  transition: left var(--dur) var(--ease);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.14), 0 1px 2px rgba(15, 23, 42, 0.08);
  max-width: calc(100vw - 40px);
}

.command-bar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.command-bar .btn {
  border-radius: var(--r-full);
  white-space: nowrap;
}

.command-bar-divider {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--border);
}

.command-bar-count,
.command-bar-task {
  padding-left: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}

.command-bar-count {
  color: var(--accent);
}

.command-bar-step {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.command-bar.is-running {
  border-color: var(--accent-border);
}

.command-bar-spinner {
  width: 13px;
  height: 13px;
  margin-left: 6px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

.toast-stack {
  position: fixed;
  /* above the command bar, so a toast never lands on the controls */
  bottom: 78px;
  right: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px 11px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-tertiary);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  animation: toast-in var(--dur-slow) var(--ease);
}

.toast.success {
  border-left-color: var(--success);
}

.toast.danger {
  border-left-color: var(--danger);
}

.toast.warning {
  border-left-color: var(--warning);
}

.toast.info {
  border-left-color: var(--info);
}

.toast .toast-body {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}

.toast .toast-close {
  flex: none;
  margin: -3px -4px 0 0;
  width: 24px;
  height: 24px;
}

.toast.leaving {
  animation: toast-out var(--dur) var(--ease) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* --- skeletons -------------------------------------------------------------- */

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 25%, #e9edf3 40%, var(--surface-3) 55%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  color: transparent !important;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* --- empty states ----------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 36px 20px;
  color: var(--text-secondary);
}

.empty .empty-icon {
  font-size: 22px;
  opacity: 0.6;
}

.empty strong {
  font-weight: 600;
  color: var(--text);
}

.empty p {
  font-size: var(--fs-sm);
  max-width: 340px;
}

.empty .btn {
  margin-top: 8px;
}

/* --- drawer ----------------------------------------------------------------- */

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(22, 24, 29, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease);
}

.drawer-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  width: min(460px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease), visibility var(--dur-slow);
  visibility: hidden;
}

.drawer.open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-header .drawer-title {
  flex: 1;
  min-width: 0;
}

.drawer-header h2 {
  font-size: var(--fs-md);
  line-height: 1.35;
}

.drawer-header .pill {
  margin-top: 6px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.drawer-footer select {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  font-size: var(--fs-sm);
}

.drawer-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.drawer-meta .meta-item span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.drawer-meta .meta-item strong {
  font-size: var(--fs-sm);
  font-weight: 550;
  overflow-wrap: break-word;
}

.drawer-block h4 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.drawer-block p {
  font-size: var(--fs-sm);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.drawer-block .drawer-block-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.drawer-hint {
  margin-top: 8px;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  line-height: 1.5;
}

.popover-note {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

.drawer-block textarea {
  width: 100%;
  font-size: var(--fs-sm);
}

.draft-quote {
  padding: 10px 12px;
  border-left: 3px solid var(--accent-border);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--accent-soft);
}

/* --- studio ------------------------------------------------------------------ */

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.studio-chat-card {
  display: flex;
  flex-direction: column;
  /* Tall enough to hold a conversation without the page itself scrolling. */
  height: calc(100vh - 280px);
  min-height: 460px;
  padding-bottom: 0;
}

.studio-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 12px;
}

.studio-chat-card .composer {
  margin: 0 -16px;
  border-top: 1px solid var(--border);
}

/* What the assistant changed, and the way back. */
.voice-change {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 3px 6px 3px 10px;
  border: 1px solid var(--accent-border);
  border-radius: var(--r-full);
  background: var(--accent-soft);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  align-self: flex-start;
}

.voice-change.is-undone {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text-tertiary);
}

.voice-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.voice-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voice-field > span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.voice-field > span small {
  margin-left: 6px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.voice-field textarea {
  width: 100%;
  font-size: var(--fs-sm);
  resize: vertical;
}

.voice-field select {
  width: 100%;
  font-size: var(--fs-sm);
}

.voice-limits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.voice-limits label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.voice-switches {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.voice-actions .composer-hint {
  margin-left: auto;
}

@media (max-width: 1100px) {
  .studio-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .studio-chat-card {
    height: auto;
    min-height: 420px;
  }
}

/* --- drawer: relevant work -------------------------------------------------- */

.drawer-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.drawer-block-head h4 {
  margin-bottom: 0;
}

.work-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.work-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  min-width: 0;
}

.work-row .cell-link {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-row .cell-muted {
  margin-left: auto;
  flex: none;
  font-size: var(--fs-xs);
}

/* --- drawer: new lead form -------------------------------------------------- */

.drawer-hint {
  margin-bottom: 14px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.drawer-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drawer-form label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.drawer-form input,
.drawer-form textarea {
  width: 100%;
  font-size: var(--fs-sm);
}

/* --- modal ------------------------------------------------------------------ */

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(22, 24, 29, 0.45);
}

.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  animation: modal-in var(--dur-slow) var(--ease);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px 12px;
}

.modal-body {
  padding: 0 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.picker-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
}

.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: var(--fs-sm);
  cursor: pointer;
}

.picker-item:hover {
  background: var(--surface-2);
}

.picker-item .picker-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}

/* --- avatar ----------------------------------------------------------------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  font-size: var(--fs-sm);
  font-weight: 650;
  color: #fff;
  background: var(--accent);
  -webkit-user-select: none;
  user-select: none;
}

/* --- app shell --------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 16px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #6a8cff);
  color: #fff;
  font-weight: 750;
  font-size: 15px;
  box-shadow: var(--shadow-xs);
}

.sidebar-brand strong {
  display: block;
  font-size: var(--fs-base);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.sidebar-brand span {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: 550;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.side-nav a:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}

.side-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.side-nav a svg {
  width: 17px;
  height: 17px;
  flex: none;
}

.side-nav .nav-label {
  flex: 1;
}

.nav-badge {
  min-width: 19px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 650;
  text-align: center;
  line-height: 19px;
  font-variant-numeric: tabular-nums;
}

.nav-run-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--info);
  animation: pulse 1.6s var(--ease) infinite;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.sidebar-footer #statePill {
  align-self: flex-start;
  margin-bottom: 5px;
}

.sidebar-task {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 6px;
}

/* Footer actions mirror the nav items so they collapse the same way. */
.sidebar-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sidebar-action:hover {
  background: var(--surface-3);
  color: var(--text);
}

.sidebar-action svg {
  width: 17px;
  height: 17px;
  flex: none;
}

/* --- collapsed sidebar ---------------------------------------------------------- */

/* Read by the app grid and by the command bar, which centres over the content
   column — one value keeps them in step when the sidebar collapses. */
.app.sidebar-collapsed {
  --sidebar-w: 60px;
}

.sidebar-collapsed .sidebar {
  padding: 18px 8px 14px;
  align-items: stretch;
}

.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 2px 0 16px;
}

.sidebar-collapsed .sidebar-brand > div,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .sidebar-task {
  display: none;
}

.sidebar-collapsed .side-nav a,
.sidebar-collapsed .sidebar-action {
  justify-content: center;
  padding: 9px 0;
  gap: 0;
}

.sidebar-collapsed .side-nav a {
  position: relative;
}

/* the unread count rides the icon instead of sitting beside a label */
.sidebar-collapsed .nav-badge {
  position: absolute;
  top: 2px;
  right: 6px;
  min-width: 16px;
  line-height: 16px;
  font-size: 10px;
}

.sidebar-collapsed .nav-run-dot {
  position: absolute;
  top: 6px;
  right: 10px;
}

.sidebar-collapsed .sidebar-footer {
  align-items: center;
  padding: 12px 0 0;
}

.sidebar-collapsed .sidebar-footer #statePill {
  align-self: center;
  width: 24px;
  height: 24px;
  padding: 0;
  justify-content: center;
  font-size: 0;
  border-radius: 50%;
}

.sidebar-collapsed .sidebar-footer #statePill::before {
  margin: 0;
}

/* the caret points the other way once collapsed */
.sidebar-collapsed .toggle-caret {
  transform: translateX(2px) scaleX(-1);
  transform-origin: 14.25px 12px;
}

/* --- views -------------------------------------------------------------------- */

.views {
  min-width: 0;
  /* the bottom padding clears the docked command bar */
  padding: 26px 30px 96px;
}

.view {
  max-width: 1160px;
  margin: 0 auto;
}

/* The grid is a data surface, not prose — it should use every pixel available,
   which is the whole point of being able to collapse the sidebar. */
.view[data-view="leads"] {
  max-width: none;
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.view-header h1:focus-visible {
  box-shadow: none;
}

.view-sub {
  margin-top: 3px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* --- overview ------------------------------------------------------------------ */

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.overview-main,
.overview-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.status-list {
  display: flex;
  flex-direction: column;
}

.status-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
}

.status-list > div + div {
  border-top: 1px solid var(--border);
}

.status-list dt {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  font-weight: 500;
  flex: none;
}

.status-list dd {
  font-size: var(--fs-sm);
  font-weight: 550;
  text-align: right;
  overflow-wrap: break-word;
  min-width: 0;
}

.status-card-stop {
  margin-top: 14px;
  width: 100%;
}

.readiness-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
}

.readiness-item + .readiness-item {
  border-top: 1px solid var(--border);
}

.readiness-item .item-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.readiness-item p {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  margin-top: 1px;
}

.readiness-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 10px;
}

.missing-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
}

.missing-list:empty {
  margin: 0;
}

.missing-list li {
  font-size: var(--fs-xs);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}

.summary-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.summary-lists h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.summary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: var(--fs-sm);
}

.summary-list li {
  padding-left: 14px;
  position: relative;
  overflow-wrap: break-word;
}

.summary-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-strong);
}

.summary-list li.summary-muted {
  color: var(--text-tertiary);
}

.summary-list li.summary-muted::before {
  display: none;
}

#summaryErrors li::before {
  background: var(--danger);
}

/* --- leads grid: view tabs -------------------------------------------------------- */

.view-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.view-tab-strip {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}

.view-tab-strip::-webkit-scrollbar {
  display: none;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  padding: 7px 12px;
  margin-bottom: -1px;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.view-tab:hover {
  background: var(--surface-3);
  color: var(--text);
}

.view-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.view-tab-icon {
  font-size: 11px;
  opacity: 0.85;
}

.view-tab-dot {
  color: var(--warning);
  font-size: 16px;
  line-height: 0;
}

/* --- leads grid: toolbar ----------------------------------------------------------- */

.grid-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toolbar-button {
  gap: 6px;
}

.toolbar-button.is-set {
  background: var(--accent-soft);
  color: var(--accent);
}

.toolbar-count {
  min-width: 16px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.toolbar-button:not(.is-set) .toolbar-count {
  background: var(--surface-3);
  color: var(--text-tertiary);
}

.grid-toolbar .leads-search-wrap {
  margin-left: auto;
  max-width: 260px;
}

.grid-toolbar .leads-search-wrap input {
  min-height: 32px;
  font-size: var(--fs-sm);
}

.dirty-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--warning-border);
  border-radius: var(--r-md);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--fs-sm);
  font-weight: 550;
}

.dirty-bar-actions {
  display: flex;
  gap: 6px;
}

/* --- leads grid: table -------------------------------------------------------------- */

.grid-wrap {
  position: relative;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  /* leaves room for the leads footer and the docked command bar below it */
  max-height: calc(100vh - 400px);
  min-height: 260px;
}

.grid-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
  /* Fixed layout only engages with a definite width — an intrinsic keyword like
     max-content silently falls back to auto layout, where a column can never be
     narrower than its widest cell. The exact pixel width is set from JS. */
  table-layout: fixed;
  width: max-content;
}

.grid-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.grid-table th:hover {
  background: var(--surface-3);
}

.grid-table th .sort-arrow {
  margin-left: 5px;
  font-size: 8px;
  color: var(--accent);
}

/* drag the right edge of a header to resize that column */
.col-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
  touch-action: none;
}

.col-resize::after {
  content: "";
  position: absolute;
  top: 0;
  left: 3px;
  width: 2px;
  height: 100%;
  background: transparent;
  transition: background-color var(--dur-fast) var(--ease);
}

.col-resize:hover::after,
.col-resize.dragging::after {
  background: var(--accent);
}

body.is-resizing {
  cursor: col-resize;
  -webkit-user-select: none;
  user-select: none;
}

.grid-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0 12px;
  height: 36px;
  vertical-align: middle;
  overflow: hidden;
  white-space: nowrap;
  background: var(--surface);
}

/* Truncation belongs to the text span, not the cell: an ellipsis on the cell
   renders stray dots next to pills and other non-text content. */
.cell .pill {
  max-width: 100%;
  overflow: hidden;
}

/* --- leads grid: multi-select ------------------------------------------------------ */

/* The checkbox gutter is the true first column, so it takes left: 0 and the
   frozen title column starts after it. Both stay put while the rest scrolls. */
.grid-table th.select-all,
.grid-table td.row-select {
  position: sticky;
  left: 0;
  z-index: 1;
  padding: 0;
  text-align: center;
  cursor: default;
}

.grid-table th.select-all {
  z-index: 3;
}

.grid-table th.select-all:hover {
  background: var(--surface-2);
}

.row-check {
  width: 14px;
  height: 14px;
  margin: 0;
  vertical-align: middle;
  accent-color: var(--accent);
  cursor: pointer;
}

/* the title column stays put while the rest scrolls sideways */
.grid-table th.col-frozen,
.grid-table td.col-frozen {
  position: sticky;
  left: var(--select-col-w);
  z-index: 1;
  border-right: 1px solid var(--border-strong);
}

.grid-table th.col-frozen {
  z-index: 3;
}

.grid-row:hover td {
  background: var(--surface-2);
}

.grid-row[aria-selected="true"] td {
  background: var(--accent-soft);
}

/* ticked for a bulk action — distinct from the drawer's expanded row */
.grid-row.is-picked td {
  background: var(--accent-soft);
}

.grid-row.is-picked:hover td {
  background: #e4eaff;
}

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--accent-soft);
  font-size: var(--fs-sm);
}

.selection-count {
  font-weight: 600;
  color: var(--accent);
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.selection-divider {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--border-strong);
}

.selection-actions .btn-ghost.danger {
  color: var(--danger);
}

.selection-actions .btn-ghost.is-armed {
  background: var(--danger);
  color: #fff;
}

/* the job was pulled from Twine — keep the row, drop the promise */
.grid-row.is-gone td {
  color: var(--text-tertiary);
}

.grid-row.is-gone td[data-column="lead_name"] .cell-text {
  text-decoration: line-through;
}

.cell {
  position: relative;
}

.cell.editable {
  cursor: text;
}

.cell.editable:hover {
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.cell-text,
.cell-link {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.cell-muted::after {
  content: "—";
  color: var(--text-tertiary);
}

.cell-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  font-size: 11px;
  color: #fff;
}

.cell-check.checked {
  background: var(--success);
  border-color: var(--success);
}

.cell-input {
  width: calc(100% + 4px);
  margin-left: -2px;
  min-height: 28px;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--accent);
  box-shadow: var(--focus-ring);
  font-size: var(--fs-sm);
}

.cell-clip {
  color: var(--text-secondary);
}

/* Pinned to the right edge and stacked above the title text, so it stays a full
   22px target no matter how narrow the column is dragged. */
.row-expand {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  width: 22px;
  height: 22px;
  font-size: 11px;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease);
}

.grid-row:hover .row-expand {
  opacity: 1;
  pointer-events: auto;
  background: var(--surface-2);
}

/* Only pad while it is showing: the text ellipsises short of the button instead
   of running underneath it, and nothing shifts when the row is not hovered. */
.grid-row:hover td.has-expand {
  padding-right: 34px;
}

.row-expand:hover {
  color: var(--accent);
  border-color: var(--accent-border);
}

/* group rows */
.group-row td {
  background: var(--surface-3);
  padding: 0;
  position: sticky;
  left: 0;
}

.group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 7px 12px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.group-caret {
  color: var(--text-tertiary);
  font-size: 10px;
}

.group-count {
  padding: 0 7px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* --- popover ------------------------------------------------------------------------- */

.popover {
  position: fixed;
  z-index: 75;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur) var(--ease);
}

.popover-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.popover-title:not(:first-child) {
  margin-top: 14px;
}

.popover-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popover-list.scroll {
  max-height: 260px;
  overflow-y: auto;
}

.popover-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  padding: 6px 9px;
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
}

.popover-item:hover {
  background: var(--surface-2);
}

.popover-item.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.popover-item.danger {
  color: var(--danger);
}

.popover-item.danger:hover {
  background: var(--danger-soft);
}

.popover-item-type {
  font-size: 10px;
  color: var(--text-tertiary);
}

.popover-group-label {
  padding: 8px 9px 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.popover-empty {
  padding: 10px 9px;
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
}

.popover-search,
.popover-input,
.popover-select,
.popover-textarea {
  min-height: 30px;
  padding: 4px 8px;
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.popover-search,
.popover-input.wide,
.popover-textarea {
  width: 100%;
}

.popover-select.tiny {
  min-width: 62px;
}

.popover-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.popover-footer.start {
  justify-content: flex-start;
}

.popover-hint {
  margin-right: auto;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

/* filter / sort rows */
.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-row .popover-select,
.filter-row .popover-input {
  min-width: 0;
  flex: 1;
}

.filter-joiner {
  flex: none;
  width: 52px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
}

.value-multi {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  flex: 1;
  padding: 4px 0;
}

.value-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text);
}

/* field picker rows */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
}

.field-row:hover {
  background: var(--surface-2);
}

.field-row-name {
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-row-controls {
  display: flex;
  gap: 2px;
  flex: none;
}

.btn-icon-xs {
  width: 22px;
  height: 22px;
  font-size: 11px;
}

.btn-icon-xs:disabled {
  opacity: 0.3;
  cursor: default;
}

/* --- leads ---------------------------------------------------------------------- */

.leads-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.leads-search-wrap {
  position: relative;
  flex: 1;
  max-width: 380px;
}

.leads-search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.leads-search-wrap input {
  width: 100%;
  padding-left: 34px;
}

.leads-count {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.leads-chip-row {
  margin-bottom: 14px;
}

.lead-title-cell {
  max-width: 340px;
}

.lead-title-cell .lead-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-chip {
  display: inline-block;
  min-width: 34px;
  text-align: center;
  padding: 1px 7px;
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: var(--surface-3);
  color: var(--text-secondary);
}

.score-chip.high {
  background: var(--success-soft);
  color: var(--success);
}

.score-chip.mid {
  background: var(--warning-soft);
  color: var(--warning);
}

.leads-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.leads-footer .showing {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* --- messages --------------------------------------------------------------------- */

.messages-card {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  padding: 0;
  overflow: hidden;
  height: calc(100vh - 200px);
  min-height: 460px;
}

.thread-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
}

.thread-tools {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  border-bottom: 1px solid var(--border);
}

.thread-tools input {
  width: 100%;
  min-height: 34px;
  font-size: var(--fs-sm);
}

.thread-tools .segmented {
  display: flex;
}

.thread-tools .segmented button {
  flex: 1;
  padding: 4px 6px;
  font-size: var(--fs-xs);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 6px;
}

.thread-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--r-md);
  padding: 9px 10px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.thread-item:hover {
  background: var(--surface-2);
}

.thread-item.active {
  background: var(--accent-soft);
}

.thread-item .avatar {
  grid-row: 1 / 3;
  width: 36px;
  height: 36px;
}

.thread-item .thread-name {
  font-size: var(--fs-sm);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-item.unread .thread-name {
  font-weight: 700;
}

.thread-item .thread-time {
  grid-column: 3;
  grid-row: 1;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
}

.thread-item .thread-preview {
  grid-column: 2;
  grid-row: 2;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-item.unread .thread-preview {
  color: var(--text);
}

.thread-item .thread-badges {
  grid-column: 3;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.thread-mini-pill {
  font-size: 10px;
  font-weight: 650;
  padding: 0 6px;
  border-radius: var(--r-full);
  line-height: 16px;
  white-space: nowrap;
}

.thread-mini-pill.queued {
  background: var(--warning-soft);
  color: var(--warning);
}

.thread-mini-pill.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.thread-sparkle {
  font-size: 11px;
  color: var(--violet);
}

/* thread view */
.thread-pane-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thread-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.thread-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.thread-back {
  display: none;
}

.thread-title {
  flex: 1;
  min-width: 0;
}

.thread-title h2 {
  font-size: var(--fs-md);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-title p {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.thread-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.lead-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--r-full);
  padding: 3px 11px;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.lead-chip:hover {
  background: #e2e9ff;
}

.lead-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
}

.date-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 8px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
}

.date-sep::before,
.date-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.bubble-row {
  display: flex;
  flex-direction: column;
  margin: 2px 0;
}

.bubble-row.in {
  align-items: flex-start;
}

.bubble-row.out {
  align-items: flex-end;
}

.bubble {
  max-width: min(78%, 560px);
  padding: 9px 13px;
  border-radius: 14px;
  font-size: var(--fs-base);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.bubble-row.in .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.bubble-row.out .bubble {
  background: var(--bubble-out);
  border: 1px solid var(--accent-border);
  border-bottom-right-radius: 5px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.bubble-meta .delivery-ok {
  color: var(--success);
}

.bubble-meta .meta-pill {
  font-size: 10px;
  font-weight: 650;
  padding: 0 6px;
  border-radius: var(--r-full);
  line-height: 15px;
}

.bubble-meta .meta-pill.queued {
  background: var(--warning-soft);
  color: var(--warning);
}

.bubble-meta .meta-pill.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.bubble-error {
  margin-top: 2px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--danger);
  max-width: min(78%, 560px);
  text-align: right;
}

.bubble-meta .bubble-retry {
  border: none;
  background: none;
  padding: 0;
  font-size: 11px;
  font-weight: 650;
  color: var(--accent);
  cursor: pointer;
}

.bubble-meta .bubble-retry:hover {
  text-decoration: underline;
}

/* AI draft card */
.draft-card {
  margin: 0 16px 10px;
  border: 1.5px dashed var(--accent-border);
  border-radius: var(--r-md);
  background: var(--accent-soft);
  padding: 12px 14px;
}

.draft-card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--accent);
}

.draft-card-head .draft-age {
  font-weight: 500;
  color: var(--text-tertiary);
}

.draft-card textarea {
  width: 100%;
  border-color: var(--accent-border);
  background: var(--surface);
  font-size: var(--fs-sm);
  min-height: 66px;
}

.draft-warnings {
  margin: 6px 0 0;
  font-size: var(--fs-xs);
  color: var(--warning);
}

.draft-stale {
  margin: 6px 0 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--warning);
}

.draft-card-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
}

.draft-card-actions .btn-ghost {
  margin-left: auto;
}

.draft-skeleton {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.draft-skeleton .skeleton {
  height: 12px;
}

.draft-skeleton .skeleton:last-child {
  width: 60%;
}

/* composer */
.composer {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin: 0;
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 180px;
  resize: none;
  font-size: var(--fs-base);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.composer-hint {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

/* --- activity ---------------------------------------------------------------------- */

.activity-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.log-viewer {
  position: relative;
}

.log-output {
  height: min(60vh, 620px);
  overflow-y: auto;
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--log-bg);
  color: var(--log-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  overscroll-behavior: contain;
}

.log-line {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.log-line .log-time {
  color: #58637a;
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}

.log-line[data-stream="stderr"] {
  color: #ff9f9f;
}

.log-line[data-stream="system"] {
  color: #8ab4ff;
  font-weight: 600;
}

.log-empty {
  color: #58637a;
  font-style: italic;
}

.jump-latest {
  position: absolute;
  bottom: 14px;
  right: 18px;
  z-index: 2;
  border: none;
  border-radius: var(--r-full);
  background: rgba(233, 238, 246, 0.95);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

.usage-model-list {
  display: flex;
  flex-direction: column;
}

.usage-model-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  flex-wrap: wrap;
}

.usage-model-row + .usage-model-row {
  border-top: 1px solid var(--border);
}

.usage-model-name {
  font-weight: 600;
  font-size: var(--fs-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.usage-model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.usage-totals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

/* --- settings ----------------------------------------------------------------------- */

.settings-column {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.settings-inline .interval-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-inline input[type="number"] {
  width: 84px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.settings-note {
  margin-top: 10px;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.submit-confirm {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--danger-border);
  border-radius: var(--r-md);
  background: var(--danger-soft);
}

.submit-confirm p {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--danger);
  margin-bottom: 9px;
}

.submit-confirm .actions {
  display: flex;
  gap: 8px;
}

/* --- connect twine modal -------------------------------------------------------------- */

.connect-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(22, 24, 29, 0.5);
}

.connect-dialog {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(1080px, 100%);
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  gap: 12px;
}

.connect-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.connect-header .actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.connect-screen-wrap {
  aspect-ratio: 1280 / 800;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: #101319;
}

.connect-screen {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.connect-hint {
  font-size: var(--fs-sm);
}

/* --- responsive ------------------------------------------------------------------------ */

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: auto;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand {
    padding: 0;
  }

  .sidebar-brand > div {
    display: none;
  }

  .side-nav {
    flex-direction: row;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .side-nav a {
    padding: 6px 10px;
    white-space: nowrap;
  }

  .sidebar-footer {
    margin: 0;
    padding: 0;
    border: none;
    flex-direction: row;
    align-items: center;
  }

  .sidebar-task {
    display: none;
  }

  .views {
    padding: 18px 16px 40px;
  }

  .overview-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 719px) {
  .view-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table .col-hide-sm {
    display: none;
  }

  .summary-lists {
    grid-template-columns: 1fr;
  }

  /* messages become two screens: list, then thread */
  .messages-card {
    grid-template-columns: 1fr;
    height: calc(100vh - 170px);
  }

  .thread-pane {
    border-right: none;
  }

  .messages-card.thread-open .thread-pane {
    display: none;
  }

  .messages-card:not(.thread-open) .thread-pane-view {
    display: none;
  }

  .thread-back {
    display: inline-flex;
  }

  .thread-header {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .thread-title {
    flex: 1 1 55%;
  }

  .thread-header-actions {
    flex-wrap: wrap;
  }

  .bubble {
    max-width: 88%;
  }

  .drawer {
    width: 100vw;
  }

  .drawer-meta {
    grid-template-columns: 1fr;
  }
}

/* --- motion preferences ----------------------------------------------------------------- */

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

  .skeleton {
    animation: none;
  }
}

.connect-email-dialog { max-width: 540px; }
.connect-email-dialog form { display: grid; gap: 12px; margin: 20px 0; }
.connect-email-dialog form.hidden { display: none; }
.connect-email-dialog input { width: 100%; padding: 12px; }
#connectCode { font-size: 26px; letter-spacing: .3em; font-variant-numeric: tabular-nums; }
.connect-email-dialog .actions { display: flex; gap: 8px; flex-wrap: wrap; }
