/* =========================================================================
   ListingLoom — component recipes. Every rule maps to a design.md "Component
   tokens" recipe (buttons/inputs/cards/tags/chips/meter/modal/toast/skeleton/
   banners/header/nav). No raw hex/px outside tokens.css.
   ========================================================================= */

/* ---- Header / nav ---- */
.site-header {
  background: var(--color-bg);
  border-block-end: 1px solid transparent;
}
.site-header.is-scrolled {
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-4);
  /* Wrap to a second row rather than forcing a page-level horizontal scrollbar
     on very narrow phones (≤360px) where brand + nav can't fit on one line. */
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--color-text);
}
.brand__tile {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-4deg);
  flex-shrink: 0;
}
.brand__tile svg {
  width: 16px;
  height: 16px;
}
.brand__word {
  font-family: var(--font-head);
  font-weight: var(--weight-semibold);
  font-size: 20px;
  letter-spacing: -0.01em;
}
.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.nav-link {
  font-size: var(--text-sm-med-size);
  font-weight: var(--text-sm-med-weight);
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition:
    color var(--duration-fast) var(--easing-standard),
    background-color var(--duration-fast) var(--easing-standard);
}
.nav-link:hover {
  color: var(--color-text);
  background: var(--color-primary-soft);
}
.nav-link--cta {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}
/* A <button> in the nav (logout) must look identical to its sibling <a>
   .nav-link elements — reset the button-default chrome, keep the same font/
   color/hover recipe as .nav-link above. */
.btn--logout-link {
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn--logout-link:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.site-nav .hide-on-mobile {
  display: none;
}
@media (min-width: 768px) {
  .site-nav .hide-on-mobile {
    display: inline-flex;
  }
}

.site-footer {
  border-block-start: 1px solid var(--color-border);
  padding-block: var(--space-10);
  margin-block-start: var(--space-16);
}
.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-block-start: var(--space-4);
}
.site-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--text-sm-size);
}
.site-footer a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--button-gap);
  height: var(--button-height);
  padding-inline: var(--button-padding-x);
  border-radius: var(--radius-full);
  font-size: var(--text-button-size);
  line-height: var(--text-button-line);
  font-weight: var(--text-button-weight);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition:
    background-color var(--duration-fast) var(--easing-standard),
    color var(--duration-fast) var(--easing-standard),
    border-color var(--duration-fast) var(--easing-standard),
    transform var(--duration-fast) var(--easing-standard);
  white-space: nowrap;
}
.btn--sm {
  height: var(--button-height-sm);
  padding-inline: var(--button-padding-x-sm);
  font-size: var(--text-button-sm-size);
}
.btn--block {
  width: 100%;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  box-shadow: var(--shadow-md);
}
.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}
.btn--primary:active:not(:disabled) {
  background: var(--color-primary-active);
  transform: translateY(0);
}
.btn--secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
}
.btn--link {
  background: transparent;
  color: var(--color-primary);
  height: auto;
  padding: 0;
  box-shadow: none;
  font-weight: var(--weight-semibold);
}
.btn--link:hover:not(:disabled) {
  color: var(--color-primary-hover);
  text-decoration: underline;
}
.btn--danger {
  background: var(--color-danger);
  color: var(--color-text-on-primary);
}
.btn--danger:hover:not(:disabled) {
  background: var(--color-danger-hover);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  background: var(--line);
  color: var(--color-text-disabled);
  border-color: transparent;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn--link:disabled {
  background: transparent;
}

.btn__spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@media (prefers-reduced-motion: reduce) {
  .btn__spinner {
    animation-duration: 1.4s;
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Cards ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--card-padding);
}
@media (max-width: 767px) {
  .card {
    padding: var(--card-padding-mobile);
  }
}
.well {
  background: var(--color-surface-sage);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
}

/* ---- Eyebrow pill ---- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface-soft);
  color: var(--color-text-strong);
  font-size: var(--text-xs-size);
  font-weight: var(--text-xs-weight);
  line-height: var(--text-xs-line);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---- Inputs ---- */
.field {
  display: block;
}
.field + .field {
  margin-block-start: var(--space-4);
}
.field__label {
  display: block;
  font-size: var(--text-sm-med-size);
  font-weight: var(--text-sm-med-weight);
  color: var(--color-text-muted);
  margin-block-end: var(--space-2);
}
.field__hint {
  font-size: var(--text-sm-size);
  color: var(--color-text-muted);
  margin-block-start: var(--space-2);
}
.input,
.textarea {
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--input-radius);
  padding: var(--input-padding-y) var(--input-padding-x);
  font-family: var(--font-body);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line);
  box-shadow: var(--shadow-inset-input);
  transition:
    border-color var(--duration-fast) var(--easing-standard),
    box-shadow var(--duration-fast) var(--easing-standard);
}
.input {
  height: var(--input-height);
}
.textarea {
  min-height: var(--input-min-height-textarea);
  resize: vertical;
  background: var(--color-bg);
}
.input::placeholder,
.textarea::placeholder {
  /* AA contrast: --color-text-disabled (#8a8078) is only 3.6:1 on the warm paper
     bg and these placeholders carry real guidance ("e.g. Hand-poured lavender…").
     --color-text-placeholder (ink-500) clears 4.5:1 on all three surfaces. */
  color: var(--color-text-placeholder);
}
.input:hover,
.textarea:hover {
  border-color: var(--color-border-strong);
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-inset-input), var(--input-focus-ring);
}
.field.has-error .input,
.field.has-error .textarea {
  border-color: var(--color-danger);
}
.field__error {
  display: none;
  color: var(--color-danger);
  font-size: var(--text-sm-size);
  margin-block-start: var(--space-2);
}
.field.has-error .field__error {
  display: block;
}

/* ---- Category chips (radio-group semantics) ---- */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  border-radius: var(--chip-radius);
  padding: var(--chip-padding);
  font-size: var(--text-sm-med-size);
  font-weight: var(--text-sm-med-weight);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--easing-standard),
    border-color var(--duration-fast) var(--easing-standard),
    color var(--duration-fast) var(--easing-standard);
}
.chip:hover {
  border-color: var(--color-border-strong);
}
.chip input[type='radio'] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
/* :has() covers the server-rendered initial `checked` state (SEO-variant
   pages pre-select a category, AC-2.4) so it's correct before any JS runs.
   The .is-selected class is the reliable mechanism generator.js applies on
   user interaction — some engines lag on re-invalidating :has() style
   recalculation after a scripted `checked` change, so client-driven state
   does not depend on :has() alone. */
.chip:has(input:checked),
.chip.is-selected {
  background: var(--color-accent-soft);
  border-color: var(--sage-500);
  color: var(--color-accent-text);
}
.chip:has(input:focus-visible) {
  box-shadow: var(--shadow-focus);
}

/* ---- Result tags ---- */
.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--tag-radius);
  padding: var(--tag-padding);
  font-size: var(--text-sm-size);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--easing-standard);
}
.tag:hover {
  background: var(--color-primary-soft);
}
.tag.is-copied {
  background: var(--color-success-soft);
}
.tag__check {
  color: var(--color-success);
  display: none;
}
.tag.is-copied .tag__check {
  display: inline;
}

/* ---- Allowance meter ---- */
.meter {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.meter__track {
  flex: 1;
  height: var(--meter-height);
  background: var(--line);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-base) var(--easing-standard);
}
.meter__fill.is-low {
  background: var(--color-warning-fill);
}
.meter__text {
  font-size: var(--text-sm-size);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---- Skeleton (generation wait) ---- */
.skeleton-block {
  display: flex;
  flex-direction: column;
  gap: var(--skeleton-gap);
}
.skeleton-line {
  height: var(--skeleton-line-height);
  border-radius: var(--skeleton-radius);
  background: var(--color-skeleton-base);
  background-image: var(--skeleton-sheen-gradient);
  background-size: 200% 100%;
  animation: skeleton-sheen var(--skeleton-sheen-duration) linear infinite;
}
.skeleton-line--w60 {
  width: 60%;
}
.skeleton-line--w80 {
  width: 80%;
}
.skeleton-line--w40 {
  width: 40%;
}
/* Placeholder shape only (no themed color/spacing choice here beyond the
   tokens already used) — width approximates a real tag's average rendered
   width, height approximates tag-padding (space-1 space-3) around
   text-sm's line-height, i.e. the shape of the real .tag component. */
.skeleton-tag {
  display: inline-block;
  width: 84px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-skeleton-base);
  background-image: var(--skeleton-sheen-gradient);
  background-size: 200% 100%;
  animation: skeleton-sheen var(--skeleton-sheen-duration) linear infinite;
}
@keyframes skeleton-sheen {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-line,
  .skeleton-tag {
    animation: none;
    background-image: none;
  }
}

/* ---- Progressive reveal ---- */
.reveal-block {
  opacity: 0;
  transform: translateY(8px);
  animation: reveal-in var(--reveal-duration) var(--reveal-easing) forwards;
}
.reveal-block[data-reveal-order='1'] {
  animation-delay: calc(var(--reveal-stagger) * 0);
}
.reveal-block[data-reveal-order='2'] {
  animation-delay: calc(var(--reveal-stagger) * 1);
}
.reveal-block[data-reveal-order='3'] {
  animation-delay: calc(var(--reveal-stagger) * 2);
}
@keyframes reveal-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .reveal-block {
    animation: reveal-in-reduced 120ms linear forwards;
    transform: none;
  }
  @keyframes reveal-in-reduced {
    to {
      opacity: 1;
    }
  }
}

.tag-pop {
  opacity: 0;
  transform: scale(0.96);
  animation: tag-pop-in var(--tag-pop-duration) var(--easing-standard) forwards;
}
@keyframes tag-pop-in {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---- Title >140 flag ---- */
.title-flag {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-warning-soft);
  color: var(--color-text);
  border-radius: var(--banner-radius);
  padding: var(--banner-padding);
  font-size: var(--text-sm-size);
  margin-block-start: var(--space-2);
}
.title-flag__icon {
  color: var(--color-warning-fill);
  flex-shrink: 0;
}
.charcount {
  font-family: var(--font-mono);
  font-size: var(--text-mono-sm-size);
  color: var(--color-text-muted);
}
.charcount.is-over {
  color: var(--color-warning);
}
.title-meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-block-start: var(--space-3);
  flex-wrap: wrap;
}

/* ---- S2 result actions row (Regenerate + saved/nudge) ---- */
.result-actions {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-block-start: var(--space-6);
}

/* ---- Banners (inline, non-modal) ---- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  border-radius: var(--banner-radius);
  padding: var(--banner-padding);
  font-size: var(--text-sm-size);
}
.banner--success {
  background: var(--color-success-soft);
  color: var(--color-success);
}
.banner--warning {
  background: var(--color-warning-soft);
  color: var(--color-text);
}
.banner--danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.banner--offline {
  background: var(--color-bg-inset);
  color: var(--color-text-muted);
}

/* ---- Toast (copy confirmation) ---- */
/* design.md Motion: "toast fade 200ms in / 200ms out" — opacity only, no
   slide/translate motion is specified, so none is added here. The -50%
   translateX is pure horizontal-centering layout, not motion. */
.toast {
  position: fixed;
  inset-block-end: var(--space-6);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--toast-radius);
  box-shadow: var(--toast-shadow);
  padding: var(--toast-padding);
  font-size: var(--text-sm-size);
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-base) var(--easing-standard);
  z-index: 60;
}
.toast.is-visible {
  opacity: 1;
  /* Re-enable interaction once shown: the base toast is pointer-events:none so a
     hidden-but-in-DOM toast never blocks clicks, but the history "Undo delete"
     toast has a real button — without this, mouse clicks passed straight through
     it and the delete committed unrecoverably. */
  pointer-events: auto;
}
.toast__icon {
  color: var(--color-success);
}

/* ---- Modal / bottom-sheet ---- */
/* Background scroll-lock while a modal is open (public/js/lib/modal.js toggles
   this on <body>) — not a new visual token, just a behavior so the page
   underneath doesn't scroll behind the focused overlay. */
body.has-modal-open {
  overflow: hidden;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 80;
}
.modal-overlay.is-open {
  display: flex;
}
.modal {
  position: relative; /* containing block for .modal__close — without it the X
    escaped to the fixed overlay (viewport corner) whenever the enter animation's
    retained transform went away: under prefers-reduced-motion, and mid exit-fade. */
  background: var(--color-surface);
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  padding: var(--modal-padding);
  max-width: var(--modal-max-width);
  width: 100%;
  animation: modal-enter var(--duration-slow) var(--easing-emphasis) forwards;
}
/* design.md Motion: "modal-exit: opacity, duration-base, easing-exit" —
   opacity only, no translate (unlike the enter animation). Applied via a
   .is-closing class the JS adds and waits out before actually removing the
   overlay from display, so the exit animation is visible rather than an
   instant disappearance. */
.modal-overlay.is-closing .modal {
  animation: modal-exit var(--duration-base) var(--easing-exit) forwards;
}
@keyframes modal-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes modal-exit {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .modal {
    animation: none;
  }
  .modal-overlay.is-closing .modal {
    animation: none;
  }
}
@media (max-width: 639px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    border-radius: var(--modal-radius) var(--modal-radius) 0 0;
    padding: var(--modal-padding-mobile);
  }
}
.modal__close {
  position: absolute;
  inset-block-start: var(--space-4);
  inset-inline-end: var(--space-4);
  z-index: 1; /* lift above .modal__body (position:relative, later in DOM) so the
    whole X is clickable, not just the corner the title doesn't overlap. */
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}
.modal__close:hover {
  background: var(--color-primary-soft);
  color: var(--color-text);
}
.modal__body {
  position: relative;
}
.modal__title {
  font-family: var(--font-head);
  font-size: var(--text-h3-size);
  line-height: var(--text-h3-line);
  font-weight: var(--text-h3-weight);
  margin-block-end: var(--space-3);
  padding-inline-end: var(--space-8);
}
.modal__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-block-start: var(--space-6);
}

/* ---- S10 history rows ---- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.history-row {
  border-radius: var(--radius-sm);
  background: var(--color-bg-inset);
  overflow: hidden;
}
.history-row__summary {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: start;
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  color: var(--color-text);
}
.history-row__summary:hover {
  background: var(--color-primary-soft);
}
.history-row__snippet {
  font-weight: var(--weight-medium);
}
.history-row__detail {
  padding: var(--space-4);
  border-block-start: 1px solid var(--color-border);
  background: var(--color-surface);
}
.history-row-skeleton {
  border-radius: var(--radius-sm);
  background: var(--color-bg-inset);
  padding: var(--space-4);
}

/* Legal-page prose (S11 — server/content/legal.js renders h2/ul/table content).
   Scoped to .legal-body so generic text-body elsewhere is untouched. */
.legal-body h2 {
  font-family: var(--font-head);
  font-size: var(--text-h3-size);
  line-height: var(--text-h3-line);
  font-weight: var(--text-h3-weight);
  margin-block-start: var(--space-8);
  margin-block-end: var(--space-3);
}
.legal-body p,
.legal-body ul {
  margin-block-end: var(--space-4);
}
.legal-body ul {
  padding-inline-start: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.legal-body a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.legal-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm-size, 14px);
  margin-block-end: var(--space-4);
}
.legal-body th,
.legal-body td {
  text-align: start;
  vertical-align: top;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
}
.legal-body th {
  background: var(--color-bg-inset);
  font-weight: var(--weight-semibold);
}
@media (max-width: 767px) {
  .legal-body table {
    display: block;
    overflow-x: auto;
  }
}

/* Inline link inside running prose (fine-print, sentences). Distinct from
   .btn--link, which is a standalone tertiary ACTION at 16px/600 — borrowing it
   for in-sentence links (login legal line, checkout terms) rendered those words
   bigger and bolder than their own sentence. */
.link-inline {
  color: var(--color-primary);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-inline:hover {
  color: var(--color-primary-hover);
}

/* Coarse-pointer (touch) minimum tap targets. The core loop is tapping 13 result
   tags to copy them, plus category chips and footer links — all below the 44px
   touch guideline at their designed desktop paddings. Desktop (fine pointer) is
   untouched; only touch devices get the larger hit area. */
@media (pointer: coarse) {
  .tag,
  .chip {
    min-height: var(--touch-target-min);
    padding-block: var(--space-2);
  }
  .skeleton-tag {
    height: var(--touch-target-min);
  }
  .nav-link {
    padding-block: var(--space-3);
  }
  .site-footer__links a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch-target-min);
  }
  .btn--link {
    min-height: var(--touch-target-min);
    display: inline-flex;
    align-items: center;
  }
  .modal__close {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inset-block-start: var(--space-2);
    inset-inline-end: var(--space-2);
  }
}
