:root {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-border: #e2e2e2;
  --color-text: #1a1a1a;
  --color-muted: #6b6b6b;
  --color-accent: #2952e3;
  --color-accent-contrast: #ffffff;
  --color-line: #c7c7c7;
  --color-success: #1f9254;
  --color-success-bg: #e3f4ea;
  --color-warning: #b45309;
  --color-warning-bg: #fbf0dd;
  /* Distinct from success/warning above so a source's chart line never
     collides visually with a status badge's meaning. */
  --chart-1: #2952e3;
  --chart-2: #9c36b5;
  --chart-3: #0ca678;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14151a;
    --color-surface: #1d1e24;
    --color-border: #2c2d34;
    --color-text: #f0f0f0;
    --color-muted: #9a9aa2;
    --color-accent: #6d8bff;
    --color-accent-contrast: #0b0c10;
    --color-line: #3a3b44;
    --color-success: #4ade80;
    --color-success-bg: rgba(74, 222, 128, 0.14);
    --color-warning: #fbbf24;
    --color-warning-bg: rgba(251, 191, 36, 0.14);
    --chart-1: #6d8bff;
    --chart-2: #d599f2;
    --chart-3: #38d9a9;
  }
}

* { box-sizing: border-box; }

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

.header {
  padding: 2rem 1.25rem 1rem;
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}

.header h1 { margin: 0 0 0.5rem; font-size: 1.75rem; }
.tagline { color: var(--color-muted); margin: 0; }

main { max-width: 640px; margin: 0 auto; padding: 0 1.25rem 3rem; }

/* The search form itself stays a comfortable reading width, but once
   results come in the centered timeline benefits from more room on large
   screens — two columns either side of the spine need real width to be
   worth it. */
main.search-main { max-width: 1100px; }
main.search-main .search-panel { max-width: 640px; margin: 1rem auto 0; }

/* The admin dashboard is a data-dense operator view, not the minimal public
   search page — it earns the extra width so the table and chart don't feel
   cramped. */
main.admin-main { max-width: 1400px; padding: 0 1.5rem 3rem; }

.header--admin { max-width: 1400px; padding-left: 1.5rem; padding-right: 1.5rem; text-align: left; }

.search-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.25rem;
}

.admin-main .dashboard-row:first-child { margin-top: 0; }

.dashboard-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.dashboard-row .search-panel {
  flex: 1 1 320px;
  margin-top: 0;
}

#search-form { display: flex; flex-direction: column; gap: 0.75rem; }

label { font-weight: 600; font-size: 0.9rem; }

input[type="url"] {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--color-bg);
  color: var(--color-text);
}

button {
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: progress; }

.status { min-height: 1.2em; color: var(--color-muted); font-size: 0.9rem; margin: 0.75rem 0 0; }

.supported-sources {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.9rem 0 0;
  color: var(--color-muted);
  font-size: 1rem;
}

.supported-sources .source-logo {
  width: 30px;
  height: 30px;
  margin-right: 0;
}

.results { margin-top: 2rem; }
.results h2 { font-size: 1.1rem; margin-bottom: 1rem; }

/* Centered timeline: a spine down the middle, articles alternating left and
   right of it. How far a card sits from the spine (via --match-offset, set
   per-item in JS) visualizes match confidence — a direct match hugs the
   spine, an indirect one drifts away from it. Rows are positioned via
   JS-computed `top` (see layoutRows in app.js) rather than normal document
   flow, so the left and right columns can stack independently instead of
   forcing every row into lockstep with whichever side is taller. */
.timeline--centered {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline--centered::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-line);
  transform: translateX(-1px);
}

.timeline-row {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr 20px 1fr;
  align-items: start;
}

.timeline-node {
  grid-column: 2;
  justify-self: center;
  width: 14px;
  height: 14px;
  margin-top: 0.35rem;
  border-radius: 50%;
  border: 3px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-line);
  background: var(--color-muted);
  z-index: 1;
}

.timeline-node--direct {
  background: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-success-bg);
}

.timeline-node--indirect { background: var(--color-line); }

.timeline-node--anchor {
  width: 16px;
  height: 16px;
  background: var(--color-text);
  box-shadow: 0 0 0 4px var(--color-bg), 0 0 0 5px var(--color-accent);
}

.timeline-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  max-width: 480px;
  min-width: 0;
  transition: opacity 0.2s ease, filter 0.2s ease;
}

.timeline-row--left .timeline-card {
  grid-column: 1;
  justify-self: end;
  margin-right: var(--match-offset, 0px);
}

.timeline-row--right .timeline-card {
  grid-column: 3;
  justify-self: start;
  margin-left: var(--match-offset, 0px);
}

.timeline-row--anchor .timeline-card {
  grid-column: 1 / -1;
  justify-self: center;
  max-width: 520px;
  background: var(--color-bg);
  border-color: var(--color-text);
}

.timeline-card--direct { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }
.timeline-card--indirect { opacity: 0.6; filter: grayscale(0.6); }

.source-logo {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  object-fit: cover;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.timeline-meta {
  display: flex;
  align-items: center;
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 0.35rem;
}

.timeline-title { margin: 0 0 0.35rem; font-size: 1.05rem; }
.timeline-summary { margin: 0 0 0.6rem; color: var(--color-text); font-size: 0.95rem; }

.timeline-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.timeline-footer a { color: var(--color-accent); text-decoration: none; font-weight: 600; }
.timeline-footer a:hover { text-decoration: underline; }

.similarity { color: var(--color-muted); font-variant-numeric: tabular-nums; }

.match-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.match-badge--direct { color: var(--color-success); background: var(--color-success-bg); }
.match-badge--indirect { color: var(--color-muted); background: var(--color-bg); border: 1px solid var(--color-border); }

@media (max-width: 700px) {
  /* Not enough width for a centered zigzag — collapse to a single-column
     timeline with the spine on the left, same as before this redesign.
     The match-offset effect is dropped here; there's no room to spare. */
  .timeline--centered::before { left: 20px; }

  .timeline-row,
  .timeline-row--anchor {
    grid-template-columns: 40px 1fr;
  }

  .timeline-node { grid-column: 1; }

  .timeline-row--left .timeline-card,
  .timeline-row--right .timeline-card,
  .timeline-row--anchor .timeline-card {
    grid-column: 2;
    justify-self: stretch;
    margin: 0;
    max-width: none;
  }
}

.admin-section-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.heartbeat {
  margin: 0 0 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.5rem;
  flex: 0 0 auto;
  background: var(--color-muted);
}

.status-dot--running {
  background: var(--color-success);
  box-shadow: 0 0 0 3px var(--color-success-bg);
}

.status-dot--idle { background: var(--color-muted); }
.status-dot--none { background: var(--color-line); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--success { color: var(--color-success); background: var(--color-success-bg); }
.badge--warning { color: var(--color-warning); background: var(--color-warning-bg); }
.badge--muted { color: var(--color-muted); background: var(--color-border); }

.config-list {
  margin: 0;
  display: grid;
  gap: 0.4rem;
}

.config-list > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--color-border);
}

.config-list dt { color: var(--color-muted); margin: 0; }
.config-list dd { margin: 0; font-weight: 600; text-align: right; }
.config-list > div:last-child { border-bottom: none; padding-bottom: 0; }

.settings-hint {
  margin: 0 0 0.75rem;
  color: var(--color-muted);
  font-size: 0.85rem;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-muted);
}

.settings-form input {
  max-width: 200px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.settings-form button {
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
}

.last-run-note {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--color-muted);
  white-space: normal;
}

.last-run-note--warning {
  color: var(--color-warning);
  font-weight: 600;
}

.rescan-button {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  font-weight: 600;
  cursor: pointer;
}

.rescan-button:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.table-scroll {
  /* Fallback for very narrow viewports — normally shouldn't need to
     scroll at all now that only headers/badges/numbers are nowrap. */
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.admin-table thead th {
  color: var(--color-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding-top: 0;
}

.admin-table tbody tr:hover {
  background: var(--color-bg);
}

.admin-table th.num,
.admin-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.admin-table td.num--warning {
  color: var(--color-warning);
  font-weight: 700;
}

.admin-table th.actions-col,
.admin-table td:last-child {
  width: 1%;
  text-align: right;
}

.source-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.55rem;
}

.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;
}

.date-part {
  white-space: nowrap;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-gridline {
  stroke: var(--color-border);
  stroke-width: 1;
}

.chart-axis-label {
  font-size: 9px;
  fill: var(--color-muted);
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
}

.chart-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.admin-table tfoot td {
  border-top: 2px solid var(--color-border);
  border-bottom: none;
}

@media (max-width: 480px) {
  .header h1 { font-size: 1.4rem; }
  .timeline-card { padding: 0.75rem 0.85rem; }
  .admin-table { font-size: 0.85rem; }
  .admin-table th, .admin-table td { padding: 0.4rem 0.5rem; }
  .dashboard-row { gap: 1rem; }
  .dashboard-row .search-panel { flex-basis: 100%; }
  .search-panel { padding: 1rem; }
}
