:root {
  --ink: #1a1a2e;
  --accent: #c8102e;       /* American Bridge red */
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f7f9;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.topbar {
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
header.topbar a { color: #fff; }
header.topbar .brand { font-weight: 700; font-size: 1.1rem; }
header.topbar .brand small { font-weight: 400; opacity: 0.7; display: block; font-size: 0.7rem; }
header.topbar nav { display: flex; gap: 1rem; }
header.topbar .spacer { flex: 1; }
main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.25rem; }
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.muted { color: var(--muted); }
.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; background: var(--line); color: var(--ink);
}
.badge.public { background: #dcfce7; color: #166534; }
.badge.draft { background: #fef9c3; color: #854d0e; }
.badge.internal { background: #e0e7ff; color: #3730a3; }
.badge.burned { background: #dcfce7; color: #166534; }
.badge.pending { background: #fee2e2; color: #991b1b; }
/* Pipeline phase status badges (processing page) */
.badge.st-done { background: #dcfce7; color: #166534; }
.badge.st-run  { background: #fef9c3; color: #854d0e; }
.badge.st-fail { background: #fee2e2; color: #991b1b; }
.badge.st-none { background: #e5e7eb; color: #374151; }
.proc-table { width: 100%; border-collapse: collapse; }
.proc-table th, .proc-table td {
  text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line);
}
.proc-table th { font-weight: 600; font-size: 0.8rem; color: #6b7280; }
input[type=text], input[type=search], input[type=date], input[type=number],
textarea, select {
  width: 100%; padding: 0.5rem; border: 1px solid var(--line); border-radius: 6px;
  font: inherit;
}
.btn {
  display: inline-block; background: var(--accent); color: #fff;
  padding: 0.45rem 0.9rem; border-radius: 6px; border: 0; cursor: pointer;
  font: inherit;
}
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.grid { display: grid; gap: 0.75rem; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; }
.thumbs img { width: 100%; border: 1px solid var(--line); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--line); }
.facets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.searchbar { display: flex; gap: 0.5rem; align-items: center; }
.searchbar input { flex: 1; }

/* Dashboard */
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 1rem; text-align: center; display: flex; flex-direction: column;
  gap: 0.2rem; color: var(--ink); text-decoration: none;
}
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat-n { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.dash-list { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.dash-list li { margin-bottom: 0.2rem; }

/* Public landing */
.hero {
  text-align: center;
  padding: 3rem 1rem 2.5rem;
  background: linear-gradient(180deg, #fff 0%, var(--bg) 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 2rem;
}
.hero-title { font-size: 2rem; line-height: 1.2; margin: 0 auto 0.5rem; max-width: 720px; }
.hero-sub { color: var(--muted); margin: 0 auto 1.5rem; max-width: 560px; }
.hero-search { display: flex; gap: 0.5rem; max-width: 580px; margin: 0 auto 0.75rem; }
.hero-search input { flex: 1; padding: 0.75rem 1rem; font-size: 1.05rem; border-radius: 8px; }
.hero-stats { color: var(--muted); font-size: 0.9rem; margin: 0; }
section { margin-bottom: 2rem; }
section > h2 { font-size: 1.1rem; border-bottom: 2px solid var(--accent); display: inline-block; padding-bottom: 0.2rem; }
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; }
.subject-card {
  display: flex; flex-direction: column; gap: 0.25rem;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.9rem 1rem; color: var(--ink); text-decoration: none;
}
.subject-card:hover { border-color: var(--accent); text-decoration: none; }
.subject-card .subject-name { font-weight: 600; }
.subject-card .badge { align-self: flex-start; }
.site-footer {
  max-width: 1100px; margin: 2rem auto 1rem; padding: 1.5rem 1.25rem;
  border-top: 1px solid var(--line); color: var(--ink); font-size: 0.9rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}

/* Public persistent sidebar */
.public-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem; align-items: start; }
.public-layout .content { min-width: 0; }
.sidebar { position: sticky; top: 1rem; }
.sidebar-nav {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.75rem 0.9rem; font-size: 0.9rem;
}
.sidebar-home {
  display: block; font-weight: 600; padding: 0.3rem 0; color: var(--ink);
  border-bottom: 1px solid var(--line); margin-bottom: 0.5rem;
}
.sidebar-home.is-current { color: var(--accent); }
.sidebar-context {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.1rem 0 0.6rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--line);
}
.sidebar-context-name { font-weight: 600; }
.sidebar-section { margin-top: 0.9rem; }
.sidebar-section:first-of-type { margin-top: 0; }
.sidebar-section h3 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin: 0 0 0.35rem;
}
.sidebar-list { list-style: none; margin: 0; padding: 0; }
.sidebar-list li {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.18rem 0; line-height: 1.3;
}
.sidebar-list li a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-list li .badge { flex: none; }
.sidebar-more { margin: 0.15rem 0; }
.sidebar-more summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; }
.sidebar-more summary:hover { color: var(--accent); }
.sidebar-all { display: inline-block; margin-top: 0.4rem; font-size: 0.82rem; }
.small { font-size: 0.82rem; }
@media (max-width: 820px) {
  .public-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

/* Redaction editor */
.redact-page { position: relative; margin-bottom: 1rem; display: inline-block; }
.redact-page img { display: block; max-width: 100%; border: 1px solid var(--line); }
.redact-layer { position: absolute; inset: 0; cursor: crosshair; }
.redact-rect { position: absolute; background: rgba(0,0,0,0.85); border: 1px solid #c8102e; }

/* Document viewer (shared by internal + public record-detail) ----------- */
.doc-viewer { display: flex; flex-direction: column; gap: 0.85rem; }

.doc-search { display: flex; align-items: center; gap: 0.5rem; }
.doc-search-input {
  flex: 1; padding: 0.5rem 0.65rem; border: 1px solid var(--line);
  border-radius: 6px; font: inherit; background: #fff; color: var(--ink);
}
.doc-search-clear {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 6px; width: 2rem; height: 2rem; cursor: pointer; line-height: 1;
  font-size: 1.1rem;
}
.doc-search-status { font-size: 0.85rem; white-space: nowrap; }

.doc-pagenav { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.25rem; }
.doc-pagechip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center;
  gap: 0.2rem; min-width: 2.4rem; padding: 0.35rem 0.6rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); cursor: pointer; font: inherit;
}
.doc-pagechip.has-thumb { padding: 0.3rem; }
.doc-pagechip:hover { border-color: var(--accent); }
.doc-pagechip.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.doc-pagechip.has-thumb img {
  display: block; width: 96px; height: auto; border-radius: 3px;
}
.doc-pagechip-label { font-size: 0.78rem; color: var(--muted); }

.doc-pdf {
  width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 6px;
  background: #fff;
}
.doc-pdf-fallback { margin: 0; }

.doc-pages { display: flex; flex-direction: column; gap: 0.75rem; }
.doc-pages-head { margin: 0.25rem 0 0; }
.doc-page { border: 1px solid var(--line); border-radius: 6px; padding: 0.75rem 0.9rem; }
.doc-page.is-nomatch { opacity: 0.45; }
.doc-page-head { margin-bottom: 0.4rem; }
.doc-page-num { font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.doc-page-text { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
mark.doc-hit { background: #fde68a; color: inherit; padding: 0 1px; border-radius: 2px; }
mark.doc-hit.is-current { background: var(--accent); color: #fff; }

@media (max-width: 820px) {
  .doc-pdf { height: 60vh; }
  .doc-pagechip.has-thumb img { width: 64px; }
}

/* Bulk-action bar (Awaiting-review page) */
.bulk-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.bulk-bar .bulk-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
