/* PetSite Factory authenticated app — minimal, functional styling.
   Deliberately NOT claiming 3E-D visual/font parity; this reuses the site's
   palette tokens for cohesion with the public builder. */
:root {
  --app-primary: #744738;
  --app-accent: #b98980;
  --app-bg: #f6efe9;
  --app-paper: #fffdfb;
  --app-ink: #4a413d;
  --app-muted: #876b5c;
  --app-danger: #a3423a;
  --app-line: rgba(74, 65, 61, 0.14);
}
* { box-sizing: border-box; }
.app-body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--app-ink);
  background: linear-gradient(180deg, var(--app-bg), #efe4da);
  min-height: 100svh;
  /* Phase 3 scroll fix. The legacy /assets/styles.css (loaded first, for its
     [hidden] + shared modal rules) locks `body{overflow:hidden}` for the
     full-viewport public builder. The /app/ page is an ordinary scrolling
     document, so restore normal vertical scrolling here. This file loads AFTER
     styles.css and `.app-body` outranks the bare `body` selector, so this wins
     without touching the legacy public builder's styling. No required control
     is ever trapped behind a fixed-height / overflow:hidden container. */
  overflow-x: hidden;
  overflow-y: auto;
}
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.7rem 1rem; background: var(--app-paper);
  border-bottom: 1px solid var(--app-line); position: sticky; top: 0; z-index: 5;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; color: inherit; }
.brand img { height: 34px; width: auto; }
.brand__text { display: flex; flex-direction: column; justify-content: center; line-height: 1.1; }
.app-header__actions { display: flex; align-items: center; gap: 0.6rem; }
.session-email { color: var(--app-muted); font-size: 0.85rem; }

.app-main { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.panel {
  background: var(--app-paper); border: 1px solid var(--app-line);
  border-radius: 18px; padding: 1.2rem; margin-bottom: 1.2rem;
}
.panel--error { border-color: var(--app-danger); }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
h2 { margin: 0 0 0.4rem; font-size: 1.2rem; }
.muted { color: var(--app-muted); }
.form-hint { display: block; color: var(--app-muted); font-size: 0.78rem; margin: 0.1rem 0 0.6rem; }
.form-error { color: var(--app-danger); font-size: 0.85rem; margin: 0.5rem 0 0; }

/* buttons */
.btn {
  border: 1px solid transparent; border-radius: 999px; padding: 0.55rem 1rem;
  font-weight: 700; font-size: 0.9rem; cursor: pointer; background: #e9ddd2; color: var(--app-ink);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* The header "Account" control is a REAL link styled as a button. Keep it
   button-shaped (no underline, centered) and give it a clear keyboard focus
   ring + a current-page state for when the ACCOUNT view is active. */
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
a.btn:focus-visible { outline: 3px solid var(--app-primary); outline-offset: 2px; }
#accountNavBtn[aria-current="page"] { background: var(--app-primary); color: #fff; border-color: var(--app-primary); }
.btn--primary { background: var(--app-primary); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--app-line); }
.btn--danger { background: var(--app-danger); color: #fff; }
.btn--danger-ghost { background: transparent; border-color: var(--app-danger); color: var(--app-danger); }

/* auth */
.auth-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.auth-tab { flex: 1; padding: 0.6rem; border: 1px solid var(--app-line); border-radius: 12px; background: transparent; font-weight: 700; cursor: pointer; }
.auth-tab.is-active { background: var(--app-primary); color: #fff; border-color: var(--app-primary); }
.auth-form label, .account-actions__form label, .builder__form label { display: block; margin-bottom: 0.7rem; font-weight: 600; font-size: 0.9rem; }
.auth-form input, .account-actions__form input,
.builder__form input, .builder__form select, .builder__form textarea {
  width: 100%; margin-top: 0.25rem; padding: 0.55rem 0.7rem; font: inherit;
  border: 1px solid var(--app-line); border-radius: 10px; background: #fff;
}
.notice { border-radius: 12px; padding: 1rem; }
.notice--info { background: #eef4f4; }

/* pets */
.pet-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.pet-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.8rem 1rem; border: 1px solid var(--app-line); border-radius: 14px; }
.pet-card__lead { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
/* Small hero thumbnail to the LEFT of the name. Neutral circle background so a
   not-yet-loaded / src-less image still reads as a tasteful avatar, never a
   broken-image icon. */
.pet-card__avatar { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; object-fit: cover; background: #ece1d6; border: 1px solid var(--app-line); }
.pet-card__avatar--placeholder { display: grid; place-items: center; color: var(--app-primary); font-weight: 800; font-size: 1.05rem; background: #f0e6dc; }
.pet-card__body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.pet-card__handle { overflow-wrap: anywhere; }
.pet-card__meta { font-size: 0.75rem; color: var(--app-muted); }
.pet-card__stats { font-size: 0.78rem; color: var(--app-ink); font-weight: 600; }
.pet-card__status { font-size: 0.75rem; color: var(--app-muted); }
.pet-card__status--review_required { color: var(--app-danger); }
.pet-card__actions { display: flex; gap: 0.4rem; }

/* pets — per-card share arrow (min 44px accessible touch target) */
.pet-card__share {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0.4rem; border-radius: 50%;
  color: var(--app-primary);
}
.pet-card__share svg { display: block; }

/* Add another — persistent create-or-gated affordance below the card list */
.add-another { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--app-line); }
.add-another__heading { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--app-muted); }

/* account */
.account-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.4rem; }
.account-actions__form { margin-top: 0.8rem; max-width: 360px; }
.account-links { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 0.2rem 0 0.9rem; }
.account-terms-link { color: var(--app-primary); font-size: 0.85rem; font-weight: 600; }

/* signup Terms consent */
.terms-consent { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.2rem 0 0.9rem; }
.terms-consent input[type="checkbox"] { width: 1.1rem; height: 1.1rem; margin-top: 0.15rem; flex: 0 0 auto; }
.terms-consent__label { font-weight: 500; font-size: 0.9rem; line-height: 1.4; }
.link-btn {
  border: 0; background: transparent; padding: 0; margin: 0; font: inherit; cursor: pointer;
  color: var(--app-primary); font-weight: 700; text-decoration: underline;
}

/* Terms modal meta + z-index guard (both stylesheets define `.modal`; pin the
   terms overlay above the app surface deterministically). */
.modal.terms-modal { z-index: 30; }
.terms-modal__meta { font-size: 0.8rem; margin: 0 0 0.6rem; text-align: center; }

/* footer */
.app-footer { max-width: 1100px; margin: 0 auto; padding: 0 1rem 2rem; text-align: center; }
.app-footer a { color: var(--app-muted); font-size: 0.82rem; text-decoration: underline; }

/* builder */
.builder { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
/* Live preview sits beside the active step on desktop. It is bounded (its own
   contained overflow) so it never becomes a scroll trap for the form/nav: the
   page body owns the vertical scroll; the iframe scrolls its own document. */
.builder__preview { position: sticky; top: 70px; height: calc(100svh - 100px); max-height: calc(100svh - 100px); border: 1px solid var(--app-line); border-radius: 16px; overflow: hidden; background: #fff; }
.builder__preview iframe { width: 100%; height: 100%; border: 0; }
.builder__form { background: var(--app-paper); border: 1px solid var(--app-line); border-radius: 16px; padding: 1.1rem; }

/* ---- stepper: only the active step's panel is shown (never all at once) ---- */
.builder-step { display: none; }
.builder-step.is-active { display: block; animation: stepIn 0.25s ease; }
@keyframes stepIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.builder-step__title { margin: 0 0 0.3rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.2rem; color: var(--app-primary); }
.builder-step__title:focus { outline: none; }
.builder-step__sub { margin: 0 0 0.7rem; color: var(--app-muted); font-size: 0.88rem; }

/* progress: a COMPACT single-step indicator — one descriptive step line, one
   bar, and one percentage label positioned OUTSIDE the filled portion (never
   overlaid on it). There is no row of step pills. */
.builder-progress { display: grid; gap: 0.4rem; margin: 0.2rem 0 1rem; justify-items: start; }
.builder-step-heading { margin: 0; color: var(--app-ink); font-size: 0.92rem; font-weight: 700; }
/* track = pale neutral; fill = the PetSite accent→brown. */
.builder-progressbar { position: relative; width: 100%; height: 12px; border-radius: 999px; background: #ece1d6; border: 1px solid var(--app-line); overflow: hidden; }
.builder-progressbar__fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, var(--app-accent), var(--app-primary)); transition: width 0.3s ease; }
/* Percentage sits OUTSIDE the fill, in a DARK neutral — never the fill colour,
   so it can never be brown-on-brown. Its value never depends on fill width. */
.builder-progressbar__pct { justify-self: end; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em; color: var(--app-ink); }
/* High-contrast / forced-colors: keep bar, fill, and label legible with system
   colours in place of the removed backgrounds. */
@media (forced-colors: active) {
  .builder-progressbar { border-color: CanvasText; }
  .builder-progressbar__fill { forced-color-adjust: none; background: Highlight; }
  .builder-progressbar__pct, .builder-step-heading { color: CanvasText; }
}

/* Type choice cards (radiogroup). The .type-btn / .type-choices visuals load
   from /assets/styles.css; add the missing focus-visible rings (CSS gap) so
   both the individual card and the group (focusable when none is selected)
   show a clear keyboard focus indicator. */
.type-btn:focus-visible { outline: 3px solid var(--app-primary); outline-offset: 3px; }
#fSiteTypeGroup:focus-visible { outline: 3px solid var(--app-primary); outline-offset: 3px; border-radius: 20px; }

/* per-step validation highlight */
.builder__form .is-invalid { border-color: var(--app-danger) !important; box-shadow: 0 0 0 3px rgba(163, 66, 58, 0.15); }

/* navigation row (Back / Continue) — always reachable in normal flow */
.builder__nav { display: flex; justify-content: space-between; gap: 0.6rem; margin-top: 1rem; }

/* review summary */
.builder-review { list-style: none; margin: 0.5rem 0 0.8rem; padding: 0; display: grid; gap: 0.4rem; }
.builder-review li { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--app-line); padding-bottom: 0.35rem; }
.builder-review .k { color: var(--app-muted); font-weight: 600; font-size: 0.85rem; }
.builder-review .v { font-weight: 700; text-align: right; }

@media (prefers-reduced-motion: reduce) {
  .builder-step.is-active { animation: none; }
  .builder-progressbar__fill { transition: none; }
}
.chapters-editor { display: grid; gap: 0.8rem; margin: 0.8rem 0; }
.chapter-card { border: 1px solid var(--app-line); border-radius: 12px; padding: 0.8rem; }
.chapter-card__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.media-field { border: 1px solid var(--app-line); border-radius: 12px; padding: 0.6rem 0.8rem; margin: 0.6rem 0; }
.media-field legend { font-weight: 700; font-size: 0.85rem; padding: 0 0.3rem; }
.media-strip { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.media-chip { display: inline-flex; align-items: center; gap: 0.3rem; background: #eee4da; border-radius: 999px; padding: 0.2rem 0.6rem; font-size: 0.78rem; }
.media-chip__rm { border: 0; background: transparent; cursor: pointer; font-size: 1rem; line-height: 1; }
.builder__save { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.8rem; }
.save-progress { color: var(--app-muted); font-size: 0.85rem; }

/* viewer modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: grid; place-items: center; z-index: 20; padding: 1rem; }
.modal__card { position: relative; background: #fff; border-radius: 16px; width: min(1000px, 96vw); }
.modal__card--viewer { height: min(88svh, 900px); overflow: hidden; display: flex; flex-direction: column; }
.modal__card--viewer iframe { width: 100%; flex: 1 1 auto; min-height: 0; border: 0; }
/* Actions sit on the LEFT, clear of the absolutely-positioned top-right close
   button; the status text fills the remaining width (harmless if it sits under
   the close button since it is non-interactive). */
.viewer-controls { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.7rem 3rem 0.7rem 1rem; border-bottom: 1px solid var(--app-line); }
.viewer-pub-status { margin-left: auto; color: var(--app-muted); font-size: 0.85rem; font-weight: 600; }
.viewer-controls__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
/* The site-wide `.modal__card button` rule (styles.css) turns every button in a
   modal card into an absolutely-positioned 34px circle for the close ×. Undo
   that ONLY for the viewer control buttons so they render as normal pills. */
.viewer-controls .btn { position: static; width: auto; height: auto; right: auto; top: auto; border-radius: 999px; padding: 0.42rem 0.85rem; font-size: 0.82rem; font-weight: 700; }
.viewer-controls .btn--primary { background: var(--app-primary); color: #fff; }
.viewer-controls .btn--ghost { background: transparent; }
.viewer-controls .btn--danger-ghost { background: transparent; color: var(--app-danger); }
.viewer-controls__actions .btn { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.modal__close { position: absolute; top: 0.4rem; right: 0.6rem; z-index: 2; border: 0; background: rgba(0,0,0,0.5); color: #fff; width: 34px; height: 34px; border-radius: 50%; font-size: 1.3rem; cursor: pointer; }

/* toasts */
.toast-host { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); display: grid; gap: 0.4rem; z-index: 40; }
.toast { background: var(--app-ink); color: #fff; padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.86rem; opacity: 1; transition: opacity 0.4s, transform 0.4s; }
.toast--out { opacity: 0; transform: translateY(8px); }

@media (max-width: 860px) {
  .builder { grid-template-columns: 1fr; }
  .builder__preview { position: relative; top: 0; height: 46svh; }
}

/* Mobile header: drop the long email + brand wordmark so the logo + Account +
   Sign out fit on one row without overflowing (keeps the Account link reachable
   and the page free of horizontal overflow on small screens). */
@media (max-width: 560px) {
  .session-email { display: none; }
  .brand__text { display: none; }
  .app-header { gap: 0.5rem; padding: 0.7rem 0.8rem; }
  .app-header__actions { gap: 0.4rem; }
}

/* UX8 fine-tune colors: active-override badge, reset action, and the
   non-blocking contrast advisory (a polite live region — present at all
   times, so :empty hides it visually without removing it from the DOM). */
.color-custom-badge {
  margin-left: 0.45rem; font-size: 0.68rem; font-weight: 800;
  letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--app-primary); background: rgba(185, 137, 128, 0.16);
  border-radius: 999px; padding: 0.12rem 0.5rem; vertical-align: middle;
}
.color-reset { margin: 0.1rem 0 0.4rem; font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.form-hint--warn { color: #8a4f1d; font-weight: 700; }
.form-hint--warn:empty { display: none; }
