:root {
  --ink: #161616;
  --ink-soft: #393939;
  --muted: #6f6f6f;
  --line: #d8d8d8;
  --surface: #ffffff;
  --surface-alt: #f4f4f4;
  --surface-dark: #1f1f1f;
  --red: #da1e28;
  --red-dark: #a2191f;
  --green: #198038;
  --amber: #b28600;
  --blue: #0f62fe;
  --max: 1480px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font-family: "IBM Plex Sans", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.topbar {
  min-height: 72px;
  padding: 0 max(28px, calc((100vw - var(--max)) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: var(--ink);
  border-bottom: 4px solid var(--red);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--red);
  font-weight: 600;
  letter-spacing: -.04em;
}

.brand__copy { display: grid; line-height: 1.15; }
.brand__copy strong { font-size: 17px; font-weight: 500; }
.brand__copy small { margin-top: 5px; color: #c6c6c6; font-size: 12px; letter-spacing: .03em; }

.system-state { display: flex; gap: 8px; align-items: center; color: #c6c6c6; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #8d8d8d; }
.status-dot.is-ready { background: #42be65; box-shadow: 0 0 0 4px rgba(66,190,101,.12); }
.status-dot.is-error { background: #fa4d56; }

.overline, .field-label {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.select, input, textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  background: #f4f4f4;
  border: 0;
  border-bottom: 1px solid #8d8d8d;
  border-radius: 0;
}
.select:focus, input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -2px; }
.select--compact { min-width: 210px; min-height: 36px; padding-block: 7px; }
.field-label { display: block; margin-bottom: 7px; }
.button {
  min-height: 44px;
  padding: 11px 18px;
  border: 1px solid transparent;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
}
.button:disabled { cursor: not-allowed; opacity: .45; }
.button--wide { width: 100%; }
.button--primary { color: #fff; background: var(--red); }
.button--primary:hover:not(:disabled) { background: var(--red-dark); }
.button--secondary { color: var(--ink); background: #fff; border-color: #8d8d8d; }
.button--secondary:hover:not(:disabled) { background: #e8e8e8; }
.button--tertiary { min-height: auto; padding: 8px 0; color: var(--blue); background: transparent; }
.button--tertiary:hover { text-decoration: underline; }
.button--danger-secondary { color: var(--red-dark); background: #fff; border-color: var(--red); }
.button--danger-secondary:hover { color: #fff; background: var(--red-dark); }
.button--small { min-height: 34px; padding: 6px 12px; font-size: 12px; }
.button--accent { color: #fff; background: var(--red); }
.button--accent:hover:not(:disabled) { background: #fa4d56; }
.button-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.stage-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-inline: max(28px, calc((100vw - var(--max)) / 2));
  background: #fff;
  border-block: 1px solid var(--line);
}
.stage-nav a { padding: 16px 20px; color: var(--ink); border-right: 1px solid var(--line); text-decoration: none; font-weight: 500; }
.stage-nav a:first-child { border-left: 1px solid var(--line); }
.stage-nav span { margin-right: 12px; color: var(--red); font-family: "IBM Plex Mono", monospace; font-size: 11px; }

.section { padding: 64px max(28px, calc((100vw - var(--max)) / 2)); scroll-margin-top: 54px; }
.section--muted { background: var(--surface-alt); }
.section--dark { color: #fff; background: var(--surface-dark); }
.section-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 520px); gap: 36px; align-items: end; margin-bottom: 32px; }
.section-heading--actions { grid-template-columns: minmax(0, 1fr) auto; }
.section-heading h2 { margin: 7px 0 0; font-size: clamp(30px, 3vw, 44px); font-weight: 300; letter-spacing: -.025em; }
.section-heading p { margin: 0; color: var(--muted); }
.section-heading--light p, .section-heading--light .overline { color: #c6c6c6; }
.run-meta { justify-self: end; color: var(--muted); font-family: "IBM Plex Mono", monospace; font-size: 12px; }

.schedule-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0,0,0,.06);
}
.schedule-panel__details { display: grid; gap: 4px; }
.schedule-panel__time { font-size: 18px; font-weight: 500; }
.schedule-panel__meta { color: var(--muted); font-size: 12px; }
.schedule-panel__actions { display: flex; gap: 8px; align-items: center; }
.schedule-panel__actions .button { white-space: nowrap; }

.source-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-left: 1px solid var(--line); }
.source-card { position: relative; min-height: 218px; padding: 22px; display: flex; flex-direction: column; border: 1px solid var(--line); border-left: 0; }
.source-card__number { color: var(--red); font-family: "IBM Plex Mono", monospace; font-size: 11px; }
.source-card__edit { position: absolute; top: 16px; right: 16px; padding: 5px 9px; color: var(--blue); background: transparent; border: 1px solid transparent; font-size: 12px; }
.source-card__edit:hover { background: #edf5ff; border-color: var(--blue); }
.connection-menu { position: absolute; top: 48px; right: 16px; z-index: 4; width: 190px; padding: 6px; background: #fff; border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0,0,0,.16); }
.connection-menu button { width: 100%; padding: 9px 10px; color: var(--ink); background: transparent; border: 0; text-align: left; font-size: 12px; }
.connection-menu button:hover { background: var(--surface-alt); }
.connection-menu button:disabled { color: #8d8d8d; cursor: not-allowed; }
.connection-menu button:disabled:hover { background: transparent; }
.connection-menu .connection-menu__danger { color: var(--red-dark); }
.connection-menu .connection-menu__danger:disabled { color: #8d8d8d; }
.connection-menu__message { display: block; padding: 7px 10px 5px; color: var(--muted); border-top: 1px solid var(--line); font-size: 10px; line-height: 1.3; }
.connection-menu__message:empty { display: none; }
.source-card h3 { margin: 20px 0 7px; font-size: 18px; font-weight: 500; line-height: 1.25; }
.source-card__vendor { color: var(--muted); font-size: 13px; }
.source-card__footer { margin-top: auto; padding-top: 20px; }
.source-card__status { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.source-card__status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #8d8d8d; }
.source-card[data-status="retrieving"] .source-card__status::before,
.source-card[data-status="awaiting_mfa"] .source-card__status::before { background: var(--amber); animation: pulse 1s infinite; }
.source-card[data-status="retrieved"] .source-card__status::before,
.source-card[data-status="extracted"] .source-card__status::before { background: var(--green); }
.source-card[data-status="extracted_fallback"] .source-card__status::before { background: var(--amber); }
.source-card[data-status="failed"] .source-card__status::before { background: var(--red); }
.source-card__message { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.connections-footer { display: flex; justify-content: flex-end; padding-top: 12px; }

@keyframes pulse { 50% { opacity: .35; } }

.overall-progress { display: grid; grid-template-columns: 1fr 52px; gap: 16px; align-items: center; margin-bottom: 26px; }
.overall-progress__track { height: 5px; overflow: hidden; background: #d8d8d8; }
.overall-progress__track span { display: block; height: 100%; width: 0; background: var(--red); transition: width .35s ease; }
.overall-progress strong { font-family: "IBM Plex Mono", monospace; font-size: 13px; }

.pipeline-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.pipeline-step { min-height: 160px; padding: 20px; background: #fff; }
.pipeline-step__top { display: flex; justify-content: space-between; gap: 10px; }
.pipeline-step__index { color: var(--red); font-family: "IBM Plex Mono", monospace; font-size: 11px; }
.pipeline-step__status { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.pipeline-step h3 { margin: 18px 0 10px; font-size: 16px; font-weight: 500; }
.pipeline-step p { margin: 0; color: var(--muted); font-size: 12px; }
.pipeline-step[data-status="running"] { box-shadow: inset 0 3px var(--red); }
.pipeline-step[data-status="complete"] { box-shadow: inset 0 3px var(--green); }
.pipeline-step[data-status="ready"] { box-shadow: inset 0 3px var(--blue); }

.notice { margin-top: 22px; padding: 14px 16px; display: flex; gap: 9px; border-left: 4px solid; }
.notice--warning { color: #4d3800; background: #fff1c7; border-color: #f1c21b; }
.notice--error { color: #750e13; background: #fff1f1; border-color: var(--red); }

.metrics { display: grid; grid-template-columns: repeat(5, 1fr); margin-bottom: 32px; border: 1px solid var(--line); }
.metric { min-height: 110px; padding: 18px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 10px; font-size: 30px; font-weight: 300; }

.review-toolbar { display: flex; justify-content: space-between; align-items: end; margin-bottom: 12px; }
.table-count { color: var(--muted); font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.table-shell { overflow-x: auto; border: 1px solid var(--line); }
.records-table, .preview-table { width: 100%; border-collapse: collapse; }
.records-table { min-width: 1240px; }
th { padding: 12px 14px; color: #fff; background: var(--ink); font-size: 12px; font-weight: 500; text-align: left; white-space: nowrap; }
td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.records-table tbody tr:hover { background: #f4f4f4; }
.align-right { text-align: right; }
.cell-main { display: block; font-weight: 500; }
.cell-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.mono { font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.review-state { display: inline-flex; padding: 3px 8px; color: var(--ink-soft); background: #e0e0e0; font-size: 11px; text-transform: capitalize; }
.review-state--approved, .review-state--corrected { color: #0e6027; background: #defbe6; }
.review-state--rejected { color: #750e13; background: #fff1f1; }
.review-state--needs_information { color: #684e00; background: #fff1c7; }
.flag-list { display: flex; gap: 5px; flex-wrap: wrap; }
.flag { display: inline-flex; padding: 3px 6px; color: #684e00; background: #fff1c7; font-size: 10px; }
.flag--ok { color: #0e6027; background: #defbe6; }
.table-action { padding: 6px 10px; color: var(--blue); background: transparent; border: 1px solid var(--blue); }
.table-action:hover { color: #fff; background: var(--blue); }

.preview-shell { overflow-x: auto; background: #fff; color: var(--ink); }
.preview-table { min-width: 930px; }
.preview-table th { background: #393939; }
.preview-table td { border-color: #e0e0e0; }
.empty-preview { padding: 42px; color: var(--muted); text-align: center; }

.review-dialog { width: min(1120px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.review-dialog::backdrop { background: rgba(0,0,0,.55); }
.settings-dialog { width: min(650px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.settings-dialog--wide { width: min(820px, calc(100vw - 32px)); }
.settings-dialog::backdrop { background: rgba(0,0,0,.55); }
.settings-card { background: var(--surface); }
.settings-card__header { padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.settings-card__header h2 { margin: 4px 0 0; font-size: 25px; font-weight: 400; }
.settings-card__body { padding: 24px; }
.settings-card__footer { padding: 18px 24px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }
.settings-card__footer--split { justify-content: space-between; }
.settings-card__hint { margin: 0; color: var(--muted); font-size: 12px; }
.connection-state { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.connections-list { margin-top: 18px; border: 1px solid var(--line); }
.connections-list__item { padding: 14px 16px; display: flex; justify-content: space-between; gap: 20px; align-items: center; border-bottom: 1px solid var(--line); }
.connections-list__item:last-child { border-bottom: 0; }
.connections-list__item div { display: grid; gap: 3px; }
.connections-list__item span { color: var(--muted); font-size: 12px; }
.document-preview-dialog { width: min(1180px, calc(100vw - 32px)); height: min(860px, calc(100vh - 32px)); padding: 0; border: 0; background: #262626; box-shadow: 0 24px 80px rgba(0,0,0,.38); }
.document-preview-dialog::backdrop { background: rgba(0,0,0,.72); }
.document-preview-card { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.document-preview-card__header, .document-preview-card__footer { padding: 16px 20px; display: flex; justify-content: space-between; gap: 20px; align-items: center; color: #fff; background: #262626; }
.document-preview-card__header h2 { max-width: 850px; margin: 3px 0 0; overflow: hidden; font-size: 18px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.document-preview-card__header .overline, .document-preview-card__footer span { color: #c6c6c6; }
.document-preview-card__header .icon-button { color: #fff; }
.document-preview-card__body { min-height: 0; background: #525252; }
.document-preview-card__body iframe { width: 100%; height: 100%; display: block; background: #fff; border: 0; }
.document-preview-card__footer { font-size: 12px; }
.document-preview-link { display: inline-flex; align-items: center; text-decoration: none; }
.dialog-card { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-card__header, .dialog-card__footer { padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.dialog-card__header h2 { margin: 4px 0 0; font-size: 25px; font-weight: 400; }
.dialog-card__body { min-height: 0; display: grid; grid-template-columns: 360px 1fr; overflow: auto; }
.dialog-card__footer { border-top: 1px solid var(--line); border-bottom: 0; }
.icon-button { width: 38px; height: 38px; color: var(--ink); background: transparent; border: 0; font-size: 28px; }
.evidence-panel { padding: 26px; background: var(--surface-alt); border-right: 1px solid var(--line); }
.evidence-panel h3 { margin: 10px 0 20px; font-size: 17px; line-height: 1.35; }
.source-document-heading { margin: 10px 0 20px; display: flex; gap: 10px; align-items: start; }
.source-document-heading h3 { flex: 1; margin: 0; }
.source-preview-trigger { flex: 0 0 auto; padding: 5px 8px; color: var(--blue); background: #fff; border: 1px solid var(--blue); font-size: 11px; }
.source-preview-trigger::before { content: "◉"; margin-right: 5px; }
.source-preview-trigger:hover { color: #fff; background: var(--blue); }
.evidence-list { margin: 0 0 20px; }
.evidence-list div { padding: 9px 0; border-bottom: 1px solid var(--line); }
.evidence-list dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.evidence-list dd { margin: 3px 0 0; }
.evidence-panel blockquote { margin: 20px 0; padding-left: 14px; color: var(--ink-soft); border-left: 3px solid var(--red); }
.text-link { display: inline-block; margin-bottom: 18px; color: var(--blue); }
.edit-panel { padding: 26px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.form-field { display: grid; gap: 7px; }
.form-field span { font-size: 12px; font-weight: 500; }
.form-field--wide { grid-column: 1 / -1; }
#save-message { color: var(--muted); font-size: 12px; }

.footer { padding: 24px max(28px, calc((100vw - var(--max)) / 2)); display: flex; justify-content: space-between; color: #c6c6c6; background: var(--ink); font-size: 12px; }

[hidden] { display: none !important; }

@media (max-width: 1100px) {
  .section-heading { grid-template-columns: minmax(0, 1fr) minmax(420px, 520px); }
  .source-grid { grid-template-columns: repeat(2, 1fr); }
  .pipeline-grid { grid-template-columns: repeat(2, 1fr); }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 720px) {
  .topbar { padding-inline: 18px; }
  .system-state { display: none; }
  .section { padding: 42px 20px; }
  .stage-nav { padding: 0; }
  .stage-nav a { padding: 12px 8px; font-size: 12px; text-align: center; }
  .stage-nav span { display: block; margin: 0 0 2px; }
  .section-heading, .section-heading--actions { grid-template-columns: 1fr; }
  .schedule-panel { grid-template-columns: 1fr; }
  .schedule-panel__actions .button { flex: 1; }
  .settings-card__footer--split { align-items: stretch; flex-direction: column; }
  .settings-card__footer--split .button-row { display: grid; grid-template-columns: 1fr 1fr; }
  .document-preview-card__footer { align-items: stretch; flex-direction: column; }
  .source-grid, .pipeline-grid, .metrics { grid-template-columns: 1fr; }
  .dialog-card__body { grid-template-columns: 1fr; }
  .evidence-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .form-field--wide { grid-column: auto; }
  .footer { gap: 10px; flex-direction: column; }
}
