/* ============================================================
   Tatami Flow — Design System
   All tokens from DESIGN.md. Variable names mirror the prototype
   (app.jsx / BJJ Leads.html) so prototype CSS can be lifted directly.
   ============================================================ */

:root {
  /* Mat blue */
  --mat:        oklch(48% 0.16 252);
  --mat-strong: oklch(42% 0.18 252);
  --mat-soft:   oklch(94% 0.04 252);
  --mat-ring:   oklch(48% 0.16 252 / 0.20);
  --mat-fg-on:  #fff;

  /* Dark chrome */
  --ink-0:    #07090d;
  --ink-1:    #0d1117;
  --ink-2:    #161b22;
  --ink-3:    #1f2630;
  --ink-line: #232a35;

  /* Light content */
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface-2: #fafbfc;
  --line:      #e6e8ec;
  --line-2:    #eef0f3;

  /* Text — light mode */
  --fg:   #0f1218;
  --fg-2: #4b5462;
  --fg-3: #79828f;

  /* Text — dark backgrounds */
  --fg-on-dark:   #e7ebf1;
  --fg-on-dark-2: #99a3b0;
  --fg-on-dark-3: #5e6772;

  /* Source chip tones */
  --tone-indigo-bg:  #e7eaff; --tone-indigo-fg:  #3a3fc4; --tone-indigo-border: #c8cbf4;
  --tone-amber-bg:   #fdf1d4; --tone-amber-fg:   #8a6a14;
  --tone-orange-bg:  #ffe6d6; --tone-orange-fg:  #a14418;
  --tone-emerald-bg: #ddf3e6; --tone-emerald-fg: #1a6d44;
  --tone-teal-bg:    #d6f0ee; --tone-teal-fg:    #156866;
  --tone-violet-bg:  #ece1ff; --tone-violet-fg:  #5a3da6;
  --tone-neutral-bg: #eef0f3; --tone-neutral-fg: #495260;

  /* Semantic states */
  --success-bg:     #eaf4ec;
  --success-fg:     #1f5a36;
  --success-border: #c1dcc9;
  --danger:         #a23322;
  --danger-bg:      #fbe9e6;
  --danger-border:  #f1c8c0;
  --live-pulse:     #4ec38a;

  /* Radius */
  --radius-sm:  7px;
  --radius:     8px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-1: 0 1px 0 rgba(15,18,24,.04), 0 1px 2px rgba(15,18,24,.04);
  --shadow-2: 0 1px 0 rgba(15,18,24,.04), 0 4px 16px rgba(15,18,24,.08);
  --shadow-3: 0 12px 40px rgba(15,18,24,.14);

  /* Motion */
  --motion-fast:   120ms;
  --motion-base:   150ms;
  --motion-medium: 180ms;
  --motion-slow:   280ms;
  --easing-snap:   cubic-bezier(.3,.7,.4,1);

  /* Layout */
  --sidebar-w: 232px;

  /* Breakpoints (documented here because media queries cannot read custom
     properties): 768px collapses the shell to the bottom tab bar, 1100px
     collapses the lead card and lead-detail layouts to one column. */

  /* Control scale */
  --control-min-height: 44px;
  --control-font-size: 16px;

  /* Bottom tab bar (below 768px). This is the bar's own laid-out height —
     icon + gap + label + its padding, plus the top border — with a little
     margin to spare so real font metrics rounding up doesn't reopen the
     overlap. Both .tabbar and .content's reserve read from this token so
     they can't drift apart again. */
  --tabbar-h: 64px;
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

body {
  font-family: 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

.mono {
  font-family: 'Geist Mono', ui-monospace, monospace;
}

[x-cloak] { display: none !important; }

@keyframes slide-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   App Shell
   ============================================================ */

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

.main {
  min-width: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  background: var(--ink-0);
  color: var(--fg-on-dark);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid #0a0d12;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--mat) 0%, var(--mat-strong) 100%);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -.01em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.4);
  flex-shrink: 0;
}

.brand-mark svg { display: block; }

.brand-name {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--fg-on-dark-2);
  letter-spacing: 0;
  margin-top: 1px;
}

.nav-section {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-on-dark-3);
  padding: 14px 10px 6px;
}

.nav-item {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--fg-on-dark-2);
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: default;
  transition: background var(--motion-fast), color var(--motion-fast);
  width: 100%;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--ink-2);
  color: var(--fg-on-dark);
}

.nav-item.active {
  background: var(--ink-2);
  color: var(--fg-on-dark);
  box-shadow: inset 2px 0 0 var(--mat);
}

.nav-item .ni-icon {
  width: 16px;
  height: 16px;
  color: currentColor;
  flex-shrink: 0;
}

.nav-item .ni-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-on-dark-3);
  background: var(--ink-2);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.nav-item.active .ni-count {
  background: var(--mat);
  color: white;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 6px 0;
  border-top: 1px solid var(--ink-line);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #344256 0%, #1a2230 100%);
  color: #d5dbe5;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

.who { line-height: 1.25; }
.who-name { font-size: 13px; font-weight: 500; color: var(--fg-on-dark); }
.who-role  { font-size: 11px; color: var(--fg-on-dark-3); }

/* Settings' identity card sits on the light page background, not the dark
   sidebar, so it overrides the dark-only foreground tokens above. */
.identity-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.identity-card .who-name { color: var(--fg); }
.identity-card .who-role { color: var(--fg-2); }

/* ============================================================
   Tab bar (bottom nav below 768px, hidden at 768px and above)
   ============================================================ */

.tabbar {
  display: none;
  position: fixed;
  left: 0px;
  right: 0px;
  bottom: 0px;
  z-index: 10;
  background: var(--ink-0);
  border-top: 1px solid var(--ink-line);
  min-height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  min-height: var(--control-min-height);
  padding: 6px 4px;
  color: var(--fg-on-dark-2);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 500;
}

.tab-item .ni-icon {
  width: 18px;
  height: 18px;
}

.tab-item.active {
  color: var(--fg-on-dark);
  box-shadow: inset 0 2px 0 var(--mat);
}

/* ============================================================
   Page chrome
   ============================================================ */

.page-head {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 18px 32px 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.018em;
  margin: 0;
}

.page-sub {
  font-size: 13px;
  color: var(--fg-2);
  margin-top: 3px;
}

.page-head-right { display: flex; align-items: center; gap: 10px; }

.today-bar {
  background: var(--ink-1);
  color: var(--fg-on-dark);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 22px;
  border-bottom: 1px solid #050709;
}

.today-bar .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-on-dark-3);
  font-weight: 600;
}

.content {
  padding: 24px 32px 48px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-min-height);
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.005em;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast), box-shadow var(--motion-fast);
  text-decoration: none;
  white-space: nowrap;
}

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

.btn.primary {
  background: var(--mat);
  color: #fff;
  border-color: transparent;
}

.btn.primary:hover {
  background: var(--mat-strong);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-2);
}

.btn.ghost:hover {
  background: var(--line-2);
  color: var(--fg);
}

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

.btn.danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.btn.sm {
  padding: 5px 9px;
  font-size: 12px;
}

.btn.lg {
  padding: 10px 16px;
  font-size: 14px;
}

/* ============================================================
   Pills (filter toggles)
   ============================================================ */

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-min-height);
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.4;
  background: var(--surface);
  color: var(--fg-2);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast);
  text-decoration: none;
}

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

.pill.active {
  background: var(--ink-1);
  color: #fff;
  border-color: transparent;
}

/* ============================================================
   Chips (source badges)
   ============================================================ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  line-height: 1.4;
  letter-spacing: -.005em;
  white-space: nowrap;
}

.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}

/* ============================================================
   Cards
   ============================================================ */

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

.card:hover {
  box-shadow: var(--shadow-2);
}

.empty-state {
  font-size: 13.5px;
  color: var(--fg-2);
  text-align: center;
  padding: 24px 0;
  margin: 0;
}

/* ============================================================
   Today bar stats
   ============================================================ */

.today-bar .today-stat { display: flex; align-items: baseline; gap: 5px; }
.today-bar .today-stat .n {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-on-dark);
}
.today-bar .today-stat .t {
  font-size: 12px;
  color: var(--fg-on-dark-2);
}
.today-bar .today-stat.accent .n { color: var(--mat); }
.today-bar .today-divide {
  width: 1px;
  height: 18px;
  background: var(--ink-line);
  flex-shrink: 0;
}

/* ============================================================
   Queue page layout
   ============================================================ */

.q-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 14px;
}
.q-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.018em;
  margin: 0;
  color: var(--fg);
}
.q-sub {
  font-size: 13px;
  color: var(--fg-2);
  margin-top: 3px;
}

.q-filters {
  display: flex;
  gap: 8px;
  padding: 0 0 18px;
  align-items: center;
  flex-wrap: wrap;
}

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

/* ============================================================
   Lead cards
   ============================================================ */

.lead-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--motion-medium), border-color var(--motion-medium);
  cursor: default;
  position: relative;
}
.lead-card:hover { box-shadow: var(--shadow-2); border-color: #d7dae0; }

.lead-card .col-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.lead-name {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.012em;
  color: var(--fg);
  text-decoration: none;
}
.lead-name:hover { color: var(--mat); }
.lead-meta {
  color: var(--fg-3);
  font-size: 12.5px;
}

.lead-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.lead-last {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--fg-2);
}
.lead-last b { color: var(--fg); font-weight: 500; }

.lead-actions {
  display: flex;
  gap: 8px;
  padding-top: 2px;
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   AI preview panel (light gradient, right column of lead card)
   ============================================================ */

.ai-preview {
  background: linear-gradient(180deg, #f4f6fb 0%, #eef2f9 100%);
  border: 1px solid #dde4f1;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  position: relative;
}

.ai-tag {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--mat);
}

.ai-msg {
  font-size: 12.5px;
  color: var(--fg-2);
  line-height: 1.55;
  background: rgba(255,255,255,.6);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 8px;
  padding: 9px 11px;
  max-height: 78px;
  overflow: hidden;
  position: relative;
  transition: max-height 350ms ease;
}
.lead-card:hover .ai-msg { max-height: 320px; }
.ai-msg::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 30px;
  background: linear-gradient(180deg, transparent, rgba(244,246,251,.95));
  transition: opacity var(--motion-slow);
}
.lead-card:hover .ai-msg::after { opacity: 0; }

.brief-loading {
  font-size: 12.5px;
  color: var(--fg-3);
  font-style: italic;
  margin: 0;
}

.brief-error {
  font-size: 12.5px;
  color: var(--danger);
  margin: 0;
}

.ai-hint {
  font-size: 10px;
  color: var(--fg-3);
  text-align: right;
  margin-top: auto;
  padding-top: 4px;
}

.search-input {
  flex: 1;
  max-width: 220px;
  min-height: var(--control-min-height);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--control-font-size);
  font-family: inherit;
  outline: none;
  transition: border-color var(--motion-medium), box-shadow var(--motion-medium);
}
.search-input::placeholder { color: var(--fg-3); }
.search-input:focus {
  border-color: var(--mat);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* ============================================================
   Responsive — collapse lead card to single column
   ============================================================ */

@media (max-width: 1100px) {
  .lead-card { grid-template-columns: 1fr; }
}

/* ============================================================
   Entrance animation
   ============================================================ */

.anim-in {
  animation: slide-up 280ms ease-out both;
}

/* ============================================================
   Lead Detail — two-column layout
   ============================================================ */

.detail-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.detail-main { min-width: 0; }

.detail-side {
  position: sticky;
  top: 24px;
}

@media (max-width: 1100px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-side { position: static; }
}

/* ============================================================
   Lead Detail — page header
   ============================================================ */

.lead-detail-head {
  padding: 20px 32px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.lead-detail-name {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.018em;
  margin: 0 0 4px;
  color: var(--fg);
}

.lead-detail-meta {
  font-size: 13px;
  color: var(--fg-2);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lead-detail-meta .divider {
  color: var(--line);
}

/* ============================================================
   Pipeline bar
   ============================================================ */

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

.pipe-step {
  display: flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: -.005em;
  color: var(--fg-3);
  white-space: nowrap;
}

.pipe-step .pipe-label {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  transition: background var(--motion-fast), color var(--motion-fast);
}

.pipe-step.done .pipe-label {
  background: var(--mat-soft);
  color: var(--mat-strong);
}

.pipe-step.current .pipe-label {
  background: var(--mat);
  color: #fff;
  font-weight: 600;
}

.pipe-chevron {
  color: var(--fg-3);
  font-size: 11px;
  padding: 0 2px;
  flex-shrink: 0;
}

.terminal-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  margin-left: 10px;
}

.terminal-badge.no-show {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.terminal-badge.unsubscribed {
  background: var(--tone-neutral-bg);
  color: var(--tone-neutral-fg);
}

.terminal-badge.dead {
  background: var(--tone-neutral-bg);
  color: var(--tone-neutral-fg);
}

/* ============================================================
   Timeline
   ============================================================ */

#timeline {
  position: relative;
}

.tl-spine {
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 0;
  width: 1.5px;
  background: linear-gradient(180deg, var(--line) 0%, transparent 100%);
  pointer-events: none;
}

.tl-entry {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 0 0 18px;
  position: relative;
}

.tl-dot {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px currentColor;
  flex-shrink: 0;
  margin-top: 1px;
  position: relative;
  z-index: 1;
}

.tl-dot.email  { color: var(--tone-indigo-fg); background: var(--tone-indigo-fg); }
.tl-dot.note   { color: var(--mat); background: var(--mat); }
.tl-dot.system { color: var(--fg-3); background: var(--fg-3); }

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

.tl-ts {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--fg-3);
  line-height: 1.4;
  display: block;
  margin-bottom: 2px;
}

.tl-desc {
  font-size: 13px;
  color: var(--fg-2);
  line-height: 1.5;
}

.tl-empty {
  font-size: 13px;
  color: var(--fg-3);
  font-style: italic;
  padding-left: 30px;
}

/* ============================================================
   AI Brief panel (dark chrome)
   ============================================================ */

.brief-panel {
  background: var(--ink-1);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius-lg);
  padding: 18px;
  color: var(--fg-on-dark);
}

.brief-eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--mat);
  margin: 0 0 10px;
}

.brief-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-on-dark-2);
  margin: 0 0 12px;
}

.brief-placeholder {
  font-size: 12.5px;
  color: var(--fg-on-dark-3);
  font-style: italic;
  margin: 0 0 12px;
}

.brief-panel .brief-error {
  display: inline-block;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  margin: 0 0 12px;
}

.brief-retry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

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

.brief-panel .btn {
  border-color: var(--ink-line);
  background: var(--ink-2);
  color: var(--fg-on-dark-2);
}

.brief-panel .btn:hover {
  background: var(--ink-3);
  color: var(--fg-on-dark);
}

/* `.demo-banner` (macros.html) is a light-surface component built for the
   login page; dropped unscoped into `.brief-panel`'s near-black chrome it
   reads as a pale card stranded on a dark surface. Same dark-surface-override
   pattern as `.brief-panel .brief-error` / `.brief-panel .btn` above: repaint
   with the `--ink-*` / `--fg-on-dark*` tokens already used elsewhere in this
   panel, and drop the margin to the panel's own 12px rhythm (`.brief-text`,
   `.brief-placeholder`) instead of the login page's 20px. */
.brief-panel .demo-banner {
  background: var(--ink-2);
  color: var(--fg-on-dark-2);
  border-color: var(--ink-line);
  margin-bottom: 12px;
}

.brief-panel .demo-banner-title {
  color: var(--fg-on-dark);
}

/* ============================================================
   Detail sections / cards
   ============================================================ */

.detail-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-1);
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.005em;
  color: var(--fg);
  margin: 0 0 14px;
}

.detail-section-eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: 0 0 12px;
}

/* ============================================================
   Contact details list
   ============================================================ */

.contact-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  align-items: baseline;
  font-size: 13px;
}

.contact-list dt {
  color: var(--fg-3);
  font-weight: 500;
}

.contact-list dd {
  margin: 0;
  min-width: 0;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.contact-list dd a {
  color: var(--mat-strong);
}

.contact-list dd a:hover {
  text-decoration: underline;
}

.contact-list .contact-empty {
  color: var(--fg-3);
}

/* ============================================================
   Action buttons row
   ============================================================ */

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   Notes form
   ============================================================ */

.notes-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notes-form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--control-font-size);
  line-height: 1.5;
  color: var(--fg);
  background: var(--surface);
  resize: vertical;
  min-height: 72px;
  transition: border-color var(--motion-base);
}

.notes-form textarea:focus {
  outline: none;
  border-color: var(--mat);
  box-shadow: 0 0 0 3px var(--mat-ring);
}

.notes-form textarea::placeholder {
  color: var(--fg-3);
}

/* ============================================================
   Sequence reassignment
   ============================================================ */

.seq-select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--control-font-size);
  color: var(--fg);
  background: var(--surface);
  min-width: 180px;
  min-height: var(--control-min-height);
  transition: border-color var(--motion-base);
}

.seq-select:focus {
  outline: none;
  border-color: var(--mat);
  box-shadow: 0 0 0 3px var(--mat-ring);
}

.seq-select:disabled {
  background: var(--surface-2);
  color: var(--fg-3);
  cursor: not-allowed;
}

.seq-locked-note {
  font-size: 12px;
  color: var(--fg-3);
  font-style: italic;
  margin: 6px 0 0;
}

/* ============================================================
   Typography utilities
   ============================================================ */

.heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.018em;
  line-height: 1.25;
  margin: 0;
  color: var(--fg);
}

.title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.012em;
  line-height: 1.3;
  color: var(--fg);
}

.label {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -.005em;
  line-height: 1;
  color: var(--fg);
}

.caption {
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--fg-2);
}

/* ============================================================
   Chip tone variants
   ============================================================ */

.chip.tone-indigo  { background: var(--tone-indigo-bg);  color: var(--tone-indigo-fg); }
.chip.tone-amber   { background: var(--tone-amber-bg);   color: var(--tone-amber-fg); }
.chip.tone-orange  { background: var(--tone-orange-bg);  color: var(--tone-orange-fg); }
.chip.tone-emerald { background: var(--tone-emerald-bg); color: var(--tone-emerald-fg); }
.chip.tone-teal    { background: var(--tone-teal-bg);    color: var(--tone-teal-fg); }
.chip.tone-violet  { background: var(--tone-violet-bg);  color: var(--tone-violet-fg); }
.chip.tone-neutral { background: var(--tone-neutral-bg); color: var(--tone-neutral-fg); }

/* ============================================================
   State chip (lead state, distinct from source chip: no dot,
   bolder weight)
   ============================================================ */

.state-chip {
  font-weight: 600;
}

.state-chip.tone-success { background: var(--success-bg); color: var(--success-fg); }

/* ============================================================
   Form inputs (design system)
   ============================================================ */

.input {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: var(--control-font-size);
  color: var(--fg);
  line-height: 1.5;
  min-height: var(--control-min-height);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  outline: none;
}

.input:focus {
  border-color: var(--mat);
  box-shadow: 0 0 0 3px var(--mat-ring);
}

.input::placeholder { color: var(--fg-3); }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: -.005em;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stacked-form > .alert {
  margin-bottom: 0;
}

/* ============================================================
   Alerts and field-level errors
   ============================================================ */

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  margin-bottom: 20px;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-fg);
  border-color: var(--success-border);
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

.alert-warning {
  background: var(--tone-amber-bg);
  color: var(--tone-amber-fg);
  border-color: var(--tone-amber-bg);
}

.field-error {
  font-size: 12.5px;
  color: var(--danger);
}

.input-error {
  outline: 2px solid var(--danger);
  outline-offset: 0;
}

/* ============================================================
   Login page layout (no sidebar, full dark-chrome page)
   ============================================================ */

.login-page {
  min-height: 100vh;
  background: var(--ink-1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-3);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--mat) 0%, var(--mat-strong) 100%);
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.4);
  flex-shrink: 0;
}

.login-brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.012em;
  color: var(--fg);
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.018em;
  margin: 0 0 20px;
  color: var(--fg);
}

.demo-banner {
  font-size: 13px;
  color: var(--tone-indigo-fg);
  background: var(--tone-indigo-bg);
  border: 1px solid var(--tone-indigo-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 20px;
}

.demo-banner-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.demo-banner-copy:not(:last-child) {
  margin-bottom: 8px;
}

.demo-banner-creds {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.demo-banner-label {
  font-weight: 600;
  margin-right: 4px;
}

/* ============================================================
   Sequences page layout
   ============================================================ */

.seq-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.seq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seq-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--motion-medium), border-color var(--motion-medium);
}

.seq-card:hover {
  box-shadow: var(--shadow-2);
  border-color: #d7dae0;
}

.seq-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-card-actions,
.seq-card-actions {
  margin: 0;
}

.user-card.is-inactive,
.seq-card.is-inactive {
  opacity: .6;
}

/* ============================================================
   Sequence detail layout
   ============================================================ */

.seq-detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.seq-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.seq-step-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.seq-step-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seq-step-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.seq-step-preview-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.seq-step-preview {
  min-height: 1.5em;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.5;
}

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

.md-toolbar-btn {
  min-width: 32px;
}

.seq-actions-bar {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   Sequence new / edit form
   ============================================================ */

.form-card {
  max-width: 520px;
}

.seq-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
}

/* ============================================================
   Page header macro
   ============================================================ */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 14px;
}

.page-header-text { min-width: 0; }

.page-header-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.018em;
  margin: 0;
  color: var(--fg);
}

.page-header-sub {
  font-size: 13px;
  color: var(--fg-2);
  margin-top: 3px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ============================================================
   Stats page
   ============================================================ */

.stats-section {
  margin-bottom: 32px;
}

.stats-heading {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--fg);
  margin: 0 0 12px;
}

.stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-1);
  min-width: 140px;
}

.stat-label {
  font-size: 12px;
  color: var(--fg-3);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}

.stats-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--fg-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.stats-table td {
  padding: 10px 14px;
  color: var(--fg);
  border-bottom: 1px solid var(--line-2);
}

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

/* ============================================================
   Responsive — phone shell: sidebar out, bottom tab bar in

   Kept at the end of the stylesheet on purpose. Media queries add no
   specificity, so an unmediated rule declared *after* this block would win
   at every width, including a phone's, for any property both rules set —
   silently, since the override wouldn't even need to look responsive. This
   block used to sit mid-file, above .page-header-actions, .seq-step-actions
   and .brief-actions, which set overlapping flex properties at equal
   specificity; it stayed harmless only because none of them happened to
   touch flex-wrap. .tabbar/.tab-item (declared near the top of the file)
   are exposed to the same hazard, which is the other reason this block —
   the only place that overrides them — belongs after everything it touches.
   ============================================================ */

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

  .sidebar {
    display: none;
  }

  .tabbar {
    display: flex;
  }

  .content {
    padding-left: 16px;
    padding-right: 16px;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  }

  .today-bar {
    padding-left: 16px;
    padding-right: 16px;
    flex-wrap: wrap;
  }

  .page-header {
    flex-wrap: wrap;
  }

  .page-header-text {
    flex: 1 1 100%;
  }

  .page-header-actions,
  .seq-step-actions,
  .brief-actions {
    flex-wrap: wrap;
  }
}
