:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* 登录页 */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 55%, #e2e8f0 100%);
}

.login-shell {
  width: 100%;
  max-width: 420px;
}

.login-card {
  padding: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.login-brand h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
}

.login-brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.03em;
}

.brand-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.03em;
}

.login-form {
  display: grid;
  gap: 18px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field label,
.checkbox-field span {
  color: #374151;
  font-size: 13px;
  font-weight: 600;
}

.form-field input,
.form-field select {
  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 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-error {
  padding: 9px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 13px;
}

.login-footer {
  margin: 24px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

/* 后台布局 */
.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 28px;
}

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

.header-brand .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  font-size: 14px;
}

.header-brand strong {
  display: block;
  font-size: 16px;
}

.header-brand span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-label {
  color: var(--text-muted);
  font-size: 12px;
}

.user-name {
  font-size: 14px;
}

.admin-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 48px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  padding: 5px;
  background: #e8ecf3;
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.tab-btn {
  padding: 9px 18px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #475569;
  white-space: nowrap;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.is-active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.tab-panel {
  display: grid;
  gap: 20px;
}

.panel {
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  /* grid 子项默认 min-width:auto，会被表格 min-width 撑破容器；显式归零后
     由 .table-wrap 的 overflow-x 接管横向滚动 */
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

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

.detail-devices {
  margin-top: 14px;
}

.detail-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.inline-form,
.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.inline-form .form-field,
.filter-form .form-field {
  min-width: 160px;
}

.inline-form .form-field input,
.filter-form .form-field input,
.filter-form .form-field select {
  min-width: 170px;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  border-color: var(--border);
  background: #fff;
  color: #374151;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-danger-ghost {
  background: #fef2f2;
  color: var(--danger);
}

.btn-success-ghost {
  background: #ecfdf5;
  color: var(--success);
}

.btn-sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.btn-xs {
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 500;
}

.btn-block {
  width: 100%;
  min-height: 42px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

/* 表格 */
.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  background: var(--surface-muted);
  color: #475569;
  font-size: 12px;
  font-weight: 650;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: #fafcff;
}

.mono-cell,
.key-item {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn {
  margin-right: 5px;
}

.actions-cell .btn:last-child {
  margin-right: 0;
}

.empty-cell {
  padding: 28px 12px !important;
  color: var(--text-muted);
  text-align: center !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-ok {
  background: #dcfce7;
  color: #15803d;
}

.badge-info {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-warn {
  background: #fef3c7;
  color: #b45309;
}

.badge-muted,
.badge-neutral {
  background: #f1f5f9;
  color: #475569;
}

/* 分页 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}

.pager-btn {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: #374151;
  font-size: 12px;
}

.pager-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.pager-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager-info {
  color: var(--text-muted);
  font-size: 12px;
}

/* 生成结果 */
.generate-result {
  margin-top: 16px;
  padding: 13px 15px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  font-size: 13px;
}

.key-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.key-item {
  padding: 4px 8px;
  border: 1px solid #dbeafe;
  border-radius: 6px;
  background: #fff;
  word-break: break-all;
}

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.45);
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(900px, 100%);
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.modal-foot {
  justify-content: flex-end;
  border-bottom: 0;
  border-top: 1px solid var(--border);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.confirm-body p {
  margin: 0;
  font-size: 14px;
}

.detail-subtitle {
  margin: 22px 0 0;
  font-size: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 14px;
  margin: 0;
  padding: 15px;
  border-radius: 9px;
  background: var(--surface-muted);
  overflow-wrap: anywhere;
}

.detail-grid dt {
  color: var(--text-muted);
}

.detail-grid dd {
  margin: 0;
  font-weight: 500;
}

.detail-table-wrap {
  margin-top: 12px;
}

.detail-table {
  min-width: 620px;
}

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

.modal-form {
  display: grid;
  gap: 15px;
  max-width: 420px;
}

/* 轻提示 */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(340px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  font-size: 13px;
  animation: toast-in 0.2s ease-out;
}

.toast-success {
  border-left-color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-info {
  border-left-color: var(--primary);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateX(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式 */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 18px;
  }

  .header-user {
    width: 100%;
    justify-content: flex-end;
  }

  .admin-main {
    padding: 18px 14px 40px;
  }

  .tabs {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
    padding: 9px 12px;
  }

  .panel {
    padding: 16px;
  }

  .panel-head {
    flex-direction: column;
  }

  .inline-form .form-field,
  .filter-form .form-field {
    flex: 1 1 100%;
  }

  .inline-form .form-field input,
  .filter-form .form-field input,
  .filter-form .form-field select {
    min-width: 0;
  }

  .pagination {
    justify-content: center;
    flex-wrap: wrap;
  }

  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-grid dt {
    margin-top: 4px;
  }

  .login-card {
    padding: 26px;
  }
}
