:root {
  --bg: #07090d;
  --glass: rgba(255, 255, 255, 0.055);
  --glass-strong: rgba(22, 25, 32, 0.88);
  --glass-hover: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.055);
  --text: #eceef4;
  --muted: #8b93a3;
  --accent: #0a84ff;
  --up: #30d158;
  --slow: #ff9f0a;
  --down: #ff453a;
  --blocked: #bf5af2;
  --pending: #98989d;
  --disabled: #5b6170;
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ambient background glow */
#bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(620px 420px at 12% -8%, rgba(10, 132, 255, 0.16), transparent 65%),
    radial-gradient(720px 520px at 105% 12%, rgba(191, 90, 242, 0.10), transparent 65%),
    radial-gradient(800px 600px at 50% 115%, rgba(48, 209, 88, 0.07), transparent 65%);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--down); font-size: 0.9em; }
a { color: var(--accent); }

/* glass surface */
.glass, .panel, #modal, #ctx-menu {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  border: 1px solid var(--border);
}

/* ---------- login ---------- */
#login-view, #setup-view {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
#setup-view.hidden { display: none !important; }
.login-box {
  border-radius: 22px;
  padding: 38px; width: 370px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
}
.login-box h1 { font-size: 1.3em; margin: 0 0 4px; font-weight: 650; }
.login-box input {
  width: 100%; padding: 11px 13px; margin: 16px 0 12px;
  border: 1px solid var(--border); border-radius: 12px; font-size: 1em;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
}
.login-box input::placeholder { color: var(--muted); }
.login-box #passkey-login { margin-top: 22px; padding: 12px; }
.login-divider {
  display: flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 0.82em; margin-top: 18px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ---------- app shell ---------- */
#app-view { min-height: 100vh; }
main { max-width: 1150px; margin: 0 auto; padding: 26px 30px 110px; }

/* floating dock (replaces the sidebar) */
#dock {
  position: fixed; left: 18px; bottom: 18px; z-index: 80;
  display: flex; align-items: center; gap: 4px; padding: 7px;
  border-radius: 18px; border: 1px solid var(--border);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}
.dock-sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; }
.icon-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 13px;
  color: var(--muted); background: transparent; border: none; cursor: pointer;
  transition: background 0.12s, color 0.12s; text-decoration: none;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.icon-btn.active { color: var(--text); background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.health-dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; }
.health-dot.up { background: var(--up); box-shadow: 0 0 6px rgba(48, 209, 88, 0.7); }
.health-dot.slow { background: var(--slow); box-shadow: 0 0 6px rgba(255, 159, 10, 0.7); }
.health-dot.down { background: var(--down); box-shadow: 0 0 7px rgba(255, 69, 58, 0.8); animation: pulse 1.5s infinite; }
#paused-badge { position: fixed; left: 18px; bottom: 80px; z-index: 80; }

/* server health page */
.sh-sub { color: var(--muted); font-weight: 400; font-size: 0.85em; }

/* zapier setup steps */
.zap-steps { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 12px; font-size: 0.92em; }
.zap-steps li::marker { color: var(--accent); font-weight: 600; }
.zap-steps .hint code { font-size: 0.95em; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.06); color: var(--text);
  border-radius: 11px; padding: 7px 14px; font-size: 0.92em; cursor: pointer; font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
  font-family: inherit;
}
.btn:hover { background: var(--glass-hover); border-color: rgba(255, 255, 255, 0.16); }
.btn.primary {
  background: var(--accent); border-color: transparent; color: #fff;
  box-shadow: 0 2px 14px rgba(10, 132, 255, 0.35);
}
.btn.primary:hover { background: #2e95ff; }
.btn.danger { color: var(--down); }
.btn.ghost { border: none; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.btn.small { padding: 4px 10px; font-size: 0.85em; border-radius: 9px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- badges + dots ---------- */
.badge {
  font-size: 0.74em; padding: 3px 10px; border-radius: 999px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.badge.paused { background: rgba(255, 159, 10, 0.16); color: var(--slow); border: 1px solid rgba(255, 159, 10, 0.3); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.up { background: var(--up); box-shadow: 0 0 7px rgba(48, 209, 88, 0.6); }
.dot.slow { background: var(--slow); box-shadow: 0 0 7px rgba(255, 159, 10, 0.6); }
.dot.down { background: var(--down); box-shadow: 0 0 8px rgba(255, 69, 58, 0.7); animation: pulse 1.5s infinite; }
.dot.blocked { background: var(--blocked); box-shadow: 0 0 7px rgba(191, 90, 242, 0.6); }
.dot.pending { background: var(--pending); }
.dot.disabled { background: var(--disabled); }
@keyframes pulse { 50% { opacity: 0.4; } }

.status-text.up { color: var(--up); }
.status-text.slow { color: var(--slow); }
.status-text.down { color: var(--down); }
.status-text.blocked { color: var(--blocked); }
.status-text.pending, .status-text.disabled { color: var(--pending); }

/* ---------- summary chips ---------- */
.summary { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.summary .chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass); border: 1px solid var(--border); border-radius: 13px; padding: 9px 15px;
  -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%);
}
.summary .chip b { font-size: 1.12em; }
.summary .chip.clickable { cursor: pointer; user-select: none; transition: border-color 0.12s, background 0.12s; }
.summary .chip.clickable:hover { background: var(--glass-hover); }
.summary .chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 2px 16px rgba(10, 132, 255, 0.25); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] {
  flex: 1; min-width: 200px; padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 11px; font-size: 0.95em;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
}
.toolbar input[type=search]::placeholder { color: var(--muted); }
.toolbar a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.tips { font-size: 0.85em; margin-top: 6px; }

/* ---------- tree ---------- */
.panel { border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
details.node > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; transition: background 0.1s;
}
details.node > summary:hover { background: rgba(255, 255, 255, 0.03); }
details.node > summary::-webkit-details-marker { display: none; }
details.node > summary .chev { transition: transform 0.15s; color: var(--muted); font-size: 0.72em; }
details.node[open] > summary .chev { transform: rotate(90deg); }
.node-name { font-weight: 600; }
.node-meta { color: var(--muted); font-size: 0.85em; }
.node-actions { margin-left: auto; display: flex; gap: 6px; opacity: 0; transition: opacity 0.12s; }
summary:hover .node-actions, .vrow:hover .node-actions { opacity: 1; }
.node-children { padding-left: 26px; border-top: 1px solid var(--border-soft); }
.level-client > summary { padding: 10px 16px; }
.level-campaign > summary, .level-lp > summary { padding: 9px 16px; }
.level-client .node-name, .level-campaign .node-name { font-weight: 550; }
.level-lp .node-name { font-weight: 500; }

.vrow {
  display: flex; align-items: center; gap: 10px; padding: 9px 16px;
  border-top: 1px solid var(--border-soft); transition: background 0.1s;
}
.vrow:hover { background: rgba(255, 255, 255, 0.03); }
.vrow .vname { font-weight: 500; text-decoration: none; color: var(--text); }
.vrow .vname:hover { color: var(--accent); }
.vrow .vurl {
  color: var(--muted); font-size: 0.85em; text-decoration: none;
  max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vrow .vurl:hover { color: var(--accent); }
.vrow .vstats {
  margin-left: auto; display: flex; align-items: center;
  color: var(--muted); font-size: 0.85em; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.vstats .v-status { width: 74px; font-weight: 600; }
.vstats .v-load { width: 78px; text-align: right; }
.vstats .v-time { width: 86px; text-align: right; }
/* only ONE auto margin per row, or flexbox splits the slack and columns drift */
.vrow .node-actions { margin-left: 14px; }
.empty-hint { padding: 12px 16px; color: var(--muted); font-size: 0.9em; }

.vcheck { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; margin: 0; }

/* ---------- context menu ---------- */
#ctx-menu {
  position: fixed; z-index: 200;
  background: var(--glass-strong);
  border-radius: 14px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  padding: 6px; min-width: 205px;
}
#ctx-menu .ctx-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 7px 12px; border-radius: 9px; font-size: 0.92em; cursor: pointer; color: var(--text);
  font-family: inherit;
}
#ctx-menu .ctx-item:hover { background: rgba(255, 255, 255, 0.08); }
#ctx-menu .ctx-item.danger { color: var(--down); }
#ctx-menu .ctx-sep { height: 1px; background: var(--border-soft); margin: 5px 6px; }

/* ---------- bulk bar ---------- */
#bulk-bar {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--border);
  color: var(--text); border-radius: 16px; padding: 10px 16px;
  display: flex; gap: 8px; align-items: center; z-index: 90;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  white-space: nowrap;
}
#bulk-bar b { margin-right: 4px; font-size: 0.92em; }
#bulk-bar .btn.danger { color: var(--down); }

/* ---------- modal ---------- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#modal {
  background: var(--glass-strong);
  border-radius: 20px; padding: 26px; width: 450px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
#modal h3 { margin: 0 0 16px; font-weight: 650; }
#modal label { display: block; font-size: 0.88em; font-weight: 600; margin: 12px 0 5px; }
#modal input[type=text], #modal input[type=url], #modal input[type=password], #modal textarea, #modal select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 11px; font-size: 0.95em;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-family: inherit;
}
#modal select.range-sel { width: auto; padding: 5px 8px; font-size: 0.88em; border-radius: 9px; background: var(--glass-strong); }
#modal input::placeholder, #modal textarea::placeholder { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-error { color: var(--down); font-size: 0.88em; margin-top: 10px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--glass-strong); color: var(--text);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 13px;
  font-size: 0.92em; z-index: 100; box-shadow: 0 14px 50px rgba(0, 0, 0, 0.5);
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.85em; padding: 10px 14px; border-bottom: 1px solid var(--border); }
td { padding: 9px 14px; border-bottom: 1px solid var(--border-soft); }
tr:last-child td { border-bottom: none; }

/* ---------- detail page ---------- */
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; flex-wrap: wrap; }
.detail-head h2 { margin: 0; font-weight: 650; }
.detail-head a.btn { text-decoration: none; }
.crumbs { color: var(--muted); font-size: 0.9em; margin-bottom: 18px; }
.stat-grid { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.stat {
  background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%);
  padding: 14px 18px; min-width: 130px;
}
.stat .label { color: var(--muted); font-size: 0.78em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.35em; font-weight: 650; margin-top: 4px; }
.stat .value.ok { color: var(--up); }
.stat .value.warn { color: var(--slow); }
.stat .value.bad { color: var(--down); }
.stat .target { color: var(--muted); font-size: 0.76em; margin-top: 3px; }
.chart-panel { padding: 16px; }
.chart-panel h3, .panel h3.pad { margin: 0 0 12px; font-size: 1em; font-weight: 600; }
canvas { width: 100%; height: 180px; display: block; }
.range-sel {
  border: 1px solid var(--border); border-radius: 9px; padding: 5px 8px; font-size: 0.88em;
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-family: inherit;
}

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-section {
  background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%);
  padding: 20px;
}
.settings-section h3 { margin: 0 0 4px; font-size: 1.02em; font-weight: 650; }
.settings-section .sub { color: var(--muted); font-size: 0.86em; margin: 0 0 14px; }
.settings-section a.btn { text-decoration: none; display: inline-block; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.88em; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: 0.8em; color: var(--muted); margin-top: 4px; }
.field input[type=number], .field input[type=text], .field input[type=url], .field input[type=password] {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 11px; font-size: 0.95em;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
}
.field input::placeholder { color: var(--muted); }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field.inline label { margin: 0; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: rgba(255, 255, 255, 0.14); border-radius: 999px; cursor: pointer; transition: background 0.15s;
}
.switch .track::after {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: left 0.15s; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.switch input:checked + .track { background: var(--up); }
.switch input:checked + .track::after { left: 20px; }
.save-bar { margin-top: 12px; display: flex; gap: 10px; align-items: center; }

.pk-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border-soft); font-size: 0.92em;
}
.pk-row:last-of-type { border-bottom: none; }
.pk-row .pk-name { font-weight: 550; }
.pk-row .pk-date { color: var(--muted); font-size: 0.88em; margin-left: auto; }

/* ---------- headings ---------- */
h2 { font-weight: 650; }

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* touch devices: hover-revealed buttons must stay visible */
@media (hover: none) {
  .node-actions { opacity: 1 !important; }
}

@media (max-width: 1180px) {
  /* keep the floating batch bar clear of the dock */
  #bulk-bar { bottom: 86px; }
  #toast { bottom: 86px; }
}
@media (max-width: 900px) {
  main { padding: 20px 16px 120px; }
  .settings-grid { grid-template-columns: 1fr; }
  .vrow .vurl { display: none; }
  #bulk-bar { flex-wrap: wrap; white-space: normal; max-width: 92vw; }
}
