:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f0f1f4;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefe;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --nav: #111318;
  --nav-ink: #c9ccd3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --ink: #e8eaee;
    --muted: #9aa0ab;
    --line: #262a33;
    --soft: #1e222a;
    --accent: #5b82ff;
    --accent-soft: #1d2744;
    --ok: #4ade80;
    --ok-soft: #13291c;
    --warn: #fbbf24;
    --warn-soft: #2e2410;
    --bad: #f87171;
    --bad-soft: #321616;
    --nav: #0b0d10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.ic { width: 16px; height: 16px; flex: none; }

/* ---------- layout ---------- */
body.has-nav { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav {
  background: var(--nav); color: var(--nav-ink);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 15px; padding: 0 8px 22px; }
.brand:hover { text-decoration: none; }
.brand.big { color: var(--ink); padding: 0 0 18px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 15px;
}
.nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav nav a {
  display: flex; align-items: center; gap: 10px; color: var(--nav-ink);
  padding: 9px 10px; border-radius: 8px;
}
.nav nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.nav-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding: 14px 10px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-foot .who { font-size: 13px; color: #fff; overflow: hidden; text-overflow: ellipsis; }
button.link { background: none; border: 0; color: var(--nav-ink); cursor: pointer; display: flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; padding: 4px; }
button.link:hover { color: #fff; }

.main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1240px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); margin-bottom: 14px; font-size: 13px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; height: 40px; }
.btn.update { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.btn.danger-btn { color: var(--bad); }
.btn.danger-btn:hover { background: var(--bad-soft); }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn .spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
input:not([type=checkbox]), textarea {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-weight: 400;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.hint { margin: -6px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.narrow { max-width: 460px; padding: 22px; }
.card.narrow h2 { margin-bottom: 14px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat .num { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .num small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat .lbl { color: var(--muted); font-size: 12px; }
.stat.warn .num { color: var(--warn); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.site-card { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.site-top { display: flex; align-items: flex-start; gap: 10px; }
.site-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.site-name { color: var(--ink); font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-url { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.meta div { background: var(--soft); border-radius: 8px; padding: 8px 10px; }
.meta dt { font-size: 11px; color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta div { min-width: 0; }
.meta dd .muted { font-weight: 400; font-size: 12px; }
.err-line { margin: 0; color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.site-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; }
.row-actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; margin-top: 6px; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.error { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
h1.with-dot { display: flex; align-items: center; gap: 12px; }
h1.with-dot .dot { margin-top: 0; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--soft); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12px; }
.chip b { font-weight: 600; }

/* ---------- table ---------- */
.table-card { overflow: hidden; }
.table-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search { flex-direction: row; align-items: center; gap: 0; position: relative; font-weight: 400; }
.search .ic { position: absolute; left: 10px; color: var(--muted); }
.search input { padding-left: 32px; height: 34px; width: 220px; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 16px; background: var(--soft); white-space: nowrap; }
.tbl td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tr.busy td { opacity: .6; }
.p-name { font-weight: 600; }
.p-sub { font-size: 12px; color: var(--muted); }
.ver { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ver .arrow { color: var(--warn); font-weight: 600; }
.empty-inline { padding: 28px 16px; text-align: center; }
.empty-inline p { margin: 0 0 8px; }

.empty { padding: 32px; max-width: 640px; }
.steps { padding-left: 20px; line-height: 1.9; color: var(--muted); }
.steps strong { color: var(--ink); }

.danger { margin-top: 28px; display: flex; justify-content: flex-end; }

/* ---------- alerts & toasts ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12); font-size: 13px; animation: in .2s ease-out; }
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--bad); }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- dialog ---------- */
.dialog { border: 0; border-radius: 14px; padding: 24px; width: min(520px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10, 12, 16, .5); }
.dialog h2 { font-size: 18px; }
.dialog p { margin: -8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- auth ---------- */
.no-nav .main { max-width: none; padding: 0; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; }
.auth-card > p { margin: 6px 0 20px; }


/* ---------- tabs & modules ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 10px 14px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { background: var(--soft); color: var(--muted); border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.tabs .livedot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

.module-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.module-head p { margin: 2px 0 0; }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); padding: 0 6px; height: 30px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); position: relative; }
.pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--ok); opacity: 0; animation: pulse 1.6s ease-out infinite; }
.live.paused .pulse { background: var(--muted); }
.live.paused .pulse::after { animation: none; }
@keyframes pulse { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.6); opacity: 0; } }

.widgets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.widget { grid-column: span 2; }
.widget.half { grid-column: span 1; }
.widget.card { padding: 0; overflow: hidden; }
.widget .w-title { font-size: 13px; font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.widget .w-body { padding: 14px 16px; }
.widget .w-body.flush { padding: 0; }
.widget .tbl td, .widget .tbl th { padding: 9px 16px; }
.widget .tbl tr:first-child td { border-top: 0; }
.w-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat .hint { font-size: 11px; color: var(--muted); }
.stat.ok .num { color: var(--ok); }
.stat.bad .num { color: var(--bad); }
.w-list { list-style: none; margin: 0; padding: 0; }
.w-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--line); }
.w-list li:first-child { border-top: 0; }
.w-list .li-meta { font-size: 12px; color: var(--muted); }
.w-empty { padding: 18px 16px; color: var(--muted); text-align: center; font-size: 13px; }
.w-text { white-space: pre-wrap; margin: 0; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--ink); font-size: 13px; }
.notice.ok { background: var(--ok-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.chart svg { width: 100%; height: 200px; display: block; }
.chart .axis { stroke: var(--line); }
.chart .lbl { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); padding-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.w-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.w-form .full { grid-column: 1 / -1; }
.w-form select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.w-form .help { font-weight: 400; font-size: 12px; color: var(--muted); }
.w-form-foot { display: flex; justify-content: flex-end; margin-top: 14px; }

.mod-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.mod-chip { display: inline-flex; align-items: baseline; gap: 5px; font-size: 12px; background: var(--accent-soft); color: var(--ink); border-radius: 8px; padding: 4px 10px; }
.mod-chip:hover { text-decoration: none; filter: brightness(.97); }
.mod-chip b { font-size: 13px; color: var(--accent); }

@media (max-width: 860px) {
  .widgets { grid-template-columns: 1fr; }
  .widget, .widget.half { grid-column: span 1; }
}

.subpages { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.subpages button { background: var(--soft); border: 1px solid transparent; border-radius: 999px; padding: 3px 11px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; }
.subpages button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.embed-frame { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: max(560px, calc(100vh - 250px)); }
.embed-frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #f0f0f1; }
.embed-frame .embed-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
.embed-frame .embed-msg .stack { align-items: center; max-width: 420px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body.has-nav { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 6px; }
  .brand { padding: 0; }
  .brand span:last-child { display: none; }
  .nav nav { flex-direction: row; }
  .nav nav a span, .nav-foot .who, button.link span { display: none; }
  .nav-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .main { padding-top: 22px; }
  .search input { width: 100%; }
  .search { flex: 1; }
  .tbl th:nth-child(2), .tbl td:nth-child(2) { display: none; }
}
