/* Shared form controls: fields, check and radio, switch, range, chip. Buttons, cards, toasts and
 * the livery are in components.css; the tokens in styles.css. */

/* ---------- Fields ---------- */

.profile-form {
  display: grid;
  gap: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4) var(--s-3);
}

/* A label wrapping its control: label text muted and semibold above the control. */
.field {
  display: grid;
  gap: var(--s-1);
  color: var(--muted);
  font-size: var(--t-meta);
  font-weight: 600;
}

.field.wide {
  grid-column: 1 / -1;
}

.field.rank {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0;
  border: 0;
}

.field.rank legend {
  padding: 0 0 var(--s-2);
}

.field.rank legend small {
  margin-left: var(--s-1);
  font-weight: 400;
}

.label {
  color: var(--text);
  font-size: var(--t-meta);
  font-weight: 600;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--t-meta);
  font-weight: 400;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: var(--t-meta);
  font-weight: 600;
}

/* Text, number, select, textarea: a hairline box with a 3 px base rule in the text colour. */
.input,
.select,
.textarea,
.field input:not([type="checkbox"], [type="radio"], [type="range"]),
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);
  border-bottom: 3px solid var(--text);
  background: var(--pane);
  color: var(--text);
  font: 400 var(--t-body) / var(--lh-snug) var(--font-ui);
  transition: border-color var(--dur-fast) var(--ease);
}

.input::placeholder,
.textarea::placeholder,
.field input::placeholder,
.field textarea::placeholder {
  color: var(--faint);
  opacity: 1;
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  outline-offset: 0;
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  border-style: dashed;
  border-bottom-color: var(--line-strong);
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.field input[aria-invalid="true"],
.field select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-bottom-color: var(--danger);
  border-bottom-style: dashed;
}

.textarea,
.field textarea {
  min-height: 96px;
  line-height: var(--lh-ui);
  resize: vertical;
}

/* A plain chevron from two gradients: no icon file. */
.select,
.field select {
  appearance: none;
  padding-right: var(--s-7);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 22px) 52%,
    calc(100% - 16px) 52%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

@media (hover: hover) {
  .input:hover:not(:disabled),
  .select:hover:not(:disabled),
  .textarea:hover:not(:disabled),
  .field input:hover:not(:disabled),
  .field select:hover:not(:disabled),
  .field textarea:hover:not(:disabled) {
    border-color: var(--text);
  }
}

@media (max-width: 960px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Checkbox and radio: a square box; ticked or filled in yellow ---------- */

.check {
  appearance: none;
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  margin: var(--s-2);
  border: 2px solid var(--line-strong);
  background: var(--pane);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.check:checked {
  border-color: var(--btn-edge);
  background: var(--volt);
}

/* The tick: two ink strokes, no icon file. */
.check[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 1px;
  width: 7px;
  height: 13px;
  border: solid var(--on-volt);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

/* A radio's mark is a small ink square: one of a set, not a tick. */
.check[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 5px;
  background: var(--on-volt);
}

.check:disabled {
  border-style: dashed;
  background: var(--disabled-bg);
  cursor: not-allowed;
}

/* A label around a check or a switch: the whole row is the target. */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--tap);
  cursor: pointer;
}

/* ---------- Switch: a slanted track, a square thumb (input type=checkbox role=switch) ---------- */

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 56px;
  height: 30px;
  margin: var(--s-2) var(--s-2);
  border: 2px solid var(--line-strong);
  background: var(--pane);
  transform: skewX(var(--skew));
  cursor: pointer;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--muted);
  transition:
    transform var(--dur) var(--ease),
    background-color var(--dur) var(--ease);
}

.switch:checked {
  border-color: var(--btn-edge);
  background: var(--volt);
}

.switch:checked::before {
  transform: translateX(26px);
  background: var(--on-volt);
}

.switch:disabled {
  border-style: dashed;
  cursor: not-allowed;
}

/* ---------- Range: a hard track, a square yellow thumb, a 44 px tall target ---------- */

.range {
  appearance: none;
  width: 100%;
  height: var(--tap);
  margin: 0;
  background: none;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--line-strong);
}

.range::-moz-range-track {
  height: 4px;
  background: var(--line-strong);
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: calc(-1 * var(--s-2));
  border: 2px solid var(--btn-edge);
  background: var(--volt);
}

.range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 2px solid var(--btn-edge);
  border-radius: 0;
  background: var(--volt);
}

.range:focus-visible {
  outline-offset: 0;
}

.range:disabled {
  cursor: not-allowed;
}

.range:disabled::-webkit-slider-thumb {
  background: var(--disabled-bg);
}

.range:disabled::-moz-range-thumb {
  background: var(--disabled-bg);
}

/* ---------- Chip: a parallelogram that selects ---------- */

.chip {
  position: relative;
  isolation: isolate;
  display: inline-flex;
}

/* The face: a <button class="chip"> itself, or the <span> after a label's hidden input. */
button.chip,
label.chip > span {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--s-4);
  border: 0;
  background: none;
  color: var(--text);
  font: 600 var(--t-meta) / var(--lh-snug) var(--font-ui);
  cursor: pointer;
}

button.chip::before,
label.chip > span::before {
  content: "";
  position: absolute;
  inset: 4px 3px;
  z-index: -1;
  border: 1px solid var(--line-strong);
  background: var(--row);
  transform: skewX(var(--skew));
  transition: background-color var(--dur-fast) var(--ease);
}

.chip > input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.chip > input:focus-visible + span {
  outline: var(--focus-w) solid var(--focus);
  outline-offset: 2px;
}

button.chip[aria-pressed="true"],
.chip > input:checked + span {
  color: var(--on-volt);
}

button.chip[aria-pressed="true"]::before,
.chip > input:checked + span::before {
  border: 2px solid var(--btn-edge);
  background: var(--volt);
}

button.chip:disabled,
.chip > input:disabled + span {
  color: var(--disabled-text);
  cursor: not-allowed;
}

button.chip:disabled::before,
.chip > input:disabled + span::before {
  border-style: dashed;
  background: var(--disabled-bg);
}

@media (hover: hover) {
  button.chip:hover:not(:disabled, [aria-pressed="true"])::before,
  .chip > input:hover:not(:disabled, :checked) + span::before {
    border-color: var(--text);
  }
}

/* pressed */
button.chip:active:not(:disabled)::before,
.chip > input:active:not(:disabled) + span::before {
  background: color-mix(in srgb, currentColor 16%, var(--pane));
}

/* A bag chip you can take off: the same face, a cross in its own slot. */
button.chip.removable {
  padding-right: var(--s-2);
}

.chip-x {
  margin-left: var(--s-2);
  font-size: var(--t-lead);
  line-height: 1;
}

/* A switch says On or Off in a word before its track, never by colour alone. */
.sw { color: var(--muted); font: 600 var(--t-xs) / 1 var(--font-ui); }
.sw b { display: none; }
.sw i { font-style: normal; }
:has(> .switch:checked) .sw b { display: inline; }
:has(> .switch:checked) .sw i { display: none; }
