:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2f7a1f;
  --brand-ink: #ffffff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --top: #10230c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --panel: #131c2e;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #23304a;
    --brand: #3f9a2b;
    --good: #4ade80;
    --good-bg: #14532d55;
    --warn: #fbbf24;
    --warn-bg: #78350f55;
    --bad: #f87171;
    --bad-bg: #7f1d1d55;
    --info: #93c5fd;
    --info-bg: #1e3a8a55;
    --top: #0a1608;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: .85em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.txt-good, .ok-text { color: var(--good); }
.txt-warn { color: var(--warn); }
.txt-bad { color: var(--bad); }
.wrap { max-width: 1400px; margin: 0 auto; padding: 20px 16px 40px; }

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--top); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs a {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 10px; color: #cbd5e1; font-weight: 500;
}
.tabs a:hover { background: #ffffff14; text-decoration: none; color: #fff; }
.tabs a.on { background: #ffffff1f; color: #fff; }
.tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: #f59e0b; color: #111; font-size: 12px; line-height: 20px; text-align: center;
}
.logout { margin: 0; }
.topbar .btn.ghost { color: #cbd5e1; border-color: #334155; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn.big { min-height: 48px; font-size: 1rem; }
.btn.icon { width: 40px; padding: 0; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin .8s linear infinite;
}
.btn.primary.busy::after { border-color: #fff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- page heads */
.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-block; margin-bottom: 6px; font-size: .9rem; }
.site-head h1 { display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------------------ summary */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.stat b { font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 260px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-size: .9rem; cursor: pointer;
}
.chip:hover { text-decoration: none; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* -------------------------------------------------------------- cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
.card, .panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 10px; border-top: 4px solid var(--line); }
.card.state-ok { border-top-color: var(--good); }
.card.state-updates { border-top-color: #f59e0b; }
.card.state-down, .card.state-error { border-top-color: var(--bad); }
.card header { display: flex; align-items: flex-start; gap: 10px; }
.card .title { min-width: 0; flex: 1; }
.card h2 { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card h2 a { color: var(--ink); }
.domain { display: block; font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.dot { flex: none; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; background: var(--muted); }
.state-ok .dot, .state-updates .dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.state-down .dot, .state-error .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.statusline { margin: 0; font-size: .9rem; color: var(--muted); }
.statusline strong { color: var(--ink); font-weight: 600; }
.state-down .statusline strong, .state-error .statusline strong { color: var(--bad); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.facts.wide { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

.updates { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; align-items: center; font-size: .9rem; }
.pill { padding: 3px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.pill.warn { background: var(--bad-bg); color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.actions .btn { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; }
.card .refresh { flex: none; width: 34px; min-height: 34px; margin: -4px -6px 0 0; border-color: transparent; color: var(--muted); }
.card .refresh:hover { color: var(--ink); border-color: var(--line); }
.checked { margin: 0; font-size: .75rem; color: var(--muted); }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 10px; margin: 0; font-size: .9rem; overflow-wrap: anywhere; }

/* backup menu */
details.menu { position: relative; flex: 1 1 0; min-width: 0; }
details.menu > summary { list-style: none; width: 100%; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after { content: " ▾"; font-size: .8em; }
.menu-pop {
  position: absolute; z-index: 15; bottom: calc(100% + 6px); left: 0; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px #0003; padding: 6px;
}
.menu-pop button {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px;
  background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.menu-pop button:hover, .menu-pop button:focus-visible { background: var(--bg); }
.menu-pop button span { color: var(--muted); font-size: .85em; }

/* -------------------------------------------------------------- panels */
.panel { padding: 16px; margin-bottom: 14px; }
.panel h2 { margin-bottom: 4px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.warn-panel { background: var(--warn-bg); color: var(--warn); border-color: transparent; font-weight: 500; }
.help { background: var(--info-bg); border-color: transparent; }
.help p { margin: 0; }
.notes { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--line); white-space: pre-wrap; }
.panel.danger { border-color: var(--bad-bg); }
.panel.danger p { margin-top: 0; color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; }
.empty ol { text-align: left; display: inline-block; margin: 16px auto 24px; }

.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 14px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-ver { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.row-ver b { color: var(--ink); }
.row.has-update .row-main strong::before { content: "● "; color: #f59e0b; }
.row-err { grid-column: 1 / -1; }
.row .check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.group .row { grid-template-columns: 1fr auto; }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; padding: 4px 0 8px; }

.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); align-items: baseline; }
.log li:first-child { border-top: 0; }
.log .ok .mark { color: var(--good); }
.log .fail .mark { color: var(--bad); }

/* --------------------------------------------------------------- forms */
input, textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-size: 16px;
}
textarea { min-height: 80px; }
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); flex: none; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.stack label.check { flex-direction: row; align-items: center; }
.form { max-width: 640px; }
.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login h1 { margin: 10px 0 20px; }
.login form { text-align: left; }
.login .error { margin-bottom: 14px; }

/* -------------------------------------------------------- results sheet */
.sheet { position: fixed; inset: 0; z-index: 50; background: #0f172a99; display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  width: 100%; max-width: 760px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: 18px 18px 0 0; padding: 16px 16px max(16px, env(safe-area-inset-bottom));
}
@media (min-width: 760px) { .sheet { align-items: center; } .sheet-panel { border-radius: 18px; } }
.sheet-panel header, .sheet-panel footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-panel footer { padding-top: 12px; border-top: 1px solid var(--line); justify-content: flex-end; }
.sheet-summary { margin: 8px 0 10px; }
.results { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.results li { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.results li:first-child { border-top: 0; }
.job-main { display: flex; flex-direction: column; min-width: 0; }
.job-main span { font-size: .9rem; color: var(--muted); }
.job-main .msg { font-size: .85rem; overflow-wrap: anywhere; }
.job-links { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.results .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--bg); }
.results .working .mark { border: 2px solid var(--brand); border-top-color: transparent; background: transparent; animation: spin .8s linear infinite; }
.results .ok .mark { background: var(--good-bg); color: var(--good); }
.results .ok .mark::before { content: "✓"; }
.results .fail .mark { background: var(--bad-bg); color: var(--bad); }
.results .fail .mark::before { content: "✗"; }
.results .ok .msg { color: var(--good); }
.results .fail .msg { color: var(--bad); font-weight: 600; }
body.sheet-open { overflow: hidden; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 150%); z-index: 60;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 6px 24px #0004;
  transition: transform .25s ease, visibility 0s .25s; pointer-events: none; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform .25s ease; }
#toast.good { background: var(--good); color: #fff; }
#toast.bad { background: var(--bad); color: #fff; }

/* -------------------------------------------------------------- mobile */
@media (max-width: 720px) {
  .wrap { padding: 14px 12px 96px; }
  h1 { font-size: 1.3rem; }
  .topbar { justify-content: space-between; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    justify-content: space-around; padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    background: var(--top); border-top: 1px solid #1f3a18;
  }
  .tabs a { flex-direction: column; gap: 2px; padding: 6px 14px; font-size: .75rem; }
  .tabs .count { position: absolute; top: 0; right: 4px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .facts.wide { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr; }
  .pagehead .head-actions { width: 100%; }
  .pagehead .head-actions .btn { flex: 1; }
  .row { grid-template-columns: 1fr auto; }
  .row-ver { grid-column: 1; grid-row: 2; }
  .row-act { grid-column: 2; grid-row: 1 / span 2; }
  .results li { grid-template-columns: 24px 1fr; }
  .job-links { grid-column: 2; justify-content: flex-start; }
  #toast { bottom: 84px; }
}
