/* AutoMin UI kit components: base, layout helpers, buttons, fields, progress bar,
   cards, messages and the language switch. Colours and sizes come only from
   tokens.css. Plain CSS, no build step (ADR-0003). */

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%; /* never fix the root size: the browser's text-size setting must scale everything */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-body);
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
.h1,
.h2,
.h3 {
  margin: 0;
  font-weight: var(--weight-bold);
  line-height: var(--leading-heading);
  text-wrap: balance;
}

h1,
.h1 {
  font-size: var(--text-2xl);
}
h2,
.h2 {
  font-size: var(--text-xl);
}
h3,
.h3 {
  font-size: var(--text-lg);
}
h4 {
  font-size: var(--text-base);
}

p {
  margin: 0;
  max-width: var(--measure);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.muted {
  color: var(--text-muted);
}

a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 2px;
}

/* One focus style for everything that can be focused. */
:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}

/* ---------- Layout helpers ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
}

.cluster--split {
  justify-content: space-between;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  min-width: var(--control-height);
  padding: 0 var(--space-6);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: var(--weight-strong);
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

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

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

.btn--quiet {
  background: transparent;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 2px;
}
.btn--quiet:hover {
  background: var(--accent-soft);
}

.btn--danger {
  background: var(--danger-fill);
  color: var(--on-danger-fill);
}
.btn--danger:hover {
  background: var(--danger-fill-hover);
}

.btn--block {
  display: flex;
  width: 100%;
}

/* Disabled controls are exempt from the contrast rule, but stay readable. */
.btn:disabled {
  cursor: not-allowed;
  background: var(--surface-sunken);
  color: var(--text-muted);
  border-color: var(--border);
  text-decoration: none;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

.field__label {
  font-weight: var(--weight-strong);
  padding: 0;
}

.field__hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.field__error {
  color: var(--danger-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
}

.input,
.select {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.input:focus-visible,
.select:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: 0;
  border-color: var(--focus-ring);
}

.input:disabled,
.select:disabled {
  background: var(--surface-sunken);
  color: var(--text-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

/* An error is shown by colour, a thicker border and the message text, never by colour alone. */
.field--error .input,
.field--error .select {
  border-color: var(--danger-text);
  border-width: 4px;
  padding: 0 calc(var(--space-4) - 2px);
}

.select {
  appearance: none;
  padding-right: var(--space-7);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.6rem) 50%, calc(100% - 1.15rem) 50%;
  background-size: 0.45rem 0.45rem, 0.45rem 0.45rem;
  background-repeat: no-repeat;
}

/* Checkbox and radio: the real input is kept (keyboard, screen readers) and restyled. */
.check {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--control-height);
  cursor: pointer;
}

.check input {
  appearance: none;
  flex: none;
  position: relative;
  width: 2rem;
  height: 2rem;
  margin: 0;
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.check input[type="radio"] {
  border-radius: 50%;
}

.check input:checked {
  background: var(--accent);
  border-color: var(--accent-text);
}

.check input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 0.6rem;
  top: 0.2rem;
  width: 0.55rem;
  height: 1.1rem;
  border: solid var(--on-accent);
  border-width: 0 4px 4px 0;
  transform: rotate(45deg);
}

.check input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 0.45rem;
  border-radius: 50%;
  background: var(--on-accent);
}

.check input:disabled {
  background: var(--surface-sunken);
  border-color: var(--border);
  cursor: not-allowed;
}

/* ---------- Progress bar ---------- */

.progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.progress__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-4);
}

.progress__step {
  font-weight: var(--weight-strong);
}

.progress__time {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.progress__bar {
  --progress: 0%;
  height: 1rem;
  border-radius: var(--radius-pill);
  background: var(--progress-track);
  overflow: hidden;
}

.progress__fill {
  display: block;
  height: 100%;
  width: var(--progress);
  border-radius: var(--radius-pill);
  background: var(--progress-fill);
  transition: width var(--transition);
}

/* ---------- Cards ---------- */

.card {
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card__title {
  margin-bottom: var(--space-2);
}

/* A card that is also a checkbox. The input comes first so that a sibling selector
   can style the box on :checked and :focus-visible without :has(). */
.choice {
  position: relative;
  display: block;
  cursor: pointer;
}

.choice__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.choice__box {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-5);
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: background-color var(--transition), border-color var(--transition);
}

.choice:hover .choice__box {
  background: var(--surface-sunken);
}

.choice__input:checked + .choice__box {
  background: var(--accent-soft);
  border-color: var(--accent-text);
  border-width: 4px;
  padding: calc(var(--space-5) - 2px);
}

.choice__input:focus-visible + .choice__box {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.choice__mark {
  position: relative;
  flex: none;
  width: 2rem;
  height: 2rem;
  margin-top: 0.1rem;
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.choice__input:checked + .choice__box .choice__mark {
  background: var(--accent);
  border-color: var(--accent-text);
}

.choice__input:checked + .choice__box .choice__mark::after {
  content: "";
  position: absolute;
  left: 0.6rem;
  top: 0.2rem;
  width: 0.55rem;
  height: 1.1rem;
  border: solid var(--on-accent);
  border-width: 0 4px 4px 0;
  transform: rotate(45deg);
}

.choice__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.choice__title {
  font-weight: var(--weight-bold);
}

.choice__text {
  color: var(--text);
  font-size: var(--text-sm);
}

/* ---------- Messages ---------- */

.banner {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  border-left: 0.5rem solid var(--accent-text);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
}

.banner__title {
  font-weight: var(--weight-bold);
  color: var(--accent-text);
}

.banner--warning {
  border-left-color: var(--warning-border);
  background: var(--warning-soft);
}
.banner--warning .banner__title {
  color: var(--warning-text);
}

.banner--danger {
  border-left-color: var(--danger-text);
  background: var(--danger-soft);
}
.banner--danger .banner__title {
  color: var(--danger-text);
}

/* ---------- Language switch ---------- */

.lang-switch {
  display: inline-flex;
  padding: var(--space-1);
  gap: var(--space-1);
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.lang-switch__btn {
  min-height: 3rem;
  min-width: 3rem;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: var(--weight-strong);
  cursor: pointer;
}

/* The pressed state is the green fill plus a dark ring: the fill alone is under 3:1 on light. */
.lang-switch__btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: inset 0 0 0 3px var(--accent-text);
}

.lang-switch__btn:not([aria-pressed="true"]):hover {
  background: var(--surface-sunken);
}
