:root {
  --bg: #F1F4F1;
  --ink: #22312B;
  --ink-soft: #5B6B63;
  --brand: #2F5D50;
  --brand-dark: #21433A;
  --accent: #D9A441;
  --accent-dark: #B8842E;
  --surface: #FFFFFF;
  --border: #DDE4DE;
  --error: #B33A3A;
  --brand-tint: #EAF1EE;
  --on-brand: #FFFFFF;
  --accent-tint: #FBF2E1;
  --radius: 14px;
  --font-display: "Fraunces", serif;
  --font-body: "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over any display rule set by a
   class on the same element (e.g. flex containers toggled via JS) */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 440px;
  height: min(760px, calc(100dvh - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 26px 16px;
}

/* Single scrollable region between the fixed header and fixed bottom bar */
.step-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 26px 20px;
}

.step {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.lang-search-wrap {
  position: relative;
}

/* Bottom action bar stays pinned per step, never scrolls with content */
.bottom-bar {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 14px 26px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
}

/* A lone action button (e.g. Continue) fills the full width;
   the publish-row below overrides this for its own two buttons */
.bottom-bar-content > .btn {
  width: 100%;
}

.back-arrow {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  margin-left: -6px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.back-arrow:hover {
  background: var(--bg);
  color: var(--brand-dark);
}

.brand {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--brand-dark);
}

.progress {
  display: flex;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.25s ease;
}

.dot.active {
  background: var(--accent);
}

.dot.done {
  background: var(--brand);
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 0 0 6px;
  color: var(--ink);
}

.sub {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

.optional {
  color: var(--ink-soft);
  font-weight: 400;
  font-size: 0.85em;
}

/* Language search dropdown */
.lang-search-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease;
}

.lang-search-input:focus {
  border-color: var(--brand);
}

.lang-options {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(34, 49, 43, 0.14);
  z-index: 20;
}

.lang-option-item {
  padding: 13px 14px;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
}

.lang-option-item + .lang-option-item {
  border-top: 1px solid var(--border);
}

.lang-option-item:hover {
  background: var(--brand-tint);
  color: var(--brand-dark);
}

.lang-no-results {
  padding: 13px 14px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

input, textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  padding: 12px 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease;
  resize: vertical;
}

input:focus, textarea:focus {
  border-color: var(--brand);
}

textarea {
  min-height: 130px;
  line-height: 1.5;
}

/* Star rating */
.rating-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rating-label {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.stars {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.star {
  background: none;
  border: none;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--border);
  cursor: pointer;
  padding: 4px;
  flex: 1;
  text-align: center;
  transition: color 0.15s ease, transform 0.05s ease;
}

.star:active {
  transform: scale(0.92);
}

.star.filled {
  color: var(--accent);
}

.rating-error {
  color: var(--error);
  font-size: 0.85rem;
  margin: 0;
}

/* AI review draft cards */
.step[data-step="3"] .drafts-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.carousel {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.carousel-viewport {
  flex: 1;
  overflow: hidden;
  display: flex;
  /* Declared explicitly here too, not just on .carousel-track below — this
     is the element the pointerdown listener is attached to, and touch-action
     is supposed to compose up the ancestor chain from whatever the finger
     actually lands on, but real mobile browsers (iOS Safari in particular)
     have a documented history of inconsistent composition specifically for
     nested scrollable descendants (.draft-card below has its own
     overflow-y). Declaring pan-y at every level removes the dependency on
     that composition being bulletproof everywhere. */
  touch-action: pan-y;
}

.carousel-track {
  display: flex;
  width: 100%;
  touch-action: pan-y;
  cursor: grab;
  /* Disabled via inline style during an active drag so finger-tracking
     stays 1:1 with zero lag; re-enabled (falls back to this rule) for the
     snap/loop animation after release. */
  transition: transform 0.28s ease-out;
}

.carousel-track:active {
  cursor: grabbing;
}

.draft-card {
  position: relative;
  flex: 0 0 100%;
  box-sizing: border-box;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow-y: auto;
  /* This is what the finger actually touches, and it's independently
     scrollable (overflow-y above) — see the .carousel-viewport comment. */
  touch-action: pan-y;
  /* iOS Safari's native long-press text-selection/callout gesture can
     intercept a touch-drag over text even with user-select: none alone;
     these close that gap. touch-callout has no Chromium equivalent to
     verify here — included per documented WebKit behavior. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.draft-card-text {
  text-align: left;
  padding: 14px 40px 14px 16px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.draft-card-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.draft-card-copy-btn:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.draft-card-copy-btn .icon-check {
  display: none;
}

.draft-card-copy-btn.copied .icon-copy {
  display: none;
}

.draft-card-copy-btn.copied .icon-check {
  display: block;
  color: var(--brand);
}

.carousel-arrow {
  flex: 0 0 auto;
  background: none;
  border: none;
  font-size: 1.9rem;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 2px;
}

.carousel-arrow:hover {
  color: var(--brand);
}

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
}

.carousel-dot {
  width: 7px;
  height: 7px;
  border-radius: 4px;
  border: none;
  background: var(--border);
  padding: 0;
  cursor: pointer;
  transition: width 0.2s ease, background 0.2s ease;
}

.carousel-dot.active {
  width: 18px;
  background: var(--accent);
}

.select-error {
  color: var(--error);
  font-size: 0.85rem;
  margin: 0;
}

.drafts-status {
  flex: 1;
  display: flex;
}

.drafts-retry {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--error);
  padding: 8px 0;
}

.drafts-retry button {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-family: var(--font-body);
  color: var(--brand-dark);
  cursor: pointer;
}

.drafts-retry button:hover {
  border-color: var(--brand);
}

.drafts-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  padding: 4px 0;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Publish + Copy link split row */
.publish-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn.btn-publish {
  flex: 1;
}

.btn.btn-copylink {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Shown proactively (before any submit attempt) when the business hasn't
   set a Google Place ID yet — see loadConfig()'s placeConfigured check in
   app.js. Uses the accent (gold) tokens rather than --error, since this
   isn't something the customer did wrong. */
.notice {
  background: var(--accent-tint);
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 12px;
}

.inline-success {
  background: var(--brand-tint);
  border: 1px solid var(--brand);
  color: var(--brand-dark);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 4px;
}

/* Buttons */
.btn {
  flex: 1;
  padding: 13px 16px;
  border-radius: 10px;
  border: none;
  font-family: var(--font-body);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--ink-soft);
}

.error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 12px;
}

.footer-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 16px;
}

/* Thank-you popup */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(34, 49, 43, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  z-index: 100;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 28px 26px calc(26px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  box-shadow: 0 -10px 32px rgba(34, 49, 43, 0.18);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg);
  color: var(--ink-soft);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover {
  background: var(--border);
  color: var(--ink);
}

.modal-card h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
  color: var(--ink);
  margin: 4px 0 8px;
}

.modal-sub {
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 22px;
}

.social-row {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.social-icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  transition: background 0.15s ease, transform 0.05s ease;
}

.social-icon:hover {
  background: var(--brand-dark);
}

.social-icon:active {
  transform: scale(0.95);
}

/* Bottom-sheet on small screens, centered card on larger ones */
@media (min-width: 480px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }

  .modal-card {
    border-radius: var(--radius);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
