:root {
  --paper: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #18202B;
  --muted: #5D6878;
  --line: #D3D9E1;
  --line-strong: #B8C1CD;
  --stop: #B4232C;
  --talk: #1E7A55;
  --quiet: #A8670D;
  --new: #2350A0;
  --airmail-red: #C2313A;
  --airmail-blue: #2350A0;
  --focus: #2350A0;
  --radius-s: 4px;
  --radius-m: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 "Public Sans", system-ui, sans-serif;
  font-feature-settings: "tnum" 1;
}
[hidden] { display: none !important; }

a { color: var(--new); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding-inline: 24px; }
@media (max-width: 640px) { .wrap { padding-inline: 16px; } }

/* ---------------------------------------------------------------- top bar */
.bar {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.bar .wrap {
  display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; margin-right: auto; }
.brand span { color: var(--muted); font-weight: 400; }
.fresh { color: var(--muted); font-size: 14px; }
.fresh.stale { color: var(--stop); }
.linkbtn {
  background: none; border: 0; padding: 6px 0; color: var(--muted); cursor: pointer;
  font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}
.linkbtn:hover { color: var(--ink); }

main { padding-block: 48px 80px; }
@media (max-width: 640px) { main { padding-block: 28px 56px; } }

h1 {
  font-size: clamp(28px, 4.2vw, 44px); line-height: 1.1; letter-spacing: -0.025em;
  font-weight: 700; margin: 0 0 12px; max-width: 18ch;
}
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 32px; font-size: 17px; }

/* ---------------------------------------------------------------- drop zone (the airmail edge) */
.drop {
  position: relative; display: block; cursor: pointer;
  border-radius: var(--radius-m);
  padding: 10px;
  background: repeating-linear-gradient(-45deg,
      var(--airmail-red) 0 14px, var(--surface) 14px 22px,
      var(--airmail-blue) 22px 36px, var(--surface) 36px 44px);
}
.drop-inner {
  background: var(--surface); border-radius: 4px;
  padding: 56px 32px; text-align: left;
  display: grid; gap: 6px; justify-items: start;
}
.drop-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.drop-hint { color: var(--muted); max-width: 60ch; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }
.drop.over .drop-inner { background: #F4F7FB; }
.drop.busy { cursor: progress; }
.drop.busy .drop-inner { background: #F7F8FA; }
@media (max-width: 640px) { .drop-inner { padding: 36px 20px; } }

/* ---------------------------------------------------------------- progress */
.progress {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 28px 32px 24px; display: grid; gap: 12px;
}
@media (max-width: 640px) { .progress { padding: 22px 18px 18px; } }
.progress-head, .progress-foot {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap;
}
.progress-file { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.progress-pct { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.progress-foot { color: var(--ink); font-size: 15px; }
.progress-foot #prog-count { color: var(--muted); }
.progress-time { color: var(--muted); font-size: 13px; }
.bar {
  height: 14px; border-radius: 99px; background: #E3E8EE; overflow: hidden;
}
/* the fill reuses the airmail stripe from the drop zone, so it reads as the letter in transit */
.bar-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: repeating-linear-gradient(-45deg,
      var(--airmail-red) 0 10px, #fff 10px 14px, var(--airmail-blue) 14px 24px, #fff 24px 28px);
  background-size: 39.6px 100%;
  transition: width .45s ease-out;
}
.bar.done .bar-fill { background: var(--talk); }
@media (prefers-reduced-motion: no-preference) {
  .bar:not(.done) .bar-fill { animation: travel 1.2s linear infinite; }
  @keyframes travel { to { background-position: 39.6px 0; } }
}
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

.btn {
  display: inline-flex; align-items: center; gap: 8px; border-radius: var(--radius-s);
  padding: 10px 16px; border: 1px solid var(--ink); background: var(--ink); color: #fff;
  font-weight: 600; cursor: pointer; text-decoration: none; font-size: 15px;
}
.btn:hover { background: #2B3644; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { border-color: var(--ink); }
.drop .btn { margin-top: 14px; pointer-events: none; }

.error {
  margin-top: 16px; padding: 12px 14px; border-left: 3px solid var(--stop);
  background: #FBEDEE; color: #6E1519; border-radius: 0 var(--radius-s) var(--radius-s) 0;
}

/* ---------------------------------------------------------------- the four trays */
.trays-explain { margin-top: 40px; }
.trays-explain h2, .section-title {
  font-size: 15px; font-weight: 600; margin: 0 0 12px; color: var(--muted);
}
.trays {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
@media (max-width: 860px) { .trays { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .trays { grid-template-columns: 1fr; } }

.tray {
  --c: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  border-top: 4px solid var(--c);
  padding: 14px 16px 16px; text-align: left; display: grid; gap: 4px; align-content: start;
}
.tray.stop { --c: var(--stop); }
.tray.talk { --c: var(--talk); }
.tray.quiet { --c: var(--quiet); }
.tray.new { --c: var(--new); }
.tray-name { font-weight: 600; }
.tray-desc { color: var(--muted); font-size: 14px; line-height: 1.45; }

button.tray { cursor: pointer; font: inherit; color: inherit; }
button.tray:hover { border-color: var(--line-strong); border-top-color: var(--c); }
button.tray[aria-selected="true"] {
  border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c);
}
.tray-count {
  font-size: clamp(30px, 5vw, 40px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; color: var(--c);
}

/* ---------------------------------------------------------------- results */
.result-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 20px;
}
.result-head > div:first-child { flex: 1 1 480px; min-width: 0; }
.result-head h1 { margin: 0; font-size: clamp(24px, 3.2vw, 34px); max-width: none; overflow-wrap: anywhere; }
.result-head .actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.summary { color: var(--muted); margin: 6px 0 0; font-size: 15px; }
.summary b { color: var(--ink); font-weight: 600; }

.panel {
  margin-top: 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.panel-head {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 17px; font-weight: 600; margin-right: auto; }
.search {
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 8px 10px;
  min-width: 300px; background: var(--surface);
}
@media (max-width: 520px) { .search { min-width: 0; width: 100%; } }
.note { color: var(--muted); font-size: 13px; padding: 10px 16px; border-top: 1px solid var(--line); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); white-space: nowrap; background: #F7F8FA; position: sticky; top: 0; }
td.num, th.num { text-align: right; }
td .sub { color: var(--muted); font-size: 13px; }
td.clip { max-width: 380px; }
td.clip div { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #F7F9FC; }
tr.row[aria-expanded="true"] td { background: #F3F6FA; border-bottom-color: transparent; }
tr.detail td { background: #F3F6FA; padding: 4px 12px 18px; }
.detail-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
@media (min-width: 860px) { .detail-grid > div:first-child { grid-column: span 2; } }
.detail-grid h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.detail-grid pre {
  margin: 0; white-space: pre-wrap; font: inherit; font-size: 14px; line-height: 1.5;
}
.flag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.flag.bad { background: #FBEDEE; color: var(--stop); }
.flag.ok { background: #E8F3EE; color: var(--talk); }
.flag.warn { background: #FBF1E2; color: var(--quiet); }
.empty { padding: 28px 16px; color: var(--muted); }

/* ---------------------------------------------------------------- past checks */
.history { margin-top: 32px; }
.history .panel { margin-top: 0; }
.history .table-wrap { max-height: 520px; overflow-y: auto; }
.admin-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.select {
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 7px 10px;
  background: var(--surface); font: inherit; font-size: 14px; color: inherit;
}
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-s); overflow: hidden; }
.seg button {
  border: 0; background: var(--surface); padding: 7px 12px; font-size: 14px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
td.n-stop { color: var(--stop); font-weight: 600; }
td.n-talk { color: var(--talk); font-weight: 600; }
td.n-quiet { color: var(--quiet); font-weight: 600; }
td.n-new { color: var(--new); font-weight: 600; }
td.failed { color: var(--stop); }
td.acts { white-space: nowrap; text-align: right; }
td.acts a, td.acts button { margin-left: 12px; font-size: 14px; }
td.acts button { background: none; border: 0; padding: 0; color: var(--new); cursor: pointer; text-decoration: underline; }
td.when { white-space: nowrap; }
td.file { overflow-wrap: anywhere; min-width: 160px; }

/* ---------------------------------------------------------------- login */
.login-page main { display: grid; place-items: start center; padding-block: 12vh 48px; }
.login {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-m); overflow: hidden;
}
.login .stripe {
  height: 8px;
  background: repeating-linear-gradient(-45deg,
      var(--airmail-red) 0 14px, var(--surface) 14px 22px,
      var(--airmail-blue) 22px 36px, var(--surface) 36px 44px);
}
.login form { padding: 28px; display: grid; gap: 14px; }
.login h1 { font-size: 26px; margin: 0; }
.login p { margin: 0; color: var(--muted); font-size: 15px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.field input {
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 10px 12px;
  background: var(--surface);
}
.login .btn { justify-content: center; margin-top: 6px; }

@media (prefers-reduced-motion: no-preference) {
  .tray-count.settle { animation: settle .5s cubic-bezier(.2,.7,.2,1) both; }
  @keyframes settle { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
