/* ===========================================================================
   Base — reset / 排版原子 / 通用控件
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: var(--lh-base);
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;               /* 应用型布局：滚动交给内部容器 */
}

[hidden] { display: none !important; }

h1, h2, h3, h4, p, figure, blockquote, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a {
  color: inherit;
  text-decoration: none;
  text-underline-offset: 3px;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: not-allowed; }

svg { display: block; }
img { max-width: 100%; }

::selection {
  background: var(--paper-warm);
  color: var(--ink);
}

/* 焦点：只在键盘可见，朱砂细环 */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
  border-radius: 1px;
}

/* ---- 滚动条：细、无色，避免打断纸感 -------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--rule);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 6px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--rule-strong); background-clip: padding-box; }

/* ===========================================================================
   排版原子
   =========================================================================== */

.serif { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.01em; }
.mono  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* 档案标签：极小的全大写轨道字 */
.label {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  line-height: 1.4;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.muted { color: var(--ink-3); }

/* 点线引导：元信息表专用 */
.leader {
  flex: 1;
  min-width: 12px;
  border-bottom: 1px dotted var(--rule-strong);
  transform: translateY(-0.28em);
}

/* 朱砂印章：极少量使用 */
.seal-mark {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border: 1.5px solid var(--seal);
  border-radius: 1px;
  color: var(--seal);
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  background: transparent;
}

/* ===========================================================================
   按钮
   =========================================================================== */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-bd: var(--rule-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 38px;
  padding: 0 var(--s-4);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius);
  font-size: var(--t-base);
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background var(--d-instant) var(--ease-out),
              border-color var(--d-instant) var(--ease-out),
              color var(--d-instant) var(--ease-out),
              transform var(--d-instant) var(--ease-out);
}
.btn:hover { border-color: var(--ink-3); background: var(--paper-warm); }
.btn:active { transform: translateY(0.5px); }

.btn--primary {
  --btn-bg: var(--ink);
  --btn-fg: var(--paper-card);
  --btn-bd: var(--ink);
  font-weight: 500;
}
.btn--primary:hover { background: oklch(28% 0.014 72); border-color: oklch(28% 0.014 72); }

.btn--seal {
  --btn-bg: var(--seal);
  --btn-fg: oklch(98% 0.01 32);
  --btn-bd: var(--seal);
}
.btn--seal:hover { background: var(--seal-deep); border-color: var(--seal-deep); }

.btn--ghost { --btn-bd: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--paper-sunk); border-color: transparent; }

.btn--sm { min-height: 30px; padding: 0 var(--s-3); font-size: var(--t-sm); }
.btn--lg { min-height: 46px; padding: 0 var(--s-6); font-size: var(--t-base); }

.btn:disabled { opacity: 0.45; }

/* 图标按钮 */
.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  color: var(--ink-2);
  transition: background var(--d-instant) var(--ease-out), color var(--d-instant) var(--ease-out);
}
.icon-btn::before { content: ""; position: absolute; inset: -6px; }
.icon-btn:hover { background: var(--paper-sunk); color: var(--ink); }

/* ===========================================================================
   输入
   =========================================================================== */

.field {
  width: 100%;
  height: 40px;
  padding: 0 var(--s-3);
  background: var(--paper-card);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font-size: var(--t-base);
  color: var(--ink);
  transition: border-color var(--d-instant) var(--ease-out), box-shadow var(--d-instant) var(--ease-out);
}
.field::placeholder { color: var(--ink-3); }
.field:hover { border-color: var(--ink-4); }
.field:focus {
  border-color: var(--ink-2);
  box-shadow: 0 0 0 3px var(--paper-warm);
}
/* 已有边框与柔光环，不再叠加焦点描边 */
.field:focus-visible,
.palette__input input:focus-visible,
.f-search input:focus-visible { outline: none; }

textarea.field {
  height: auto;
  padding: var(--s-3);
  line-height: 1.75;
  resize: vertical;
}

select.field {
  appearance: none;
  padding-right: var(--s-8);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* ===========================================================================
   Toast
   =========================================================================== */

#toasts {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: var(--s-6);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  max-width: min(92vw, 480px);
  padding: 10px var(--s-4);
  background: var(--ink);
  color: oklch(96% 0.008 84);
  border-radius: var(--radius);
  font-size: var(--t-sm);
  line-height: 1.5;
  box-shadow: var(--shadow-float);
  animation: toast-in var(--d-base) var(--ease-out) both;
}
.toast[data-kind="bad"]  { background: oklch(38% 0.130 27); }
.toast[data-kind="good"] { background: var(--ink); }
.toast.is-out { animation: toast-out 150ms var(--ease-in) both; }
.toast__mark {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--seal);
  flex: none;
}
.toast button {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: var(--t-xs);
  opacity: 0.85;
  pointer-events: auto;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(4px); }
}

/* ===========================================================================
   遮罩 / 模态
   =========================================================================== */

.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: oklch(28% 0.02 80 / 0.28);
  animation: fade-in var(--d-quick) var(--ease-out) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: var(--z-palette);
  display: grid;
  place-items: center;
  padding: var(--s-4);
}
/* 弹窗自带的遮罩只负责压暗背景；若不归零，它会盖在弹窗之上，
   导致弹窗内的按钮点不动（点击落到 scrim 上被当成取消） */
.modal-wrap > .scrim { z-index: 0; }
.modal-wrap > .modal { z-index: 1; }

.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--paper-raise);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  animation: modal-in var(--d-base) var(--ease-out) both;
}
.modal--wide { width: min(760px, 100%); }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.995); }
  to   { opacity: 1; transform: none; }
}

.modal__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--rule);
}
.modal__title {
  font-family: var(--font-display);
  font-size: var(--t-lg);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-title);
}
.modal__body {
  padding: var(--s-5);
  overflow: auto;
  font-size: var(--t-base);
  line-height: var(--lh-base);
  color: var(--ink-2);
}
.modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

/* ===========================================================================
   通用小件
   =========================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 2px var(--s-1) 3px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  line-height: 1.45;
  letter-spacing: 0.01em;
  border: 1px solid var(--rule);
  border-radius: 1px;
  background: var(--paper-card);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag::before { content: "#"; opacity: 0.55; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 30px;
  padding: 0 var(--s-2) 0 var(--s-3);
  background: var(--paper-warm);
  border: 1px solid var(--rule-strong);
  border-radius: 1px;
  font-size: var(--t-sm);
  color: var(--ink);
  white-space: nowrap;
}
.chip button {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  color: var(--ink-3);
  font-size: 14px;
  line-height: 1;
}
.chip button:hover { color: var(--seal); }

/* 骨架 */
.skel {
  background: linear-gradient(90deg, var(--paper-sunk) 0%, var(--paper-card) 50%, var(--paper-sunk) 100%);
  background-size: 240% 100%;
  animation: sheen 1.4s var(--ease-both) infinite;
  border-radius: 1px;
}
@keyframes sheen {
  from { background-position: 140% 0; }
  to   { background-position: -40% 0; }
}

/* 空状态 */
.empty {
  display: grid;
  place-items: center;
  gap: var(--s-3);
  padding: var(--s-12) var(--s-6);
  text-align: center;
}
.empty__title {
  font-family: var(--font-display);
  font-size: var(--t-md);
  letter-spacing: var(--ls-title);
  color: var(--ink-2);
}
.empty__hint {
  max-width: 34ch;
  font-size: var(--t-sm);
  line-height: var(--lh-base);
  color: var(--ink-3);
}
/* 空位标记：虚线空框，像档案盒上待填的签位 */
.empty__mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1;
  color: var(--ink-3);
}
.empty--col { padding: var(--s-8) var(--s-4); }

/* 键盘提示键帽 */
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: var(--paper-card);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  line-height: 1;
}

/* 屏幕阅读器专用 */
.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;
}

/* 分隔 */
.hr { height: 1px; background: var(--rule); border: 0; margin: var(--s-4) 0; }

/* 署名：像文件末尾的签署线，低调但不含糊 */
.credit {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  white-space: nowrap;
}
.credit::before {
  content: "";
  flex: none;
  width: 14px;
  height: 1px;
  background: var(--rule-strong);
}
.credit b {
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}

/* 状态点（文字始终存在，点仅辅助） */
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex: none;
  background: currentColor;
}
