/* APEX Wellbeing — cool stone background, deep lake blue, a 5-step answer scale as the signature element. */
:root {
  --bg: #eef0ec;
  --paper: #ffffff;
  --ink: #1c2126;
  --muted: #5b646c;
  --line: #d9ddd6;
  --primary: #17405f;
  --primary-soft: #e3ebf1;
  --green: #2f8f5b;
  --amber: #b87d14;
  --red: #b8432f;
  --t4: #2f8f5b; --t3: #7aa84f; --t2: #9a9c8e; --t1: #d0892f; --t0: #b8432f;
  --radius: 10px;
  --font: "Avenir Next", Avenir, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--primary); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .8em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
:focus-visible { outline: 3px solid #6aa2cc; outline-offset: 2px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 640px; }
main.wrap { padding-top: 24px; padding-bottom: 60px; }

/* Top bar */
.topbar { background: var(--primary); color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .01em; display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { width: 18px; height: 16px; background:
  linear-gradient(var(--t0), var(--t0)) 0 100% / 3px 40% no-repeat,
  linear-gradient(var(--t1), var(--t1)) 5px 100% / 3px 55% no-repeat,
  linear-gradient(var(--t2), var(--t2)) 10px 100% / 3px 70% no-repeat,
  linear-gradient(var(--t4), var(--t4)) 15px 100% / 3px 100% no-repeat; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.mainnav a { color: #d6e2ec; text-decoration: none; padding: 16px 10px; border-bottom: 3px solid transparent; }
.mainnav a:hover { color: #fff; }
.mainnav a[aria-current] { color: #fff; border-bottom-color: #fff; }
.mainnav .nav-quiet { opacity: .75; }

/* Panels */
.panel { background: var(--paper); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 18px; border: 1px solid var(--line); }
.panel.empty { text-align: center; padding: 40px 24px; }
.panel.is-off { opacity: .65; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.narrow-panel { max-width: 720px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead h1 { margin-bottom: 2px; }
.pagehead p { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.grid2 > .panel { margin-bottom: 0; }
.grid2 + .panel, .panel + .grid2 { margin-top: 18px; }
.mt { margin-top: 1.4em; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 650; }
.text-red { color: var(--red); }
.grow { flex: 1; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--primary); background: var(--primary); color: #fff;
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 8px; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: #0f3149; }
.btn-quiet { background: var(--paper); color: var(--primary); border-color: var(--line); }
.btn-quiet:hover { background: var(--primary-soft); }
.btn-small { padding: 5px 12px; min-height: 34px; font-size: .875rem; }
.btn-wide { width: 100%; }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

/* Forms */
.stack > * + * { margin-top: 14px; }
.field { display: block; border: 0; padding: 0; min-width: 0; }
fieldset.field { margin-left: 0; margin-right: 0; }
.stack > .field:first-child, .stack > input + .field, .stack > input + input + .field { margin-top: 0; }
.field > span, .field > legend { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; padding: 0; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fbfcfa; border: 1px solid #c7ccc4; border-radius: 8px; padding: 10px 12px; min-height: 44px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: #fff; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.field-error { display: block; color: var(--red); font-size: .85rem; margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.check-inline { align-self: center; }

.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid #c7ccc4; border-radius: 8px; overflow: hidden; background: #fbfcfa; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; padding: 9px 14px; cursor: pointer; border-right: 1px solid #e0e3dd; min-height: 42px; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #6aa2cc; outline-offset: -3px; }
.seg-small span { padding: 5px 12px; min-height: 0; font-size: .875rem; }

.copybox { display: flex; gap: 8px; margin: 10px 0; }
.copybox input { font-size: .85rem; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border-left: 5px solid var(--green); background: #e8f3ec; }
.flash-error { border-color: var(--red); background: #f8e9e5; }
.flash-warn { border-color: var(--amber); background: #faf1dd; }
.note { background: var(--primary-soft); padding: 10px 14px; border-radius: 8px; font-size: .92rem; }

/* ---------- Questionnaire ---------- */
.q-head { margin-bottom: 14px; }
.qform { counter-reset: q; }
.q { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 14px; margin: 0 0 14px; scroll-margin-top: 12px; }
.q legend { float: left; width: 100%; font-size: 1.1rem; font-weight: 650; margin-bottom: 4px; display: flex; gap: 10px; align-items: baseline; padding: 0; }
.q legend + * { clear: both; }
.q-num { color: var(--muted); font-weight: 500; font-size: .9rem; min-width: 1.2em; }
.q-help { color: var(--muted); font-size: .92rem; margin: 0 0 10px; clear: both; }
.q-missing { border-color: var(--red); box-shadow: 0 0 0 2px rgba(184, 67, 47, .15); }
.scale { display: grid; gap: 6px; clear: both; }
.opt { position: relative; display: flex; align-items: center; min-height: 50px; padding: 10px 14px 10px 22px; border-radius: 8px;
  background: #f6f7f4; cursor: pointer; border: 1px solid transparent; transition: background-color .12s, border-color .12s; }
.opt::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; border-radius: 8px 0 0 8px; background: var(--tone); transition: width .15s; }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt-text { flex: 1; }
.opt:hover { background: #eef0ec; }
.opt:has(input:checked) { background: color-mix(in srgb, var(--tone) 14%, #fff); border-color: var(--tone); font-weight: 600; }
.opt:has(input:checked)::before { width: 12px; }
.opt:has(input:checked)::after { content: "✓"; color: var(--tone); font-weight: 700; margin-left: 8px; }
.opt:has(input:focus-visible) { outline: 3px solid #6aa2cc; outline-offset: 2px; }
.tone-4 { --tone: var(--t4); } .tone-3 { --tone: var(--t3); } .tone-2 { --tone: var(--t2); } .tone-1 { --tone: var(--t1); } .tone-0 { --tone: var(--t0); }
.comment { margin: 6px 0 16px; }
.submitbar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(238, 240, 236, .94); backdrop-filter: blur(6px); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); margin-bottom: 14px; }
.progress { color: var(--muted); font-size: .92rem; }

.done { text-align: center; padding: 36px 24px; }
.scoreline { display: flex; justify-content: center; align-items: baseline; gap: 6px; margin: 8px 0 12px; }
.score-big { font-size: 4.5rem; font-weight: 700; line-height: 1; color: var(--primary); }
.score-of { font-size: 1.5rem; color: var(--muted); }
.meter { height: 10px; background: #e3e6e0; border-radius: 5px; overflow: hidden; max-width: 320px; margin: 0 auto 20px; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--t0), var(--t1) 30%, var(--t2) 50%, var(--t3) 70%, var(--t4)); }
.done .actions { justify-content: center; }

/* ---------- Coach views ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats > div { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; border-top: 4px solid var(--primary); }
.stats strong { display: block; font-size: 1.9rem; line-height: 1.1; }
.stats span { color: var(--muted); font-size: .9rem; }
.stats .stat-red { border-top-color: var(--red); }
.stats .stat-amber { border-top-color: var(--amber); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 240px; }
.toolbar select { max-width: 200px; }

.tablewrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.panel .tablewrap { border: 0; margin: 0 -8px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid #eceee9; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table-dense td { padding: 7px 10px; font-size: .9rem; }
.table tr.archived { opacity: .55; }
.table th.rot { vertical-align: bottom; height: 110px; }
.table th.rot span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.cell-red { background: #f6dcd6; color: #7d2718; font-weight: 700; }
.cell-amber { background: #f7e9c9; color: #6e4a07; font-weight: 700; }
.note-cell { max-width: 280px; font-size: .85rem; color: var(--muted); }
.reasons { max-width: 260px; margin-top: 3px; }

.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-green { background: #dff0e6; color: #1f6b43; }
.badge-amber { background: #f7e7c2; color: #7a5208; }
.badge-red { background: #f4d6cf; color: #8a2a1a; }
.badge-none { background: #e6e8e3; color: var(--muted); font-weight: 600; }

.spark { display: block; }
.spark polyline { fill: none; stroke: var(--primary); stroke-width: 1.6; stroke-linejoin: round; }

.latest { text-align: right; display: grid; gap: 2px; }
.score-mid { font-size: 1.8rem; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--paper); border: 1px solid var(--line); font-size: .9rem; }
.tabs a[aria-current] { background: var(--primary); color: #fff; border-color: var(--primary); }

.chart { position: relative; width: 100%; }
.chart-lg { height: 340px; }
.chart-sm { height: 170px; }
.minis { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.minis .panel { margin: 0; padding: 14px 16px; }

.qitem .answers { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.answers li { display: flex; gap: 10px; align-items: center; font-size: .92rem; }
.pill { display: inline-grid; place-items: center; min-width: 26px; height: 22px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .8rem; }
.optrows { display: grid; gap: 8px; margin-bottom: 10px; }
.optrow { display: grid; grid-template-columns: 1fr 80px auto; gap: 8px; align-items: center; }

.picklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 16px; max-height: 360px; overflow: auto; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfa; }
pre.code { background: #1c2126; color: #e8ece6; padding: 12px 14px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
details.danger { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
details.danger summary { cursor: pointer; color: var(--red); font-weight: 600; }

@media (max-width: 700px) {
  body { font-size: 17px; }
  .wrap { padding: 0 14px; }
  h1 { font-size: 1.5rem; }
  .panel { padding: 18px 16px; }
  .q { padding: 16px 14px 12px; }
  .mainnav { margin-left: 0; width: 100%; }
  .mainnav a { padding: 10px 8px; }
  .latest { text-align: left; }
  .chart-lg { height: 280px; }
  .optrow { grid-template-columns: 1fr 64px; }
  .optrow .linkbtn { grid-column: 1 / -1; justify-self: start; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
