:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --extracted: #4ade80;
  --derived: #fbbf24;
  --null: #475569;
  --review: #f87171;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}
header {
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 18px; }
header .sub { color: var(--muted); font-size: 13px; }
main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 1fr;
  overflow: hidden;
}
#sidebar, #left, #right { overflow: auto; }
#sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 12px; }
#sidebar h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.sample-btn {
  display: block; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 6px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; font-size: 12px;
}
.sample-btn:hover { border-color: var(--accent); }
.sample-btn.active { border-color: var(--accent); background: #1e3a5f; }
#upload-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
#left { background: #1a1a1a; position: relative; overflow: hidden; }
#pdf-container { padding: 16px; height: 100%; overflow-y: auto; }
/* Floating zoom controls, top-right of the PDF panel. */
#pdf-toolbar {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  background: rgba(30, 41, 59, 0.92); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
#pdf-toolbar[hidden] { display: none; }
#pdf-toolbar button {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; font-size: 14px; line-height: 1;
  height: 26px; min-width: 26px; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
#pdf-toolbar button#zoom-reset { min-width: auto; padding: 0 8px; font-size: 11px; }
#pdf-toolbar button:hover { border-color: var(--accent); }
#zoom-level {
  min-width: 44px; text-align: center; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; user-select: none;
}
.pdf-page-wrapper {
  position: relative;
  margin: 0 auto 16px auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  background: #fff;
}
.pdf-page-wrapper canvas { display: block; }
.pdf-page-wrapper svg.overlay {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; pointer-events: none;
}
.highlight-rect {
  fill: rgba(251, 191, 36, 0.35);
  stroke: rgba(251, 191, 36, 0.9);
  stroke-width: 2;
}
.highlight-rect.pulse {
  animation: pulse 1.5s ease-out;
}
@keyframes pulse {
  0%   { fill: rgba(251, 191, 36, 0.7); }
  100% { fill: rgba(251, 191, 36, 0.35); }
}
#pdf-error {
  padding: 16px; color: #fee2e2; background: #7f1d1d;
  border-radius: 4px; margin: 16px; font-size: 13px;
}
/* DISABLED (PDF-only mode): image upload preview + highlight overlay rules */
/* .image-wrap { */
/*   position: relative; display: block; width: fit-content; */
/*   margin: 0 auto; box-shadow: 0 2px 8px rgba(0,0,0,0.5); background: #fff; */
/* } */
/* .image-wrap img { display: block; max-width: 100%; height: auto; } */
/* .image-overlay { */
/*   position: absolute; top: 0; left: 0; */
/*   width: 100%; height: 100%; pointer-events: none; */
/* } */
/* .image-highlight { */
/*   position: absolute; box-sizing: border-box; */
/*   background: rgba(251, 191, 36, 0.35); */
/*   border: 2px solid rgba(251, 191, 36, 0.9); */
/* } */
/* .image-highlight.pulse { animation: pulse-bg 1.5s ease-out; } */
/* @keyframes pulse-bg { */
/*   0%   { background: rgba(251, 191, 36, 0.7); } */
/*   100% { background: rgba(251, 191, 36, 0.35); } */
/* } */
#right { padding: 12px; }
#metrics-bar {
  background: var(--panel); padding: 8px 12px; border-radius: 4px; margin-bottom: 12px;
  font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap;
}
#metrics-bar span { color: var(--muted); }
#metrics-bar b { color: var(--text); }
#controls { display: flex; gap: 8px; margin-bottom: 12px; }
#controls button, #controls label {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 4px; font-size: 12px; cursor: pointer;
}
.section { margin-bottom: 14px; }
.section h4 { margin: 0 0 6px; font-size: 13px; color: var(--accent); }
.field { display: flex; flex-wrap: wrap; justify-content: space-between; padding: 4px 8px; font-size: 12px;
         font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; cursor: pointer;
         border-radius: 3px; }
.field:hover { background: var(--panel); }
.field.null { opacity: 0.4; }
.field .k { color: var(--muted); }
.field .v { color: var(--text); max-width: 60%; text-align: right; word-break: break-all; }
.field .src { flex-basis: 100%; text-align: left; font-size: 10px; color: var(--muted);
              opacity: 0.8; margin-top: 2px; word-break: break-word; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.extracted { background: var(--extracted); }
.dot.derived   { background: var(--derived); }
.dot.null      { background: var(--null); }
.dot.review    { background: var(--review); }
#stage-indicator { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
#banner { padding: 8px 12px; margin-bottom: 12px; border-radius: 4px; display: none; font-size: 13px; }
#banner.partial { background: #78350f; color: #fef3c7; display: block; }
#banner.failed  { background: #7f1d1d; color: #fee2e2; display: block; }

/* In-page toast for derivation / null-field explanations. Replaces browser alert(). */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--derived);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast-null { border-left-color: var(--null); }
.toast-info { border-left-color: var(--accent); }
.toast-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}
.toast-body {
  color: var(--muted);
  line-height: 1.45;
}
