:root {
  color-scheme: light;
  --bg: #eef1ee;
  --ink: #151d1b;
  --muted: #65716d;
  --line: #d5ddd8;
  --panel: #ffffff;
  --field: #fbfcfb;
  --green: #184f41;
  --green-2: #dcece5;
  --blue: #244e76;
  --blue-2: #e3edf7;
  --amber: #8a5b16;
  --amber-2: #fff3d8;
  --danger: #8a2c2c;
  --shadow: 0 18px 48px rgba(27, 39, 35, 0.10);
  --shadow-soft: 0 8px 24px rgba(27, 39, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #e7ece8 0, #f7f8f6 320px, var(--bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

[hidden] {
  display: none !important;
}

button:hover {
  filter: brightness(1.05);
}

button:disabled {
  cursor: progress;
  opacity: 0.65;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 6px;
  min-height: 40px;
  padding: 0 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

input:focus,
select:focus {
  outline: 3px solid rgba(36, 78, 118, 0.18);
  border-color: var(--blue);
}

input[type="file"] {
  min-height: auto;
  padding: 10px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 38px clamp(22px, 4vw, 56px) 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #173d34 0%, #233b57 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.topbar::after {
  content: "";
  position: absolute;
  inset: auto -10% -85px 35%;
  height: 170px;
  background: radial-gradient(circle at center, rgba(158, 208, 189, 0.24), transparent 68%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #9ed0bd;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
}

.top-subtitle {
  margin: 12px 0 0;
  max-width: 650px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 16px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(86px, 1fr));
  gap: 8px;
  min-width: min(560px, 100%);
}

.top-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.account-actions a,
.account-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.status-strip span,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.10);
  border-radius: 6px;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.panel .pill,
.results-panel .pill,
.case-shell .pill,
.admin-shell .pill {
  border-color: var(--line);
  background: #f6f8f5;
  color: var(--muted);
}

.search-band {
  padding: 28px clamp(22px, 4vw, 56px);
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,250,248,0.96));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(28, 39, 35, 0.06);
}

.search-form {
  display: grid;
  gap: 14px;
  max-width: 1560px;
  margin: 0 auto;
}

.search-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

#searchInput {
  min-height: 64px;
  font-size: 20px;
  border-color: #c9d4ce;
  padding: 0 18px;
}

.search-row button {
  min-height: 64px;
  min-width: 128px;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(320px, auto) minmax(120px, 170px) minmax(120px, 170px);
  gap: 12px;
  align-items: end;
}

.control-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  min-height: 40px;
}

.segmented button {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #f8faf7;
  color: var(--muted);
  min-height: 40px;
  box-shadow: none;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--green-2);
  color: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  gap: 22px;
  max-width: 1680px;
  margin: 0 auto;
  padding: 26px clamp(22px, 4vw, 56px) 48px;
}

.sidebar,
.results-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-heading,
.results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: end;
}

.panel-heading button {
  min-height: 34px;
  background: #fff;
  color: var(--green);
}

.upload-panel form {
  display: grid;
  gap: 10px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.document-list,
.warning-list,
.results {
  display: grid;
  gap: 10px;
}

.document-list {
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.document-item,
.result-card,
.warning-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(22, 35, 30, 0.03);
}

.document-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  transition: border-color 120ms ease, transform 120ms ease;
}

.document-item:hover,
.result-card:hover,
.case-nav-item:hover {
  border-color: #b5c5bd;
  transform: translateY(-1px);
}

.doc-title,
.result-title {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.result-title {
  display: block;
  font-size: 18px;
  line-height: 1.25;
  margin-bottom: 8px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2ec;
  color: #34423c;
  font-weight: 700;
}

.tag.uploads {
  background: #e6eef7;
  color: var(--blue);
}

.tag.warning {
  background: var(--amber-2);
  color: var(--amber);
}

.tag.match {
  background: var(--green-2);
  color: var(--green);
}

.tag.context {
  background: #eef2ec;
  color: var(--muted);
}

.warnings-panel {
  border-color: #ead9b8;
}

.warning-item {
  padding: 10px;
  background: #fffaf0;
  color: #4f3820;
  font-size: 13px;
}

.results-panel {
  padding: 20px;
}

.results-heading {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.result-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-left: 4px solid var(--green);
  background: linear-gradient(180deg, #fff, #fbfcfb);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-actions a,
.result-actions button {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--green);
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.result-actions .primary-action,
.reader-actions a,
.reader-actions button {
  border-color: var(--green);
}

.result-actions .primary-action {
  background: var(--green);
  color: #fff;
}

.snippet {
  margin: 0;
  color: #26322e;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.6;
}

mark {
  background: #ffe18a;
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: #fbfcfa;
}

.hero-empty {
  display: grid;
  gap: 8px;
  min-height: 320px;
  place-content: center;
}

.hero-empty strong {
  color: var(--ink);
  font-size: 24px;
}

.hero-empty span {
  max-width: 560px;
}

.tag.evidence {
  background: var(--blue-2);
  color: var(--blue);
}

.reader-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 44px);
}

.case-shell,
.admin-shell,
.legal-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 44px);
}

.reader-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding-bottom: 18px;
}

.reader-header h1 {
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.reader-actions a,
.reader-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  background: #fff;
  color: var(--green);
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
  box-shadow: none;
}

.reader-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 28px);
}

.case-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.reader-stepper {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.case-nav {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
}

.case-nav-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  background: #fff;
}

.case-nav-item span {
  color: var(--muted);
  font-size: 12px;
}

.case-nav-item .timeline-date,
.timeline-date {
  color: #17624f;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.timeline-date {
  margin: 0 0 5px;
}

.timeline-date.unknown,
.page-date.unknown {
  color: #7b8581;
}

.page-date {
  border-left: 2px solid #76a998;
  padding-left: 8px;
  color: #17624f;
  font-weight: 800;
}

.case-results {
  display: grid;
  gap: 18px;
}

.case-document {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.case-document-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.case-document-header h2 {
  overflow-wrap: anywhere;
}

.case-document-header a {
  flex: 0 0 auto;
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.case-page {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.case-page:last-child {
  border-bottom: 0;
}

.matched-page {
  background: #fbfdfb;
}

.case-page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.page-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #1f2b27;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.65;
}

.page-image-frame {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1ee;
  padding: clamp(10px, 2vw, 18px);
  overflow: auto;
}

.page-image {
  max-width: 100%;
  height: auto;
  border: 1px solid #c7d3cd;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(27, 39, 35, 0.14);
}

.text-details {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.text-details summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--green);
  font-weight: 800;
}

.text-details .page-text {
  padding: 0 12px 12px;
}

.notes-panel {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.note-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.note-item {
  border: 1px solid #cfdad4;
  border-radius: 8px;
  background: #f8fbf9;
  padding: 10px;
}

.note-item.pending {
  background: var(--amber-2);
  border-color: #ead9b8;
}

.note-item p {
  margin: 4px 0;
  white-space: pre-wrap;
}

.note-item span,
.empty-note {
  color: var(--muted);
  font-size: 12px;
}

.note-form {
  display: grid;
  gap: 8px;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
}

textarea:focus {
  outline: 3px solid rgba(36, 78, 118, 0.18);
  border-color: var(--blue);
}

.login-body {
  background: linear-gradient(135deg, #153e35 0%, #263d58 52%, #eef1ee 52%, #eef1ee 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 38px);
  border-top: 5px solid var(--green);
}

.login-form,
.admin-form {
  display: grid;
  gap: 12px;
}

.admin-login-form {
  margin-top: 12px;
}

.quiet-button {
  width: 100%;
  margin-top: 12px;
  background: #fff;
  color: var(--muted);
  border-color: var(--line);
  box-shadow: none;
}

.code-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green-2);
  color: var(--green);
  padding: 12px;
}

.code-box code {
  display: block;
  font-size: 18px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.admin-code-row {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 9px;
}

.admin-code-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.admin-code-row code {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.admin-code-row button {
  min-height: 32px;
  padding: 0 10px;
  box-shadow: none;
}

.legal-shell {
  max-width: 980px;
}

.legal-content {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 42px);
}

.legal-content h2 {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.legal-content h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.legal-content p {
  max-width: 78ch;
  color: #34443f;
  line-height: 1.7;
}

.login-form label,
.admin-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-list,
.audit-list {
  display: grid;
  gap: 10px;
}

  .admin-user,
  .audit-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.admin-user-actions {
  flex: 0 0 auto;
}

.admin-user-actions button {
  background: #fff;
  color: var(--danger);
  border-color: #e3c6c6;
  box-shadow: none;
}

.admin-user-actions button:first-child {
  color: var(--green);
  border-color: #bfd6ca;
}

.checkbox-row {
  grid-template-columns: auto 1fr !important;
  align-items: center;
  justify-content: start;
}

.checkbox-row input {
  width: auto;
  min-height: auto;
  box-shadow: none;
}

.audit-panel {
  margin-top: 18px;
}

.audit-totals {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.audit-totals article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #f8faf8);
  padding: 12px;
}

.audit-totals strong {
  display: block;
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}

.audit-totals span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.security-event {
  border: 1px solid #ead0d0;
  border-left: 4px solid var(--danger);
  border-radius: 8px;
  background: #fffafa;
  padding: 12px;
}

.security-event p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.recent-searches {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 6px;
  max-width: 430px;
}

.recent-searches span {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2ec;
  color: var(--muted);
  font-size: 12px;
}

.admin-note-text {
  margin: 6px 0;
  white-space: pre-wrap;
  color: var(--ink);
}

@media (max-width: 980px) {
  .topbar {
    display: grid;
  }

  .admin-code-row {
    grid-template-columns: 1fr;
  }

  .status-strip,
  .control-row,
  .workspace,
  .reader-header,
  .case-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .account-actions {
    justify-items: start;
    justify-content: start;
  }

  .reader-actions {
    justify-content: start;
  }

  .case-nav {
    position: static;
    max-height: none;
  }

  .case-page-toolbar,
  .case-document-header,
  .admin-user,
  .audit-row,
  .audit-totals {
    display: grid;
  }
}

@media (max-width: 620px) {
  .search-row,
  .segmented,
  .status-strip {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 32px;
  }
}
