/* Vanilla CSS with custom-properties for per-branch branding. The portal sets
   --primary from the GET /portal/session response. Visual tone is "warm
   adventure-travel" — Inter for typography, generous radii, soft shadows,
   a full-bleed branded hero up top, and a sticky checkout bar at the foot
   so the CTA is always reachable while the customer scrolls add-ons. */

:root {
  --primary: #2563eb;
  /* Derived shades — recomputed at apply-branding time would be nicer, but
     CSS color-mix gives us decent fallbacks without JS. */
  --primary-soft: color-mix(in srgb, var(--primary) 12%, white);
  --primary-edge: color-mix(in srgb, var(--primary) 60%, black);
  --ink: #0f172a;
  --ink-2: #475569;
  --line: #e5e7eb;
  --bg: #fafaf7;
  --bg-warm: #f5f1ea;
  --bg-card: #ffffff;
  --danger: #c83f4d;
  --warning: #b8860b;
  --success: #4caf85;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.02);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-warm) 100%);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1 { margin: 0 0 8px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.muted { color: var(--ink-2); font-size: 14px; }
.hidden { display: none !important; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

/* ─── Hero block ─────────────────────────────────────────────────────────────
   Branded full-width image with the operator's logo/name on top and a big
   "Choose your adventure" greeting at the foot. When the branch hasn't set
   an addon_portal_hero_url, the image is display:none and the gradient
   fallback (primary → primary-edge) carries the visual weight. */
.hero-block {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  margin: 20px 0 24px;
  min-height: 360px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-edge) 100%);
  box-shadow: var(--shadow-md);
}
.brand-hero {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.brand-hero[src=""] { display: none; }
.hero-gradient {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.05) 0%, rgba(15, 23, 42, 0.65) 100%);
}
.hero-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-height: 360px;
  padding: 22px 26px 28px;
  color: white;
}
.hero-text {
  display: flex; flex-direction: column; gap: 6px;
  max-width: 520px;
}
.hero-title {
  margin: 0;
  font-size: 36px; font-weight: 800; letter-spacing: -0.02em;
  line-height: 1.1; color: white;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.hero-title-accent { color: var(--primary-soft); }
.hero-sub {
  margin: 0;
  font-size: 16px; font-weight: 400; color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.30);
}
.hero-sub #customerNameSpan { font-weight: 600; }

/* Brand header base layout — shared by the picker (inside hero-block, white
   on dark) and the confirmation page (standalone, dark on light). */
.brand-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 0 20px;
}
.brand-header img {
  max-height: 60px; max-width: 180px; object-fit: contain;
  flex: 0 0 auto;
}
.brand-header img[src=""] { display: none; }
.brand-header-text {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.brand-header-text strong {
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.brand-header-text .muted {
  font-size: 15px; color: var(--ink); font-weight: 600;
}

/* Hero overlay variant — white on the gradient/image, logo gets a soft
   white chip so it stays legible over any photograph. */
.hero-block .brand-header { padding: 0; }
.hero-block .brand-header img {
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 10px;
  border-radius: 8px;
}
.hero-block .brand-header-text strong { color: rgba(255, 255, 255, 0.85); }
.hero-block .brand-header-text .muted { color: white; }

@media (max-width: 560px) {
  main { padding: 0 12px 24px; }
  .hero-block { min-height: 300px; margin: 12px 0 20px; border-radius: 16px; }
  .hero-content { min-height: 300px; padding: 18px 20px 22px; gap: 18px; }
  .hero-title { font-size: 28px; }
  .hero-sub { font-size: 14px; }
  .brand-header img { max-height: 48px; max-width: 140px; padding: 5px 8px; }
  .brand-header-text strong { font-size: 11px; }
  .brand-header-text .muted { font-size: 13px; }
}

/* ─── Buttons ────────────────────────────────────────────────────────────────
   Bolder, chunkier — these are the only places we use the primary color
   as fill, so they need to pop. */
.btn-primary, .btn-secondary {
  font: inherit; font-weight: 600;
  cursor: pointer; padding: 12px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-primary {
  background: var(--primary); color: white; border-color: var(--primary);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-edge);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 45%, transparent);
}
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-secondary {
  background: white; color: var(--ink); border-color: var(--line);
}
.btn-secondary:hover { background: var(--bg-warm); border-color: var(--ink-2); }

.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ─── Addon tiles ────────────────────────────────────────────────────────────
   Image-forward: bigger thumb, hover lift, primary-color left accent stripe
   on selected tiles. Required-details section opens with subtle highlight. */
.addon-tile {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  background: white;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}
/* ─── Loading-dots animation ────────────────────────────────────────────────
   Three trailing dots that bounce in sequence, giving the loading heading
   ("Finding your booking…") a live, "still working" feel without spinning
   up a heavyweight spinner asset.

   Earlier attempt used animation shorthand + per-child animation-delay
   override; the stagger didn't reliably take in some browsers. This pass
   uses the FULL animation shorthand per child (including the delay slot)
   so the value can't get clobbered by cascade quirks. */
.loading-dots {
  display: inline-block;
  margin-left: 4px;
  letter-spacing: 1px;
}
.loading-dots > span {
  display: inline-block;
  font-weight: 800;
}
.loading-dots > span:nth-child(1) {
  animation: loading-dot-bounce 1.4s ease-in-out 0s infinite;
}
.loading-dots > span:nth-child(2) {
  animation: loading-dot-bounce 1.4s ease-in-out 0.18s infinite;
}
.loading-dots > span:nth-child(3) {
  animation: loading-dot-bounce 1.4s ease-in-out 0.36s infinite;
}
@keyframes loading-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  /* Respect user motion preference — show static dots instead of bouncing. */
  .loading-dots > span { transform: none; opacity: 1; animation: none; }
}

/* ─── View controls (toggle + filters) ──────────────────────────────────────
   Flex row above the addonList. Toggle pill on the left, calendar filters
   on the right. On mobile they wrap to stack. */
.view-controls {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 14px;
}

/* ─── View toggle (Calendar / Add-ons only) ─────────────────────────────────
   Segmented pill. Calendar is the default. The choice persists in
   localStorage. */
.view-toggle {
  display: inline-flex;
  gap: 0;
  padding: 4px;
  background: var(--bg-warm);
  border-radius: 999px;
  border: 1px solid var(--line);
}

/* Calendar-only category filters (Hide Accommodation / Hide Tours & Activities).
   Hidden when the view mode is "addons" since the filters target base
   items, which aren't shown in that view. */
.calendar-filters {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 14px;
  margin-left: auto;
}
.calendar-filters.hidden { display: none; }
.calendar-filter {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  cursor: pointer; user-select: none;
}
.calendar-filter input[type="checkbox"] { cursor: pointer; }
.calendar-filter:hover { color: var(--ink); }
@media (max-width: 480px) {
  .view-controls { gap: 10px; }
  .calendar-filters { margin-left: 0; width: 100%; }
  .calendar-filter { font-size: 12px; }
}
.view-toggle-btn {
  font: inherit; font-weight: 600; font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.view-toggle-btn:hover { color: var(--ink); }
.view-toggle-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.view-toggle-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

/* ─── Calendar view ────────────────────────────────────────────────────────
   Vertical day-by-day stack. Each day card shows base tour items as muted
   "Included" pills (no checkbox) and any bookable addons as the existing
   tile + checkbox + custom-fields markup. Days with neither render a
   "Free day" placeholder so trip rhythm reads through. Same layout at
   every breakpoint — no horizontal scroll, no separate sidebar. */
.calendar-day-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.calendar-day-head {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.calendar-day-head strong {
  font-size: 16px; font-weight: 700; color: var(--navy, var(--ink));
  letter-spacing: -0.01em;
}
.calendar-day-head .muted { font-size: 14px; }
.calendar-base-list {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: grid; gap: 8px;
}
.calendar-base-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--bg-warm);
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.calendar-base-included {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, white);
  padding: 4px 9px; border-radius: 999px;
}
.calendar-base-body { flex: 1; min-width: 0; }
.calendar-base-name { font-weight: 600; font-size: 14px; color: var(--ink); }
.calendar-base-meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
/* Right-side product-class icon — same four icons the agent side uses
   (accom / activity / tour / transport) so the visual language is
   consistent. Filter logic still keys off data-base-category on the
   parent <li>; the icon is just the at-a-glance cue. */
.calendar-base-icon {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  object-fit: contain;
  opacity: 0.85;
}
.calendar-base-icon--placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); font-size: 18px;
  background: var(--bg-warm);
  border-radius: 50%;
}
@media (max-width: 480px) {
  .calendar-base-icon { width: 24px; height: 24px; }
}

.calendar-day-addons { display: block; }
.calendar-day-addons-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-2);
  margin: 0 0 8px;
}
.calendar-free-day { margin: 0; font-style: italic; font-size: 14px; }

@media (max-width: 480px) {
  .calendar-day-card { padding: 14px; }
  .calendar-day-head strong { font-size: 15px; }
  .calendar-day-head .muted { font-size: 13px; }
  .calendar-base-item { padding: 9px 10px; gap: 10px; }
  .calendar-base-included { font-size: 10px; padding: 3px 7px; }
  .calendar-base-name { font-size: 13px; }
}

.addon-tile::before {
  content: ""; position: absolute; inset: 0 auto 0 0;
  width: 4px; background: var(--primary);
  transform: scaleY(0); transform-origin: center;
  transition: transform 0.18s ease;
}
.addon-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.addon-tile.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 4%, white);
  box-shadow: var(--shadow-md);
}
.addon-tile.selected::before { transform: scaleY(1); }
.addon-tile.unavailable { opacity: 0.55; }
.addon-tile.unavailable:hover { transform: none; box-shadow: none; }

.addon-row {
  display: flex; align-items: center; gap: 14px;
}
.addon-row input[type="checkbox"] {
  appearance: none;
  width: 22px; height: 22px;
  border: 2px solid var(--line); border-radius: 6px;
  flex: 0 0 auto;
  cursor: pointer;
  display: grid; place-content: center;
  background: white;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.addon-row input[type="checkbox"]:hover { border-color: var(--primary); }
.addon-row input[type="checkbox"]:checked {
  background: var(--primary); border-color: var(--primary);
}
.addon-row input[type="checkbox"]:checked::after {
  content: ""; width: 6px; height: 11px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}
/* Codex caught: appearance:none above strips the native focus ring.
   Replace with an explicit one so keyboard users still get visible
   feedback while tabbing through addons. :focus-visible scopes this
   to keyboard focus only (mouse clicks don't trigger the ring). */
.addon-row input[type="checkbox"]:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent);
}
.addon-thumb {
  width: 96px; height: 76px;
  object-fit: cover;
  border-radius: 10px;
  flex: 0 0 auto;
  background: var(--line);
}
.addon-body { flex: 1; min-width: 0; }
.addon-body > div:first-child { font-size: 15px; line-height: 1.3; }
.addon-meta { color: var(--ink-2); font-size: 13px; margin-top: 4px; }
.addon-price {
  font-weight: 700; font-size: 17px;
  background: var(--bg-warm);
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .addon-tile { padding: 12px; }
  .addon-row { gap: 10px; }
  .addon-row input[type="checkbox"] { width: 24px; height: 24px; }
  .addon-thumb { width: 70px; height: 56px; }
  .addon-body > div:first-child { font-size: 14px; }
  .addon-meta { font-size: 12px; }
  .addon-price { font-size: 14px; padding: 4px 8px; }
}

/* Custom-field controls inside selected addons */
.fields { display: grid; gap: 12px; margin-top: 4px; }
.fields label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink); }
.fields input[type="text"], .fields input[type="email"], .fields input[type="tel"], .fields input[type="date"], .fields select, .fields textarea {
  font: inherit; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 8px;
  background: white;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.fields input:focus, .fields select:focus, .fields textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.fields .required-marker { color: var(--danger); }

.addon-fields-collapsible {
  margin-top: 14px; padding: 12px 14px;
  background: var(--bg-warm);
  border-radius: 10px;
}
.addon-fields-collapsible > summary {
  cursor: pointer; font-size: 13px; font-weight: 600; padding: 2px 0;
  list-style: none; user-select: none;
  display: flex; align-items: center; gap: 6px;
}
.addon-fields-collapsible > summary::-webkit-details-marker { display: none; }
.addon-fields-collapsible > summary::before {
  content: "▾"; font-size: 11px; transition: transform 0.15s;
}
.addon-fields-collapsible:not([open]) > summary::before { transform: rotate(-90deg); }
.addon-fields-collapsible .required-tag {
  margin-left: auto; font-size: 11px; color: var(--danger); font-weight: 600;
  background: white; padding: 3px 8px; border-radius: 999px;
}
.addon-fields-collapsible > .fields { margin-top: 12px; }

/* ─── Customer / Shared details panels ──────────────────────────────────────*/
.customer-head {
  display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px;
}
.customer-head strong { font-size: 16px; font-weight: 700; }
.customer-head .muted { font-size: 13px; }
.customer-fields {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
.customer-fields label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; font-weight: 500; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.customer-fields label.full { grid-column: 1 / -1; }
.customer-fields input, .customer-fields select {
  font: inherit; font-size: 15px;
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 8px;
  color: var(--ink);
  background: white;
  text-transform: none; letter-spacing: 0;
  font-weight: 400;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.customer-fields input::placeholder { color: var(--ink-2); opacity: 0.6; }
.customer-fields input:focus, .customer-fields select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.customer-fields input.has-prefill { background: var(--bg-warm); color: var(--ink-2); }
.customer-fields input.has-prefill:focus { background: white; color: var(--ink); }

@media (max-width: 480px) {
  .customer-fields { grid-template-columns: 1fr; }
}

#validationCard { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 5%, white); }
#validationCard ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }
#confirmValidationCard { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 5%, white); }
#confirmValidationCard ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }

/* ─── Sticky checkout — totals + actions pinned to bottom of viewport ───────
   Wraps the totals card and the action buttons. Sticky positioning keeps
   the CTA in view while the customer scrolls add-ons; on short screens
   the totals stays directly above the buttons. */
.sticky-checkout {
  position: sticky;
  bottom: 12px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: auto;
  margin-bottom: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 5;
}
.sticky-checkout .totals-bar,
.sticky-checkout .actions {
  background: transparent;
  border: none; box-shadow: none;
  padding: 0; margin: 0;
}
.sticky-checkout .totals-bar { margin-bottom: 10px; }

@media (max-width: 480px) {
  .sticky-checkout {
    bottom: 0;
    border-radius: 14px 14px 0 0;
    padding: 12px 14px 14px;
    margin: 0 -12px -24px;
  }
  .sticky-checkout .actions { gap: 8px; }
  .sticky-checkout .btn-primary,
  .sticky-checkout .btn-secondary {
    flex: 1; padding: 12px 16px;
  }
  .sticky-checkout .totals-bar-row strong { font-size: 22px; }
}

.totals-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.totals-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.totals-bar-label { color: var(--ink-2); font-size: 14px; font-weight: 500; }
.totals-bar-row strong { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.totals-bar-detail { font-size: 12px; }

/* Confirmation page: per-addon line items + customer details readout. */
.confirm-list {
  list-style: none; margin: 8px 0 0; padding: 0;
}
.confirm-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.confirm-list li:last-child { border-bottom: none; }
.confirm-list .confirm-line-name { font-weight: 600; }
.confirm-list .confirm-line-meta { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.confirm-list .confirm-line-amount { font-weight: 700; white-space: nowrap; }

.confirm-customer {
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px;
  margin: 8px 0 0; font-size: 14px;
}
.confirm-customer dt { color: var(--ink-2); font-weight: 500; }
.confirm-customer dd { margin: 0; }

.footer {
  margin-top: 8px; padding: 12px 4px 0;
  text-align: center;
  font-size: 13px;
}
.footer a { color: var(--primary); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

.voucher-links {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px;
}
.voucher-links .btn-primary,
.voucher-links .btn-secondary {
  text-decoration: none; display: inline-block;
}

#paymentFail { border-color: var(--danger); }
#bookingFail { border-color: var(--warning); }
