/* ============================================================================
   Cursivia components — the shared primitive vocabulary (~12 primitives).
   Depends on tokens.css. Version-string when it changes (components.css?v=N).

   Primitives: button, card, field, kv list, badge, progress, alert,
   empty-state, modal, skeleton, ai-insight, option (answer), choice (picker).
   ========================================================================== */

/* ---- 1. Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--touch);
  padding: 10px var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn:focus-visible { box-shadow: var(--focus-ring); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-sunken); color: var(--ink); }

.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-sunken); color: var(--ink); }

.btn:disabled {
  background: var(--border);
  border-color: transparent;
  color: var(--faint);
  cursor: not-allowed;
}

.btn-sm { min-height: 36px; padding: 6px var(--sp-4); font-size: var(--text-sm); }

/* ---- 2. Cards ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.card-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--sp-3);
}
.card-help {
  color: var(--muted);
  font-size: var(--text-sm);
  margin: 0 0 var(--sp-4);
}

/* CTA card: copy on the left, one action on the right */
.card-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.card-cta .card-cta-copy { flex: 1; min-width: 0; }
.card-cta .card-cta-copy .card-title { margin-bottom: var(--sp-1); }
.card-cta .card-cta-copy p { margin: 0; color: var(--muted); font-size: var(--text-sm); }
@media (max-width: 480px) {
  .card-cta { flex-direction: column; align-items: stretch; }
}

/* ---- 3. Form fields ----------------------------------------------------------------- */
.field { display: block; margin-bottom: var(--sp-4); font-size: var(--text-sm); }
.field-label {
  display: block;
  font-weight: var(--weight-semibold);
  color: var(--ink);
  margin-bottom: var(--sp-1);
}
.field-hint { color: var(--muted); margin: var(--sp-1) 0 0; font-size: var(--text-sm); }
.field-error { color: var(--err); margin: var(--sp-1) 0 0; font-size: var(--text-sm); }

.input,
input[type="text"].input, input[type="email"].input, input[type="number"].input,
input[type="date"].input, input[type="url"].input, select.input, textarea.input {
  width: 100%;
  min-height: var(--touch);
  padding: 10px var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  transition: border-color var(--t-fast);
}
.input:hover { border-color: var(--faint); }
.input:focus-visible { border-color: var(--accent); box-shadow: var(--focus-ring); }
.input[aria-invalid="true"] { border-color: var(--err); }

.input-inline { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 480px) { .input-inline { grid-template-columns: 1fr; } }

/* ---- 4. Key-value list (definition grid) ----------------------------------------------- */
.kv {
  margin: 0;
  display: grid;
  grid-template-columns: 180px 1fr;
  row-gap: var(--sp-2);
  column-gap: var(--sp-4);
  font-size: var(--text-sm);
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
@media (max-width: 480px) {
  .kv { grid-template-columns: 1fr; row-gap: 0; }
  .kv dt { margin-top: var(--sp-2); }
}

/* ---- 5. Badges / status pills ------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  background: var(--surface-sunken);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-accent  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-border); }
.badge-ok      { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-soft-border); }
.badge-warn    { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn-soft-border); }
.badge-err     { background: var(--err-soft);    color: var(--err);    border-color: var(--err-soft-border); }

/* ---- 6. Progress ------------------------------------------------------------------------------ */
.progress-track {
  height: 4px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width var(--t-med);
}
/* thicker variant for data bars (allocation, scores) */
.progress-track.progress-bar { height: 12px; }

/* ---- 7. Alerts / banners --------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
}
.alert-info { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--ink); }
.alert-ok   { background: var(--ok-soft);     border-color: var(--ok-soft-border);     color: var(--ok); }
.alert-warn { background: var(--warn-soft);   border-color: var(--warn-soft-border);   color: var(--ink); }
.alert-err  { background: var(--err-soft);    border-color: var(--err-soft-border);    color: var(--err); }

/* inline status text (form submit feedback) */
.msg     { font-size: var(--text-sm); }
.msg-ok  { color: var(--ok); }
.msg-err { color: var(--err); }

/* ---- 8. Empty state ------------------------------------------------------------------------------------ */
.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
  line-height: var(--leading-loose);
}

/* ---- 9. Modal --------------------------------------------------------------------------------------------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(25, 29, 36, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--sp-6);
  overflow-y: auto;
}
.modal-scrim.open { display: flex; }
.modal-panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-6);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-modal);
}
.modal-panel h2 { font-size: var(--text-xl); margin: 0 0 var(--sp-2); }
.modal-panel .modal-intro { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--sp-5); }

/* ---- 10. Skeleton (AI / loading waits — never a bare spinner) ----------------------------------------------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-sunken);
  border-radius: var(--r-sm);
  min-height: 1em;
  color: transparent !important;
  user-select: none;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: skeleton-sweep 1.4s infinite;
}
@keyframes skeleton-sweep { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}
/* staged status text next to a skeleton */
.loading-status {
  color: var(--muted);
  font-size: var(--text-sm);
  font-style: normal;
}

/* ---- 11. AI insight callout + provenance labels ---------------------------------------------------------------- */
.ai-insight {
  background: var(--surface-sunken);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  padding: var(--sp-4);
  font-size: var(--text-sm);
  color: var(--ink);
  white-space: pre-wrap;
}
.provenance {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--faint);
  letter-spacing: 0.01em;
}
.meta-line { font-size: var(--text-xs); color: var(--faint); margin-top: var(--sp-2); }

/* ---- 12. Option (quiz answer) — correctness never by colour alone ----------------------------------------------- */
.option {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--sp-4);
  min-height: var(--touch);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-md);
  cursor: pointer;
  font: inherit;
  color: inherit;
  line-height: 1.45;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.option:hover:not(:disabled) { background: var(--accent-soft); }
.option:focus-visible { box-shadow: var(--focus-ring); border-color: var(--accent); }
.option:disabled { cursor: default; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.option.correct  { border-color: var(--ok); background: var(--ok-soft); }
.option.correct::after { content: "  ✓ correct"; font-weight: var(--weight-semibold); color: var(--ok); font-size: var(--text-sm); }
.option.wrong    { border-color: var(--err); background: var(--err-soft); }
.option.wrong::after { content: "  ✕ your answer"; font-weight: var(--weight-semibold); color: var(--err); font-size: var(--text-sm); }
.options-list { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ---- 13. Choice chips (pickers, likert scales, toggles) ------------------------------------------------------------ */
.choice-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.choice {
  flex: 1;
  min-width: 90px;
  min-height: var(--touch);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-md);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  text-align: center;
  user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  margin: 0;
}
/* Hover only where a pointer can hover: on a phone the tap leaves :hover stuck on the
   chip, and this rule (0,4,0) outranked the checked one below (0,3,0), so the picked
   1-5 pill went white-on-pale-blue (persona QA 2026-10-04). */
@media (hover: hover) {
  .choice:hover:not(:disabled):not(.selected) { background: var(--accent-soft); border-color: var(--accent-soft-border); }
}
.choice:focus-visible { box-shadow: var(--focus-ring); }
.choice.selected {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: var(--weight-semibold);
}
.choice:disabled { background: var(--surface-sunken); color: var(--faint); cursor: not-allowed; }
.choice .choice-sub { display: block; font-size: var(--text-xs); opacity: 0.85; margin-top: 2px; font-weight: var(--weight-regular); }

/* radio/checkbox-backed chips: hide the native input, style the label */
.choice-input { position: absolute; opacity: 0; pointer-events: none; }
.choice-input:checked + .choice,
.choice-input:checked + .choice:hover {  /* matches the hover rule's weight; later wins */
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: var(--weight-semibold);
}
.choice-input:focus-visible + .choice { box-shadow: var(--focus-ring); }

/* ---- Utilities ---------------------------------------------------------------
   Two classes every page reaches for, which until 2026-09-10 lived in ONE page's
   inline <style>. Five templates plus the Compass player each kept their own
   byte-identical copy of `.hidden`, and `.muted` had no copy at all outside the plan:
   the check-up used it six times and the privacy and terms pages once each, so their
   "Last updated ..." line rendered as ordinary body text. Two of those uses in the
   check-up carry an inline font-size, which is someone working around the miss.

   `.hidden` is the show/hide mechanism for about ten elements on the plan alone, so a
   new page that forgets to redeclare it renders every hidden element visible. That is
   a bad trap to leave for the next page, which is why these live here now. */
.hidden { display: none; }
.muted { color: var(--muted); font-size: var(--text-sm); }
