:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #15803d;   --ok-bg: #e7f6ec;
  --warn: #b45309; --warn-bg: #fdf3e1;
  --bad: #b91c1c;  --bad-bg: #fde8e8;
  --side: #0f172a; --side-text: #cbd5e1; --side-active: #1e293b;
  --code-bg: #0b1220; --code-text: #d6e2f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #121a2b; --surface-2: #0f1625; --border: #233049;
    --text: #e5ebf5; --muted: #8b9bb4; --accent: #5b8cff; --accent-ink: #0b1020; --accent-soft: #1b2847;
    --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33270e; --bad: #f87171; --bad-bg: #3a1717;
    --side: #080d1a; --side-text: #a9b6cc; --side-active: #16213a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.center { text-align: center; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: .2px; }
.brand b { color: var(--accent); font-weight: 700; }
.brand.big { font-size: 22px; justify-content: center; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent) url("favicon.svg") center/cover; flex: none; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card .muted { text-align: center; margin: 6px 0 22px; }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; padding: 4px 10px 18px; }
.srv { padding: 0 6px 10px; display: flex; flex-direction: column; gap: 4px; }
.srv-current { color: #fff; font-weight: 600; font-size: 13px; padding: 6px 10px; background: var(--side-active); border-radius: 7px; }
.srv-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 0 4px; }
.srv select { background: var(--side-active); color: #fff; border-color: #334155; width: 100%; }
ol.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 10px 6px; }
#nav a { color: var(--side-text); padding: 8px 10px; border-radius: 7px; display: flex; align-items: center; gap: 10px; }
#nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
#nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
#nav a .dot { width: 7px; height: 7px; border-radius: 50%; background: #475569; flex: none; }
#nav a.active .dot { background: var(--accent); }
.side-foot { margin-top: auto; font-size: 12px; color: #64748b; padding: 16px 10px 0; line-height: 1.6; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.top-right { display: flex; align-items: center; gap: 12px; }
.user { color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.live.off i { background: var(--muted); }
.menu-btn { display: none; }
.content { padding: 22px 24px 48px; display: flex; flex-direction: column; gap: 18px; }

/* cards / grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; }
.card.flush > h2, .card.flush > .card-head { padding: 16px 18px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.t-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.t-value { font-size: 26px; font-weight: 650; margin: 2px 0 10px; font-variant-numeric: tabular-nums; }
.t-sub { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.meter { height: 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s; }
.meter.warn i { background: var(--warn); }
.meter.bad i { background: var(--bad); }

.svc { display: flex; flex-direction: column; gap: 8px; }
.svc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.svc-head b { font-size: 15px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.svc .actions { margin-top: auto; padding-top: 6px; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.muted { color: var(--muted); background: var(--surface-2); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; margin: 1px 4px 1px 0; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { color: var(--muted); font-size: 12px; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.wrap-any { overflow-wrap: anywhere; }

/* toolbar & forms */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .grow { flex: 1; }
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.invalid { border-color: var(--bad); }
input[type="checkbox"] { padding: 0; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
textarea.code { width: 100%; min-height: 340px; font-family: var(--mono); font-size: 12.5px; background: var(--code-bg); color: var(--code-text); border-color: var(--code-bg); line-height: 1.5; tab-size: 2; }

.btn { font: inherit; font-weight: 550; font-size: 13px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
td.actions .btn { margin-left: 4px; }
.icon-btn { border: 0; background: transparent; color: inherit; font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

/* modal */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog.wide { width: min(1100px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 15, 30, .55); }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); margin: 0; }
.m-head h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.m-body { padding: 18px; max-height: calc(100vh - 200px); overflow: auto; }
.m-body p:first-child { margin-top: 0; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.card-pad { padding: 0 18px 16px; }
pre.cmd { background: var(--code-bg); color: var(--code-text); font: 12.5px/1.55 var(--mono); padding: 12px 14px; border-radius: 8px; overflow-x: auto; margin: 8px 0 0; }
pre.logs { background: var(--code-bg); color: var(--code-text); font: 12px/1.55 var(--mono); padding: 14px; border-radius: 8px; height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 12px 0 0; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); font-size: 13px; overflow-wrap: anywhere; }
.toast.error { border-left-color: var(--bad); }

.notice { border: 1px solid var(--border); border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.notice.warn { border-left-color: var(--warn); background: var(--warn-bg); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .user, .live { display: none; }
}
