:root {
  --bg: #080e1a;
  --panel: rgba(17, 28, 48, 0.85);
  --panel-2: #132139;
  --border: rgba(120, 150, 200, 0.15);
  --text: #e9effb;
  --muted: #8b9fc1;
  --up: #2fd68a;
  --degraded: #f5b942;
  --down: #ff5d6c;
  --unknown: #7c8aa5;
  --accent: #4d8dff;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 650px at 8% -12%, #16304f 0%, transparent 58%),
    radial-gradient(900px 600px at 100% 0%, #0f2f46 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 13, 24, 0.75);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.logo {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; font-weight: 800; font-size: 13px; letter-spacing: 0.5px;
  background: linear-gradient(140deg, #4d8dff, #23b7a5);
  color: #06111f;
  box-shadow: 0 8px 22px rgba(77, 141, 255, 0.28);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.live {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px;
  background: rgba(15, 26, 44, 0.7);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--up);
  box-shadow: 0 0 0 0 rgba(47, 214, 138, 0.6);
  animation: pulse 2s infinite;
}
.live.err .pulse { background: var(--down); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 214, 138, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(47, 214, 138, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 214, 138, 0); }
}

main { padding: 24px 24px 60px; max-width: 1600px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 18px; }

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 19px;
  position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; right: -30px; bottom: -60px; width: 130px; height: 130px;
  background: radial-gradient(circle, currentColor 0%, transparent 70%); opacity: 0.09;
}
.kpi .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.kpi.up { color: var(--up); }
.kpi.degraded { color: var(--degraded); }
.kpi.down { color: var(--down); }
.kpi.neutral { color: #d6e4ff; }
.kpi.agent { color: var(--accent); }

.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
}

.agent-filter {
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto; padding: 2px 2px 4px;
  scrollbar-width: thin;
}
.agent-filter:empty { display: none; }
.agent-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  white-space: nowrap; transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.agent-chip:hover { background: #1a2b47; }
.agent-chip:active { transform: translateY(1px); }
.agent-chip.active {
  background: rgba(77, 141, 255, 0.16);
  border-color: rgba(77, 141, 255, 0.55);
  color: #dbe8ff;
  box-shadow: 0 0 0 3px rgba(77, 141, 255, 0.1);
}
.agent-chip .chip-count {
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: rgba(120, 150, 200, 0.14); padding: 1px 7px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.agent-chip.active .chip-count { color: #bcd6ff; background: rgba(77, 141, 255, 0.22); }
.agent-chip .dot { width: 8px; height: 8px; }
.spacer { flex: 1; }
.search { width: 250px; }

input, select {
  background: #0b1626; border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 11px; font-size: 12.5px; font-family: inherit; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { border-color: rgba(77, 141, 255, 0.7); box-shadow: 0 0 0 3px rgba(77, 141, 255, 0.16); }
input::placeholder { color: #566b8c; }

.btn {
  appearance: none; border: 1px solid var(--border); background: #16233c; color: var(--text);
  padding: 8px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  font-family: inherit; cursor: pointer; white-space: nowrap;
  transition: transform 0.12s, background 0.15s;
}
.btn:hover { background: #1d2f4e; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(160deg, #4d8dff, #2f6ae0); border-color: transparent; color: #fff; box-shadow: 0 8px 20px rgba(47, 106, 224, 0.28); }
.btn.ghost { background: transparent; }
.btn.mini { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.muted { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 11.5px; margin: 0; line-height: 1.5; }
.mono { font-family: "Cascadia Mono", Consolas, "SF Mono", monospace; font-size: 12px; color: #bfd1f0; }

.agents { display: flex; flex-direction: column; gap: 24px; }

.agent {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
}
.agent-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(30, 46, 74, 0.7), rgba(18, 30, 50, 0.4));
  border-bottom: 1px solid var(--border);
}
.agent-head h3 { font-size: 15px; }
.agent-meta { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.chip {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: rgba(120, 150, 200, 0.12); color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.online { color: var(--up); border-color: rgba(47, 214, 138, 0.35); background: rgba(47, 214, 138, 0.1); }
.chip.offline { color: var(--down); border-color: rgba(255, 93, 108, 0.35); background: rgba(255, 93, 108, 0.1); }

.agent-body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 16px; }

.category-head {
  display: flex; align-items: center; gap: 9px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted);
  margin-bottom: 12px;
}
.category-head .line { flex: 1; height: 1px; background: var(--border); }

.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }

.item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--unknown);
  border-radius: 12px;
  padding: 16px 17px;
  display: flex; flex-direction: column; gap: 12px;
  cursor: pointer;
  transition: transform 0.13s, border-color 0.15s, background 0.15s;
  position: relative;
}
.item:hover { transform: translateY(-2px); background: #17263f; }
.item.up { border-left-color: var(--up); }
.item.degraded { border-left-color: var(--degraded); }
.item.down { border-left-color: var(--down); background: rgba(255, 93, 108, 0.05); }
.item.unknown { border-left-color: var(--unknown); opacity: 0.75; }

.item-top { display: flex; align-items: center; gap: 8px; }
.item-top h4 { margin: 0; font-size: 13.5px; font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.latency { font-size: 11px; color: var(--muted); font-family: Consolas, monospace; flex: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); flex: none; }
.dot.up { background: var(--up); box-shadow: 0 0 0 4px rgba(47, 214, 138, 0.15); }
.dot.degraded { background: var(--degraded); box-shadow: 0 0 0 4px rgba(245, 185, 66, 0.15); }
.dot.down { background: var(--down); box-shadow: 0 0 0 4px rgba(255, 93, 108, 0.15); }

.item .target { font-size: 11.5px; color: #93a9cc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.status-text { font-size: 11.5px; font-weight: 650; }
.status-text.up { color: var(--up); }
.status-text.degraded { color: var(--degraded); }
.status-text.down { color: var(--down); }
.status-text.unknown { color: var(--unknown); }
.item-foot .time { font-size: 11px; color: var(--muted); }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 16px; }
.spark i {
  flex: 1; min-width: 2px; height: 100%; border-radius: 2px;
  background: rgba(124, 138, 165, 0.35);
}
.spark i.up { background: rgba(47, 214, 138, 0.65); }
.spark i.degraded { background: rgba(245, 185, 66, 0.7); }
.spark i.down { background: rgba(255, 93, 108, 0.75); }

.msg {
  font-size: 11.5px; color: var(--muted); margin: 4px 0 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.admin-tools { display: flex; gap: 6px; }

.empty {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(17, 28, 48, 0.4);
}
.empty h3 { color: var(--text); margin-bottom: 8px; }
.empty p { max-width: 560px; margin: 0 auto; line-height: 1.6; font-size: 13px; }
.empty code { background: #0b1626; padding: 2px 6px; border-radius: 5px; color: #a9c6ff; }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 24px 26px; max-width: 1600px; margin: 0 auto;
  color: #5d7194; font-size: 11.5px;
}

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(3, 7, 14, 0.75);
  display: grid; place-items: center; padding: 20px; z-index: 60;
  backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal-box {
  width: min(620px, 100%);
  background: #0f1a2d;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  max-height: 92vh; overflow-y: auto;
}
.modal-box.small { width: min(420px, 100%); }
.modal-box h2 { margin-bottom: 14px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.switch { flex-direction: row !important; align-items: center; gap: 9px !important; color: var(--text) !important; font-size: 12.5px !important; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.detail-head p { margin: 4px 0 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.detail-grid > div {
  background: #0b1626; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.detail-grid .label, .field-block .label { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; }
.detail-grid strong { font-size: 13px; font-weight: 600; word-break: break-word; }

.status.big { font-size: 12px; font-weight: 650; padding: 5px 11px; border-radius: 999px; white-space: nowrap; }
.status.big.up { color: var(--up); background: rgba(47, 214, 138, 0.12); }
.status.big.degraded { color: var(--degraded); background: rgba(245, 185, 66, 0.12); }
.status.big.down { color: var(--down); background: rgba(255, 93, 108, 0.12); }
.status.big.unknown { color: var(--unknown); background: rgba(124, 138, 165, 0.12); }

.bars { display: flex; align-items: flex-end; gap: 2px; height: 64px; background: #0b1626; border: 1px solid var(--border); border-radius: 9px; padding: 8px; overflow: hidden; }
.bars i { flex: 1; min-width: 2px; height: 100%; border-radius: 2px; background: rgba(124, 138, 165, 0.28); }
.bars i.up { background: var(--up); opacity: 0.82; }
.bars i.degraded { background: var(--degraded); opacity: 0.85; }
.bars i.down { background: var(--down); opacity: 0.9; }

.legend { display: flex; gap: 14px; margin: 10px 0 16px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; background: var(--unknown); }
.sw.up { background: var(--up); }
.sw.degraded { background: var(--degraded); }
.sw.down { background: var(--down); }

.field-block { display: flex; flex-direction: column; gap: 7px; padding: 12px; background: #0b1626; border: 1px solid var(--border); border-radius: 12px; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; font-family: Consolas, monospace; font-size: 12px; }
.admin-agents { display: flex; flex-direction: column; gap: 8px; }
.admin-agent {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #0f1a2d; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  font-size: 12px;
}
.admin-agent .grow { flex: 1; min-width: 120px; }

.admin-users { display: flex; flex-direction: column; gap: 8px; }
.admin-user {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #0f1a2d; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  font-size: 12px;
}
.admin-user .grow { flex: 1; min-width: 120px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #16233c; border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 11px; font-size: 13px; z-index: 100;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
.toast[hidden] { display: none; }
.toast.ok { border-color: rgba(47, 214, 138, 0.5); }
.toast.err { border-color: rgba(255, 93, 108, 0.5); }

/* ---------- dashboard grid with access panel ---------- */
.dashboard-wrap {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
.dashboard-main { min-width: 0; }
.access-panel {
  position: sticky;
  top: 100px;
  align-self: start;
}
.access-panel h2 {
  font-size: 15px;
  margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.access-list {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 60vh; overflow-y: auto;
}
.access-item {
  display: flex; flex-direction: column; gap: 8px;
  background: #0b1626; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  font-size: 12px;
}
.access-item .ip { font-weight: 650; color: #dbe8ff; word-break: break-all; }
.access-item .ua { color: #93a9cc; font-size: 11px; font-family: Consolas, monospace; word-break: break-all; }
.access-item .when { color: var(--muted); font-size: 11px; margin-top: 2px; }
.access-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--up); flex: none; box-shadow: 0 0 0 3px rgba(47, 214, 138, 0.15); }
.access-item header { display: flex; align-items: center; gap: 8px; }

@media (max-width: 900px) {
  .dashboard-wrap { grid-template-columns: 1fr; }
  .access-panel { position: static; top: auto; align-self: auto; max-height: none; }
  .access-list { max-height: 300px; }
}

@media (max-width: 700px) {
  main { padding: 14px 12px 30px; }
  .topbar { padding: 12px; flex-wrap: wrap; }
  .search { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .items { grid-template-columns: 1fr; }
}
