:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #15181e;
  --muted: #646b78;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --violet: #7c3aed;
  --empty: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1015;
    --surface: #151920;
    --surface-2: #1c212a;
    --border: #262c37;
    --text: #e8eaee;
    --muted: #8b93a3;
    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, .14);
    --amber: #f59e0b;
    --amber-soft: rgba(245, 158, 11, .14);
    --red: #f05252;
    --red-soft: rgba(240, 82, 82, .15);
    --blue: #60a5fa;
    --violet: #a78bfa;
    --empty: #2a303b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1015; --surface: #151920; --surface-2: #1c212a; --border: #262c37;
  --text: #e8eaee; --muted: #8b93a3; --green: #22c55e; --green-soft: rgba(34,197,94,.14);
  --amber: #f59e0b; --amber-soft: rgba(245,158,11,.14); --red: #f05252; --red-soft: rgba(240,82,82,.15);
  --blue: #60a5fa; --violet: #a78bfa; --empty: #2a303b; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 6px 12px;
}
button:hover { background: var(--surface-2); }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { font-size: 20px; margin-top: 14px; }
.login-card form { text-align: left; margin-top: 22px; display: grid; gap: 8px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input {
  font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
.login-card button[type=submit] {
  margin-top: 8px; padding: 10px; background: var(--text); color: var(--bg); border: 0; font-weight: 600;
}
.login-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--green-soft); display: grid; place-items: center; margin: 0 auto; }
.login-mark span { width: 14px; height: 14px; border-radius: 50%; background: var(--green); }
.form-error { color: var(--red); font-size: 13px; margin: 2px 0 0; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }
.ghost { background: transparent; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; display: grid; gap: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); position: relative; flex: none; }
.pulse.ok { background: var(--green); }
.pulse.warn { background: var(--amber); }
.pulse.bad { background: var(--red); }
.pulse.ok::after, .pulse.bad::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor;
  color: inherit; opacity: 0; animation: ping 2.4s ease-out infinite;
}
.pulse.ok::after { border-color: var(--green); }
.pulse.bad::after { border-color: var(--red); }
@keyframes ping { 0% { transform: scale(.6); opacity: .7; } 100% { transform: scale(1.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pulse::after { animation: none !important; } }

/* ---------- banner ---------- */
.banner {
  border-radius: var(--radius); padding: 14px 18px; display: flex; align-items: center; gap: 12px;
  font-weight: 600; border: 1px solid transparent; min-height: 52px;
}
.banner.ok { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 25%, transparent); }
.banner.warn { background: var(--amber-soft); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }
.banner.bad { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 25%, transparent); }
.banner .sub { font-weight: 400; color: var(--muted); margin-left: auto; font-size: 12px; }

/* ---------- VPS ---------- */
.vps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.stat { padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.stat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 28px; font-weight: 600; font-family: var(--mono); letter-spacing: -.02em; line-height: 1.1; }
.big small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 2px; font-family: system-ui, sans-serif; }
.meter { height: 6px; border-radius: 3px; background: var(--empty); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--green); transition: width .4s; }
.meter.warn > i { background: var(--amber); }
.meter.bad > i { background: var(--red); }
.kv { margin: 0; width: 100%; flex: none; align-content: start; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv.multiline dd { white-space: normal; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--green); }
.pill.warn::before { background: var(--amber); }
.pill.bad::before { background: var(--red); }
.pill.plain::before { display: none; }

.status-tag { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.status-tag.ok { background: var(--green-soft); color: var(--green); }
.status-tag.warn { background: var(--amber-soft); color: var(--amber); }
.status-tag.bad { background: var(--red-soft); color: var(--red); }

/* ---------- sites ---------- */
.sites-grid { display: grid; align-items: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); gap: 14px; }
.site { padding: 18px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.site.down { border-color: color-mix(in srgb, var(--red) 55%, var(--border)); }
.site-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.site-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.site-title h3 { font-size: 16px; }
.site-title a { font-size: 12px; color: var(--muted); text-decoration: none; }
.site-title a:hover { text-decoration: underline; }
.site-error { background: var(--red-soft); color: var(--red); padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 8px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.metric .label { font-size: 11px; color: var(--muted); }
.metric .value { font-family: var(--mono); font-size: 18px; font-weight: 600; margin-top: 2px; white-space: nowrap; }
.metric .value small { font-size: 11px; font-weight: 400; color: var(--muted); }
.metric .hint { font-size: 11px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-ok { color: var(--green); }
.v-warn { color: var(--amber); }
.v-bad { color: var(--red); }

.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.block-head b { font-weight: 600; font-size: 12px; }
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; height: 28px; }
.strip i { border-radius: 2px; background: var(--empty); }
.strip i.ok { background: var(--green); }
.strip i.warn { background: var(--amber); }
.strip i.bad { background: var(--red); }
.strip i:hover { opacity: .75; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

.chart { width: 100%; height: 64px; display: block; overflow: visible; }
.chart.tall { height: 90px; }
.chart .line { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .14; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart rect.bar { fill: var(--blue); }
.chart rect.bar.alt { fill: var(--violet); }
.chart rect.hit { fill: transparent; }
.chart rect.hit:hover + rect.bar, .chart g:hover rect.bar { opacity: .7; }

.visitor-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.visitor-stats div { min-width: 0; }
.visitor-stats .value { font-family: var(--mono); font-size: 20px; font-weight: 600; }
.visitor-stats .label { font-size: 11px; color: var(--muted); }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 5px; vertical-align: middle; }

details.more { border-top: 1px solid var(--border); padding-top: 12px; }
details.more summary { cursor: pointer; font-size: 13px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸"; transition: transform .15s; color: var(--muted); }
details.more[open] summary::before { transform: rotate(90deg); }
.insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; margin-top: 14px; }
.insights .full { grid-column: 1 / -1; }
.toplist { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 12px; }
.toplist li { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 3px 6px; border-radius: 4px; overflow: hidden; }
.toplist li > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; z-index: 1; }
.toplist li > span:last-child { font-family: var(--mono); color: var(--muted); position: relative; z-index: 1; }
.toplist li > i { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--blue) 12%, transparent); border-radius: 4px; }
.empty { font-size: 12px; color: var(--muted); padding: 4px 0; }
.note { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- incidents ---------- */
.incidents { list-style: none; margin: 0; padding: 0; }
.incidents li { display: grid; grid-template-columns: 150px 1fr auto; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); align-items: center; font-size: 13px; }
.incidents li:first-child { border-top: 0; }
.incidents .when { color: var(--muted); font-size: 12px; }
.incidents .none { display: block; color: var(--muted); grid-column: 1 / -1; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg);
  font-size: 12px; padding: 6px 9px; border-radius: 6px; max-width: 260px; white-space: pre-line; line-height: 1.35;
}
.skeleton { height: 140px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.4s infinite; border: 1px solid var(--border); }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; position: static; }
  .wrap { padding: 16px 16px 40px; gap: 22px; }
  .visitor-stats { grid-template-columns: repeat(2, 1fr); }
  .insights { grid-template-columns: 1fr; }
  .incidents li { grid-template-columns: 1fr auto; }
  .incidents .when { grid-column: 1 / -1; }
  #updated { display: none; }
}

/* ---------- muted sites ---------- */
.status-tag.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.site.is-muted { opacity: .7; transition: opacity .15s; }
.site.is-muted:hover, .site.is-muted:focus-within { opacity: 1; }
.site-error.quiet { background: var(--surface-2); color: var(--muted); }
.site-status { text-align: right; display: grid; gap: 4px; justify-items: end; }
.site-status-row { display: flex; align-items: center; gap: 8px; }
.mute-btn { font-size: 12px; padding: 2px 10px; border-radius: 999px; color: var(--muted); }
.mute-btn:hover { color: var(--text); }
