/* ============================================================
   DNA ME theme - the look of crm.dna-me.net, as a drop-in file.
   ============================================================
   SOURCE OF TRUTH: DNAMECRMMINI/frontend/css/main.css. Everything above the
   "Additive" fence below is copied from it verbatim, section by section, and
   the :root block MUST stay identical: DNAMESIGNALORDERS/backend/src/theme.test.ts
   compares every token against the CRM's file whenever that repository is
   checked out beside this one. Do not edit tokens here; edit them in the CRM
   and copy.

   ONE DELIBERATE EDIT: the CRM's `#content { overflow-x: hidden }` is written
   here as `.content { ... }`, because this file must not know an element id.
   The CRM's main#content.content still matches.

   TO ADOPT IN THE CRM: replace the matching sections of main.css with this
   file and keep the CRM-only sections (pipeline, tag picker, timeline,
   notifications, GDPR, drop zone, search dropdown) after it. The fonts are
   served at /fonts in both apps, so the @font-face block needs no change.

   WHAT THE PANEL ADDS is fenced at the end, written with tokens only, and is
   harmless in the CRM: an in-flow toast, a warning toast, a no-JavaScript
   drawer toggle, focus rings, reduced motion, monospace, a gated button, and
   the gate track. ADR-0012 in the panel repository has the reasoning.
   ============================================================ */

/* Local fonts (DSGVO-compliant, no external requests) */
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/dm-sans-v17-latin-regular.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/dm-sans-v17-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/dm-sans-v17-latin-600.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/dm-sans-v17-latin-700.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 800; font-display: swap; src: url('/fonts/dm-sans-v17-latin-800.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/inter-v20-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/inter-v20-latin-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/inter-v20-latin-700.woff2') format('woff2'); }

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #1f2b3d;
  --border: #2d3a4f;
  --border-focus: #3b82f6;
  --text: #e6edf3;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --success: #22c55e;
  --danger: #dc2626;
  --warning: #d97706;

  /* A recessed panel INSIDE a surface: one step darker than --surface, so an
     inset block reads as sunk into the card rather than as a hole cut in it.
     Used by the lead dimension strip.

     This theme is dark-only - there is no prefers-color-scheme block and no
     light variant anywhere below. That is exactly why reading this token with a
     near-white fallback rendered a white panel while the token was missing: the
     fallback was the only value ever applied. Do not reintroduce light fallbacks
     at call sites; a missing token should fail visibly, and
     tests/config/cssTokens.test.js now catches one before it can. */
  --bg-subtle: #141c27;

  /* Attention without alarm: the tint behind a cell that disagrees with the
     poster. A neutral --bg-subtle would be readable but would lose the signal,
     which is the whole reason that cell is coloured at all. */
  --warning-bg: rgba(217, 119, 6, 0.14);

  /* Aliases for names already in use across the SPA. Defining them is cheaper
     and far safer than renaming five call sites - and --error in particular was
     being used with NO fallback, so the "High" priority badge and the "Revoked"
     label were rendering with no colour at all. */
  --error: var(--danger);
  --text-secondary: var(--text-muted);
  --warning-color: var(--warning);

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.25);
  --transition: 150ms ease;
  --sidebar-w: 240px;
  --font: 'DM Sans', 'Inter', system-ui, sans-serif;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 48px;

  /* Type scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-lg: 17px;
  --fs-xl: 22px;

  --radius-lg: 12px;

  /* Minimum interactive target on touch devices */
  --touch: 44px;

  /* Canonical breakpoint: 768px. CSS vars can't be used inside @media,
     so the value is hard-coded in each query but documented here. */
}

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

html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* ---- Login ---- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}
.login-card h1 {
  text-align: center;
  color: var(--accent);
  margin-bottom: 24px;
  font-size: 24px;
}

/* ---- Layout ---- */
#main-app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  border-right: 1px solid var(--border);
}
.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 20px; font-weight: 700; color: #fff; }
.logo-sub { font-size: 14px; font-weight: 400; color: var(--accent); margin-left: 4px; }

.nav-links {
  list-style: none;
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}
.nav-links li a {
  display: block;
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.nav-links li a:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-links li a.active {
  background: rgba(59,130,246,0.12);
  color: #fff;
  border-left-color: var(--accent);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}

.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 32px;
  min-height: 100vh;
}

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color var(--transition);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.6; }
select option { background: var(--surface); color: var(--text); }
textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.btn:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-accent { background: var(--success); color: #fff; border-color: var(--success); }
.btn-accent:hover { opacity: 0.9; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 8px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2 { font-size: 18px; font-weight: 600; }
.card-header h3 { font-size: 16px; font-weight: 600; }

/* ---- Data Grid ---- */
.data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-grid th, .data-grid td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-grid th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.data-grid th.sortable { cursor: pointer; user-select: none; }
.data-grid th.sortable:hover { color: var(--accent); }
.data-grid tbody tr { transition: background var(--transition); }
.data-grid tbody tr:hover { background: var(--surface-hover); }
.data-grid tbody tr.clickable { cursor: pointer; }
.clickable-row { transition: background var(--transition); border-radius: var(--radius-sm); }
.clickable-row:hover { background: var(--surface-hover); }
.data-grid a { color: var(--accent); text-decoration: none; }
.data-grid a:hover { color: var(--accent-hover); }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.pagination .btn { margin-left: 4px; }

/* ---- Page Header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input { max-width: 280px; }

/* ---- Tags/Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(59,130,246,0.18);
  color: var(--accent);
}
.badge-accent { background: rgba(34,197,94,0.18); color: var(--success); }
.badge-warning { background: rgba(217,119,6,0.18); color: #fbbf24; }
.badge-danger { background: rgba(220,38,38,0.18); color: #f87171; }
.badge-neutral { background: rgba(139,156,179,0.15); color: var(--text-muted); }

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- Person Tag Badges (accessible: icon + label + tooltip) ---- */
.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tag-badge .tag-icon { font-size: 10px; opacity: 0.85; }

/* Category shapes via left-border */
.tag-cat--outreach      { border-left: 3px solid; border-radius: 2px 10px 10px 2px; }
.tag-cat--relationship  { border-radius: 3px; }
.tag-cat--lifecycle     { border-radius: 10px; }
.tag-cat--data_quality  { border-left: 3px dashed; border-radius: 2px 10px 10px 2px; }

/* Color variants */
.tag-color--gray   { background: rgba(139,156,179,0.15); color: var(--text-muted); border-color: rgba(139,156,179,0.3); }
.tag-color--blue   { background: rgba(59,130,246,0.15); color: #60a5fa; border-color: rgba(59,130,246,0.3); }
.tag-color--teal   { background: rgba(20,184,166,0.15); color: #2dd4bf; border-color: rgba(20,184,166,0.3); }
.tag-color--orange { background: rgba(249,115,22,0.15); color: #fb923c; border-color: rgba(249,115,22,0.3); }
.tag-color--yellow { background: rgba(234,179,8,0.15); color: #facc15; border-color: rgba(234,179,8,0.3); }
.tag-color--purple { background: rgba(168,85,247,0.15); color: #c084fc; border-color: rgba(168,85,247,0.3); }
.tag-color--red    { background: rgba(239,68,68,0.15); color: #f87171; border-color: rgba(239,68,68,0.3); }
.tag-color--green  { background: rgba(34,197,94,0.15); color: #4ade80; border-color: rgba(34,197,94,0.3); }
.tag-color--gold   { background: rgba(234,179,8,0.18); color: #fbbf24; border-color: rgba(234,179,8,0.35); }

/* Do-not-contact warning banner */
.dnc-banner {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  gap: 0;
}
.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  min-width: 280px;
  color: var(--text);
  animation: slideIn 200ms ease;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Error ---- */
.error-msg { color: #f87171; font-size: 13px; margin-top: 8px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ---- Stats Row ---- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-card-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* Compact stats: dense auto-fit cards so 3-4 fit per row on phones, more on
   desktop, filling the width without wasted space or horizontal overflow. */
.stats-row.compact { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: var(--sp-2); }
.stats-row.compact .stat-card { padding: var(--sp-3) var(--sp-2); text-align: center; }
.stats-row.compact .stat-card-value { font-size: 22px; }
.stats-row.compact .stat-card-label { font-size: var(--fs-xs); margin-top: 0; }

/* Clickable stat cards drill into a filtered page view */
.stat-card-link { display: block; text-decoration: none; color: inherit; transition: border-color var(--transition), background var(--transition); }
.stat-card-link:hover { border-color: var(--accent); background: var(--surface-hover); }

/* Dashboard stacked sections: tasks above activity, full width on every screen */
.dash-stack { display: flex; flex-direction: column; gap: var(--sp-5); }

/* Active-filter banner (e.g. drill-down from a dashboard stat) */
.filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  background: rgba(59,130,246,0.10);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}

/* ---- Detail Layout ---- */
.detail-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}
/* Detail two-column layout stacks at the canonical breakpoint (see Responsive section). */
@media (max-width: 768px) { .detail-layout { grid-template-columns: 1fr; } }

/* ---- Utility ---- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.hidden { display: none !important; }

/* ---- Icon button ---- */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  position: relative;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--surface-hover); }

/* ============================================================
   Responsive (<= 768px, canonical breakpoint --bp-md)
   All mobile overrides live below this banner. Base rules above
   are the desktop layout; new foundation patterns are authored
   mobile-first and enhanced with min-width where needed.
   Sections: nav drawer | data-grid cards | pipeline | modals |
   touch targets | page-header/toolbar stacking
   ============================================================ */

/* ---- Nav: mobile top bar + slide-out drawer ---- */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 90;
  }
  .mobile-topbar .logo { font-size: 17px; }
  .mobile-topbar .logo-sub { font-size: 12px; }
  .mobile-topbar #mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 95;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .content { margin-left: 0; padding: 72px 16px 16px; }

  /* Safety net: nested kanban board / tab / pill bars keep their own
     overflow-x:auto scrollers, so this only clips accidental page-level
     horizontal overflow (never intended scroll regions). */
  .content { overflow-x: hidden; } /* was #content in the CRM; see header */
}


/* ---- Data grid: stacked, labelled cards on mobile ---- */
@media (max-width: 768px) {
  .data-grid thead { display: none; }
  .data-grid,
  .data-grid tbody,
  .data-grid tr,
  .data-grid td { display: block; width: 100%; }
  .data-grid tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
  }
  .data-grid tbody tr:hover { background: var(--surface); }
  .data-grid td {
    border: 0;
    padding: var(--sp-1) 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
    text-align: right;
  }
  .data-grid td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    flex-shrink: 0;
  }
  .data-grid td.mobile-full {
    display: block;
    text-align: left;
    padding-top: var(--sp-2);
  }
  .data-grid td.mobile-full::before { display: none; }
}

/* ---- Tabs scroll horizontally on mobile ---- */
@media (max-width: 768px) {
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { flex-shrink: 0; }
}

/* ---- Mobile modals - full-screen sheet ---- */
@media (max-width: 768px) {
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: 0;
    padding: 16px;
  }
  .modal-backdrop { align-items: stretch; }

  /* No hover on touch, so the Adjust button must be permanently visible */
  .timeline-item .tl-edit-btn { opacity: 1; }
  .tl-inline-edit { flex-direction: column; align-items: stretch; }

  /* Stage advance buttons in lead detail: 2-up grid with tappable height */
  #stage-buttons { gap: 8px; }
  #stage-buttons .btn {
    flex: 1 1 calc(50% - 4px);
    min-height: 40px;
  }

  /* Form rows always stack on the full-screen sheet (covers 3-col rows too) */
  .form-row { grid-template-columns: 1fr; }
  .form-group { margin-bottom: var(--sp-4); }

  /* Modal footer: sticky, full-bleed action bar so Save/Cancel are always reachable */
  .modal-footer {
    position: sticky;
    bottom: 0;
    flex-wrap: wrap;
    margin: var(--sp-4) calc(-1 * var(--sp-4)) 0;
    padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .modal-footer .btn { flex: 1 1 auto; min-height: var(--touch); }
}

/* ---- Touch targets + header/toolbar stacking ---- */
@media (max-width: 768px) {
  .btn,
  .btn-icon,
  #mobile-menu-btn,
  .modal-close,
  input:not([type=checkbox]):not([type=radio]),
  select, textarea,
  .nav-links a,
  .pipeline-pill,
  .seg-btn {
    min-height: var(--touch);
  }
  .btn, .btn-icon, #mobile-menu-btn, .modal-close, .seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Page header: title over full-width primary action */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Toolbar: search + filters stack full-width */
  .toolbar > * { flex: 1 1 100%; }
  .search-input { max-width: none; }
}

/* ==== Additive: shared, not yet in the CRM ================================
   Tokens only. Every rule below is harmless when this file replaces the
   matching sections of the CRM's main.css. ============================ */

/* An in-flow toast: the server-rendered flash, placed at the top of .content
   rather than fixed in a corner. Same colours, same left border. */
.toast-inline {
  position: static;
  width: 100%;
  min-width: 0;
  animation: none;
  margin-bottom: var(--sp-4);
}
.toast-inline ul { margin: var(--sp-2) 0 0 var(--sp-5); }
.toast-warning { border-left: 4px solid var(--warning); }

/* The drawer without JavaScript. A visually-hidden checkbox precedes the
   sidebar; the hamburger and the backdrop are labels for it. The CRM's
   .sidebar.open rules stay, so both mechanisms coexist.
   Limits, stated: no Escape to close, no aria-expanded, no focus trap; every
   navigation is a full page load, which resets the state. */
.nav-toggle {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.nav-toggle-btn { display: none; }
@media (max-width: 768px) {
  .nav-toggle-btn {
    background: none;
    border: none;
    color: var(--text);
    padding: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
    min-width: var(--touch);
    border-radius: var(--radius-sm);
  }
  .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  .nav-toggle:checked ~ .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .nav-toggle:focus-visible ~ .mobile-topbar .nav-toggle-btn {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
  }
}

/* Focus rings. The CRM styles input focus only; keyboard users of the panel
   reach every control. */
.btn:focus-visible, .btn-icon:focus-visible, .nav-links a:focus-visible,
.tab:focus-visible, a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

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

/* Identifiers and checksums. */
code, .mono {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* A button whose action the API gates: the marker sits in the control, so
   the asterisk in the note next to it has something to point at. */
.btn-gated { border-color: var(--warning); box-shadow: inset 0 0 0 1px var(--warning); }
.btn[disabled], .btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* The gate track: one job's gates in operational order, each in one of five
   states carried by a class AND by text (never colour alone). */
.gate-track {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  list-style: none;
  margin: 0; padding: 0;
}
.gate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 2px 8px 2px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.gate-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 11px;
  line-height: 1;
  color: var(--text-muted);
}
.gate--na .gate-mark { border-style: dashed; }
.gate--pending .gate-mark { background: transparent; }
.gate--blocking {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: #fbbf24;
}
.gate--blocking .gate-mark { background: var(--warning); border-color: var(--warning); color: #0f1419; }
.gate--unknown .gate-mark { border-style: dotted; }
.gate-track--lg { gap: var(--sp-3); margin: var(--sp-2) 0 var(--sp-3); }
.gate-track--lg .gate { font-size: var(--fs-sm); padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-2); }
.gate-track--lg .gate-mark { width: 20px; height: 20px; font-size: 13px; }
.gate-track--lg .gate + .gate::before {
  content: "";
  display: inline-block;
  width: var(--sp-4); height: 1px;
  background: var(--border);
  margin-right: var(--sp-2);
}
.gate-why { font-size: var(--fs-sm); color: var(--text-muted); margin: 0 0 var(--sp-3); }
.gate-why code { display: block; margin-top: var(--sp-1); }
