:root {
  --bg: #0a0b0d;
  --surface: #101216;
  --surface-2: #15181e;
  --surface-3: #1b1f26;
  --border: #23272f;
  --border-soft: #1a1d23;
  --text: #e7e9ee;
  --muted: #8b93a1;
  --muted-dim: #626b78;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --sev0: #7c8797;
  --sev1: #38bdf8;
  --sev2: #fbbf24;
  --sev3: #fb923c;
  --sev4: #f4536b;
  --ok: #34d399;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent); text-decoration: none; }

code, .mono { font-family: var(--mono); }

.hidden { display: none !important; }

.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 4px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: grid; place-items: center;
  color: #04181c; font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted-dim); font-size: 11px; font-family: var(--mono); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; border: none; background: none;
  width: 100%; text-align: left; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; margin-left: auto; background: var(--sev4); }
.nav-item .badge { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted-dim); }

.nav-spacer { flex: 1; }
.nav-foot { padding: 10px; color: var(--muted-dim); font-size: 11px; }
.nav-foot button { color: var(--muted); background: none; border: none; cursor: pointer; padding: 4px 0; }
.nav-foot button:hover { color: var(--text); }

.main { overflow-y: auto; padding: 26px 32px 60px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.page-desc { color: var(--muted); font-size: 13px; margin-top: 3px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn {
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--surface-3); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-weight: 500;
  transition: transform .06s, background .12s, border-color .12s;
}
.btn:hover { background: #20242c; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04181c; font-weight: 600; }
.btn-primary:hover { background: #38dcf3; }
.btn-danger { color: var(--sev4); border-color: #3a2027; }
.btn-danger:hover { background: #241318; }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.stat.alarm .stat-value { color: var(--sev4); }
.stat.good .stat-value { color: var(--ok); }

.panel {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); overflow: hidden;
}
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: center; }
.panel-title { font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 10px 18px; color: var(--muted-dim);
  font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--border-soft);
}
td { padding: 11px 18px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px;
  background: var(--surface-3); border: 1px solid var(--border);
  font-family: var(--mono);
}
.tag .d { width: 6px; height: 6px; border-radius: 50%; }
.status-active { color: var(--ok); } .status-active .d { background: var(--ok); }
.status-killed, .status-revoked { color: var(--sev4); } .status-killed .d, .status-revoked .d { background: var(--sev4); }
.status-suspended { color: var(--sev2); } .status-suspended .d { background: var(--sev2); }
.status-offline { color: var(--muted-dim); } .status-offline .d { background: var(--muted-dim); }

.sev { font-family: var(--mono); font-size: 12px; }
.sev-0 { color: var(--sev0); } .sev-1 { color: var(--sev1); }
.sev-2 { color: var(--sev2); } .sev-3 { color: var(--sev3); } .sev-4 { color: var(--sev4); }

.mono-id { font-family: var(--mono); color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.dim { color: var(--muted-dim); }

.empty { padding: 46px 20px; text-align: center; color: var(--muted-dim); }
.empty-title { color: var(--muted); font-size: 15px; margin-bottom: 6px; }

.skeleton { height: 14px; border-radius: 5px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }

.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  outline: none; transition: border-color .12s;
}
.input:focus { border-color: var(--accent-dim); }
.input::placeholder { color: var(--muted-dim); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
textarea.input { resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters .input { width: auto; min-width: 150px; }

.overlay {
  position: fixed; inset: 0; background: rgba(4,5,7,.66);
  display: flex; justify-content: flex-end; z-index: 40;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } }
.drawer {
  width: min(560px, 100%); height: 100%; background: var(--surface);
  border-left: 1px solid var(--border); overflow-y: auto; padding: 24px 26px;
  animation: slide .18s cubic-bezier(.16,1,.3,1);
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.drawer-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; }
.drawer-close:hover { color: var(--text); }

.modal-center { justify-content: center; align-items: center; }
.modal { width: min(560px, 92%); max-height: 88vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 26px; animation: pop .16s cubic-bezier(.16,1,.3,1); }
@keyframes pop { from { transform: scale(.97); opacity: .5; } }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 8px 14px; margin: 4px 0 18px; }
.kv .k { color: var(--muted); font-size: 12.5px; }
.kv .v { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

.alertbar {
  background: linear-gradient(90deg, rgba(244,83,107,.14), transparent);
  border: 1px solid #3a2027; border-left: 3px solid var(--sev4);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 18px;
}
.alertbar .t { color: var(--sev4); font-weight: 600; margin-bottom: 4px; }

.section-label { color: var(--muted-dim); font-size: 12px; margin: 22px 0 10px; font-weight: 500; }

.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.toggle-row:last-child { border-bottom: none; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border); border-radius: 22px; transition: .16s; cursor: pointer; }
.switch .track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 2px; background: var(--muted); border-radius: 50%; transition: .16s; }
.switch input:checked + .track { background: var(--accent-dim); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); background: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 3px 9px; border-radius: 6px; background: var(--surface-3); border: 1px solid var(--border); font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.codebox { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; white-space: pre-wrap; word-break: break-all; color: var(--muted); line-height: 1.55; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 16px; box-shadow: 0 12px 40px rgba(0,0,0,.4); animation: pop .16s; }
.toast.err { border-color: #3a2027; color: var(--sev4); }
.toast.ok { border-color: #1d3a30; color: var(--ok); }

.login-wrap { display: grid; place-items: center; height: 100vh; }
.login-card { width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 28px; }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; box-shadow: 0 0 0 0 rgba(52,211,153,.5); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.4); } 70% { box-shadow: 0 0 0 6px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }

.routing-note { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; line-height: 1.5; }
.routing-tbl { width: 100%; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); overflow: hidden; }
.routing-tbl th { padding: 8px 12px; font-size: 11.5px; text-align: center; }
.routing-tbl th:first-child { text-align: left; }
.routing-tbl td { padding: 8px 12px; text-align: center; border-bottom: 1px solid var(--border-soft); }
.routing-tbl td:first-child { text-align: left; color: var(--text); }
.routing-tbl tr:last-child td { border-bottom: none; }

.switch.sm { width: 34px; height: 19px; margin: 0 auto; }
.switch.sm .track::before { width: 13px; height: 13px; top: 2px; }
.switch.sm input:checked + .track::before { transform: translateX(15px); }

.detect-row { display: grid; grid-template-columns: 1fr 130px 44px 30px; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.detect-row:last-child { border-bottom: none; }
.detect-name { color: var(--text); }
.input.sm, select.input.sm { padding: 5px 8px; font-size: 12.5px; }

.exp-caret { color: var(--muted-dim); display: inline-block; transition: transform .12s; font-size: 11px; }
tr.expanded .exp-caret { transform: rotate(90deg); color: var(--accent); }
.detail-row td { background: var(--surface-2); padding: 0; }
.ev-detail { padding: 16px 20px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; }
}
