/* =====================================================
   ApiGateway 控制台设计系统
   亮色内容区 + 深色侧边栏 · 移动端表格卡片化
   ===================================================== */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e4e9f2;
  --border-strong: #cbd5e1;
  --text: #1a2333;
  --muted: #64748b;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, .16);

  --accent: #0d9488;
  --accent-soft: #d9f6f1;

  --success: #16833f;
  --success-soft: #dcf5e5;
  --danger: #dc2626;
  --danger-soft: #feeaea;
  --warning: #b45309;
  --warning-soft: #fdf0d3;

  --sidebar-bg: #ffffff;
  --sidebar-border: var(--border);

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 8px;

  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 20px 48px rgba(15, 23, 42, .14);

  --sidebar-w: 248px;
  /* 侧栏品牌区与顶栏共用同一高度,保证两条底部分隔线对齐 */
  --header-h: 66px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover { color: var(--primary-hover); }

::selection {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* ===== 布局 ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  transition: filter .18s ease;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1030;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  height: var(--header-h);
  flex: 0 0 auto;
  padding: 0 20px;
  font-weight: 800;
  font-size: 16.5px;
  color: #0f172a;
  letter-spacing: .01em;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  box-shadow: 0 8px 18px rgba(99, 102, 241, .35);
  flex: 0 0 auto;
}

.sidebar-nav {
  padding: 12px 12px 20px;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.sidebar-nav .nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #8b98ac;
  padding: 18px 12px 7px;
  font-weight: 700;
}

.sidebar-nav a.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: #3b4a5f;
  font-weight: 600;
  min-height: 42px;
  transition: background .15s ease, color .15s ease;
}

.sidebar-nav a.nav-item i {
  font-size: 16.5px;
  color: #64748b;
  width: 20px;
  text-align: center;
  transition: color .15s ease;
}

.sidebar-nav a.nav-item:hover {
  background: var(--surface-2);
  color: #0f172a;
}

.sidebar-nav a.nav-item:hover i { color: var(--primary); }

.sidebar-nav a.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-nav a.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 3px;
  background: var(--primary);
}

.sidebar-nav a.nav-item.active i { color: var(--primary); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1025;
  background: rgba(10, 15, 28, .48);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
  backdrop-filter: blur(2px);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ===== 顶栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  height: var(--header-h);
  background: rgba(255, 255, 255, .82);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 28px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.title-copy { min-width: 0; }

.topbar .page-title {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
  color: #0f172a;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .page-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.user-menu .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(99, 102, 241, .28);
  user-select: none;
}

.user-menu .uname {
  font-weight: 700;
  color: #1e293b;
}

.user-menu .role-badge { flex: 0 0 auto; }

.content {
  padding: 26px 28px 64px;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
  animation: page-in .3s ease both;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ===== 页面头 ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.3;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -.01em;
}

.page-header .desc {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
  max-width: 760px;
}

/* ===== 卡片 ===== */
.card-app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-app .card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}

.card-app .card-head h3 {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.35;
  font-weight: 800;
  color: #0f172a;
}

.card-app .card-head h3 i {
  color: var(--primary);
  margin-right: 2px;
}

.card-app .card-body {
  padding: 20px;
  min-width: 0;
}

/* ===== 按钮 ===== */
.btn-app {
  border-radius: var(--radius-sm);
  font-weight: 700;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  letter-spacing: 0;
  transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.btn-primary-app {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .24);
}

.btn-primary-app:hover,
.btn-primary-app:focus {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
  box-shadow: 0 8px 20px rgba(79, 70, 229, .3);
  transform: translateY(-1px);
}

.btn-primary-app:active {
  transform: none;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .22);
}

.btn-danger-app {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 6px 16px rgba(220, 38, 38, .2);
}

.btn-danger-app:hover,
.btn-danger-app:focus {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
  box-shadow: 0 8px 20px rgba(220, 38, 38, .26);
  transform: translateY(-1px);
}

.btn-danger-app:active {
  transform: none;
  box-shadow: 0 4px 10px rgba(220, 38, 38, .18);
}

.btn-danger-app:disabled {
  transform: none;
  box-shadow: none;
  opacity: .75;
}

.btn-soft {
  background: var(--surface);
  border-color: var(--border);
  color: #26334a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.btn-soft:hover,
.btn-soft:focus {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: #0f172a;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.btn-icon { padding: 7px 11px; }

.topbar .sidebar-toggle { display: none; }

.btn-link-app {
  color: var(--primary);
  padding: 6px 10px;
  font-weight: 700;
  font-size: 13px;
  background: none;
  border: none;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s ease, color .15s ease;
}

.btn-link-app:hover {
  color: var(--primary-hover);
  background: var(--primary-soft);
}

.btn-link-app.danger { color: var(--danger); }

.btn-link-app.danger:hover {
  color: #b91c1c;
  background: var(--danger-soft);
}

/* ===== 表格 ===== */
.table-responsive-app {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive-app::-webkit-scrollbar { height: 8px; }

.table-responsive-app::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.table-app {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.table-app th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 800;
  padding: 12px 16px;
  text-align: left;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-app td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: #26324a;
}

.table-app tbody tr:last-child td { border-bottom: none; }

.table-app tbody tr { transition: background .12s ease; }

.table-app tbody tr:hover { background: #f7f9fd; }

.table-app td.mono {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-app td.cell-actions { white-space: nowrap; }

.cell-time {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.cell-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.cell-clip {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-clip.wide { max-width: 320px; }

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0;
}

.text-muted-app { color: var(--muted); }

/* ===== 卡片操作 ===== */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.dashboard-refresh-btn {
  width: 38px;
  height: 38px;
  padding: 0;
}

.dashboard-refresh-btn.is-refreshing i {
  animation: dashboard-refresh-spin .8s linear infinite;
}

@keyframes dashboard-refresh-spin {
  to { transform: rotate(360deg); }
}

/* ===== 徽章 ===== */
.badge-app {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-app .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-success .dot { background: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-danger .dot { background: var(--danger); }
.badge-muted { background: var(--surface-3); color: #4f6076; }
.badge-muted .dot { background: #4f6076; }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-warning .dot { background: var(--warning); }

/* ===== 开关 ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  vertical-align: middle;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background .2s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .22);
}

.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* ===== 表单 ===== */
.form-label-app {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  color: #26324a;
  display: inline-block;
}

.form-control-app,
.form-select-app {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid #d8dfeb;
  padding: 9px 12px;
  font-size: 14px;
  background-color: var(--surface);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control-app::placeholder { color: #9aa7ba; }

.form-control-app:focus,
.form-select-app:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
  outline: none;
}

.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

.pattern-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pattern-add-row {
  width: 100%;
  min-height: 40px;
  justify-content: center;
  margin-top: 8px;
  color: #94a3b8;
}

.pattern-add-row:hover,
.pattern-add-row:focus {
  color: #64748b;
}

.pattern-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
}

.pattern-row .btn-icon {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
}

.pattern-remove:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* ===== 统计卡片 ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  min-height: 128px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, .06), 0 16px 36px rgba(15, 23, 42, .09);
  border-color: #d5ddeb;
}

.stat-card::after {
  content: "";
  position: absolute;
  top: -46px;
  right: -46px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--primary-soft), transparent);
  opacity: .8;
  pointer-events: none;
}

.stat-card:nth-child(2)::after { background: radial-gradient(closest-side, var(--accent-soft), transparent); }
.stat-card:nth-child(3)::after { background: radial-gradient(closest-side, var(--warning-soft), transparent); }
.stat-card:nth-child(4)::after { background: radial-gradient(closest-side, var(--surface-3), transparent); }

.stat-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 17px;
  background: var(--primary-soft);
  color: var(--primary);
  flex: 0 0 auto;
}

.stat-card:nth-child(2) .stat-icon { background: var(--accent-soft); color: var(--accent); }
.stat-card:nth-child(3) .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-card:nth-child(4) .stat-icon { background: var(--surface-3); color: #4b5c72; }

.stat-card .value {
  position: relative;
  z-index: 1;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 800;
  margin-top: 10px;
  color: #0f172a;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

.stat-card .sub {
  position: relative;
  z-index: 1;
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

/* ===== 详情字段 / 提示条 ===== */
.field-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 2px;
}

.alert-app {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert-app i {
  flex: 0 0 auto;
  margin-top: 1px;
}

.alert-warning-app {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid rgba(180, 83, 9, .16);
}

/* ===== 确认弹窗 ===== */
.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 1090;
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease;
}

.confirm-dialog.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.confirm-dialog-open { overflow: hidden; }

.confirm-dialog-open .app-layout {
  filter: blur(4px);
}

.confirm-dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .38);
}

.confirm-dialog__panel {
  position: relative;
  width: min(430px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid rgba(226, 232, 240, .9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 20px;
  transform: translateY(10px) scale(.98);
  transition: transform .2s cubic-bezier(.21, 1.02, .55, 1);
}

.confirm-dialog.is-open .confirm-dialog__panel { transform: none; }

.confirm-dialog__body {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  align-items: flex-start;
}

.confirm-dialog__icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 18px;
}

.confirm-dialog__copy h2 {
  margin: 0;
  color: #0f172a;
  font-size: 17px;
  line-height: 1.35;
  font-weight: 800;
}

.confirm-dialog__copy p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.confirm-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}

.empty-state i {
  font-size: 40px;
  color: #c3cddc;
  display: block;
  margin-bottom: 12px;
}

/* ===== Key / JSON 展示 ===== */
.key-box {
  background: #0f172a;
  color: #e7eefb;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  padding: 18px 20px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-all;
}

.json-box {
  background: #0f172a;
  color: #d9e2f0;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  padding: 16px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow: auto;
}

.json-box::-webkit-scrollbar { width: 8px; height: 8px; }

.json-box::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 999px;
}

/* ===== Toast ===== */
.toast-stack {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast-app {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  border-radius: var(--radius);
  min-width: 240px;
  max-width: min(420px, calc(100vw - 32px));
  cursor: pointer;
  animation: toast-in .32s cubic-bezier(.21, 1.02, .55, 1) both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.toast-app.hide {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s ease, transform .3s ease;
}

.toast-app.success { border-left-color: var(--success); }
.toast-app.error { border-left-color: var(--danger); }
.toast-app i { font-size: 18px; flex: 0 0 auto; }
.toast-app.success i { color: var(--success); }
.toast-app.error i { color: var(--danger); }

/* ===== 登录页 ===== */
.login-wrap {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  overflow: hidden;
  background: #f4f6fa;
}

.login-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(560px 420px at 12% 8%, rgba(99, 102, 241, .16), transparent 68%),
    radial-gradient(620px 460px at 88% 92%, rgba(13, 148, 136, .14), transparent 68%),
    radial-gradient(420px 320px at 82% 12%, rgba(139, 92, 246, .1), transparent 70%);
}

.login-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(26, 35, 51, .14) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(closest-side at 50% 42%, #000 20%, transparent 100%);
  -webkit-mask-image: radial-gradient(closest-side at 50% 42%, #000 20%, transparent 100%);
  opacity: .5;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 36px));
  max-width: 100%;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(226, 232, 240, .9);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 36px 32px 30px;
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: page-in .35s ease both;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6, #0d9488);
}

.login-card .logo {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 25px;
  margin: 0 auto 18px;
  box-shadow: 0 14px 30px rgba(99, 102, 241, .32);
}

.login-card h1 {
  text-align: center;
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 6px;
  color: #0f172a;
  letter-spacing: -.01em;
}

.login-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.login-card .btn-primary-app {
  min-height: 44px;
  width: 100%;
}

.login-remember {
  margin-bottom: 18px;
  user-select: none;
}

.login-remember .form-check-input { cursor: pointer; }

.login-remember .form-check-label {
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.login-alert {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-alert ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: inline;
}

/* ===== 分页 ===== */
.pagination-app {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.pagination-info,
.pagination-actions,
.pagination-size-form,
.pagination-jump-form {
  display: flex;
  align-items: center;
}

.pagination-info {
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.pagination-size-form,
.pagination-jump-form {
  gap: 6px;
  margin: 0;
}

.pagination-info span,
.pagination-label,
.pagination-unit {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.pagination-link {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, border-color .15s ease;
}

.pagination-link:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.pagination-link.disabled {
  color: var(--muted);
  background: var(--surface-2);
  cursor: default;
}

.pagination-select {
  width: 78px;
  height: 36px;
  padding: 7px 30px 7px 10px;
  font-size: 13px;
}

.pagination-page-input {
  width: 74px;
  height: 36px;
  padding: 7px 10px;
  font-size: 13px;
  text-align: center;
}

.pagination-app .btn-app {
  min-height: 36px;
  padding: 7px 12px;
}

/* =====================================================
   响应式
   ===================================================== */
@media (max-width: 992px) {
  .content { padding: 22px 20px 52px; }
  .page-header { align-items: flex-start; }
}

@media (max-width: 768px) {
  body.sidebar-open { overflow: hidden; }

  .sidebar {
    width: min(84vw, 300px);
    transform: translateX(-110%);
    transition: transform .24s cubic-bezier(.3, .8, .4, 1), box-shadow .24s ease;
    box-shadow: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .sidebar.show {
    transform: none;
    box-shadow: 24px 0 60px rgba(15, 23, 42, .22);
  }

  .sidebar-backdrop { display: block; }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .main { margin-left: 0; }

  .topbar {
    height: 60px;
    padding: 0 14px;
  }

  .topbar .sidebar-toggle {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .content {
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .page-header {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-header > .btn { width: 100%; }

  .btn-app { min-height: 42px; }

  .btn-icon { min-height: 38px; }

  .card-app { border-radius: var(--radius); }

  .card-app .card-head { padding: 13px 16px; }

  .card-app .card-body { padding: 16px; }

  .card-app .card-body[style*="padding:0"] { padding: 0 !important; }

  .empty-state { padding: 40px 14px; }

  /* --- 表格 → 卡片式键值行 --- */
  .table-responsive-app { overflow: visible; }

  .table-app,
  .table-app tbody {
    display: block;
    min-width: 0;
  }

  .table-app tbody {
    padding: 12px;
    background: var(--surface-2);
  }

  .table-app thead { display: none; }

  .table-app tbody tr {
    display: block;
    padding: 13px 16px 12px;
    margin-bottom: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
  }

  .table-app tbody tr:hover { background: var(--surface); }

  .table-app tbody tr:last-child { margin-bottom: 0; }

  .table-app td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    column-gap: 12px;
    align-items: center;
    justify-items: end;
    padding: 5px 0;
    border: none;
    text-align: right;
    min-height: 30px;
    font-size: 13.5px;
  }

  .table-app td::before {
    content: attr(data-label);
    grid-column: 1;
    justify-self: start;
    text-align: left;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
  }

  .table-app td > * { grid-column: 2; }

  .table-app td.mono,
  .table-app td .cell-clip,
  .table-app td.cell-clip {
    max-width: none;
    white-space: normal;
    word-break: break-all;
  }

  .table-app td.cell-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
  }

  .table-app td.cell-actions::before { display: none; }

  .table-app td.cell-actions .btn-link-app {
    min-height: 38px;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
  }

  .table-app td.cell-actions .btn-link-app:hover { background: var(--primary-soft); }

  .table-app td.cell-actions .btn-link-app.danger:hover { background: var(--danger-soft); }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .toast-app {
    min-width: 0;
    width: 100%;
    max-width: none;
  }

  .confirm-dialog {
    align-items: end;
    padding: 12px;
  }

  .confirm-dialog__panel {
    width: 100%;
    padding: 18px;
  }
}

@media (max-width: 575px) {
  .user-menu { gap: 8px; }

  .user-menu .uname { display: none; }

  .user-menu .role-badge { display: none; }

  .topbar .page-title { font-size: 16px; }

  .topbar .page-sub { max-width: 52vw; }

  .page-header h2 { font-size: 19px; }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat-card {
    min-height: 108px;
    padding: 14px 16px;
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    font-size: 15px;
    border-radius: 8px;
  }

  .stat-card .value { font-size: 22px; }

  .stat-card .label { font-size: 11px; }

  .card-app form .mt-4.d-flex,
  .card-app .card-body > .mt-3.d-flex {
    flex-direction: column;
  }

  .card-app form .mt-4.d-flex .btn,
  .card-app .card-body > .mt-3.d-flex .btn {
    width: 100%;
  }

  .pagination-app {
    padding: 12px !important;
    align-items: stretch;
  }

  .pagination-info,
  .pagination-actions {
    width: 100%;
    margin-left: 0;
  }

  .pagination-info {
    justify-content: space-between;
  }

  .pagination-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination-size-form,
  .pagination-jump-form {
    width: 100%;
  }

  .pagination-select,
  .pagination-page-input {
    flex: 1;
    width: auto;
  }

  .pagination-link,
  .pagination-app .btn-app {
    width: 100%;
    min-height: 40px;
  }

  .json-box { max-height: 320px; }

  .confirm-dialog__body {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
  }

  .confirm-dialog__icon {
    width: 38px;
    height: 38px;
  }

  .confirm-dialog__actions {
    flex-direction: column-reverse;
  }

  .confirm-dialog__actions .btn {
    width: 100%;
  }

  .login-wrap { padding: 20px 14px; }

  .login-card { padding: 30px 22px 24px; }

  .login-card h1 { font-size: 20px; }
}

/* ===== 动效偏好 ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
