:root {
  --bg: #0a0e15;
  --panel: #111827;
  --panel-2: #151f31;
  --line: #22304a;
  --text: #e8eefb;
  --muted: #8b9dba;
  --accent: #4f8cff;
  --accent-2: #7aa9ff;
  --ok: #38d996;
  --warn: #ffb02e;
  --bad: #ff6172;
  --radius: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(79, 140, 255, .14), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(56, 217, 150, .08), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: .2px; }
h1 { font-size: 17px; }
h2 { font-size: 16px; }
code { font-family: "JetBrains Mono", Consolas, "Courier New", monospace; }

.muted { color: var(--muted); margin: 0; }
.tiny { font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- 登录 ---------- */

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, rgba(28, 40, 62, .85), rgba(17, 24, 39, .95));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  font-size: 19px; font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #4f8cff, #7d5bff);
  box-shadow: 0 8px 20px rgba(79, 140, 255, .35);
}

/* ---------- 布局 ---------- */

.app-view { min-height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: rgba(10, 14, 21, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 40px;
  display: grid;
  gap: 18px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; line-height: 1.25; margin-top: 2px; }
.stat .value.ok { color: var(--ok); }
.stat .value.warn { color: var(--warn); }
.stat .value.bad { color: var(--bad); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

/* ---------- 控件 ---------- */

.input, select.input, textarea {
  background: #0c1320;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, .18);
}
.search { width: 280px; max-width: 100%; }
.select { min-width: 120px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: transform .06s, background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #5b96ff, #3f7ef0); color: #fff; box-shadow: 0 8px 18px rgba(63, 126, 240, .28); }
.btn-primary:hover { background: linear-gradient(180deg, #6ba2ff, #4a86f5); }
.btn-ghost { background: rgba(255, 255, 255, .04); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, .08); }
.btn-danger { background: rgba(255, 97, 114, .12); border-color: rgba(255, 97, 114, .35); color: #ff8b97; }
.btn-danger:hover { background: rgba(255, 97, 114, .2); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .06); }

/* ---------- 表格 ---------- */

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }

.table th {
  position: sticky; top: 0;
  text-align: left;
  font-size: 12px; font-weight: 600;
  color: var(--muted);
  background: #0e1624;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: 11px 16px;
  border-bottom: 1px solid rgba(34, 48, 74, .55);
  vertical-align: middle;
}

.table tbody tr:hover { background: rgba(79, 140, 255, .05); }
.table tbody tr:last-child td { border-bottom: 0; }

.col-actions { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.card-code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px;
  color: var(--accent-2);
  cursor: pointer;
  background: none; border: 0; padding: 0;
  text-align: left;
}
.card-code:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.ok { color: var(--ok); background: rgba(56, 217, 150, .1); border-color: rgba(56, 217, 150, .25); }
.badge.bad { color: var(--bad); background: rgba(255, 97, 114, .1); border-color: rgba(255, 97, 114, .25); }
.badge.warn { color: var(--warn); background: rgba(255, 176, 46, .1); border-color: rgba(255, 176, 46, .25); }
.badge.mute { color: var(--muted); background: rgba(255, 255, 255, .05); border-color: var(--line); }

.empty { padding: 40px; text-align: center; color: var(--muted); }

.pager {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* ---------- 底部 ---------- */

.footer { display: grid; gap: 8px; }

.key-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  flex-wrap: wrap;
}
.key-box code {
  font-size: 12px; color: var(--accent-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 200px;
}

/* ---------- 弹层 ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 12, .72);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
}

.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: linear-gradient(180deg, #172136, #101827);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.modal .muted { font-size: 12.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input, .field select { width: 100%; }
.field input, .field select {
  background: #0c1320; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: inherit; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, .18); }

.form-error { color: var(--bad); font-size: 12.5px; margin: 0; }

.gen-result { display: grid; gap: 8px; border-top: 1px dashed var(--line); padding-top: 12px; }
.gen-result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gen-result textarea {
  width: 100%; resize: vertical;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px; line-height: 1.7;
}

/* ---------- 抽屉 ---------- */

.drawer {
  position: fixed; top: 0; right: 0; z-index: 60;
  width: min(440px, 100%);
  height: 100%;
  background: #0f1726;
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.drawer-body { padding: 18px; overflow: auto; display: grid; gap: 16px; align-content: start; }

.drawer-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 7, 12, .5);
}

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.device {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
  font-size: 12.5px;
  background: #0c1320;
}
.device-head { display: flex; align-items: center; gap: 8px; }
.device-head code { font-size: 11.5px; color: var(--accent-2); }
.device-meta { color: var(--muted); font-size: 11.5px; }

.log-list { display: grid; gap: 6px; font-size: 12px; }
.log-item { display: flex; gap: 8px; color: var(--muted); }
.log-item .act { color: var(--text); min-width: 70px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  background: #17233a;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: 340px;
  animation: toast-in .18s ease-out;
}
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  .wrap { padding: 16px 12px 32px; }
  .topbar { padding: 12px; }
  .search { width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  .table th:nth-child(6), .table td:nth-child(6) { display: none; }
}
