:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #2f5bd3;
  --high: #c62828;
  --medium: #d97706;
  --low: #2563eb;
  --info: #6b7280;
  --ok: #15803d;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b1f27;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --border: #2b313c;
    --accent: #7ea2ff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
pre { white-space: pre-wrap; max-width: 60ch; }
h1 { font-size: 1.35rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: .5rem 0; }
h4 { margin: 1rem 0 .25rem; font-weight: 500; }

.topbar { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; padding: .75rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }

.logout { margin-left: auto; display: flex; gap: .75rem; align-items: center; }
main { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 380px; margin: 4rem auto; }
.row { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.row.top { align-items: start; }
.row.spread { justify-content: space-between; align-items: center; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack label, .row label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.row label:has(input[type=checkbox]) { flex-direction: row; align-items: center; }
.muted { color: var(--muted); }
.error { color: var(--high); }
.error-cell { color: var(--high); font-size: .8rem; max-width: 40ch; }
.scroll { overflow-x: auto; }

input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
textarea { width: 100%; resize: vertical; }
.add-sites { display: flex; flex-direction: column; gap: .75rem; }
button { padding: .45rem .9rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 0; }
button.danger { background: var(--high); }
.danger-zone form { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; font-size: .8rem; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.compact td { padding: .15rem .5rem; }
tr.tracker td:first-child { font-weight: 600; }

.pill { display: inline-block; padding: 0 .45rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--border); white-space: nowrap; }
.sev-high { color: #fff; background: var(--high); border-color: var(--high); }
.sev-medium { color: #fff; background: var(--medium); border-color: var(--medium); }
.sev-low { color: var(--low); border-color: var(--low); }
.sev-info { color: var(--info); }
.status-done { color: var(--ok); border-color: var(--ok); }
.status-failed, .status-blocked { color: var(--high); border-color: var(--high); }
.status-queued, .status-running { color: var(--medium); border-color: var(--medium); }
.status-stalled { color: var(--high); border-color: var(--high); border-style: dashed; }

.stats { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1rem 0; }
.stats div { display: flex; flex-direction: column; padding: .5rem .9rem; border: 1px solid var(--border); border-radius: 6px; min-width: 110px; }
.stats b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: .8rem; color: var(--muted); }
.shot { max-width: 420px; width: 100%; border: 1px solid var(--border); border-radius: 6px; }
meter { width: 120px; }
details summary { cursor: pointer; color: var(--accent); }

/* sortable headers */
th { vertical-align: bottom; }
th a.sort { color: inherit; display: flex; gap: .25rem; align-items: baseline; line-height: 1.2; }
th a.sort:hover { color: var(--accent); text-decoration: none; }
th.num a.sort { flex-direction: row-reverse; }
th.sorted { color: var(--text); }
th .arrow { font-size: .65rem; min-width: .7rem; }

/* live updates */
.live[hidden] { display: none; }
.live { font-size: .75rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }
.live::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--muted); }
.live[data-state="ok"]::before { background: var(--ok); animation: pulse 2s ease-in-out infinite; }
.live[data-state="offline"]::before { background: var(--high); }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes updated { from { box-shadow: 0 0 0 2px var(--accent); } to { box-shadow: 0 0 0 2px transparent; } }
.flash-update { animation: updated 1.2s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .live[data-state="ok"]::before, .flash-update { animation: none; }
}

/* upload + messages */
label.file { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.flash { background: var(--card); border: 1px solid var(--accent); border-left-width: 4px; border-radius: 6px; padding: .6rem .9rem; margin: 0 0 1rem; }

/* severity pills link to that group of findings on the crawl page */
a.pill { text-decoration: none; }
a.pill:hover { filter: brightness(1.1); text-decoration: none; box-shadow: 0 0 0 2px var(--border); }
#findings, table.findings tbody { scroll-margin-top: 5rem; }
table.findings tbody:target td { animation: target-hl 2.5s ease-out; }
table.findings tbody:target td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
@keyframes target-hl { from { background: color-mix(in srgb, var(--accent) 18%, transparent); } }
@media (prefers-reduced-motion: reduce) { table.findings tbody:target td { animation: none; } }

/* links */
ul.links { margin: .4rem 0 .2rem; padding-left: 1.1rem; font-size: .85rem; }
ul.links li { margin: .1rem 0; overflow-wrap: anywhere; }
table.outbound details summary { color: var(--text); }
td.action { white-space: nowrap; text-align: right; }
form.inline { display: inline; }
button.small { padding: .15rem .6rem; font-size: .8rem; }
.stats span a { color: inherit; text-decoration: underline dotted; }

/* crawler page */
.headline { font-size: 1.2rem; font-weight: 600; }
.small { font-size: .8rem; }
.workers { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.worker { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; }
.worker header { display: flex; gap: .5rem; align-items: center; }
.worker header button { margin-left: auto; }
.worker p { margin: .35rem 0; }
.worker .site { overflow-wrap: anywhere; }
.worker .step { font-size: .9rem; overflow-wrap: anywhere; }
.worker.state-crawling { border-color: var(--ok); }
.worker.state-offline, .worker.state-stopped { opacity: .7; }
.status-crawling { color: var(--ok); border-color: var(--ok); }
.status-idle { color: var(--muted); }
.status-offline { color: var(--high); border-color: var(--high); }
.status-stopped { color: var(--muted); }

nav.filter { display: flex; gap: .75rem; font-size: .85rem; }
nav.filter a.active { font-weight: 600; color: var(--text); }
ol.log { list-style: none; margin: 0; padding: 0; font-size: .85rem; max-height: 70vh; overflow-y: auto; }
ol.log li { display: grid; grid-template-columns: 6.5rem 11rem 3.5rem 1fr; gap: .5rem; padding: .25rem .25rem; border-bottom: 1px solid var(--border); align-items: baseline; }
ol.log time, ol.log .who { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
ol.log .msg { overflow-wrap: anywhere; }
ol.log li.lvl-warn { background: color-mix(in srgb, var(--medium) 10%, transparent); }
ol.log li.lvl-error { background: color-mix(in srgb, var(--high) 12%, transparent); }
@media (max-width: 640px) {
  ol.log li { grid-template-columns: 5.5rem 1fr; }
  ol.log .who, ol.log .crawl { display: none; }
}

.viewer-frame { position: relative; background: #000; border-radius: 6px; overflow: hidden; aspect-ratio: 1366 / 768; display: grid; place-items: center; }
.viewer-frame img { width: 100%; height: 100%; object-fit: contain; }
.viewer-frame p { color: #ccc; padding: 1rem; text-align: center; }

td.status-cell { white-space: nowrap; }
td.status-cell form.inline { margin-left: .35rem; }
button.retry { background: var(--high); }

/* accounts */
.card.narrow-wide { max-width: 520px; }
.error-flash { border-color: var(--high); color: var(--high); }
.temp-password { border-color: var(--medium); border-width: 2px; }
code.secret { font-size: 1.1rem; padding: .3rem .6rem; background: var(--bg); border: 1px dashed var(--border); border-radius: 4px; user-select: all; }
form.delete-user label { display: inline; }

button.secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.secondary:hover { color: var(--text); }
.worker header form { margin-left: auto; }

.backoff { display: block; }
.backoff-note { font-size: .9rem; }
