/**
 * ui-components.css - The shared component classes (.ui-*) for both sides of the app.
 *
 * UI polish round 2 (2026-11-11): the census found six segmented controls, ten main-button looks,
 * three input looks and eleven empty-state wordings. Each piece below copies the look of the best
 * EXISTING component (named in its block) so a screen that moves onto it looks like the chosen one.
 * See wiki/ui-standards.md, "Components".
 *
 * Sizes per side: every size reads a --ui-* variable. The fallback in each var() is the clinician
 * size; patient-tokens.css sets the patient sizes (bigger, >= 44 px tap targets at every width).
 * A page is "patient" when it loads patient-tokens.css; nothing else is needed.
 *
 * Colours: the shared set in colour-tokens.css (--color-*, Evergreen since 2026-11-15), loaded first
 * by every template, so one rule serves both sides. The few colours with a meaning of their own
 * (errors, status chips, the New marker) are named once in the :root block below.
 *
 * Tabs, switch and section head live in ui-components-nav.css (file size).
 */

:root {
  /* Colours the chosen components already used, named once. The lines are the shared Evergreen
     hairline (colour-tokens.css); the error and chip colours carry meaning and stay. */
  --ui-line: var(--color-line);       /* the secondary button border (was #e3d3c4) */
  --ui-field-line: var(--color-line); /* the text field border (was #e5e0d4) */
  --ui-error-bg: #fbede7;        /* .rv6a-error */
  --ui-error-text: #8a2f17;      /* .rv6a-error */
  --ui-new-bg: #346f97;          /* roster "New" badge (= --cw-blue) */
  --ui-chip-blue-bg: #e3edf8;    /* .clin-stchip and its variants */
  --ui-chip-blue: #2d5e95;
  --ui-chip-amber-bg: #fbf0d7;
  --ui-chip-amber: #8a6309;
  --ui-chip-green-bg: #e4f1e9;
  --ui-chip-green: #1f7a4d;
  --ui-chip-red-bg: #fbe3de;
  --ui-chip-red: #9a2e1a;
  --ui-chip-grey-bg: #ecebe6;
  --ui-chip-grey: #4f5560;
  --ui-chip-teal-bg: #ddf1ee;
  --ui-chip-teal: #1d6a60;

  /* Vertical rhythm (layout fix round, 2026-11-11): the gap between a heading or a line of text and the
     card, list or switch beside it. Small = a label and its own control; medium = a heading and the card
     it heads; large = between sections. Nothing sits closer than --ui-gap-s to a card or switch. */
  --ui-gap-s: 8px;
  --ui-gap-m: 12px;
  --ui-gap-l: 16px;
}

/* ------------------------------------------------------------------------------------------
   Buttons: .ui-btn + one of --main / --secondary / --quiet / --danger / --link / --tool.
   Main = the accent pill (.rv6s-pri on clinician, .ui-dialog-btn--primary on patient).
   Secondary = the white outlined pill (.dx-btn). Quiet = text only (.rv6-rb-btn--plain).
   Tool = the tinted header pill (.clin-detail-btn--muted). Link = accent text (.dx-link).
   One filled main button per card, window or toolbar.
   ------------------------------------------------------------------------------------------ */
.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  min-height: var(--ui-btn-h, 32px);
  padding: 0 var(--ui-btn-pad, 14px);
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--color-card);
  color: var(--color-text);
  font: inherit;
  font-family: var(--font-ui, "Inter", system-ui, sans-serif);
  font-size: var(--ui-btn-fs, 13px);
  font-weight: var(--fw-medium, 500);
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.ui-btn:hover:not(:disabled) {
  background: var(--color-panel);
}

.ui-btn:focus-visible {
  outline: 2px solid var(--color-selected);
  outline-offset: 2px;
}

.ui-btn:disabled,
.ui-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
}

/* ButtonBusy (lib/button-busy.js) adds .is-btn-busy and a spinner; it keeps the button's
   colours, so only the dimming differs from button-busy.css's default. */
.ui-btn.is-btn-busy {
  opacity: 0.75;
}

.ui-btn > i {
  font-size: 0.95em;
}

/* .ui-btn--secondary is the base look above; the class is still written in markup so every
   button says which kind it is. */

.ui-btn--main {
  min-height: var(--ui-btn-main-h, var(--ui-btn-h, 32px));
  border-color: var(--color-main);
  background: var(--color-main);
  color: var(--color-on-main);
  font-weight: var(--fw-semibold, 600);
}

/* Hover darkens forest to the text colour (the website's button keeps its colour family). */
.ui-btn--main:hover:not(:disabled) {
  border-color: var(--color-text);
  background: var(--color-text);
}

.ui-btn--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--color-muted);
  padding-inline: 8px;
}

.ui-btn--quiet:hover:not(:disabled) {
  color: var(--color-text);
}

/* Outlined; the filled red is kept for the confirm window (UiDialog danger). */
.ui-btn--danger {
  border-color: var(--cw-danger, var(--ps-red, #b42318));
  color: var(--cw-danger, var(--ps-red, #b42318));
}

.ui-btn--danger:hover:not(:disabled) {
  background: var(--cw-danger-bg, var(--ps-red-bg, #fff1f2));
}

.ui-btn--tool {
  border-color: var(--color-line);
  background: var(--color-panel);
  color: var(--color-link);
}

.ui-btn--tool:hover:not(:disabled) {
  background: var(--color-selected-row);
}

/* A word that acts: accent text, no box. On patient pages the tap area still reaches
   the button height (the box grows, the text does not move). */
.ui-btn--link {
  min-height: var(--ui-link-h, 0px);
  padding: 2px 4px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--color-link);
  font-size: var(--ui-link-fs, 13px);
}

.ui-btn--link:hover:not(:disabled) {
  background: var(--color-panel);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ui-btn--block {
  width: 100%;
}

/* Round icon-only button (header and tool rows). Needs an aria-label. */
.ui-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-sizing: border-box;
  width: var(--ui-x-size, 32px);
  height: var(--ui-x-size, 32px);
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: var(--ui-icon-fs, 14px);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.ui-icon-btn:hover:not(:disabled) {
  background: var(--color-selected-row);
  color: var(--color-link);
}

.ui-icon-btn:focus-visible {
  outline: 2px solid var(--color-selected);
  outline-offset: 2px;
}

.ui-icon-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* A shared button marked hidden stays hidden: .ui-btn / .ui-icon-btn set display, which beats
   the hidden attribute (Add file for a reader who may not add, Add person on a view-only case). */
.ui-btn[hidden],
.ui-icon-btn[hidden] { display: none; }

/* ------------------------------------------------------------------------------------------
   Chips (.clin-stchip) and the "New" marker (roster .clin-aci-new-badge).
   ------------------------------------------------------------------------------------------ */
.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  box-sizing: border-box;
  padding: 2px var(--ui-chip-px, 9px);
  border: 0;
  border-radius: 999px;
  background: var(--ui-chip-blue-bg);
  color: var(--ui-chip-blue);
  font-family: var(--font-ui, "Inter", system-ui, sans-serif);
  font-size: var(--ui-chip-fs, 12px);
  font-weight: var(--fw-medium, 500);
  line-height: var(--ui-chip-lh, 18px);
  white-space: nowrap;
}

.ui-chip--amber { background: var(--ui-chip-amber-bg); color: var(--ui-chip-amber); }
.ui-chip--green { background: var(--ui-chip-green-bg); color: var(--ui-chip-green); }
.ui-chip--red { background: var(--ui-chip-red-bg); color: var(--ui-chip-red); }
.ui-chip--grey { background: var(--ui-chip-grey-bg); color: var(--ui-chip-grey); }
.ui-chip--teal { background: var(--ui-chip-teal-bg); color: var(--ui-chip-teal); }

.ui-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-sizing: border-box;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ui-new-bg);
  color: #fff;
  font-family: var(--font-ui, "Inter", system-ui, sans-serif);
  font-size: var(--ui-new-fs, 11px);
  font-weight: var(--fw-semibold, 600);
  line-height: var(--ui-new-lh, 16px);
  white-space: nowrap;
}

/* ------------------------------------------------------------------------------------------
   Card (.clin-case-letter on clinician, .acp-card on patient) and the heading inside one.
   ------------------------------------------------------------------------------------------ */
.ui-card {
  box-sizing: border-box;
  padding: var(--ui-card-pad, 16px);
  border: 1px solid var(--color-line);
  border-radius: var(--ui-card-radius, 14px);
  background: var(--color-card);
  color: var(--color-text);
}

/* A card that holds section heads or rows edge to edge. */
.ui-card--flush {
  padding: 0;
  overflow: hidden;
}

.ui-subhead {
  margin: 0;
  font-size: var(--ui-subhead-fs, var(--fs-card-title, 14px));
  font-weight: var(--fw-semibold, 600);
  line-height: var(--lh-title, 1.25);
  color: var(--color-text);
}

/* ------------------------------------------------------------------------------------------
   Text fields (.v6t-field on clinician, the window input on patient), search (.clin-roster-search).
   ------------------------------------------------------------------------------------------ */
.ui-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 12px;
}

.ui-label {
  font-size: var(--ui-label-fs, 13px);
  font-weight: var(--fw-semibold, 600);
  color: var(--color-text);
}

.ui-help {
  font-size: var(--fs-secondary, 13px);
  color: var(--color-muted);
}

.ui-input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--ui-input-h, 36px);
  padding: 7px 12px;
  border: 1px solid var(--ui-field-line);
  border-radius: var(--ui-input-radius, 8px);
  background: var(--color-card);
  color: var(--color-text);
  font: inherit;
  font-family: var(--font-ui, "Inter", system-ui, sans-serif);
  font-size: var(--ui-input-fs, 14px);
  line-height: 1.45;
}

textarea.ui-input {
  min-height: 88px;
  resize: vertical;
}

.ui-input::placeholder {
  /* --ui-placeholder: the patient side reads its hints on cream/white at touch size, so
     patient-tokens.css sets the soft text (the 0.48 dim was ~2.5:1; Codex run 3). */
  color: var(--ui-placeholder, var(--color-muted));
}

.ui-input:focus-visible,
.ui-input:focus {
  outline: 2px solid var(--color-selected);
  outline-offset: 0;
  border-color: transparent;
}

.ui-input[aria-invalid="true"] {
  border-color: var(--cw-danger, var(--ps-red, #b42318));
}

.ui-input:disabled {
  opacity: 0.6;
}

/* The line under a field that is wrong. */
.ui-field-error {
  margin: 0;
  font-size: var(--fs-secondary, 13px);
  color: var(--cw-danger, var(--ps-red, #b42318));
}

.ui-search {
  position: relative;
  display: block;
}

.ui-search > i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-12, 12px);
  color: var(--color-muted);
  pointer-events: none;
}

.ui-search > input {
  box-sizing: border-box;
  width: 100%;
  height: var(--ui-search-h, 34px);
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--color-line);
  border-radius: 999px;
  background: var(--color-panel);
  color: var(--color-text);
  font: inherit;
  font-size: var(--ui-input-fs, 14px);
}

.ui-search > input:focus-visible {
  outline: 2px solid var(--color-selected);
  outline-offset: 0;
}

/* ------------------------------------------------------------------------------------------
   Inline error (.rv6a-error), load error (same look + "Try again"), empty state.
   ------------------------------------------------------------------------------------------ */
.ui-error,
.ui-load-error {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--ui-error-bg);
  color: var(--ui-error-text);
  font-size: var(--ui-error-fs, 13px);
  line-height: 1.4;
}

.ui-error__text,
.ui-load-error__text {
  flex: 1 1 12em;
  min-width: 0;
}

/* The Try again button sits on the pink box: white secondary pill, as Retry did. */
.ui-load-error .ui-btn,
.ui-error .ui-btn {
  flex: none;
}

/* One grey line: "No <things> yet." */
.ui-empty {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0;
  padding: 4px 0;
  color: var(--color-muted);
  font-size: var(--ui-empty-fs, 13px);
  line-height: 1.45;
}

.ui-empty > i {
  font-size: 1em;
}

/* A whole pane with nothing in it (the roster's "Pick a patient" look): icon over the line. */
.ui-empty--pane {
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-height: 200px;
  padding: 28px 20px;
  text-align: center;
}

.ui-empty--pane > i {
  font-size: var(--fs-24, 24px);
  color: color-mix(in srgb, var(--color-text) 28%, transparent); /* a faint icon, not words */
}

@media (prefers-reduced-motion: reduce) {
  .ui-btn,
  .ui-icon-btn {
    transition: none;
  }
}

/* One row, one height: when a row holds the main button, every button beside it takes the main height, so a
   48 px "Pay $500" never sits next to a 44 px "Not now" (owner, 2026-11-11). Rows of secondary buttons alone
   (a list's Edit / Remind / Remove) keep the shorter secondary height. The doubled .ui-btn.ui-btn outranks side rules such as
   patient-r2.css .acp-cta.ui-btn, which load later. */
:where(*):has(> .ui-btn--main) > .ui-btn.ui-btn {
  min-height: var(--ui-btn-main-h, var(--ui-btn-h, 32px));
}
