/* Buyer pages. Mobile-first (360px up). Content mirrors the legacy site; brand colors and
   font come only from /tenant.css custom properties, everything else is neutral.
   Design: a brand-colored hero band with a quiet "route" motif, a lifted form card, parcel
   cards with a progress route, and a receipt-style payment summary. */

:root {
  /* Tenant-provided (fallbacks) */
  --color-primary: #222222;
  --color-on-primary: #ffffff;
  --color-secondary: #0a7902;
  --color-on-secondary: #ffffff;
  --font-family: system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Neutral system */
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --canvas: #f4f5f7;
  --surface: #ffffff;
  --surface-sunken: #f8f9fb;
  --ink: #121417;
  --ink-muted: #525a66;
  --ink-soft: #6b7280;
  --line: #e3e6ea;
  --line-strong: #a3a9b3;
  --danger: #b42318;
  --danger-bg: #fff4f2;
  --success: #067647;

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(18, 20, 23, 0.04), 0 12px 32px -12px rgba(18, 20, 23, 0.18);
  --shadow-lift: 0 2px 4px rgba(18, 20, 23, 0.05), 0 28px 56px -24px rgba(18, 20, 23, 0.32);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 5px var(--ink);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --page-max: 880px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--ink);
  font: 400 1rem/1.6 var(--font-family);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--ink);
  text-decoration-color: color-mix(in srgb, var(--color-secondary) 70%, transparent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-color: var(--color-secondary);
}

:focus-visible {
  /* Transparent outline stays visible in forced-colors mode, where box-shadow is dropped. */
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
  border-radius: 6px;
}

#result:focus-visible {
  box-shadow: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  top: 12px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

/* ---------- Hero band ---------- */

.hero {
  position: relative;
  overflow: hidden;
  color: var(--color-on-primary);
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--color-on-primary) 14%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    linear-gradient(160deg, color-mix(in srgb, var(--color-on-primary) 6%, var(--color-primary)) 0%, var(--color-primary) 55%);
  background-color: var(--color-primary);
}

.hero::after {
  /* Soft fade of the dot grid towards the content. */
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 60%;
  background: linear-gradient(to bottom, transparent, var(--color-primary));
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 48px 20px 104px;
}

.page-title {
  margin: 0;
  font-size: clamp(2rem, 1.4rem + 3vw, 3rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

/* The journey motif: four stops on a dashed route, drawn slowly. */
.hero-route {
  display: none; /* phones: the title needs the width */
  position: absolute;
  top: 36px;
  right: 24px;
  width: 300px;
  height: auto;
  color: var(--color-on-primary);
  opacity: 0.32;
  pointer-events: none;
}

.hero-route-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 2 10;
  animation: route-flow 2.6s linear infinite;
}

.hero-route circle {
  fill: var(--color-primary);
  stroke: currentColor;
  stroke-width: 2.5;
}

.hero-route .hero-route-end {
  fill: currentColor;
}

@keyframes route-flow {
  to {
    stroke-dashoffset: -24;
  }
}

/* ---------- Page body ---------- */

.page-body {
  position: relative;
  z-index: 2;
  max-width: var(--page-max);
  margin: -72px auto 0;
  padding: 0 16px 64px;
}

.card {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.form-card {
  padding: 24px 20px;
  box-shadow: var(--shadow-lift);
  animation: rise 420ms var(--ease-out) both;
}

/* ---------- Forms ---------- */

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.field-row {
  display: grid;
  gap: 0 20px;
}

i.required,
.text-danger {
  color: var(--danger);
}

i.required {
  font-weight: 400;
}

.input {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.0625rem; /* >16px: no zoom on iOS */
  transition: border-color 150ms, box-shadow 150ms, background-color 150ms;
}

textarea.input {
  min-height: 148px;
  resize: vertical;
}

.input::placeholder {
  color: #9097a1;
}

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

.input:focus-visible {
  border-color: var(--ink);
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Legacy behaviour: invalid fields are highlighted (no inline text). */
.input[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.guide-link {
  margin: 2px 0 22px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.form-actions .btn {
  flex: 1 1 auto; /* phones: buttons share the row evenly */
}

.required-note {
  color: var(--danger);
}

.captcha {
  margin: 0 0 20px;
  min-height: 65px;
}

/* Support details under the contact form. */
.contact-info {
  margin-top: 24px;
  padding: 18px 18px 14px;
  border-radius: var(--radius);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  line-height: 2;
}

.contact-info p,
.contact-info ul {
  margin: 0;
}

.contact-info p {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  column-gap: 8px;
}

.contact-info p .icon {
  color: var(--ink-soft);
}

.contact-info p a,
.contact-info p br + * {
  overflow-wrap: anywhere;
}

.contact-info p br {
  display: none;
}

.contact-info ul {
  margin-left: 28px;
  padding-left: 1.1rem;
  color: var(--ink-muted);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 24px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms var(--ease-out), box-shadow 150ms, filter 150ms, background-color 150ms;
}

.btn:active {
  transform: translateY(1px) scale(0.985);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 8px 18px -10px color-mix(in srgb, var(--color-primary) 80%, black);
}

.btn-primary:hover {
  filter: brightness(1.08) saturate(1.05);
}

.btn-outline {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--ink) 22%, transparent);
  color: var(--ink);
}

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

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

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.8;
}

.btn[aria-busy="true"]::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 700ms linear infinite;
}

.link-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--color-secondary) 70%, transparent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  cursor: pointer;
}

.link-button:hover {
  color: var(--ink);
}

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

/* ---------- Result ---------- */

#result {
  margin-top: 40px;
}

.block-info {
  margin-bottom: 36px;
}

.block-title {
  margin: 0 0 16px;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.block-title [data-field="order"] {
  font-family: var(--font-mono);
  font-size: 0.92em;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

/* One ordered item with its shipping progress. */
.parcel {
  position: relative;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 14px;
  overflow: hidden;
  animation: rise 380ms var(--ease-out) both;
}

.parcel::before {
  /* Brand accent rail on the leading edge. */
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--color-secondary);
  opacity: 0.9;
}

.parcel:nth-child(2) { animation-delay: 60ms; }
.parcel:nth-child(3) { animation-delay: 120ms; }
.parcel:nth-child(n + 4) { animation-delay: 180ms; }

.parcel-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 16px;
  align-items: start;
}

.parcel-item.no-image {
  grid-template-columns: 1fr;
}

.parcel-image {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-sunken);
}

.parcel-name {
  margin: 0 0 6px;
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.parcel-name a {
  text-decoration-color: color-mix(in srgb, var(--ink) 25%, transparent);
}

.parcel-meta {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  font-size: 0.9375rem;
}

.parcel-meta dt {
  font-weight: 600;
  color: var(--ink-muted);
}

.parcel-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.tracking {
  margin-top: 14px;
}

.tracking-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Waybill-style tracking number. */
.tracking-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px dashed color-mix(in srgb, var(--ink) 30%, transparent);
  border-radius: 8px;
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.tracking-chip:hover {
  border-style: solid;
  border-color: var(--ink);
}

.tracking-note {
  margin-top: 8px;
  font-size: 0.9375rem;
  color: var(--danger);
}

/* Shipping progress: vertical on phones, horizontal from 640px. */
.route {
  list-style: none;
  margin: 22px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--line);
}

.route-stop {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr;
  column-gap: 12px;
  padding-bottom: 16px;
}

.route-stop:last-child {
  padding-bottom: 0;
}

.route-stop::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 32px;
  bottom: 2px;
  width: 2px;
  border-radius: 2px;
  background: var(--line);
}

.route-stop:last-child::before {
  display: none;
}

.route-stop.is-linked::before {
  background: var(--color-secondary);
}

.route-marker {
  position: relative;
  z-index: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--color-on-secondary);
}

.is-done .route-marker {
  border-color: var(--color-secondary);
  background: var(--color-secondary);
}

.is-done .route-marker::after {
  content: "";
  width: 15px;
  height: 15px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.2 11.6 2.6 8l1.1-1.1 2.5 2.5 6.1-6.1 1.1 1.1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.2 11.6 2.6 8l1.1-1.1 2.5 2.5 6.1-6.1 1.1 1.1z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* The current step breathes; everything else is still. */
.is-current .route-marker::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--color-secondary);
  opacity: 0;
  animation: pulse 2.2s var(--ease-out) infinite;
}

@keyframes pulse {
  0% {
    opacity: 0.55;
    transform: scale(0.85);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

.route-title {
  font-weight: 700;
  line-height: 30px;
  text-transform: uppercase;
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
}

.route-stop:not(.is-done) .route-title {
  color: var(--ink-soft);
  font-weight: 600;
}

.route-date {
  grid-column: 2;
  font-size: 0.875rem;
  color: var(--ink-muted);
}

/* Payment: a receipt with a torn-edge divider before the total. */
.receipt {
  position: relative;
  margin-top: 20px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.summary {
  width: 100%;
  border-collapse: collapse;
}

.summary td,
.summary th {
  padding: 7px 0;
  text-align: left;
  font-weight: 400;
}

.summary td:first-child {
  color: var(--ink-muted);
}

.summary td:last-child,
.summary th:last-child {
  text-align: right;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.summary tfoot th {
  position: relative;
  padding-top: 20px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.summary tfoot tr {
  background:
    linear-gradient(to right, var(--line-strong) 50%, transparent 0) 0 6px / 10px 1.5px repeat-x;
}

.receipt::before,
.receipt::after {
  /* Notches where the paper would be torn. */
  content: "";
  position: absolute;
  bottom: 62px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--canvas);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.receipt::before {
  left: -10px;
  clip-path: inset(0 0 0 50%);
}

.receipt::after {
  right: -10px;
  clip-path: inset(0 50% 0 0);
}

.customer-grid {
  display: grid;
  gap: 12px;
}

.info-tile {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius);
}

.info-tile .icon {
  margin-bottom: 8px;
  color: var(--color-secondary);
}

.info-tile h3 {
  margin: 0 0 6px;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.info-tile div {
  overflow-wrap: anywhere;
}

/* ---------- Dialogs (legacy modals / alerts) ---------- */

.dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 28px 24px 24px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 32px 80px -24px rgba(18, 20, 23, 0.5);
}

.dialog::backdrop {
  background: rgba(18, 20, 23, 0.55);
  backdrop-filter: blur(2px);
}

.dialog[open] {
  animation: pop 240ms var(--ease-out);
}

.dialog-head {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.dialog-alert {
  text-align: center;
}

.dialog-alert h2 {
  margin-bottom: 8px;
  font-size: 1.375rem;
  letter-spacing: 0.04em;
}

.dialog-alert p {
  color: var(--ink-muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.dialog-alert .dialog-actions {
  justify-content: center;
}

.dialog-actions .btn {
  min-width: 120px;
}

.guide-body {
  display: grid;
  gap: 4px;
  text-align: center;
}

.guide-body img {
  width: 168px;
  height: auto;
  margin: 0 auto 6px;
}

.guide-body p {
  margin: 0 0 14px;
  color: var(--ink-muted);
}

.alert-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  position: relative;
}

.alert-icon-error {
  background: var(--danger-bg);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger-bg) 60%, transparent);
}

.alert-icon-error::before,
.alert-icon-error::after {
  content: "";
  position: absolute;
  top: 30px;
  left: 20px;
  width: 24px;
  height: 3px;
  border-radius: 2px;
  background: var(--danger);
  transform: rotate(45deg);
}

.alert-icon-error::after {
  transform: rotate(-45deg);
}

.alert-icon-success {
  background: #ecfdf3;
  box-shadow: 0 0 0 6px rgba(236, 253, 243, 0.6);
}

.alert-icon-success::after {
  content: "";
  position: absolute;
  left: 25px;
  top: 16px;
  width: 13px;
  height: 25px;
  border: solid var(--success);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

#sent-dialog p {
  margin: 0 0 12px;
  color: var(--ink-muted);
}

#sent-dialog p:first-of-type {
  color: var(--ink);
  text-align: center;
}

.strong {
  font-weight: 700;
  color: var(--ink);
}

.brand-team {
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
}

/* ---------- Motion ---------- */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* ---------- Larger screens ---------- */

@media (min-width: 640px) {
  .hero-inner {
    padding: 72px 24px 128px;
  }

  .hero-route {
    display: block;
    top: 44px;
    width: 340px;
  }

  .form-actions .btn {
    flex: 0 0 auto;
  }

  .page-body {
    margin-top: -88px;
    padding: 0 24px 88px;
  }

  .form-card {
    padding: 32px;
  }

  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  .parcel {
    padding: 24px 24px 22px 28px;
  }

  .parcel-item {
    grid-template-columns: 112px 1fr;
    gap: 22px;
  }

  .parcel-image {
    width: 112px;
    height: 112px;
  }

  .route {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .route-stop {
    grid-template-columns: 1fr;
    row-gap: 8px;
    padding-bottom: 0;
  }

  .route-stop::before {
    left: 36px;
    right: 4px;
    top: 14px;
    bottom: auto;
    width: auto;
    height: 2px;
  }

  .route-title {
    line-height: 1.3;
  }

  .route-date {
    grid-column: 1;
  }

  .receipt {
    width: min(100%, 420px);
    margin-left: auto;
  }

  .customer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
}

@media (min-width: 960px) {
  .page-title {
    max-width: 60%;
  }
}
