:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f1f4; --border: #e2e4e9;
  --text: #1b1e24; --muted: #6b7280; --accent: #3b6ef5; --accent-text: #fff;
  --ok: #18a058; --warn: #d98b0b; --danger: #d64545; --chart-grid: rgba(0,0,0,.06);
  --c1: #3b6ef5; --c2: #e0752d; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e6e8ec; --muted: #8b93a3; --accent: #5b8bff; --chart-grid: rgba(255,255,255,.06);
    --c1: #5b8bff; --c2: #f0894a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 2px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0; } h3 { font-size: 14px; margin: 0 0 8px; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow-x: auto; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.break { word-break: break-all; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.logo { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.logout { margin: 0; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.crumb { font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-head p { margin: 4px 0 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 26px; font-weight: 650; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.tile-value.small-value { font-size: 16px; line-height: 1.6; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar.thin { height: 4px; width: 70px; margin-left: auto; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.bar span.hot { background: var(--warn); } .bar span.crit { background: var(--danger); }
.mini { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }

.chart-wrap { position: relative; height: 220px; } .chart-wrap.sm { height: 170px; }
.live { font-weight: 600; font-variant-numeric: tabular-nums; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vm-link { font-weight: 600; }
.actions { text-align: right; white-space: nowrap; }
.actions form { display: inline-flex; gap: 4px; margin: 0; }
table.kv td { padding: 6px 8px; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

.state { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.state-running { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.state-paused, .state-pmsuspended { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.state-crashed { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); margin-left: 4px; font-weight: 500; }
.pill.fw { color: var(--ok); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; }
.badge.warn { background: var(--warn); color: #fff; }
.count { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); padding: 0 7px; border-radius: 99px; }
.act { font-weight: 600; font-size: 12px; }
.act-accept { color: var(--ok); } .act-drop, .act-reject { color: var(--danger); }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; padding: 7px 14px;
  border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.full { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; }

input, select { font: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); max-width: 100%; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; max-width: 760px; }
.form-grid .span2 { grid-column: span 2; }
details summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
details[open] { display: grid; gap: 12px; }
.rule-form, .policy-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.policy-row label { flex-direction: row; align-items: center; gap: 8px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.presets form { margin: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; } .tab-panel.active { display: block; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; white-space: pre-wrap; }
.flash.ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.flash.error { border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.flash.warn { border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }

.login-box { max-width: 380px; margin: 10vh auto; padding: 28px; }
.login-box h1 { justify-content: center; margin-bottom: 18px; }
.login-box form { display: grid; gap: 14px; }

.checklist { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.checklist .mark { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; }
.checklist .ok .mark { background: var(--ok); } .checklist .ko .mark { background: var(--warn); }
.stack { display: grid; gap: 10px; max-width: 380px; }
.steps { padding-left: 20px; margin: 0; display: grid; gap: 18px; }
.qr-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.qr { background: #fff; padding: 6px; border-radius: 8px; line-height: 0; }
.qr svg { width: 200px; height: 200px; }
.secret { display: inline-block; font-size: 15px; letter-spacing: .08em; padding: 6px 10px; background: var(--surface-2); border-radius: 6px; word-break: break-all; margin: 4px 0; }
.code-input { font-size: 20px; letter-spacing: .3em; text-align: center; max-width: 180px; font-family: ui-monospace, Consolas, monospace; }
tr.row-bad td { background: color-mix(in srgb, var(--danger) 7%, transparent); }

.busy-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; color: #fff; font-size: 16px; }

@media (max-width: 700px) {
  .container { padding: 16px; } .topbar { padding: 10px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; }
}
