:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #e2e7ef;
  --text: #0f1729;
  --muted: #5d6b82;
  --accent: #2071a8;
  --accent-soft: rgba(32, 113, 168, .1);
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --idle: #8a94a6;
  --info: #2071a8;
  --chart-1: #2071a8;
  --chart-2: #9333ea;
  --chart-3: #0d9488;
  --chart-4: #ea580c;
  --shadow: 0 1px 2px rgba(15, 23, 41, .05), 0 4px 16px rgba(15, 23, 41, .04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #121a2e; --surface-2: #18223a; --border: #232f4a;
    --text: #e6ebf5; --muted: #8b98b3; --accent: #4fa3dc; --accent-strong: #2071a8; --accent-soft: rgba(79, 163, 220, .14);
    --ok: #22c55e; --warn: #f59e0b; --bad: #f87171; --idle: #6b7690; --info: #4fa3dc;
    --chart-1: #4fa3dc; --chart-2: #c084fc; --chart-3: #2dd4bf; --chart-4: #fb923c;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --surface: #121a2e; --surface-2: #18223a; --border: #232f4a;
  --text: #e6ebf5; --muted: #8b98b3; --accent: #4fa3dc; --accent-strong: #2071a8; --accent-soft: rgba(79, 163, 220, .14);
  --ok: #22c55e; --warn: #f59e0b; --bad: #f87171; --idle: #6b7690; --info: #4fa3dc;
  --chart-1: #4fa3dc; --chart-2: #c084fc; --chart-3: #2dd4bf; --chart-4: #fb923c;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 6px; }
.brand-lg { font-size: 20px; padding: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; object-fit: contain; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.login-logo { width: 56px; height: 56px; object-fit: contain; }
.login-title { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.server-chip { font-size: 12px; color: var(--muted); padding: 8px 10px; background: var(--surface-2); border-radius: 8px; line-height: 1.4; }
.server-chip b { color: var(--text); font-weight: 600; display: block; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--accent); }
nav a svg { width: 18px; height: 18px; flex: none; }
nav .badge { margin-left: auto; }
.sidebar-foot { display: flex; gap: 6px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.menu-btn { display: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live.stale .dot { background: var(--warn); box-shadow: none; }
.page { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1500px; width: 100%; }

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.span-2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.section-title { display: flex; align-items: center; gap: 10px; }
.section-title .spacer { flex: 1; }

.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.stat-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 550; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.pill.idle { color: var(--idle); }
.pill.info { color: var(--info); background: var(--accent-soft); }
.pill.plain::before { display: none; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.bad { background: var(--bad); color: #fff; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  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;
  transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong, var(--accent)); border-color: var(--accent-strong, var(--accent)); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-strong, var(--accent)) 88%, #000); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: color-mix(in srgb, var(--bad) 10%, transparent); border-color: var(--bad); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--bad) 85%, #000); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 9px; }
.btn-block { width: 100%; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 18px; border-top: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-top: 0; background: var(--surface-2); white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }
tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.cell-main { font-weight: 550; }
.cell-sub { font-size: 12px; color: var(--muted); }

/* ---------- project cards ---------- */
.proj-card { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s, transform .15s; position: relative; overflow: hidden; }
.proj-card:hover { border-color: var(--accent); }
.proj-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--idle); }
.proj-card.ok::before { background: var(--ok); }
.proj-card.warn::before { background: var(--warn); }
.proj-card.bad::before { background: var(--bad); }
.proj-card h3 { font-size: 16px; }
.proj-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.proj-metrics div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.proj-metrics b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.proj-metrics span { font-size: 11px; color: var(--muted); }

/* ---------- alerts ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 500; }
.alert::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--info); flex: none; }
.alert.bad { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.alert.bad::before { background: var(--bad); }
.alert.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.alert.warn::before { background: var(--warn); }
.alert a { margin-left: auto; font-size: 12px; }
.all-good { display: flex; align-items: center; gap: 10px; color: var(--ok); font-weight: 600; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 10.5px; font-family: inherit; }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg);
  font-size: 12px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; transform: translate(-50%, -110%);
  font-variant-numeric: tabular-nums; z-index: 2;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.core { background: var(--surface-2); border-radius: 6px; height: 34px; position: relative; overflow: hidden; }
.core > span { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent-soft); border-top: 2px solid var(--accent); }
.core b { position: relative; font-size: 10.5px; display: block; text-align: center; line-height: 34px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- key/value ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ---------- logs, modal, toasts ---------- */
pre.logs {
  background: #0a0f1c; color: #cbd5e1; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  padding: 14px; border-radius: 10px; max-height: 62vh; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0;
}
pre.plain { background: var(--surface-2); color: var(--text); padding: 12px; border-radius: 8px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; margin: 0; overflow: auto; }
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 0; width: min(960px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.narrow { width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 10, 20, .55); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
#modal-body { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 500; max-width: 420px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); white-space: pre-wrap; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
input, select {
  font: inherit; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--bad); min-height: 1.5em; margin: 0; font-weight: 500; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }

.empty { color: var(--muted); padding: 24px; text-align: center; }
.back { font-size: 13px; font-weight: 550; }
.spin { display: inline-block; 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); } }

/* ---------- responsive ---------- */
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar { padding: 12px 16px; }
  .page { padding: 16px 16px 40px; }
  .user { display: none; }
}
@media (max-width: 560px) { .grid-4 { grid-template-columns: 1fr; } .stat-value { font-size: 24px; } }

/* ---------- logo in dark mode: lift the blue so the outline reads on navy ---------- */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-mark, :root:not([data-theme="light"]) .login-logo { filter: brightness(1.5) saturate(1.1); } }
:root[data-theme="dark"] .brand-mark, :root[data-theme="dark"] .login-logo { filter: brightness(1.5) saturate(1.1); }

/* ---------- view-only accounts never see controls that would be refused ---------- */
body[data-role="viewer"] :is([data-cact], [data-pact], [data-sact], [data-prune], [data-unload], [data-logs], [data-slogs], [data-deploy], [data-joblog], [data-gitcheck], [data-mute], .admin-only) { display: none !important; }
.role-chip { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- banners ---------- */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-weight: 500; }
.banner .spacer { flex: 1; }
.banner.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }

/* ---------- forms in cards ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.field-hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.switch { display: inline-flex; flex-direction: row; align-items: center; gap: 10px; cursor: pointer; font-weight: 550; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: var(--border); position: relative; padding: 0; border: 0; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(16px); }
.steps { margin: 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }
.steps b, .steps code { color: var(--text); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: var(--mono); font-size: 12px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 220px; height: 220px; display: grid; place-items: center; }
.qr svg { width: 100%; height: 100%; }

/* ---------- deploy ---------- */
.deploy-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.deploy-meta > div { background: var(--surface-2); border-radius: 8px; padding: 9px 12px; min-width: 0; }
.deploy-meta b { display: block; font-size: 14px; overflow-wrap: anywhere; }
.deploy-meta span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.incoming { margin: 0 0 14px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-family: var(--mono); font-size: 12px; max-height: 160px; overflow: auto; }
.step-list { margin: 0; padding: 10px 12px 10px 30px; background: var(--surface-2); border-radius: 8px; font-family: var(--mono); font-size: 12px; }

/* ---------- backups ---------- */
.backup-item { border-top: 1px solid var(--border); padding: 12px 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; }
.backup-item:first-of-type { border-top: 0; padding-top: 0; }
.problem { color: var(--bad); font-weight: 500; font-size: 13px; }
