/* Standard controls: the ONE place that decides how a control looks on PsycheDB.

   Rule (site-wide, 2026-11-12): the same kind of control looks the same everywhere. Text and search fields,
   selects, check boxes, radios, sliders, chips, buttons and segmented controls are drawn here and nowhere else.
   A page or a component may only place a control: width, margin, position, flex or grid behaviour, order, and
   the content of a label. It may not set a colour, border, radius, padding, font, shadow or focus style on a
   control. A change of the standard is made in this file and reaches every page at once.
   scripts/check-controls.js (npm run check:controls, part of npm run ci) enforces the rule.

   Fields, check boxes, radios and sliders are styled by element, so every new one gets the standard without a class.
   Chips, buttons and segmented controls carry a class: .ui-chip, .ui-btn (.ui-btn--quiet, .ui-btn--text), .ui-seg.
   The theme variables (--accent, --border, --surface-elevated ...) come from theme-overrides.css. */

:root {
  --ctl-radius: var(--radius-sm, 12px);
  --ctl-pill: 999px;
  --ctl-pad: 10px 12px;
  --ctl-size: 0.95rem;
  --ctl-bg: var(--surface-elevated, var(--surface));
  --ctl-border: var(--border);
  --ctl-focus-border: rgba(var(--accent-rgb), 0.5);
  --ctl-focus: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
  --ctl-check: 1.05rem;
  --ctl-chip-min: 32px;
  --ctl-btn-min: 40px;
}

/* ---- Base: every control takes the font of the page ---- */
button,
input,
select,
textarea { font: inherit; }

/* ---- Fields: text, search, e-mail, number, text area and select ---- */
input:not([type]),
input[type="text"],
input[type="search"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="password"],
textarea,
select {
  box-sizing: border-box;
  padding: var(--ctl-pad);
  font: inherit;
  font-size: var(--ctl-size);
  line-height: 1.3;
  color: var(--text);
  background: var(--ctl-bg);
  border: 1px solid var(--ctl-border);
  border-radius: var(--ctl-radius);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
input::placeholder,
textarea::placeholder { color: var(--text-muted); opacity: 1; }
input:not([type]):focus-visible,
input[type="text"]:focus-visible,
input[type="search"]:focus-visible,
input[type="email"]:focus-visible,
input[type="url"]:focus-visible,
input[type="tel"]:focus-visible,
input[type="number"]:focus-visible,
input[type="password"]:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--ctl-focus-border);
  box-shadow: var(--ctl-focus);
}
input:disabled,
textarea:disabled,
select:disabled { opacity: 0.6; cursor: not-allowed; }
input:user-invalid,
textarea:user-invalid,
select:user-invalid { border-color: #f43f5e; }

/* ---- Check boxes, radios and sliders: the site accent, never the browser blue ---- */
input[type="checkbox"],
input[type="radio"] {
  flex: none;
  width: var(--ctl-check);
  height: var(--ctl-check);
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type="range"] { accent-color: var(--accent); cursor: pointer; }
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible,
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A label that carries a check box or a radio. */
.ui-opt { display: inline-flex; align-items: center; gap: 6px; color: var(--text-soft); font-size: 0.86rem; cursor: pointer; }
.ui-opt small { color: var(--text-muted); }

/* ---- Chips: a pill to choose by, or to jump by. aria-pressed, aria-current or .is-on marks the chosen one ---- */
.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl-chip-min);
  padding: 6px 12px;
  font: inherit;
  font-size: 0.86rem;
  color: var(--text);
  text-decoration: none;
  background: rgba(var(--accent-rgb), 0.10);
  border: 1px solid rgba(var(--accent-rgb), 0.18);
  border-radius: var(--ctl-pill);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.ui-chip:hover { background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); border-color: rgba(var(--accent-rgb), 0.24); }
.ui-chip[aria-pressed="true"],
.ui-chip[aria-current="true"],
.ui-chip.is-active,
.ui-chip.is-on { background: var(--accent-soft); border-color: rgba(var(--accent-rgb), 0.4); font-weight: 700; }
.ui-chip small { color: var(--text-muted); font-size: 0.78em; font-weight: 400; }
.ui-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Buttons: .ui-btn is the main action, --quiet a bordered second action, --text a link-like action ---- */
.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--ctl-btn-min);
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  color: var(--button-text, #fff);
  text-decoration: none;
  white-space: nowrap;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  border: 0;
  border-radius: var(--ctl-radius);
  cursor: pointer;
  transition: filter 140ms ease, transform 140ms ease;
}
.ui-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.ui-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ui-btn--quiet { color: var(--text); font-weight: 600; background: var(--ctl-bg); border: 1px solid var(--ctl-border); }
.ui-btn--quiet:hover { filter: none; background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); }
.ui-btn--text { min-height: 0; padding: 0; font-weight: 400; color: var(--text-soft); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; }
.ui-btn--text:hover { filter: none; transform: none; color: var(--text); }
/* A small round icon button, for example a clear cross inside a field, and a square one next to a field. */
.ui-btn--icon { min-height: 0; padding: 0; font-size: 1.05rem; font-weight: 400; line-height: 1; color: var(--text-muted); background: none; border: 0; border-radius: 50%; }
.ui-btn--icon:hover { filter: none; transform: none; color: var(--text); background: var(--surface-soft); }
.ui-btn--quiet.ui-btn--square { min-width: var(--ctl-btn-min); padding: 0; color: var(--accent); }
.ui-btn[hidden] { display: none; }
.ui-btn:disabled { opacity: 0.6; cursor: progress; transform: none; filter: none; }

/* ---- Segmented control: radios in labels or buttons, one of them chosen ---- */
.ui-seg {
  display: inline-flex;
  gap: 2px;
  margin: 0;
  padding: 2px;
  background: var(--ctl-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--ctl-pill);
}
.ui-seg > label,
.ui-seg > button {
  position: relative;
  padding: 5px 14px;
  font: inherit;
  font-size: 0.86rem;
  color: var(--text-soft);
  background: transparent;
  border: 0;
  border-radius: var(--ctl-pill);
  cursor: pointer;
}
.ui-seg > label:has(input:checked),
.ui-seg > button.active,
.ui-seg > button.is-active,
.ui-seg > button[aria-pressed="true"] { color: var(--button-text, #fff); font-weight: 600; background: var(--accent); }
.ui-seg > label input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.ui-seg > label:has(input:focus-visible),
.ui-seg > button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ui-seg > label.is-disabled,
.ui-seg > button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Menu: the list that drops down from a search field or a picker. The component places it, this draws it ---- */
.ui-menu {
  box-sizing: border-box;
  padding: 4px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--ctl-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--ctl-radius);
  box-shadow: var(--shadow);
}
.ui-menu > * { padding: 8px 10px; color: var(--text); border-radius: 8px; cursor: pointer; }
.ui-menu > *:hover,
.ui-menu > .active,
.ui-menu > .is-active,
.ui-menu > [aria-selected="true"] { background: color-mix(in srgb, var(--accent-soft) 70%, var(--ctl-bg)); }
