:root {
  --bg: #f6f3ea;
  --bg-warm: #faf7f0;
  --ink: #172f34;
  --ink-soft: #486268;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(31, 68, 76, 0.14);
  --accent: #085a63;
  --accent-2: #d07a34;
  --accent-3: #2f9b7d;
  --serif: "Libre Baskerville", "Georgia", "Times New Roman", serif;
  --sans: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

/* --- About grid --- */

.about-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
}

@media (max-width: 800px) {
  .about-grid { grid-template-columns: 1fr; }
}

.about-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.5rem 1.6rem;
}

.about-card h3 {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.9rem;
}

.about-card p {
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.75;
  color: var(--ink-soft);
  margin: 0;
}

/* --- Footer --- */

.site-footer {
  width: min(1200px, calc(100% - 1.2rem));
  margin: 0 auto 2.5rem;
  padding: 1.5rem 0 0;
  border-top: 1px solid var(--line);
}

.footer-disclaimer {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 0.75rem;
}

.footer-meta {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin: 0;
}

.footer-meta a {
  color: var(--accent);
  text-decoration: none;
}

.footer-meta a:hover {
  text-decoration: underline;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--serif);
  color: var(--ink);
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 40px,
      rgba(139, 119, 86, 0.018) 40px,
      rgba(139, 119, 86, 0.018) 41px
    ),
    radial-gradient(circle at 15% 10%, #fce7b0 0%, transparent 29%),
    radial-gradient(circle at 82% 85%, #c8eadf 0%, transparent 34%),
    var(--bg);
}

.bg-shape {
  display: none;
}

.s1 {
  width: 340px;
  height: 340px;
  top: -140px;
  right: -80px;
  background: #f7c55f;
}

.s2 {
  width: 420px;
  height: 420px;
  left: -140px;
  bottom: -190px;
  background: #7fcdb8;
}

.page {
  width: min(1200px, calc(100% - 1.2rem));
  margin: 1.2rem auto 2.5rem;
  position: relative;
  z-index: 2;
}

/* --- Typography --- */

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.015em;
}

.hero-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.72rem;
}

.beta-tag {
  border: 1px solid rgba(208, 122, 52, 0.36);
  border-radius: 4px;
  padding: 0.12rem 0.42rem 0.1rem;
  background: rgba(208, 122, 52, 0.09);
  color: #9a5624;
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transform: translateY(-0.18rem);
}

.subtitle {
  margin: 0.6rem 0 0;
  max-width: 68ch;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.5;
}

.hero-context {
  display: none;
}

.hero-context p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.55;
}

.refresh-rule {
  margin: 0.7rem 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.48rem;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  line-height: 1.5;
  text-transform: uppercase;
}

.refresh-rule:empty {
  display: none;
}

.refresh-rule::before {
  content: "";
  width: 28px;
  height: 1px;
  background: currentColor;
  opacity: 0.42;
}

.refresh-rule .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

.refresh-rule.error {
  color: #9f2b2b;
  letter-spacing: 0.01em;
  text-transform: none;
}

h2 {
  margin: 0 0 0.7rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
}

h3 {
  margin: 0.8rem 0 0.5rem;
  font-family: var(--serif);
  font-size: 0.92rem;
  font-weight: 700;
}

/* --- Status bar --- */

.status-wrap { margin-top: 0.9rem; }

.status {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.6);
  font-family: var(--sans);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status.error {
  border-color: rgba(173, 45, 45, 0.4);
  color: #9f2b2b;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner[hidden] {
  display: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Tabs --- */

.tabs {
  margin-top: 1.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.6rem;
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  appearance: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  padding: 0.6rem 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 400;
  letter-spacing: 0.005em;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}

.tab-btn[data-tab="admin"] {
  margin-left: auto;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.tab-panel { display: none; margin-top: 0.9rem; }
.tab-panel.active { display: block; }

/* --- Admin view frame --- */

.admin-mode .page {
  margin-top: 0.85rem;
}

.admin-mode .hero {
  padding-bottom: 0.15rem;
}

.admin-mode .subtitle,
.admin-mode .hero-context,
.admin-mode .refresh-rule,
.admin-mode .facet-filter-bar {
  display: none !important;
}

.admin-mode .tabs {
  margin-top: 0.65rem;
}

.admin-mode #tab-admin {
  margin-top: 1rem;
  opacity: 1;
  transform: none;
  animation: none;
}

.admin-mode .site-footer {
  margin-top: 2rem;
}

/* --- Facet filter bar --- */

.facet-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.85rem 0 0;
  padding: 0 0 0.8rem;
  border-bottom: 1px solid var(--line);
}
.facet-toggle {
  display: none;
}
.facet-filter-content {
  display: contents;
}
.facet-filter-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.facet-group {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.facet-label {
  font-family: var(--sans);
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
}
.facet-select {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius, 6px);
  background: var(--bg);
  color: var(--ink);
  max-width: 220px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.facet-select.is-active {
  border-color: var(--accent);
  background: rgba(8, 90, 99, 0.07);
  color: var(--accent);
  font-weight: 600;
}
.facet-filter-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
  padding-bottom: 0.1rem;
}
.facet-count {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.facet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.facet-chips:empty { display: none; }
.facet-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.45rem 0.18rem 0.65rem;
  background: var(--accent);
  color: #fff;
  font-family: var(--sans);
  font-size: 0.73rem;
  border-radius: 999px;
  line-height: 1.4;
}
.facet-chip-dim {
  font-size: 0.62rem;
  opacity: 0.72;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.facet-chip-remove {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
}
.facet-chip-remove:hover { color: #fff; }

/* --- Panels --- */

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(4px);
  box-shadow: 0 10px 26px rgba(35, 64, 70, 0.08);
  padding: 1rem;
}

.split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 0.75rem;
}

/* --- Document filter --- */

.doc-filter {
  width: 100%;
  margin-bottom: 0.55rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  padding: 0.48rem 0.6rem;
  min-height: 40px;
}

.doc-filter:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- Tables --- */

.table-wrap {
  overflow: auto;
  max-height: 70vh;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
}

th, td {
  text-align: left;
  padding: 0.58rem 0.55rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

th {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-family: var(--sans);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.doc-check-col { width: 32px; text-align: center; padding-left: 0.3rem; padding-right: 0; }
.doc-check-col input[type="checkbox"] { margin: 0; cursor: pointer; }

th.sortable[data-sort-key="title"]     { width: 34%; }
th.sortable[data-sort-key="author"]    { width: 20%; }
th.sortable[data-sort-key="year"]      { width: 7%; }
th.sortable[data-sort-key="degree"]    { width: 18%; }
th.sortable[data-sort-key="pages"]     { width: 8%; }
th.sortable[data-sort-key="wordCount"] { width: 11%; }

th.sortable {
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
}

th.sortable:hover {
  color: var(--accent);
}

th.sortable::after {
  content: '';
  display: inline-block;
  margin-left: 0.3em;
  width: 0;
  height: 0;
  vertical-align: middle;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-bottom: 4.5px solid var(--line);
}

th.sort-asc::after {
  border-bottom: 4.5px solid var(--accent);
}

th.sort-desc::after {
  border-bottom: 0;
  border-top: 4.5px solid var(--accent);
}

tbody tr:nth-child(even) {
  background: rgba(8, 90, 99, 0.025);
}

.doc-row {
  cursor: pointer;
  transition: background 0.12s;
}

.doc-row:hover {
  background: rgba(8, 90, 99, 0.06);
}

.doc-row.active {
  background: rgba(8, 90, 99, 0.10);
}

.doc-card-mobile {
  display: none;
}

.document-page-status td {
  color: var(--ink-soft);
  font-family: var(--sans);
  text-align: center;
  background: var(--panel);
}

/* --- Document modal --- */

.doc-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 47, 52, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.doc-modal-overlay[hidden] {
  display: none;
}

.doc-modal {
  position: relative;
  max-width: 720px;
  width: calc(100% - 2rem);
  max-height: 85vh;
  overflow-y: auto;
}

.doc-modal h2 {
  padding-right: 2rem;
}

.doc-modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: background 0.12s;
}

.doc-modal-close:hover {
  background: rgba(8, 90, 99, 0.08);
}

/* --- Phone detail/results screen --- */

.phone-screen {
  display: none;
}

.phone-screen[hidden] {
  display: none !important;
}

body.phone-screen-open {
  overflow: hidden;
}

/* --- Detail panel --- */

.detail-body {
  display: grid;
  gap: 1.2rem;
}

.detail-section-title {
  font-size: 0.88rem;
  font-family: var(--serif);
  font-weight: 700;
  margin: 0 0 0.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
}

.detail-abstract {
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--ink-soft);
  max-height: 30vh;
  overflow-y: auto;
  position: relative;
  mask-image: linear-gradient(to bottom, #000 85%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 85%, transparent 100%);
}

.detail-abstract p {
  margin: 0 0 0.5rem;
}

.meta {
  margin: 0;
  display: grid;
  gap: 0.3rem;
}

.meta p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.token {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0.2rem 0.52rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
}

.token.concept {
  background: rgba(47, 155, 125, 0.10);
  border-color: rgba(47, 155, 125, 0.35);
  color: #1a6b50;
}

.token.topic {
  background: rgba(75, 115, 195, 0.10);
  border-color: rgba(75, 115, 195, 0.35);
  color: #2b4f8a;
}

.token.clickable {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.token.concept.clickable:hover {
  background: rgba(47, 155, 125, 0.22);
  border-color: rgba(47, 155, 125, 0.55);
}
.token.topic.clickable:hover {
  background: rgba(75, 115, 195, 0.22);
  border-color: rgba(75, 115, 195, 0.55);
}

/* --- Document detail subtitle & actions --- */

.doc-subtitle {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.doc-actions .btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.detail-download-note {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-style: italic;
}

/* --- Detail metadata grid --- */

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-family: var(--sans);
  font-size: 0.84rem;
}

.detail-meta-label {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.detail-meta-value {
  color: var(--ink);
}

/* --- Citations disclosure --- */

.citations-details summary {
  font-family: var(--serif);
  font-size: 0.88rem;
  font-weight: 700;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  cursor: pointer;
  list-style: revert;
}

.citations-details summary:hover {
  opacity: 0.8;
}

.related-list {
  display: grid;
  gap: 0.45rem;
}

.person-role-group {
  display: grid;
  gap: 0.5rem;
}

.person-role-group + .person-role-group {
  margin-top: 0.85rem;
}

.person-role-group-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.person-role-group-heading span:first-child {
  color: var(--ink);
  font-weight: 700;
}

.related-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.52rem;
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: box-shadow 0.12s;
}

.related-item:hover {
  box-shadow: 0 2px 8px rgba(35, 64, 70, 0.12);
}

.related-item strong {
  display: block;
  font-family: var(--serif);
  font-size: 0.88rem;
}

.related-item p {
  margin: 0.2rem 0 0;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* --- KPIs --- */

.kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.kpi {
  flex: 1 1 0;
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.82);
}

.kpi p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 0.78rem;
  font-style: italic;
}

.kpi strong {
  display: block;
  margin-top: 0.3rem;
  font-family: var(--sans);
  font-size: 1.1rem;
  font-weight: 700;
}

.kpi-range {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* --- Shared sub-tabs (analytics, citations) --- */

.sub-tabs {
  display: flex;
  gap: 1.2rem;
  margin-top: 1rem;
  margin-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.sub-tab-btn {
  appearance: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.2rem;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.sub-tab-btn:hover { color: var(--ink); }

.sub-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.analytics-tab-section { display: none; }
.analytics-tab-section.active { display: block; }

/* --- Scatter plot --- */

.scatter-tooltip {
  position: absolute;
  padding: 0.5rem 0.7rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  font-family: var(--sans);
  font-size: 0.78rem;
  max-width: 280px;
  pointer-events: none;
  z-index: 10;
}

.scatter-tooltip .tooltip-title {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.scatter-tooltip .tooltip-meta {
  color: var(--ink-soft);
  font-size: 0.72rem;
}

/* --- Network graph --- */

.net-node { cursor: pointer; }
.net-node:hover { filter: brightness(1.2); }
.net-edge { pointer-events: none; }
.net-label {
  font-family: var(--sans);
  font-size: 9px;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
}

.scatter-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
  padding: 0.3rem;
}

.scatter-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.scatter-legend-item.dimmed { opacity: 0.3; }
.scatter-legend-item.is-active { color: var(--ink); font-weight: 600; text-decoration: underline; }

.scatter-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* --- Analytics --- */

.analytics-grid {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1.15fr 0.85fr;
  align-items: start;
}
.analytics-left {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.analytics-right {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#tab-analytics.analytics-refreshing {
  cursor: progress;
}

#tab-analytics.analytics-refreshing .analytics-tab-section.active .panel,
#tab-analytics.analytics-refreshing .kpi {
  position: relative;
  overflow: hidden;
}

#tab-analytics.analytics-refreshing .analytics-tab-section.active .panel > *,
#tab-analytics.analytics-refreshing .kpi > * {
  opacity: 0;
  pointer-events: none;
}

#tab-analytics.analytics-refreshing .analytics-tab-section.active .panel::after,
#tab-analytics.analytics-refreshing .kpi::after {
  content: "";
  position: absolute;
  inset: 1rem;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(244, 241, 234, 0), rgba(255, 255, 255, 0.78), rgba(244, 241, 234, 0)) 0 0 / 220% 100%,
    linear-gradient(rgba(220, 226, 221, 0.9), rgba(220, 226, 221, 0.9)) 0 0.2rem / 42% 0.8rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.95), rgba(231, 222, 207, 0.95)) 0 2.1rem / 88% 1.2rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.78), rgba(231, 222, 207, 0.78)) 0 4.1rem / 72% 1.2rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.62), rgba(231, 222, 207, 0.62)) 0 6.1rem / 54% 1.2rem no-repeat;
  animation: analytics-skeleton-shimmer 1.15s ease-in-out infinite;
  pointer-events: none;
}

#tab-analytics.analytics-refreshing .kpis:empty {
  min-height: 92px;
  position: relative;
}

#tab-analytics.analytics-refreshing .kpis:empty::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(90deg, rgba(244, 241, 234, 0), rgba(255, 255, 255, 0.78), rgba(244, 241, 234, 0)) 0 0 / 220% 100%,
    linear-gradient(rgba(220, 226, 221, 0.9), rgba(220, 226, 221, 0.9)) 1rem 1rem / 26% 0.8rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.95), rgba(231, 222, 207, 0.95)) 1rem 2.5rem / 18% 1.4rem no-repeat,
    linear-gradient(rgba(220, 226, 221, 0.9), rgba(220, 226, 221, 0.9)) 38% 1rem / 26% 0.8rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.95), rgba(231, 222, 207, 0.95)) 38% 2.5rem / 18% 1.4rem no-repeat,
    linear-gradient(rgba(220, 226, 221, 0.9), rgba(220, 226, 221, 0.9)) 74% 1rem / 20% 0.8rem no-repeat,
    linear-gradient(rgba(231, 222, 207, 0.95), rgba(231, 222, 207, 0.95)) 74% 2.5rem / 16% 1.4rem no-repeat;
  animation: analytics-kpi-skeleton-shimmer 1.15s ease-in-out infinite;
}

@keyframes analytics-skeleton-shimmer {
  0% { background-position: -180% 0, 0 0.2rem, 0 2.1rem, 0 4.1rem, 0 6.1rem; }
  100% { background-position: 180% 0, 0 0.2rem, 0 2.1rem, 0 4.1rem, 0 6.1rem; }
}

@keyframes analytics-kpi-skeleton-shimmer {
  0% { background-position: -180% 0, 1rem 1rem, 1rem 2.5rem, 38% 1rem, 38% 2.5rem, 74% 1rem, 74% 2.5rem; }
  100% { background-position: 180% 0, 1rem 1rem, 1rem 2.5rem, 38% 1rem, 38% 2.5rem, 74% 1rem, 74% 2.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  #tab-analytics.analytics-refreshing .analytics-tab-section.active .panel::after,
  #tab-analytics.analytics-refreshing .kpi::after,
  #tab-analytics.analytics-refreshing .kpis:empty::before {
    animation: none;
  }
}

.axis {
  font-size: 11px;
  font-family: var(--sans);
  fill: #4a6970;
}

.word-cloud {
  min-height: 320px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.35rem 0.5rem;
  padding: 0.3rem;
}

.cloud-term {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  line-height: 1.15;
  font-family: var(--sans);
  color: var(--ink);
  transition: opacity 0.12s;
}

.cloud-term:hover {
  opacity: 0.7;
}

.cloud-term.active {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.theme-results {
  margin-top: 0.8rem;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}

.theme-results p {
  margin: 0 0 0.5rem;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

/* --- Subject bars --- */

.bars { margin-top: 0.15rem; display: grid; gap: 0.46rem; }

.bar-row {
  display: grid;
  gap: 0.42rem;
  grid-template-columns: minmax(120px, 1fr) 2.2fr auto;
  align-items: center;
}

.bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--sans);
  font-size: 0.82rem;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(8, 90, 99, 0.10);
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

.bar-value {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.bar-value:hover {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

/* --- Heatmap --- */

.heatmap-table {
  --heatmap-label-width: 10rem;
  --heatmap-col-width: 6rem;
  --heatmap-header-height: 7.2rem;
  border-collapse: collapse;
  width: max-content;
  font-family: var(--sans);
  table-layout: fixed;
}

.heatmap-table th,
.heatmap-table td {
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--line);
  font-size: 0.75rem;
}

.heatmap-table .heatmap-header {
  width: var(--heatmap-col-width);
  min-width: var(--heatmap-col-width);
  max-width: var(--heatmap-col-width);
  height: var(--heatmap-header-height);
  padding: 0.45rem 0.35rem;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: #fff;
  white-space: normal;
  vertical-align: bottom;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.72rem;
  letter-spacing: 0;
  line-height: 1.12;
  text-transform: none;
  overflow: hidden;
}

.heatmap-table .heatmap-header-label {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: calc(var(--heatmap-header-height) - 1.1rem);
  overflow-wrap: normal;
  text-align: center;
}

.heatmap-table .heatmap-label {
  width: var(--heatmap-label-width);
  min-width: var(--heatmap-label-width);
  max-width: var(--heatmap-label-width);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  color: var(--ink-soft);
}

.heatmap-table tr > :first-child {
  width: var(--heatmap-label-width);
  min-width: var(--heatmap-label-width);
  max-width: var(--heatmap-label-width);
}

.heatmap-table .heatmap-cell {
  width: var(--heatmap-col-width);
  min-width: var(--heatmap-col-width);
  max-width: var(--heatmap-col-width);
  height: 2.25rem;
  padding: 0;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
}

.heatmap-cell-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.heatmap-cell-btn:hover {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

/* --- Forms --- */

.query-grid {
  display: grid;
  gap: 0.9rem;
}

.settings-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  margin: 0;
  min-width: 0;
}

.settings-section legend {
  padding: 0 0.35rem;
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.settings-grid {
  display: grid;
  gap: 0.62rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-grid.four-col {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.job-controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.85rem;
  margin-bottom: 0.9rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.query-grid label,
.settings-section label {
  display: grid;
  gap: 0.22rem;
}

.query-grid label span,
.settings-section label span {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.settings-section label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-section label.checkbox-row input {
  width: auto;
  margin: 0;
}

.settings-grid .full { grid-column: 1 / -1; }

.settings-actions {
  display: grid;
  gap: 0.85rem;
}

.action-block {
  display: grid;
  gap: 0.45rem;
}

.action-block h3 {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.settings-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.1rem;
}

.settings-status-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  padding: 0.65rem 0.75rem;
  font-family: var(--sans);
  color: var(--ink-soft);
}

.settings-status-title {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.settings-status-main {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
}

.settings-status-detail {
  margin: 0.22rem 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.settings-status-detail + .settings-status-detail {
  margin-top: 0.12rem;
}

.import-rules-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 0.7fr) minmax(0, 1.6fr);
  gap: 1rem;
  align-items: start;
}

.import-rules-list,
.import-rule-editor {
  min-width: 0;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.section-heading-row h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.05rem;
}

.import-rule-list {
  display: grid;
  gap: 0.45rem;
}

.import-rule-card {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  padding: 0.5rem 0.6rem;
}

.import-rule-card:hover,
.import-rule-card.active {
  border-color: var(--accent);
  background: white;
}

.import-rule-check {
  padding-top: 0.1rem;
}

.import-rule-check input {
  min-height: 0;
}

.import-rule-open {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
  min-width: 0;
}

.import-rule-card strong {
  display: block;
  font-family: var(--sans);
  font-size: 0.88rem;
}

.import-rule-card span {
  display: block;
  margin-top: 0.2rem;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.76rem;
  line-height: 1.35;
}

.import-scope-row {
  display: grid;
  max-width: 18rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.generated-query {
  min-height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  font-family: monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.advanced-options summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--accent);
}

.advanced-options[open] summary {
  margin-bottom: 0.45rem;
}

.import-actions {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.import-action-toolbar,
.import-maintenance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.import-run-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.import-action-card {
  appearance: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  min-height: 4.1rem;
  padding: 0.78rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 0 rgba(18, 52, 59, 0.04);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.import-action-card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(18, 52, 59, 0.08);
  transform: translateY(-1px);
}

.import-action-card.primary {
  border-color: rgba(18, 128, 140, 0.55);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(230, 249, 247, 0.9));
}

.import-action-card:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.import-action-title {
  min-width: 0;
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
}

.import-action-meta {
  justify-self: end;
  max-width: 9rem;
  border-radius: 999px;
  background: rgba(18, 128, 140, 0.08);
  color: var(--accent);
  padding: 0.26rem 0.48rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

.import-preview {
  margin-top: 0.85rem;
  font-family: var(--sans);
}

.import-preview-list {
  margin: 0.45rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.35rem;
}

.import-preview-list li {
  border-top: 1px solid var(--line);
  padding-top: 0.35rem;
}

.import-warning {
  margin: 0.4rem 0 0;
  color: #8a4b12;
}

input, select {
  font-family: var(--sans);
  font-size: 0.88rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  padding: 0.52rem 0.6rem;
  min-height: 44px;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 0.58rem 1rem;
  background: linear-gradient(120deg, var(--accent), #12808c);
  color: white;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  transition: opacity 0.12s;
}

.btn:hover { opacity: 0.9; }

.btn.ghost {
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent);
  border: 1px solid var(--line);
}

.btn-sm {
  padding: 0.38rem 0.7rem;
  font-size: 0.82rem;
  min-height: 36px;
}

.btn:disabled { opacity: 0.6; cursor: wait; }

.btn.danger {
  background: #c0392b;
}

.btn.danger:hover { opacity: 0.9; }

/* --- Section rules --- */

.section-rule {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1rem 0;
}

/* --- Admin --- */

.login-panel {
  max-width: 400px;
  margin-top: 0.2rem;
  padding: 1.25rem;
}

.login-form, .create-user-form, .mfa-setup-card {
  display: grid;
  gap: 0.55rem;
}

.login-form[hidden],
.create-user-form[hidden],
.admin-panel-section[hidden],
.login-panel[hidden] {
  display: none;
}

.login-form label, .create-user-form label {
  display: grid;
  gap: 0.22rem;
}

.login-form label span, .create-user-form label span {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.secret-code {
  display: block;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.form-error {
  font-family: var(--sans);
  font-size: 0.82rem;
  color: #9f2b2b;
  padding: 0.3rem 0;
}

.reset-link-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 0.7rem;
  font-family: var(--sans);
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.reset-link-result p {
  margin: 0 0 0.5rem;
}

.reset-link-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.reset-link-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 0.82rem;
}

.mfa-setup-card {
  margin-top: 0.45rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.mfa-setup-card label {
  display: grid;
  gap: 0.22rem;
}

.mfa-setup-card label span {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  padding: 0.2rem 0 0.7rem;
  border-bottom: 1px solid var(--line);
}

.admin-user-label {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.admin-tab-btn {
  appearance: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  padding: 0.45rem 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-soft);
  cursor: pointer;
  min-height: 36px;
  transition: border-color 0.12s, color 0.12s;
}

.admin-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.admin-panel-section { display: none; }
.admin-panel-section.active { display: block; }

.cache-stats {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.cache-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-width: 13rem;
}

.job-progress {
  margin-top: 0.4rem;
  font-family: var(--sans);
}

.job-progress-current {
  color: var(--ink);
  font-weight: 700;
  font-size: 0.8rem;
}

.job-progress-steps {
  display: grid;
  gap: 0.25rem;
  margin-top: 0.3rem;
}

.job-progress-step {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem 0.45rem;
  align-items: baseline;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.job-progress-step span {
  min-width: 4.8rem;
  color: var(--accent);
  font-weight: 700;
  text-transform: capitalize;
}

.job-progress-step.completed span {
  color: #347a45;
}

.job-progress-step strong {
  color: var(--ink);
  font-size: 0.76rem;
}

.job-progress-step em,
.job-progress-step small {
  font-style: normal;
}

/* --- Links --- */

a {
  color: var(--accent-2);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent);
}

/* --- Animations --- */

.reveal {
  opacity: 0;
  transform: translateY(8px);
  animation: reveal 520ms ease forwards;
}

@keyframes reveal {
  to { opacity: 1; transform: translateY(0); }
}

.citation-tab-section { display: none; }
.citation-tab-section.active { display: block; }

/* --- Citation Explorer --- */

.citations-explorer {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr);
  gap: 0.75rem;
  align-items: start;
}

.citations-list-col,
.citations-detail-col {
  min-width: 0;
}

.citations-list-col .panel,
.citations-detail-col .panel {
  min-width: 0;
}

.citations-list-col .table-wrap { max-height: 78vh; }

.citations-detail-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.citation-entries { max-height: 78vh; overflow-y: auto; overflow-x: hidden; }

.citation-entry {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1.4;
  overflow-wrap: anywhere;
  min-width: 0;
}

.citation-entry:hover { background: rgba(8, 90, 99, 0.06); }

.citation-entry-check {
  flex-shrink: 0;
  margin-top: 0.15rem;
  cursor: pointer;
}

.citation-select-all {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.citation-select-all label { cursor: pointer; }
.citation-select-all input { margin-right: 0.3rem; vertical-align: middle; cursor: pointer; }

.citation-entry .shared-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.4rem;
}

.citation-entry .citation-count {
  display: inline-block;
  min-width: 1.55rem;
  text-align: center;
  background: rgba(8, 90, 99, 0.08);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.08rem 0.35rem;
  margin-left: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
}

.catalogue-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.08rem 0.4rem;
  margin-left: 0.35rem;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 700;
  vertical-align: middle;
  white-space: nowrap;
}

.catalogue-badge.held {
  background: rgba(47, 155, 125, 0.14);
  color: #1a7a5a;
}

.catalogue-badge.not-held {
  background: rgba(192, 57, 43, 0.08);
  color: #9f5b53;
}

a.catalogue-badge {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

a.catalogue-badge:hover {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.summon-modal-overlay { z-index: 200; }

.summon-result-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 0.2rem;
}

.summon-result-item:last-of-type { border-bottom: none; }

.summon-result-title {
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
}

.summon-result-title a {
  color: var(--accent);
  text-decoration: none;
}

.summon-result-title a:hover { text-decoration: underline; }

.summon-result-meta {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.summon-result-snippet {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
  line-height: 1.45;
}

.summon-result-footer {
  margin-top: 1.2rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.summon-result-footer a {
  color: var(--accent);
  text-decoration: none;
}

.summon-result-footer a:hover { text-decoration: underline; }

button.summon-check-btn {
  border: 1px solid rgba(8, 90, 99, 0.35);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

button.summon-check-btn:hover:not(:disabled) {
  background: rgba(8, 90, 99, 0.07);
}

button.summon-check-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.citation-docs-table {
  table-layout: fixed;
  width: 100%;
}

.citation-docs-table th:nth-child(2),
.citation-docs-table td:nth-child(2) {
  width: 28%;
}

.citation-docs-table th:nth-child(3),
.citation-docs-table td:nth-child(3) {
  width: 70px;
}

.citation-docs-table th:nth-child(4),
.citation-docs-table td:nth-child(4) {
  width: 64px;
}

.citation-docs-table td:first-child {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.citation-doc-row { cursor: pointer; transition: background 0.12s; }
.citation-doc-row:hover { background: rgba(8, 90, 99, 0.06); }
.citation-doc-row.active { background: rgba(8, 90, 99, 0.10); }
.citation-doc-row.greyed td { color: var(--ink-soft); opacity: 0.5; }

/* --- Timeline legend --- */

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin-top: 0.5rem;
  padding: 0.3rem;
}

.timeline-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.timeline-legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* --- Foundational works --- */

.foundational-works-list {
  max-height: 40vh;
  overflow-y: auto;
}

.foundational-work-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.4;
}

.foundational-work-item:hover {
  background: rgba(8, 90, 99, 0.06);
}

.fw-rank-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 1.6rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.fw-text {
  flex: 1;
  min-width: 0;
}

/* --- Topic labels --- */

.topic-label {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.topic-terms {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-style: italic;
  margin-top: 0.15rem;
}

/* --- Research gap fill --- */

.bar-fill.gap-fill {
  background: linear-gradient(90deg, #d07a34, #e6a54c);
}

/* --- Supervisor link --- */

.supervisor-link {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

.supervisor-link:hover {
  color: var(--accent-2);
}

/* --- Export row --- */

.export-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

/* --- Person Explorer --- */

.people-explorer {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr);
  gap: 0.75rem;
  align-items: start;
}

.people-list-col,
.people-detail-col {
  min-width: 0;
}

.people-filter-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin: 0 0 0.55rem;
}

.people-detail-col {
  position: sticky;
  top: 1rem;
}

.people-explorer td .token-list {
  gap: 0.3rem 0.35rem;
  padding: 0.15rem 0;
}

.people-detail-col .detail-body {
  margin-top: 0.9rem;
}

/* --- Responsive SVG --- */

svg[viewBox] {
  width: 100%;
  height: auto;
  display: block;
}

#topicClusterChart {
  width: 100%;
  height: auto;
  aspect-ratio: 940 / 600;
  display: block;
  touch-action: none;
}

/* --- Responsive --- */

@media (max-width: 1020px) {
  .analytics-grid { grid-template-columns: 1fr; }
  .kpis { gap: 0.5rem; }
  .citations-explorer { grid-template-columns: 1fr; }
  .people-explorer { grid-template-columns: 1fr; }
  .import-rules-layout { grid-template-columns: 1fr; }
  .people-detail-col { position: static; }
}

@media (max-width: 800px) {
  .hero-context { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body {
    padding-bottom: calc(4.6rem + env(safe-area-inset-bottom));
  }

  .page {
    width: min(100% - 0.8rem, 1200px);
    margin-top: 0.65rem;
    margin-bottom: 1.2rem;
  }

  .hero {
    padding: 0.2rem 0 0;
  }

  .hero-title-row {
    align-items: center;
  }

  .hero h1 {
    font-size: 1.45rem;
    letter-spacing: 0;
  }

  .subtitle {
    margin-top: 0.35rem;
    font-size: 0.82rem;
    line-height: 1.4;
  }

  .hero-context {
    display: none;
  }

  .refresh-rule {
    margin-top: 0.45rem;
    gap: 0.34rem;
    font-size: 0.61rem;
    letter-spacing: 0.06em;
  }

  .refresh-rule::before {
    display: none;
  }

  .status-wrap {
    margin-top: 0.55rem;
  }

  .tabs {
    position: fixed;
    z-index: 150;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 0.38rem max(0.28rem, env(safe-area-inset-left)) max(0.5rem, env(safe-area-inset-bottom)) max(0.28rem, env(safe-area-inset-right));
    border-top: 1px solid rgba(31, 68, 76, 0.16);
    border-bottom: 0;
    background: rgba(250, 247, 240, 0.96);
    box-shadow: 0 -10px 26px rgba(31, 68, 76, 0.12);
    backdrop-filter: blur(12px);
  }

  .tab-btn,
  .tab-btn[data-tab="admin"] {
    min-width: 0;
    min-height: 42px;
    margin: 0;
    padding: 0.36rem 0.12rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink-soft);
    font-size: 0;
    line-height: 1;
    text-align: center;
  }

  .tab-btn::after {
    content: attr(data-mobile-label);
    display: block;
    overflow: hidden;
    font-family: var(--sans);
    font-size: 0.64rem;
    font-weight: 700;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tab-btn.active {
    border-color: rgba(8, 90, 99, 0.18);
    background: rgba(8, 90, 99, 0.10);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
  }

  .tab-panel {
    margin-top: 0.65rem;
  }

  .settings-grid,
  .settings-grid.four-col,
  .settings-status-grid,
  .job-controls-grid,
  .import-rules-layout,
  .import-run-actions { grid-template-columns: 1fr; }
  .import-action-card {
    min-height: 3.7rem;
  }
  .kpis { flex-direction: column; }
  .bar-row { grid-template-columns: 1fr; }
  .admin-tabs { gap: 0.3rem; }
  .heatmap-table {
    --heatmap-label-width: 6.5rem;
    --heatmap-col-width: 5.2rem;
    --heatmap-header-height: 7.4rem;
    font-size: 0.7rem;
  }
  .heatmap-label,
  .heatmap-table tr > :first-child { width: 6.5rem; min-width: 6.5rem; max-width: 6.5rem; }

  /* Facet filters: collapsed mobile disclosure. */
  .facet-filter-bar {
    gap: 0.5rem;
    margin-top: 0.6rem;
    padding: 0.55rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
  }

  .facet-toggle {
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 7px;
    padding: 0.55rem 0.62rem;
    background: rgba(8, 90, 99, 0.08);
    color: var(--accent);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 800;
    text-align: left;
  }

  .facet-toggle::after {
    content: '';
    width: 0.48rem;
    height: 0.48rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-0.12rem);
    transition: transform 0.16s;
  }

  .facet-filter-bar.is-open .facet-toggle::after {
    transform: rotate(225deg) translate(-0.1rem, -0.02rem);
  }

  .facet-toggle-summary {
    margin-left: auto;
    overflow: hidden;
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .facet-filter-content {
    display: none;
  }

  .facet-filter-bar.is-open .facet-filter-content {
    display: grid;
    gap: 0.55rem;
  }

  .facet-filter-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.58rem;
  }

  .facet-select {
    width: 100%;
    max-width: none;
    min-height: 40px;
    font-size: 0.86rem;
    background: rgba(250, 247, 240, 0.95);
  }

  .facet-filter-right {
    justify-content: space-between;
    margin-left: 0;
    padding-top: 0.12rem;
  }

  /* Document Explorer: use touch cards instead of a compressed table. */
  #tab-records .table-wrap {
    overflow: visible;
    max-height: none;
  }
  #tab-records table,
  #tab-records tbody {
    display: block;
  }
  #tab-records thead {
    display: none;
  }
  #tab-records .doc-row {
    display: block;
    margin-bottom: 0.55rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.78);
    padding: 0.72rem 0.78rem;
    box-shadow: 0 2px 8px rgba(35, 64, 70, 0.06);
  }
  #tab-records .doc-row.active {
    border-color: rgba(8, 90, 99, 0.32);
    background: rgba(8, 90, 99, 0.07);
  }
  #tab-records .doc-row td {
    display: none;
    border: 0;
    padding: 0;
  }
  #tab-records .doc-row .doc-title-cell {
    display: grid;
    gap: 0.18rem;
  }
  .doc-title-text {
    display: block;
    font-family: var(--serif);
    font-size: 0.94rem;
    line-height: 1.35;
    color: var(--ink);
  }
  .doc-card-mobile {
    display: block;
    font-family: var(--sans);
    font-size: 0.76rem;
    line-height: 1.35;
    color: var(--ink-soft);
  }
  .document-page-status {
    display: block;
  }
  .document-page-status td {
    display: block;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.7rem;
  }

  /* Tighter table cells outside the card list. */
  th, td { padding: 0.4rem 0.35rem; font-size: 0.78rem; }

  .sub-tab-btn { font-size: 0.78rem; }

  /* Tooltip width cap */
  .scatter-tooltip { max-width: min(280px, 85vw); }

  /* SVG chart containers: horizontal scroll fallback */
  .panel > svg[viewBox] { min-width: 0; }

  .table-wrap {
    position: relative;
  }

  .table-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(90deg, transparent, rgba(246, 243, 234, 0.6));
    pointer-events: none;
  }

  .doc-modal-overlay {
    display: none !important;
  }

  .phone-screen {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--bg-warm);
    color: var(--ink);
  }

  .phone-screen-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
    padding: max(0.8rem, env(safe-area-inset-top)) 0.85rem 0.75rem;
    border-bottom: 1px solid var(--line);
    background: rgba(250, 247, 240, 0.96);
    backdrop-filter: blur(8px);
  }

  .phone-screen-back {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--accent);
    font-family: var(--sans);
    font-size: 0.84rem;
    font-weight: 700;
    padding: 0.38rem 0.62rem;
  }

  .phone-screen-title-block {
    min-width: 0;
  }

  .phone-screen-eyebrow {
    margin: 0 0 0.14rem;
    overflow: hidden;
    color: var(--ink-soft);
    font-family: var(--sans);
    font-size: 0.68rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
  }

  .phone-screen-title-block h2 {
    margin: 0;
    display: -webkit-box;
    overflow: hidden;
    font-size: 1rem;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .phone-screen-body {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.9rem 0.85rem max(1.25rem, env(safe-area-inset-bottom));
  }

  .phone-screen-body .detail-body,
  .phone-screen-body .summon-phone-body {
    display: grid;
    gap: 1rem;
  }

  .phone-screen-body .citation-entries {
    max-height: none;
    overflow: visible;
  }

  .phone-screen-body .doc-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
    padding: 0.45rem 0;
  }

  .phone-screen-body .doc-actions .btn {
    justify-content: center;
    min-height: 42px;
  }

  .phone-screen-body .detail-meta {
    grid-template-columns: 1fr;
    gap: 0.12rem 0;
  }

  .phone-screen-body .detail-meta-label {
    margin-top: 0.45rem;
  }

  .phone-screen-body .detail-abstract {
    max-height: none;
    overflow: visible;
    mask-image: none;
    -webkit-mask-image: none;
  }

  .phone-screen-body .related-item {
    padding: 0.7rem;
  }
}

.topic-label-toolbar {
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) minmax(10rem, 0.35fr) minmax(15rem, 0.55fr);
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.85rem;
}

.topic-label-toolbar label {
  display: grid;
  gap: 0.22rem;
}

.topic-label-toolbar label span {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.topic-label-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.topic-label-summary-card {
  min-height: 3.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font-family: var(--sans);
  background: rgba(255, 255, 255, 0.55);
}

.topic-label-summary-card span {
  display: block;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.topic-label-summary-card strong {
  display: block;
  margin-top: 0.1rem;
  color: var(--ink);
  font-size: 1.12rem;
}

.topic-label-summary-card.attention strong {
  color: #9f5b1d;
}

.topic-label-workspace {
  display: grid;
  grid-template-columns: minmax(19rem, 0.95fr) minmax(0, 1.55fr);
  gap: 0.9rem;
  align-items: start;
}

.topic-label-list-panel,
.topic-label-detail-panel {
  min-width: 0;
}

.topic-label-list-panel {
  border-right: 1px solid var(--line);
  padding-right: 0.9rem;
}

.section-heading-row.compact {
  margin-bottom: 0.4rem;
}

.section-heading-row.compact h3,
.section-heading-row.compact h4 {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.topic-label-list {
  display: grid;
  gap: 0.35rem;
  max-height: 68vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.topic-label-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: center;
  border: 1px solid rgba(45, 74, 82, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  padding: 0.55rem 0.62rem;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.topic-label-row:hover,
.topic-label-row.active {
  border-color: rgba(8, 90, 99, 0.35);
  background: rgba(8, 90, 99, 0.06);
}

.topic-label-row-main {
  min-width: 0;
  display: grid;
  gap: 0.16rem;
}

.topic-label-row-main strong {
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.84rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-label-row-main small {
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-label-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.4rem;
  border-radius: 999px;
  padding: 0.18rem 0.42rem;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topic-label-status.ready {
  background: rgba(47, 155, 125, 0.12);
  color: #25724f;
}

.topic-label-status.pending,
.topic-label-status.warning {
  background: rgba(208, 122, 52, 0.14);
  color: #8a4b12;
}

.topic-label-status.locked {
  background: rgba(8, 90, 99, 0.12);
  color: var(--accent);
}

.topic-label-detail-panel {
  position: sticky;
  top: 0.75rem;
  display: grid;
  gap: 0.9rem;
  font-family: var(--sans);
}

.topic-label-detail-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.topic-label-detail-header h3 {
  margin: 0.08rem 0 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.25;
}

.topic-label-warning-list,
.topic-label-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.topic-label-warning-list span,
.topic-label-chip-list span {
  border-radius: 999px;
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
  line-height: 1.2;
}

.topic-label-warning-list span {
  background: rgba(192, 57, 43, 0.08);
  color: #9f5b53;
}

.topic-label-chip-list span {
  background: rgba(8, 90, 99, 0.08);
  color: var(--accent);
}

.topic-label-manual-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: end;
}

.topic-label-detail-section {
  display: grid;
  gap: 0.5rem;
}

.topic-label-detail-section h4 {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topic-label-candidates {
  display: grid;
  gap: 0.45rem;
}

.topic-label-candidate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem 0.65rem;
  align-items: center;
  padding: 0.55rem 0.6rem;
  border: 1px solid rgba(45, 74, 82, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
}

.topic-label-candidate.selected {
  border-color: rgba(47, 155, 125, 0.38);
  background: rgba(47, 155, 125, 0.06);
}

.topic-label-candidate strong {
  display: block;
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.35;
}

.topic-label-candidate small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.35;
}

.topic-label-candidate .topic-label-candidate-warning {
  color: #9f5b53;
}

.topic-label-title-list {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding-left: 1.05rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1.45;
}

@media (max-width: 1020px) {
  .topic-label-toolbar { grid-template-columns: 1fr 1fr; }
  .topic-label-summary { grid-column: 1 / -1; }
  .topic-label-workspace { grid-template-columns: 1fr; }
  .topic-label-list-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 0.85rem;
  }
  .topic-label-list { max-height: 22rem; }
  .topic-label-detail-panel { position: static; }
}

@media (max-width: 680px) {
  .topic-label-toolbar,
  .topic-label-summary,
  .topic-label-manual-edit {
    grid-template-columns: 1fr;
  }
  .topic-label-summary { grid-column: auto; }
  .topic-label-detail-header {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.3rem; }
  .subtitle { font-size: 0.85rem; }
  .kpis { gap: 0.3rem; }
  .panel { padding: 0.7rem; }
}

.people-provenance-notice {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.research-area-list {
  display: grid;
  gap: 0.5rem;
}

.research-area-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 0.6fr);
  gap: 0.75rem;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: rgba(255, 255, 255, 0.55);
}

.research-area-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.6rem;
  align-items: baseline;
  font-family: var(--sans);
}

.research-area-children {
  margin: 0.25rem 0 0;
}

.research-area-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.research-area-edit input {
  flex: 1 1 10rem;
  min-width: 0;
}

@media (max-width: 760px) {
  .research-area-row { grid-template-columns: 1fr; }
}
