:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --faint: #8a97a5;
  --line: #d4dde6;
  --accent: #1e4d7b;
  --accent-soft: #e4eef6;
  --gold: #9a7b1a;
  --gold-soft: #f5efd8;
  --danger: #a33b2d;
  --danger-soft: #f8ebe8;
  --ok: #2f7a45;
  --ok-soft: #e8f3eb;
  --accused: #3d4a5c;
  --civilian: #1f6f8b;
  --police: #4a5d23;
  --exhibit: #1a5f9e;
  --forensic: #7a3d1a;
  --nav-w: 208px;
  --drawer-w: 340px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(26, 35, 50, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
a { color: var(--accent); }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; }
.brand-mark {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}
.brand-mark .gold { color: var(--gold); }
.product-name { font-size: 0.95rem; font-weight: 600; color: var(--accent); }
.top-tagline { margin: 0; font-size: 0.78rem; color: var(--muted); max-width: 34rem; }
.top-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.matter-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid #e5d9a8;
  color: #6b5612;
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.matter-badge.is-empty {
  background: var(--accent-soft);
  border-color: #c5d6e8;
  color: var(--accent);
}

/* Shell */
.shell {
  flex: 1;
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 0;
}
.shell.has-drawer {
  grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--drawer-w);
}

.nav {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 8px 10px 6px;
}
.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
}
.nav-btn:hover { background: var(--bg); color: var(--ink); }
.nav-btn[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.nav-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  font-size: 0.72rem;
  color: var(--faint);
  line-height: 1.35;
}

.stage {
  padding: 20px 22px 40px;
  overflow: auto;
  min-width: 0;
}
.view[hidden] { display: none !important; }
.view-title {
  margin: 0 0 6px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.view-lead { margin: 0 0 18px; color: var(--muted); max-width: 42rem; font-size: 0.95rem; }

.drawer {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
}
.drawer[hidden] { display: none !important; }
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.drawer-head h2 {
  margin: 0;
  font-size: 1rem;
  font-family: "Source Serif 4", Georgia, serif;
}
.drawer-body { font-size: 0.88rem; color: var(--ink); }
.drawer-body .meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 10px; }
.drawer-body .claim {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}
.drawer-body .claim strong { display: block; margin-bottom: 4px; font-size: 0.78rem; color: var(--muted); }
.drawer-body .excerpt { font-style: italic; color: var(--muted); margin-top: 4px; }
.cite-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
}
.cite-link:hover { color: #163a5e; }

/* Buttons / forms */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 560;
  font-size: 0.88rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #163a5e; border-color: #163a5e; color: #fff; }
.btn-ghost { background: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input, .field textarea, .field select {
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--ink);
}
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.hint { font-size: 0.8rem; color: var(--faint); margin-top: 4px; }

/* Cards / stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.mini-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.mini-stat .n {
  font-size: 1.45rem;
  font-weight: 700;
  font-family: "Source Serif 4", Georgia, serif;
  line-height: 1.1;
}
.mini-stat .l { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.panel h3 { margin: 0 0 8px; font-size: 0.95rem; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 140px;
  border: 1.5px dashed #b7c5d4;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fafc 0%, #eef3f8 100%);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 4px;
}
.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone strong { font-weight: 650; }
.dropzone span { color: var(--muted); font-size: 0.88rem; }
.dropzone input { display: none; }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.doc-list li:last-child { border-bottom: 0; }
.doc-meta { color: var(--muted); font-size: 0.8rem; }
.doc-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.doc-actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; border-radius: 6px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.contradiction { background: var(--danger-soft); color: var(--danger); }
.badge.tension { background: #fef3e2; color: #9a5b12; }
.badge.unresolved_gap { background: #eceef2; color: #4a5562; }
.badge.high { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: #fef3e2; color: #9a5b12; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.tension-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow);
}
.tension-card:hover { border-color: var(--accent); }
.tension-card .topic {
  font-weight: 650;
  margin: 6px 0 4px;
  font-size: 0.95rem;
}
.tension-card .pair { color: var(--muted); font-size: 0.82rem; }
.tension-card .badges { display: flex; flex-wrap: wrap; gap: 6px; }

.people-grid, .exhibit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.person-card, .exhibit-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow);
}
.person-card:hover, .exhibit-card:hover { border-color: var(--accent); }
.person-card .name, .exhibit-card .name { font-weight: 650; }
.person-card .sub, .exhibit-card .sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.role-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.role-dot.civilian { background: var(--civilian); }
.role-dot.accused { background: var(--accused); }
.role-dot.police { background: var(--police); }
.role-dot.exhibit { background: var(--exhibit); }
.role-dot.forensic { background: var(--forensic); }

/* Map */
.map-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 420px;
  position: relative;
}
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: linear-gradient(160deg, #f7fafc, #eef3f8);
}
.map-empty[hidden] { display: none; }
.node-box { cursor: pointer; }
.node-box rect {
  fill: #fff;
  stroke: var(--line);
  stroke-width: 1.5;
  rx: 8;
}
.node-box.civilian rect { stroke: var(--civilian); }
.node-box.accused rect { stroke: var(--accused); fill: #f4f5f7; }
.node-box.police rect { stroke: var(--police); }
.node-box.exhibit rect { stroke: var(--exhibit); fill: #eef5fb; }
.node-box.forensic rect { stroke: var(--forensic); fill: #faf3ee; }
.node-box.hot rect { stroke-width: 2.5; }
.node-box.dim { opacity: 0.28; }
.node-box text { font-family: "DM Sans", sans-serif; font-size: 11px; fill: var(--ink); pointer-events: none; }
.node-box .sub-label { fill: var(--muted); font-size: 9px; }
.edge-line {
  fill: none;
  stroke: #9aadc0;
  stroke-width: 1.6;
  cursor: pointer;
}
.edge-line.has-contradiction { stroke: var(--danger); stroke-width: 2; }
.edge-line.hot { stroke: var(--accent); stroke-width: 2.4; }
.edge-line.dim { opacity: 0.18; }
.band-label {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  fill: var(--faint);
}

.doc-preview {
  max-height: 420px;
  overflow: auto;
  font-size: 0.86rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  padding: 12px;
}
.doc-preview .para {
  margin-bottom: 10px;
  border-radius: 6px;
  padding: 3px 6px;
  transition: background-color 0.3s ease;
}
.doc-preview .para.is-target {
  background-color: var(--gold-soft);
  box-shadow: 0 0 0 1.5px #e5d9a8;
}
.doc-preview .num {
  display: inline-block;
  min-width: 2.2em;
  color: var(--accent);
  font-weight: 650;
  font-size: 0.78rem;
}
.doc-photo {
  display: block;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
  background: #0b1220;
}
.image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.exhibit-photo {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
}
.doc-thumb,
.doc-photo,
.exhibit-photo {
  cursor: zoom-in;
}

.image-hover-preview {
  position: fixed;
  z-index: 1000;
  max-width: min(440px, 80vw);
  pointer-events: none;
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.35);
  padding: 8px 8px 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.image-hover-preview:not([hidden]) {
  opacity: 1;
  transform: translateY(0);
}
.image-hover-preview img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 6px;
}
.image-hover-preview .caption {
  color: #fff;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 6px 2px 8px;
  text-align: center;
}
.image-hover-preview .caption:empty { display: none; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 35, 50, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 22px 24px;
  width: min(440px, 100%);
  box-shadow: 0 12px 40px rgba(26, 35, 50, 0.18);
}
.modal h2 {
  margin: 0 0 6px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.25rem;
}
.modal p { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
}
.status-bar .spin {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-note {
  padding: 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.summary-box {
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.55;
}

.warn-list { margin: 0; padding-left: 1.1rem; color: #9a5b12; font-size: 0.88rem; }

/* Relationship report */
.report-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.select-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; }
.select-list li {
  border-bottom: 1px solid var(--line);
}
.select-list li:last-child { border-bottom: 0; }
.select-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 2px;
  cursor: pointer;
  font-size: 0.88rem;
}
.select-list input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.select-list .sel-sub { color: var(--muted); font-size: 0.78rem; margin-left: auto; padding-left: 8px; white-space: nowrap; }

.report-output h2 {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.1rem;
  margin: 18px 0 8px;
}
.report-output h2:first-child { margin-top: 0; }
.report-output h3 { font-size: 0.98rem; margin: 14px 0 4px; }
.report-output .report-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.report-entity {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--bg);
}
.report-entity h4 { margin: 0 0 6px; font-size: 0.95rem; }
.report-entity .report-subhead {
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  margin: 10px 0 4px;
}
.report-entity ul { margin: 0; padding-left: 1.15rem; }
.report-entity li { margin-bottom: 6px; font-size: 0.86rem; }
.report-entity .excerpt { font-style: italic; color: var(--muted); font-size: 0.82rem; }
.report-related-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; }
.report-related-list li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.print-only { display: none; }
.print-heading { margin: 0 0 12px; font-size: 0.85rem; color: #333; }

/* Print — each report-style view prints its own content only. Non-report
   chrome (nav, topbar, drawer, buttons, toasts) is hidden; the visible
   `.view` section (the SPA already hides all others via [hidden]) is
   reflowed to fill the page on a plain white background. */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .nav, .drawer, .toast, .image-hover-preview, .modal-backdrop,
  .status-bar, .nav-foot, .btn-row, .btn { display: none !important; }
  .shell, .shell.has-drawer { display: block !important; }
  .stage { padding: 0 !important; overflow: visible !important; }
  .view[hidden] { display: none !important; }
  .view { display: block !important; }
  .print-only { display: block !important; }
  .view-title { font-size: 1.4rem; }
  .view-lead, .doc-meta, .hint, .report-entity .excerpt, .drawer-body .excerpt {
    color: #333 !important;
  }
  a, .cite-link { color: #000 !important; text-decoration: none !important; }

  .panel, .tension-card, .person-card, .exhibit-card, .report-entity,
  .mini-stat, .claim {
    box-shadow: none !important;
    border: 1px solid #999 !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .card-list, .people-grid, .exhibit-grid { display: block !important; }
  .card-list > *, .people-grid > *, .exhibit-grid > * { margin-bottom: 10px; width: 100%; }
  .stat-row { display: flex; flex-wrap: wrap; }

  .badge {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #999 !important;
  }

  .map-wrap {
    border: none !important;
    box-shadow: none !important;
    min-height: 0 !important;
  }
  .map-empty { display: none !important; }
  .map-wrap svg {
    width: 100% !important;
    height: auto !important;
    max-height: 95vh;
  }

  .doc-preview { max-height: none !important; overflow: visible !important; border: none; background: #fff !important; }
  .doc-preview .para { break-inside: avoid; page-break-inside: avoid; }
  #view-documents .field { display: none !important; }

  .report-output { break-inside: auto; }
  .report-entity { background: #fff !important; }

  @page { margin: 14mm; }
}

@media (max-width: 900px) {
  .shell, .shell.has-drawer {
    grid-template-columns: 1fr;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 4px;
  }
  .nav-label, .nav-foot { display: none; }
  .nav-btn { padding: 8px 10px; font-size: 0.82rem; }
  .drawer {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 40vh;
  }
}
