:root {
  --bg: #f1f3f8;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --danger: #e11d48;
  --danger-soft: #ffe4e6;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --border: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #e0e7ff 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 16px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff; display: grid; place-items: center;
  font-size: 24px; font-weight: 700; box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  font-size: 15px; background: #f8fafc; outline: none;
}
.login-card input:focus { border-color: var(--primary); background: #fff; }
.form-err { color: var(--danger); font-size: 12px; min-height: 18px; margin-bottom: 6px; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; max-width: 560px; margin: 0 auto; }
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(241, 243, 248, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-live.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--muted); font-size: 17px;
}
.icon-btn:active { transform: scale(0.95); }

.view { flex: 1; padding: 16px 14px 92px; }

/* ---------- cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); border: 1px solid rgba(226, 232, 240, 0.6);
}
.stat .stat-label { color: var(--muted); font-size: 12px; }
.stat .stat-value { font-size: 26px; font-weight: 750; margin-top: 4px; letter-spacing: -0.5px; }
.stat .stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.danger .stat-value { color: var(--danger); }
.stat.ok .stat-value { color: var(--ok); }
.stat.primary .stat-value { color: var(--primary); }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 4px 10px; font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px;
}
.section-title .link { color: var(--primary); font-weight: 600; font-size: 13px; cursor: pointer; text-transform: none; letter-spacing: 0; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, 0.6); overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card-pad { padding: 14px 16px; }

.srv-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; cursor: pointer; }
.srv-row + .srv-row { border-top: 1px solid var(--border); }
.srv-row:active { background: #f8fafc; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.srv-main { flex: 1; min-width: 0; }
.srv-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srv-host { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srv-metrics { display: flex; gap: 8px; margin-top: 6px; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #f1f5f9; color: var(--muted);
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 650; }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.primary { background: var(--primary-soft); color: var(--primary); }

.mini-bar { height: 4px; border-radius: 3px; background: #e2e8f0; overflow: hidden; margin-top: 6px; }
.mini-bar > span { display: block; height: 100%; background: var(--primary); }
.mini-bar.warn > span { background: var(--warn); }
.mini-bar.danger > span { background: var(--danger); }

/* ---------- gauges ---------- */
.gauge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gauge { background: #f8fafc; border-radius: 14px; padding: 12px 14px; }
.gauge-label { font-size: 12px; color: var(--muted); }
.gauge-value { font-size: 22px; font-weight: 750; margin: 2px 0 6px; }
.gauge .track { height: 6px; border-radius: 4px; background: #e2e8f0; overflow: hidden; }
.gauge .track > span { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #4f46e5); }
.gauge.warn .track > span { background: linear-gradient(90deg, #f59e0b, #d97706); }
.gauge.danger .track > span { background: linear-gradient(90deg, #f43f5e, #e11d48); }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv { display: flex; flex-direction: column; }
.kv span:first-child { font-size: 12px; color: var(--muted); }
.kv span:last-child { font-weight: 650; }

/* ---------- lists ---------- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 650; font-size: 14px; }
.list-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 11px; font-size: 14px; font-weight: 600;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: #f8fafc; }
.btn.sm { padding: 6px 12px; font-size: 12px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 11px;
  font-size: 14px; background: #f8fafc; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); background: #fff; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.switch input { width: 46px; height: 26px; appearance: none; background: #cbd5e1; border-radius: 999px; position: relative; transition: background 0.2s; outline: none; }
.switch input:checked { background: var(--primary); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: left 0.2s; }
.switch input:checked::after { left: 23px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  border: none; background: none; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  border-radius: 12px;
}
.tab .tab-ico { font-size: 18px; line-height: 1; }
.tab.active { color: var(--primary); font-weight: 700; }

/* ---------- modal / toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, 0.4);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal-box {
  width: 100%; max-width: 560px; background: #fff; border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal-title { font-size: 17px; font-weight: 750; margin: 0 0 16px; }
.modal .btn-row { margin-top: 8px; }
.modal .btn-row .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 13px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,0.25); max-width: 86%;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- chart ---------- */
.chart-wrap { padding: 6px 4px 0; }
.spark { width: 100%; height: 90px; display: block; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); padding: 6px 12px 12px; }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.back-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back-btn { border: none; background: #fff; border-radius: 10px; padding: 7px 12px; font-size: 13px; color: var(--muted); box-shadow: var(--shadow); }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
  .view { padding-left: 20px; padding-right: 20px; }
}
