* {
  box-sizing: border-box;
}

:root {
  /* Light grey/white app surface */
  --paper: #eef0f3;
  --paper-dark: #e3e6ea;
  --ink: #1a1d24;
  --muted: #5b6470;
  /* Patriotic accents: federal navy + old-glory red */
  --accent: #16335c;
  --accent-soft: #e7edf6;
  --flag-red: #b22234;
  --flag-blue: #3c3b6e;
  --panel: #ffffff;
  --panel-alt: #f6f8fa;
  --border: #cdd3db;
  --border-strong: #aab2bd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.08);
  --ui-font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display-font: "Spectral", "Playfair Display", "Palatino Linotype", "Book Antiqua", Palatino, serif;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
}

.app {
  max-width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 26px;
  background: var(--panel);
  border: 2px solid var(--border-strong);
  border-top: 5px solid var(--flag-red);
  box-shadow: var(--shadow);
  border-radius: 14px;
}

.hero-text {
  display: flex;
  flex-direction: column;
}

/* Title lockup: Betsy Ross flag + wordmark */
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-flag {
  width: 58px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.25);
}

.hero h1 {
  margin: 0;
  font-family: var(--display-font);
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--accent);
}

.hero .hero-tagline {
  margin: 2px 0 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--flag-red);
}

.hero p {
  margin: 10px 0 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.hero-meta {
  font-size: 0.95rem;
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.hero-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-link.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.controls {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-note {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1em;
}

label {
  font-weight: 600;
  color: var(--muted);
  font-family: var(--ui-font);
}

select,
input[type="number"] {
  padding: 8px 10px;
  font-size: 1rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-family: var(--ui-font);
}

select:focus,
input[type="number"]:focus,
input[type="date"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-controls input {
  width: 70px;
  text-align: center;
}

/* Compact controls layout */
.compact-controls {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.compact-controls .control-group {
  min-width: 0;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.label-row label {
  margin: 0;
}

.nav-arrows {
  display: flex;
  gap: 2px;
}

.nav-btn {
  padding: 2px 6px;
  font-size: 0.85rem;
  min-width: 24px;
}

.page-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-input-row input {
  width: 60px;
  text-align: center;
}

.btn {
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--ui-font);
  font-size: 0.92rem;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  background: #1f4475;
  border-color: #1f4475;
}

.btn.ghost {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.ghost-link:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.ghost-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: 1.5px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  width: fit-content;
}

.sources {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.sources-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.source-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f6f8fa;
  cursor: pointer;
}

.source-chip input {
  accent-color: var(--accent);
}

.layout {
  margin-top: 20px;
  display: flex;
  align-items: stretch;
  gap: 0;
}

.panel-header {
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: 12px 12px 0 0;
}

.image-panel,
.transcripts-panel,
.diff-panel,
.article-panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.image-panel {
  flex: 0 0 60%;
  min-width: 300px;
}

.transcripts-panel {
  flex: 1 1 40%;
  min-width: 320px;
}

.diff-panel {
  flex: 1 1 40%;
  min-width: 320px;
}

.article-panel {
  flex: 1 1 40%;
  min-width: 320px;
}

.layout-divider {
  width: 12px;
  cursor: col-resize;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(22, 51, 92, 0.25) 20%,
    rgba(22, 51, 92, 0.45) 50%,
    rgba(22, 51, 92, 0.25) 80%,
    transparent 100%
  );
  margin: 0 6px;
  border-radius: 999px;
}

.layout-divider:hover {
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(22, 51, 92, 0.45) 20%,
    rgba(22, 51, 92, 0.7) 50%,
    rgba(22, 51, 92, 0.45) 80%,
    transparent 100%
  );
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

.image-frame {
  padding: 16px;
  min-height: 60vh;
  position: relative;
  background: #f3f5f8;
  overflow: auto;
}

.image-frame img {
  display: block;
  width: 100%;
  height: auto;
  transform-origin: top left;
}

.image-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}

.transcript-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.compare-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border-bottom: 1px solid var(--border);
  background: #f6f8fa;
}

.compare-title {
  padding: 10px 12px;
  font-weight: 700;
  color: var(--ink);
  border-right: 1px solid var(--border);
}

.compare-title:last-child {
  border-right: none;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  max-height: 75vh;
  overflow: auto;
  background: #fbfcfd;
}

.compare-grid .diff-placeholder {
  grid-column: 1 / -1;
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}

.compare-cell {
  padding: 6px 10px;
  border-bottom: 1px solid #e4e8ee;
  font-family: "IBM Plex Mono", "Fira Mono", "Menlo", "Consolas", monospace;
  white-space: pre-wrap;
  line-height: 1.4;
}

.compare-cell.baseline {
  border-right: 1px solid #e4e8ee;
}

.compare-cell.tag-equal {
  background: #fbfcfd;
}

.compare-cell.tag-replace {
  background: #ffffff;
  box-shadow: inset 6px 0 0 #f4b400;
}

.compare-cell.tag-delete {
  background: #ffffff;
  box-shadow: inset 6px 0 0 #e53935;
}

.compare-cell.tag-insert {
  background: #ffffff;
  box-shadow: inset 6px 0 0 #0f9d58;
}

.compare-cell .char-add {
  background: #00c853;
  color: #ffffff;
  font-weight: 700;
  padding: 0 1px;
  border-radius: 2px;
}

.compare-cell .char-del {
  background: #d50000;
  color: #ffffff;
  font-weight: 700;
  text-decoration: line-through;
  padding: 0 1px;
  border-radius: 2px;
}


.transcript-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.transcript-header {
  padding: 10px 12px;
  background: #eef1f5;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.transcript-body {
  padding: 12px;
  overflow: auto;
  max-height: 75vh;
  white-space: pre-wrap;
  line-height: 1.6;
}

.article-meta {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f6f8fa;
  color: var(--muted);
  font-size: 0.9rem;
}

.article-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  background: #fbfcfd;
  border-bottom: 1px solid var(--border);
}

.article-tab {
  border: 1px solid var(--border);
  background: #eef1f5;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-weight: 700;
}

.article-tab.active {
  background: #fbfcfd;
  color: var(--accent);
  border-bottom-color: #fbfcfd;
}

.article-tab-panel {
  display: none;
}

.article-tab-panel.active {
  display: block;
}

.article-body {
  padding: 12px;
  overflow: auto;
  max-height: 75vh;
}

.article-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
  font-family: "IBM Plex Mono", "Fira Mono", "Menlo", "Consolas", monospace;
}

.article-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}

.entity-panel,
.mention-panel {
  background: #fbfcfd;
}

.section-heading {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: #f6f8fa;
}

.entity-summary {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.entity-content {
  padding: 12px 14px 16px;
  display: grid;
  gap: 12px;
}

.entity-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 10px;
}

.entity-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #f6f8fa;
}

.entity-group h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.entity-item {
  padding: 6px 0;
  border-bottom: 1px dashed #e4e8ee;
}

.entity-item:last-child {
  border-bottom: none;
}

.entity-name {
  font-weight: 700;
}

.entity-meta {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--muted);
}

.entity-citations {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.article {
  padding: 10px 0;
  border-bottom: 1px dashed #e4e8ee;
}

.article:last-child {
  border-bottom: none;
}

.article.cited-highlight {
  background: rgba(22, 51, 92, 0.1);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  border-radius: 4px;
}

.article.structured {
  padding-bottom: 16px;
}

.item-kind {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 8px;
}

.chunk {
  margin-bottom: 12px;
}

.chunk:last-child {
  margin-bottom: 0;
}

.chunk-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.chunk-text {
  white-space: pre-wrap;
}

/* Entity Highlighting */
.entity-hl {
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  padding: 0 1px;
  border-radius: 3px;
}

.entity-hl:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.entity-hl.active {
  background-color: rgba(255, 255, 0, 0.3);
  border-bottom-color: currentColor;
}

/* Entity Type Colors (using --accent derivatives or distinct hues) */
.entity-hl.type-people { color: #d32f2f; border-bottom-color: rgba(211, 47, 47, 0.3); }
.entity-hl.type-organizations { color: #1976d2; border-bottom-color: rgba(25, 118, 210, 0.3); }
.entity-hl.type-places { color: #388e3c; border-bottom-color: rgba(56, 142, 60, 0.3); }
.entity-hl.type-events { color: #f57c00; border-bottom-color: rgba(245, 124, 0, 0.3); }
.entity-hl.type-documents { color: #7b1fa2; border-bottom-color: rgba(123, 31, 162, 0.3); }
.entity-hl.type-dates { color: #0097a7; border-bottom-color: rgba(0, 151, 167, 0.3); }

/* Sidebar Entity Interaction */
.entity-item {
  padding: 6px 0;
  border-bottom: 1px dashed #e4e8ee;
  cursor: pointer;
  transition: background-color 0.1s;
  border-radius: 4px;
}

.entity-item:hover,
.entity-item.active {
  background-color: rgba(0, 0, 0, 0.04);
}

.entity-item:last-child {
  border-bottom: none;
}

.mention-review {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  min-height: 55vh;
}

.mention-list {
  max-height: 70vh;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--border);
  background: #f6f8fa;
}

.mention-text-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mention-review-note {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  background: #f1f5fb;
  font-size: 0.85rem;
}

.mention-text {
  padding: 12px;
  overflow: auto;
  max-height: 70vh;
}

.mention-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mention-type-pill {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid currentColor;
}

.mention-type-pill.type-people { color: #d32f2f; }
.mention-type-pill.type-organizations { color: #1976d2; }
.mention-type-pill.type-places { color: #388e3c; }
.mention-type-pill.type-events { color: #f57c00; }
.mention-type-pill.type-documents { color: #7b1fa2; }
.mention-type-pill.type-dates { color: #0097a7; }

.mention-citation-ref {
  background: rgba(22, 51, 92, 0.12);
  border: 1px solid rgba(22, 51, 92, 0.18);
  border-radius: 4px;
  padding: 0 2px;
}

.mention-citation-ref.active {
  background: rgba(22, 51, 92, 0.22);
  border-color: rgba(22, 51, 92, 0.45);
}

.page-break {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 10px 0;
}

.transcript-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d3c7b5;
  transition: 0.2s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--accent);
}

.switch input:checked + .slider:before {
  transform: translateX(24px);
}

/* Citation and entity deep-link styles */
.citation-link {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.citation-link:hover {
  color: var(--accent);
  text-decoration-style: solid;
}

.entity-search-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 2px;
}

.entity-search-link:hover {
  color: var(--accent);
  text-decoration-style: solid;
}

@media (max-width: 1000px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-actions {
    align-items: flex-start;
  }

  .layout {
    flex-direction: column;
    gap: 18px;
  }

  .layout-divider {
    display: none;
  }

  .image-panel,
  .transcripts-panel,
  .diff-panel,
  .article-panel {
    flex: 1 1 auto;
    min-width: 0;
  }

  .mention-review {
    grid-template-columns: 1fr;
  }

  .mention-list {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* Demo mode: hide experiment-tuning controls (body class set by shared.js). */
body.demo-mode .demo-hide {
  display: none !important;
}

/* Hide main-panel images until a source is set so alt text never shows. */
#page-image:not([src]),
#tile-image:not([src]),
#article-image:not([src]) {
  display: none;
}
