/* ============================================================
   Anytest — Apple-style design system
   Principles from microsoft/apple-ux-guide:
   - continuous corners (uniform radii)
   - layered, soft shadows (divide Figma blur by 2; use 3 shadow layers)
   - one idea per screen, generous whitespace
   - single accent color, SF Symbols-style iconography
   - springy, subtle motion (opacity + transform only, 0.2-0.4s ease-out)
   - semantic colors that adapt to light/dark
   - minimum 44px touch targets
   ============================================================ */

:root {
  /* DESIGN TOKENS v2 — 8pt grid, 4-level type, 3-tier elevation, teal accent */
  --sp-1:8px; --sp-2:16px; --sp-3:24px; --sp-4:32px; --sp-5:48px; --sp-6:64px;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: rgba(15,23,42,0.045);
  --line: rgba(15,23,42,0.10);
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --accent: #0f766e;        /* deep teal — precision-tool primary */
  --accent-press: #115e59;
  --accent-tint: rgba(15,118,110,0.10);
  --needs-action: #b45309;
  --good: #0f766e;
  --warn: #b45309;
  --bad: #b91c1c;
  /* 3-tier elevation: 0 page · 1 card · 2 drawer/active */
  --shadow-1: 0 1px 2px rgba(15,23,42,0.05), 0 2px 8px rgba(15,23,42,0.06);
  --shadow-2: 0 2px 4px rgba(15,23,42,0.06), 0 8px 24px rgba(15,23,42,0.10);
  --shadow-3: 0 4px 8px rgba(15,23,42,0.08), 0 16px 48px rgba(15,23,42,0.16);
  --r-sm: 10px; --r-md: 14px; --r-lg: 22px; --r-full: 999px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  /* type scale: Display 28/600 · Title 17/600 · Body 14/400 · Caption 12/500 */
  --t-display: 28px; --t-title: 17px; --t-body: 14px; --t-caption: 12px;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #1a2230;
    --surface-2: rgba(255,255,255,0.06);
    --line: rgba(255,255,255,0.12);
    --text: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #64748b;
    --accent: #2dd4bf;
    --accent-press: #5eead4;
    --accent-tint: rgba(45,212,191,0.14);
    --needs-action: #fbbf24;
    --good: #2dd4bf;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.45);
    --shadow-2: 0 2px 4px rgba(0,0,0,0.45), 0 8px 24px rgba(0,0,0,0.55);
    --shadow-3: 0 4px 8px rgba(0,0,0,0.5), 0 16px 48px rgba(0,0,0,0.65);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Inter", -apple-system, "SF Pro Display", system-ui, "Segoe UI", sans-serif;
  font-feature-settings: "cv01","ss03";
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; letter-spacing: -0.01em;
  min-height: 100vh;
}
button { font-family: inherit; }
.hidden { display: none !important; }
.sub { color: var(--text-2); font-size: 15px; }
.opt { color: var(--text-3); font-size: 12px; font-weight: 400; }

/* ───────────── menubar (macOS-style, floating, frosted) ───────────── */
.menubar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 700;
  box-shadow: var(--shadow-1);
}
.wordmark { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

/* segmented control */
.seg { display: flex; background: var(--surface-2); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segbtn {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 14px; font-weight: 500; padding: 8px 16px; min-height: 38px;
  border-radius: 8px; cursor: pointer;
  transition: all 0.25s var(--spring);
}
.segbtn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* LLM brain status chip */
.brain {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: var(--r-full);
  padding: 7px 14px; font-size: 13px; color: var(--text-2); font-weight: 500;
  min-height: 36px;
}
.brain-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); transition: background 0.3s; }
.brain-dot.ok { background: var(--good); box-shadow: 0 0 8px color-mix(in srgb, var(--good) 60%, transparent); }
.brain-dot.err { background: var(--bad); }

/* ───────────── layout ───────────── */
main { padding: clamp(20px, 4vw, 44px) clamp(16px, 4vw, 40px) 80px; max-width: 1080px; margin: 0 auto; }
.pagehead { margin-bottom: 22px; }
.pagehead h1 { font-size: clamp(28px, 5vw, 40px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.pagehead .sub { margin-top: 6px; }

/* ───────────── panels & cards ───────────── */
.panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: 22px;
  margin-bottom: 16px;
}
.form-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input {
  background: var(--surface-2); border: 0; outline: none;
  border-radius: var(--r-sm); padding: 12px 14px;
  font-size: 15px; color: var(--text); min-height: 44px;
  transition: box-shadow 0.2s var(--spring), background 0.2s;
}
.field input:focus { background: var(--accent-tint); box-shadow: inset 0 0 0 1.5px var(--accent); }

.cta {
  grid-column: 1 / -1;
  background: var(--accent); color: #fff; border: 0; cursor: pointer;
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  min-height: 48px; border-radius: var(--r-md);
  transition: transform 0.15s var(--spring), background 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.cta:hover { background: var(--accent-press); box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.cta:active { transform: scale(0.98); }
.cta:disabled { opacity: 0.5; cursor: wait; }

/* card grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: 22px; cursor: pointer;
  transition: transform 0.25s var(--spring), box-shadow 0.25s var(--spring);
  animation: rise 0.4s var(--spring) both;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); }
.card .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card h4 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.card .sub { font-size: 13px; }
.card .stats { display: flex; gap: 22px; margin: 14px 0 10px; flex-wrap: wrap; }
.stat b { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; display: block; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--text-2); }
.card .foot { font-size: 12px; color: var(--text-3); }

/* status pill */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 4px 10px;
  border-radius: var(--r-full); background: var(--surface-2); color: var(--text-2);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.pill.active .dot { background: var(--good); }
.pill.paused .dot { background: var(--warn); }
.pill.active { color: color-mix(in srgb, var(--good) 80%, var(--text)); }
.pill.paused { color: color-mix(in srgb, var(--warn) 80%, var(--text)); }

/* detail panel */
.detail { animation: rise 0.35s var(--spring) both; }
.detail .kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kv > div { background: var(--surface-2); border-radius: var(--r-md); padding: 14px; }
.kv b { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; display: block; }
.kv span { font-size: 12px; color: var(--text-2); }

/* list rows */
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack .row-item {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); padding: 16px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  animation: rise 0.35s var(--spring) both;
}
.stack .row-item .grow { flex: 1; min-width: 160px; }
.stack .row-item b { font-size: 15px; font-weight: 600; }
.stack .row-item .note { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.stack .row-item .meta { font-size: 12px; color: var(--text-3); text-align: right; }

.empty { color: var(--text-3); font-size: 15px; padding: 18px 6px; }

/* ───────────── buttons ───────────── */
.btn {
  background: var(--surface-2); color: var(--text); border: 0; cursor: pointer;
  font-size: 14px; font-weight: 500; padding: 10px 16px; min-height: 40px;
  border-radius: var(--r-sm);
  transition: transform 0.15s var(--spring), background 0.15s, box-shadow 0.2s;
}
.btn:hover { box-shadow: var(--shadow-1); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.iconbtn {
  width: 36px; height: 36px; min-height: 36px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2); border: 0; cursor: pointer;
  font-size: 15px; display: grid; place-items: center;
  transition: background 0.15s, transform 0.15s var(--spring);
}
.iconbtn:hover { background: var(--accent-tint); color: var(--accent); }
.iconbtn:active { transform: scale(0.92); }

/* ───────────── drawer (campaign workspace) ───────────── */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 90; animation: fadein 0.25s ease both; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; right: 0; height: 100dvh; width: 480px; max-width: 100vw; z-index: 100;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform: translateX(105%);
  transition: transform 0.4s var(--spring);
  display: flex; flex-direction: column;
  border-left: 0.5px solid var(--line);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 18px 22px; border-bottom: 0.5px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.drawer-head h2 { font-size: 19px; font-weight: 650; letter-spacing: -0.02em; }
.drawer-head .sub { font-size: 13px; margin-top: 2px; }
.drawer-steps { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; flex: 1; }

/* stepper */
.step {
  background: var(--surface-2); border-radius: var(--r-md); padding: 18px;
  animation: rise 0.35s var(--spring) both;
}
.step .step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step .step-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--surface);
  color: var(--accent); font-size: 13px; font-weight: 700;
  display: grid; place-items: center; box-shadow: var(--shadow-1);
}
.step h5 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.step .hint { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.step .count-row { display: flex; align-items: center; gap: 10px; margin: 10px 0 14px; }
.step .count-row input { width: 76px; text-align: center; background: var(--surface); border: 0; border-radius: var(--r-sm); padding: 10px; font-size: 15px; color: var(--text); min-height: 44px; }
.step .count-row label { font-size: 13px; color: var(--text-2); }

/* progress bar in step */
.prog { height: 4px; border-radius: 4px; background: var(--surface); overflow: hidden; margin: 12px 0; display: none; }
.prog.on { display: block; }
.prog > i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 4px; animation: slide 1.2s ease-in-out infinite; }

/* output pre */
.out {
  white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.55;
  background: var(--surface); padding: 12px; border-radius: var(--r-sm);
  max-height: 300px; overflow: auto; color: var(--text); margin-top: 10px;
  font-family: "Inter", system-ui;
}
.out .k { color: var(--accent); font-weight: 500; }
.out.muted, .out.err { color: var(--text-2); }
.out.err { color: var(--bad); }

/* leads */
.lead {
  border-bottom: 0.5px solid var(--line); padding: 14px 0;
  animation: rise 0.3s var(--spring) both;
}
.lead:last-child { border-bottom: 0; }
.lead .l-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.lead .l-head b { font-size: 14.5px; font-weight: 600; }
.lead .l-head .role { font-size: 13px; color: var(--text-2); }
.lead .l-mail { font-size: 13px; color: var(--text-2); margin-top: 3px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: var(--r-full); margin-left: 6px; vertical-align: 1px;
}
.badge.guessed { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.high { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.low { background: var(--surface-2); color: var(--text-3); }
.lead .l-why { font-size: 13px; color: var(--text-2); margin-top: 6px; line-height: 1.5; }
.lead .l-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* email slot */
.email-slot { margin-top: 10px; }

/* audit rows */
.log-row .badge-ok { color: var(--good); font-weight: 600; }
.log-row .badge-warn { color: var(--warn); font-weight: 600; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500;
  padding: 13px 22px; border-radius: var(--r-full); box-shadow: var(--shadow-2);
  z-index: 200; opacity: 0; transition: opacity 0.3s, transform 0.3s var(--spring);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* animations */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide { 0%,100% { transform: translateX(-100%); } 50% { transform: translateX(220%); } }

/* stagger children */
.grid .card:nth-child(2) { animation-delay: 0.05s; }
.grid .card:nth-child(3) { animation-delay: 0.1s; }
.stack .row-item:nth-child(2) { animation-delay: 0.04s; }
.stack .row-item:nth-child(3) { animation-delay: 0.08s; }

/* ───────────── mobile ───────────── */
@media (max-width: 700px) {
  .menubar { flex-wrap: wrap; gap: 10px; }
  .seg { order: 3; width: 100%; justify-content: center; }
  .segbtn { flex: 1; padding: 8px 6px; font-size: 13px; }
  .brain { margin-left: 0; }
  .drawer { width: 100vw; max-width: 100vw; }
  main { padding-top: 20px; }
  .card .stats { gap: 16px; }
  .stat b { font-size: 22px; }
}

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

/* ============================================================
   v2 ADDITIONS — KPIs, funnel, live findings, quality gate,
   empty states, send-gate, accessible status chips
   ============================================================ */

/* section outcome lines */
.outcome-line { font-size: var(--t-body); color: var(--text-2); margin: 6px 0 20px; max-width: 560px; }

/* KPI card grid (dashboard) — primary KPI is larger */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.kpi { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); padding: var(--sp-2); display:flex; flex-direction:column; gap:6px; animation: rise .35s var(--spring) both; }
.kpi.primary { grid-column: span 2; }
.kpi .k-label { font-size: var(--t-caption); font-weight:600; letter-spacing:.04em; text-transform:uppercase; color:var(--text-2); }
.kpi .k-num { font-size: 30px; font-weight:700; letter-spacing:-.03em; line-height:1; }
.kpi.primary .k-num { font-size: 40px; }
.kpi .k-delta { font-size: var(--t-caption); color: var(--text-3); }
.kpi .k-delta.up { color: var(--good); }
.kpi .k-delta.down { color: var(--bad); }

/* cumulative proof strip */
.proof-strip { display:flex; gap: 18px; flex-wrap:wrap; font-size: var(--t-caption); color: var(--text-3); margin-bottom: var(--sp-3); padding: 10px 2px; border-bottom: .5px solid var(--line); }
.proof-strip b { color: var(--text-2); font-weight:600; }

/* funnel (horizontal bars) */
.funnel { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); padding: var(--sp-3); margin-bottom: var(--sp-3); }
.funnel h3 { font-size: var(--t-title); font-weight:600; margin-bottom: 14px; }
.funnel .f-row { display:grid; grid-template-columns: 76px 1fr 40px; align-items:center; gap: 12px; margin: 10px 0; }
.funnel .f-label { font-size: var(--t-body); color: var(--text-2); font-weight:500; }
.funnel .f-bar { height: 26px; background: var(--surface-2); border-radius: 6px; overflow:hidden; position:relative; }
.funnel .f-bar > i { display:block; height:100%; background: var(--accent); border-radius:6px; transition: width .5s var(--spring); min-width:2px; }
.funnel .f-num { font-size: var(--t-body); font-weight:600; text-align:right; }

/* live findings (research progress panel) */
.findings { display:flex; flex-direction:column; gap:8px; margin: 12px 0; }
.findings .f-item { display:flex; gap:8px; font-size: var(--t-caption); color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; animation: rise .3s var(--spring) both; }
.findings .f-item .f-ico { width:6px; height:6px; border-radius:50%; background: var(--accent); margin-top:4px; flex-shrink:0; }
.live-status { font-size: var(--t-caption); color: var(--text-2); font-style: italic; margin: 8px 0; }

/* status chip (icon + text, never color-only) */
.chip { display:inline-flex; align-items:center; gap:6px; font-size: var(--t-caption); font-weight:600; padding: 4px 10px; border-radius: var(--r-full); }
.chip .chip-ico { font-size: 12px; }
.chip.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.chip.run { background: var(--accent-tint); color: var(--accent); }
.chip.act { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.chip.mut { background: var(--surface-2); color: var(--text-3); }

/* quality badge (draft gate) */
.q-badge { display:inline-flex; align-items:center; gap:5px; font-size: var(--t-caption); font-weight:700; padding: 3px 9px; border-radius: var(--r-full); }
.q-badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.q-badge.meh { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.q-badge.low { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.why-line { font-size: var(--t-caption); color: var(--text-2); margin: 6px 0 0; line-height:1.5; }
.why-line b { color: var(--text); font-weight:600; }

/* empty states */
.empty-hero { text-align:center; padding: var(--sp-5) var(--sp-3); animation: rise .4s var(--spring) both; }
.empty-hero .eh-icon { font-size: 40px; margin-bottom: 12px; }
.empty-hero h2 { font-size: var(--t-title); font-weight:600; margin-bottom: 8px; }
.empty-hero p { font-size: var(--t-body); color: var(--text-2); max-width: 420px; margin: 0 auto 20px; line-height:1.6; }

/* send-gate preview */
.send-gate { background: var(--surface-2); border-radius: var(--r-md); padding: 14px; margin: 10px 0; }
.send-gate .sg-note { font-size: var(--t-caption); color: var(--text-2); margin-bottom: 10px; line-height:1.5; }
.send-gate .sg-list { display:flex; flex-direction:column; gap:6px; margin-bottom: 12px; max-height: 200px; overflow:auto; }
.send-gate .sg-item { font-size: var(--t-caption); color: var(--text-2); padding: 6px 8px; background: var(--surface); border-radius:6px; }
.send-gate .sg-item b { color: var(--text); font-weight:600; }
.mode-toggle { display:flex; gap:8px; align-items:center; margin: 10px 0; }
.mode-toggle .chip { cursor:pointer; }

/* error card (what/why/fix) */
.err-card { background: color-mix(in srgb, var(--bad) 6%, var(--surface)); border: .5px solid color-mix(in srgb, var(--bad) 25%, transparent); border-radius: var(--r-md); padding: 14px; margin: 10px 0; }
.err-card .e-what { font-size: var(--t-body); font-weight:600; color: var(--bad); margin-bottom:4px; }
.err-card .e-why { font-size: var(--t-caption); color: var(--text-2); margin-bottom: 10px; }
.err-card .e-acts { display:flex; gap:8px; }

/* stepper done collapse */
.step.done .step-body { display:none; }
.step.done .step-head { cursor:pointer; }
.step.done .step-head .step-num { background: var(--good); color:#fff; }

/* view switch transition */
.view { animation: viewin .2s ease-out both; }
@keyframes viewin { from { opacity:0; transform: translateY(6px);} to { opacity:1; transform:none; } }
