/* ============================================================================
   ApexNext Brand Stylesheet — single source of truth for form & admin pages
   ----------------------------------------------------------------------------
   Palette source of truth:
     Obsidian Vault / 02 Projects/APEX/08-Brand/APEX NEXT Palette.md
     (Approved 2026-09-14 · status FINAL)

   APEX Gold   #C9A227  highlights, key words, accents, secondary button
   APEX Blue   #123B5D  primary brand, headings, nav, primary button
   Light Grey  #F2F4F5  page backgrounds, cards, sections
   White       #FFFFFF  card surfaces, text on dark
   Dark Blue   #0B2438  body text, footer, strong contrast
   Luxury Gold #C6A15B  premium alternative gold
   Teal        #1A4A6E  subtle accents, hover states
   Danger      #B83227  errors, warnings
   Success     #27AE60  positive indicators

   Rules honoured here:
     - Gold is NEVER a page background (highlights/buttons only).
     - No gold text on blue, no blue text on dark blue, no grey on grey.
     - Headings use APEX Blue; body text uses Dark Blue.
     - Navigation/primary buttons use APEX Blue.
   ============================================================================ */

:root {
  /* Surfaces */
  --bg: #F2F4F5;            /* Light Grey — page background */
  --bg2: #FFFFFF;
  --panel: #FFFFFF;         /* White — card surface */
  --panel2: #F2F4F5;        /* Light Grey — hover / inset */
  --line: rgba(11, 36, 56, 0.12);

  /* Text */
  --ink: #0B2438;           /* Dark Blue — body text */
  --muted: #5A6B7C;         /* Grey — muted text */

  /* Brand */
  --accent: #C9A227;        /* APEX Gold */
  --gold: #C6A15B;          /* Luxury Gold */
  --gold-ink: #8A6D10;      /* readable gold for small text on light */
  --teal: #123B5D;          /* APEX Blue — primary */
  --teal2: #1A4A6E;         /* Teal — hover states */

  /* Semantic */
  --danger: #B83227;
  --ok: #27AE60;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 30px; font-weight: 800; color: var(--teal); letter-spacing: -0.5px; margin: 0 0 10px; }
h2 { font-size: 19px; font-weight: 700; color: var(--teal); margin: 0 0 8px; }
h3 { font-size: 16px; font-weight: 700; color: var(--ink); margin: 0 0 8px; }
p  { color: var(--muted); font-size: 14px; margin: 0 0 16px; }

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }

/* ── Top bar / navigation ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.topbar .brand {
  font-weight: 800; letter-spacing: 0.4px; font-size: 15px; color: var(--ink);
}
.topbar .brand span { color: var(--accent); }

.topnav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topnav a {
  color: var(--muted); padding: 8px 13px; border-radius: 8px;
  font-size: 13px; font-weight: 600; text-decoration: none;
}
.topnav a:hover, .topnav a.active {
  background: var(--panel2); color: var(--ink); text-decoration: none;
}
.topnav .logout { color: var(--danger); }

/* ── Layout ───────────────────────────────────────────────────────────── */
.container { padding: 24px 32px; max-width: 1000px; margin: 0 auto; }
/* Admin screens carry wide tables and charts; the marketing width cramps them. */
.container.wide { max-width: 1320px; }
.wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box, .box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 36px;
}
.login-box { width: 100%; max-width: 400px; }
.box { width: 100%; max-width: 520px; }

.hero { padding: 64px 32px 32px; text-align: center; max-width: 800px; margin: 0 auto; }
.hero h1 { font-size: 34px; margin-bottom: 12px; }
.hero p { font-size: 17px; max-width: 620px; margin: 0 auto; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; margin-bottom: 20px;
}
.card h2 { color: var(--teal); }
.card h3 { color: var(--ink); }
.card p { color: var(--muted); font-size: 14px; }

.page-title { font-size: 24px; font-weight: 800; color: var(--teal); margin: 0 0 6px; }
.page-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--teal); margin: 0 0 6px; }
.subtitle { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

/* ── Logo lockup ──────────────────────────────────────────────────────── */
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.logo .mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--teal); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.logo span { font-weight: 800; font-size: 17px; color: var(--ink); }

.back { color: var(--muted); font-size: 13px; font-weight: 600; display: inline-block; margin-bottom: 14px; }
.back:hover { color: var(--accent); }

/* ── Forms ────────────────────────────────────────────────────────────── */
label {
  display: block; font-size: 12px; color: var(--muted); margin: 13px 0 5px;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
input, textarea, select {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg2); color: var(--ink);
  font-size: 14px; font-family: inherit; outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(18, 59, 93, 0.10);
}
textarea { min-height: 100px; resize: vertical; }
.req { color: var(--danger); }

.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label {
  margin: 0; text-transform: none; letter-spacing: normal;
  font-size: 14px; color: var(--ink); font-weight: 500;
}

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar input, .toolbar select { width: auto; min-width: 170px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row .grow, .grow { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: 10px;
  font-family: inherit; font-size: 14px; font-weight: 700;
  border: 1px solid transparent; cursor: pointer; transition: all 0.2s;
}
.btn.primary, button.primary, button[type="submit"] {
  background: var(--teal); color: #fff;
  box-shadow: 0 4px 18px rgba(18, 59, 93, 0.16);
}
.btn.primary:hover, button.primary:hover, button[type="submit"]:hover {
  background: var(--teal2); transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(18, 59, 93, 0.22);
}
.btn.danger {
  background: var(--danger); color: #fff;
}
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent; border-color: var(--teal); color: var(--teal);
}
.btn.ghost:hover { background: rgba(18, 59, 93, 0.06); }
.btn.sm { padding: 7px 14px; font-size: 12.5px; border-radius: 8px; }
.btn:hover, button:hover { filter: brightness(1.03); }
.export-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 20px; border-radius: 10px; font-weight: 700; cursor: pointer;
}
.export-btn:hover { filter: brightness(1.06); }

/* ── Messages ─────────────────────────────────────────────────────────── */
.msg { margin-top: 16px; padding: 14px 16px; border-radius: 8px; display: none; font-size: 14px; }
.msg.success { display: block; background: rgba(39, 174, 96, 0.10); color: #1E7D46; border: 1px solid rgba(39, 174, 96, 0.25); }
.msg.error   { display: block; background: rgba(184, 50, 39, 0.08); color: var(--danger); border: 1px solid rgba(184, 50, 39, 0.22); }

/* ── Status icon (verification) ───────────────────────────────────────── */
.status-icon {
  width: 68px; height: 68px; border-radius: 50%; margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 800;
}
.status-icon.success { background: rgba(39, 174, 96, 0.12); color: var(--ok); }
.status-icon.error   { background: rgba(184, 50, 39, 0.10); color: var(--danger); }

.spinner {
  width: 34px; height: 34px; margin: 0 auto 18px;
  border: 3px solid var(--line); border-top-color: var(--teal);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stats ────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px;
  border-left: 3px solid var(--accent);
}
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.stat .value {
  font-size: 26px; font-weight: 800; color: var(--teal); margin-top: 4px;
  font-variant-numeric: tabular-nums; line-height: 1.15;
  overflow-wrap: anywhere;
}
.stat .label { overflow-wrap: anywhere; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }

/* ── Tables ───────────────────────────────────────────────────────────── */
/* A table cannot shrink below its content, so a wide one overflows its card and
   drags the page sideways. table-wrap.js puts every table in one of these. */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  max-width: 100%; margin: 2px 0 4px;
}
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); font-weight: 700; padding: 10px 12px;
  border-bottom: 2px solid var(--line); white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--line); color: var(--ink); vertical-align: middle; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--panel2); }
tbody tr:last-child td { border-bottom: none; }

/* Keep short, machine-ish values on one line so columns line up; let prose wrap. */
td.mono, td.nowrap { white-space: nowrap; }
td .trunc {
  display: block; max-width: 240px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
/* Numeric columns line up when the digits are tabular. */
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  background: rgba(11, 36, 56, 0.06); color: var(--muted);
}
.badge.new                                   { background: rgba(201, 162, 39, 0.14); color: var(--gold-ink); }
.badge.contacted, .badge.scheduled, .badge.sending { background: rgba(18, 59, 93, 0.10); color: var(--teal); }
.badge.active, .badge.sent, .badge.converted { background: rgba(39, 174, 96, 0.13); color: #1E7D46; }
.badge.qualified                             { background: rgba(26, 74, 110, 0.12); color: var(--teal2); }
.badge.pending, .badge.draft                 { background: rgba(11, 36, 56, 0.07); color: var(--muted); }
.badge.unsubscribed                          { background: rgba(184, 50, 39, 0.10); color: var(--danger); }

/* ── Empty state ──────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 14px; }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11, 36, 56, 0.42);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  padding: 28px; box-shadow: 0 20px 60px rgba(11, 36, 56, 0.22);
}
.modal h2 { margin-bottom: 4px; }
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 22px; flex-wrap: wrap;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 520px) { .field-grid { grid-template-columns: 1fr; } }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  background: var(--ink); color: #fff; padding: 13px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(11, 36, 56, 0.28);
  max-width: 380px;
}
.toast.ok    { background: #1E7D46; }
.toast.error { background: var(--danger); }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
  background: rgba(11, 36, 56, 0.06); color: var(--muted);
}
.pill.yes { background: rgba(39, 174, 96, 0.13); color: #1E7D46; }
.pill.no  { background: rgba(201, 162, 39, 0.16); color: var(--gold-ink); }

@media (max-width: 600px) {
  .container { padding: 18px 16px; }
  .hero { padding: 44px 20px 24px; }
  .hero h1 { font-size: 26px; }
  .stat .value { font-size: 22px; }
}

/* ============================================================================
   LOOK & FEEL LAYER — shared polish for the assessment toolbox & templates
   Additive only; earlier rules are untouched. Reusable across member surfaces.
   ============================================================================ */

:root {
  --shadow-sm: 0 1px 2px rgba(11,36,56,.06), 0 2px 8px rgba(11,36,56,.05);
  --shadow-md: 0 6px 22px rgba(11,36,56,.09), 0 2px 6px rgba(11,36,56,.05);
  --shadow-lg: 0 16px 44px rgba(11,36,56,.14);
  --radius:   14px;
  --brand-gradient: linear-gradient(120deg, #123B5D 0%, #1A4A6E 55%, #0B2438 100%);
  --gold-gradient:  linear-gradient(120deg, #C9A227 0%, #C6A15B 100%);
}

/* ── Page hero band — gives every toolbox page a branded header ─────────── */
.page-hero {
  position: relative; overflow: hidden;
  background: var(--brand-gradient);
  color: #fff; border-radius: 18px;
  padding: 30px 32px; margin: 4px 0 26px;
  box-shadow: var(--shadow-md);
}
.page-hero::after {
  content: ""; position: absolute; right: -60px; top: -60px;
  width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(201,162,39,.30), rgba(201,162,39,0) 70%);
  pointer-events: none;
}
.page-hero .eyebrow {
  font-size: 11px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase;
  color: #E7D8A6; margin: 0 0 8px;
}
.page-hero h1, .page-hero .page-title { color: #fff; margin: 0 0 6px; }
.page-hero p, .page-hero .page-sub { color: rgba(255,255,255,.82); margin: 0; max-width: 640px; }
.page-hero .hero-meta { margin-top: 14px; }
.page-hero .badge {
  background: rgba(255,255,255,.14); color: #fff; backdrop-filter: blur(4px);
}

/* ── Cards lift on the toolbox surfaces ────────────────────────────────── */
.card { box-shadow: var(--shadow-sm); transition: box-shadow .2s ease, transform .2s ease; }

/* ── Stat cards get a subtle top sheen + hover ─────────────────────────── */
.stat { box-shadow: var(--shadow-sm); transition: transform .18s ease, box-shadow .18s ease; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ── Assessment library tiles — the "toolbox" ──────────────────────────── */
.lib-item {
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.lib-item::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--gold-gradient); opacity: .9;
}
.lib-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(201,162,39,.5);
}
.lib-item h3 { color: var(--teal); font-weight: 800; letter-spacing: -.2px; }
.lib-item .meta .badge { background: rgba(18,59,93,.07); color: var(--teal2); }
.lib-item .lib-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }

/* Icon chip that can front each tile / section */
.tile-icon {
  width: 40px; height: 40px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(18,59,93,.08); color: var(--teal);
  font-size: 19px; font-weight: 800; flex: none;
}

/* ── Progress bars — brand gradient fill + shimmer while incomplete ─────── */
.progress { background: rgba(11,36,56,.08); box-shadow: inset 0 1px 2px rgba(11,36,56,.08); }
.progress .fill {
  background: linear-gradient(90deg, var(--teal), var(--teal2));
  box-shadow: 0 0 8px rgba(18,59,93,.25);
}
.progress .fill.done {
  background: linear-gradient(90deg, #27AE60, #1E7D46);
  box-shadow: 0 0 8px rgba(39,174,96,.3);
}

/* ── Assessment form: section cards instead of a flat wall ─────────────── */
.section {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 24px;
  box-shadow: var(--shadow-sm);
}
.section h3 {
  display: flex; align-items: center; gap: 10px;
  color: var(--teal); font-weight: 800; font-size: 17px;
  border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px;
}
.section h3 .sec-num {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-gradient); color: #fff; font-size: 13px; font-weight: 800;
}
.q { padding: 16px; border-radius: 10px; transition: background .15s ease; }
.q:hover { background: var(--panel2); }
.q .qlabel { font-size: 14.5px; }

/* Scale chips read as tappable segments */
.scale label { transition: all .15s ease; background: var(--panel); font-weight: 600; }
.scale label:hover { border-color: var(--teal); background: rgba(18,59,93,.05); }
.scale input:checked + * , .scale label:has(input:checked) {
  border-color: var(--teal); background: var(--teal); color: #fff;
}

/* ── Sticky action bars gain a shadow so they read as floating ─────────── */
.sticky-bar, .sticky-actions {
  box-shadow: 0 -8px 24px rgba(11,36,56,.08);
  border-radius: 14px 14px 0 0;
}

/* ── Template preview sections lift too ────────────────────────────────── */
.pv-section { box-shadow: var(--shadow-sm); transition: box-shadow .2s ease; }
.pv-section:hover { box-shadow: var(--shadow-md); }
.pv-section > h3 { color: var(--teal); font-weight: 800; }

/* ── Report reader: hero head + meta chips ─────────────────────────────── */
.report-head { border-bottom: none; }
.meta-grid .m { box-shadow: var(--shadow-sm); transition: transform .16s ease, box-shadow .16s ease; }
.meta-grid .m:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ── Buttons: primary gets a gradient for a premium feel ───────────────── */
.btn.primary, button.primary, button[type="submit"] {
  background: var(--brand-gradient);
}
.btn.primary:hover, button.primary:hover, button[type="submit"]:hover {
  background: var(--brand-gradient); filter: brightness(1.08);
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .lib-item, .stat, .card, .meta-grid .m, .q, .scale label,
  .btn, button { transition: none !important; }
  .lib-item:hover, .stat:hover, .meta-grid .m:hover { transform: none; }
}

/* ============================================================================
   Yes/No toggle switch
   ----------------------------------------------------------------------------
   The two radios remain the real inputs, so `form.elements[name].value` keeps
   working and persisted answers stay "Yes"/"No" — the switch is presentation
   only. Colours come from the tokens above; none are introduced here.
   ========================================================================== */
.yn { display: flex; align-items: center; gap: 12px; }
.yn input[type="radio"] {
  position: absolute; width: 1px; height: 1px; opacity: 0;
  pointer-events: none; margin: 0;
}
.yn-switch {
  width: 54px; height: 30px; padding: 0; border-radius: 99px;
  border: 1px solid var(--line); background: var(--panel2);
  position: relative; flex: 0 0 auto; cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}
.yn-switch .knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--panel); box-shadow: var(--shadow-sm);
  transition: transform .18s ease;
}
.yn-switch[aria-checked="true"] { background: var(--teal); border-color: var(--teal); }
.yn-switch[aria-checked="true"] .knob { transform: translateX(24px); }
.yn-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.yn-switch:disabled { opacity: .55; cursor: not-allowed; }
.yn-state { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.yn.set .yn-state { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .yn-switch, .yn-switch .knob { transition: none !important; }
}

/* Plain option lists (radio / checkbox). These rules lived only in
   assessment.html's inline style, so the two PREVIEW pages rendered the same
   questions unstyled — the preview then did not match the form it claims to
   show. Same declarations, now shared. */
.opts { display: flex; flex-direction: column; gap: 8px; }
.opts label {
  display: flex; align-items: center; gap: 9px; margin: 0;
  font-size: 14px; font-weight: 500; color: var(--ink);
  text-transform: none; letter-spacing: normal;
}
.opts input { width: auto; }
