/* Component styles. Only custom properties from tokens.css; phone sizes are the
   defaults and the tokens switch to tablet values from 768 px. */

/* Status colours that need a dark-mode twin not present in tokens.json roles. */
:root {
  --soon-bg: var(--c-brand-amber-pale);
  --soon-fg: var(--c-brand-amber-chip-text);
  --tint-selected: color-mix(in srgb, var(--c-selected) 12%, var(--c-surface));
  --tint-danger: color-mix(in srgb, var(--c-danger) 12%, var(--c-surface));
  --tint-success: color-mix(in srgb, var(--c-success) 12%, var(--c-surface));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --soon-bg: color-mix(in srgb, var(--c-brand-amber) 20%, var(--c-surface));
    --soon-fg: var(--c-brand-amber);
  }
}
:root[data-theme="dark"] {
  --soon-bg: color-mix(in srgb, var(--c-brand-amber) 20%, var(--c-surface));
  --soon-fg: var(--c-brand-amber);
}

/* ---- Icon ------------------------------------------------------------------ */
.icon {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Button ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--size-secondary-button);
  padding: 0 20px;
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  font-family: var(--font-ui);
  font-size: var(--type-body);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease-out, border-color 120ms ease-out;
}
.btn--primary {
  min-height: var(--size-primary-button);
  width: 100%;
  background: var(--c-brand-amber);
  color: var(--c-brand-charcoal);
}
.btn--primary:hover {
  background: var(--c-brand-amber-strong);
}
.btn--hero {
  min-height: var(--size-primary-button-hero);
}
.btn--secondary {
  background: var(--c-surface);
  border-color: var(--c-border);
  color: var(--c-text);
}
.btn--secondary:hover {
  border-color: var(--c-text-2);
}
.btn--danger {
  background: var(--c-surface);
  border-color: var(--c-danger);
  color: var(--c-danger);
}
.btn--danger:hover {
  background: var(--tint-danger);
}
.btn--icon {
  width: var(--size-icon-row-button);
  min-height: var(--size-icon-row-button);
  padding: 0;
}
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---- Field ------------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field__optional {
  margin-left: 8px;
  font-size: var(--type-meta);
  font-weight: 400;
  color: var(--c-text-2);
}
.field__hint {
  font-size: var(--type-meta);
  color: var(--c-text-2);
}
.field__input--big {
  min-height: var(--size-numeric-input);
  font-size: var(--type-numeric);
  font-weight: 600;
}
.field[data-invalid] .field__input {
  border-color: var(--c-danger);
  background: var(--tint-danger);
}
.field__error {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--type-meta);
  font-weight: 600;
  color: var(--c-danger);
}
.field__error .icon {
  width: 20px;
  height: 20px;
}

/* ---- Chip + Segmented (checkbox / radio backed) -------------------------------- */
.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.chip,
.segmented__option {
  position: relative;
  display: block;
}
.chip__input,
.segmented__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip__face {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: var(--size-chip);
  padding: 8px 14px;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--radius-lg);
  font-weight: 600;
  line-height: 1.2;
}
.chip__sub {
  font-size: var(--type-meta);
  font-weight: 400;
  color: var(--c-text-2);
}
.chip__input:checked + .chip__face,
.segmented__input:checked + .segmented__face {
  background: var(--tint-selected);
  border-color: var(--c-selected);
  color: var(--c-selected);
}
.chip__input:checked + .chip__face .chip__sub {
  color: inherit;
}
.chip__input:focus-visible + .chip__face,
.segmented__input:focus-visible + .segmented__face {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
}

.segmented__legend {
  margin-bottom: 6px;
  padding: 0;
  font-weight: 600;
}
.segmented__options {
  display: flex;
}
.segmented__option {
  flex: 1 1 0;
  min-width: 0;
}
.segmented__face {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--size-secondary-button);
  padding: 0 6px;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  margin-left: -2px;
  font-weight: 600;
}
.segmented__option:first-child .segmented__face {
  margin-left: 0;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}
.segmented__option:last-child .segmented__face {
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.segmented__input:checked + .segmented__face {
  position: relative;
  z-index: 1;
}

/* ---- Plate chip + make tile -------------------------------------------------------- */
.plate {
  display: inline-flex;
  align-items: stretch;
  overflow: hidden;
  border: 1.5px solid var(--c-brand-graphite);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--c-brand-charcoal);
  line-height: 1;
  vertical-align: middle;
}
.plate__stub {
  display: flex;
  align-items: center;
  padding: 0 6px;
  background: var(--c-brand-graphite);
  color: #fff;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
}
.plate__no {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  font-weight: 600;
  font-size: var(--type-meta);
}
.plate--md .plate__no {
  padding: 6px 10px;
  font-size: var(--type-data);
}
.plate--lg .plate__stub {
  padding: 0 10px;
  font-size: 16px;
}
.plate--lg .plate__no {
  padding: 8px 14px;
  font-size: calc(var(--type-data) + 5px);
}
.plate--on-dark {
  border-color: #fff;
}

.make-tile {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--c-brand-graphite);
  color: #fff;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.04em;
}
.make-tile--due {
  background: var(--c-brand-amber);
  color: var(--c-brand-charcoal);
}

/* ---- Status ------------------------------------------------------------------------ */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: var(--type-meta);
  font-weight: 600;
  line-height: 1.2;
}
.status .icon {
  width: 18px;
  height: 18px;
}
.status--overdue {
  background: var(--tint-danger);
  color: var(--c-danger);
}
.status--soon {
  background: var(--soon-bg);
  color: var(--soon-fg);
}
.status--ok {
  background: var(--c-bg);
  color: var(--c-text-2);
  border: 1px solid var(--c-border);
}
.status--done {
  background: var(--tint-success);
  color: var(--c-success);
}

/* ---- Money --------------------------------------------------------------------------- */
.money--unknown {
  color: var(--c-text-2);
}

/* ---- Card ---------------------------------------------------------------------------- */
.card {
  padding: 16px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
}
.card__title {
  margin-bottom: 8px;
}

/* ---- List row: one link, optional sibling action ---------------------------------------- */
.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
}
.row__main {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 12px;
  min-height: var(--size-list-row);
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  color: inherit;
  text-decoration: none;
}
a.row__main:hover {
  background: var(--c-bg);
}
.row__body {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.row__title {
  font-weight: 700;
  overflow-wrap: anywhere;
}
.row__sub {
  color: var(--c-text-2);
  font-size: var(--type-meta);
}
.row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 4px;
}
.row__trailing {
  display: flex;
  flex: none;
  align-items: center;
  color: var(--c-text-2);
}
.row__action {
  display: flex;
  flex: none;
  align-items: center;
  padding-right: 10px;
}

/* ---- Sheet ---------------------------------------------------------------------------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(21 24 25 / 0.55);
}
.sheet__panel {
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px;
  background: var(--c-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.sheet__title {
  font-size: var(--type-question);
}

/* ---- Toasts --------------------------------------------------------------------------- */
.toast-region {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--size-nav-item) + 24px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  max-width: 480px;
  padding: 14px 18px;
  background: var(--c-brand-charcoal);
  color: #fff;
  border-radius: var(--radius-lg);
  font-weight: 600;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
}

/* ---- Step form ------------------------------------------------------------------------- */
.steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: var(--form-max);
}
.steps__progress {
  display: flex;
  gap: 6px;
}
.steps__progress s {
  flex: 1 1 0;
  height: 6px;
  border-radius: 3px;
  background: var(--c-border);
  text-decoration: none;
}
.steps__progress s[data-on] {
  background: var(--c-brand-amber);
}
.step {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}
.step__question {
  margin-bottom: 12px;
  padding: 0;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: var(--type-question);
  line-height: 1.1;
  text-transform: uppercase;
}
.step__fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
/* Back/Next exist only on the phone, once app.js has taken over the form. */
.step__nav {
  display: none;
}
@media (max-width: 767.98px) {
  .steps[data-ready] .step__nav {
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
  }
  .steps[data-ready] .step:last-of-type .step__next {
    display: none;
  }
}
@media (min-width: 768px) {
  .steps__progress {
    display: none;
  }
}

/* ---- Wide screens: chips 3 across, sheet becomes a centred panel ---------------------------- */
@media (min-width: 768px) {
  .chips {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .sheet {
    align-items: center;
  }
  .sheet__panel {
    max-width: 520px;
    border-radius: var(--radius-lg);
  }
  .toast-region {
    bottom: 24px;
  }
  .btn--primary {
    width: auto;
    min-width: 200px;
  }
}

/* ---- Dev gallery (/dev/ui) -------------------------------------------------------------------- */
.gallery__main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px;
}
.gallery__section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gallery__title {
  font-size: var(--type-body);
  letter-spacing: 0.08em;
  color: var(--c-text-2);
}
.gallery__stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: var(--form-max);
}
.gallery__cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.gallery__dark {
  display: inline-flex;
  padding: 10px;
  background: var(--c-brand-charcoal);
  border-radius: var(--radius-md);
}
