/* Servant DM — Apple HIG–aligned PWA
   HIG: typography, 44pt targets, safe-area, color contrast (light/dark AA) */

:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --bg: #f5f4f1;
  --bg-elevated: #fdfbf7;
  --raised: #efece6;
  --label: #1f1b16;
  --secondary: #5e554a;
  --muted: #7b7266;
  --separator: rgba(31, 27, 22, 0.08);
  --fill: rgba(31, 27, 22, 0.06);
  --accent: #007aff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn: #c2410c;
  --ok: #16a34a;
  --radius: 10px;
  --radius-lg: 14px;
  --space: 16px;
  --space-sm: 8px;
  --space-lg: 24px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --touch: 44px;
  --tabbar-h: 56px;
  --sidebar-w: 260px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --bg-elevated: #1c1a18;
    --raised: #262421;
    --label: #efe9de;
    --secondary: #aaa398;
    --muted: #8a847a;
    --separator: rgba(239, 233, 222, 0.08);
    --fill: rgba(239, 233, 222, 0.08);
    --accent: #0a84ff;
    --danger: #e5484d;
    --warn: #f5a524;
    --ok: #4cc38a;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
  line-height: 1.47;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.link { color: var(--accent); font-size: 15px; font-weight: 500; }

.app-guest .main {
  min-height: 100dvh;
  padding: calc(var(--space-lg) + var(--safe-t)) var(--space) calc(var(--space-lg) + var(--safe-b));
  max-width: 420px;
  margin: 0 auto;
}
.app-authed {
  display: block;
  min-height: 100dvh;
}
.main {
  padding:
    calc(var(--space) + var(--safe-t))
    calc(var(--space) + var(--safe-r))
    calc(var(--tabbar-h) + var(--safe-b) + 48px)
    calc(var(--space) + var(--safe-l));
  max-width: 960px;
  margin: 0 auto;
}

/* Desktop sidebar */
.sidebar { display: none; }
@media (min-width: 900px) {
  .app-authed {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: calc(var(--space) + var(--safe-t)) var(--space) calc(var(--space) + var(--safe-b));
    background: var(--bg-elevated);
    border-right: 1px solid var(--separator);
    gap: var(--space);
  }
  .tabbar { display: none !important; }
  .main {
    padding-bottom: calc(var(--space-lg) + var(--safe-b));
    max-width: 1200px;
  }
  .brand { display: flex; gap: 12px; align-items: center; }
  .brand strong { font-weight: 500; font-size: 16px; }
  .brand-icon { border-radius: 8px; }
  .brand-sub { margin: 0; font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
  .side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .side-nav a {
    display: flex; align-items: center; gap: 10px;
    min-height: var(--touch);
    padding: 0 12px;
    border-radius: 8px;
    color: var(--secondary);
    font-size: 14px; font-weight: 400;
    text-decoration: none;
    transition: background-color 140ms var(--ease), color 140ms var(--ease);
  }
  .side-nav a .ico { color: var(--muted); }
  .side-nav a:hover { background: var(--fill); color: var(--label); text-decoration: none; }
  .side-nav a:hover .ico { color: var(--secondary); }
  .side-nav a.active {
    background: var(--raised);
    color: var(--label);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  }
  .side-nav a.active .ico { color: var(--accent); }
  .side-foot { border-top: 1px solid var(--separator); padding-top: var(--space); }
}

h1 { font-size: 28px; font-weight: 500; letter-spacing: -0.01em; margin: 0 0 4px; line-height: 1.15; }
h2 { font-size: 20px; font-weight: 500; margin: 0 0 8px; }
.eyebrow {
  margin: 0 0 4px; font-size: 13px; font-weight: 400;
  color: var(--muted); letter-spacing: 0.01em; text-transform: none;
}
.subtitle, .meta, .hint, .kpi-sub { color: var(--secondary); font-size: 15px; margin: 0 0 var(--space); }
.kpi-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: var(--space);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
}
.card.quiet { background: transparent; box-shadow: none; border: 1px solid var(--separator); }
.card.tight { padding: 12px; }
details.card > summary {
  cursor: pointer; font-weight: 600; min-height: var(--touch);
  display: flex; align-items: center;
}
details.card[open] > summary { margin-bottom: 8px; }

.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--space); margin-bottom: var(--space);
}
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px;
  padding: 0 10px; border-radius: 8px; font-size: 12px; font-weight: 500;
  font-family: var(--font-mono); background: var(--raised); color: var(--secondary);
  border: 1px solid var(--separator);
}
.pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.pill-ok { color: var(--ok); }
.pill-ok::before { background: var(--ok); }
.pill-warn { color: var(--warn); }
.pill-warn::before { background: var(--warn); }
.pill-danger { color: var(--danger); }
.pill-danger::before { background: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--touch); min-width: var(--touch);
  padding: 0 16px; border-radius: 10px; border: 1px solid var(--separator);
  font: inherit; font-weight: 500; font-size: 15px;
  background: var(--raised); color: var(--label); cursor: pointer;
  text-decoration: none;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--fill); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.05); }
@media (prefers-color-scheme: dark) {
  .btn-primary {
    background: #efe9de; color: #1f1b16; border-color: transparent;
  }
  .btn-primary:hover { filter: brightness(0.96); }
}
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover { filter: brightness(1.05); }

.confirm-dialog {
  border: 2px solid var(--danger);
  border-radius: 16px;
  padding: 20px;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--bg-elevated);
  color: var(--label);
  box-shadow: var(--shadow);
}
.confirm-dialog::backdrop { background: rgba(20, 16, 12, 0.46); }
.confirm-dialog h2 { margin: 0 0 8px; font-size: 20px; }
.confirm-dialog p { margin: 0 0 16px; }
.confirm-dialog .btn-danger { min-width: 46%; }

.media-picker { position: relative; }
.media-picker [hidden] { display: none !important; }
.media-picker-trigger {
  width: 100%;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--separator);
  background: var(--bg);
  color: var(--label);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
}
.media-picker-thumb {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--raised); flex-shrink: 0; overflow: hidden;
}
.media-picker-thumb img { width: 36px; height: 36px; object-fit: cover; display: block; }
.media-picker-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-picker-panel {
  margin-top: 8px;
  border: 1px solid var(--separator);
  border-radius: 12px;
  background: var(--bg-elevated);
  max-height: 320px;
  overflow: auto;
  padding: 8px;
}
.media-picker-status { margin: 4px 4px 8px; color: var(--muted); font-size: 14px; }
.media-option {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.media-option:hover, .media-option:focus-visible { background: var(--fill); }
.media-option img, .media-option-ph {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: var(--raised);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.row.gap { gap: 12px; }
.mt { margin-top: 8px; }

.field { display: flex; flex-direction: column; gap: 8px; font-size: 15px; font-weight: 400; }
.field span { color: var(--muted); font-size: 13px; font-weight: 500; }
.field input, .field textarea, .select, input, textarea, select {
  font: inherit; font-size: 17px; font-weight: 400;
  min-height: var(--touch); padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--separator);
  background: var(--bg); color: var(--label); width: 100%;
}
.field textarea { min-height: 88px; resize: vertical; }
.check {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 15px; min-height: var(--touch); padding: 8px 0;
}
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); }

.error {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger); padding: 12px; border-radius: 10px; font-weight: 500;
}

/* Mobile tab bar — max 5 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around; align-items: stretch;
  min-height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--separator);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; min-height: var(--tabbar-h); color: var(--muted);
  font-size: 10px; font-weight: 400; text-decoration: none;
}
.tab.active { color: var(--accent); font-weight: 500; }
.tab .ico { width: 22px; height: 22px; }
.ico { width: 18px; height: 18px; flex-shrink: 0; }

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: var(--space);
}
@media (min-width: 700px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
.kpi-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
}
.kpi-label { margin: 0; font-size: 13px; font-weight: 400; color: var(--muted); }
.kpi-value {
  margin: 8px 0 0; font-size: 28px; font-weight: 500; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.spark { display: none; }

/* Activity feed */
.activity { list-style: none; margin: 0; padding: 0; }
.activity-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--separator);
}
.activity-item:last-child { border-bottom: 0; }
.activity-title { margin: 0; font-size: 15px; font-weight: 500; }
.activity-detail { margin: 2px 0 0; font-size: 14px; color: var(--secondary); }
.activity-meta { text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--secondary); margin-bottom: 4px;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 15px; flex-shrink: 0;
}

/* Automations list */
.view-tabs {
  display: flex; gap: 8px; margin: 0 0 16px;
}
.view-tabs a {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--touch); padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--separator);
  text-decoration: none; color: var(--label); background: var(--bg-elevated);
}
.view-tabs a.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tab-count {
  min-width: 1.4em; padding: 0 6px; border-radius: 999px;
  background: var(--raised); font-variant-numeric: tabular-nums; font-size: 13px;
}
.restore-toast {
  position: static; opacity: 1; transform: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 0 16px; max-width: none;
}
.restore-toast p { margin: 0; }

.auto-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.auto-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
}
@media (min-width: 600px) {
  .auto-card { grid-template-columns: 56px 1fr auto; }
}
.auto-card.archived-card { grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .auto-card.archived-card { grid-template-columns: 1fr; }
}
.thumb {
  width: 56px; height: 56px; border-radius: 12px;
  background: var(--raised); border: 1px solid var(--separator);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.thumb .ico { width: 22px; height: 22px; }
.thumb-label {
  font-size: 11px; font-weight: 500; font-family: var(--font-mono);
  letter-spacing: 0.02em; color: var(--muted); text-transform: none;
}
.auto-body { min-width: 0; }
.stats-line { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 0; font-size: 13px; color: var(--secondary); }
.switch {
  width: 52px; height: 32px; border-radius: 16px; border: none;
  background: #787880; position: relative; cursor: pointer; flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 28px; height: 28px; border-radius: 50%; background: #fff;
  transition: transform 160ms var(--ease);
}
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }
.toggle-form { margin: 0; }

.wizard-grid {
  display: grid; gap: var(--space);
}
@media (min-width: 900px) {
  .wizard-grid { grid-template-columns: 1fr 340px; align-items: start; }
}
.preview-pane { position: sticky; top: var(--space); }

/* Flow builder — vertical, no crossing arrows */
.flow-layout { display: grid; gap: var(--space); }
@media (min-width: 800px) {
  .flow-layout { grid-template-columns: 1fr 1fr; align-items: start; }
}
.flow-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.flow-step {
  display: grid; grid-template-columns: 36px 1fr; gap: 12px;
  padding: 14px; background: var(--bg-elevated); border-radius: var(--radius);
  margin-bottom: 8px; position: relative; box-shadow: var(--shadow);
}
.flow-step:not(:last-child)::after {
  content: ""; position: absolute; left: 31px; bottom: -10px;
  width: 2px; height: 10px; background: var(--separator);
}
.step-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 500;
}

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--separator); }
.list > li:last-child { border-bottom: 0; }

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list a {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--touch); padding: 0 4px;
  color: var(--label); font-weight: 500; text-decoration: none;
  border-bottom: 1px solid var(--separator);
}
.menu-list a:hover { color: var(--accent); }

.chat-bubbles { display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 18px;
  font-size: 15px; border-bottom: 0 !important;
}
.bubble.in { align-self: flex-start; background: var(--fill); }
.bubble.out { align-self: flex-end; background: var(--accent); color: #fff; }

.empty { text-align: center; padding: var(--space-lg) var(--space); }
.empty.tight { padding: var(--space); }
.empty-title { font-size: 20px; font-weight: 500; margin: 0 0 8px; }

.login-card { text-align: center; }
.login-card .stack { text-align: left; }
.login-brand { margin-bottom: 12px; }
.login-brand img { border-radius: 16px; }

.stat-row {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--separator);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row strong { margin-left: auto; font-size: 20px; }

/* Toasts */
.toast-host {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px;
  width: min(360px, calc(100vw - 32px)); pointer-events: none;
}
@media (min-width: 900px) {
  .toast-host { bottom: 24px; }
}
.toast {
  background: #1c1c1e; color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: 15px; font-weight: 500; opacity: 0; transform: translateY(8px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease); box-shadow: var(--shadow);
}
@media (prefers-color-scheme: light) {
  .toast { background: #3a3a3c; }
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Phone preview tweaks */
.phone-frame {
  max-width: 320px; margin: 0 auto;
  border: 2px solid var(--separator); border-radius: 28px;
  padding: 12px 10px 20px; background: var(--bg);
}

details.card.quiet > summary {
  color: var(--secondary);
  font-size: 15px;
  font-weight: 500;
}
.auto-card .btn { margin-top: 8px; justify-self: start; }
@media (min-width: 600px) {
  .auto-card .btn { margin-top: 0; justify-self: end; }
}

/* Instagram DM preview phone */
.ig-phone {
  max-width: 320px;
  margin: 0 auto;
  background: #000;
  color: #fff;
  border-radius: 36px;
  overflow: hidden;
  border: 3px solid #2c2c2e;
  box-shadow: var(--shadow);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 560px;
}
.ig-status {
  display: flex; justify-content: space-between;
  padding: 10px 18px 4px; font-size: 12px; font-weight: 600;
}
.ig-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 12px; border-bottom: 1px solid #222;
}
.ig-back { font-size: 28px; line-height: 1; opacity: 0.9; }
.ig-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.ig-header-text { flex: 1; min-width: 0; }
.ig-page-name { display: block; font-size: 14px; }
.ig-page-handle { display: block; font-size: 12px; color: #a8a8a8; }
.ig-context {
  padding: 10px 14px; background: #111;
  border-bottom: 1px solid #222; font-size: 12px; color: #a8a8a8;
}
.ig-context-comment { color: #fff; margin: 4px 0; font-size: 13px; }
.ig-context-reply { margin: 0; }
.ig-thread {
  flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 10px;
  background: #000; overflow: auto;
}
.ig-row { display: flex; flex-direction: column; max-width: 88%; }
.ig-row.out { align-self: flex-end; align-items: flex-end; }
.ig-row.in { align-self: flex-start; align-items: flex-start; }
.ig-bubble {
  background: #3797f0;
  color: #fff;
  padding: 10px 12px;
  border-radius: 18px;
  border-bottom-right-radius: 4px;
}
.ig-row.in .ig-bubble {
  background: #262626;
  border-bottom-right-radius: 18px;
  border-bottom-left-radius: 4px;
}
.ig-bubble p { margin: 0 0 8px; }
.ig-bubble p:last-child { margin-bottom: 0; }
.ig-pill {
  display: block; width: 100%;
  margin-top: 8px; padding: 8px 12px;
  border-radius: 999px; border: 1px solid rgba(255,255,255,0.55);
  background: transparent; color: #fff;
  font: inherit; font-weight: 600; font-size: 13px; cursor: default;
}
.ig-link-card {
  display: flex; gap: 10px; align-items: center;
  background: #1a1a1a; border: 1px solid #333;
  border-radius: 14px; padding: 10px; color: #fff; text-decoration: none;
  max-width: 100%;
}
.ig-link-thumb {
  width: 44px; height: 44px; border-radius: 8px;
  background: #333; display: flex; align-items: center; justify-content: center;
}
.ig-link-host { margin: 0; font-weight: 600; font-size: 13px; }
.ig-link-url {
  margin: 2px 0 0; font-size: 11px; color: #a8a8a8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px;
}
.ig-time { font-size: 10px; color: #6e6e6e; margin-top: 4px; }
.ig-composer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 16px; border-top: 1px solid #222;
}
.ig-composer-input {
  flex: 1; background: #1a1a1a; border-radius: 999px;
  padding: 10px 14px; color: #6e6e6e; font-size: 13px;
}
.ig-composer-send {
  width: 32px; height: 32px; border-radius: 50%;
  background: #3797f0; display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.wizard-grid {
  display: grid; gap: var(--space);
}
@media (min-width: 960px) {
  .wizard-grid {
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
  }
  .preview-pane {
    position: sticky;
    top: calc(var(--space) + var(--safe-t));
  }
}
.wiz-section {
  border-top: 1px solid var(--separator);
  padding-top: var(--space);
  margin-top: 4px;
}
.wiz-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.wiz-section h3 {
  margin: 0 0 12px; font-size: 15px; font-weight: 600;
}
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: var(--touch);
}
.profile-grid {
  display: grid; gap: var(--space);
}
@media (min-width: 800px) {
  .profile-grid { grid-template-columns: 1fr 1fr; }
}
.tag {
  display: inline-flex; padding: 4px 8px; border-radius: 6px;
  background: var(--raised); border: 1px solid var(--separator);
  font-size: 12px; font-weight: 400; margin: 2px; color: var(--secondary);
  font-family: var(--font-mono);
}
.file-btn input[type=file] { display: none; }


/* Author flex rules beat UA [hidden]; force preview option blocks off */
.ig-phone [hidden],
.ig-phone .ig-hidden {
  display: none !important;
}

/* Accessibility */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 10px 14px;
  background: var(--accent, #007aff);
  color: #fff;
  border-radius: 0 0 8px 0;
  font-weight: 600;
}
.skip-link:focus {
  left: 0;
}
:focus-visible {
  outline: 2px solid var(--accent, #007aff);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* Inbox 2-pane */
.inbox-grid {
  display: grid;
  gap: var(--space);
}
@media (min-width: 900px) {
  .inbox-grid {
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
    align-items: start;
  }
  .thread-pane { position: sticky; top: calc(var(--space) + var(--safe-t)); }
}
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  color: inherit; text-decoration: none;
  min-height: var(--touch);
}
.conv-item:hover { background: var(--fill); }
.conv-item.active {
  background: var(--raised);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.conv-meta { min-width: 0; }
.conv-meta strong { display: block; font-size: 15px; }
.thread-head { margin-bottom: 12px; }
h2.tight { margin: 0; font-size: 17px; }
.reply-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--separator); }
.inbox-list-pane { padding: 8px; }

/* —— Flow builder (HIG canvas) —— */
.main.main-wide {
  max-width: none;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  justify-self: stretch;
}
@media (min-width: 900px) {
  .main.main-wide { max-width: none; }
}
.flow-builder { display: flex; flex-direction: column; gap: var(--space-sm); min-height: 0; }
.flow-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 0;
}
.flow-toolbar .btn-icon {
  min-width: var(--touch); min-height: var(--touch);
  border-radius: 10px; border: 1px solid var(--separator);
  background: var(--bg-elevated); color: var(--label); font-size: 18px;
  cursor: pointer;
}
.flow-toolbar .btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.fc-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.fc-palette .btn {
  font-size: 13px; padding: 8px 12px; min-height: 36px;
  background: var(--raised); border: 1px solid var(--separator); border-radius: 8px; color: var(--label);
  cursor: pointer; font-weight: 400;
}
.fc-palette .btn:hover { background: var(--fill); color: var(--label); border-color: var(--accent); }
.fc-selected {
  font-size: 13px; color: var(--secondary); margin: 0;
}
.flow-workspace {
  display: grid; gap: var(--space);
  min-height: 560px;
}
@media (min-width: 901px) {
  .flow-workspace {
    grid-template-columns: minmax(0, 1fr) min(340px, 32vw);
    align-items: stretch;
  }
  .flow-layout { grid-template-columns: 1fr; }
}
.flow-canvas-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  background: var(--bg-elevated);
  overflow: hidden;
  min-height: 560px;
}
.drawflow-host {
  width: 100%;
  height: min(72vh, 720px);
  min-height: 560px;
  position: relative;
  background-color: var(--bg);
  background-image: radial-gradient(var(--separator) 1px, transparent 1px);
  background-size: 16px 16px;
}
.drawflow-host .drawflow {
  background: transparent !important;
  transform-origin: 0 0 !important;
}
.drawflow-host .drawflow .parent-node { }
/* Soft connection lines */
.drawflow-host svg.connection .main-path {
  stroke: var(--accent) !important;
  stroke-width: 2.5px !important;
  opacity: 0.55;
}
.drawflow-host .drawflow-node {
  display: block !important;
  align-items: stretch !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
  min-width: 300px;
  width: 320px;
  max-width: 320px;
}
.drawflow-host .drawflow-node.selected .fc-card {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.drawflow-host .drawflow-node .fc-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  color: var(--label);
}
.drawflow-host .fc-icon {
  flex: 0 0 40px; width: 40px; height: 40px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.fc-trigger .fc-icon { background: var(--accent); }
.fc-action .fc-icon { background: var(--ok); }
.fc-condition .fc-icon { background: var(--warn); }
.fc-delay .fc-icon { background: var(--muted); color: #fff; }
.drawflow-host .fc-body { min-width: 0; flex: 1; }
.drawflow-host .fc-body strong {
  display: block; font-size: 16px; font-weight: 600; line-height: 1.3;
  margin: 0 0 4px;
}
.drawflow-host .fc-preview {
  margin: 0; font-size: 14px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 250px;
}
/* Top / bottom ports (vertical flow) — override Drawflow width:0 + left/right docks */
.drawflow-host .drawflow-node .inputs,
.drawflow-host .drawflow-node .outputs {
  position: absolute !important;
  left: 0 !important; right: 0 !important;
  width: 100% !important; height: 12px !important;
  display: block !important;
  pointer-events: none;
  margin: 0 !important;
}
.drawflow-host .drawflow-node .inputs { top: -5px !important; }
.drawflow-host .drawflow-node .outputs { bottom: -5px !important; top: auto !important; }
.drawflow-host .drawflow-node .input,
.drawflow-host .drawflow-node .output {
  position: absolute !important;
  left: 50% !important; right: auto !important;
  transform: translateX(-50%);
  width: 10px !important; height: 10px !important;
  background: var(--bg-elevated) !important;
  border: 2px solid var(--separator) !important;
  border-radius: 50% !important;
  pointer-events: all;
  margin: 0 !important;
}
.drawflow-host .drawflow-node .input { top: 0 !important; bottom: auto !important; }
.drawflow-host .drawflow-node .output { bottom: 0 !important; top: auto !important; }
.drawflow-host .drawflow-node .input:hover,
.drawflow-host .drawflow-node .output:hover {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
}
#flow-inspector {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  padding: 20px;
  position: sticky; top: var(--space);
  max-height: min(72vh, 720px); overflow: auto;
}
#flow-inspector h2 { font-size: 17px; margin: 0 0 8px; }
@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }
}
@media (min-width: 901px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: block !important; }
}


/* Bot honeypot — visually hidden, not display:none (some bots skip display:none) */
.hp-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.public-footer {
  margin: 48px auto 24px;
  padding: 16px;
  max-width: 40rem;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.public-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  justify-content: center;
  margin-bottom: 8px;
}
.public-footer a { color: var(--accent); }
.login-legal { margin-top: 16px; text-align: center; }
.readable { max-width: 42rem; margin: 0 auto; padding: var(--space); }
.readable h1 { font-size: 1.75rem; }
.readable h2 { font-size: 1.2rem; margin-top: 1.5rem; }
