:root {
  color-scheme: light;
  --page: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --line: #d4dee6;
  --text: #172b3a;
  --muted: #526779;
  --accent: #086b61;
  --accent-strong: #07564f;
  --accent-soft: #e3f3f0;
  --positive: #176b3d;
  --positive-soft: #e8f5ec;
  --negative: #a32439;
  --negative-soft: #fbecef;
  --caution: #845300;
  --caution-soft: #fff4dc;
  --blue: #255e9b;
  --radius: 16px;
  --shadow: 0 8px 24px rgb(23 43 58 / 5%);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }

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

button, input, select { font: inherit; }

:focus-visible {
  outline: 3px solid #16887c;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 12px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 700;
}

.skip-link:focus { transform: translateY(0); color: #fff; }

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

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  gap: 24px;
  padding: 12px max(24px, calc((100vw - 1280px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 2px 10px rgb(23 43 58 / 3%);
}

.brand { display: flex; flex: 0 0 auto; align-items: center; gap: 11px; }

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: 700 21px Georgia, serif;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }

.nav { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.nav a {
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.nav a:hover, .nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }

main { width: min(1280px, 100%); margin: 0 auto; padding: 38px 28px 72px; }

.hero { display: flex; align-items: end; justify-content: space-between; gap: 32px; padding: 4px 0 30px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.hero h1, .detail-hero h1 {
  max-width: 800px;
  margin: 0;
  font-size: clamp(34px, 4vw, 52px);
  font-weight: 680;
  letter-spacing: -.035em;
  line-height: 1.08;
}

.lede, .detail-hero > p { max-width: 720px; margin: 12px 0 0; color: var(--muted); font-size: 17px; }

.hero-score { min-width: 145px; text-align: right; }
.hero-score span { display: block; color: var(--accent-strong); font-size: 42px; font-weight: 700; line-height: 1.1; }
.hero-score small { color: var(--muted); font-size: 13px; }

.metrics, .detail-metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 26px; }

.metrics article, .detail-metrics article {
  min-width: 0;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metrics span, .metrics small, .detail-metrics span, .detail-metrics small { display: block; color: var(--muted); }
.metrics span, .detail-metrics span { font-size: 13px; font-weight: 600; }
.metrics strong, .detail-metrics strong { display: block; margin: 4px 0 1px; font-size: 27px; font-weight: 700; line-height: 1.2; }
.metrics small, .detail-metrics small { font-size: 12px; }
.positive-text { color: var(--positive); }
.negative-text { color: var(--negative); }

.workspace { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }

.filters { display: flex; flex-direction: column; gap: 18px; }
.primary-filters { display: grid; grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(145px, 1fr)); gap: 14px; align-items: end; }

.filters label, .subscriber-head label, .subscriber-grid label { display: grid; min-width: 0; gap: 6px; }

.filters label > span:first-child, .subscriber-head label > span:first-child, .subscriber-grid label > span:first-child {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

input, select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid #bccbd6;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
}

input::placeholder { color: #65798b; opacity: 1; }
input:hover, select:hover { border-color: #879dab; }
input:focus-visible, select:focus-visible { border-color: var(--accent); }
input[type="checkbox"] { width: 19px; min-height: 19px; height: 19px; margin: 0; accent-color: var(--accent); }
input[type="date"] { min-height: 46px; color-scheme: light; }
input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; padding: 3px; }
input[type="number"] { font-variant-numeric: tabular-nums; }

button {
  min-height: 46px;
  padding: 9px 17px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
button:active { transform: translateY(1px); }

.advanced-filters { border-top: 1px solid var(--line); }
.advanced-filters summary { display: flex; min-height: 48px; align-items: center; gap: 10px; cursor: pointer; list-style: none; color: var(--accent-strong); font-weight: 700; }
.advanced-filters summary::-webkit-details-marker { display: none; }
.advanced-filters summary::before { content: "+"; display: grid; width: 21px; height: 21px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 15px; line-height: 1; }
.advanced-filters[open] summary::before { content: "−"; }
.advanced-filters summary small { color: var(--muted); font-size: 13px; font-weight: 400; }
.advanced-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; padding: 4px 0 18px; }
.within-field { grid-column: span 2; }

.relative-filter { display: grid; grid-template-columns: minmax(0, 1fr) 112px; align-items: center; border: 1px solid #bccbd6; border-radius: 9px; background: #fff; overflow: hidden; }
.relative-filter input, .relative-filter select { min-height: 44px; border: 0; border-radius: 0; }
.relative-filter select { border-left: 1px solid var(--line); padding-left: 9px; }
.relative-filter:focus-within { outline: 3px solid #16887c; outline-offset: 2px; }
.relative-filter input:focus-visible, .relative-filter select:focus-visible { outline: none; box-shadow: none; }

.filter-actions { display: flex; align-items: center; gap: 16px; }
.filter-actions a { color: var(--accent-strong); font-size: 14px; font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 28px 0 12px; }
.section-heading h2 { margin: 0; font-size: 25px; font-weight: 700; letter-spacing: -.025em; }
.section-heading > span { color: var(--muted); font-size: 14px; }

.document-card { display: grid; grid-template-columns: 70px minmax(0, 1fr) 88px; gap: 18px; padding: 20px 12px; border-top: 1px solid var(--line); border-radius: 10px; }
.document-card:hover { background: var(--surface-soft); }
.document-card:focus-visible { position: relative; z-index: 1; }
.score strong, .impact-score strong { display: block; font-size: 23px; font-weight: 700; line-height: 1.25; }
.score small, .impact-score small { color: var(--muted); font-size: 12px; }
.impact-score { text-align: right; }
.story { min-width: 0; }
.story h3 { margin: 8px 0 5px; font-size: 19px; font-weight: 680; letter-spacing: -.015em; line-height: 1.3; }
.story > p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips span { padding: 3px 9px; border: 1px solid #d5e0e7; border-radius: 999px; background: #f1f5f7; color: #334a5b; font-size: 12px; font-weight: 650; }
.chips .positive { border-color: #c4e4ce; background: var(--positive-soft); color: var(--positive); }
.chips .negative { border-color: #f0c7cf; background: var(--negative-soft); color: var(--negative); }
.chips .neutral { border-color: #e9d7ad; background: var(--caution-soft); color: var(--caution); }

.meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 11px; color: var(--muted); font-size: 13px; }
.time-ago { padding: 1px 8px; border-radius: 999px; font-weight: 650; }
.time-ago.fresh { background: var(--positive-soft); color: var(--positive); }
.time-ago.recent { background: var(--caution-soft); color: var(--caution); }
.time-ago.stale { background: #edf1f4; color: #465b6c; }
.time-ago.unknown { padding: 0; background: transparent; color: var(--muted); font-weight: 400; }

.pagination { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 24px 0 4px; }
.pagination a { color: var(--accent-strong); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.pagination span { color: var(--muted); }

.alert, .notice, .empty { margin-bottom: 22px; padding: 17px 19px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.alert { border-color: #e7b9c2; background: var(--negative-soft); color: #79192a; }
.notice { border-color: #b9ddc5; background: var(--positive-soft); color: #14562f; }
.empty { margin: 0; background: var(--surface-soft); text-align: center; }
.empty p { margin: 5px 0 0; color: var(--muted); }

.back { display: inline-block; margin: 0 0 22px; color: var(--accent-strong); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.detail-hero { padding-bottom: 27px; border-bottom: 1px solid var(--line); }
.detail-hero h1 { margin-top: 14px; font-size: clamp(32px, 3.5vw, 46px); }
.detail-hero .meta a { color: var(--accent-strong); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.detail-metrics { margin: 22px 0; }
.detail-metrics strong { font-size: 23px; }
.detail-metrics article { position: relative; }
.detail-metrics article:nth-child(5) .metric-tooltip { right: 0; left: auto; }
.metric-label { position: relative; display: inline-flex !important; align-items: center; gap: 6px; }
.tooltip-trigger {
  display: inline-grid;
  width: 19px;
  min-height: 19px;
  height: 19px;
  place-items: center;
  padding: 0;
  border: 1px solid #8396a5;
  border-radius: 50%;
  background: #fff;
  color: #40596b;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}
.tooltip-trigger:hover, .tooltip-trigger:focus-visible { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.metric-tooltip {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  display: block !important;
  width: min(340px, calc(100vw - 48px));
  padding: 12px 14px;
  border: 1px solid #385265;
  border-radius: 10px;
  background: #172b3a;
  box-shadow: 0 8px 22px rgb(23 43 58 / 20%);
  color: #fff !important;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  text-transform: none;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.metric-label:hover .metric-tooltip, .metric-label:focus-within .metric-tooltip { visibility: visible; opacity: 1; }
.metric-more {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  margin-top: 9px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 650;
}
.metric-more:hover { border-color: #9eb1bf; background: var(--accent-soft); color: var(--accent-strong); }
.metric-dialog {
  width: min(640px, calc(100vw - 32px));
  max-width: none;
  max-height: min(82vh, 760px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(12 30 43 / 28%);
}
.metric-dialog::backdrop { background: rgb(13 30 43 / 58%); }
.dialog-heading {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.dialog-heading .eyebrow { margin: 0 0 3px; }
.dialog-heading h2 { margin: 0; font-size: 23px; line-height: 1.25; }
.dialog-close {
  display: grid;
  width: 36px;
  min-height: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}
.dialog-close:hover { border-color: #9eb1bf; background: var(--accent-soft); color: var(--accent-strong); }
.dialog-content { padding: 18px 24px 24px; color: #263d4e; }
.dialog-content p { margin: 0 0 13px; }
.dialog-content h3 { margin: 20px 0 7px; color: var(--text); font-size: 16px; }
.dialog-content ul { margin: 0 0 14px; padding-left: 21px; }
.dialog-content li + li { margin-top: 8px; }
.dialog-content strong { color: var(--text); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { min-width: 0; padding: 22px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel.wide { grid-column: 1 / -1; }
.panel-heading { margin-bottom: 14px; }
.article-body { max-width: 900px; color: #263d4e; font: 17px/1.8 Georgia, "Times New Roman", serif; white-space: pre-line; overflow-wrap: anywhere; }
.bar-row { display: grid; grid-template-columns: 78px minmax(60px, 1fr) 48px; gap: 10px; align-items: center; margin: 16px 0; text-transform: capitalize; }
.bar-row > div { height: 10px; overflow: hidden; border-radius: 8px; background: #e8eef2; }
.bar { display: block; height: 100%; background: var(--blue); }
.bar.positive { background: var(--positive); }
.bar.negative { background: var(--negative); }
.bar.neutral { background: var(--caution); }
.breakdown, .entity-group { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); text-transform: capitalize; }
.entity { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 11px 0; border-bottom: 1px solid var(--line); }
.entity small, .muted { color: var(--muted); }
.reasons { padding-left: 20px; color: var(--muted); }
.panel pre { max-height: 400px; padding: 15px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); color: #263d4e; font-size: 12px; line-height: 1.6; }
.timeline > div { display: grid; grid-template-columns: 14px 170px minmax(120px, 1fr) auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.timeline i { width: 9px; height: 9px; border-radius: 50%; background: var(--caution); }
.timeline i.success { background: var(--positive); }
.timeline i.failed { background: var(--negative); }
.timeline small { color: var(--muted); }

.settings-form { display: flex; flex-direction: column; gap: 16px; }
.toggle { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.toggle span { color: var(--text); font-size: 15px; font-weight: 650; }
.pending-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }
.pending-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 20px; }
.pending-row small { display: block; margin-top: 4px; color: var(--muted); }
.pending-row form { display: inline-block; }
.subscriber-card { display: flex; flex-direction: column; gap: 18px; }
.card-title { margin: 0; font-size: 19px; }
.subscriber-head { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) auto; gap: 14px; align-items: end; }
.subscriber-head .toggle { min-height: 46px; }
.checkbox-group { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; min-width: 0; margin: 0; padding: 0; border: 0; }
.checkbox-group legend { float: left; width: 100%; margin: 0 0 2px; padding: 0; color: var(--text); font-size: 13px; font-weight: 650; }
.chip-check { display: inline-flex; min-height: 38px; align-items: center; gap: 8px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); color: #334a5b; font-size: 13px; cursor: pointer; }
.chip-check:hover { border-color: #9eb1bf; background: #f0f5f7; }
.subscriber-grid { display: grid; grid-template-columns: minmax(190px, 1fr) minmax(240px, 1fr) minmax(190px, .8fr); gap: 14px; align-items: start; }
.subscriber-grid select[multiple] { min-height: 112px; padding: 6px; }
.field-help { color: var(--muted); font-size: 12px; }
.field-group { display: flex; flex-direction: column; gap: 10px; }
.field-group > span { color: var(--text); font-size: 13px; font-weight: 650; }
.chip-list { display: flex; min-height: 34px; flex-wrap: wrap; gap: 8px; }
.chip-tag { display: inline-flex; min-height: 34px; align-items: center; gap: 8px; padding: 4px 7px 4px 11px; border: 1px solid #c4e4dc; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; }
.chip-remove { display: grid; width: 26px; min-height: 26px; height: 26px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: #d1eae5; color: var(--accent-strong); font-size: 17px; line-height: 1; }
.chip-remove:hover { background: #b7ddd5; }
.chip-add { display: flex; gap: 10px; }
.chip-add-select { flex: 1; }
.chip-add-btn { background: #fff; color: var(--accent-strong); }
.chip-add-btn:hover { background: var(--accent-soft); }
button.danger { border-color: var(--negative); background: #fff; color: var(--negative); }
button.danger:hover { background: var(--negative-soft); }
.subscriber-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.subscriber-actions form { margin: 0; }
button.save { align-self: flex-start; min-width: 170px; }
.add-subscriber-card .section-heading { margin: 0 0 15px; }
.add-subscriber-card .section-heading h2 { font-size: 21px; }

footer { padding: 22px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; text-align: center; }

@media (max-width: 1000px) {
  main { padding-top: 30px; }
  .primary-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics, .detail-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-metrics article:nth-child(3n) .metric-tooltip { right: 0; left: auto; }
  .detail-metrics article:nth-child(5) .metric-tooltip { right: auto; left: 0; }
  .advanced-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .subscriber-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timeline > div { grid-template-columns: 14px 150px minmax(100px, 1fr); }
  .timeline small { grid-column: 2 / -1; }
}

@media (max-width: 680px) {
  .topbar { min-height: 64px; flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .brand { margin-right: auto; }
  .brand-mark { width: 36px; height: 36px; }
  .nav { order: 3; width: 100%; margin: 0; border-top: 1px solid var(--line); padding-top: 6px; }
  .nav a { flex: 1; text-align: center; }
  main { padding: 24px 16px 48px; }
  .hero { align-items: start; padding-bottom: 22px; }
  .hero h1 { font-size: 36px; }
  .hero-score { min-width: auto; }
  .hero-score span { font-size: 32px; }
  .hero-score small { font-size: 11px; }
  .lede, .detail-hero > p { font-size: 16px; }
  .metrics, .detail-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .detail-metrics article:nth-child(2n) .metric-tooltip { right: 0; left: auto; }
  .metrics article, .detail-metrics article { padding: 14px; }
  .dialog-heading { padding: 16px 18px 13px; }
  .dialog-content { padding: 16px 18px 20px; }
  .workspace { padding: 15px; }
  .primary-filters, .advanced-grid { grid-template-columns: 1fr; }
  .within-field { grid-column: auto; }
  .advanced-filters summary { flex-wrap: wrap; gap: 7px; padding: 8px 0; }
  .advanced-filters summary small { flex-basis: calc(100% - 32px); margin-left: 31px; }
  .filter-actions { flex-wrap: wrap; }
  .section-heading { align-items: start; flex-direction: column; gap: 4px; }
  .section-heading h2 { font-size: 22px; }
  .document-card { grid-template-columns: 48px minmax(0, 1fr); gap: 12px; padding: 17px 5px; }
  .score strong { font-size: 19px; }
  .story h3 { font-size: 17px; }
  .impact-score { display: flex; grid-column: 2; align-items: baseline; gap: 8px; text-align: left; }
  .impact-score strong { font-size: 16px; }
  .meta { gap: 6px 12px; font-size: 12px; }
  .detail-hero h1 { font-size: 32px; }
  .detail-grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: auto; }
  .panel { padding: 17px; }
  .article-body { font-size: 16px; }
  .subscriber-head, .subscriber-grid { grid-template-columns: 1fr; }
  .pending-row { align-items: start; flex-direction: column; }
  .pending-row .subscriber-actions { width: 100%; }
  .pending-row form, .pending-row button { flex: 1; }
  .subscriber-actions button { min-height: 44px; }
  .pagination { gap: 12px; font-size: 14px; }
  .timeline > div { grid-template-columns: 14px minmax(0, 1fr); gap: 7px 10px; }
  .timeline > div > span, .timeline small { grid-column: 2; }
  .entity { grid-template-columns: 74px minmax(0, 1fr); }
  .entity small { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
