:root {
  --bg: #070b12;
  --bg-soft: #0e1520;
  --card: #131c2b;
  --card-hover: #182436;
  --text: #e8eef7;
  --muted: #7d94b3;
  --accent: #2b8cff;
  --accent-glow: rgba(43, 140, 255, 0.35);
  --accent-hover: #4da0ff;
  --danger: #ff6b6b;
  --success: #3dd68c;
  --online: #3dd68c;
  --border: #243248;
  --sidebar-w: 252px;
  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Login ── */
.page-login {
  display: grid;
  place-items: center;
  padding: 24px;
  padding-bottom: 56px;
  position: relative;
  overflow: hidden;
}

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.site-footer__beian {
  color: inherit;
  text-decoration: none;
}

.site-footer__beian:hover,
.site-footer__beian:focus-visible {
  text-decoration: underline;
  color: var(--text);
}

.login-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(43, 140, 255, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 85% 80%, rgba(61, 214, 140, 0.06) 0%, transparent 50%),
    linear-gradient(180deg, #0a111c 0%, var(--bg) 100%);
  pointer-events: none;
}

.login-shell {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 32px;
  width: min(960px, 100%);
  grid-template-columns: 1fr 1fr;
  align-items: center;
}

.login-brand h1 {
  margin: 16px 0 4px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-tag {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
}

.brand-mark {
  position: relative;
  display: inline-block;
  width: 88px;
  height: 88px;
}

.brand-icon {
  position: relative;
  z-index: 1;
  display: block;
  width: 88px;
  height: 88px;
  border-radius: 20px;
  object-fit: cover;
  box-shadow: 0 0 32px var(--accent-glow), 0 8px 24px rgba(0, 0, 0, 0.4);
}

.brand-glow {
  position: absolute;
  inset: -20%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  filter: blur(8px);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.login-card h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
.subtitle, .hint { color: var(--muted); margin: 0 0 16px; line-height: 1.55; font-size: 14px; }
.hint code {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a1018;
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -4px 0 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.login-remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.login-remember span {
  line-height: 1.3;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

button:active:not(:disabled) { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 4px; padding: 12px; }

.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.08); }
.btn-sm { padding: 7px 14px; font-size: 13px; }

.btn-danger {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.3);
}
.btn-danger:hover { background: rgba(255, 107, 107, 0.22); }

.link-btn {
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  font-weight: 500;
}
.link-btn:hover { color: var(--text); }

.error { color: var(--danger); margin-top: 12px; font-size: 14px; }
.success { color: var(--success); margin-top: 12px; font-size: 14px; }

/* ── Console layout ── */
.nav-text-short,
.btn-text-short { display: none; }

.page-console {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: clip;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sidebar-brand-title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logo {
  border-radius: 8px;
  box-shadow: 0 0 12px var(--accent-glow);
  flex-shrink: 0;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
  flex: 1;
  align-content: start;
}

.nav-section-label {
  margin: 14px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.85;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  color: var(--muted);
  padding: 11px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.9;
  background: currentColor;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
}
.nav-icon--device {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='3' width='20' height='14' rx='2'/%3E%3Cpath d='M8 21h8M12 17v4'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='3' width='20' height='14' rx='2'/%3E%3Cpath d='M8 21h8M12 17v4'/%3E%3C/svg%3E");
}
.nav-icon--users {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2M16 3.1a4 4 0 0 1 0 7.8M21 21v-2a4 4 0 0 0-3-3.9'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2M16 3.1a4 4 0 0 1 0 7.8M21 21v-2a4 4 0 0 0-3-3.9'/%3E%3C/svg%3E");
}
.nav-icon--lock {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
}
.nav-icon--audit {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M16 13H8M16 17H8M10 9H8'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M16 13H8M16 17H8M10 9H8'/%3E%3C/svg%3E");
}
.nav-icon--account {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20v-1a6 6 0 0 1 12 0v1'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20v-1a6 6 0 0 1 12 0v1'/%3E%3C/svg%3E");
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active {
  background: rgba(43, 140, 255, 0.14);
  color: #9ec5ff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.sidebar-account-actions {
  display: flex;
  gap: 4px;
  padding: 0 4px;
}

.sidebar-account-actions .link-btn {
  flex: 1;
  font-size: 13px;
  padding: 8px 6px;
  border-radius: 8px;
}

.sidebar-account-actions .link-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #1a5fbf);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-name { font-size: 14px; font-weight: 600; }
.user-role { font-size: 12px; color: var(--muted); }
.logout-btn { text-align: center; }

.console-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 40% at 100% 0%, rgba(43, 140, 255, 0.05) 0%, transparent 50%),
    var(--bg);
}

.console-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 24px 32px 16px;
  background: rgba(7, 11, 18, 0.85);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(36, 50, 72, 0.6);
}

.console-body {
  flex: 1;
  padding: 8px 32px 48px;
  max-width: 1280px;
  width: 100%;
}

.console-header h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.hint--flush { margin-bottom: 0; }
.hint--tight { margin-bottom: 8px; font-size: 13px; }

.panel { display: none; gap: 20px; }
.panel.active { display: grid; }

.panel-split.active {
  grid-template-columns: 1fr 300px;
  align-items: start;
  gap: 20px;
}

.card--grow { min-width: 0; }
.card--aside { position: sticky; top: 88px; }
.card--primary { padding: 24px; }
.card--compact { padding: 20px; }
.card--narrow { max-width: 480px; }

.card-subtitle {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.card-subtitle--sm {
  font-size: 14px;
  margin: 0;
}

.card-head--sub {
  margin-top: 16px;
  margin-bottom: 8px;
}

.section-title {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.section-desc {
  margin: 4px 0 12px;
}

.admin-section {
  display: grid;
  gap: 16px;
}

/* 操作员：仅设备连接，隐藏侧栏导航等多余入口 */
.role-operator .sidebar-nav {
  display: none;
}

.role-operator .sidebar {
  padding-bottom: 0;
}

@media (min-width: 861px) {
  .role-operator .console-header {
    display: block;
  }
}

.enrollment-card {
  padding: 24px;
  display: grid;
  gap: 0;
}

.enrollment-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 20px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

.enrollment-block-title {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.enrollment-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.enrollment-field {
  display: grid;
  gap: 6px;
  margin: 0;
  min-width: 0;
}

.enrollment-field .field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.enrollment-field input {
  margin-top: 0;
  min-width: 0;
  width: 100%;
}

.enrollment-field:not(.enrollment-field--grow):not(.enrollment-field--action) {
  flex: 0 0 100px;
}

.enrollment-field--grow {
  flex: 1 1 180px;
}

.enrollment-field--action {
  flex: 0 0 auto;
}

.enrollment-field--action .btn-primary {
  min-width: 88px;
  margin-top: 0;
}

.enrollment-guide {
  padding: 16px 18px;
  border-radius: var(--radius);
  background: rgba(43, 140, 255, 0.06);
  border: 1px solid rgba(43, 140, 255, 0.18);
}

.enrollment-steps {
  margin: 0;
  padding-left: 1.2em;
  display: grid;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

.enrollment-steps li::marker {
  color: var(--accent);
  font-weight: 700;
}

.enrollment-steps strong {
  font-weight: 600;
  color: #b8d4ff;
}

.enrollment-history {
  padding-top: 16px;
}

.enrollment-history .card-head--sub {
  margin-top: 0;
  margin-bottom: 10px;
}

.cards-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid--enroll {
  max-width: none;
  grid-template-columns: 1fr 1fr;
}

.form-grid-span-2 {
  grid-column: 1 / -1;
}

.table-wrap--compact .data-table th,
.table-wrap--compact .data-table td {
  padding: 10px 12px;
  font-size: 13px;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-card--online .stat-value { color: var(--online); }
.stat-card--online { border-color: rgba(61, 214, 140, 0.25); }
.stat-card--offline .stat-value { color: var(--muted); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.filter-select {
  margin-top: 0;
  min-width: 140px;
  width: auto;
  max-width: 200px;
  padding: 8px 10px;
  font-size: 13px;
}
.device-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.tag-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(43, 140, 255, 0.12);
  color: #9ec5ff;
  border: 1px solid rgba(43, 140, 255, 0.25);
}
.device-group {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-perms {
  display: grid;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0a1018;
}
.device-perms label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 400;
}
.enrollment-created-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}
.enrollment-created-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 212, 121, 0.2);
}
.enrollment-created-list code.enrollment-token {
  flex: 1 1 100%;
  word-break: break-all;
  color: #ffd479;
  font-size: 14px;
  line-height: 1.4;
}
.enrollment-created-list .hint {
  margin: 0;
  font-size: 12px;
}

.device-list { display: grid; gap: 12px; }

.device-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  flex-wrap: wrap;
  transition: border-color 0.15s, background 0.15s;
}

.device-item:hover { background: var(--card-hover); }

.device-item.is-online {
  border-color: rgba(61, 214, 140, 0.3);
  box-shadow: 0 0 0 1px rgba(61, 214, 140, 0.08);
}

.device-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(43, 140, 255, 0.1);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.device-item.is-online .device-icon {
  background: rgba(61, 214, 140, 0.1);
  box-shadow: 0 0 12px rgba(61, 214, 140, 0.15);
}

.device-icon img {
  display: block;
  border-radius: 6px;
  opacity: 0.85;
}
.device-item:not(.is-online) .device-icon img {
  opacity: 0.45;
  filter: grayscale(0.6);
}

.device-main { flex: 1 1 180px; min-width: 0; }

.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.device-item .name {
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-item .edge-id {
  color: var(--muted);
  font-size: 13px;
  font-family: ui-monospace, monospace;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta-line {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-item .created { color: var(--muted); font-size: 12px; margin-top: 4px; }

.device-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.device-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.device-status {
  flex-shrink: 0;
}

@media (min-width: 861px) {
  .card-head {
    align-items: flex-start;
  }

  .device-item {
    flex-wrap: nowrap;
    align-items: center;
  }

  .device-main {
    flex: 1 1 auto;
    min-width: 0;
  }

  .device-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    margin-left: 4px;
  }

  .device-actions .btn-primary {
    width: auto;
    min-width: 96px;
    padding: 10px 20px;
  }

  .device-actions-row {
    flex-wrap: nowrap;
  }

  .device-actions-row button {
    width: auto;
    min-height: 0;
    padding: 7px 14px;
    font-size: 13px;
  }
}

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: #1e2836;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.status-pill.online {
  background: rgba(61, 214, 140, 0.15);
  color: var(--online);
}
.status-pill.online::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
  margin-right: 5px;
  vertical-align: middle;
  animation: pulse-dot 2s ease infinite;
}
.status-pill.reconnecting {
  background: rgba(245, 166, 35, 0.16);
  color: #e8a317;
}
.status-pill.reconnecting::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e8a317;
  margin-right: 5px;
  vertical-align: middle;
  animation: pulse-dot 1.2s ease infinite;
}
.status-pill.disabled {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--online);
  vertical-align: middle;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.inline-form input,
.inline-form select { flex: 1 1 160px; margin-top: 0; }
.inline-form label { margin-bottom: 0; flex: 1 1 160px; }

.form-grid {
  display: grid;
  gap: 16px;
  max-width: 420px;
}
.form-grid--narrow { max-width: 360px; }

.form-actions { margin-top: 8px; }

.secret-box {
  margin-top: 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: #0a1018;
  border: 1px dashed rgba(43, 140, 255, 0.35);
}
.secret-box--success {
  margin-top: 16px;
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.06);
}
.secret-box--warn {
  border-color: rgba(255, 212, 121, 0.35);
  background: rgba(255, 212, 121, 0.06);
}
.secret-box-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
}
.secret-box code {
  display: block;
  word-break: break-all;
  margin: 8px 0;
  color: #ffd479;
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.2);
}
.data-table tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 20px;
  z-index: 1000;
}

.modal-overlay[hidden] { display: none !important; }
.modal-overlay:not([hidden]) {
  display: grid;
  place-items: center;
}

.modal { width: min(440px, 100%); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state p { margin: 0; }

@media (max-width: 1024px) {
  .panel-split.active { grid-template-columns: 1fr; }
  .card--aside { position: static; }
  .cards-grid-2 { grid-template-columns: 1fr; }
  .enrollment-layout { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }

  .nav-text-long,
  .btn-text-long { display: none; }

  /* 手机端导航仍显示全称（仅账户按钮用短文案） */
  .nav-text-short { display: none; }
  .btn-text-short { display: inline; }
  .sidebar-nav .nav-text-long { display: inline; }

  .page-console {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow-x: clip;
  }

  body.page-console,
  html:has(body.page-console) {
    overflow-x: hidden;
  }

  .console-main,
  .console-body {
    overflow-x: clip;
    max-width: 100%;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    width: 100%;
    padding: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(14, 21, 32, 0.94);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
  }

  .sidebar-brand {
    grid-column: 1;
    grid-row: 1;
    padding: 8px 10px 4px;
    margin: 0;
    border-bottom: 0;
    gap: 8px;
  }

  .sidebar-logo {
    width: 28px;
    height: 28px;
  }

  .sidebar-brand-title { font-size: 0.9rem; }

  .sidebar-brand-sub { display: none; }

  .sidebar-foot {
    grid-column: 2;
    grid-row: 1;
    flex: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 10px 4px 0;
    margin: 0;
    border-top: 0;
  }

  .user-card {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 108px;
    padding: 4px 6px;
    gap: 6px;
  }

  .user-meta {
    min-width: 0;
    overflow: hidden;
  }

  .user-name,
  .user-role {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
    border-radius: 7px;
  }

  .user-name { font-size: 12px; }
  .user-role { font-size: 10px; }

  .sidebar-account-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 2px;
    padding: 0;
  }

  .sidebar-account-actions .link-btn {
    font-size: 11px;
    padding: 6px 7px;
    min-height: 0;
    white-space: nowrap;
    text-align: center;
  }

  .sidebar-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px;
    padding: 0 10px 8px;
    overflow: visible;
    flex: none;
  }

  .nav-section-label { display: none !important; }

  .nav-item {
    flex: 1 1 calc(50% - 4px);
    min-width: calc(50% - 4px);
    justify-content: center;
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    box-shadow: none;
    gap: 6px;
  }

  .nav-icon { width: 15px; height: 15px; }

  .nav-item.active {
    background: rgba(43, 140, 255, 0.18);
    color: #9ec5ff;
    box-shadow: none;
    border: 1px solid rgba(43, 140, 255, 0.35);
  }

  .console-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
  }

  .console-header {
    display: none;
  }

  .console-body {
    padding: 10px 10px max(16px, env(safe-area-inset-bottom));
  }

  .panel.active { gap: 10px; }

  .stats-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .stat-card {
    padding: 8px 4px;
    text-align: center;
  }

  .stat-label {
    font-size: 10px;
    letter-spacing: 0;
    text-transform: none;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-value { font-size: 1.15rem; }

  .card--primary,
  .card,
  .enrollment-card { padding: 12px; }

  .card-head {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
  }

  .card-head > div:first-child {
    flex: 1;
    min-width: 0;
  }

  .card-head h2 {
    font-size: 0.95rem;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .card-head .hint--tight {
    display: none;
  }

  .head-actions {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .head-actions .filter-select {
    flex: 0 1 auto;
    min-width: 0;
    width: 72px;
    padding: 6px 6px;
    font-size: 11px;
  }

  .head-actions .btn-sm {
    flex-shrink: 0;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  .device-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    grid-template-areas:
      "icon main status"
      "actions actions actions";
    align-items: start;
    padding: 10px;
    gap: 8px 8px;
  }

  .device-icon {
    grid-area: icon;
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .device-icon img {
    width: 22px;
    height: 22px;
  }

  .device-main { grid-area: main; }

  .device-status {
    grid-area: status;
    align-self: start;
    margin-top: 2px;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 3px 7px;
    font-size: 10px;
  }

  .device-item .name { font-size: 14px; }
  .device-item .edge-id { font-size: 12px; margin-top: 2px; }
  .device-meta-line,
  .device-group { font-size: 11px; margin-top: 2px; }

  .device-head {
    justify-content: flex-start;
  }

  .device-actions {
    grid-area: actions;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .device-actions .btn-primary {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  .device-actions-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    overflow: visible;
  }

  .device-actions-row button {
    width: 100%;
    min-height: 44px;
    padding: 10px 4px;
    font-size: 13px;
    white-space: nowrap;
    justify-content: center;
    text-align: center;
  }

  .enrollment-form {
    flex-direction: column;
    align-items: stretch;
  }

  .enrollment-field,
  .enrollment-field:not(.enrollment-field--grow):not(.enrollment-field--action),
  .enrollment-field--grow,
  .enrollment-field--action {
    flex: 1 1 100%;
    width: 100%;
  }

  .enrollment-field--action .btn-primary {
    width: 100%;
    min-height: 40px;
    white-space: nowrap;
  }

  .enrollment-block-title {
    white-space: nowrap;
    font-size: 12px;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    overflow: visible;
  }

  .row-actions button {
    width: 100%;
    min-height: 32px;
    white-space: nowrap;
    font-size: 11px;
    padding: 6px 8px;
  }

  .table-wrap {
    margin-left: 0;
    margin-right: 0;
    border-radius: 8px;
    overflow-x: auto;
  }

  .data-table th,
  .data-table td {
    padding: 8px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  #enrollmentTable th:nth-child(2),
  #enrollmentTable td:nth-child(2),
  #enrollmentTable th:nth-child(5),
  #enrollmentTable td:nth-child(5) {
    display: none;
  }

  #userTable th:nth-child(4),
  #userTable td:nth-child(4),
  #auditTable th:nth-child(4),
  #auditTable td:nth-child(4) {
    display: none;
  }

  .data-table td:first-child {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .modal-overlay {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: min(88dvh, 640px);
    overflow-y: auto;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 16px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-actions button {
    width: 100%;
    min-height: 40px;
    white-space: nowrap;
  }

  .section-desc,
  .enrollment-guide .hint {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .sidebar-brand { padding: 6px 8px 2px; }
  .sidebar-brand-title { font-size: 0.85rem; }
  .sidebar-foot { padding: 6px 8px 2px 0; }
  .user-card { max-width: 88px; }
  .sidebar-nav { padding: 0 8px 6px; gap: 6px; }
  .nav-item {
    flex: 1 1 calc(50% - 3px);
    min-width: calc(50% - 3px);
    padding: 7px 8px;
    font-size: 12px;
    gap: 4px;
  }
  .nav-item .nav-icon { width: 14px; height: 14px; }
  .stats-row { gap: 4px; }
  .stat-card { padding: 6px 2px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 1.05rem; }
  .console-body { padding: 8px 8px max(14px, env(safe-area-inset-bottom)); }
  .card--primary,
  .card,
  .enrollment-card { padding: 10px; }
  .device-item { padding: 8px; gap: 6px 6px; }
  .head-actions .filter-select { width: 64px; }
  .form-grid { max-width: none; }
  .btn-block { min-height: 40px; }
  .enrollment-guide { padding: 10px 12px; }
}

@media (max-width: 600px) {
  .inline-form { flex-direction: column; }
  .form-grid--enroll { grid-template-columns: 1fr; }
  .form-grid-span-2 { grid-column: auto; }
}

body.password-change-locked .console-body {
  pointer-events: none;
  opacity: 0.45;
}

body.password-change-locked .sidebar-foot,
body.password-change-locked .modal-overlay {
  pointer-events: auto;
}
