/*
  ClearlyKept Self-Service Onboarding — application design system.

  This is NOT a copy-paste of the marketing site's stylesheet
  (../ClearlyKept-Website-main/styles/site.css) — the two projects stay
  decoupled so this app can be deployed independently (e.g. on an
  application subdomain). It ports the same design tokens (color, type,
  spacing, radius, shadow) and the same button/card/eyebrow/header/footer
  *patterns* by hand, so the onboarding flow reads as one continuous
  ClearlyKept product rather than a bolted-on prototype, then adds the
  app-specific pieces the marketing site never needed: a progress stepper,
  form controls, status banners, and score/report presentation.

  One stylesheet, linked by every server-rendered page (see app_shell.py
  and templates/qualification.html) — no per-page inline <style> blocks.
*/

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400..800;1,400..800&display=swap');

:root {
  --font-body: 'Plus Jakarta Sans', 'Inter', 'Helvetica Neue', sans-serif;

  /* Type scale */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.5rem;
  --text-2xl:  2rem;

  /* Spacing — 4px base (same scale as the marketing site) */
  --s-1:  0.25rem;
  --s-2:  0.5rem;
  --s-3:  0.75rem;
  --s-4:  1rem;
  --s-5:  1.25rem;
  --s-6:  1.5rem;
  --s-8:  2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;
  --s-16: 4rem;

  /* Color — ClearlyKept brand system (matches site.css tokens) */
  --c-bg:            #faf7f2;
  --c-surface:       #f9f6f0;
  --c-surface-2:     #ede8de;
  --c-border:        rgba(11, 43, 77, 0.10);
  --c-border-mid:    rgba(11, 43, 77, 0.16);
  --c-text:          #12263f;
  --c-text-muted:    rgba(18, 38, 63, 0.62);
  --c-text-faint:    rgba(18, 38, 63, 0.38);
  --c-navy:          #0c3a5e;
  --c-navy-dark:     #08263f;
  --c-navy-deep:     #061a2c;
  --c-accent:        #8dcf9b;
  --c-accent-mid:    #6dc283;
  --c-accent-dark:   #3a9b56;
  --c-accent-subtle: rgba(109, 194, 131, 0.12);
  --c-inverse:       #f5f1e9;

  /* App-only status tokens (the marketing site has no error/warning UI) */
  --c-amber:         #c98a2b;
  --c-amber-subtle:  rgba(201, 138, 43, 0.12);
  --c-red:           #c0455a;
  --c-red-subtle:    rgba(192, 69, 90, 0.10);

  /* Radius */
  --r-sm:  0.5rem;
  --r-md:  0.875rem;
  --r-lg:  1.25rem;
  --r-xl:  1.75rem;

  /* Shadows */
  --shadow-xs: 0 1px 4px rgba(12, 58, 94, 0.06);
  --shadow-sm: 0 4px 16px rgba(12, 58, 94, 0.07);
  --shadow-md: 0 12px 36px rgba(12, 58, 94, 0.10);

  /* Layout */
  --max-w-app: 700px;
  --tx: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Base reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body {
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; transition: color var(--tx); }
button, input, textarea, select { font: inherit; color: inherit; }
p { color: var(--c-text-muted); }
h1, h2, h3 {
  font-family: var(--font-body);
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--c-text);
}
::selection { background: rgba(141, 207, 155, 0.28); }

.skip-link {
  position: absolute; top: -100%; left: var(--s-4);
  padding: var(--s-2) var(--s-4);
  background: var(--c-navy); color: var(--c-inverse);
  border-radius: var(--r-sm); font-size: var(--text-sm);
  font-weight: 600; z-index: 999;
}
.skip-link:focus { top: var(--s-4); }

/* ── Layout ── */
.wrap {
  width: min(calc(100% - var(--s-8)), var(--max-w-app));
  margin-inline: auto;
}

/* ── Eyebrow / labels ── */
.eyebrow {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--c-accent-dark);
  margin-bottom: var(--s-3);
}

/* ── Buttons (ported from site.css) ── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px;
  padding: 0.875rem 1.75rem;
  background: var(--c-accent-mid);
  color: var(--c-navy-dark);
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background var(--tx), transform var(--tx), opacity var(--tx);
}
.btn-primary:hover:not(:disabled) { background: var(--c-accent-dark); color: #fff; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }

.btn-outline {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px;
  padding: 0.875rem 1.75rem;
  background: transparent;
  color: var(--c-navy);
  border: 1.5px solid var(--c-border-mid);
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--tx), border-color var(--tx), transform var(--tx);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(255,255,255,0.6);
  border-color: rgba(12, 58, 94, 0.28);
  transform: translateY(-1px);
}

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 48px;
  padding: 0.875rem 1.5rem;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: color var(--tx);
}
.btn-ghost:hover:not(:disabled) { color: var(--c-text); }

.btn-block { width: 100%; }
.btn-row { display: flex; gap: var(--s-3); margin-top: var(--s-6); }
.btn-row .btn-primary { flex: 1; }

/* ── App header ── */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(243, 239, 231, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--c-border);
}
.app-header .wrap {
  max-width: 880px;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  min-height: 4.5rem;
}
.app-header .brand { display: inline-flex; align-items: center; gap: var(--s-3); min-height: 40px; }
.app-header .brand-logo { height: 2.1rem; width: auto; }
.app-header .brand-tag {
  font-size: var(--text-xs);
  color: var(--c-text-muted);
  border-left: 1px solid var(--c-border-mid);
  padding-left: var(--s-3);
  white-space: nowrap;
}
.app-header .site-link {
  font-size: var(--text-xs); font-weight: 600;
  color: var(--c-text-muted);
  white-space: nowrap;
}
.app-header .site-link:hover { color: var(--c-navy); }

/* ── Progress stepper ── */
.stepper {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: var(--s-8) 0 var(--s-8);
}
.stepper::before { content: none; }
.step {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--s-2);
}
.step:not(:first-child)::before {
  content: '';
  position: absolute;
  top: 13px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--c-border-mid);
  z-index: 0;
}
.step.done:not(:first-child)::before,
.step.active:not(:first-child)::before { background: var(--c-accent-mid); }
.step .dot {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c-surface);
  border: 2px solid var(--c-border-mid);
  color: var(--c-text-faint);
  font-size: 0.7rem; font-weight: 800;
}
.step.active .dot { background: var(--c-navy); border-color: var(--c-navy); color: var(--c-inverse); }
.step.done .dot { background: var(--c-accent-mid); border-color: var(--c-accent-mid); color: var(--c-navy-dark); }
.step .label {
  font-size: 0.66rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--c-text-faint);
}
.step.active .label { color: var(--c-navy); }
.step.done .label { color: var(--c-accent-dark); }

/* ── Cards ── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: clamp(var(--s-6), 4vw, var(--s-8));
  box-shadow: var(--shadow-sm);
}
.card h2 { font-size: var(--text-xl); font-weight: 800; margin-bottom: var(--s-2); }
.card .card-sub { font-size: var(--text-sm); color: var(--c-text-muted); margin-bottom: var(--s-6); }
.card.result-card { text-align: center; padding: clamp(var(--s-8), 5vw, var(--s-10)) clamp(var(--s-6), 4vw, var(--s-8)); }
.card.result-card p { max-width: 44ch; margin: 0 auto var(--s-6); }

/* ── Status chips ── */
.tag {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: var(--s-1) var(--s-3);
  border-radius: 999px;
  margin-bottom: var(--s-4);
}
.tag-green { background: var(--c-accent-subtle); color: var(--c-accent-dark); }
.tag-amber { background: var(--c-amber-subtle); color: var(--c-amber); }
.tag-red   { background: var(--c-red-subtle); color: var(--c-red); }

.result-icon {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto var(--s-4);
  font-size: 1.5rem;
}
.result-icon.ok    { background: var(--c-accent-subtle); color: var(--c-accent-dark); }
.result-icon.warn  { background: var(--c-amber-subtle); color: var(--c-amber); }
.result-icon.block { background: var(--c-red-subtle); color: var(--c-red); }

/* ── Form fields ── */
.field { margin-bottom: var(--s-5); text-align: left; }
.field label {
  display: block; font-size: var(--text-sm); font-weight: 700;
  color: var(--c-text); margin-bottom: var(--s-2);
}
.field .helptext { font-size: var(--text-xs); color: var(--c-text-muted); margin-top: var(--s-2); }

input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-sm);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--c-border-mid);
  border-radius: var(--r-md);
  background: #fff;
  color: var(--c-text);
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%235c6672'%3E%3Cpath d='M5.25 7.5L10 12.25 14.75 7.5H5.25z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.1rem;
  padding-right: 2.2rem;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-accent-mid);
  box-shadow: 0 0 0 3px var(--c-accent-subtle);
}
input.has-error { border-color: var(--c-red); }

.checkbox-row { display: flex; align-items: flex-start; gap: var(--s-3); font-size: var(--text-sm); }
.checkbox-row input { margin-top: 0.2rem; width: auto; }

/* ── Progress bar (quiz sub-steps) ── */
.progress-wrap { margin-bottom: var(--s-5); }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--c-text-muted); margin-bottom: var(--s-2);
}
.progress-track { height: 6px; background: var(--c-surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--c-accent-mid); border-radius: 999px; transition: width 0.35s ease; }

/* ── Banners ── */
.banner {
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: var(--text-sm);
  margin-bottom: var(--s-5);
}
.banner-error { background: var(--c-red-subtle); border: 1px solid rgba(192, 69, 90, 0.35); color: var(--c-red); }
.banner-warning { background: var(--c-amber-subtle); border: 1px solid var(--c-amber); color: var(--c-text); }
.banner-success { background: var(--c-accent-subtle); border: 1px solid var(--c-accent-mid); color: var(--c-accent-dark); }
.banner[hidden] { display: none; }

/* ── Legal / note boxes ── */
.box {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
}
.legal-box { font-size: var(--text-sm); color: var(--c-text-muted); max-height: 190px; overflow-y: auto; margin-bottom: var(--s-5); }
.legal-box strong { color: var(--c-text); }

.cal-embed { background: var(--c-navy); color: var(--c-inverse); border-radius: var(--r-lg); padding: var(--s-5); margin-top: var(--s-4); font-size: var(--text-sm); }
.cal-embed a { color: var(--c-accent); font-weight: 700; }

.email-log {
  margin-top: var(--s-8);
  border: 1px dashed var(--c-border-mid);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  font-size: var(--text-xs);
  color: var(--c-text-muted);
  background: var(--c-surface-2);
  text-align: left;
}
.email-log .log-title { font-weight: 800; color: var(--c-text); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--s-2); display: flex; align-items: center; gap: var(--s-2); }
.email-log pre { white-space: pre-wrap; font-family: 'SF Mono', Consolas, monospace; font-size: 0.7rem; line-height: 1.5; color: var(--c-text); background: #fff; border-radius: var(--r-sm); padding: var(--s-3); margin-top: var(--s-2); border: 1px solid var(--c-border); }
.dot-pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--c-red); display: inline-block; }

/* ── Summary rows ── */
.summary-box { text-align: left; margin-top: var(--s-5); font-size: var(--text-sm); }
.summary-box .row { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-2) 0; border-bottom: 1px solid var(--c-border); }
.summary-box .row:last-child { border-bottom: none; }
.summary-box .k { color: var(--c-text-muted); font-weight: 600; flex-shrink: 0; }
.summary-box .v { color: var(--c-text); font-weight: 700; text-align: right; }
.summary-box ul { padding-left: 1.1rem; font-size: var(--text-xs); color: var(--c-text-muted); }
.summary-box li { margin-bottom: var(--s-2); }

/* ── Full legal document (GET /agreement/review) ── */
.legal-doc { text-align: left; }
.legal-doc p { font-size: var(--text-sm); color: var(--c-text); line-height: 1.7; margin-bottom: var(--s-4); }
.legal-doc ol { padding-left: 1.4rem; margin-bottom: var(--s-4); }
.legal-doc ol li { font-size: var(--text-sm); color: var(--c-text); line-height: 1.7; margin-bottom: var(--s-4); }
.legal-doc .witnesseth { text-align: center; font-weight: 700; letter-spacing: 0.04em; }

/* ── Spinner ── */
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--c-border-mid);
  border-top-color: var(--c-accent-mid);
  animation: spin 0.9s linear infinite;
  margin: 0 auto var(--s-5);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Score / report presentation ── */
.score-block { display: flex; align-items: baseline; gap: var(--s-8); flex-wrap: wrap; margin-bottom: var(--s-6); }
.score-number { font-size: 3.4rem; font-weight: 800; line-height: 1; color: var(--c-navy); }
.score-suffix { font-size: var(--text-lg); color: var(--c-text-muted); }
.band-pill { display: inline-block; padding: var(--s-1) var(--s-4); border-radius: 999px; font-weight: 700; color: #fff; font-size: var(--text-sm); }

.pillar-row { padding: var(--s-3) 0; border-bottom: 1px solid var(--c-border); font-size: var(--text-sm); }
.pillar-row:last-child { border-bottom: none; }
.pillar-row .top { display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--s-2); }
.pillar-row .name { font-weight: 600; }
.pillar-row .val { font-weight: 700; color: var(--c-text); }
.pillar-row .desc { display: block; margin-top: var(--s-1); font-size: var(--text-xs); font-weight: 400; color: var(--c-text-muted); }

.section-title { font-size: var(--text-sm); font-weight: 800; margin-top: var(--s-6); margin-bottom: var(--s-3); }

.narrative-box { background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--s-5); font-size: var(--text-sm); line-height: 1.65; margin: var(--s-3) 0 var(--s-5); }
.narrative-box .l { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-accent-dark); display: block; margin-bottom: var(--s-2); }

.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: var(--s-3); margin-top: var(--s-2); }
.metric-card { position: relative; border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--s-3); background: var(--c-bg); cursor: help; }
.metric-card .l { font-size: var(--text-xs); color: var(--c-text-muted); margin-bottom: var(--s-1); }
.metric-card .v { font-size: var(--text-lg); font-weight: 700; color: var(--c-text); }

/* Hover tooltip: why a metric card shows the value (or N/A) it does --
   MetricValue.calculation/source when available, MetricValue.reason when
   not. Pure CSS (no JS): the tooltip text lives in [data-tooltip]. */
.metric-card[data-tooltip] { z-index: 1; }
.metric-card[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: 220px;
  background: var(--c-navy); color: var(--c-inverse);
  font-size: var(--text-xs); font-weight: 500; line-height: 1.4;
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--tx), transform var(--tx);
  z-index: 20;
}
.metric-card[data-tooltip]::before {
  content: ''; position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%) translateY(4px);
  border: 6px solid transparent; border-top-color: var(--c-navy);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--tx), transform var(--tx);
  z-index: 20;
}
.metric-card[data-tooltip]:hover::after, .metric-card[data-tooltip]:hover::before,
.metric-card[data-tooltip]:focus-visible::after, .metric-card[data-tooltip]:focus-visible::before {
  opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0);
}

/* ── Data availability table (all 18 scoring inputs, not just the missing ones) ── */
.table-scroll { overflow-x: auto; }
.availability-table { width: 100%; min-width: 460px; border-collapse: collapse; margin-top: var(--s-2); font-size: var(--text-sm); }
.availability-table th { text-align: left; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-border); }
.availability-table td { padding: var(--s-3); border-bottom: 1px solid var(--c-border); vertical-align: top; }
.availability-table tr:last-child td { border-bottom: none; }
.availability-table .detail { color: var(--c-text-muted); font-size: var(--text-xs); }
.status-tick, .status-cross { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-weight: 800; font-size: 0.75rem; }
.status-tick { background: var(--c-accent-subtle); color: var(--c-accent-dark); }
.status-cross { background: var(--c-red-subtle); color: var(--c-red); }

/* ── App footer ── */
.app-footer { margin-top: auto; padding: var(--s-8) 0; border-top: 1px solid var(--c-border); }
.app-footer .wrap { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); text-align: center; }
.app-footer .brand-logo { height: 1.35rem; opacity: 0.55; filter: grayscale(1); }
.app-footer p { font-size: var(--text-xs); color: var(--c-text-faint); }

.app-main { flex: 1; padding-block: var(--s-6) var(--s-16); }

.hidden { display: none !important; }
fieldset { border: none; }

/* ══════════════════════════════════════════════════════════════════════
   Internal /admin portal (admin_shell.py, admin_views.py) -- reuses every
   token above; only adds the wider layout + nav/table/badge/stat-card
   pieces the public onboarding flow never needed.
   ══════════════════════════════════════════════════════════════════════ */
.wrap-wide { width: min(calc(100% - var(--s-8)), 1120px); margin-inline: auto; }
.app-header .wrap-wide { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: 4.5rem; }
.app-footer .wrap-wide { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); text-align: center; }

.admin-account { display: flex; align-items: center; gap: var(--s-4); }
.admin-account-name { font-size: var(--text-sm); color: var(--c-text-muted); }
.admin-account-name strong { color: var(--c-text); }
.admin-account .btn-ghost { min-height: auto; padding: var(--s-2) var(--s-3); }

.admin-nav { border-bottom: 1px solid var(--c-border); background: var(--c-surface); }
.admin-nav .wrap-wide { display: flex; gap: var(--s-2); }
.admin-nav-link {
  display: inline-block; padding: var(--s-4) var(--s-3);
  font-size: var(--text-sm); font-weight: 600; color: var(--c-text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--tx), border-color var(--tx);
}
.admin-nav-link:hover { color: var(--c-navy); }
.admin-nav-link.active { color: var(--c-navy); border-bottom-color: var(--c-accent-mid); }

.admin-body .app-main { padding-block: var(--s-8) var(--s-16); }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-header h1 { font-size: var(--text-2xl); font-weight: 800; }
.page-header p { margin-top: var(--s-1); }

/* ── Login card ── */
.admin-login-wrap { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.admin-login-card { max-width: 380px; width: 100%; text-align: center; }
.admin-login-card h2 { font-size: var(--text-xl); margin-bottom: var(--s-2); }
.admin-login-note { font-size: var(--text-xs); color: var(--c-text-faint); margin-top: var(--s-5); }

/* ── Dashboard stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-8); }
.stat-card { display: block; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-xs); text-decoration: none; color: inherit; }
.stat-card .stat-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); margin-bottom: var(--s-2); }
.stat-card .stat-value { font-size: var(--text-2xl); font-weight: 800; color: var(--c-navy); }
.stat-card--link { cursor: pointer; transition: border-color var(--tx), box-shadow var(--tx), transform var(--tx); }
.stat-card--link:hover { border-color: var(--c-navy); box-shadow: var(--shadow-sm, var(--shadow-xs)); transform: translateY(-1px); }

/* ── Data tables (leads / clients / recent leads) ── */
.table-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-xs); }
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th { text-align: left; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); padding: var(--s-3) var(--s-4); background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.data-table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; transition: background var(--tx); }
.data-table tbody tr.clickable:hover { background: var(--c-surface-2); }
.data-table .muted-cell { color: var(--c-text-faint); }
.data-table .empty-row td { text-align: center; padding: var(--s-10); color: var(--c-text-faint); }
/* Real links inside a data-table cell (email/company URL) -- `a { color:
   inherit }` above would otherwise make them indistinguishable from the
   plain-text cells around them, so they need their own affordance. */
.data-table td a,
.detail-row .v a { color: var(--c-accent-dark); text-decoration: underline; text-decoration-color: transparent; transition: text-decoration-color var(--tx); }
.data-table td a:hover,
.detail-row .v a:hover { text-decoration-color: currentColor; }

/* Compact variant: more columns than fit comfortably at the roomy row height
   above (e.g. the dashboard's 8-column Recent Leads preview) -- trades row
   height and per-cell padding for guaranteed-fits-without-scrolling instead
   of the horizontal scrollbar the roomy variant falls back to. table-layout:
   fixed + a <colgroup> keeps every column's width content-independent, and
   overflow/ellipsis on both cells and the badge/pill chips means a long
   email, URL, or stage label quietly truncates instead of blowing out the
   column or wrapping to a second line. */
.data-table--compact { table-layout: fixed; min-width: 0; font-size: var(--text-xs); }
.data-table--compact th,
.data-table--compact td { padding: var(--s-2) var(--s-3); }
.data-table--compact td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table--compact .badge-status,
.data-table--compact .stage-pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }

/* ── Status badges (never color-only: each carries a distinct label/icon) ── */
.badge-status { display: inline-flex; align-items: center; gap: var(--s-1); padding: 3px var(--s-3); border-radius: 999px; font-size: var(--text-xs); font-weight: 700; white-space: nowrap; }
.badge-qualified { background: var(--c-accent-subtle); color: var(--c-accent-dark); }
.badge-unqualified { background: var(--c-red-subtle); color: var(--c-red); }
.badge-pending { background: var(--c-amber-subtle); color: var(--c-amber); }
.badge-progress { background: var(--c-surface-2); color: var(--c-navy); border: 1px solid var(--c-border-mid); }
.status-note { display: block; margin-top: var(--s-1); font-size: var(--text-xs); color: var(--c-text-muted); white-space: normal; }
.filter-tabs + .filter-tabs { margin-left: var(--s-2); }
.stage-pill { display: inline-block; padding: 3px var(--s-3); border-radius: 999px; font-size: var(--text-xs); font-weight: 600; background: var(--c-surface-2); color: var(--c-text); border: 1px solid var(--c-border-mid); white-space: nowrap; }

/* ── Filters / search ── */
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-4); }
.filter-tabs { display: inline-flex; gap: var(--s-1); background: var(--c-surface-2); padding: 3px; border-radius: 999px; }
.filter-tab { padding: var(--s-2) var(--s-4); border-radius: 999px; font-size: var(--text-sm); font-weight: 600; color: var(--c-text-muted); }
.filter-tab.active { background: var(--c-navy); color: var(--c-inverse); }
.search-input { max-width: 280px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--s-3); margin-top: var(--s-5); font-size: var(--text-sm); color: var(--c-text-muted); }

/* ── Lead detail ── */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-6); }
.detail-section { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: var(--s-6); box-shadow: var(--shadow-xs); }
.detail-section h3 { font-size: var(--text-sm); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); margin-bottom: var(--s-4); }
.detail-row { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-2) 0; border-bottom: 1px solid var(--c-border); font-size: var(--text-sm); }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--c-text-muted); }
.detail-row .v { color: var(--c-text); font-weight: 600; text-align: right; }

.progress-track-h { display: flex; align-items: center; gap: 0; margin-bottom: var(--s-6); }
.progress-step { flex: 1; text-align: center; position: relative; }
.progress-step:not(:last-child)::after { content: ''; position: absolute; top: 13px; left: 50%; width: 100%; height: 2px; background: var(--c-border-mid); z-index: 0; }
.progress-step.done:not(:last-child)::after, .progress-step.current:not(:last-child)::after { background: var(--c-accent-mid); }
.progress-step .dot { position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--c-surface); border: 2px solid var(--c-border-mid); color: var(--c-text-faint); font-size: 0.7rem; font-weight: 800; }
.progress-step.done .dot { background: var(--c-accent-mid); border-color: var(--c-accent-mid); color: var(--c-navy-dark); }
.progress-step.current .dot { background: var(--c-navy); border-color: var(--c-navy); color: var(--c-inverse); }
.progress-step .step-label { display: block; margin-top: var(--s-2); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--c-text-faint); }
.progress-step.done .step-label, .progress-step.current .step-label { color: var(--c-navy); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .app-header .brand-tag { display: none; }
  .stepper { margin: var(--s-6) 0 var(--s-6); }
  .step .label { font-size: 0.58rem; }
  .btn-row { flex-direction: column; }
  .card { padding: var(--s-6) var(--s-5); }
  .score-block { gap: var(--s-4); }
  .admin-account-name { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ══════════════════════════════════════════════════════════════════════
   Client Login link + support messaging (client Messages tab, admin inbox)
   ══════════════════════════════════════════════════════════════════════ */
.header-links { display: flex; align-items: center; gap: var(--s-4); }
.client-login-link {
  display: inline-flex; align-items: center; min-height: 36px;
  padding: 0 var(--s-4); border: 1.5px solid var(--c-navy); border-radius: 999px;
  font-size: var(--text-sm); font-weight: 700; color: var(--c-navy); white-space: nowrap;
  transition: background var(--tx), color var(--tx);
}
.client-login-link:hover { background: var(--c-navy); color: var(--c-inverse); }

.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; }
.btn-row-inline { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; }

.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem; margin-left: var(--s-2);
  border-radius: 999px; background: var(--c-red); color: #fff;
  font-size: 0.7rem; font-weight: 800; line-height: 1; vertical-align: middle;
}
.nav-badge[hidden] { display: none; }
.nav-badge--inline { margin-left: 0; }
.admin-nav-link[aria-current="page"] { font-weight: 800; }

.row-unread td { font-weight: 700; }
.preview-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-card { padding: var(--s-6); }
.chat-card--wide { max-width: none; }
.chat-notice { font-size: var(--text-sm); color: var(--c-text-muted); margin-bottom: var(--s-4); }
.chat-status { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--c-amber); margin-bottom: var(--s-3); }
.chat-status[hidden] { display: none; }
.chat-thread {
  display: flex; flex-direction: column; gap: var(--s-3);
  height: min(55vh, 480px); min-height: 240px; overflow-y: auto;
  padding: var(--s-4); margin-bottom: var(--s-4);
  background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--r-md);
}
.chat-empty { margin: auto; text-align: center; color: var(--c-text-muted); font-size: var(--text-sm); max-width: 32ch; }
.chat-empty[hidden] { display: none; }
.msg { display: flex; }
.msg-mine { justify-content: flex-end; }
.msg-staff, .msg-client { justify-content: flex-start; }
.msg-bubble {
  max-width: min(80%, 560px); padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); border: 1px solid var(--c-border);
  background: var(--c-surface); overflow-wrap: anywhere;
}
.msg-mine .msg-bubble { background: var(--c-accent-subtle); border-color: rgba(58, 155, 86, 0.35); }
.msg-staff .msg-bubble { background: var(--c-navy); border-color: var(--c-navy); color: var(--c-inverse); }
.msg-staff .msg-meta, .msg-staff .msg-seen { color: rgba(245, 241, 233, 0.72); }
.msg-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2); font-size: var(--text-xs); color: var(--c-text-muted); margin-bottom: var(--s-1); }
.msg-sender { font-weight: 800; }
.msg-text { white-space: pre-wrap; font-size: var(--text-sm); line-height: 1.5; }
.msg-seen { margin-top: var(--s-1); font-size: var(--text-xs); color: var(--c-text-faint); text-align: right; }
.msg-tag-new { background: var(--c-accent); color: var(--c-navy-dark); border-radius: 999px; padding: 1px var(--s-2); font-weight: 800; font-size: 0.65rem; text-transform: uppercase; }
.chat-form textarea { width: 100%; }
.chat-meta { display: flex; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-2); }
.chat-meta .helptext { margin: 0; }
.chat-counter { font-size: var(--text-xs); color: var(--c-text-muted); white-space: nowrap; }
.chat-counter.over { color: var(--c-red); font-weight: 800; }

@media (max-width: 640px) {
  .header-links { gap: var(--s-3); }
  .app-header .header-links .site-link { display: none; }
  .client-login-link { padding: 0 var(--s-3); }
  .chat-card { padding: var(--s-4); }
  .chat-thread { height: 50vh; padding: var(--s-3); }
  .msg-bubble { max-width: 92%; }
  .chat-meta { flex-direction: column; gap: var(--s-1); }
  .btn-row-inline { width: 100%; }
  .admin-nav .wrap-wide { overflow-x: auto; }
}

/* ══════════════════════════════════════════════════════════════════════
   Books Health page -- the wide layout itself is just .wrap-wide +
   .detail-grid (both already existed for the admin lead-detail page); the
   only genuinely new pieces are the provenance-signal badges and the
   history trend chart's sizing below.
   ══════════════════════════════════════════════════════════════════════ */
.signal-badge {
  display: inline-flex; align-items: center; padding: 2px var(--s-3);
  border-radius: 999px; font-size: var(--text-xs); font-weight: 700;
  white-space: nowrap;
}
.signal-direct      { background: var(--c-accent-subtle); color: var(--c-accent-dark); }
.signal-calculated  { background: rgba(47, 125, 209, 0.12); color: #2f7dd1; }
.signal-inferred    { background: var(--c-amber-subtle); color: var(--c-amber); }
.signal-unavailable { background: var(--c-red-subtle); color: var(--c-red); }

.legend-row { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; font-size: var(--text-sm); }
.legend-row .desc { color: var(--c-text-muted); }

.action-pillar {
  display: inline-block; margin-top: var(--s-2); font-size: var(--text-xs); font-weight: 700;
  color: var(--c-text-muted); text-transform: uppercase; letter-spacing: 0.04em;
}

.bh-trend-chart { margin: var(--s-4) 0; }
.bh-trend-svg { width: 100%; height: auto; max-height: 160px; display: block; }

@media (max-width: 640px) {
  .legend-row { flex-wrap: wrap; }
}

/* ══════════════════════════════════════════════════════════════════════
   Pizza Tracker -- an 8-slice accessible SVG "pizza" progress ring plus
   its text/list equivalents (client_tracker_views.py builds the markup;
   this only styles it). Every status is carried by a shape/glyph as well
   as color (checkmark / dot / alert mark), never color alone.
   ══════════════════════════════════════════════════════════════════════ */
.pizza-page .tag { margin-bottom: var(--s-3); }
.pizza-layout { display: flex; gap: var(--s-8); align-items: flex-start; margin: var(--s-6) 0; }
.pizza-layout-empty { align-items: center; }
.pizza-visual { flex: 0 0 240px; max-width: 240px; margin-inline: auto; }
.pizza-svg { width: 100%; height: auto; display: block; }
.pizza-panel { flex: 1; min-width: 0; }
.pizza-panel-heading { margin: 0 0 var(--s-2); font-size: var(--text-lg); font-weight: 800; }

.pizza-slice { stroke: var(--c-bg); stroke-width: 2; }
.pizza-slice-completed { fill: var(--c-accent-mid); }
.pizza-slice-current { fill: #d9a441; }
.pizza-slice-upcoming { fill: var(--c-surface-2); }
.pizza-glyph-check { stroke: var(--c-navy-dark); }
.pizza-glyph-dot { fill: #fff; }
.pizza-glyph-alert { stroke: var(--c-navy-dark); fill: var(--c-navy-dark); }
.pizza-center-disc { fill: var(--c-bg); stroke: var(--c-border-mid); stroke-width: 1.5; }
.pizza-center-pct { font-size: 2rem; font-weight: 800; fill: var(--c-navy); font-family: var(--font-body); }
.pizza-center-status { font-size: 0.66rem; font-weight: 700; fill: var(--c-text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-family: var(--font-body); }
.pizza-visual-complete .pizza-center-disc { stroke: var(--c-accent-mid); stroke-width: 2.5; }

.pizza-action-box { margin-top: var(--s-4); padding: var(--s-4); border: 1.5px solid var(--c-amber); border-radius: var(--r-md); background: var(--c-amber-subtle); }
.pizza-action-label { font-size: var(--text-xs); font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--c-amber); margin-bottom: var(--s-1); }
.pizza-action-text { color: var(--c-text); margin-bottom: var(--s-3); }

.pizza-stage-list { list-style: none; }
.pizza-stage-row { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--c-border); }
.pizza-stage-row:last-child { border-bottom: none; }
.pizza-stage-icon {
  flex: 0 0 24px; height: 24px; width: 24px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 0.8rem; font-weight: 800; background: var(--c-surface-2); color: var(--c-text-faint);
}
.pizza-stage-row-completed .pizza-stage-icon { background: var(--c-accent-mid); color: var(--c-navy-dark); }
.pizza-stage-row-current .pizza-stage-icon { background: #d9a441; color: #fff; }
.pizza-stage-text { flex: 1; min-width: 0; }
.pizza-stage-text .name { display: block; font-weight: 700; }
.pizza-stage-text .desc { display: block; font-size: var(--text-xs); color: var(--c-text-muted); margin-top: 2px; }
.pizza-stage-status { flex: 0 0 auto; font-size: var(--text-xs); color: var(--c-text-muted); white-space: nowrap; }

.pizza-update-row { padding: var(--s-3) 0; border-bottom: 1px solid var(--c-border); }
.pizza-update-row:last-child { border-bottom: none; }
.pizza-update-meta { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--text-xs); color: var(--c-text-muted); margin-bottom: var(--s-1); flex-wrap: wrap; }
.pizza-update-stage { font-weight: 700; }
.pizza-update-text { color: var(--c-text); font-size: var(--text-sm); }

@media (prefers-reduced-motion: no-preference) {
  .pizza-stage-row { transition: background var(--tx); }
}

@media (max-width: 640px) {
  .pizza-layout { flex-direction: column; align-items: stretch; }
  .pizza-visual { max-width: 220px; }
  .pizza-stage-row { flex-wrap: wrap; }
  .pizza-stage-status { white-space: normal; flex: 1 0 100%; padding-left: calc(24px + var(--s-3)); }
}

/* ══════════════════════════════════════════════════════════════════════
   Report Delivery (client Reports tab + admin publishing page)
   ══════════════════════════════════════════════════════════════════════ */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.report-page .table-card { margin-top: var(--s-2); }
.report-table .report-title { font-weight: 700; color: var(--c-text); }
.report-table td.report-actions { text-align: right; white-space: nowrap; }
.report-table .btn-primary,
.report-table .btn-ghost { min-height: 36px; padding: var(--s-2) var(--s-4); font-size: var(--text-xs); }
/* `.data-table td a` would otherwise turn the button text green on the green button. */
.report-table .btn-primary { color: var(--c-navy-dark); }
/* Download PDF + Download Excel side by side; a version without Excel shows why, wrapped under the PDF button. */
.report-downloads { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--s-2); }
.report-excel-unavailable { margin: 0; max-width: 22rem; white-space: normal; text-align: left; font-size: var(--text-xs); }
/* The client Statements table has four short columns: let it fit the tablet layout instead of scrolling sideways. */
.report-page .report-table { min-width: 0; }
.report-empty { text-align: center; padding: var(--s-10) var(--s-5); }
.report-empty h2 { font-size: var(--text-lg); font-weight: 800; margin-bottom: var(--s-2); }
.report-empty .card-sub { margin-bottom: var(--s-4); }
@media (max-width: 640px) {
  /* Stack each report as a labelled card instead of a sideways-scrolling table. */
  .report-table { min-width: 0; }
  .report-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .report-table tr { display: block; padding: var(--s-4); border-bottom: 1px solid var(--c-border); }
  .report-table tbody tr:last-child { border-bottom: none; }
  .report-table td { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-1) 0; border: none; text-align: right; }
  .report-table td::before { content: attr(data-label); font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); text-align: left; }
  .report-table td.report-actions { display: block; padding-top: var(--s-3); }
  .report-table td.report-actions::before { content: none; }
  .report-table td.report-actions .report-downloads { display: flex; flex-direction: column; align-items: stretch; }
  .report-table td.report-actions .btn-primary,
  .report-table td.report-actions .btn-ghost { width: 100%; min-height: 44px; justify-content: center; }
  .report-excel-unavailable { max-width: none; }
}

/* Report Delivery: client sections by report type + staff review workbench */
.report-section { margin-top: var(--s-6); }
.report-section h2 { font-size: var(--text-lg); font-weight: 800; margin-bottom: var(--s-3); }
.report-section-empty { margin-bottom: 0; }
.report-commentary { margin-top: var(--s-2); font-size: var(--text-sm); }
.report-commentary summary { cursor: pointer; font-weight: 700; color: var(--c-navy); }
.report-commentary p { margin-top: var(--s-2); white-space: pre-line; color: var(--c-text); }
.review-overview { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.review-overview li { display: flex; gap: var(--s-3); align-items: flex-start; }
.review-step-num { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 28px; height: 28px; border-radius: 999px; background: var(--c-surface-2); color: var(--c-navy); font-size: var(--text-xs); font-weight: 800; }
.review-card { margin-top: var(--s-4); }
.review-card h3 { font-size: var(--text-sm); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text-muted); margin: var(--s-5) 0 var(--s-2); }
.review-card-head { display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.review-card-head h2 { margin-bottom: var(--s-1); }
.review-card-tags { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: flex-start; }
.review-steps { list-style: none; padding: 0; margin: var(--s-4) 0 var(--s-2); display: flex; gap: var(--s-2); flex-wrap: wrap; }
.review-step { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3) var(--s-1) var(--s-1); border-radius: 999px; border: 1px solid var(--c-border); font-size: var(--text-xs); font-weight: 700; color: var(--c-text-muted); }
.review-step.done { color: var(--c-accent-dark); }
.review-step.done .review-step-num { background: var(--c-accent-mid); color: var(--c-navy-dark); }
.review-step.current { border-color: var(--c-navy); color: var(--c-navy); }
.review-step.current .review-step-num { background: var(--c-navy); color: var(--c-inverse); }
.review-buttons { flex-wrap: wrap; }
.review-buttons .btn-primary { flex: 0 1 auto; }
.review-notify { display: flex; gap: var(--s-2); align-items: center; font-size: var(--text-sm); margin-top: var(--s-3); }
.review-history { margin-top: var(--s-4); }
.review-history summary { cursor: pointer; font-weight: 700; font-size: var(--text-sm); color: var(--c-navy); margin-bottom: var(--s-2); }
@media (max-width: 900px) { .review-overview { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .review-overview { grid-template-columns: 1fr; } }
.review-zero-activity { margin-top: var(--s-4); }
.review-zero-activity strong { color: var(--c-amber); display: block; margin-bottom: var(--s-1); }
.review-ai-draft, .review-ai-error { margin: var(--s-2) 0 var(--s-3); }
.review-ai-draft strong, .review-ai-error strong { display: block; margin-bottom: var(--s-1); }
