:root {
  /* 颜色 token 全部定义在 theme.css（浅色默认 + [data-theme="dark"] 覆盖） */
  --r-sm: 4px;
  --r: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-lg: 15px;
  --fs-xl: 20px;
  --fs-2xl: 28px;
  --fs-3xl: 36px;

  /* 全站正文使用本机 MiSans，已复用现有 woff2 资产；缺失时回退系统字体。 */
  --font: "MiSans", Inter, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei UI",
          "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC",
          "WenQuanYi Micro Hei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", Consolas,
               "Noto Sans Mono CJK SC", monospace;


  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --nav-w: 208px;
  --nav-w-collapsed: 60px;
  --top-h: 52px;
}

* {
  box-sizing: border-box;
}

/* hidden 属性必须赢过组件自身的 display（.count / .dot 都是 inline-flex）。
   没有这条，未读角标会以空红点形式出现在每个导航项上。 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background-color: var(--bg-base);
  background-image:
    radial-gradient(ellipse 76% 54% at 4% 0%, var(--aurora-1), transparent 72%),
    radial-gradient(ellipse 64% 56% at 96% 100%, var(--aurora-2), transparent 74%),
    linear-gradient(145deg, var(--bg-base), var(--bg-panel-2));
  background-attachment: fixed;
  color: var(--text-1);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.7;
  font-weight: 400;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  color: var(--text-1);
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.015em;
}

button, .btn, .tag, .pill, .nav-item {
  font-weight: 500;
}

input, textarea, select, table, .kpi-value, .stat .v, .num {
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--brand-hover);
  outline-offset: 3px;
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
.search-box input:focus-visible {
  outline: none;
}

/* 动效强制开启，保留所有系统偏好下的动效。 */

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  color: var(--brand-hover);
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 6px;
  border: 2px solid var(--bg-base);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* ============ 布局骨架 ============ */
.app {
  display: flex;
  min-height: 100vh;
}

.nav {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--nav-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width 220ms var(--ease);
}

.nav-brand {
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow: hidden;
}

.nav-brand .mark {
  width: 32px;
  height: 32px;
  border-radius: 0;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.nav-brand .mark svg {
  display: block;
  width: 32px;
  height: 32px;
  max-width: none;
  overflow: visible;
}

.nav-brand .mark::after {
  content: none;
}

@keyframes markSweep {
  0%, 70%, 100% { transform: translateX(-120%); }
  35% { transform: translateX(120%); }
}

.nav-brand .name {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.nav-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}

.nav-group-label {
  font-size: 11px;
  color: var(--text-4);
  letter-spacing: 0.08em;
  padding: 12px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--r);
  color: var(--text-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}

.nav-item:hover {
  background: var(--bg-panel-2);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--brand-soft);
  color: var(--active-text);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 16px;
  margin-top: -8px;
  border-radius: 0 2px 2px 0;
  background: var(--brand);
  animation: navBar 240ms var(--ease-out);
}

@keyframes navBar {
  from { height: 0; margin-top: 0; }
  to { height: 16px; margin-top: -8px; }
}

.nav-item .ico {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item .badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: var(--onbrand);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-foot {
  border-top: 1px solid var(--line);
  padding: 10px;
  flex-shrink: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background 140ms var(--ease);
  overflow: hidden;
}
.user-chip:hover {
  background: var(--bg-panel-2);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--avatar-grad-a), var(--avatar-grad-b));
  border: 1px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  flex-shrink: 0;
}

.user-chip .meta {
  min-width: 0;
  overflow: hidden;
}

.user-chip .n {
  font-size: var(--fs-sm);
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-chip .r {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  margin-left: var(--nav-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left 220ms var(--ease);
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--top-h);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  z-index: 30;
}

.topbar h1 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.topbar .spacer {
  flex: 1;
}

.page {
  /* 大屏铺满：不设 max-width 硬上限，用随视口增长的内边距控制可读性 */
  padding: clamp(20px, 1.4vw, 28px) clamp(20px, 1.6vw, 32px);
  flex: 1;
  min-width: 0;
  width: 100%;
}

/* ============ 通用组件 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 13px;
  border-radius: var(--r);
  border: 1px solid var(--line-strong);
  background: var(--bg-panel-2);
  color: var(--text-1);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 140ms var(--ease), border-color 140ms var(--ease),
    transform 90ms var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--bg-raised);
  border-color: var(--line-hover);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--onbrand);
  font-weight: 500;
}
.btn.primary:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--bg-panel-2);
  color: var(--text-1);
}

.btn.danger {
  background: transparent;
  border-color: var(--danger-line);
  color: var(--danger);
}
.btn.danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn.sm {
  height: 26px;
  padding: 0 9px;
  font-size: var(--fs-xs);
}

.btn.icon {
  width: 32px;
  padding: 0;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 7px 11px;
  color: var(--text-1);
  outline: none;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-4);
}

.textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.65;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field > label {
  font-size: var(--fs-xs);
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.hint {
  font-size: var(--fs-xs);
  color: var(--text-4);
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 600;
}

.card-head .spacer {
  flex: 1;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-raised);
  color: var(--text-2);
  white-space: nowrap;
}

.tag.dot::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.tag.brand { background: var(--brand-soft); color: var(--brand-text); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.purple { background: var(--purple-soft); color: var(--purple); }
.tag.muted { background: var(--bg-panel-2); color: var(--text-3); }

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.grid {
  display: grid;
  gap: 14px;
}
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 44px 20px;
  color: var(--text-3);
  text-align: center;
}

.empty .icon {
  width: 40px;
  height: 40px;
  opacity: 0.3;
}

/* ============ 骨架屏 ============ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-panel-2) 0%,
    var(--bg-raised) 50%,
    var(--bg-panel-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ============ 动效工具类 ============ */
.fade-up {
  animation: fadeUp 260ms var(--ease-out) both;
}

@keyframes fadeUp {
  from {
    opacity: 1;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 200ms var(--ease) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.pop-in {
  animation: popIn 200ms var(--ease-out) both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 超期脉冲：只用 opacity，GPU 友好 */
.pulse-danger {
  animation: pulseDanger 1.8s ease-in-out infinite;
}

@keyframes pulseDanger {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.stagger > * {
  animation: fadeUp 240ms var(--ease-out) both;
}
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 30ms; }
.stagger > *:nth-child(3) { animation-delay: 60ms; }
.stagger > *:nth-child(4) { animation-delay: 90ms; }
.stagger > *:nth-child(5) { animation-delay: 120ms; }
.stagger > *:nth-child(6) { animation-delay: 150ms; }
.stagger > *:nth-child(7) { animation-delay: 180ms; }
.stagger > *:nth-child(8) { animation-delay: 210ms; }
.stagger > *:nth-child(n + 9) { animation-delay: 240ms; }

/* ============ 弹层 ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  animation: fadeIn 160ms var(--ease) both;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  animation: popIn 200ms var(--ease-out) both;
}

.modal.wide {
  max-width: 820px;
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-head h3 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ============ Toast ============ */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 380px;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  display: flex;
  align-items: flex-start;
  gap: 9px;
  animation: toastIn 220ms var(--ease-out) both;
}

.toast.leaving {
  animation: toastOut 180ms var(--ease) both;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.info { border-left: 3px solid var(--info); }

/* ============ 表格 ============ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-3);
  font-size: var(--fs-xs);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table tbody tr {
  transition: background 120ms var(--ease);
}

.table tbody tr:hover {
  background: var(--bg-panel-2);
}

/* ============ 响应式 ============ */
@media (max-width: 1199px) {
  :root {
    --nav-w: var(--nav-w-collapsed);
  }
  .nav-brand .name,
  .nav-item span,
  .nav-group-label,
  .user-chip .meta {
    display: none;
  }
  .nav-item {
    justify-content: center;
    padding: 0;
  }
  .nav-item .badge {
    position: absolute;
    top: 2px;
    right: 2px;
    margin: 0;
  }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  :root {
    --nav-w: 0px;
  }
  .nav {
    top: auto;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 56px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .nav-brand,
  .nav-group-label,
  .nav-foot {
    display: none;
  }
  .nav-body {
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .nav-item {
    flex: 1;
    min-width: 62px;
    height: 56px;
    flex-direction: column;
    gap: 3px;
    font-size: 10px;
    padding: 0;
    justify-content: center;
    border-radius: 0;
  }
  .nav-item.active::before {
    left: 50%;
    top: 0;
    width: 18px;
    height: 2px;
    margin: 0 0 0 -9px;
  }
  .nav-item .badge {
    top: 6px;
  }
  .main {
    margin-left: 0;
    padding-bottom: 56px;
  }
  .page {
    padding: 14px;
  }
  .grid.c2,
  .grid.c3,
  .grid.c4 {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 0 14px;
  }
  .topbar h1 {
    font-size: var(--fs-base);
  }
}
