/*
 * Palette note: the carrier colours below are derived from each company's brand
 * colours but adjusted where the originals fail WCAG contrast (DHL yellow and the
 * various oranges/golds are unusable behind white text; raw UPS brown is so dark it
 * reads as black). Every accent clears 4.5:1 with white text and every tint clears
 * 7:1 with black text. Colours identify a format -- they imply no affiliation.
 */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #14181f;
  --ink-soft: #5b636e;
  --line: #e2e5ea;

  /* USPS-derived site theme */
  --usps-blue: #004b87;
  --usps-red: #da291c;
  --accent: #c4241a;              /* USPS red, darkened so white button text passes AA */
  --field-bg: #fbfcfd;
  --focus-ring: rgba(0, 75, 135, .35);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 31, .06), 0 6px 18px rgba(20, 24, 31, .05);
}

/* ----------------------------------------------------- carrier card themes */

.card--usps    { --carrier-accent: #004b87; --tint: #e9f1f8; }
.card--placard { --carrier-accent: #b3221a; --tint: #fcedec; }
.card--ups     { --carrier-accent: #4e2c1a; --tint: #f6efe8; }
.card--fedex   { --carrier-accent: #4d148c; --tint: #f2ebf9; }
.card--dhl     { --carrier-accent: #d40511; --tint: #fff6d9; }
.card--amazon  { --carrier-accent: #232f3e; --tint: #fff3e0; }
.card--s10     { --carrier-accent: #4a6d7c; --tint: #edf3f5; }
.card--unknown { --carrier-accent: #5b6770; --tint: #f2f3f4; }

/* The carrier badge wears the accent; every pair above clears AA on white text. */
.card[class*="card--"] .badge:not(.badge-warn) {
  background: var(--carrier-accent);
  color: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Uncaught-failure banner (see showErrorStrip in js/app.js). */
.error-strip {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  background: #b3221a;
  color: #ffffff;
  font-size: 13px;
}
.error-strip-close {
  margin-left: auto;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  background: none;
  border: 0;
  color: #ffffff;
  cursor: pointer;
  padding: 0 4px;
}

h1, h2 { margin: 0; font-weight: 600; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 22px 28px 20px;
  background: var(--usps-blue);
  border-bottom: 4px solid var(--usps-red);
  color: #ffffff;
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: block;
  flex: none;
}

.topbar h1 { font-size: 30px; letter-spacing: -.02em; color: #ffffff; }
.topbar p { margin: 2px 0 0; font-size: 15px; color: rgba(255, 255, 255, .82); }

/* Pinned right on wide screens so the brand stays optically centred. */
.topbar-actions {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
}
.summary { font-size: 13px; color: rgba(255, 255, 255, .82); }

/* On the blue bar a white button reads better than the red accent. */
.topbar .button {
  background: #ffffff;
  border-color: #ffffff;
  color: var(--usps-blue);
}
.topbar .button:hover { background: #eef3f8; filter: none; }

/* ----------------------------------------------------------------- buttons */

.button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.button:hover { filter: brightness(1.06); }

.button-quiet {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.button-quiet:hover { background: #f0f2f5; filter: none; }

.button:disabled {
  cursor: default;
  opacity: .5;
  filter: none;
}
.button:disabled:hover { background: var(--surface); filter: none; }

.button[hidden] { display: none; }

.link-button {
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 8px 0 0;
  cursor: pointer;
  align-self: flex-start;
}
.link-button:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  padding: 24px 28px 48px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.field-heading {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--accent); }

.hint { margin: 8px 0 12px; font-size: 12px; color: var(--ink-soft); }
.hint-tight { margin: 6px 0 0; }
.muted { color: var(--ink-soft); font-weight: 400; text-transform: none; letter-spacing: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.apply-zip { margin-top: 10px; }

.text-input {
  width: 100%;
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field-bg);
  color: var(--ink);
}
.text-input:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--accent); }
.text-input.invalid { border-color: #f0a29b; background: #fef7f6; }

/* ---------------------------------------------------------- extract status */

.extract-status {
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid #cfe3d3;
  background: #f2f9f4;
  border-radius: 8px;
  font-size: 12px;
}
.extract-status[hidden] { display: none; }

/* Neutral (non-success) variant, e.g. "nothing usable on the clipboard". */
.extract-status.neutral { border-color: var(--line); background: #f6f7f9; }
.extract-status.neutral .status-text { color: var(--ink-soft); }

.status-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.status-text { color: #1c6b38; }
.extract-status .link-button { padding: 0; font-size: 12px; }

.skipped-list {
  margin: 8px 0 0;
  padding-left: 16px;
  max-height: 140px;
  overflow-y: auto;
  color: var(--ink-soft);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
}
.skipped-list[hidden] { display: none; }
.skipped-list li { margin-top: 3px; word-break: break-all; }

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 14px 0 4px;
}
.slider-label:first-of-type { margin-top: 0; }
.slider-label output { font-variant-numeric: tabular-nums; color: var(--ink); }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink);
}
.checkbox input { accent-color: var(--accent); }

.notes ul { margin: 0; padding-left: 16px; font-size: 12px; color: var(--ink-soft); }
.notes li + li { margin-top: 6px; }

/* ----------------------------------------------------------------- results */

.results { display: flex; flex-direction: column; gap: 16px; }

.empty {
  margin: 0 0 16px;
  padding: 40px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--carrier-accent, var(--line));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--tint, #fbfcfd);
}

.card-index {
  font-size: 11px;
  font-weight: 600;
  color: var(--carrier-accent, var(--ink-soft));
  font-variant-numeric: tabular-nums;
}

.card-value {
  font: 600 15px/1.3 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .02em;
  word-break: break-all;
}

.card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  padding: 18px;
  align-items: start;
}

.panel { display: flex; flex-direction: column; min-width: 0; }

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.panel-title { font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.panel-meta { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.panel-select {
  margin-left: auto;
  font: inherit;
  font-size: 11px;
  padding: 2px 4px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.panel-select:hover { color: var(--ink); }

/* -------------------------------------------------------- per-card routing ZIP */

.zip-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.zip-control-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.zip-input {
  width: 96px;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  color: var(--ink);
}
.zip-input:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--accent); }
.zip-input.invalid { border-color: #f0a29b; background: #fef7f6; }
.zip-note { margin: 6px 0 0; font-size: 11px; color: var(--ink-soft); }

/* ------------------------------------------------------------------ badges */

.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 20px;
  background: #eef2f7;
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge-warn { background: #fef3f2; color: #b42318; border: 1px solid #fecdc9; }

.panel-frame {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
}

/* Long symbols scale down to the card instead of overflowing. */
.symbol-svg { display: block; max-width: 100%; height: auto; }

.panel-error { color: #b42318; }
.error-text {
  margin: 0;
  font-size: 12px;
  background: #fef3f2;
  border: 1px solid #fecdc9;
  border-radius: 8px;
  padding: 10px;
  max-width: 340px;
}

/* ----------------------------------------------------- page copy (SEO/help) */

/* Slim keyword-bearing strip between the hero and the tool. */
.page-intro {
  max-width: 74ch;
  margin: 0 auto;
  padding: 22px 28px 0;
  text-align: center;
}
.page-intro h2 {
  font-size: 19px;
  letter-spacing: -.01em;
}
.page-intro p {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}

/* Reference/FAQ copy below the tool. */
.page-content {
  max-width: 72ch;
  margin: 8px auto 0;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.page-content h2 {
  font-size: 20px;
  margin: 32px 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--usps-blue);
}
.page-content h2:first-child { margin-top: 0; }
.page-content h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 4px;
  color: var(--usps-blue);
}
.page-content p {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.65;
  color: #3c444f;
}
.page-content code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
  word-break: break-all;
}

@media (max-width: 620px) {
  .page-intro { padding: 18px 18px 0; }
  .page-intro h2 { font-size: 17px; }
  .page-content { padding: 20px 18px; border-radius: 0; border-left: 0; border-right: 0; }
}

/* ------------------------------------------------------------------ footer */

.site-footer {
  margin-top: 8px;
  padding: 22px 28px 32px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
}

.footer-support { margin: 0 0 10px; font-size: 13px; }
.footer-support a { color: var(--accent); font-weight: 500; }

.footer-note { margin: 0 auto 8px; max-width: 62ch; }

.footer-disclaimer {
  margin: 0 auto;
  max-width: 78ch;
  font-size: 11px;
  color: #7b828c;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }

  /* Not enough width to pin the actions beside a centred brand -- stack them. */
  .topbar-actions { position: static; transform: none; }
}

@media (max-width: 620px) {
  .card-body { grid-template-columns: minmax(0, 1fr); }

  /* iOS Safari force-zooms the page when a focused field is under 16px. */
  textarea, .text-input, .zip-input { font-size: 16px; }

  /* Comfortable touch targets without changing the desktop density. */
  .panel-select { padding: 8px 10px; font-size: 13px; }
  .link-button { padding: 12px 0 4px; font-size: 14px; }
  .zip-input { padding: 8px 10px; width: 132px; }
  .button { padding: 11px 16px; }
}

/* -------------------------------------------------------------------- print */

@media print {
  body { background: #fff; }
  .topbar, .sidebar, .empty, .link-button, .panel-select, .extract-status,
  .zip-control, .site-footer,
  .page-intro, .page-content { display: none !important; }
  .layout { display: block; padding: 0; }
  .card {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 12px;
  }
  .panel-frame { border-color: #ddd; }

  /* A carrier tint must never print behind a symbol, even with
     "print backgrounds" enabled. */
  .card, .card-head, .panel-frame { background: #fff !important; }
  .card { border-left-color: #ccc !important; }
  .badge { background: #fff !important; color: #000 !important; border: 1px solid #ccc; }
}
