/* 全站基础样式（WP-0.2）：重置、排版、链接与焦点、表单控件的基本高度与字号、通用工具类。
   只用浅色、系统字体；禁止 :has()、subgrid；整页不得横向滚动（架构第 10 节）。 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--ui-ground);
}

body {
  margin: 0;
  min-width: 0;
  color: var(--ui-ink);
  background: var(--ui-ground);
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-body);
  line-height: 1.6;
  /* 折行（界面规范 二.15）：正文用浏览器默认的中文折行（行尾填满，标点不放到行首、数字日期不拆）；
     只防最后一行只剩一两个字（pretty）。标题、按钮、标签这类短字另见下面的“短字只在标点处折”。
     text-wrap 会继承；不认识它的旧内核（钉钉安卓 U4）照常折行，不出错。 */
  overflow-wrap: break-word;
  text-wrap: pretty;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.04);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--ui-ink);
  line-height: 1.4;
  text-wrap: balance;
}

/* 短字只在标点、空格处折（界面规范 二.15）：标题、按钮、标签、表头、页签、字段标题、字段说明。
   这些字短，不该从词中间断开（“连续失 / 败”“删除 / 成员”）；整句比一行还长时 break-word 兜底照样能折。
   成段的正文不加：加了会每行在逗号处提前断、右边参差。 */
h1,
h2,
h3,
h4,
legend,
th,
button,
.ui-button,
.ui-badge,
.ui-tabs a,
.ui-field-label,
.ui-metric-label,
.ui-card-link,
.ui-menu-item,
.ui-dialog-title {
  word-break: keep-all;
}

h1 {
  font-size: var(--ui-font-title);
  font-weight: 700;
}

h2 {
  font-size: var(--ui-font-card-title);
  font-weight: 700;
}

h3 {
  font-size: 15px;
  font-weight: 700;
}

p {
  margin: 0;
}

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

img {
  height: auto;
}

a {
  color: var(--ui-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

hr {
  height: 0;
  margin: var(--ui-gap-card) 0;
  border: 0;
  border-top: 1px solid var(--ui-line);
}

pre,
code,
kbd {
  font-family: var(--ui-font-mono);
  font-size: 0.92em;
}

pre {
  max-width: 100%;
  margin: 0;
  overflow-x: auto; /* 格子里的代码块是允许横向滑动的两处之一（界面规范 五） */
  white-space: pre-wrap;
}

table {
  border-collapse: collapse;
}

[hidden] {
  display: none !important;
}

/* 焦点：键盘操作时清楚可见 */
:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 1px;
}

/* 表单控件：字号随令牌（手机 16px 防 iOS 放大），高度随站点 */
button,
input,
select,
textarea {
  margin: 0;
  color: inherit;
  font: inherit;
  font-size: var(--ui-font-input);
}

/* 选择器只用元素名（特异性最低），组件的类可以覆盖；勾选框、单选、文件框在下面复位 */
input,
select,
textarea {
  width: 100%;
  min-height: var(--ui-control);
  padding: 0 12px;
  border: 1px solid var(--ui-line-strong);
  border-radius: var(--ui-radius-control);
  background: var(--ui-surface);
  color: var(--ui-ink);
  line-height: 1.4;
}

/* 单行的框（文字、数字、日期、下拉）一律同高：管理端 40、学员 / 平台 / 办公 44（界面规范 二.1、二.16）。
   用 :where() 不加特异性，组件的类（小筛选 32px 等）照样能改。 */
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]), select:not([multiple]):not([size])) {
  height: var(--ui-control);
}
textarea {
  min-height: calc(var(--ui-control) * 2.5);
  padding: 10px 12px;
  line-height: 1.6;
  resize: vertical;
}

select {
  padding-right: 32px;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  border-color: var(--ui-primary);
  outline: 3px solid var(--ui-focus);
  outline-offset: 0;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  accent-color: var(--ui-primary);
}

input[type="file"],
input[type="range"],
input[type="color"] {
  width: auto;
  /* 自然宽度（文件框是“选择文件 + 文件名”）不许比所在容器宽，否则窄屏整页横向滚动 */
  max-width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
}

/* 没走 file_pick 组件的原生文件框：“选择文件”是描边小按钮，不用浏览器自带的灰按钮（界面规范 二.11） */
input[type="file"]::file-selector-button {
  min-height: var(--ui-control-sm);
  margin-right: 12px;
  padding: 0 12px;
  border: 1px solid var(--ui-line-strong);
  border-radius: var(--ui-radius-control);
  background: var(--ui-surface);
  color: var(--ui-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* 原生文件框作为网格或弹性布局子项时，也允许收缩到父容器。 */
input[type="file"] {
  min-width: 0;
}

input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

::placeholder {
  color: var(--ui-faint);
}

/* 只给读屏软件的文字 */
.ui-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 跳到正文（键盘用户） */
.ui-skip {
  position: absolute;
  top: -100px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--ui-radius-control);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-pop);
}

.ui-skip:focus {
  top: 8px;
}

/* 常用文字工具类 */
.ui-muted {
  color: var(--ui-muted);
}

.ui-note {
  color: var(--ui-muted);
  font-size: var(--ui-font-note);
  line-height: 1.6;
}

.ui-num {
  font-variant-numeric: tabular-nums;
}

.ui-nowrap {
  white-space: nowrap;
}

.ui-text-danger {
  color: var(--ui-danger);
}

.ui-text-warn {
  color: var(--ui-warn);
}

.ui-text-success {
  color: var(--ui-success);
}

/* 标签与状态不从中间断开（界面规范 五） */
.ui-keep {
  white-space: nowrap;
}

/* 竖排与横排的通用堆叠 */
.ui-stack {
  display: flex;
  flex-direction: column;
  gap: var(--ui-gap-section);
  min-width: 0;
}

.ui-stack-tight {
  display: flex;
  flex-direction: column;
  gap: var(--ui-gap-control);
  min-width: 0;
}

.ui-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ui-gap-control);
  min-width: 0;
}

.ui-grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: start;
  gap: var(--ui-gap-section);
}

@media (max-width: 1100px) {
  .ui-grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
