/*
 * Thailand Post parcel pre-load LINE LIFF.
 *
 * Design goals:
 *  - Audience skews 35+ and elderly: large type, generous spacing, big
 *    touch targets (>= 52px), strong contrast.
 *  - Corporate identity follows Thailand Post (postal red).
 *  - Calm, single-column, one-thing-at-a-time flow.
 */

:root {
  /* This is a light-themed app. Force native controls (select popups, date
   * pickers, form fields) to render light even when the device/webview is in
   * dark mode — otherwise their OS-drawn popups appear dark grey and floating,
   * clashing with the white UI. */
  color-scheme: light;

  /* Thailand Post corporate identity */
  --post-red: #d9261c;        /* primary brand red */
  --post-red-dark: #b01e16;   /* pressed / emphasis */
  --post-red-soft: #fdeceb;   /* tinted backgrounds, focus glow */

  --ink: #1a1a1a;             /* near-black body text, high contrast */
  --muted: #4b5563;           /* darker than usual for readability */
  --line: #d6d9dd;            /* borders */
  --bg: #f5f6f8;
  --card: #ffffff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;

  --radius: 14px;
  --radius-lg: 16px;

  /* Comfortable tap target (compact, modern proportions). */
  --tap: 44px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over component display rules (e.g. .btn uses
 * display: inline-flex), otherwise JS-hidden wizard buttons stay visible. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "Noto Sans Thai", "Sarabun", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px 56px;
  min-height: 100vh;
}

.screen--center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Top bar -------------------------------------------------------------- */
/* Pinned to the top of the viewport (mirror of .action-bar at the bottom)
 * so the title + actions stay reachable while the list/form scrolls. Uses
 * position: sticky so it keeps its place in flow — no content jump and no
 * manual padding compensation. Bleeds to the screen edges to read as an app
 * bar. Applies to every page that uses .topbar. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* Negative side margins span the .screen horizontal padding (16px). */
  margin: -14px -16px 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.97);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}

.topbar h1 { font-size: 1.2rem; margin: 0; font-weight: 800; }

.topbar__actions { display: flex; gap: 10px; align-items: center; }

/* Round, clearly tappable close ("back to list") button. */
.topbar__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  text-decoration: none;
}
.topbar__close:active { background: var(--line); }

/* Language switcher (TH/EN segmented control) ------------------------- */
.lang-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: #eceef1;
  border-radius: 999px;
}
.lang-switch form { margin: 0; display: flex; }
.lang-switch__btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
}
.lang-switch__btn--active {
  background: #fff;
  color: var(--post-red);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.brand {
  color: var(--post-red);
  font-size: 1.9rem;
  font-weight: 800;
  margin: 0 0 6px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  color: var(--post-red);
}
.brand-mark__logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--post-red);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* Cards ---------------------------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.card--center { text-align: center; }
.card--error {
  border: 2px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}
.card--error ul { margin: 0; padding-left: 20px; }
.card--error li { margin: 4px 0; }

.muted { color: var(--muted); }
.small { font-size: 0.95rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Customer address link ------------------------------------------------ */
.customer-link__result { margin-top: 12px; }

/* Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }

.btn--primary { background: var(--post-red); color: #fff; }
.btn--primary:active { background: var(--post-red-dark); }

/* "Not ready yet" state, e.g. the create-label button before the form is complete. */
.btn:disabled,
.btn[disabled] {
  background: #c9ccd1;
  color: #fff;
  cursor: not-allowed;
  opacity: 1;
}
.btn:disabled:active,
.btn[disabled]:active { transform: none; }

.btn--ghost {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
}
.btn--ghost:active { background: var(--bg); }

.btn--sm {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 0.85rem;
}
.btn--block { width: 100%; margin-top: 12px; }
.btn--danger { color: var(--danger); border-color: var(--danger); background: #fff; }

/* Fields --------------------------------------------------------------- */
.fields { display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; }

/* A labelled grouping of related fields (e.g. the box dimensions row). */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group__label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}

/* Labels: compact, bold, high contrast. */
.field__label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}
.field__label em { color: var(--post-red); font-style: normal; font-weight: 800; }

.field__hint {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.4;
}

.field__input {
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}

.field__input:focus {
  outline: none;
  border-color: var(--post-red);
  box-shadow: 0 0 0 4px var(--post-red-soft);
}

/* Height is driven by the autogrow controller; max-height is the ceiling it
   grows to before the textarea starts scrolling internally. */
textarea.field__input {
  min-height: 56px;
  max-height: 180px;
  line-height: 1.45;
  resize: vertical;
  width: 100%;
  max-width: 100%;
}

/* The paste box should stay inviting while empty, so it keeps its 5-row look. */
textarea.field__input--tall { min-height: 120px; max-height: 320px; }

.field__input--ghost { margin-top: 6px; }

.field__input--invalid {
  border-color: var(--post-red);
  background: var(--post-red-soft);
}
.field__input--invalid:focus {
  border-color: var(--post-red);
  box-shadow: 0 0 0 4px var(--post-red-soft);
}

.field__error {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--post-red-dark);
  line-height: 1.4;
}

.field__input--locked {
  background: #f1f2f4;
  color: var(--muted);
  cursor: not-allowed;
}

.field__edit {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--post-red);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 0;
  min-height: 40px;
}

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* Quick address search dropdown ------------------------------------------ */
.address-suggest { position: relative; }
.address-suggest__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 60;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 300px;
  overflow-y: auto;
}
.address-suggest__list[hidden] { display: none; }
.address-suggest__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 14px;
  cursor: pointer;
}
.address-suggest__item:hover { background: var(--post-red-soft); }
.address-suggest__name { font-weight: 700; color: var(--ink); }
.address-suggest__meta { font-size: 0.82rem; color: var(--muted); }

/* ID document (national ID / passport) -------------------------------- */
.id-document { gap: 8px; }
.field__input--id-type { font-weight: 600; }
/* .field sets display:flex, which would otherwise beat the [hidden] attribute. */
.id-document__country[hidden] { display: none; }

/* Hint banner for required fields, etc. */
.hint {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--post-red-soft);
  color: var(--post-red-dark);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 14px;
}
.hint__icon { flex: none; display: inline-flex; color: var(--post-red); }
.hint__icon svg { width: 18px; height: 18px; display: block; }

.price-estimate {
  background: var(--info-soft);
  color: var(--info);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 1.02rem;
  font-weight: 700;
  margin: 4px 0 12px;
}

/* Prominent result card on the new-parcel form (same info/blue tone). */
.price-estimate--card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}
.price-estimate__icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
}
.price-estimate__icon svg { width: 100%; height: 100%; display: block; }
.price-estimate__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.price-estimate__label { font-size: 0.84rem; font-weight: 700; }
.price-estimate__amount { font-size: 1.9rem; font-weight: 800; line-height: 1.15; }
.price-estimate__remote { font-size: 0.8rem; font-weight: 600; }
.price-estimate__note {
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0.8;
  margin-top: 2px;
}
.price-estimate--unavailable .price-estimate__amount { font-size: 1rem; font-weight: 700; }
.price-estimate--unavailable .price-estimate__label,
.price-estimate--unavailable .price-estimate__note,
.price-estimate--unavailable .price-estimate__remote { display: none; }

.more { margin-top: 4px; border-top: 1px solid var(--line); }
.more summary {
  color: var(--post-red);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 0;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after {
  content: "";
  width: 9px;
  height: 9px;
  margin-left: auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.more[open] summary::after { transform: rotate(-135deg); }
.more__body {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding-bottom: 6px;
}

/* Stepper -------------------------------------------------------------- */
.wizard-progress {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--post-red);
  margin: 0 0 8px;
}

/* Segmented two-card stepper: each step is a bordered card with a number
 * badge, an icon, and a title + subtitle. The active step is outlined red. */
.stepper {
  display: flex;
  gap: 10px;
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}

.stepper__item {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px;
  min-width: 0;
}
.stepper__item--arrow { padding-right: 38px; }
.stepper__item--middle { padding-left: 38px; padding-right: 38px; }
.stepper__item--notch { padding-left: 38px; }

/* Arrow-ribbon / notch shape drawn as a stretching SVG behind the content. */
.stepper__shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  fill: #fff;
  stroke: var(--line);
  stroke-width: 1.5;
}
.stepper__item--active .stepper__shape {
  fill: var(--post-red-soft);
  stroke: var(--post-red);
  stroke-width: 2;
}
.stepper__item--done .stepper__shape {
  fill: #fff;
  stroke: var(--success);
}
.stepper__badge,
.stepper__body { position: relative; z-index: 1; }

.stepper__badge {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #c9ccd1;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stepper__item--active .stepper__badge { background: var(--post-red); }
.stepper__item--done .stepper__badge { background: var(--success); }

.stepper__body { display: flex; flex-direction: column; min-width: 0; }
.stepper__title {
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.25;
  color: var(--muted);
}
.stepper__item--active .stepper__title { color: var(--ink); }
.stepper__sub {
  font-size: 0.78rem;
  line-height: 1.25;
  color: var(--muted);
  margin-top: 2px;
}

/* Narrow phones: tighten padding, the arrow overlap, and type so the Thai
 * titles fit without cramped multi-line wrapping. */
@media (max-width: 430px) {
  .stepper { gap: 6px; }
  .stepper__item { padding: 12px 10px; gap: 8px; }
  .stepper__item--arrow { padding-right: 24px; }
  .stepper__item--middle { padding-left: 24px; padding-right: 24px; }
  .stepper__item--notch { padding-left: 24px; }
  .stepper__badge { width: 26px; height: 26px; font-size: 0.85rem; }
  .stepper__title { font-size: 0.82rem; }
  .stepper__sub { display: none; }
}

.step__title { font-size: 1.1rem; margin: 0 0 14px; font-weight: 800; }

/* Lists ---------------------------------------------------------------- */
.screen .parcels__results { margin-top: 16px; }
.list { list-style: none; padding: 0; margin: 0; }
.list__item { margin-bottom: 14px; }
.list__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 18px;
  min-height: 76px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
  border: 1px solid transparent;
}
.list__link:active { border-color: var(--post-red); }
.list__main { display: flex; flex-direction: column; gap: 4px; }
.list__title { font-weight: 700; font-size: 1.15rem; }
.list__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

/* Badges --------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  background: var(--line);
  color: var(--ink);
}
.badge--labeled { background: var(--success-soft); color: var(--success); }
.badge--submitted { background: var(--info-soft); color: var(--info); }
.badge--draft { background: #eef0f2; color: #374151; }
.badge--dropped_off { background: #ede9fe; color: #5b21b6; }
.badge--exception { background: var(--danger-soft); color: var(--danger); }
.badge--failed { background: var(--danger-soft); color: var(--danger); }

/* Tracking timeline ---------------------------------------------------- */
.tracking-timeline__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tracking-timeline__item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
}
.tracking-timeline__dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--post-red);
  box-shadow: 0 0 0 4px var(--post-red-soft);
}
.tracking-timeline__body { min-width: 0; }
.tracking-timeline__body p { margin: 0 0 3px; }
.tracking-timeline__title { font-weight: 800; }
/* Label / QR ----------------------------------------------------------- */
.label .qr {
  width: 280px;
  height: 280px;
  max-width: 80vw;
  margin: 18px auto;
  background: #fff;
  padding: 8px;
  border-radius: 12px;
}
.label .qr svg { width: 100%; height: 100%; }
.label .qr--sm { width: 160px; height: auto; margin: 8px auto 0; cursor: pointer; }
.label .qr--sm [data-barcode-toggle-target="code"] { width: 100%; }
.label .qr--sm [data-barcode-toggle-target="code"] svg { width: 100%; height: auto; display: block; }
.label .barcode-1d {
  margin: 12px auto 0;
  max-width: 90%;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
.label .barcode-1d svg { width: 100%; height: auto; display: block; }
.barcode__caption { display: block; text-align: center; margin-top: 6px; }
.label .qr--sm .barcode__caption { margin-bottom: 24px; }
.label__barcode { margin-top: 12px; }
.label__barcode .mono { font-size: 1.4rem; letter-spacing: 2px; font-weight: 700; }

/* Flash ---------------------------------------------------------------- */
/* Flash messages are shown as a toast that floats over the top of the screen,
 * animates in, then fades out on its own (see flash_controller.js). It is
 * pinned above the sticky topbar (z-index 50) so it reads as an overlay, not
 * part of the page. */
.flash-stack {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 460px;
  /* Hidden + lifted until the controller adds .is-visible. */
  transform: translateX(-50%) translateY(-16px);
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}
.flash-stack.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.flash {
  margin: 0;
  padding: 13px 18px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 1.02rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  pointer-events: auto;
}
.flash--notice { background: var(--success-soft); color: var(--success); }
.flash--alert { background: var(--danger-soft); color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .flash-stack { transition: opacity 0.2s ease; transform: translateX(-50%); }
}

/* Spinner -------------------------------------------------------------- */
.spinner {
  width: 44px;
  height: 44px;
  margin: 18px auto;
  border: 4px solid var(--line);
  border-top-color: var(--post-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status { font-size: 1.1rem; margin: 4px 0 0; }

/* Address book --------------------------------------------------------- */
.address-group { margin-top: 26px; }
.address-group__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.address-group__title { font-size: 1.2rem; margin: 0; font-weight: 800; }

/* Search box ----------------------------------------------------------- */
.address-search {
  position: relative;
  margin: 4px 0 18px;
}
.address-search__icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  opacity: 0.6;
  pointer-events: none;
}
.address-search__input {
  width: 100%;
  min-height: var(--tap);
  padding: 13px 16px 13px 46px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 1.05rem;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}
.address-search__input:focus {
  outline: none;
  border-color: var(--post-red);
  box-shadow: 0 0 0 4px var(--post-red-soft);
}
.address-search__input::-webkit-search-cancel-button { cursor: pointer; }

/* Tabs ----------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  background: #eceef1;
  border-radius: 999px;
}
.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab--active {
  background: #fff;
  color: var(--post-red);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.tab__count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  color: inherit;
  font-size: 0.75rem;
  font-weight: 700;
}
.tab--active .tab__count { background: var(--post-red-soft); color: var(--post-red); }

/* Panels --------------------------------------------------------------- */
.address-panel__head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}
.address-panel__empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 8px;
  margin: 0;
}

/* Address card --------------------------------------------------------- */
.address-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
  border: 1px solid transparent;
}
.address-card__body { display: flex; flex-direction: column; gap: 4px; }
.address-card__head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.address-card__label { font-weight: 800; font-size: 1.15rem; }
.address-card__line { margin: 0; }

.address-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
/* Default toggle grows to fill the row; edit/delete are compact icon buttons. */
.address-card__default { flex: 1 1 auto; }
.address-card__secondary { display: flex; gap: 10px; flex: 0 0 auto; }

/* Edit / delete: equal-weight round icon buttons, tinted by intent
 * (edit = neutral grey, delete = postal danger red). */
.address-card__icon-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border-width: 1.5px;
  border-color: var(--line);
  color: var(--muted);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.address-card__icon-btn svg { width: 18px; height: 18px; }
.address-card__icon-btn:active { background: var(--bg); color: var(--ink); }
.address-card__icon-btn.btn--danger {
  color: var(--danger);
  border-color: var(--line);
  background: #fff;
}
.address-card__icon-btn.btn--danger:active {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.address-card__default {
  background: #fff;
  color: var(--muted);
  border: 2px solid var(--line);
}
.address-card__default .address-card__star { font-size: 1.15rem; line-height: 1; }
.address-card__default:active { background: var(--bg); }
.address-card__default.is-active {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}
.address-card__default.is-active .address-card__star { color: var(--info); }

.badge--default {
  padding: 3px 12px;
  font-size: 0.82rem;
  background: var(--info-soft);
  color: var(--info);
}

/* Role toggle ---------------------------------------------------------- */
.role-toggle { border: none; padding: 0; margin: 0 0 18px; }
.role-toggle legend { margin-bottom: 10px; }
/* Pill segmented control, matching the address-book tabs (.tabs) and the
   wizard segmented control (.seg) for a consistent single-select look. */
.role-toggle__options {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #eceef1;
  border-radius: 999px;
}
.role-toggle__option {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
/* The pill selection conveys the choice; hide the native radio dot but keep it
   in the DOM so the form still submits and screen readers announce it. */
.role-toggle__option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.role-toggle__option:has(input:checked) {
  background: #fff;
  color: var(--post-red);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.role-toggle__option:has(input:focus-visible) {
  box-shadow: 0 0 0 3px var(--post-red-soft);
}

/* Address book picker (inside parcel wizard) --------------------------- */
.address-picker {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 16px;
}
.address-picker .field { flex: 1; margin: 0; }

/* Address-label photo scan -------------------------------------------- */
.address-scan { margin-bottom: 16px; }
.address-scan__btn { width: 100%; }
.address-scan--loading .address-scan__btn { opacity: 0.6; cursor: progress; }
.address-scan__panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.address-scan__status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
}
.address-scan__status--error { color: var(--danger); }
.address-scan__spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--post-red-soft);
  border-top-color: var(--post-red);
  border-radius: 50%;
  animation: address-scan-spin 0.7s linear infinite;
}
@keyframes address-scan-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .address-scan__spinner { animation-duration: 1.6s; }
}

.field--inline {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  min-height: 32px;
}
.field--inline input { width: 16px; height: 16px; accent-color: var(--post-red); }
.field--inline span { font-size: 0.82rem; }

/* Sticky bottom action bar (Shopee-style) ------------------------------ */
/* Primary actions live in a fixed bar pinned to the bottom of the viewport
 * so the main CTA is always within thumb reach on mobile / inside LIFF. */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 14px rgba(0, 0, 0, 0.08);
}
.action-bar .btn { flex: 1; margin-top: 0; }
.action-bar form.button_to { flex: 1; display: flex; }
.action-bar form.button_to .btn { width: 100%; }
/* Keep page content clear of the fixed bar. */
.screen--with-action-bar { padding-bottom: 92px; }

/* Topbar overflow ("kebab") menu — holds a parcel's edit/delete actions ---- */
.menu { position: relative; display: inline-flex; }

.kebab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.kebab:active { background: var(--line); }

.menu__panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 6px;
  z-index: 60;
}
.menu__panel[hidden] { display: none; }
.menu__panel form.button_to { display: block; margin: 0; }

.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  background: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu__item:active { background: #f3f4f6; }
.menu__item--danger { color: var(--danger); }
.menu__icon { width: 18px; height: 18px; flex: none; }

/* Card section header with leading icon (Shopee-style section blocks) --- */
.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.card__icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--post-red-soft);
  color: var(--post-red);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}
.card__title { font-size: 0.95rem; font-weight: 800; margin: 0; }

/* Field with a leading icon ------------------------------------------- */
.field__control { position: relative; display: flex; }
.field__control .field__input { width: 100%; }
.field__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.55;
  pointer-events: none;
}
.field__input--icon { padding-left: 36px; }
.field__input::placeholder { color: #9aa1ab; }

/* ID document: type select + number in two columns. */
.id-document__row { display: flex; gap: 10px; }
/* Size the type select to its content so the dropdown chevron sits right after
 * the label instead of being pushed to the far right edge. */
.id-document__row .field__input--id-type { flex: 0 0 auto; width: auto; max-width: 52%; }
.id-document__row .id-document__number { flex: 1; min-width: 0; }

/* Scan label call-to-action, rendered as one tappable card row. -------- */
.scan-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.scan-row:active { transform: translateY(1px); }
.scan-row__icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--post-red-soft);
  color: var(--post-red);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.scan-row__cam { width: 22px; height: 22px; display: block; }
.scan-row__body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.scan-row__title { font-weight: 800; font-size: 0.88rem; color: var(--ink); }
.scan-row__sub { font-size: 0.72rem; color: var(--muted); line-height: 1.3; }
.scan-row__chev { flex: none; color: var(--muted); font-size: 1.3rem; line-height: 1; }

/* Recipient quick-actions: two pills side by side (paste / ask customer). */
/* Recipient mode segmented control (fill it yourself / ask the customer) */
.recipient-mode { margin-bottom: 12px; }
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #eceef1;
  border-radius: 999px;
}
.seg__btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
  min-height: var(--tap);
}
.seg__btn--active {
  background: #fff;
  color: var(--post-red);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Paste-to-fill hint bar (opens the paste modal) */
.address-parse { margin-bottom: 0; }
.paste-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--post-red);
  border-radius: var(--radius);
  background: var(--post-red-soft);
  color: var(--post-red);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
}
.paste-bar:active { background: #fbdedc; }
.paste-bar__text { flex: 1; }
/* Looks like a button; the whole bar is the actual <button> that opens the modal. */
.paste-bar__cta {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--post-red);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}
.paste-bar:active .paste-bar__cta { background: var(--post-red-dark); }

/* The headless customer-link (opened by the segmented control) contributes no
 * visible box, so strip the .address-scan spacing that would leave a gap. */
.customer-link--headless { margin: 0; }

/* ─── Modal dialogs (paste address / customer link) ─────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.modal-open { overflow: hidden; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 20, 24, 0.45);
  opacity: 0;
  transition: opacity 0.16s ease;
}
.modal.is-open .modal__backdrop { opacity: 1; }

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 360px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 26px 22px 20px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(17, 20, 24, 0.28);
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal.is-open .modal__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.modal__close:active { background: var(--bg); }

.modal__icon {
  width: 56px;
  height: 56px;
  margin: 4px auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--post-red-soft);
  color: var(--post-red);
  font-size: 1.5rem;
}
.modal__icon svg { width: 28px; height: 28px; }

.modal__title {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
}
.modal__desc {
  margin: 0 0 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}
.modal__info {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--info-soft);
  color: var(--info);
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}
/* Fields inside a modal aren't wrapped in the .fields grid, so space them here. */
.modal__panel .field + .field { margin-top: 14px; }
.modal__status { margin: 12px 0 0; }
.modal__status--error,
.modal__status.address-scan__status--error { color: var(--danger); }
.modal .btn--block { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  .modal__backdrop,
  .modal__panel { transition: none; }
}

/* ─── App-style confirm dialog ──────────────────────────────────────────
 * Replaces the browser-native confirm() Turbo would otherwise show, so a
 * destructive action inside the LIFF webview looks like the phone's own
 * dialogs (centered card, big taps) instead of "localhost:3000 says". */
.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.confirm-dialog-open { overflow: hidden; }

.confirm-dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 20, 24, 0.45);
  opacity: 0;
  transition: opacity 0.16s ease;
}
.confirm-dialog.is-open .confirm-dialog__backdrop { opacity: 1; }

.confirm-dialog__panel {
  position: relative;
  width: 100%;
  max-width: 320px;
  padding: 26px 22px 18px;
  background: var(--card);
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 18px 48px rgba(17, 20, 24, 0.28);
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.confirm-dialog.is-open .confirm-dialog__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.confirm-dialog__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--post-red-soft);
  color: var(--post-red);
}
.confirm-dialog__panel--danger .confirm-dialog__icon {
  background: var(--danger-soft);
  color: var(--danger);
}
.confirm-dialog__icon svg { width: 28px; height: 28px; }

.confirm-dialog__title {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
}
.confirm-dialog__note {
  margin: 0 0 22px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--muted);
}

.confirm-dialog__actions {
  display: flex;
  gap: 10px;
}
.confirm-dialog__btn {
  flex: 1;
  min-height: var(--tap);
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.confirm-dialog__btn--cancel {
  background: var(--bg);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.confirm-dialog__btn--cancel:active { background: var(--line); }
.confirm-dialog__btn--ok {
  background: var(--post-red);
  color: #fff;
}
.confirm-dialog__btn--ok:active { background: var(--post-red-dark); }
.confirm-dialog__btn--danger { background: var(--danger); }
.confirm-dialog__btn--danger:active { background: #991b1b; }

@media (prefers-reduced-motion: reduce) {
  .confirm-dialog__backdrop,
  .confirm-dialog__panel { transition: none; }
}
