:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1d2330;
  --muted: #667085;
  --border: #dde1e7;
  --accent: #2557c7;
  --accent-soft: #e8eefc;
  --ok: #1f7a3f;
  --warn: #9a6200;
  --fail: #b42318;
  --ok-bg: #e5f4ea;
  --warn-bg: #fff4dc;
  --fail-bg: #fde8e6;
  --add-bg: #e5f4ea;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2128;
    --surface-2: #232830;
    --text: #e4e7ec;
    --muted: #949bab;
    --border: #323844;
    --accent: #7ea6ff;
    --accent-soft: #1f2a44;
    --ok: #5cc98a;
    --warn: #f0b44c;
    --fail: #ff8a7f;
    --ok-bg: #17331f;
    --warn-bg: #3a2e14;
    --fail-bg: #3d1d1a;
    --add-bg: #17331f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- Header and navigation ---- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 52px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.logo {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
}
.main-nav { display: flex; gap: 4px; flex: 1; }
.main-nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
.main-nav a:hover, .main-nav a[aria-current] { background: var(--accent-soft); color: var(--accent); }
.user { display: flex; align-items: center; gap: 10px; margin: 0 0 0 auto; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 48px; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 14px; font-size: 0.9rem; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs [aria-current] { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
.crumbs .sep { opacity: 0.6; }

/* ---- Headings and page structure ---- */
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.25rem; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; margin: 2.2rem 0 0.75rem; scroll-margin-top: 70px; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; scroll-margin-top: 70px; }
h4 { font-size: 0.95rem; margin: 20px 0 8px; }
h1 .pill { vertical-align: middle; margin-left: 6px; font-size: 0.8rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; margin-bottom: 16px; }
.page-head p { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.to-top { margin-top: 32px; text-align: right; font-size: 0.9rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; font-weight: 400; }
.error { color: var(--fail); background: var(--fail-bg); padding: 8px 12px; border-radius: 6px; }

/* "On this page" links */
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 20px; }
.toc a {
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
}
.toc a:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Cards, key figures ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.narrow { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; }
.narrow h1 { margin: 0; }
.narrow p { margin: 0; }
.empty { text-align: center; padding: 40px 16px; }
.empty p { margin: 4px 0; }

.facts { display: flex; flex-wrap: wrap; gap: 12px 40px; padding: 12px 16px; }
.facts div { display: grid; gap: 2px; }
.facts span { font-size: 0.82rem; }
.facts b { font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 0 0 20px; }
.tile {
  display: grid;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.tile b { font-size: 1.7rem; line-height: 1.1; }
.tile span { font-size: 0.85rem; color: var(--muted); }
.tile-fail { border-left-color: var(--fail); }
.tile-fail b { color: var(--fail); }
.tile-warn { border-left-color: var(--warn); }
.tile-warn b { color: var(--warn); }
.tile-info, .tile-changes { border-left-color: var(--muted); }
.tile-link { border-left-color: var(--accent); }
a.tile:hover { border-color: var(--accent); }

.disclosure { padding: 0; }
.disclosure summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--accent); list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::before { content: "+"; display: inline-block; width: 1.2em; font-weight: 700; }
.disclosure[open] summary::before { content: "–"; }
.disclosure[open] summary { border-bottom: 1px solid var(--border); }
.disclosure form { padding: 16px; }

.link-settings { flex: 1 1 100%; margin: 4px 0 0; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.link-settings legend { padding: 0 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.link-settings .wide { grid-column: 1 / -1; }
.link-settings p { margin: 0; }
textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--text); width: 100%; resize: vertical; }
::placeholder { color: var(--muted); opacity: 0.65; }
code { font-size: 0.9em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.danger-zone { border-color: var(--fail); }
.danger-zone b { color: var(--fail); }

/* ---- Forms and buttons ---- */
label { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
input, select, button {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}
input[type="checkbox"] { padding: 0; }
button, a.button {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
button:hover, a.button:hover { filter: brightness(1.08); }
a.button.secondary, .button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
a.button.secondary:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.segmented { display: inline-flex; }
.segmented .button { border-radius: 0; }
.segmented .button:first-child { border-radius: 6px 0 0 6px; }
.segmented .button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.button.disabled { opacity: 0.45; cursor: default; display: inline-block; padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px; }
button.ghost { background: none; border-color: var(--border); color: var(--text); padding: 4px 10px; font-weight: 400; }
button.ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
button.danger { background: var(--fail); border-color: var(--fail); }

.add { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.add .grow { flex: 1 1 220px; }
.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.right { margin-left: auto; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td { overflow-wrap: anywhere; }
table.list tbody tr:hover td { background: var(--surface-2); }
td.icon { width: 2rem; text-align: center; }
table.results { table-layout: fixed; }
td.label { width: 16rem; overflow-wrap: anywhere; }
tr.inactive td { color: var(--muted); }
.site-link { font-weight: 600; font-size: 1.02rem; }
.site-cell .small { margin-top: 1px; }

.st { font-weight: 700; }
.st-ok, .st-info { color: var(--ok); }
.st-info { color: var(--muted); }
.st-warn { color: var(--warn); }
.st-fail { color: var(--fail); }
.st-none { color: var(--muted); }

.pill {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--border);
  color: var(--muted);
}
.pill-ok, .pill-info { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-fail { background: var(--fail-bg); color: var(--fail); }

.cnt { display: inline-block; margin-right: 6px; padding: 0 8px; border-radius: 999px; font-size: 0.82rem; white-space: nowrap; background: var(--border); }
.cnt-fail { background: var(--fail-bg); color: var(--fail); font-weight: 600; }
.cnt-warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.cnt-link { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--border);
  color: var(--text);
  text-decoration: none;
}
.badge.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.badge.fail { background: var(--fail-bg); color: var(--fail); }

tr.chg-changed td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
tr.chg-added td:first-child { box-shadow: inset 4px 0 0 var(--ok); }
tr.chg-removed td:first-child, tr.chg-newproblem td:first-child { box-shadow: inset 4px 0 0 var(--fail); }

/* ---- Link check results ---- */
.about { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 16px; margin: 0 0 20px; font-size: 0.92rem; }
.about p { margin: 4px 0 8px; }
.about dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.about dt { font-weight: 600; }
.about dd { margin: 0; }
@media (max-width: 700px) { .about dl { grid-template-columns: 1fr; gap: 0; } .about dd { margin-bottom: 6px; } }
.scope-note { position: relative; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--muted); border-radius: 8px; padding: 10px 16px; margin: 0 0 20px; font-size: 0.92rem; }
.popup { display: inline-block; margin-left: 6px; }
.popup summary { display: inline; cursor: pointer; color: var(--accent); text-decoration: underline; }
.popup[open] > ul { position: absolute; z-index: 5; left: 16px; right: 16px; top: calc(100% - 4px); max-height: 18rem; overflow: auto; list-style: none; margin: 0; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.18); font-size: 0.85rem; }
.popup li { overflow-wrap: anywhere; margin-bottom: 3px; }
.scope-note ul { margin: 4px 0 0; padding-left: 20px; }
.link-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px; font-size: 0.9rem; }
table.links th.icon, table.links td.icon { width: 2.5rem; }
table.links th:nth-child(1), table.links td:nth-child(1) { width: 36%; }
table.links th:nth-child(2), table.links td:nth-child(2) { width: 36%; }
table.links th.icon, table.links td.icon { text-align: right; }
ul.clean-pages { columns: 22rem; column-gap: 24px; padding-left: 20px; margin: 0; font-size: 0.9rem; }
ul.clean-pages li { break-inside: avoid; overflow-wrap: anywhere; margin-bottom: 3px; }
table.link-changes th:nth-child(1), table.link-changes td:nth-child(1) { width: 6rem; }
table.link-changes th:nth-child(2), table.link-changes td:nth-child(2) { width: 30%; }
table.link-changes th:nth-child(3), table.link-changes td:nth-child(3) { width: 36%; }
table.links td div + div { margin-top: 6px; }
.link-area { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 8px; font-size: 0.78rem; margin-left: 2px; }
.locate-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0 0 16px; }
.locate-facts dt { font-weight: 600; }
.locate-facts dd { margin: 0; overflow-wrap: anywhere; }
.notice { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 6px; }
.show-link { display: inline-block; font-size: 0.78rem; font-weight: 600; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 10px; margin-left: 4px; white-space: nowrap; text-decoration: none; }
.show-link:hover { filter: brightness(1.15); }
.locate-shot { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,.12)); }
.link-text { display: block; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
table.findings th:nth-child(1), table.findings td:nth-child(1) { width: 7.5rem; }
table.findings th:nth-child(2), table.findings td:nth-child(2) { width: 14rem; }
table.findings th:nth-child(3), table.findings td:nth-child(3) { width: 16rem; }
.older { margin-top: 12px; }
.older .list { box-shadow: none; border: none; border-radius: 0; }
.older summary { font-weight: 500; }

/* ---- Small screens ---- */
@media (max-width: 720px) {
  .top-inner { gap: 12px; }
  h1 { font-size: 1.35rem; }
  .toolbar { width: 100%; }
  .link-settings { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
  .tile { padding: 8px 12px; }
  .tile b { font-size: 1.35rem; }
  .toc { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .toc a { white-space: nowrap; }

  /* Lists become compact cards */
  table.list, table.list tbody, table.links, table.links tbody, table.findings, table.findings tbody { display: block; }
  table.list thead, table.links thead, table.findings thead { display: none; }
  table.list tr, table.links tr, table.findings tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.list tr:last-child, table.links tr:last-child, table.findings tr:last-child { border-bottom: none; }
  table.links tr { display: flex; flex-direction: column; }
  table.links td.icon { order: -1; text-align: left; }
  table.links td { display: block; width: auto !important; border: none; padding: 2px 12px; }
  table.links td[data-label]::before { content: attr(data-label); display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
  table.links td.icon { width: auto; text-align: left; font-size: 1.1rem; }
  table.link-changes td[data-label="Change"]::before { display: none; }

  table.list tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 12px; }
  table.list td { display: block; width: auto; border: none; padding: 0; }
  table.list td[data-label]::before { content: attr(data-label); display: inline; margin-right: 5px; font-size: 0.78rem; color: var(--muted); }
  table.list td[data-label="Status"]::before, table.list td[data-label="Site"]::before, table.list td[data-label="Findings"]::before,
  table.list td[data-label="Started"]::before, table.list td[data-label="Duration"]::before { display: none; }
  table.list td.site-cell { flex: 1 1 0; min-width: 0; }
  table.list td[data-label="Findings"] { flex-basis: 100%; }

  table.findings tr { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 2px 10px; padding: 10px 12px; }
  table.findings td { display: block; width: auto; border: none; padding: 0; }
  table.findings td::before { display: none; }
  table.findings td[data-label="Area"] { display: none; }
  table.findings td[data-label="Check"] { font-weight: 600; }
  table.findings td[data-label="Result"] { grid-column: 1 / -1; color: var(--muted); }
  td.label { width: 8.5rem; overflow-wrap: anywhere; }
  .right { margin-left: 0; }
}

table.area-overview { width: auto; min-width: 360px; margin: 0 0 16px; }
table.area-overview caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
table.area-overview td:not(:first-child), table.area-overview th:not(:first-child) { text-align: right; }

.fix-form { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.fix-note { font-size: 12px; color: var(--muted, #5b6472); }
.fix-note.again { color: var(--fail, #b4281e); font-weight: 600; }
button.link-button { background: none; border: 0; padding: 0; color: var(--accent, #2250c8); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
table.users form.inline { display: flex; gap: 6px; align-items: center; }
table.users input[type=password] { max-width: 200px; }
