/* Shipping-label typography on stamp-ink colours.
   The parcel number is the artifact this app is about, so it is set large and
   monospaced; everything that labels rather than states is small, letterspaced
   and uppercase, the way a waybill sets its field names.

   System faces on purpose: on the iPhone this resolves to SF Pro and SF Mono,
   which are excellent, need no network round-trip, and keep a Home Screen app
   feeling native. A webfont here would only add a blocking request. */

:root {
  --paper: #e7e9e4;          /* recycled label stock, cooled off so it is not cream */
  --card: #fbfbf9;
  --ink: #1a1d21;
  --ink-soft: #5c6169;
  --ink-faint: #8f959d;
  --rule: #d2d6ce;

  /* Status colours read as rubber-stamp inks rather than UI blues. */
  --stamp-red: #b4341f;      /* exception, and the out-of-step badge */
  --stamp-blue: #26436e;     /* in motion */
  --stamp-green: #3f6b45;    /* delivered */
  --stamp-grey: #6b7078;     /* dormant / label only */

  --radius: 10px;
  --shadow: 0 1px 2px rgb(26 29 33 / 6%), 0 6px 16px -10px rgb(26 29 33 / 22%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15171a;
    --card: #1e2126;
    --ink: #eceef0;
    --ink-soft: #a2a8b0;
    --ink-faint: #71777f;
    --rule: #31353c;

    --stamp-red: #e2705a;
    --stamp-blue: #7ea3d8;
    --stamp-green: #7fb388;
    --stamp-grey: #9aa0a8;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 16px -10px rgb(0 0 0 / 60%);
  }
}

* { box-sizing: border-box; }

/* The UA stylesheet's `[hidden] { display: none }` loses to any author rule that
   sets `display` on the same element — `.gate` sets `display: grid`, which made
   the token gate render on top of the app for anyone already signed in. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  /* Home Screen apps run under the notch and over the home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  /* Nothing here is text you select on purpose; long-press selection in a
     Home Screen app mostly gets in the way of tapping. Inputs opt back in. */
  -webkit-user-select: none;
  user-select: none;
}

input, textarea { -webkit-user-select: text; user-select: text; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 48px; }

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  margin: 0 0 8px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* --- top bar -------------------------------------------------------------- */

.topbar {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 12px;
}

.topbar-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.wordmark {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.summary { margin: 6px 0 0; font-size: 12px; color: var(--ink-faint); }

/* --- shipment groups ------------------------------------------------------ */

.list { display: flex; flex-direction: column; gap: 18px; }

/* The rail is the structure that matters: parcels sharing a shipment are
   physically bracketed together, because the whole reason this app exists is
   that DPD's own site hides which parcel is which inside one shipment. */
.group { position: relative; }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px 14px;
}

.group.multi .stack {
  margin-left: 14px;
  padding-left: 14px;
  border-left: 2px solid var(--rule);
}

.stack { display: flex; flex-direction: column; gap: 10px; }

/* --- parcel card ---------------------------------------------------------- */

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
}

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

.number {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  letter-spacing: 0.02em;
  word-break: break-all;
}

.card-label { margin: 2px 0 0; font-size: 14px; color: var(--ink-soft); }

.role {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  padding-top: 4px;
}

.status-line { display: flex; align-items: center; gap: 8px; margin-top: 12px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot, var(--stamp-grey)); flex: none; }

.status-text { font-weight: 600; font-size: 15px; color: var(--dot, var(--ink)); }

.meta { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.meta .sep { color: var(--ink-faint); padding: 0 6px; }

/* The estimate caveat earns its own line: a predictive date that gets read as a
   booked slot is how you waste a day waiting at home. */
.estimate { color: var(--ink-faint); font-style: italic; }

/* --- the one bold moment -------------------------------------------------- */

/* A parcel that is behind its own siblings. This is the state the whole app was
   built to catch, so it is the only place that shouts. */
.stamp {
  position: absolute;
  top: 12px;
  /* Inset far enough that the rotated box still lands inside the card — a
     rotated element's painted box is wider than its layout box, and at right:10
     it pushed a few pixels of horizontal scroll onto the whole document. */
  right: 15px;
  transform: rotate(-6deg);
  padding: 3px 8px;
  border: 2px solid var(--stamp-red);
  border-radius: 3px;
  color: var(--stamp-red);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.9;
  animation: stamp-down 320ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.card.lagging { border-color: color-mix(in srgb, var(--stamp-red) 45%, var(--rule)); }
.card.lagging .card-top { padding-right: 104px; }

@keyframes stamp-down {
  from { transform: rotate(-14deg) scale(1.6); opacity: 0; }
  to   { transform: rotate(-6deg) scale(1); opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  .stamp { animation: none; }
}

/* --- scan log ------------------------------------------------------------- */

.log-toggle {
  margin-top: 10px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-faint);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.log {
  margin: 10px 0 0;
  padding: 10px 0 0;
  border-top: 1px dashed var(--rule);
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.log li { display: flex; gap: 10px; font-size: 12.5px; }
.log time { color: var(--ink-faint); flex: none; font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.log .ev { color: var(--ink-soft); }
.log li:last-child .ev { color: var(--ink); font-weight: 600; }

.card-actions { display: flex; gap: 14px; margin-top: 12px; }

/* --- notification banner -------------------------------------------------- */

.notify {
  margin: 0 0 18px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--stamp-blue);
  border-radius: var(--radius);
}

.notify p { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.notify p:last-child { margin-bottom: 0; }
.notify strong { color: var(--ink); }
.notify.ok { border-left-color: var(--stamp-green); }

/* --- forms and buttons ---------------------------------------------------- */

.add { margin-top: 26px; }
.add-form { display: flex; flex-direction: column; gap: 8px; }

.field {
  width: 100%;
  padding: 11px 12px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  /* 16px min, or iOS zooms the whole page in when the field takes focus. */
  font-size: 16px;
  font-family: inherit;
}

.field::placeholder { color: var(--ink-faint); }
.field:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .link-btn:focus-visible, .log-toggle:focus-visible {
  outline: 2px solid var(--stamp-blue);
  outline-offset: 2px;
}

.btn {
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-quiet { background: transparent; border-color: var(--rule); color: var(--ink-soft); }

.icon-btn {
  background: none;
  border: 0;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

.icon-btn.spinning { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spinning { animation: none; opacity: 0.5; } }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.card-actions .link-btn { font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }

.error { margin: 10px 0 0; font-size: 13.5px; color: var(--stamp-red); }

.empty {
  padding: 28px 16px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 32px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* --- gate ----------------------------------------------------------------- */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-inner { width: 100%; max-width: 320px; }
.gate-title { margin: 0 0 18px; font-size: 22px; font-weight: 600; }
.gate-form { display: flex; flex-direction: column; gap: 8px; }
