/* ==========================================================================
   LeadMatch — single stylesheet (stage 3 design spec 2026-08-24, §1-9)

   Clean B2B SaaS baseline, deliberately "not final" (reworked before
   market). Vanilla CSS, custom properties for the palette, no JS.

Constraints that shaped it:
* Template class names are FROZEN (stage 2 tests pin exact markup) — only
  the EXISTING utility classes (.muted/.note/.hint/...) are styled.
* All status texts ride the single .note class, so per-status colors
  (spec §3) are approximated: .note is the pastel-blue "New" badge, a
  dismissed card mutes itself via .dismissed, failures use .error.
  STAGE 4 (2026-08-24, spec §9) WIRED THE BADGE CLASSES: the leads pages'
  status badges now carry .note + a per-status .badge-* class (badge-new /
  badge-ok / badge-muted / badge-warn / badge-low below); failures keep
  .error. Stage4 §5 also added the .load-line under the score value.
========================================================================== */

/* ---------- palette (spec §2-3) ---------- */

:root {
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;

  /* neutral scale */
  --gray-900: #1f2430;
  --gray-700: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50: #f9fafb;

  /* surfaces + geometry */
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);

  /* status badges — pastel bg + dark fg (accessibility, spec §3) */
  --status-blue-bg: #e0e7ff;   --status-blue-fg: #3730a3;   /* New */
  --status-green-bg: #dcfce7;  --status-green-fg: #166534;  /* Assigned */
  --status-gray-bg: #eceef1;   --status-gray-fg: #4b5563;   /* Dismissed */
  --status-orange-bg: #ffedd5; --status-orange-fg: #9a3412; /* at capacity */
  --status-yellow-bg: #fef9c3; --status-yellow-fg: #854d0e; /* low data */
  --status-red-bg: #fee2e2;    --status-red-fg: #991b1b;    /* failed */
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--gray-900);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; } /* §2 */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
main a:hover { text-decoration: underline; }

h1 {
  margin: 0 0 0.9rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h2 { margin: 1.8rem 0 0.6rem; font-size: 1.15rem; font-weight: 600; }
h1 a, h2 a { font-size: 0.85em; font-weight: 500; }

hr { border: none; border-top: 1px solid var(--border); margin: 1.75rem 0; }

/* Polling "Analyzing…" block (results.html): a centered note while the
   background run is watched. The block's h1/p elements are direct children
   of <main>, so :has() centers the whole block. Progressive: browsers
   without :has() keep the default left alignment — no markup change. */
main:has(> #analyzing-status) { text-align: center; }
main:has(> #analyzing-status) h1 { margin-top: 1.25rem; }
main:has(> #analyzing-status) .muted { display: inline-block; }

code { background: var(--gray-100); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }

/* ---------- header (spec §4): brand left, nav next, user+logout right ---- */

header { background: var(--card); border-bottom: 1px solid var(--border); }

.header-inner {
  display: flex;
  align-items: center;
  /* Small screens: the nav wraps under the brand instead of overflowing
     (stage3 T2) — row-gap only matters once a wrap happens. */
  flex-wrap: wrap;
  column-gap: 1.5rem;
  row-gap: 0.4rem;
  min-height: 56px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  color: var(--gray-900);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover { color: var(--accent); text-decoration: none; }

header nav { display: flex; align-items: center; gap: 0.25rem; }
header nav a {
  color: var(--gray-700);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 6px;
}
header nav a:hover { color: var(--gray-900); background: var(--gray-100); text-decoration: none; }

.user-box { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.user-box form { margin: 0; }
.user-box .btn-secondary { padding: 5px 12px; font-size: 13px; }
.user-email { color: var(--gray-500); font-size: 13.5px; }

/* ---------- utility classes (names frozen — spec §9) ---------- */

.muted { color: var(--gray-500); }
.hint { color: var(--gray-500); font-size: 13px; line-height: 1.5; }

.note {
  /* status badge: pastel bg + dark fg (spec §3). Default = blue ("New");
     the .badge-* variants below carry the other status colors. */
  display: inline-block;
  background: var(--status-blue-bg);
  color: var(--status-blue-fg);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.65;
  vertical-align: middle;
  white-space: nowrap;
}

/* Per-status badge colors (spec §3), wired in stage 4 (spec §9): every
   status badge renders as ``<span class="note badge-*">…</span>`` so it
   keeps the shared pill shape above and only the palette varies.
   Six statuses: New (blue), Assigned (green), Dismissed (gray),
   at capacity (orange), low data (yellow); failures keep .error (red). */
.badge-new   { background: var(--status-blue-bg);   color: var(--status-blue-fg); }
.badge-ok     { background: var(--status-green-bg);  color: var(--status-green-fg); }
.badge-muted { background: var(--status-gray-bg);   color: var(--status-gray-fg); }
.badge-warn   { background: var(--status-orange-bg); color: var(--status-orange-fg); }
.badge-low    { background: var(--status-yellow-bg); color: var(--status-yellow-fg); }
.badge-danger { background: var(--status-red-bg);    color: var(--status-red-fg); }

/* Load transparency line (stage4 §5): the «← raw ×coef · N deals this week»
   info that used to cram into a Load column now sits in the score cell,
   directly under the adjusted score value -- smaller, gray, single line. */
.load-line {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--gray-500);
}

.error {
  /* form/validation failures — dark red on pastel red (spec §3) */
  background: var(--status-red-bg);
  color: var(--status-red-fg);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-width: 640px;
}

/* Wizard step strip (stage4 §6): one horizontal numbered indicator on every
   onboarding page (_wizard_steps.html include). Completed steps are links,
   the current step is the accent «active» item, future steps are muted
   plain text. CSS counters carry the 1..5 numbers (list-style off; ::before
   inserts «N. » so the numbers align with the labels). */
ol.steps {
  counter-reset: step;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.4rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  font-size: 14px;
}
ol.steps li { counter-increment: step; color: var(--gray-400); }
ol.steps li::before { content: counter(step) ". "; font-weight: 500; }
ol.steps li a { color: var(--gray-700); }
ol.steps li a:hover { color: var(--accent); }
ol.steps li.active { color: var(--accent); font-weight: 600; }
ol.steps li.active::before { font-weight: 600; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0.25rem 0 1.25rem;
  color: var(--gray-400);
  font-size: 14px;
}
.filters a {
  color: var(--gray-700);
  text-decoration: none;
  padding: 3px 11px;
  border-radius: 999px;
}
.filters a:hover { color: var(--gray-900); background: var(--gray-100); text-decoration: none; }
.filters a.active { background: var(--accent); color: #fff; }

/* Lead cards on /app/leads: soft card (spec §2), clearly separated blocks. */
.lead {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 22px 18px;
  margin: 0 0 1.5rem;
}
.lead > h2 { margin-top: 2px; font-size: 1.05rem; }
.lead > .muted { margin-top: 0.4rem; margin-bottom: 0.4rem; }
.lead table { margin: 0.75rem 0 0.5rem; }

/* Dismissed lead: the whole card is muted gray (spec §3) — dimmer text,
   gray border, no shadow, so live leads stay visually primary. */
.lead.dismissed {
  opacity: 0.62;
  background: var(--gray-50);
  border-color: var(--gray-200);
  box-shadow: none;
}

/* Top-3 rows in the full ranking: light accent highlight (spec §6). */
tbody tr.top-3 { background: var(--accent-soft); }

/* Stage8 T3 (§7): an at-capacity row in the full ranking (coef 0 -- the rep
   is EXCLUDED from the adjusted top-3 above) reads as context, not advice:
   dimmed text like a dismissed card. The at-capacity badge keeps its own
   colors; the top-3 accent background still applies when both classes ride
   one row. */
tbody tr.at-capacity { color: var(--gray-500); }

/* Inline action forms (lead detail Actions row). */
form.inline { display: inline-block; vertical-align: top; margin: 0 1rem 1rem 0; }

/* ---------- buttons (spec §5) ---------- */

button {
  /* base look = secondary, so an unclassed button never renders naked */
  display: inline-block;
  background: var(--card);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 7px 15px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}
button:hover { border-color: var(--gray-400); color: var(--gray-900); }

.btn,
.btn-secondary {
  display: inline-block;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn { background: var(--accent); color: #fff; }
.btn:hover { background: var(--accent-hover); color: #fff; }

.btn-secondary { background: var(--card); color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { border-color: var(--gray-400); color: var(--gray-900); }

.btn-danger { background: #fff; color: var(--status-red-fg); border-color: #fecaca; }
.btn-danger:hover { background: var(--status-red-bg); }

/* Clear-search ✕ (stage8 п.2): a quiet borderless character button next to
   the reps search input -- reads as "drop the query", never "reset picks". */
.btn-clear {
  border: none;
  background: none;
  color: var(--gray-400);
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}
.btn-clear:hover { color: var(--gray-700); }

button:focus-visible,
.btn:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- tables (spec §6) ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0.5rem 0 1.25rem;
  font-size: 14px;
}

thead th {
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-200);
  text-align: left;
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--gray-50); }          /* zebra-lite */
tbody tr.top-3 { background: var(--accent-soft); }  /* re-asserted so zebra never covers it */
td { font-variant-numeric: tabular-nums; }          /* aligned digits (§6) */

/* Numeric columns (stage3 T2): <td class="num">/<th class="num"> in the
   templates — right-aligned, non-wrapping digits (rank/score/revenue/
   percentages). Prose cells (rep names, the load transparency line) stay
   left-aligned. */
th.num, td.num {
  text-align: right;
  white-space: nowrap;
}

/* Per-rep load limits (stage5 T2): a team of more than 30 reps renders its
   table inside a capped, scrollable container instead of an endless page. */
.scroll-y {
  max-height: 26rem;
  overflow-y: auto;
}

/* ---------- forms (spec §7): labels above inputs, even spacing ---------- */

form { margin: 0 0 1rem; }

fieldset {
  /* Card look (stage3 T2 polish): the wizard/settings steps stack several
     fieldsets — border + soft shadow + comfortable padding keep each group
     a distinct card on the gray page background. */
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px 18px;
  margin: 0 0 1.25rem;
}

legend {
  font-weight: 600;
  font-size: 14px;
  color: var(--gray-700);
  padding: 0 8px;
  letter-spacing: 0.01em;
}

/* Fieldset body copy (helper <p> inside a card) sits clear of the edges. */
fieldset > p { margin: 0.4rem 0 0.75rem; }

label { font-weight: 500; font-size: 14px; }

/* Wrapping labels (<label>text <input|select></label>): label text ABOVE the
   control, capped at 420px (spec §7). :has() is progressive — browsers
   without it keep the plain inline flow. */
label:has(> input:not([type="checkbox"]):not([type="radio"])),
label:has(> select),
label:has(> datalist) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  max-width: 420px;
  margin: 0 0 0.75rem;
}

/* Choice labels (checkbox/radio) stay a single inline row. */
label:has(> input[type="checkbox"]) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  max-width: none;
  font-weight: 400;
}
label:has(> input[type="radio"]) {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  max-width: none;
  font-weight: 400;
}

/* Two-column control rows (stage8 п.5): the training-filter block puts its
   Property/Value labels SIDE BY SIDE — sibling wrapping-labels each grow to
   an equal share of the row (half-width on a desktop form) and wrap below
   on narrow screens instead of overflowing. */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.form-row > label:has(> input:not([type="checkbox"]):not([type="radio"])),
.form-row > label:has(> select),
.form-row > label:has(> datalist) {
  flex: 1 1 0;
  min-width: 200px;
  max-width: none;
}
.form-row > label input,
.form-row > label select {
  max-width: none;
}

input,
select,
input[list] {
  /* One control look for every input kind (stage3 T2): <input list>
     comboboxes (the datalist property pickers) render exactly like the
     selects next to them — same font, border, radius, focus ring. */
  font: inherit;
  font-size: 14.5px;
  color: var(--gray-900);
  background: var(--card);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
  max-width: 420px; /* spec §7 */
}

/* Compact inline pairs (load anchors "Normal · Max") stay on one row. */
input[type="number"] { width: auto; max-width: 8.5rem; }

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  max-width: none;
  accent-color: var(--accent);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* The <datalist> ELEMENT itself renders nothing in any browser — nothing to
   style; its visible pair, the <input list> combobox, rides the shared
   input/select rule above (stage3 T2). */

/* Stage8b-2 (live feedback): native <select>/datalist popups proved
   unreliable in the user's embedded browser (selects never open; datalist
   popups render far from the input) — the training-filter value control
   renders its OWN in-page suggestion list instead: positioned by us,
   regular DOM clicks, identical in every browser. */
.tf-value-wrap {
  position: relative;
  display: inline-block;
}
.tf-suggest {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 100%;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
  z-index: 30;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}
.tf-suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  font: inherit;
  color: var(--gray-900);
}
.tf-suggest-item:hover {
  background: var(--accent-soft);
}

/* Notes stage (live-design item 4): the per-rep table's optional meeting
   link input — wider than the narrow norm/max number cells. */
.link-input {
  min-width: 220px;
}

/* The proof block under the all-reps ranking (client: verify the math):
   one compact block per rep -- history table + core score line. */
.why-ranking {
  margin-top: 10px;
}
.why-rep {
  margin: 14px 0;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.why-rep table {
  margin: 8px 0 4px;
}

/* Site footer (marketplace: legal/setup links reachable from every page). */
.site-footer {
  max-width: 960px;
  margin: 28px auto 20px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--gray-500);
}
.site-footer a {
  color: var(--gray-500);
}
.site-footer a:hover {
  color: var(--accent);
}
