:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1c2128;
  --muted: #6b7480;
  --accent: #2f6feb;
  --good: #1a7f45;
  --warn: #b26a00;
  --bad: #b3261e;
  --hand: #7b3fb8;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 18px; margin: 0; }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
}
.pill.ok  { background: #e4f4ea; color: var(--good); }
.pill.bad { background: #fdeaea; color: var(--bad); }

/* Document type radios */
.doctype { border: 0; margin: 0 0 16px; padding: 0; }
.doctype legend {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 0 0 8px;
}
.radio { display: block; margin-bottom: 8px; cursor: pointer; }
.radio input { margin-right: 10px; }
.radio span { display: inline-flex; flex-direction: column; vertical-align: top; }
.radio small { color: var(--muted); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: #f0f5ff; }
.dropzone p { margin: 0 0 4px; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { background: #c3c9d2; cursor: not-allowed; }
#browse {
  background: none; color: var(--accent);
  padding: 0; text-decoration: underline;
}

#preview {
  display: block;
  max-width: 100%;
  max-height: 320px;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

#submit { margin-top: 8px; }

.status {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #eef1f5;
  color: var(--muted);
}
.status.error { background: #fdeaea; color: var(--bad); }

/* Summary grid */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.summary div {
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.summary dt {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 3px;
}
.summary dd { margin: 0; font-weight: 600; word-break: break-word; }

/* Dynamic field tree - must not assume a schema */
.tree { font-size: 14px; }
.tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px solid var(--border); }
.tree > ul { padding-left: 0; border-left: 0; }
.tree li { padding: 3px 0; }
.tree .k { color: var(--muted); margin-right: 6px; }
.tree .v { font-weight: 600; word-break: break-word; }
.tree .v.empty { font-weight: 400; color: #aeb4bd; font-style: italic; }

/* Handwriting gets its own visual treatment */
.hand {
  border: 1px solid #e6dcf5;
  background: #faf7fe;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.hand h3 { margin: 0 0 8px; font-size: 13px; color: var(--hand); }
.hand ul { margin: 0; padding-left: 18px; }
.hand li { color: #3f2a5c; }
.hand .where { color: var(--muted); font-size: 12px; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }
pre {
  white-space: pre-wrap; word-break: break-word;
  background: #f8f9fb; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; font-size: 12.5px; max-height: 340px; overflow: auto;
}

/* Match card */
.match-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.verdict { font-size: 17px; font-weight: 700; }
.verdict.matched   { color: var(--good); }
.verdict.uncertain { color: var(--warn); }
.verdict.none      { color: var(--bad); }

.bar { height: 9px; border-radius: 999px; background: #eef1f5; overflow: hidden; margin-bottom: 14px; }
.bar > i { display: block; height: 100%; background: var(--good); }
.bar.uncertain > i { background: var(--warn); }
.bar.none > i { background: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: #f8f9fb; color: var(--muted);
}
.chip.hit { background: #e4f4ea; border-color: #bfe3cd; color: var(--good); }
.chip.miss { background: #fdeaea; border-color: #f2c9c6; color: var(--bad); }
.chip.na { opacity: .6; }

.group {
  margin-top: 16px; padding: 12px 14px;
  border: 1px solid #cfe0ff; background: #f2f7ff; border-radius: 8px;
}
.group h3 { margin: 0 0 6px; font-size: 13px; color: var(--accent); }

a { color: var(--accent); }

/* Page thumbnail + side links */
.thumbwrap {
  display: flex; gap: 14px; align-items: flex-start;
  margin: 6px 0 16px;
}
.thumb {
  width: 150px; max-height: 200px; object-fit: cover; object-position: top;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: zoom-in;
  transition: border-color .15s, box-shadow .15s;
}
.thumb:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(47,111,235,.18); }
.thumbside { display: flex; flex-direction: column; gap: 6px; font-size: 13px; padding-top: 2px; }
.thumbside a, .thumbside .linkish { text-decoration: none; }
.thumbside a:hover, .thumbside .linkish:hover { text-decoration: underline; }
/* A button that reads as a link - same affordance, no navigation. */
.thumbside .linkish {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; text-align: left; cursor: pointer;
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 20, 26, .88);
  display: flex; flex-direction: column; align-items: center;
  padding: 56px 16px 24px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%; max-height: calc(100vh - 110px);
  object-fit: contain; background: #fff; border-radius: 6px;
}
.lb-bar {
  position: absolute; top: 14px; left: 16px; right: 60px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  color: #f2f4f7; font-size: 13px;
}
.lb-hint { color: #9aa3ae; }
.lb-toggle { display: inline-flex; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; }
.lb-toggle button {
  background: transparent; color: #cdd3db; border: 0;
  padding: 4px 12px; font-size: 12px; border-radius: 0; cursor: pointer;
}
.lb-toggle button.on { background: #f2f4f7; color: #1c2128; }
.lb-close {
  position: absolute; top: 10px; right: 14px;
  background: transparent; color: #f2f4f7;
  font-size: 30px; line-height: 1; padding: 4px 10px; cursor: pointer;
}
.lb-close:hover { color: #fff; }

@media (max-width: 560px) {
  .thumbwrap { flex-direction: column; }
  .thumb { width: 100%; max-height: 240px; }
}

#submit:disabled { background: #c3c9d2; }
