/* ===========================================================================
   dentbrain: components
   ---------------------------------------------------------------------------
   The input vocabulary, lifted from PerioBrain because its users must
   recognise it: wheel, slider, segmented control, toggle, stepper.
   There is no free-text input anywhere in this file, and there must never be.
   =========================================================================== */

/* --- Section header bar (PerioBrain's dark pill) -------------------------- */

.sect {
  margin: var(--sp-5) 0 var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  background: var(--ink);
  color: var(--text-on-ink);
  border-radius: var(--r-pill);
  font-size: var(--size-lg);
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.005em;
}
.sect:first-child { margin-top: var(--sp-2); }

/* --- Field ---------------------------------------------------------------- */

.field { margin-bottom: var(--sp-5); }

.field__label {
  display: block;
  font-size: var(--size-md);
  line-height: 1.3;
  text-wrap: pretty;
}
.field__sub {
  display: block;
  margin-top: 2px;
  color: var(--text-2);
  font-size: var(--size-sm);
  line-height: 1.35;
  text-wrap: pretty;
}

/* A row that puts label left, control right — used by toggles. */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: var(--tap);
  margin-bottom: var(--sp-4);
}
.row__text { flex: 1; min-width: 0; }

/* --- Wheel ---------------------------------------------------------------
   An ordinal picker. Three values visible; the centre one is the value.
   Scroll-snap does the work, so it stays smooth without requestAnimationFrame
   (which never fires in the verification browser pane).                     */

.wheel {
  position: relative;
  height: 92px;
  margin-top: var(--sp-1);
  overflow: hidden;
  touch-action: pan-y;
}

.wheel__track {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior: contain;
  /* Top/bottom padding of exactly one item so the first and last values can
     reach the centre band. Set inline by wheel.js from the item height. */
}
.wheel__track::-webkit-scrollbar { display: none; }

.wheel__item {
  display: grid;
  place-items: center;
  height: 46px;
  scroll-snap-align: center;
  color: var(--text-3);
  font-size: var(--size-md);
  font-variant-numeric: tabular-nums;
  transition: color var(--t-fast) var(--ease);
  user-select: none;
}
.wheel__item[data-sel="1"] {
  color: var(--mint);
  font-size: var(--size-2xl);
  font-weight: 600;
}

/* Keyboard access: the wheel itself is focusable and takes arrow keys. */
.wheel:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; border-radius: var(--r-md); }

/* --- Slider ---------------------------------------------------------------
   Percentages. Dotted track, big thumb, live readout to the right.          */

.slider {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
}

.slider__input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.slider__input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--r-pill);
  background: repeating-linear-gradient(to right,
    var(--line-strong) 0 2px, transparent 2px 12px);
}
.slider__input::-moz-range-track {
  height: 4px;
  border-radius: var(--r-pill);
  background: repeating-linear-gradient(to right,
    var(--line-strong) 0 2px, transparent 2px 12px);
}
.slider__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px; height: 26px;
  margin-top: -11px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: var(--shadow-1);
}
.slider__input::-moz-range-thumb {
  width: 26px; height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: var(--shadow-1);
}
:root[data-theme="dark"] .slider__input::-webkit-slider-thumb,
:root[data-theme="dark"] .slider__input::-moz-range-thumb { background: var(--text); }

.slider__out {
  min-width: 3.6em;
  text-align: right;
  font-size: var(--size-lg);
  font-variant-numeric: tabular-nums;
}

/* Filled portion of the track, driven by a --fill custom property. */
.slider__input {
  background-image: linear-gradient(to right, var(--ink) 0 var(--fill, 0%), transparent var(--fill, 0%));
  background-repeat: no-repeat;
  background-size: 100% 4px;
  background-position: 0 50%;
  border-radius: var(--r-pill);
}
:root[data-theme="dark"] .slider__input { background-image: linear-gradient(to right, var(--text) 0 var(--fill, 0%), transparent var(--fill, 0%)); }

/* --- Segmented control ---------------------------------------------------
   2–4 mutually exclusive bands. Implemented as a radiogroup.                */

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  margin-top: var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
}

.seg__opt {
  display: grid;
  place-items: center;
  min-height: 56px;
  padding: var(--sp-2) var(--sp-1);
  background: var(--surface);
  border: 0;
  border-left: 1px solid var(--line-strong);
  color: var(--text);
  font-size: var(--size-base);
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg__opt:first-child { border-left: 0; }
.seg__opt:hover { background: var(--surface-2); }
.seg__opt[aria-checked="true"] {
  background: var(--surface-3);
  font-weight: 600;
}
.seg__opt[aria-checked="true"][data-tone="mint"] {
  background: var(--mint-soft);
  color: var(--ok);
}

/* --- Toggle ---------------------------------------------------------------
   Booleans. Off = outlined with a dark knob (PerioBrain's own look);
   on = filled ink with the knob to the right.                               */

.toggle {
  flex: none;
  position: relative;
  width: 62px;
  height: 34px;
  padding: 0;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
.toggle__knob {
  position: absolute;
  top: 50%;
  left: 5px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transform: translateY(-50%);
  transition: transform var(--t-base) var(--ease), background var(--t-base) var(--ease);
}
.toggle[aria-pressed="true"] { background: var(--ink); }
.toggle[aria-pressed="true"] .toggle__knob {
  background: var(--surface);
  transform: translateY(-50%) translateX(27px);
}
:root[data-theme="dark"] .toggle { border-color: var(--line-strong); }
:root[data-theme="dark"] .toggle__knob { background: var(--line-strong); }
:root[data-theme="dark"] .toggle[aria-pressed="true"] { background: var(--mint); border-color: var(--mint); }
:root[data-theme="dark"] .toggle[aria-pressed="true"] .toggle__knob { background: var(--mint-ink); }

/* --- Stepper --------------------------------------------------------------
   Real millimetre values without a keyboard. Minus / big readout / plus.    */

.stepper {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding: var(--sp-1);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.stepper__btn {
  display: grid;
  place-items: center;
  width: var(--tap); height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--size-xl);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast) var(--ease);
}
.stepper__btn:hover:not(:disabled) { background: var(--surface-3); }
.stepper__btn:disabled { opacity: 0.35; cursor: default; }
.stepper__out {
  text-align: center;
  font-size: var(--size-2xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stepper__unit { color: var(--text-2); font-size: var(--size-md); font-weight: 400; }

/* --- Result sheet ---------------------------------------------------------
   Appears crisply in place. No bounce.                                      */

.sheet-root:empty { display: none; }

.sheet__scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(12, 16, 20, 0.5);
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
}
.sheet__scrim[data-open="1"] { opacity: 1; }

.sheet {
  position: fixed;
  z-index: 81;
  left: 50%;
  bottom: 0;
  width: min(100%, var(--app-max));
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-2);
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  transition: transform var(--t-base) var(--ease), opacity var(--t-base) var(--ease);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet[data-open="1"] { transform: translateX(-50%) translateY(0); opacity: 1; }

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
}
.sheet__title { font-size: var(--size-md); font-weight: 600; }
.sheet__close {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  background: var(--surface-2);
  border: 0; border-radius: 50%;
  cursor: pointer;
}
.sheet__close svg { width: 16px; height: 16px; }
.sheet__body { padding: 0 var(--sp-4) var(--sp-5); overflow-y: auto; }

/* Centred modal variant, for the Reference dialog. */
.sheet--modal {
  bottom: auto;
  top: 50%;
  width: min(calc(100% - 2 * var(--sp-5)), 400px);
  border-radius: var(--r-lg);
  transform: translate(-50%, -46%);
  text-align: center;
}
.sheet--modal[data-open="1"] { transform: translate(-50%, -50%); }
.sheet--modal .sheet__body { padding-top: var(--sp-2); }

/* --- Result card ---------------------------------------------------------- */

.result__dx {
  padding: var(--sp-4);
  background: var(--mint-soft);
  border: 1px solid var(--mint-edge);
  border-radius: var(--r-md);
  font-size: var(--size-lg);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}
.result__dx--flat {
  background: var(--surface-2);
  border-color: var(--line);
}
.result__read {
  margin-top: var(--sp-3);
  color: var(--text-2);
  font-size: var(--size-base);
  text-wrap: pretty;
}
.result__h {
  margin: var(--sp-4) 0 var(--sp-2);
  color: var(--text-3);
  font-size: var(--size-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.result__drivers li {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-1) 0;
  font-size: var(--size-base);
}
.result__drivers li::before { content: "—"; color: var(--text-3); flex: none; }

.cite {
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: var(--size-xs);
  line-height: 1.45;
  text-wrap: pretty;
}

/* --- Unverified banner ----------------------------------------------------
   Any tool whose criteria have not been signed off by a clinician says so,
   visibly, on the tool itself. Non-negotiable.                              */

.unverified {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 34%, transparent);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--size-sm);
  line-height: 1.4;
  text-wrap: pretty;
}
.unverified strong { color: var(--warn); }

/* --- Article renderer (guidelines) --------------------------------------- */

.article h2 {
  margin: var(--sp-5) 0 var(--sp-2);
  font-family: var(--font-display);
  font-size: var(--size-xl);
  font-weight: 400;
  line-height: 1.2;
  text-wrap: balance;
}
.article h2:first-child { margin-top: var(--sp-1); }
.article h3 {
  margin: var(--sp-4) 0 var(--sp-1);
  font-size: var(--size-base);
  font-weight: 600;
}
.article p { margin: var(--sp-2) 0; text-wrap: pretty; }
.article ul, .article ol { margin: var(--sp-2) 0; padding-left: var(--sp-5); }
.article ul li { list-style: disc; margin: var(--sp-2) 0; text-wrap: pretty; }
.article ol li { list-style: decimal; margin: var(--sp-2) 0; text-wrap: pretty; }
.article strong { font-weight: 600; }

/* --- Index list (guidelines library, trauma index) ----------------------- */

.list { display: grid; gap: var(--sp-3); }

.list__item {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  padding: var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.list__item:hover { border-color: var(--mint-edge); background: var(--surface); }

.list__badge {
  flex: none;
  width: 62px;
  color: var(--text-2);
  font-size: var(--size-sm);
  font-weight: 600;
}
.list__glyph { flex: none; width: 44px; height: 52px; color: var(--text); }
.list__title { font-size: var(--size-base); line-height: 1.3; text-wrap: pretty; }
.list__meta  { color: var(--text-3); font-size: var(--size-sm); }

/* --- Two big numbers side by side (space planning) ----------------------- */

.readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  padding: var(--sp-4);
  background: var(--ink);
  border-radius: var(--r-md);
  color: var(--text-on-ink);
  text-align: center;
}
.readout__n {
  font-size: var(--size-3xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.readout__n[data-sign="neg"] { color: var(--mint-bright); }
.readout__k {
  margin-top: var(--sp-1);
  font-size: var(--size-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}
.readout__cap {
  grid-column: 1 / -1;
  order: -1;
  font-size: var(--size-sm);
  opacity: 0.8;
}

/* --- Score meter (ICON, STOP-BANG, PSQ) ---------------------------------- */

.score {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-variant-numeric: tabular-nums;
}
.score__n { font-size: var(--size-3xl); font-weight: 600; line-height: 1; }
.score__d { color: var(--text-2); font-size: var(--size-lg); }

.band {
  display: inline-block;
  margin-top: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--size-sm);
  font-weight: 600;
}
.band--low  { background: var(--mint-soft); color: var(--ok); }
.band--mid  { background: var(--warn-soft); color: var(--warn); }
.band--high { background: var(--danger-soft); color: var(--danger); }

/* --- Empty / offline states ---------------------------------------------- */

.state {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--text-2);
  text-wrap: pretty;
}
.state__h { color: var(--text); font-size: var(--size-md); font-weight: 600; margin-bottom: var(--sp-2); }

/* --- Text button --------------------------------------------------------- */

.btn {
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  font-size: var(--size-base);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn--mint {
  background: linear-gradient(135deg, var(--mint), var(--mint-bright));
  border-color: transparent;
  color: var(--mint-ink);
  font-weight: 600;
}
.btn--block { display: block; width: 100%; }

/* --- Disclosure (About) --------------------------------------------------- */

.disc {
  margin-bottom: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.disc__sum {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-4);
  background: none;
  border: 0;
  text-align: left;
  font-size: var(--size-base);
  cursor: pointer;
}
.disc__chev { flex: none; width: 18px; height: 18px; color: var(--text-2); transition: transform var(--t-base) var(--ease); }
.disc__sum[aria-expanded="true"] .disc__chev { transform: rotate(180deg); }
.disc__body { padding: 0 var(--sp-4) var(--sp-4); color: var(--text-2); text-wrap: pretty; }
.disc__body p + p { margin-top: var(--sp-3); }
