/*
 * Shared stylesheet for the duplicate-checker admin UI (index.html, harvest-check.html,
 * accessibility.html). Color tokens are chosen to meet WCAG 2.2 AA contrast (see ADR-0011 and
 * docs/akadalymentesites.md): --muted, --border-field and --accent were re-picked from the
 * original palette specifically to clear 4.5:1 (text) / 3:1 (UI component/graphical object)
 * against both --bg and --card.
 */
:root {
  --bg: #f5f6f8;
  --card: #fff;
  --border: #dfe3e8; /* decorative card border only — never the sole boundary of an interactive control */
  --border-field: #767f8c; /* 4.05:1 on --card, 3.75:1 on --bg — input/button borders (1.4.11) */
  --muted: #4b5563; /* 7.56:1 on --card, 6.99:1 on --bg */
  --text: #111;
  --accent: #1d4ed8; /* 6.70:1 both as text-on-white and white-on-fill */
  --accent-contrast: #fff;
  --meter-rel: #6b7280; /* 4.23:1 on --meter-track */
  --meter-track: #eef0f3;
  --focus-ring: #1d4ed8;
}

* { box-sizing: border-box; }

html { font-size: 100%; } /* 1rem = 16px by default; all sizing below is rem so it follows the user's base size */

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.wrap { max-width: 80rem; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.25rem; }
h2 { font-size: 1.0625rem; }
h3.title, .card h3 { margin: 0 0 0.375rem; font-size: 0.9375rem; }

code { font-family: ui-monospace, Menlo, monospace; }

/* Skip link (2.4.1) */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.5rem 1rem;
  border-radius: 0 0 0.5rem 0.5rem;
  z-index: 100;
  transition: top .15s;
}
.skip-link:focus { top: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; border: 0; padding: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* Header / nav / footer */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.site-header nav {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
}
.site-header ul {
  list-style: none;
  display: flex;
  gap: 1.25rem;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}
.site-header a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.25rem 0.125rem;
  border-bottom: 2px solid transparent;
}
.site-header a:hover { text-decoration: underline; }
.site-header a[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.site-footer {
  max-width: 80rem;
  margin: 2rem auto 0;
  padding: 1rem 1.5rem 2rem;
  color: var(--muted);
  font-size: 0.8125rem;
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--accent); }

/* Focus visibility (2.4.7 / 2.4.11) */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
.left { position: sticky; top: 1.5rem; }
@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; }
  .left { position: static; }
}

/* Forms */
.field { margin: 0.75rem 0; display: flex; flex-direction: column; gap: 0.25rem; }
.field label, .filters label, fieldset > label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}
.hint { font-size: 0.75rem; color: var(--muted); margin: 0; }

textarea {
  width: 100%;
  height: 17.5rem;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.75rem;
  padding: 0.625rem;
  border: 1px solid var(--border-field);
  border-radius: 0.5rem;
  resize: vertical;
  color: var(--text);
  background: var(--card);
}

input[type="text"], input[type="url"], input[type="number"] {
  font-size: 0.875rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border-field);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--text);
  width: 100%;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 0.75rem 1rem 1rem;
  margin: 0.75rem 0;
}
fieldset legend {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: 0 0.375rem;
}

.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.filters .field { flex: 1; min-width: 10rem; margin: 0.25rem 0; }

.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 0.625rem; }
.field-row .field { min-width: 10rem; margin: 0; }
.field-row .field.wide { min-width: 20rem; flex: 2 1 20rem; }
.field-row .field.narrow { min-width: 6rem; max-width: 8rem; }

.row { display: flex; gap: 0.5rem; align-items: center; margin: 0.625rem 0; flex-wrap: wrap; }

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid transparent;
  padding: 0.5625rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
}
button:hover { filter: brightness(1.08); }
button[aria-disabled="true"] { opacity: .5; cursor: default; filter: none; }
.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border-field);
}

.toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8125rem; color: var(--text); }

.controls {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Progress */
.progress {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.progress .stat { display: flex; flex-direction: column; }
.progress .stat .lbl { font-size: 0.6875rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.progress .stat .val { font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { flex: 1; min-width: 12.5rem; height: 0.5rem; background: var(--meter-track); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
@media (prefers-reduced-motion: reduce) {
  .bar-fill, .skip-link { transition: none; }
}
/*
 * Phase badges. `.ph-*` = whole-run phase (RunPhase), `.sp-*` = one source row's phase (SourcePhase);
 * the two enums share colors where they mean the same thing, so the selectors are grouped rather than
 * duplicated. All pairs clear 4.5:1 (see docs/akadalymentesites.md).
 */
.phase-badge { font-size: 0.75rem; padding: 0.1875rem 0.625rem; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.ph-RUNNING, .sp-RUNNING, .sp-DISCOVERING { background: #dbeafe; color: #1e40af; }
.ph-COMPLETED, .sp-COMPLETED { background: #dcfce7; color: #166534; }
.ph-FAILED, .sp-FAILED { background: #fee2e2; color: #991b1b; }
.ph-STOPPED, .sp-STOPPED { background: #fef3c7; color: #92400e; }
.ph-COMPLETED_WITH_ERRORS { background: #ffedd5; color: #9a3412; } /* 6.23:1 */
.ph-IDLE, .sp-PENDING, .sp-SKIPPED { background: #e5e7eb; color: #374151; }

/* Verdicts */
.verdict { padding: 0.875rem 1rem; border-radius: 0.625rem; margin: 1rem 0; font-weight: 600; }
.v-DUPLICATE_EDITION { background: #fee2e2; color: #991b1b; }
.v-DUPLICATE_WORK { background: #fef3c7; color: #92400e; }
.v-NO_DUPLICATE { background: #dcfce7; color: #166534; }
.v-UNCERTAIN { background: #e5e7eb; color: #374151; }
.verdict .summary { font-weight: 400; margin-top: 0.25rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 0.875rem 1rem;
  margin: 0.625rem 0;
}
.card.best { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(29, 78, 216, .2); }
.card.best .best-flag { font-weight: 700; color: var(--accent); }
.query-card {
  background: var(--card);
  border: 1px dashed var(--accent);
  border-radius: 0.625rem;
  padding: 0.75rem 1rem;
  margin: 0.625rem 0;
}
.query-card .narrative { font-style: normal; color: var(--text); margin-top: 0.25rem; }

h3.title a { color: var(--accent); text-decoration: underline; }
h3.title a:hover { text-decoration-thickness: 2px; }

.badges { display: flex; gap: 0.375rem; flex-wrap: wrap; margin: 0.375rem 0; }
.badge { font-size: 0.75rem; padding: 0.125rem 0.5rem; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.badge.cls-EDITION_MATCH { background: #fee2e2; color: #991b1b; }
.badge.cls-WORK_MATCH { background: #fef3c7; color: #92400e; }
.badge.cls-DIFFERENT { background: #e5e7eb; color: #374151; }

.meters { display: flex; flex-direction: column; gap: 0.4375rem; margin: 0.5rem 0; }
.meter-head { display: flex; justify-content: space-between; font-size: 0.6875rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 0.125rem; }
.meter-head .mv { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.meter-track { height: 0.375rem; background: var(--meter-track); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.meter-fill.rel { background: var(--meter-rel); }

.reason { margin: 0.5rem 0; padding: 0.375rem 0.625rem; background: #f0f7ff; border-left: 3px solid var(--accent); border-radius: 0.25rem; font-size: 0.8125rem; color: #1e3a8a; }
.reason-label { font-weight: 700; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: .03em; margin-right: 0.375rem; }

dl.fields {
  font-size: 0.8125rem;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.1875rem 0.875rem;
  margin: 0.5rem 0 0;
}
dl.fields dt { color: var(--muted); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .03em; align-self: center; }
dl.fields dd { color: var(--text); font-weight: 500; margin: 0; }

.muted { color: var(--muted); }
.narrative { font-size: 0.75rem; color: var(--muted); margin-top: 0.375rem; font-style: italic; }
.nomatch { color: var(--muted); font-style: italic; padding: 0.5rem 0; }
.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.875rem 1rem;
  border-radius: 0.625rem;
  margin: 1rem 0;
  border: 1px solid #f3b4b4;
}
.error:empty { display: none; }

/* Harvest-check accordion pairs */
.pair { border: 1px solid var(--border); border-radius: 0.75rem; margin: 1rem 0; overflow: hidden; background: var(--card); }
.pair-head { padding: 0.75rem 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.pair-head .idx { font-variant-numeric: tabular-nums; opacity: .75; }
.pair-head .summary { font-weight: 400; margin-left: auto; text-align: right; font-size: 0.8125rem; }
.pair-head .isbn-tag { font-weight: 700; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .03em; padding: 0.125rem 0.5rem; border-radius: 999px; background: rgba(17,17,17,.12); }
details.pair > summary { list-style: none; cursor: pointer; }
details.pair > summary::-webkit-details-marker { display: none; }
details.pair > summary::after { content: '▸'; opacity: .7; transition: transform .15s; margin-left: 0.5rem; }
details.pair[open] > summary::after { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) {
  details.pair > summary::after { transition: none; }
}
.pair-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.pair-col { padding: 0.875rem 1rem; }
.pair-col.input { border-right: 1px dashed var(--border); }
.col-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; margin: 0 0 0.5rem; }
@media (max-width: 860px) {
  .pair-cols { grid-template-columns: 1fr; }
  .pair-col.input { border-right: 0; border-bottom: 1px dashed var(--border); }
}

/*
 * Data tables (harvest.html: configured tenants, per-source progress). The wrapper scrolls
 * horizontally on narrow viewports — WCAG 1.4.10 exempts data tables from the no-two-way-scroll
 * requirement, and squeezing OAI endpoint URLs into 320 px would be worse than a scroller.
 */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  overflow-x: auto;
  margin: 0.625rem 0 1rem;
}
table.grid { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
table.grid th, table.grid td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.grid thead th {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  white-space: nowrap;
}
table.grid tbody tr:last-child > * { border-bottom: 0; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid td.name { font-weight: 600; }
table.grid td code { overflow-wrap: anywhere; }
table.grid td .cell-note { display: block; color: var(--muted); font-size: 0.75rem; }
table.grid td.err { color: #991b1b; }

/* Accessibility statement page */
.statement section { margin-bottom: 1.75rem; }
.statement dt { font-weight: 600; margin-top: 0.5rem; }
