/* ============ Bark 管理台 · 深色主题 ============ */

:root {
  --bg-0: #070b16;
  --bg-1: #0a1122;
  --panel: rgba(13, 21, 41, 0.72);
  --panel-solid: #0d1529;
  --card: #0d162e;
  --card-hover: #111c38;
  --border: #1c2947;
  --border-light: #27375e;
  --text: #e7edfb;
  --text-dim: #8b9bc0;
  --text-faint: #5c6c94;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --amber: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

/* 作者样式(如 .field{display:block})会覆盖 UA 的 [hidden]{display:none},需显式守卫 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(37, 99, 235, 0.16), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(14, 165, 233, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-dim); }

/* ============ 顶栏 ============ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  margin: 10px 10px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

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

.logo {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #16233f, #0b1326);
  border: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: center;
  color: #cfe0ff;
}
.logo svg { width: 22px; height: 22px; }

.brand-title { font-size: 16px; font-weight: 700; letter-spacing: 0.3px; }
.brand-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-title-block { text-align: right; }
.page-title { font-size: 14px; font-weight: 700; }
.page-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
  display: inline-block;
}

/* ============ 布局 ============ */

.layout {
  display: flex;
  gap: 14px;
  padding: 14px 10px 24px;
  align-items: flex-start;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  position: sticky;
  top: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, #1a2b52, #14213f);
  border-color: var(--border-light);
  color: var(--text);
  font-weight: 600;
}

.content { flex: 1; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  backdrop-filter: blur(8px);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.panel-head h2 { font-size: 20px; font-weight: 700; }
.panel-head p { margin-top: 4px; font-size: 13px; }

.sub-head { margin: 26px 0 12px; }
.sub-head h3 { font-size: 15px; font-weight: 700; }
.sub-head p { font-size: 12px; margin-top: 2px; }

/* ============ 工具栏 ============ */

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(7, 12, 24, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 38px;
  width: 220px;
}
.search-box svg { width: 15px; height: 15px; color: var(--text-faint); flex-shrink: 0; }
.search-box input {
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  color: var(--text);
  font-size: 13px;
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box:focus-within { border-color: var(--accent); }

.count-chip {
  height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(7, 12, 24, 0.4);
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

/* ============ 按钮 ============ */

.btn {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #101a33;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: #162240; border-color: var(--border-light); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.strong { font-weight: 600; }

.btn.primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #2f6fe0;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #4d8ffa, #2b6cf0); }

.btn.danger { background: #3a1420; border-color: #5f2233; color: #ffb4c0; }
.btn.danger:hover:not(:disabled) { background: #4a1a29; border-color: #7c2c42; }

.btn.small { height: 32px; padding: 0 12px; font-size: 12.5px; }

.icon-btn {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  border-radius: 8px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }

/* ============ 设备列表 ============ */

.device-list { display: flex; flex-direction: column; gap: 10px; }

.device-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.15s, border-color 0.15s;
}
.device-row:hover { background: var(--card-hover); border-color: var(--border-light); }
.device-row.disabled { opacity: 0.6; }

.device-check {
  width: 17px; height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.device-check:disabled { cursor: not-allowed; opacity: 0.4; }

.device-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(145deg, #131f3c, #0b1224);
  border: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: center;
  color: #b9cdf5;
  flex-shrink: 0;
}
.device-icon svg { width: 18px; height: 18px; }

.device-main { flex: 1; min-width: 0; }
.device-name { font-size: 14.5px; font-weight: 600; }
.device-name .unnamed { color: var(--text-faint); font-weight: 400; }
.device-url {
  font-size: 12.5px;
  color: #6f83b3;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-note { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.device-note .group-tag {
  display: inline-block;
  padding: 1px 8px;
  margin-right: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #9ec2ff;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.device-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.online { background: var(--green-bg); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.3); }
.badge.offline { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.3); }
.badge.unknown { background: rgba(139, 155, 192, 0.1); color: var(--text-dim); border: 1px solid rgba(139, 155, 192, 0.25); }

.toggle-label { font-size: 12.5px; color: var(--text-dim); }

.toggle {
  position: relative;
  width: 40px; height: 22px;
  appearance: none;
  background: #2a3654;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle:checked { background: var(--green); }
.toggle:checked::after { transform: translateX(18px); }

/* ============ 分页 ============ */

.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.pager { display: flex; align-items: center; gap: 8px; }

.select {
  height: 38px;
  padding: 0 10px;
  background: #101a33;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.select:focus { border-color: var(--accent); }
.select.wide { width: 100%; }

/* ============ 概览 ============ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-dim); }
.stat-card .stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-card .stat-extra { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.stat-card .stat-value.good { color: #4ade80; }
.stat-card .stat-value.bad { color: var(--red); }

.log-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th, .log-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.log-table td.wrap { white-space: normal; max-width: 300px; }
.log-table th { color: var(--text-dim); font-weight: 600; font-size: 12.5px; background: rgba(7, 12, 24, 0.4); }
.log-table tr:last-child td { border-bottom: none; }
.log-table .ok { color: #4ade80; }
.log-table .fail { color: var(--red); }

/* ============ 分组 ============ */

.group-list { display: flex; flex-direction: column; gap: 12px; }

.group-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.group-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.group-name { font-size: 15px; font-weight: 700; }
.group-count { font-size: 12.5px; color: var(--text-dim); margin-left: 10px; }
.group-actions { display: flex; gap: 8px; }
.group-devices { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.dev-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.dev-chip.on { color: #9ec2ff; border-color: rgba(59, 130, 246, 0.3); }

.input {
  height: 38px;
  padding: 0 12px;
  background: rgba(7, 12, 24, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--accent); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
#newGroupName { width: 180px; }

/* ============ 弹窗 ============ */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 14, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: 560px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0f1832, #0b1226);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal.small { width: 420px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 700; }

.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-body p { line-height: 1.6; color: var(--text-dim); }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.field > span em { color: var(--red); font-style: normal; }
.field > span code {
  background: rgba(59, 130, 246, 0.12);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
  color: #9ec2ff;
}
.field small { display: block; margin-top: 5px; font-size: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.check-line input { width: 15px; height: 15px; accent-color: var(--accent); }
.check-row { display: flex; gap: 22px; margin-bottom: 6px; flex-wrap: wrap; }

.tab-row { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
}
.tab.active { background: var(--accent-soft); border-color: rgba(59, 130, 246, 0.4); color: #9ec2ff; font-weight: 600; }

.target-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.target-chips .chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-size: 12px;
  color: #9ec2ff;
}
.target-chips .chip.more { background: transparent; color: var(--text-dim); }

.push-results {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 180px;
  overflow-y: auto;
}
.push-results .pr-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}
.push-results .pr-row:last-child { border-bottom: none; }
.push-results .pr-ok { color: #4ade80; }
.push-results .pr-fail { color: var(--red); }
.push-results .pr-msg { color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ 空状态 / 提示 ============ */

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

#toastWrap {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: #14213f;
  border: 1px solid var(--border-light);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  max-width: 80vw;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.5); }
.toast.err { border-color: rgba(248, 113, 113, 0.55); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 登录页 ============ */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-submit { width: 100%; height: 42px; margin-top: 4px; }
.login-error {
  padding: 9px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--red-bg);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #ffc2cb;
  font-size: 12.5px;
}
.login-hint { margin-top: 16px; font-size: 12px; line-height: 1.6; text-align: center; }

/* ============ 顶栏用户 ============ */

.user-chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #9ec2ff;
  font-size: 12.5px;
  font-weight: 600;
}

/* ============ 账号角色标记 ============ */

.role-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  vertical-align: middle;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.32);
}
.self-tag { margin-left: 8px; font-size: 11.5px; color: var(--text-faint); }

.level-note {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.25);
  font-size: 12px;
  line-height: 1.6;
  color: #e5cf9a;
}

/* ============ 账号页 ============ */

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 14px;
  align-items: start;
}
.account-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
}
.account-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.account-card h3 .muted { font-weight: 400; font-size: 12.5px; }
.small-note { margin-top: 10px; font-size: 12px; line-height: 1.5; }

.user-list { margin-top: 18px; border-top: 1px solid var(--border); }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.user-row:last-child { border-bottom: none; }
.user-info { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.user-name { font-size: 14px; font-weight: 600; }
.user-actions { display: flex; gap: 8px; }

/* ============ 响应式 ============ */

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; display: flex; }
  .sidebar nav { display: flex; gap: 8px; width: 100%; }
  .nav-item { margin-bottom: 0; justify-content: center; }
  .device-actions { flex-wrap: wrap; justify-content: flex-end; }
  .field-row { grid-template-columns: 1fr; }
}
