:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1c2026;
  --muted: #667085;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf0d5;
  --err: #c0262d;
  --err-bg: #fbe4e4;
  --new-bg: #fde68a;
  --new-text: #5c4300;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1a1e25;
    --surface-2: #222732;
    --border: #2d3340;
    --text: #e6e8ec;
    --muted: #98a1b2;
    --accent: #6d93ff;
    --accent-text: #0d1220;
    --ok: #5fd39a;
    --ok-bg: #173527;
    --warn: #f3b955;
    --warn-bg: #3a2c12;
    --err: #ff7b7f;
    --err-bg: #3d1a1c;
    --new-bg: #574616;
    --new-text: #ffe28a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; word-break: break-all; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 16px; }
.brand { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.back { font-size: 13px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 48px 20px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .grid-2 { margin-top: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-error .kpi-value { color: var(--err); }
.kpi-warning .kpi-value { color: var(--warn); }
.kpi-ok .kpi-value { color: var(--ok); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
table.compact th, table.compact td { padding: 6px 8px; }
table.compact th { white-space: normal; }
.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trunc { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; opacity: .35; }
th.sorted-asc::after { content: " ↑"; opacity: 1; }
th.sorted-desc::after { content: " ↓"; opacity: 1; }
.site-link { font-weight: 550; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warning { background: var(--warn-bg); color: var(--warn); }
.pill-error { background: var(--err-bg); color: var(--err); }
.pill-info { background: var(--surface-2); color: var(--muted); }
.badge-new { display: inline-block; background: var(--new-bg); color: var(--new-text); font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 4px; margin-right: 4px; }
.delta { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }
.score { display: inline-block; min-width: 32px; text-align: center; font-weight: 700; border-radius: 6px; padding: 0 6px; }
.score.good, .score-text.good { color: var(--ok); }
.score.mid, .score-text.mid { color: var(--warn); }
.score.bad, .score-text.bad { color: var(--err); }
.text-bad { color: var(--err); }
.ok-text { color: var(--ok); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
ul.plain { padding-left: 18px; margin: 4px 0; }

.sev-head { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.sev-head:first-of-type { margin-top: 4px; }
.sev-error { color: var(--err); }
.sev-warning { color: var(--warn); }
.sev-info { color: var(--muted); }
.issue-group { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface); }
.issue-group summary { padding: 9px 12px; cursor: pointer; font-weight: 550; list-style-position: inside; }
.issue-group[open] summary { border-bottom: 1px solid var(--border); }
.issue-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.issue-list li { padding: 8px 12px; border-bottom: 1px solid var(--border); word-break: break-word; }
.issue-list li:last-child { border-bottom: 0; }

.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.score-ring { border: 1px solid var(--border); border-radius: 8px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; }
.score-ring strong { font-size: 22px; }
.score-ring span { font-size: 11px; color: var(--muted); }
.score-ring.good strong { color: var(--ok); }
.score-ring.mid strong { color: var(--warn); }
.score-ring.bad strong { color: var(--err); }

.chart-box { position: relative; height: 280px; }
.progress { display: inline-block; width: 140px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; vertical-align: middle; }
.progress span { display: block; height: 100%; background: var(--accent); }
.run-banner { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.run-banner .progress { width: 220px; }

.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 7px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 3px 9px; font-size: 12.5px; }

input[type=text], input[type=url], input[type=password], input[type=search], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
td input[type=text], td input[type=url] { width: 100%; min-width: 160px; padding: 4px 8px; }
.filter { width: 260px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: 13px; }
.login-card { max-width: 420px; margin: 40px auto; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 550; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

.checklist { list-style: none; padding: 0; margin: 0 0 12px; columns: 2; }
.checklist li { padding: 2px 0; break-inside: avoid; }
.checklist .ok { color: var(--ok); }
.checklist .bad { color: var(--err); }

/* Google Jobs */
.jobs-card { border-top: 3px solid var(--accent); }
.kpis-inner { margin: 12px 0 8px; }
.kpis-inner .kpi { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.jobs-schedule { margin-top: 12px; gap: 6px; }
.day-chip { position: relative; cursor: pointer; }
.day-chip input { position: absolute; opacity: 0; pointer-events: none; }
.day-chip span { display: inline-block; min-width: 38px; text-align: center; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; font-weight: 600; font-size: 13px; color: var(--muted); }
.day-chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.day-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
td input.input-pattern { min-width: 130px; }
.jobs-cell { font-weight: 550; margin-right: 4px; }

/* Live run status */
.run-status {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.run-status[hidden] { display: none; }
.run-status-stale { border-left-color: var(--warn); }
.run-status-done { border-left-color: var(--ok); }
.run-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.run-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.run-pct { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.run-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-check { width: 22px; height: 22px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; font-weight: 700; flex: none; }
.spinner {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.progress-live { width: 100%; height: 8px; border-radius: 4px; }
.progress-live span {
  border-radius: 4px; transition: width .6s ease;
  background-image: linear-gradient(110deg, var(--accent) 40%, color-mix(in srgb, var(--accent) 55%, #fff) 50%, var(--accent) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.live-dot { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; flex: none; }
.live-dot span { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.75); } }
@media (prefers-reduced-motion: reduce) {
  .spinner, .progress-live span, .live-dot span { animation: none; }
}

@media (max-width: 640px) {
  .live-dot { display: none; }
  .filter { width: 100%; }
  .page-head { align-items: stretch; }
  .scores { grid-template-columns: repeat(2, 1fr); }
  .checklist { columns: 1; }
  .trunc { max-width: 200px; }
}
