/* ============================================================
   TenorMD — design tokens + app styles
   Implements the TenorMD Design System (Harbor / Sage / Clay,
   warm Paper & Ink neutrals, Newsreader + IBM Plex, peer-band
   scoring). Warm, editorial, clinical-but-human.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&display=swap');

:root {
  /* Harbor · brand primary (teal-navy) */
  --harbor-900: #0F2C35; --harbor-700: #16404D; --harbor-600: #1D4E5C;
  --harbor-500: #2A6376; --harbor-400: #4C8194; --harbor-200: #A7C4CE;
  --harbor-100: #DCE9ED; --harbor-50: #EEF4F6;
  /* Sage · growth / success */
  --sage-700: #3E6A53; --sage-600: #4E7A63; --sage-500: #5B8A72;
  --sage-200: #BFD7C8; --sage-100: #E3EFE7;
  /* Clay · warm accent (sparingly) */
  --clay-700: #9C5234; --clay-600: #B5673F; --clay-500: #C2754E;
  --clay-300: #D9A884; --clay-200: #EAC8B3; --clay-100: #F6E7DD; --clay-50: #FBF3EC;
  /* Warm neutrals · Paper & Ink */
  --paper: #F7F5F1; --paper-shade: #F0EDE7; --surface: #FFFFFF; --line: #E4DFD6;
  --ink-900: #1B2A33; --ink-700: #3A4A54; --ink-500: #65737C; --ink-400: #97A2A8;
  /* Peer-band score scale (signature) */
  --score-a: #2E7D54; --score-b: #6E9A55; --score-c: #C4912F; --score-d: #B0413A; --score-na: #9AA6A0;
  /* Semantic */
  --success: #2E7D54; --success-bg: #E6F2EA; --success-line: #C7E1D3;
  --warning: #B45309; --warning-bg: #FBF1E0; --warning-line: #F0D9A8;
  --danger: #B0413A; --danger-bg: #F7E5E3; --danger-line: #EBC4BF;
  --info: #1D4E5C; --info-bg: #EEF4F6;
  /* Plan tiers */
  --plan-free: #65737C; --plan-practice: #4E7A63; --plan-group: #1D4E5C;
  /* Aliases */
  --brand: var(--harbor-600); --brand-hover: var(--harbor-700); --brand-strong: var(--harbor-900);
  --accent: var(--clay-500);
  --text-primary: var(--ink-900); --text-secondary: var(--ink-700);
  --text-muted: var(--ink-500); --text-subtle: var(--ink-400);
  --border-default: var(--line); --border-strong: #D7D0C4;

  /* Type */
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --type-display: 500 56px/1.12 var(--font-display);
  --type-h1: 600 32px/1.18 var(--font-display);
  --type-h2: 600 26px/1.22 var(--font-display);
  --type-title: 600 20px/1.3 var(--font-sans);
  --type-lead: 400 18px/1.55 var(--font-sans);
  --type-body: 400 15px/1.55 var(--font-sans);
  --type-label: 500 13px/1.3 var(--font-sans);
  --type-caption: 400 13px/1.45 var(--font-sans);
  --type-eyebrow: 700 11px/1 var(--font-sans);
  --type-mono: 400 12px/1.4 var(--font-mono);
  --tracking-tight: -0.02em; --tracking-wide: 0.04em; --tracking-caps: 0.08em;

  /* Space / radius / shadow */
  --card-pad: 18px 20px;
  --radius-xs: 4px; --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius-xl: 20px; --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(27,42,51,.05);
  --shadow-md: 0 2px 4px rgba(27,42,51,.05), 0 8px 18px rgba(27,42,51,.07);
  --shadow-brand: 0 6px 20px rgba(29,78,92,.18);
  --shadow-focus: 0 0 0 3px rgba(42,99,118,.28);
  --container: 940px; --topbar-height: 56px;
  --transition-base: 160ms cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.22,.61,.36,1);
}

* , *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--paper); color: var(--text-secondary);
  font: var(--type-body); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1 { font: var(--type-h1); color: var(--text-primary); margin: 0; letter-spacing: var(--tracking-tight); text-wrap: balance; }
h2 { font: var(--type-h2); color: var(--text-primary); margin: 0; letter-spacing: var(--tracking-tight); text-wrap: balance; }
h3 { font: var(--type-title); color: var(--text-primary); margin: 0; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--brand); text-decoration: none; transition: color 120ms var(--ease-out); }
a:hover { color: var(--brand-hover); }
strong { font-weight: 600; color: var(--text-primary); }
::selection { background: var(--harbor-100); color: var(--brand-strong); }
:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-xs); }
table, .num, .tnum { font-variant-numeric: tabular-nums; }
[data-lucide] { stroke-width: 1.75; vertical-align: middle; display: inline-flex; }

/* ---- Top bar -------------------------------------------------- */
.topbar {
  height: var(--topbar-height); background: var(--harbor-900);
  display: flex; align-items: center; gap: 18px; padding: 0 22px;
  position: sticky; top: 0; z-index: 100;
}
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; height: 30px; }
.tagline { font: var(--type-caption); color: var(--harbor-200); border-left: 1px solid rgba(255,255,255,.16); padding-left: 16px; }
.orgnav { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.orgnav > a { color: #fff; font: var(--type-label); opacity: .9; display: inline-flex; align-items: center; gap: 6px; }
.orgnav > a:hover { color: #fff; opacity: 1; }
.whoami { font: var(--type-caption); color: var(--harbor-200); display: inline-flex; align-items: center; gap: 7px; }
.linkbtn { background: none; border: none; color: var(--harbor-200); font: var(--type-caption); cursor: pointer; padding: 0; }
.linkbtn:hover { color: #fff; }

/* ---- Layout --------------------------------------------------- */
.container { max-width: var(--container); margin: 0 auto; padding: 26px 22px 80px; }
.crumbs { font: var(--type-caption); color: var(--text-muted); margin-bottom: 14px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--brand); }
.muted { color: var(--text-muted); }
.lead { font: var(--type-lead); color: var(--text-secondary); }
.error { color: var(--danger); }
.center, .centered { text-align: center; }
.reader { max-width: 720px; margin: 0 auto; }
.eyebrow { font: var(--type-eyebrow); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-muted); }
.hero { padding: 8px 0 4px; }
.hero h1 { font: var(--type-display); font-size: clamp(34px, 5vw, 56px); letter-spacing: var(--tracking-tight); margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* ---- Cards ---------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: var(--card-pad);
  box-shadow: var(--shadow-xs); position: relative; margin: 18px 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card.locked { background: var(--warning-bg); border-color: var(--warning-line); }
.card.success { background: var(--success-bg); border-color: var(--success-line); }
.card.accent-top { border-top: 4px solid var(--brand); }
.narrow { max-width: 460px; margin: 32px auto; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---- Forms ---------------------------------------------------- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline { display: inline-flex; gap: 8px; align-items: center; }
.inline-form { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid2 .span2 { grid-column: 1 / -1; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font: var(--type-label); color: var(--text-secondary); }
label.inline { flex-direction: row; align-items: center; color: var(--text-primary); }
input, select, textarea {
  font: var(--type-body); color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; width: 100%; transition: border-color 160ms, box-shadow 160ms;
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:hover, select:hover, textarea:hover { border-color: var(--harbor-400); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--harbor-500); box-shadow: var(--shadow-focus); }
input[type=number] { width: 110px; }
textarea { resize: vertical; }

/* ---- Buttons -------------------------------------------------- */
button, .btn {
  font: 600 15px/1 var(--font-sans); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 9px 16px; cursor: pointer; white-space: nowrap; transition: var(--transition-base);
}
button:hover, .btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); text-decoration: none; color: #fff; }
.btn.ghost { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--paper-shade); color: var(--text-primary); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: var(--clay-600); border-color: var(--clay-600); }
.btn.big { padding: 12px 22px; font-size: 18px; }
.btn.block { display: flex; width: 100%; }
button:disabled, .btn[disabled] { opacity: .5; cursor: default; pointer-events: none; }
button.mini { padding: 6px 11px; font-size: 13px; }
button.mini.ghost { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.noprint .btn svg, .btn svg { width: 1.05em; height: 1.05em; }

/* ---- Tables --------------------------------------------------- */
.tbl { width: 100%; border-collapse: collapse; font: var(--type-body); }
.tbl th {
  text-align: left; font: var(--type-eyebrow); text-transform: uppercase;
  letter-spacing: var(--tracking-caps); color: var(--text-muted);
  padding: 0 12px 10px; border-bottom: 1px solid var(--border-default);
}
.tbl td { padding: 13px 12px; border-bottom: 1px solid var(--border-default); vertical-align: middle; color: var(--text-secondary); }
.tbl tr:last-child td { border-bottom: none; }
.tbl td a { font-weight: 500; }
.tbl.report td:first-child { width: 42%; }
.qrow-label, .tbl .name { color: var(--text-primary); font-weight: 600; }

/* ---- Badges + plan pill --------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font: var(--type-eyebrow); text-transform: uppercase; letter-spacing: var(--tracking-wide);
  padding: 4px 9px; border-radius: var(--radius-pill); background: var(--paper-shade); color: var(--ink-700);
}
.badge.open { background: var(--success-bg); color: var(--success); }
.badge.closed { background: var(--paper-shade); color: var(--ink-500); }
.badge.failed { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--harbor-50); color: var(--harbor-600); }
.planpill {
  display: inline-flex; align-items: center; font: var(--type-eyebrow);
  text-transform: uppercase; letter-spacing: var(--tracking-wide);
  padding: 4px 10px; border-radius: var(--radius-pill); color: #fff !important;
  background: var(--plan-free);
}
.planpill:hover { opacity: .9; text-decoration: none; }
.planpill.practice { background: var(--plan-practice); }
.planpill.group { background: var(--plan-group); }

.copy { width: 100%; font: var(--type-mono); color: var(--text-secondary); background: var(--paper); }

/* ---- Score band (report headline) ----------------------------- */
.band { display: inline-flex; flex-direction: column; gap: 7px; }
.band__head { display: flex; align-items: center; gap: 11px; font-family: var(--font-display); font-weight: 600; color: var(--text-primary); line-height: 1.1; letter-spacing: var(--tracking-tight); font-size: 34px; }
.band__dot { flex: none; width: 14px; height: 14px; border-radius: var(--radius-pill); }
.band__sub { font: var(--type-caption); font-size: 15px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.report-summary { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }
.kpi-row { display: flex; gap: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- Stat tiles ----------------------------------------------- */
.stat { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border-default); border-radius: var(--radius-md); padding: 16px 18px; flex: 1 1 150px; }
.stat__label { font: var(--type-eyebrow); text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--text-muted); }
.stat__value { font-family: var(--font-display); font-weight: 600; font-size: 30px; line-height: 1.1; color: var(--text-primary); }
.stat__value.mono { font-family: var(--font-mono); font-size: 26px; }
.stat__sub { font: var(--type-caption); color: var(--text-muted); }

/* ---- Band tag (per-question result) --------------------------- */
.band-tag { display: inline-flex; align-items: center; gap: 8px; font: var(--type-caption); color: var(--text-primary); font-weight: 500; white-space: nowrap; }
.band-tag__dot { width: 9px; height: 9px; border-radius: var(--radius-pill); flex: none; }
.qrow-result { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Distribution bar (signature motif) ----------------------- */
.distbar { display: flex; height: 14px; border-radius: var(--radius-xs); overflow: hidden; background: var(--paper-shade); width: 180px; }
.seg { height: 100%; transition: width 320ms var(--ease-out); }
.seg4 { background: var(--score-a); } .seg3 { background: var(--score-b); }
.seg2 { background: var(--score-c); } .seg1 { background: var(--score-d); }

/* ---- Comments ------------------------------------------------- */
.comments { list-style: none; margin: 6px 0 14px; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.comments li { background: var(--paper); border: 1px solid var(--border-default); border-left: 3px solid var(--harbor-200); border-radius: var(--radius-sm); padding: 11px 14px; }
.qlabel { font: var(--type-title); color: var(--harbor-600); margin: 14px 0 8px; }

/* ---- Trend chart ---------------------------------------------- */
.chart { padding: 6px 0; }
.chart svg { width: 100%; height: 190px; }

/* ---- Survey --------------------------------------------------- */
.survey-intro { border-top: 4px solid var(--brand); }
.survey .qblock { padding: 18px 0; border-bottom: 1px solid var(--border-default); }
.survey .qblock:last-of-type { border-bottom: none; }
.qtext { font: var(--type-title); font-size: 18px; color: var(--text-primary); margin: 0 0 12px; }
.phi-note { display: flex; align-items: center; gap: 6px; margin-top: 6px; font: var(--type-caption); color: var(--text-muted); }
.phi-note svg { color: var(--warning); flex: none; }
.ratings { display: flex; flex-direction: column; gap: 7px; }
.ratings.agree { flex-direction: row; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 13px; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-default); background: var(--surface); cursor: pointer;
  transition: var(--transition-base); user-select: none; flex-direction: row; color: var(--text-secondary);
}
.ratings.agree .opt { flex: 1; justify-content: center; }
.opt:hover { border-color: var(--harbor-400); background: var(--harbor-50); }
.opt:has(input:checked) { border-color: var(--harbor-500); background: var(--harbor-50); box-shadow: inset 0 0 0 1px var(--harbor-500); }
.opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.opt .tier { flex: none; width: 4px; height: 22px; border-radius: var(--radius-pill); background: var(--harbor-400); }
.opt .radio { flex: none; width: 18px; height: 18px; border-radius: var(--radius-pill); border: 2px solid var(--border-strong); position: relative; transition: var(--transition-base); }
.opt:hover .radio { border-color: var(--harbor-400); }
.opt:has(input:checked) .radio { border-color: var(--harbor-600); }
.opt:has(input:checked) .radio::after { content: ''; position: absolute; inset: 3px; border-radius: var(--radius-pill); background: var(--harbor-600); }
.optlabel { font: var(--type-body); color: var(--text-secondary); }
.opt:has(input:checked) .optlabel { color: var(--text-primary); font-weight: 500; }
.opt.na .tier { background: var(--score-na); }

/* ---- Banners / upsell / success ------------------------------- */
.upsell {
  background: var(--harbor-50); border: 1px solid var(--harbor-100); border-radius: var(--radius-md);
  padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.upsell p { margin: 0; }
.upsell .btn { white-space: nowrap; }

/* ---- Pricing / plan grid -------------------------------------- */
.plangrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 16px 0; }
.plan { position: relative; background: var(--surface); border: 1px solid var(--border-default); border-radius: var(--radius-xl); padding: 24px 22px; display: flex; flex-direction: column; }
.plan.featured { border-color: var(--brand); box-shadow: var(--shadow-brand); }
.plan.current { border-color: var(--success); }
.plan h2 { margin: 0 0 4px; }
.plan .price { font-family: var(--font-display); font-size: 32px; font-weight: 600; color: var(--brand); margin: 4px 0; }
.plan .blurb { min-height: 42px; color: var(--text-muted); }
.plan .checks { list-style: none; padding: 0; margin: 14px 0 18px; flex: 1; }
.plan .checks li { padding: 6px 0 6px 24px; position: relative; }
.plan .checks li::before { content: ''; position: absolute; left: 2px; top: 11px; width: 11px; height: 6px; border-left: 2px solid var(--sage-600); border-bottom: 2px solid var(--sage-600); transform: rotate(-45deg); }
.plan .ribbon { position: absolute; top: -11px; right: 18px; background: var(--brand); color: #fff; font: var(--type-eyebrow); text-transform: uppercase; letter-spacing: var(--tracking-wide); padding: 4px 10px; border-radius: var(--radius-pill); }
.plan.current .ribbon { background: var(--success); }

/* ---- Seeding footer (growth loop) ----------------------------- */
.seedfooter { max-width: var(--container); margin: 8px auto 0; text-align: center; font: var(--type-caption); color: var(--text-muted); padding: 14px; border-top: 1px dashed var(--border-default); }

/* ---- Email preview / outbox ----------------------------------- */
.email .meta th { width: 90px; text-align: left; color: var(--text-muted); font: var(--type-eyebrow); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
.emailbody { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; white-space: pre-wrap; font: var(--type-body); }

/* ---- Questionnaire editor ------------------------------------- */
.qedit .retired td { opacity: .5; }
.qedit .qrow { flex-wrap: nowrap; }
.qedit .qrow input[type=text] { flex: 1; min-width: 200px; }
.movecell { white-space: nowrap; width: 60px; }
label.tiny { font: var(--type-caption); color: var(--text-muted); flex-direction: row; align-items: center; }
.kind { font: var(--type-eyebrow); text-transform: uppercase; letter-spacing: var(--tracking-wide); padding: 3px 8px; border-radius: var(--radius-pill); background: var(--harbor-50); color: var(--harbor-600); }
.kind-comment { background: var(--sage-100); color: var(--sage-700); }
.kind-agree { background: var(--clay-100); color: var(--clay-700); }

/* ---- Upgrade page --------------------------------------------- */
.upgrade-hero { text-align: center; }
.upgrade-hero .lockbadge { color: var(--brand); display: inline-flex; margin-bottom: 4px; }

/* ---- Footer --------------------------------------------------- */
.foot { text-align: center; font: var(--type-caption); color: var(--text-muted); padding: 28px; border-top: 1px solid var(--border-default); display: flex; flex-direction: column; gap: 6px; }
.footlinks a { color: var(--text-muted); }
.footlinks a:hover { color: var(--brand); }

/* ---- Print ---------------------------------------------------- */
@media print {
  .topbar, .crumbs, .foot, .noprint, .actions, .seedfooter { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 8px 0; margin: 8px 0; break-inside: avoid; }
  a { color: inherit; }
}

@media (max-width: 720px) {
  .plangrid { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
