:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #5d6b78;
  --line: #d8dee4;
  --accent: #1d4f7c;
  --on-accent: #ffffff;
  --ok-bg: #e7f4ea;
  --ok-line: #9fd0aa;
  --warn-bg: #fff4dc;
  --warn-line: #e9c46a;
  --bad: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --card: #1b232b;
    --text: #e8edf2;
    --muted: #9aa7b3;
    --line: #2e3a45;
    --accent: #5fa3df;
    --on-accent: #0b1620;
    --ok-bg: #16301f;
    --ok-line: #2f6b40;
    --warn-bg: #3a2f12;
    --warn-line: #7a6420;
    --bad: #ff8a80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px);
  max-width: 560px;
  margin: 0 auto;
}
header { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 6px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.net.off { color: var(--bad); font-weight: 600; font-size: 14px; }
code { font-size: 13px; }

.capture { display: grid; gap: 10px; margin: 8px 0 4px; }
.big {
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; border-radius: 14px; font-size: 19px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.big.primary { background: var(--accent); color: var(--on-accent); }
.big.secondary { background: var(--card); color: var(--accent); border: 2px solid var(--accent); min-height: 52px; font-size: 17px; }
.big:active { opacity: 0.8; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px 14px; margin-top: 14px; }
.pages { display: flex; flex-wrap: wrap; gap: 10px; }
.page { position: relative; }
.page img, .page .pdf, .item img, .item .pdf {
  width: 72px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block;
}
.pdf { display: flex !important; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); background: var(--bg); }
.page .remove {
  position: absolute; top: -8px; right: -8px; border-radius: 12px; padding: 2px 8px; font-size: 12px;
  background: var(--card); color: var(--bad); border: 1px solid var(--line);
}

fieldset.kind { border: 0; padding: 0; margin: 12px 0 4px; display: flex; gap: 8px; flex-wrap: wrap; }
fieldset.kind legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
fieldset.kind label { flex: 1 1 0; min-width: 90px; }
fieldset.kind input { position: absolute; opacity: 0; pointer-events: none; }
fieldset.kind span {
  display: block; text-align: center; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
fieldset.kind input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
fieldset.kind input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

label.note { display: block; margin-top: 10px; font-size: 14px; color: var(--muted); }
input:not([type]), input[type="text"] {
  width: 100%; font-size: 16px; padding: 11px 12px; margin-top: 4px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.row { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.row input { margin-top: 0; }
button {
  font: inherit; border-radius: 10px; padding: 11px 16px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; flex: 1; }
button.secondary { color: var(--accent); border-color: var(--accent); }
button.ghost { flex: 0 0 auto; }
button.small { padding: 7px 10px; font-size: 14px; }

.warning, .ok { border-radius: 12px; padding: 4px 14px 12px; margin: 8px 0; }
.warning { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.ok { background: var(--ok-bg); border: 1px solid var(--ok-line); }

.outbox { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.item img, .item .pdf { width: 48px; height: 62px; }
.item .body { flex: 1; min-width: 0; }
.item .what { font-weight: 600; }
.item .status { font-size: 14px; color: var(--muted); }
.item.sent .status { color: inherit; }
.item.unpaired .status { color: var(--bad); }

footer { margin-top: 24px; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); max-width: 528px; margin: 0 auto;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; opacity: 0; transform: translateY(10px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
body.busy::after {
  content: "Reading the photo..."; position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); color: #fff; font-weight: 600;
}
