/* ===================== 设计变量 ===================== */
:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --sidebar: #1e1b4b;
  --sidebar-2: #312e81;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2333;
  --muted: #7c849b;
  --border: #e8eaf2;
  --green: #12b76a;
  --green-soft: #e6f8ef;
  --orange: #f79009;
  --orange-soft: #fff4e5;
  --red: #f04438;
  --red-soft: #feeceb;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ===================== 登录 ===================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 10%, #e0e7ff 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, #c7d2fe 0%, transparent 40%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 20px;
  padding: 40px 30px 30px;
  box-shadow: 0 12px 40px rgba(49, 46, 129, 0.18);
  text-align: center;
  animation: pop 0.25s ease;
}

.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 8px;
}

.login-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 26px;
  line-height: 1.6;
}

.login-card input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.login-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin: 12px 0 0;
}

/* ===================== 布局：侧边栏 ===================== */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: #c7c9e6;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.side-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.5);
}

.side-title {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.side-sub {
  font-size: 11px;
  color: #8b8fb8;
  letter-spacing: 0.5px;
}

.side-nav {
  flex: 1;
  padding: 18px 14px;
  overflow-y: auto;
}

.nav-group {
  font-size: 11px;
  color: #6f74a6;
  padding: 8px 12px 6px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #c7c9e6;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.25);
  color: #fff;
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #a5b4fc;
}

.nav-ico {
  width: 18px;
  text-align: center;
}

.nav-dot {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
}

.side-foot {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: #6f74a6;
}

.side-hint {
  margin-bottom: 2px;
}

.side-version {
  color: #8b8fb8;
}

/* ===================== 主区 ===================== */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.page-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.content {
  padding: 24px 28px 80px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ===================== 统计卡 ===================== */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon-indigo {
  background: var(--brand-soft);
}

.stat-icon-green {
  background: var(--green-soft);
}

.stat-icon-orange {
  background: var(--orange-soft);
}

.stat-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--muted);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.text-green {
  color: var(--green);
}

.text-orange {
  color: var(--orange);
}

/* ===================== 面板 / 表格 ===================== */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.panel-head {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.search {
  flex: 1;
  height: 40px;
  border: 1px solid var(--border);
  background: #fafbff;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.search:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.table-wrap {
  overflow-x: auto;
}

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

.app-table thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 12px 20px;
  background: #fafbff;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.col-center {
  text-align: center !important;
}

.col-actions {
  width: 90px;
  text-align: right;
}

.app-table tbody td {
  padding: 16px 20px;
  border-bottom: 1px solid #f1f2f8;
  vertical-align: middle;
  font-size: 13px;
}

.app-table tbody tr:last-child td {
  border-bottom: none;
}

.app-table tbody tr {
  transition: background 0.12s;
}

.app-table tbody tr:hover {
  background: #fafbff;
}

.cell-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.cell-key {
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.app-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #f4f5fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: #4b5163;
}

.code-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
}

.code-cell code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted {
  color: #b6bccd;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 500;
  margin-top: 6px;
}

.tag-green {
  background: var(--green-soft);
  color: var(--green);
}

.tag-gray {
  background: #f2f4f7;
  color: var(--muted);
}

/* ===================== 开关 ===================== */
.switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  display: block;
  width: 44px;
  height: 24px;
  background: #d6dae6;
  border-radius: 999px;
  transition: background 0.18s;
  position: relative;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.switch input:checked + .switch-track {
  background: var(--brand);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-sm .switch-track {
  width: 40px;
  height: 22px;
}

.switch-sm .switch-track::after {
  width: 16px;
  height: 16px;
}

.switch-sm input:checked + .switch-track::after {
  transform: translateX(18px);
}

/* ===================== 按钮 ===================== */
.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  font-family: inherit;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}

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

.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: #4b5163;
}

.btn-ghost:hover {
  background: #f7f8fc;
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: transparent;
}

.btn-danger:hover {
  background: #fddedb;
}

.btn-block {
  width: 100%;
  height: 48px;
  font-size: 14px;
  letter-spacing: 2px;
}

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

.icon-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

.icon-btn:hover {
  background: #f2f4f7;
}

.link-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--brand);
  font-size: 11px;
  height: 24px;
  padding: 0 9px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 500;
}

.link-btn:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
}

/* ===================== 空状态 ===================== */
.empty {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

/* ===================== 弹窗 ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(30, 27, 75, 0.45);
  backdrop-filter: blur(3px);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 88vh;
  background: var(--card);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(30, 27, 75, 0.3);
  animation: pop 0.2s ease;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 12px;
}

.modal-head h2 {
  font-size: 17px;
  margin: 0;
}

.modal-body {
  padding: 4px 22px 8px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 22px 20px;
  border-top: 1px solid var(--border);
}

.modal-foot-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* ===================== 表单 ===================== */
.field {
  display: block;
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 7px;
}

.field-label em {
  font-style: normal;
  font-size: 11px;
  color: var(--orange);
  margin-left: 6px;
  font-weight: 400;
}

.field input[type='text'],
.field input[type='search'],
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.field input:disabled {
  background: #f7f8fc;
  color: var(--muted);
  cursor: not-allowed;
}

.field-hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fafbff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin: 4px 0 0;
}

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: #1e1b4b;
  color: #fff;
  padding: 11px 22px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(30, 27, 75, 0.35);
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ===================== 响应式 ===================== */
@media (max-width: 960px) {
  .sidebar {
    width: 64px;
  }
  .side-brand > div,
  .side-title,
  .side-sub,
  .nav-group,
  .nav-item:not(.active) .nav-ico ~ *,
  .side-foot {
    display: none;
  }
  .side-brand {
    justify-content: center;
    padding: 18px 0;
  }
  .stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .content {
    padding: 16px 14px 60px;
  }
  .panel-head {
    flex-direction: column;
  }
  .panel-head .btn {
    width: 100%;
  }
}
