:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-sub: #6b7280;
  --text-light: #9ca3af;
  --success: #059669;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); text-decoration: none; }

/* ---------------- 登录页 ---------------- */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f6fa 45%, #ecfdf5 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 32px 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, .6);
}

.login-logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px; font-weight: 700;
  margin-bottom: 20px;
}

.login-card h1 { font-size: 22px; font-weight: 650; letter-spacing: -.3px; }
.login-card .sub { color: var(--text-sub); font-size: 13px; margin: 6px 0 28px; }

.login-tip {
  margin-top: 20px;
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: 8px;
  font-size: 12px;
  color: #4338ca;
}

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--text-light); margin-top: 5px; }

.input, .select, textarea.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 72px; }
.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.input::placeholder { color: var(--text-light); }

.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: background .15s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 7px; }

.link-btn {
  color: var(--primary);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
}
.link-btn:hover { background: var(--primary-light); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-bg); }

/* ---------------- 主布局 ---------------- */
#appView { display: none; min-height: 100vh; }
#appView.active { display: flex; }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.brand-text b { display: block; font-size: 14px; }
.brand-text span { font-size: 11px; color: var(--text-light); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 10px;
  border-radius: 8px;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  transition: background .12s, color .12s;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: #f9fafb; color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item .ico { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.user-chip .info { min-width: 0; flex: 1; }
.user-chip .info b { display: block; font-size: 13px; font-weight: 600; }
.user-chip .info span { font-size: 11px; color: var(--text-light); }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h2 { font-size: 20px; font-weight: 650; letter-spacing: -.3px; }
.page-head p { color: var(--text-sub); font-size: 13px; margin-top: 3px; }

/* ---------------- 卡片 / 统计 ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 13px; color: var(--text-sub); }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.6px; margin-top: 6px; line-height: 1.2; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--text-light); margin-left: 4px; }
.stat .foot { font-size: 12px; color: var(--text-light); margin-top: 6px; }

/* ---------------- 工具栏 ---------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.toolbar .search .input { padding-left: 34px; }
.toolbar .search .ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-light); font-size: 13px; pointer-events: none;
}
.toolbar .spacer { flex: 1; }
.toolbar .select { width: auto; min-width: 110px; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 11px 16px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 13px 16px; border-bottom: 1px solid #f1f2f4; vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace; font-size: 13px; }

.key-cell { display: flex; align-items: center; gap: 6px; }
.key-cell code {
  background: #f3f4f6;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  color: #374151;
  white-space: nowrap;
}
.btn-copy {
  font-size: 12px; color: var(--text-light); padding: 2px 6px; border-radius: 5px;
  opacity: 0; transition: opacity .12s, background .12s;
}
tr:hover .btn-copy { opacity: 1; }
.btn-copy:hover { background: var(--primary-light); color: var(--primary); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: 20px;
  font-size: 12px; font-weight: 500;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.on { background: var(--success-bg); color: var(--success); }
.badge.off { background: #f3f4f6; color: var(--text-sub); }
.badge.super { background: #fffbeb; color: var(--warn); }
.badge.normal { background: var(--primary-light); color: var(--primary); }

.actions { display: flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }

/* ---------------- 分页 ---------------- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-sub);
}
.pager .btns { display: flex; gap: 8px; }
.pager button {
  height: 32px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 7px; background: #fff; color: var(--text); font-size: 13px;
}
.pager button:hover:not(:disabled) { background: #f9fafb; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 空状态 / 加载 ---------------- */
.empty { padding: 56px 20px; text-align: center; color: var(--text-light); }
.empty .big { font-size: 32px; margin-bottom: 10px; opacity: .5; }
.loading-row { padding: 40px; text-align: center; color: var(--text-light); }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
  display: none; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal-mask.open { display: flex; animation: fade .15s ease; }
.modal {
  width: 100%; max-width: 460px;
  background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head {
  padding: 20px 22px 14px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 650; }
.modal-close { color: var(--text-light); font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 10px;
}

.alert {
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
  background: var(--warn-bg); color: #92400e; border: 1px solid #fde68a;
}
.alert.danger { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }

/* ---------------- Toast ---------------- */
#toastBox {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: 9px;
  background: #1f2937; color: #fff; font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: drop .22s cubic-bezier(.2, .9, .3, 1.1);
  max-width: 90vw;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ---------------- 日志列表 ---------------- */
.log-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid #f1f2f4; font-size: 13px;
}
.log-item:last-child { border-bottom: none; }
.log-item .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0;
}
.log-item .txt { flex: 1; min-width: 0; }
.log-item .txt b { font-weight: 600; }
.log-item .txt .detail { color: var(--text-light); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-item .time { color: var(--text-light); font-size: 12px; white-space: nowrap; }

@media (max-width: 820px) {
  .sidebar { width: 64px; padding: 16px 8px; }
  .brand-text, .nav-item span.label, .user-chip .info { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .main { padding: 20px 16px 40px; }
  .brand { justify-content: center; padding: 0 0 16px; }
}
