:root {
  --bg: #0f1117;
  --bg-2: #161922;
  --card: #1a1e29;
  --card-2: #212635;
  --line: #2a3042;
  --text: #e7e9ee;
  --muted: #8b93a7;
  --accent: #6ea8fe;
  --accent-2: #5eead4;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --off: #64748b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f9; --bg-2: #eceef3; --card: #ffffff; --card-2: #f3f4f8; --line: #e1e4ec;
    --text: #151821; --muted: #626a7e; --accent: #2f6fe4; --accent-2: #0f9f8a;
    --ok: #10a36c; --warn: #c58a06; --bad: #dc3d3d; --off: #94a3b8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.shell { min-height: 100vh; padding-bottom: calc(64px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--safe-top)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: .2px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .logo { width: 28px; height: 28px; border-radius: 8px; }
main { max-width: 1100px; margin: 0 auto; padding: 18px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--accent); }
.tabbar .dot { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }

.icon-btn { background: transparent; border: 0; padding: 6px; border-radius: 10px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- generic ---------- */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; font-weight: 600; }
.section-title span { font-size: 12px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card-2); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 550; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty code { background: var(--card-2); padding: 2px 6px; border-radius: 6px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--off); display: inline-block; }
.status.ok i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.status.bad i { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.status.warn i { background: var(--warn); }
.status.ok { color: var(--ok); } .status.bad { color: var(--bad); } .status.warn { color: var(--warn); } .status.off { color: var(--muted); }

/* ---------- host metrics ---------- */
.host { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 720px) { .host { grid-template-columns: repeat(2, 1fr); } }
.metric .label { font-size: 12px; color: var(--muted); }
.metric .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.metric .value { margin-bottom: 0; }
.metric .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; }
.bar > b { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s; }
.bar.warn > b { background: var(--warn); } .bar.bad > b { background: var(--bad); }
.hostline { margin-top: 10px; font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }

/* ---------- module cards ---------- */
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.mod { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s, transform .15s; color: inherit; }
.mod:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.mod:active { transform: scale(.99); }
.mod .head { display: flex; gap: 12px; align-items: center; }
.mod .emoji { font-size: 22px; width: 42px; height: 42px; display: grid; place-items: center; background: var(--card-2); border-radius: 12px; flex: none; }
.mod .name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mod .desc { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 1.5em; }
.mod .stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.mod .stats b { color: var(--text); font-weight: 600; }
.mod .foot { display: flex; align-items: center; gap: 10px; }
.mod .open { margin-left: auto; }
.spark { width: 100%; height: 28px; display: block; }
.infra { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.infra .card { color: inherit; padding: 12px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.infra .card .grow div:first-child { font-weight: 600; font-size: 14px; }

/* ---------- module detail ---------- */
.detail-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.detail-head .emoji { font-size: 30px; width: 58px; height: 58px; display: grid; place-items: center; background: var(--card-2); border-radius: 16px; }
.detail-head h2 { margin: 0; font-size: 22px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
.chart { width: 100%; height: 90px; display: block; }
.logs {
  background: #0a0c10; color: #cfd6e4; border-radius: 12px; border: 1px solid var(--line);
  height: 52vh; min-height: 260px; overflow: auto; padding: 10px 12px; margin: 0;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
}
.logs .ts { color: #5b6478; }
.logs .err { color: #ff8f8f; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- embedded module ---------- */
.frame-wrap { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 20; }
.frame-bar { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-top)) 10px 6px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.frame-bar .title { flex: 1; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.frame-wrap iframe { flex: 1; border: 0; width: 100%; background: #fff; }

/* ---------- notifications ---------- */
.notif { display: flex; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.notif:last-child { border-bottom: 0; }
.notif .lvl { width: 4px; border-radius: 2px; background: var(--accent); flex: none; }
.notif.warning .lvl { background: var(--warn); } .notif.critical .lvl { background: var(--bad); }
.notif.unread .title { font-weight: 700; }
.notif .title { font-size: 15px; }
.notif .body { font-size: 13px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.notif .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- settings ---------- */
.setting { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .grow div:first-child { font-weight: 600; }
.hint { background: color-mix(in srgb, var(--warn) 12%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); border-radius: 12px; padding: 12px 14px; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { width: 84px; height: 84px; margin: 0 auto 6px; border-radius: 22px; }
.login h1 { margin: 0; font-size: 22px; }
.login input {
  font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); outline: none; text-align: center;
}
.login input:focus { border-color: var(--accent); }
.login .btn { padding: 12px; }
.login .error { color: var(--bad); font-size: 13px; min-height: 1.2em; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); z-index: 50; font-size: 14px; animation: pop .2s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
