:root {
  color-scheme: dark;
  --bg: #0a0d13;
  --panel: #10141d;
  --panel-2: #151a26;
  --panel-3: #1a2030;
  --border: #1f2635;
  --border-soft: #1a2130;
  --text: #e6eaf2;
  --muted: #8a94a8;
  --faint: #5c6579;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.12);
  --blue: #5ea8ff;
  --blue-dim: rgba(94, 168, 255, 0.12);
  --amber: #f5b942;
  --amber-dim: rgba(245, 185, 66, 0.12);
  --red: #f2635f;
  --red-dim: rgba(242, 99, 95, 0.12);
  --radius: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
.hidden { display: none !important; }
a { color: var(--blue); text-decoration: none; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.logo-mark {
  width: 34px; height: 34px; border-radius: 8px; flex: 0 0 34px;
  background: var(--accent-dim);
  border: 1px solid rgba(52, 211, 153, 0.35);
  position: relative;
}
.logo-mark::before {
  content: ""; position: absolute; inset: 8px;
  border-left: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
  border-radius: 1px;
}
.logo-mark::after {
  content: ""; position: absolute; left: 6px; right: 6px; top: 50%;
  height: 3px; margin-top: -1.5px; background: var(--accent); border-radius: 2px;
}
.logo-name { font-weight: 700; font-size: 16px; letter-spacing: 0; }
.logo-sub { color: var(--faint); font-size: 11px; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  background: none; border: none; color: var(--muted);
  font: inherit; font-weight: 500; cursor: pointer; text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item.active .nav-ic { color: var(--accent); }
.nav-ic { display: inline-flex; color: var(--faint); }

.sidebar-footer { margin-top: auto; padding: 14px; border-top: 1px solid var(--border-soft); }
.version { margin-top: 10px; text-align: center; color: var(--faint); font-size: 11px; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: rgba(16, 20, 29, 0.7); backdrop-filter: blur(6px);
}
.page-title { margin: 0; font-size: 18px; font-weight: 650; }
.page-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.clock { color: var(--faint); font-size: 12px; }

.page-root { flex: 1; overflow-y: auto; padding: 24px; }

/* ---------- dots / badges / chips ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 9px; }
.dot-up { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.dot-down { background: var(--red); box-shadow: 0 0 0 3px var(--red-dim); }
.dot-unknown { background: var(--faint); }
.dot-muted { background: var(--faint); }
.dot-pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-dim); }
  50% { box-shadow: 0 0 0 5px rgba(52, 211, 153, 0.05); }
}

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-up { color: var(--accent); background: var(--accent-dim); border-color: rgba(52, 211, 153, 0.3); }
.badge-down { color: var(--red); background: var(--red-dim); border-color: rgba(242, 99, 95, 0.3); }
.badge-unknown { color: var(--muted); background: var(--panel-3); border-color: var(--border); }
.badge-blue { color: var(--blue); background: var(--blue-dim); border-color: rgba(94, 168, 255, 0.3); }
.badge-amber { color: var(--amber); background: var(--amber-dim); border-color: rgba(245, 185, 66, 0.3); }
.badge-muted { color: var(--muted); background: var(--panel-3); border-color: var(--border); }

.lat { font-family: ui-monospace, monospace; font-weight: 600; font-size: 12.5px; }
.lat-fast { color: var(--accent); }
.lat-mid { color: var(--amber); }
.lat-slow { color: var(--red); }
.lat-none { color: var(--faint); }

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-half { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) { .grid-2, .grid-half { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 14px;
}
.card-title .ic { color: var(--faint); }

.stat-card { display: flex; gap: 14px; align-items: flex-start; }
.stat-icon {
  width: 38px; height: 38px; border-radius: var(--radius); flex: 0 0 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-3); color: var(--muted); border: 1px solid var(--border);
}
.stat-icon.tone-accent { background: var(--accent-dim); color: var(--accent); border-color: rgba(52,211,153,.3); }
.stat-icon.tone-red { background: var(--red-dim); color: var(--red); border-color: rgba(242,99,95,.3); }
.stat-icon.tone-blue { background: var(--blue-dim); color: var(--blue); border-color: rgba(94,168,255,.3); }
.stat-icon.tone-amber { background: var(--amber-dim); color: var(--amber); border-color: rgba(245,185,66,.3); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat-sub { color: var(--faint); font-size: 11px; margin-top: 3px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); border-color: #2a3348; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06281c; font-weight: 650; }
.btn-primary:hover { background: #41e0a7; border-color: #41e0a7; }
.btn-danger { background: var(--red-dim); border-color: rgba(242,99,95,.35); color: var(--red); }
.btn-danger:hover { background: rgba(242,99,95,.2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-block { width: 100%; justify-content: center; padding: 9px 14px; }
.btn-icon { padding: 7px; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn .ic { display: inline-flex; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid transparent; background: transparent; color: var(--faint);
  cursor: pointer; transition: all 0.12s;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--red); border-color: rgba(242,99,95,.35); background: var(--red-dim); }
.icon-btn.accent:hover { color: var(--accent); border-color: rgba(52,211,153,.35); background: var(--accent-dim); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.input, textarea.input {
  width: 100%; padding: 8px 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 13px; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, textarea.input:focus {
  border-color: rgba(52, 211, 153, 0.55);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12);
}
.input::placeholder { color: var(--faint); }

/* ---------- custom select ---------- */
.cselect { position: relative; display: inline-block; min-width: 130px; }
.cselect-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 8px 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.cselect-btn:hover { border-color: #2a3348; }
.cselect.open .cselect-btn, .cselect-btn:focus-visible {
  border-color: rgba(52, 211, 153, 0.55);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12);
}
.cselect-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-chev { flex: 0 0 12px; color: var(--faint); transition: transform 0.15s; display: inline-flex; }
.cselect.open .cselect-chev { transform: rotate(180deg); color: var(--accent); }
.cselect-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 100%;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 4px; z-index: 30;
  max-height: 260px; overflow-y: auto; display: none;
}
.cselect-menu.up { top: auto; bottom: calc(100% + 6px); }
.cselect.open .cselect-menu { display: block; animation: cs-in 0.12s ease; }
@keyframes cs-in { from { opacity: 0; transform: translateY(-4px); } }
.cselect.open .cselect-menu.up { animation-name: cs-in-up; }
@keyframes cs-in-up { from { opacity: 0; transform: translateY(4px); } }
.cselect-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 6px; font-size: 13px; color: var(--text);
  cursor: pointer; white-space: nowrap; user-select: none;
}
.cselect-opt .ic { opacity: 0; color: var(--accent); flex: 0 0 13px; }
.cselect-opt:hover, .cselect-opt.active { background: var(--panel-3); }
.cselect-opt.sel { color: var(--accent); font-weight: 600; }
.cselect-opt.sel .ic { opacity: 1; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field-hint { font-size: 11.5px; color: var(--faint); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- tables ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 650; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--faint);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--panel-2); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.tbl tbody tr { transition: background 0.1s; }
.tbl tbody tr:hover { background: rgba(94, 168, 255, 0.04); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.disabled-row td { opacity: 0.45; }
.cell-addr { font-family: ui-monospace, monospace; font-size: 12.5px; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--faint); font-size: 11px; margin-top: 1px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---------- endpoints table ---------- */
.tbl-eps { table-layout: fixed; min-width: 1080px; }
.tbl-eps .cell-main, .tbl-eps .cell-sub, .tbl-eps .cell-addr {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl-eps td.cell-remark { white-space: normal; word-break: break-word; line-height: 1.5; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--faint); }
.empty-state .ic { color: var(--border); margin-bottom: 10px; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--muted); }
.empty-sub { font-size: 12px; margin-top: 4px; }

.rate-bar { width: 64px; height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; display: inline-block; vertical-align: middle; }
.rate-bar > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.rate-bar.rate-mid > span { background: var(--amber); }
.rate-bar.rate-low > span { background: var(--red); }
.rate-num { color: var(--muted); font-size: 11.5px; margin-left: 7px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.search-box { position: relative; }
.search-box .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search-box .input { padding-left: 32px; width: 220px; }
.toolbar .select { width: auto; }

/* ---------- banners ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: var(--radius); padding: 11px 14px; font-size: 12.5px; margin-bottom: 16px;
  border: 1px solid;
}
.banner .ic { flex: 0 0 auto; margin-top: 1px; }
.banner-warn { background: var(--amber-dim); border-color: rgba(245,185,66,.35); color: var(--amber); }
.banner-info { background: var(--blue-dim); border-color: rgba(94,168,255,.35); color: var(--blue); }
.banner b { color: inherit; }
.banner .banner-text { color: var(--text); }
.banner .banner-text b { color: inherit; }

/* ---------- events ---------- */
.event-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; }
.event-item {
  display: flex; gap: 10px; padding: 8px 2px; font-size: 12.5px;
  border-bottom: 1px solid var(--border-soft); align-items: baseline;
}
.event-item:last-child { border-bottom: none; }
.event-time { color: var(--faint); font-size: 11px; flex: 0 0 74px; font-family: ui-monospace, monospace; }
.event-dot { flex: 0 0 auto; align-self: center; }

/* ---------- drawer ---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(4, 6, 10, 0.6); z-index: 40;
  opacity: 0; transition: opacity 0.18s;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 92vw; z-index: 41;
  background: var(--panel); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 0.2s ease;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-mask.open, .drawer.open { opacity: 1; transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 18px; }
.detail-item .k { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-item .v { font-size: 13px; margin-top: 2px; word-break: break-all; }

/* ---------- modal ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 50; background: rgba(4, 6, 10, 0.65);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px;
  overflow-y: auto;
}
.modal {
  width: 480px; max-width: 100%; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  animation: modal-in 0.16s ease;
}
@keyframes modal-in { from { transform: translateY(-10px); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 650; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.modal-wide { width: 560px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: toast-in 0.18s ease; max-width: 380px;
}
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } }
.toast.ok { border-color: rgba(52,211,153,.4); }
.toast.ok .ic { color: var(--accent); }
.toast.err { border-color: rgba(242,99,95,.4); }
.toast.err .ic { color: var(--red); }

/* ---------- login ---------- */
.login-wrap {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 15% 0%, rgba(52, 211, 153, 0.06), transparent 60%),
    radial-gradient(900px 500px at 90% 100%, rgba(94, 168, 255, 0.05), transparent 60%),
    var(--bg);
}
.login-card {
  width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 30px; box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-logo .logo-mark { width: 42px; height: 42px; flex-basis: 42px; }
.login-error {
  background: var(--red-dim); border: 1px solid rgba(242,99,95,.35); color: var(--red);
  border-radius: var(--radius); padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px;
}
.login-hint { margin-top: 14px; text-align: center; color: var(--faint); font-size: 12px; }
.login-hint code { color: var(--amber); font-family: ui-monospace, monospace; }
.login-card .btn-block { margin-top: 4px; }

/* ---------- misc ---------- */
.chart-box { position: relative; height: 220px; }
.chart-box-sm { position: relative; height: 170px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb16 { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { color: var(--faint); padding: 40px; text-align: center; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 860px) {
  .sidebar { width: 64px; flex-basis: 64px; }
  .sidebar .logo-name, .sidebar .logo-sub, .nav-item span:last-child, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-logo { justify-content: center; padding: 14px 0; }
}
