/* =========================================================
   通用布局与组件
========================================================= */

/* —— 应用框架 —— */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.app.no-sidebar { grid-template-columns: 1fr; }

/* —— 侧边栏 —— */
.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border-soft);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px dashed var(--border-soft);
}
.sb-brand .iso-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--grad-electric);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  box-shadow: var(--shadow-brand);
}
.sb-brand .sb-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--text-strong);
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.sb-brand .sb-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.sb-section {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.12em;
  padding: 4px 10px;
  margin-top: 6px;
}
.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--text-body);
  transition: background .2s var(--ease), color .2s var(--ease);
  position: relative;
  cursor: pointer;
}
.sb-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.78; }
.sb-item:hover { background: var(--bg-soft); color: var(--text-strong); }
.sb-item.active {
  background: linear-gradient(135deg, rgba(61,90,254,.10), rgba(6,182,212,.06));
  color: var(--brand-600);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(61,90,254,.16);
}
.sb-item.active svg { opacity: 1; color: var(--brand-500); }
.sb-item .badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: rgba(61,90,254,.12);
  color: var(--brand-600);
  padding: 1px 7px;
  border-radius: 5px;
  letter-spacing: 0.04em;
}
.sb-foot {
  margin-top: auto;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(61,90,254,.08), rgba(6,182,212,.06));
  border: 1px solid rgba(61,90,254,.18);
}
.sb-foot .who {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-strong);
  font-size: 13.5px;
  letter-spacing: -0.01em;
}
.sb-foot .role {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--brand-600);
  letter-spacing: 0.06em;
  margin-top: 3px;
}
.sb-foot .logout {
  margin-top: 10px;
  width: 100%;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 7px 0;
  transition: all .2s var(--ease);
}
.sb-foot .logout:hover {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}

/* —— 主内容区 —— */
.main {
  padding: 26px 32px 56px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar .crumbs {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.topbar .crumbs .crumb-link {
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s;
}
.topbar .crumbs .crumb-link:hover {
  color: var(--accent);
}
.topbar .crumbs .crumb-sep {
  margin: 0 6px;
  color: var(--text-faint);
  opacity: 0.55;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.02em;
  margin: 0;
}
.topbar .spacer { flex: 1; }
.topbar .who-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 5px 14px 5px 5px;
  font-size: 12.5px;
  color: var(--text-body);
}
.topbar .who-chip .ava {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--grad-electric);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  font-family: var(--font-display);
}

/* —— 卡片 —— */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-soft);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.card-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}
.card-head .spacer { flex: 1; }
.card-head .hint {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* —— 按钮 —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-body);
  transition: all .2s var(--ease);
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand-300); color: var(--brand-600); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--grad-electric);
  border-color: transparent;
  color: var(--text-on-brand);
  box-shadow: var(--shadow-brand);
  position: relative;
  overflow: hidden;
}
.btn-primary:hover {
  color: var(--text-on-brand);
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 18px 40px -16px rgba(61,90,254,.45);
}
.btn-primary::after {
  content: "";
  position: absolute;
  top: 0; left: -120%;
  width: 60%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.36), transparent);
  transform: skewX(-22deg);
  transition: left .8s var(--ease);
}
.btn-primary:hover::after { left: 130%; }

.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: rgba(239,68,68,.32); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { color: var(--success); border-color: rgba(22,163,74,.32); }
.btn-success:hover { background: var(--success); color: #fff; border-color: var(--success); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

/* —— 表单 —— */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.form-row label .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--text-body);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(61,90,254,.14);
}
.textarea { resize: vertical; min-height: 80px; font-family: var(--font-body); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px 16px; }
@media (max-width: 720px) { .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; } }

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

/* —— 表格 —— */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td {
  padding: 13px 18px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
table.tbl th {
  background: var(--bg-elev);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .15s var(--ease); }
table.tbl tbody tr:hover { background: var(--bg-soft); }
table.tbl td .actions { display: inline-flex; gap: 6px; }
table.tbl .name-cell { font-weight: 600; color: var(--text-strong); }
table.tbl .mono { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-muted); }

/* —— 分页 —— */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-elev);
}
.pager .pages { display: flex; gap: 4px; }
.pager .page-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-body);
  transition: all .15s var(--ease);
}
.pager .page-btn:hover { border-color: var(--brand-400); color: var(--brand-600); }
.pager .page-btn.active {
  background: var(--brand-500);
  border-color: var(--brand-500);
  color: #fff;
}

/* —— 状态 Pill —— */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px currentColor;
  filter: drop-shadow(0 0 4px currentColor);
  opacity: 0.5;
}
.pill.success { color: var(--success); background: var(--success-bg); }
.pill.warning { color: var(--warning); background: var(--warning-bg); }
.pill.danger { color: var(--danger); background: var(--danger-bg); }
.pill.info { color: var(--info); background: var(--info-bg); }
.pill.muted { color: var(--text-muted); background: var(--bg-soft); border-color: var(--border-soft); }

/* —— 空状态 —— */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
}
.empty .iso {
  width: 80px; height: 80px;
  margin: 0 auto 14px;
  border-radius: 22px;
  background: var(--grad-iso);
  display: grid; place-items: center;
  border: 1px solid rgba(61,90,254,.15);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.empty .iso svg { width: 38px; height: 38px; color: var(--brand-500); }
.empty h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 6px;
  color: var(--text-strong);
}
.empty p { margin: 0 0 14px; font-size: 13px; }

/* —— 工具栏 —— */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar .input { width: auto; min-width: 220px; }
.toolbar .select { width: auto; min-width: 130px; }
.toolbar .spacer { flex: 1; }

/* —— Toast —— */
.toast-wrap {
  position: fixed;
  top: 22px; right: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px;
  max-width: 380px;
  padding: 11px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  font-size: 13px;
  color: var(--text-body);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in .25s var(--ease);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--brand-500); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* —— 模态 —— */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 48, .42);
  backdrop-filter: blur(4px);
  z-index: 998;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 18px;
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  overflow: hidden;            /* 关键:不再让整个 modal 滚动 */
  display: flex;
  flex-direction: column;      /* head / body / foot 垂直排列 */
  box-shadow: 0 30px 80px -30px rgba(11,18,48,.32);
  animation: modal-in .26s var(--ease);
}
.modal.lg { max-width: 720px; }
.modal-head {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-card);  /* sticky 时背景不透 */
  flex-shrink: 0;              /* 不被压扁 */
}
.modal-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text-strong);
  letter-spacing: -0.01em;
  /* 长标题不应把"关闭 X"挤出可视区 */
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 12px;
}
.modal-close-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-faint);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s ease;
  padding: 0;
}
.modal-close-btn i,
.modal-close-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}
.modal-close-btn:hover {
  background: var(--bg-soft);
  border-color: var(--border-soft);
  color: var(--text-strong);
  transform: rotate(90deg);
}
.modal-close-btn:active {
  background: var(--bg-elev);
  transform: rotate(90deg) scale(0.92);
}
.modal-close-btn:focus-visible {
  outline: 2px solid rgba(99, 102, 241, .5);
  outline-offset: 2px;
}
/* 兼容旧类名(避免遗漏) */
.modal-head .close { display: none; }
.modal-body {
  padding: 22px;
  overflow-y: auto;            /* 关键:滚动只发生在 body 上 */
  flex: 1 1 auto;              /* 占据剩余空间 */
  min-height: 0;               /* flex 子项允许收缩 */
}
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-elev);
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 18px;
  flex-shrink: 0;              /* 不被压扁 */
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* —— 加载骨架 —— */
.skel {
  height: 14px;
  background: linear-gradient(90deg, #eef1f7, #f6f8fc, #eef1f7);
  background-size: 200% 100%;
  animation: skel 1.4s infinite linear;
  border-radius: 6px;
}
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* —— 移动适配 —— */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }
  .sb-foot { display: none; }
  .main { padding: 18px 16px 32px; }
}

/* —— Reduced motion —— */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
