:root {
  --bg: #efe9df; --card: #fffaf2; --ink: #2b2620; --muted: #6f655a; --line: #d9cfc0;
  --accent: #b4552d; --accent-ink: #fff; --ok: #3f7a4a; --warn: #b4552d; --done: #3f7a4a;
  --tick-off: #e6ddcf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a17; --card: #27231f; --ink: #efe7da; --muted: #a99e90; --line: #3a342d;
    --accent: #e08a5e; --accent-ink: #1d1a17; --ok: #7fbf8a; --warn: #e08a5e; --done: #7fbf8a;
    --tick-off: #332e28;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; }
.muted { color: var(--muted); }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* ---------- buttons */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.small { padding: 5px 11px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px; font-size: inherit; }
.link.danger { color: #b3322a; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- the list */
#app { max-width: 920px; margin: 0 auto; padding: 20px 16px 40px;
  padding-top: max(20px, env(safe-area-inset-top)); }
.top { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 28px; line-height: 1.2; cursor: text; }
.top p { margin: 4px 0 0; font-size: 14px; }
.top-actions { display: flex; gap: 8px; }
.toolbar { margin: 18px 0 12px; display: grid; gap: 10px; }
#search { width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 11px;
  font-size: 14px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip b { font-weight: 600; margin-left: 3px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: grid; grid-template-columns: 76px 1fr; gap: 12px; }
.item.needs { border-left: 4px solid var(--warn); }
.thumb { width: 76px; height: 76px; border-radius: 8px; object-fit: cover; background: var(--tick-off);
  display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; border: 0; padding: 0;
  cursor: pointer; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.item-head h3 { margin: 0; font: 600 18px/1.25 Georgia, "Times New Roman", serif; }
.badge { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 8px; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.edit { margin-left: auto; }
.meta { font-size: 14px; color: var(--muted); margin: 2px 0 0; }
.fixes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 15px; }
.fixes label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.fixes input { margin-top: 3px; accent-color: var(--done); width: 17px; height: 17px; flex: none; }
.fixes .done span { text-decoration: line-through; color: var(--muted); }
.notes { font-size: 14px; color: var(--muted); margin: 6px 0 0; white-space: pre-wrap; }
.stages { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.stage { border: 1px solid var(--line); background: var(--tick-off); border-radius: 8px; padding: 7px 4px;
  font-size: 13px; cursor: pointer; text-align: center; line-height: 1.2; }
.stage[aria-pressed="true"] { background: var(--done); border-color: var(--done); color: var(--card); font-weight: 600; }
.stage[aria-pressed="true"]::before { content: "✓ "; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.foot { margin-top: 28px; font-size: 13px; text-align: center; }

@media (max-width: 520px) {
  .top h1 { font-size: 24px; }
  .item { grid-template-columns: 60px 1fr; }
  .thumb { width: 60px; height: 60px; }
  .stage { font-size: 12px; padding: 8px 2px; }
}

/* ---------- editor */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink);
  padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
#edit-form { padding: 18px; display: grid; gap: 14px; }
#edit-form h2 { margin: 0; font-size: 22px; }
.field { display: grid; gap: 5px; font-size: 14px; color: var(--muted); }
.field input:not([type=checkbox]), .field textarea, .fix-add input { width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--bg); color: var(--ink); font-size: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-pick { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.photo-pick img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; }
.fix-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; color: var(--ink); font-size: 15px; }
.fix-list li { display: flex; gap: 8px; align-items: center; }
.fix-list li input[type=checkbox] { accent-color: var(--done); width: 18px; height: 18px; flex: none; }
.fix-list li span { flex: 1; }
.fix-list li.done span { text-decoration: line-through; color: var(--muted); }
.fix-list .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 4px; }
.fix-add { display: flex; gap: 8px; }
.edit-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- print preview */
#print-view { min-height: 100vh; }
.print-bar { position: sticky; top: 0; z-index: 2; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.print-options { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.print-options label { display: flex; gap: 5px; align-items: center; cursor: pointer; }
.paper-wrap { padding: 20px 12px 40px; overflow-x: auto; }
/* an A4 page on screen: 210 mm wide, white, like it will print */
.paper { width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; color: #1a1714;
  padding: 12mm; box-shadow: 0 2px 14px rgb(0 0 0 / .18); font: 10pt/1.35 system-ui, -apple-system, sans-serif; }
.paper h1 { font: 600 17pt/1.2 Georgia, serif; margin: 0; }
.paper .sub { color: #555; margin: 2pt 0 8pt; font-size: 9pt; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th { text-align: left; font-size: 8pt; text-transform: uppercase; letter-spacing: .04em; color: #555;
  border-bottom: 1.2pt solid #1a1714; padding: 4pt 4pt; vertical-align: bottom; }
.paper td { border-bottom: .6pt solid #bbb; padding: 5pt 4pt; vertical-align: top; }
.paper tr { break-inside: avoid; }
.paper .p-photo img { width: 18mm; height: 18mm; object-fit: cover; border-radius: 1.5mm; display: block; }
.paper .p-name { font-weight: 600; }
.paper .p-fix { margin: 0; padding-left: 10pt; }
.paper .p-fix li.done { text-decoration: line-through; color: #888; }
.paper .p-notes { color: #444; white-space: pre-wrap; }
.paper .tick { width: 11pt; height: 11pt; border: 1pt solid #1a1714; border-radius: 2pt; display: inline-block;
  text-align: center; line-height: 10pt; font-size: 9pt; }
.paper th.t, .paper td.t { text-align: center; width: 13mm; }
.paper .ok { color: #2f6b3a; font-weight: 600; }
.paper .warn { color: #a3401d; font-weight: 600; }
.paper .nothing { text-align: center; color: #666; padding: 20mm 0; }

@media print {
  @page { size: A4; margin: 12mm; }      /* on every page, not just the first */
  body { background: #fff; }
  #app, .print-bar, dialog { display: none !important; }
  #print-view, .paper-wrap { display: block !important; padding: 0; min-height: 0; }
  .paper { box-shadow: none; margin: 0; width: auto; min-height: 0; padding: 0; }
}
