/* ==========================================================================
   base.css — 重置、排版基准、无障碍基线
   只放"元素级"规则；任何带类名的样式都属于 components/views 层。
   ========================================================================== */

@layer base {

/* ---------- 重置 ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
}

/* 中文标题：稍紧的行距 + 略轻的字重，避免"糊成一团" */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--leading-tight);
  font-weight: var(--weight-semi);
  color: var(--color-text);
  text-wrap: balance;
}
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

p { text-wrap: pretty; }

img, svg, video, canvas {
  display: block;
  max-width: 100%;
}

/* 数字统一用等宽数位：财务表格里数字必须"列对齐" */
/* 单独成类而非全局，避免中文数字混排时字距异常 */
:where(td, th, .num, input[type="number"], .font-mono) {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- 表单元素：统一继承字体，去掉浏览器默认外观 ---------- */
input, button, textarea, select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button { background: none; border: none; cursor: pointer; }

textarea {
  resize: vertical;
  font-family: inherit;
}

/* iOS 上 input 字号 <16px 会触发聚焦缩放，移动端单独放行 */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 767px) {
    input, select, textarea { font-size: 16px; }
  }
}

/* 去掉 number 输入框的上下微调箭头（密集表单里容易误触） */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* 日期选择器的指示图标跟随暗色主题 */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.55;
}
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* ---------- 链接 ---------- */
a {
  color: var(--color-primary);
  text-decoration: none;
  text-underline-offset: 2px;
}
a:hover { text-decoration: underline; }

/* ---------- 焦点可见性：只用键盘时才显示焦点环 ---------- */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ---------- 表格基准 ---------- */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

th, td { text-align: left; vertical-align: middle; }

/* ---------- 列表 ---------- */
ul, ol { list-style: none; padding: 0; }

/* ---------- 滚动条：细一点，与整体色调一致 ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-full);
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--color-text-subtle); background-clip: content-box; }

/* ---------- 无障碍：屏幕阅读器专用文本 ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 跳转到主内容（键盘用户） */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: var(--color-text-invert);
  border-radius: var(--radius-md);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--space-4); text-decoration: none; }

/* ---------- 尊重"减少动效"偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 打印：去掉导航与装饰，保留数据 ---------- */
@media print {
  :root { --color-bg: #fff; --color-surface: #fff; --color-border: #ccc; }
  .app-sidebar,
  .app-topbar,
  .app-tabbar,
  .toast-region,
  .no-print { display: none !important; }
  .app-main { padding: 0 !important; }
  .card { border: 1px solid #ddd !important; box-shadow: none !important; break-inside: avoid; }
  body { font-size: 12px; }
}

} /* end @layer base */
