:root {
  --bg: #f6f7f9; --panel: #ffffff; --line: #dfe3e8; --text: #1c2128; --muted: #6b7480;
  --accent: #1f6feb; --accent-text: #ffffff;
  --ok: #1a7f37; --ok-bg: #dafbe1; --warn: #9a6700; --warn-bg: #fff8c5;
  --fail: #cf222e; --fail-bg: #ffebe9; --off: #57606a; --off-bg: #eaeef2;
  --pending: #6e7781; --pending-bg: #f1f3f5;
  --row-hover: #f0f4ff; --shadow: 0 8px 30px rgba(0,0,0,.14);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #161b22; --line: #2b323b; --text: #e6edf3; --muted: #8b949e;
    --accent: #3b82f6; --ok: #3fb950; --ok-bg: #12331b; --warn: #d29922; --warn-bg: #3a2d05;
    --fail: #f85149; --fail-bg: #46171a; --off: #9da7b3; --off-bg: #22272e;
    --pending: #8b949e; --pending-bg: #1c2128; --row-hover: #1c2433; --shadow: 0 8px 30px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { display: inline-flex; align-items: center; margin-right: 4px; }
.brand-logo img { display: block; height: 22px; width: auto; }
.brand-mark { color: var(--accent); font-size: 18px; }
.counts { display: inline-flex; gap: 6px; margin-left: 8px; }
.counts .pill { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.poll-status { font-size: 12px; color: var(--muted); }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 6px 12px;
  border-radius: 6px; cursor: pointer; font: inherit; line-height: 1.2; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--fail); }
.btn.danger:hover { border-color: var(--fail); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
button.icon { border: 0; background: transparent; cursor: pointer; font-size: 15px; padding: 2px 5px;
  color: var(--muted); border-radius: 4px; }
button.icon:hover { background: var(--off-bg); color: var(--text); }
button.icon.danger:hover { color: var(--fail); }
button.icon.spin { animation: spin 1s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 8px 18px 0; overflow-x: auto; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; font: inherit; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab .n { font-size: 11px; background: var(--off-bg); color: var(--off); border-radius: 999px; padding: 0 6px; }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tab .dot.OK { background: var(--ok); } .tab .dot.WARN { background: var(--warn); }
.tab .dot.FAIL, .tab .dot.OFFLINE, .tab .dot.AUTH, .tab .dot.ERROR { background: var(--fail); }
.tab .dot.PENDING { background: var(--pending); }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 18px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 260px; max-width: 420px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--text); font: inherit; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.bulk { display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: var(--row-hover);
  border: 1px solid var(--line); border-radius: 6px; }
.bulk select { padding: 4px 6px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit; }

/* table */
main { padding: 0 18px 30px; }
.site-footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px 22px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
table.fleet { width: 100%; border-collapse: collapse; min-width: 1100px; }
.fleet th, .fleet td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
  white-space: nowrap; }
.fleet th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600;
  position: sticky; top: 0; background: var(--panel); z-index: 1; }
.fleet th[data-sort] { cursor: pointer; user-select: none; }
.fleet th[data-sort]:hover { color: var(--text); }
.fleet th.sorted::after { content: " ▲"; font-size: 10px; }
.fleet th.sorted.desc::after { content: " ▼"; }
.fleet tbody tr.cam-row { cursor: pointer; }
.fleet tbody tr.cam-row:hover { background: var(--row-hover); }
.fleet tbody tr.selected { background: var(--row-hover); }
.fleet tbody tr.disabled td { opacity: .55; }
.col-check, .col-actions { width: 1%; }
.col-actions { text-align: right; }
.col-name .name { font-weight: 600; display: block; }
.col-name .notes { display: block; font-size: 12px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.col-name .notes:empty { display: none; }
.col-app .pkg { display: block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
.col-host a { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 700; letter-spacing: .02em; }
.badge.OK { background: var(--ok-bg); color: var(--ok); }
.badge.WARN { background: var(--warn-bg); color: var(--warn); }
.badge.FAIL, .badge.AUTH, .badge.ERROR { background: var(--fail-bg); color: var(--fail); }
.badge.OFFLINE { background: var(--off-bg); color: var(--off); }
.badge.PENDING, .badge.POLLING { background: var(--pending-bg); color: var(--pending); }
.badge .spinner { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
.chip { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; background: var(--off-bg); color: var(--off); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.fail { background: var(--fail-bg); color: var(--fail); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* details row */
tr.details td { background: var(--bg); padding: 12px 16px 16px 48px; white-space: normal; cursor: default; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 32px; }
@media (max-width: 1100px) { .details-grid { grid-template-columns: 1fr; } }
.details h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
  overflow-wrap: anywhere; }
.checks { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.checks li { display: grid; grid-template-columns: 16px 160px 1fr; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.checks li:last-child { border-bottom: 0; }
.checks .g { font-weight: 700; text-align: center; }
.checks .g.OK { color: var(--ok); } .checks .g.WARN { color: var(--warn); } .checks .g.FAIL { color: var(--fail); }
.checks .g.SKIP { color: var(--muted); }
.checks .nm { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }
.checks .dt { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.details .error { color: var(--fail); font-family: ui-monospace, monospace; font-size: 12px; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form, dialog .dlg-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
dialog label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
dialog input:not([type=checkbox]), dialog select, dialog textarea { padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; width: 100%; }
dialog textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; align-self: end; padding-bottom: 8px; }
.check-label input { width: auto !important; }
.interval-row { display: flex; gap: 8px; align-items: center; }
.interval-row select { flex: 1; }
.interval-row input { width: 130px !important; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-error { color: var(--fail); margin: 0; min-height: 1em; font-size: 13px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.group-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.group-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.group-list .gname { font-weight: 600; }
.group-list .gdesc { color: var(--muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.group-list input { flex: 1; }
.group-list .n { font-size: 12px; color: var(--muted); }

/* toast */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.error { background: var(--fail); color: #fff; }

/* agent upgrade dialog */
#dlg-upgrade { width: min(760px, calc(100vw - 32px)); }
.upgrade-list { max-height: 40vh; }
table.fleet.mini { min-width: 0; font-size: 13px; }
table.fleet.mini th, table.fleet.mini td { padding: 5px 8px; }
.upgrade-msg { color: var(--muted); font-size: 12px; display: block; max-width: 340px; white-space: normal; }
.badge.UPGRADING { background: var(--pending-bg); color: var(--pending); }
.badge.REBOOTING { background: var(--pending-bg); color: var(--pending); }

/* ---- sign-in page + account UI (multi-user, sc-173400) ---- */
.login-page { display: flex; flex-direction: column; min-height: 100vh; }
.login-card { margin: auto; width: min(360px, calc(100% - 32px)); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 26px 24px; box-shadow: var(--shadow); }
.login-card h1 { margin: 12px 0 18px; font-size: 20px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); box-sizing: border-box; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.login-card .hint { margin-top: 14px; font-size: 12px; color: var(--muted); }
.whoami { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.whoami .chip { font-weight: 600; }
.temp-password { display: block; margin-top: 6px; padding: 8px 10px; border-radius: 6px; border: 1px dashed var(--line);
  background: var(--bg); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row .who { flex: 1 1 160px; }
.user-row .groups { flex: 2 1 220px; font-size: 12px; color: var(--muted); }
.g-interval-label { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.g-interval-label input { padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); color: var(--text); font-size: 12px; }
