/* UI building blocks (ui/components.js, mascot.js, toast.js, sheet.js). Tokens only. */

/* ── Icon ── */
.icon {
  flex: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  color: var(--text-muted);
}
.icon-btn:active {
  background: var(--surface-alt);
}

/* ── Button ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 48px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  font-weight: 800;
  font-size: var(--fs-md);
  transition: transform var(--dur-fast) var(--ease-out);
  user-select: none;
  -webkit-user-select: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.btn--block {
  display: flex;
  width: 100%;
}
.btn--primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-1);
}
.btn--secondary {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 2px var(--c-gold-300);
}
.btn--ghost {
  color: var(--c-gold-700);
}
.btn--danger {
  background: var(--danger);
  color: var(--on-danger);
}

/* ── Card ── */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card--padded {
  padding: var(--sp-4);
}
.card--gold {
  background: var(--c-cream-100);
}
.card--leaf {
  background: var(--c-leaf-50);
}
.card--sky {
  background: var(--c-sky-50);
}
.card--coral {
  background: var(--c-coral-50);
}

/* ── List item ── */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 60px;
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  background: var(--surface);
}
.list-item + .list-item {
  border-top: 1px solid var(--border);
}
.list-item--interactive {
  transition: background-color var(--dur-fast) var(--ease-out);
}
.list-item--interactive:active {
  background: var(--surface-alt);
}
.list-item__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--r-md);
  background: var(--c-cream-100);
  color: var(--c-gold-700);
}
.list-item__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.list-item__title {
  font-weight: 800;
}
.list-item__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.list-item__chevron {
  color: var(--text-muted);
  flex: none;
}

/* ── Avatar ── */
.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--c-white);
  font-weight: 800;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ── Skeleton ── */
.skeleton {
  display: block;
  background: var(--c-cream-100);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

/* ── Module tile ── */
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  height: 100%;
  min-height: 132px;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-out);
}
.tile:active {
  transform: scale(0.97);
}
.tile__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: var(--sp-2);
  border-radius: var(--r-md);
  background: var(--tile-bg);
  color: var(--tile-fg);
}
.tile__title {
  font-weight: 800;
  line-height: 1.2;
}
.tile__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.3;
}
.tile--gold {
  --tile-bg: var(--c-cream-100);
  --tile-fg: var(--c-gold-700);
}
.tile--leaf {
  --tile-bg: var(--c-leaf-50);
  --tile-fg: var(--c-leaf-500);
}
.tile--sky {
  --tile-bg: var(--c-sky-50);
  --tile-fg: var(--c-sky-500);
}
.tile--coral {
  --tile-bg: var(--c-coral-50);
  --tile-fg: var(--c-coral-500);
}

/* ── Toggle ── */
.toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 60px;
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
}
.toggle__text {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.toggle__label {
  font-weight: 800;
}
.toggle__hint {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.toggle__track {
  position: relative;
  width: 52px;
  height: 32px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--border);
  transition: background-color var(--dur-base) var(--ease-out);
}
.toggle__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c-white);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-base) var(--ease-spring);
}
.toggle input:checked + .toggle__track {
  background: var(--c-leaf-500);
}
.toggle input:checked + .toggle__track .toggle__thumb {
  transform: translateX(20px);
}
.toggle input:focus-visible + .toggle__track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ── Section title ── */
.section-title {
  margin: var(--sp-5) 0 var(--sp-2);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ── Empty state ── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-4);
  animation: fade-up var(--dur-slow) var(--ease-out) both;
}
.empty__art {
  width: min(220px, 60vw);
}
.empty__title {
  font-size: var(--fs-lg);
}
.empty__text {
  color: var(--text-muted);
  max-width: 32ch;
}
.empty__actions {
  margin-top: var(--sp-2);
}

/* ── Toast ── */
.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-4));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  pointer-events: none;
  z-index: 70;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  max-width: var(--content-max);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--c-brown-900);
  color: var(--c-cream-50);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: fade-up var(--dur-base) var(--ease-out) both;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
}
.toast--leaving {
  opacity: 0;
  transform: translateY(12px);
}
.toast__text {
  flex: 1;
}
.toast__action {
  min-height: 44px;
  font-weight: 800;
  color: var(--c-gold-300);
}

/* ── Bottom sheet ── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(59 42 30 / 0.4);
  animation: fade-in var(--dur-base) var(--ease-out) both;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  display: flex;
  flex-direction: column;
  max-width: var(--content-max);
  max-height: 88dvh;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  outline: none;
  animation: sheet-in var(--dur-slow) var(--ease-out) both;
  transition: transform var(--dur-base) var(--ease-out);
}
.sheet--dragging {
  transition: none;
}
.sheet-root--leaving .sheet {
  animation: sheet-out var(--dur-base) var(--ease-out) both;
}
.sheet-root--leaving .sheet-backdrop {
  animation: fade-out var(--dur-base) var(--ease-out) both;
}
.sheet__handle-zone {
  display: grid;
  place-items: center;
  height: 28px;
  touch-action: none;
  cursor: grab;
}
.sheet__handle {
  width: 40px;
  height: 5px;
  border-radius: var(--r-pill);
  background: var(--border);
}
.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4) var(--sp-2);
}
.sheet__header h2 {
  font-size: var(--fs-lg);
}
.sheet__body {
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-4) var(--sp-6);
  overscroll-behavior: contain;
}
@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}
@keyframes sheet-out {
  to {
    transform: translateY(100%);
  }
}

/* ── Mascot (Riley) ── */
.mascot {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.mascot .m-fur {
  fill: var(--c-gold-500);
}
.mascot .m-fur-dark {
  fill: var(--c-gold-700);
}
.mascot .m-fur-light {
  fill: var(--c-gold-300);
}
.mascot .m-cream {
  fill: var(--c-cream-50);
}
.mascot .m-ink {
  fill: var(--c-brown-900);
}
.mascot .m-shine {
  fill: var(--c-white);
}
.mascot .m-line {
  fill: none;
  stroke: var(--c-brown-900);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.mascot .m-tongue {
  fill: var(--c-tongue);
}
.mascot .m-blush {
  fill: var(--c-coral-500);
  opacity: 0.22;
}
.mascot .m-collar {
  fill: var(--c-sky-500);
}
.mascot .m-tag {
  fill: var(--c-gold-300);
  stroke: var(--c-gold-700);
  stroke-width: 1.5;
}
.mascot .m-shadow {
  fill: var(--c-brown-900);
  opacity: 0.08;
}
.mascot .m-zzz text {
  fill: var(--c-gold-700);
  font-weight: 800;
  font-family: var(--font);
}

/* Motion – transform/opacity only */
.mascot--animated .m-tail {
  transform-box: view-box;
  transform-origin: 140px 176px;
  animation: m-wag 3.2s ease-in-out infinite;
}
.mascot--animated.mascot--sit .m-head {
  transform-box: view-box;
  transform-origin: 100px 112px;
  animation: m-tilt 6s var(--ease-out) infinite;
}
.mascot--animated .m-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: m-blink 5s infinite;
}
.mascot--animated .m-body {
  transform-box: view-box;
  transform-origin: 100px 205px;
  animation: m-breathe 3.6s ease-in-out infinite;
}
.mascot--animated.mascot--sleep .m-body,
.mascot--animated.mascot--sleep .m-head {
  transform-box: view-box;
  transform-origin: 110px 128px;
  animation: m-breathe 4.5s ease-in-out infinite;
}
.mascot--animated .m-zzz text {
  animation: m-float 3s ease-in-out infinite;
}
.mascot--animated .m-zzz text:nth-child(2) {
  animation-delay: 0.5s;
}
.mascot--animated .m-zzz text:nth-child(3) {
  animation-delay: 1s;
}

/* Short wag bursts with pauses – lively but not restless */
@keyframes m-wag {
  0%,
  30%,
  100% {
    transform: none;
  }
  6%,
  18% {
    transform: rotate(-9deg);
  }
  12%,
  24% {
    transform: rotate(11deg);
  }
}
@keyframes m-tilt {
  0%,
  40%,
  100% {
    transform: none;
  }
  50%,
  70% {
    transform: rotate(-6deg);
  }
}
@keyframes m-blink {
  0%,
  92%,
  100% {
    transform: none;
  }
  95% {
    transform: scaleY(0.1);
  }
}
@keyframes m-breathe {
  50% {
    transform: scale(1.015);
  }
}
@keyframes m-float {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  40% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ── Forms (ui/form.js) ── */
.form {
  display: grid;
  gap: var(--sp-4);
}
.form--busy {
  opacity: 0.6;
  pointer-events: none;
}
.field {
  display: grid;
  gap: var(--sp-1);
}
.field__label {
  font-weight: 800;
  font-size: var(--fs-sm);
}
.field__hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.field__input {
  width: 100%;
  min-height: 48px;
  padding: var(--sp-3);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  /* ≥16px prevents iOS from zooming into inputs */
  font: inherit;
  font-size: max(16px, var(--fs-md));
  transition: border-color var(--dur-fast) var(--ease-out);
  -webkit-appearance: none;
  appearance: none;
}
.field__input:focus {
  outline: none;
  border-color: var(--c-gold-500);
}
.field__input--area {
  min-height: 96px;
  resize: vertical;
}
select.field__input {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 50%,
    calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: var(--sp-8);
}
.field__input--file {
  padding: var(--sp-2);
}
.field--toggle {
  /* .field is a grid – the switch must sit next to its label */
  display: flex;
  padding: 0;
  min-height: 48px;
}
.form__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
.form__actions .btn--ghost {
  margin-right: auto;
  color: var(--c-coral-600);
}

/* ── Status chip ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 800;
  white-space: nowrap;
  background: var(--c-cream-100);
  color: var(--c-gold-700);
}
.chip--ok {
  background: var(--c-leaf-50);
  color: var(--c-leaf-700);
}
.chip--warn {
  background: var(--c-cream-100);
  color: var(--c-gold-700);
}
.chip--danger {
  background: var(--c-coral-50);
  color: var(--c-coral-600);
}

/* ── Dialog (ui/dialog.js) ── */
.dialog-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
}
.dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(59 42 30 / 0.45);
  animation: fade-in var(--dur-base) var(--ease-out) both;
}
.dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  max-width: 360px;
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  text-align: center;
  animation: dialog-in var(--dur-slow) var(--ease-spring) both;
}
.dialog__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--sp-1);
  border-radius: 50%;
  background: var(--c-cream-100);
  color: var(--c-gold-700);
}
.dialog__icon--danger {
  background: var(--c-coral-50);
  color: var(--c-coral-600);
}
.dialog__title {
  font-size: var(--fs-lg);
}
.dialog__text {
  color: var(--text-muted);
}
.dialog__actions {
  display: flex;
  gap: var(--sp-2);
  width: 100%;
  margin-top: var(--sp-3);
}
.dialog__actions .btn {
  flex: 1;
  padding: 0 var(--sp-3);
}
.dialog-root--leaving .dialog {
  animation: dialog-out var(--dur-fast) var(--ease-out) both;
}
.dialog-root--leaving .dialog-backdrop {
  animation: fade-out var(--dur-fast) var(--ease-out) both;
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(8px);
  }
}
@keyframes dialog-out {
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

/* ── Components field (meal ingredients) ── */
.components__rows {
  display: grid;
  gap: var(--sp-2);
}
.components__row {
  display: grid;
  grid-template-columns: 1fr 84px 44px;
  gap: var(--sp-2);
  align-items: center;
  animation: fade-up var(--dur-base) var(--ease-out) both;
}
.components__amount {
  text-align: right;
}
.components__add {
  justify-self: start;
  min-height: 44px;
  padding: 0 var(--sp-2);
}

/* Icons inside running text stay on the line */
.list-item__subtitle .icon,
.chip .icon {
  display: inline-block;
  vertical-align: -2px;
}

/* ── Colour swatches (form field) ── */
.swatches {
  margin: 0;
  padding: 0;
  border: 0;
}
.swatches__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}
.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}
.swatch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.swatch__dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px var(--surface);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.swatch input:checked + .swatch__dot {
  transform: scale(1.12);
  box-shadow:
    0 0 0 3px var(--surface),
    0 0 0 5px var(--c-brown-900);
}
.swatch input:focus-visible + .swatch__dot {
  box-shadow:
    0 0 0 3px var(--surface),
    0 0 0 5px var(--focus);
}
