/* ══════════════════════════════════════════════════════════════
   基础层：字体资源、重置、排版基线、焦点与降级动效
   ══════════════════════════════════════════════════════════════ */

/* ── 字体：只引入真正用到的字重，latin 子集，font-display: swap ── */
@font-face {
  font-family: 'Chakra Petch';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/chakrapetch-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Chakra Petch';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/chakrapetch-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Chakra Petch';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/chakrapetch-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/barlow-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/barlow-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/barlow-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── 重置 ── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

/**
 * 全局兜住 [hidden]。
 * 组件类常带 display:flex/grid，其优先级高于浏览器默认的 [hidden]{display:none}，
 * 不加这条就会出现"该藏的藏不住"（例如空的告警框）。
 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--c-abyss);
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.7; /* 中文正文 ≥1.7 */
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden; /* 大屏/登录页都不滚动，由舞台自适应 */
}

/* 数字一律等宽，避免跳动导致表格/图表对不齐 */
.num, .kpi__value, table, .font-num { font-variant-numeric: tabular-nums; }

img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--c-brand-2); text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; }

/* ── 排版工具类 ── */
/* 标题换行做平衡，避免"最后一行只剩一两个字"这种中文排版硬伤 */
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }

.u-display { font-family: var(--font-display); letter-spacing: -0.02em; }
.u-cn { font-family: var(--font-cn); letter-spacing: 0.02em; }
.u-muted { color: var(--c-muted); }
.u-dim { color: var(--c-dim); }
.u-eyebrow {
  font-family: var(--font-display);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--c-brand-3);
}
.u-visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── 焦点可见：键盘用户必须看得见 ── */
:focus-visible {
  outline: 2px solid var(--c-brand-2);
  outline-offset: 2px;
  border-radius: var(--r-2);
}
:focus:not(:focus-visible) { outline: none; }

/* ── 氛围层：渐变网格 + 噪点颗粒，替代纯色平铺 ── */
.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(64rem 42rem at 8% -12%, rgba(46, 123, 255, 0.22), transparent 62%),
    radial-gradient(52rem 38rem at 102% 4%, rgba(20, 65, 143, 0.30), transparent 58%),
    radial-gradient(46rem 34rem at 50% 118%, rgba(46, 123, 255, 0.14), transparent 60%);
}
.grain::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── 入场编排：一次错峰序列，胜过一堆零散微交互 ── */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  animation: reveal-in var(--dur-slow) var(--ease-out) forwards;
}
@keyframes reveal-in {
  to { opacity: 1; transform: none; }
}
.reveal:nth-child(1) { animation-delay: 60ms; }
.reveal:nth-child(2) { animation-delay: 140ms; }
.reveal:nth-child(3) { animation-delay: 220ms; }
.reveal:nth-child(4) { animation-delay: 300ms; }
.reveal:nth-child(5) { animation-delay: 380ms; }
.reveal:nth-child(6) { animation-delay: 460ms; }

/* ── 状态：加载 / 错误 / 空态 ── */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  min-height: 120px;
  padding: var(--sp-5);
  color: var(--c-muted);
  text-align: center;
}
.state__title { color: var(--c-text-2); font-size: var(--fs-md); }
.state__hint { font-size: var(--fs-xs); color: var(--c-dim); }
.state--error { color: var(--c-danger); }

/* 骨架屏：加载时给结构，不要白屏 */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--c-surface-2);
  border-radius: var(--r-2);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(122, 168, 255, 0.14), transparent);
  animation: skeleton-sweep 1.4s infinite;
}
@keyframes skeleton-sweep { to { transform: translateX(100%); } }

/* ── 滚动条：暗色细条，不喧宾夺主 ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(122, 168, 255, 0.24);
  border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover { background: rgba(122, 168, 255, 0.42); }

/* ── 按钮：全局基础样式，各页只做尺寸变体 ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px; /* 触摸目标 ≥44px */
  padding: 0 var(--sp-5);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-2);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: background var(--dur-fast) ease-out,
              border-color var(--dur-fast) ease-out,
              transform var(--dur-fast) ease-out,
              box-shadow var(--dur-fast) ease-out;
}
.btn:hover:not(:disabled) {
  background: var(--c-surface-3);
  border-color: var(--c-line-3);
  transform: translateY(-1px);
  box-shadow: var(--sh-1);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(180deg, var(--c-brand) 0%, var(--c-brand-deep) 100%);
  border-color: var(--c-brand-2);
  color: #fff;
  font-weight: 600;
}
.btn--primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--c-brand-2) 0%, var(--c-brand) 100%);
  box-shadow: var(--sh-glow);
}
.btn--ghost { background: transparent; border-color: var(--c-line); color: var(--c-text-2); }
.btn--ghost:hover:not(:disabled) { border-color: var(--c-line-3); color: var(--c-text); }
.btn--danger { border-color: rgba(255, 95, 95, 0.45); color: #FFB4B4; }
.btn--danger:hover:not(:disabled) { background: rgba(255, 95, 95, 0.14); border-color: var(--c-danger); }

/* ── 表单控件 ── */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field__label { font-size: var(--fs-xs); letter-spacing: 0.08em; color: var(--c-muted); }
.field__hint { font-size: var(--fs-2xs); color: var(--c-dim); }
.field__error { font-size: var(--fs-xs); color: var(--c-danger); min-height: 1.2em; }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-2);
  background: rgba(4, 8, 15, 0.6);
  color: var(--c-text);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur-fast) ease-out, box-shadow var(--dur-fast) ease-out;
}
.input::placeholder, .textarea::placeholder { color: var(--c-dim); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-line-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-brand-2);
  box-shadow: 0 0 0 3px rgba(46, 123, 255, 0.18);
}
.input[aria-invalid='true'] { border-color: var(--c-danger); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.select { appearance: none; cursor: pointer; padding-right: var(--sp-6); }

/* 自定义下拉箭头（原生箭头在暗色下几乎看不见） */
.select-wrap { position: relative; }
.select-wrap::after {
  content: '';
  position: absolute;
  right: var(--sp-4);
  top: 50%;
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--c-brand-3);
  border-bottom: 1.5px solid var(--c-brand-3);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* 复选框：44px 触摸区靠 padding 撑，视觉方块保持 18px */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  cursor: pointer;
  font-size: var(--fs-sm);
}
.checkbox input { width: 18px; height: 18px; accent-color: var(--c-brand); cursor: pointer; }

/* ── 提示条 ── */
.toast-host {
  position: fixed;
  top: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-3);
  background: var(--c-surface-2);
  box-shadow: var(--sh-2);
  font-size: var(--fs-sm);
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast--ok { border-color: rgba(34, 192, 138, 0.5); }
.toast--err { border-color: rgba(255, 95, 95, 0.55); }
.toast__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-brand-2); }
.toast--ok .toast__dot { background: var(--c-down); }
.toast--err .toast__dot { background: var(--c-danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: none; }
}

/* ── 动效降级：用户要求减少动效时全部关掉 ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
  .skeleton::after { animation: none; }
}
