/* =========================================================
   LabCTO · 基础层：设计令牌 / 重置 / 通用组件
   ========================================================= */

:root {
  color-scheme: light;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #ffffff;
  --bg-subtle: #f7f8fb;
  --bg-sunken: #eef1f7;
  --bg-elevated: #ffffff;
  --bg-inverse: #0b1220;

  --text: #0f172a;
  --text-soft: #334155;
  --text-muted: #5d6779;
  --text-faint: #8a93a6;

  --border: #e7e9f0;
  --border-strong: #d5d9e4;

  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --brand-soft: #eff4ff;
  --brand-ring: rgba(37, 99, 235, 0.18);
  --accent: #0891b2;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;

  /* AI 功能色：与品牌蓝分层，全站 AI 入口（顶栏 / 首页搜索 / 悬浮球 / 面板）共用 */
  --ai: #7c3aed;
  --ai-strong: #6d28d9;
  --ai-soft: rgba(124, 58, 237, 0.08);
  --ai-border: rgba(124, 58, 237, 0.26);
  --ai-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --ai-gradient-hover: linear-gradient(135deg, #5145e0 0%, #7c3aed 100%);

  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 26px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 8px -2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 12px 32px -16px rgba(15, 23, 42, 0.24);
  --shadow-lg: 0 30px 70px -30px rgba(15, 23, 42, 0.32);

  /* 间距刻度：4px 基准，一处改全局同步。
     页面里不要再写 22px / 26px / 30px 这类零散值，一律引用 s1~s9 */
  --s1: 4px;
  --s2: 6px;
  --s3: 8px;
  --s4: 12px;
  --s5: 16px;
  --s6: 20px;
  --s7: 24px;
  --s8: 32px;
  --s9: 44px;

  /* 语义化间距（页面级） */
  --gap-page: clamp(20px, 2.2vw, 28px);   /* 区块之间 */
  --pad-section: clamp(32px, 3.2vw, 46px); /* 板块内上下 */
  --pad-card: var(--s5);                   /* 卡片内 */
  --pad-x: clamp(18px, 2vw, 30px);         /* 版心左右 */

  --header-h: 56px;
  --content-max: 1440px;
  --content-wide: 1440px;
  --prose-max: 900px;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* 密度档：默认紧凑。需要更松弛时给 <body data-density="normal">，
   所有用语义间距变量的地方会一起放大，不用逐条改 */
[data-density="normal"] {
  --gap-page: clamp(26px, 2.8vw, 40px);
  --pad-section: clamp(44px, 4.6vw, 62px);
  --pad-card: var(--s6);
  --s9: 52px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0e16;
  --bg-subtle: #0e141f;
  --bg-sunken: #131a27;
  --bg-elevated: #111827;
  --bg-inverse: #f8fafc;

  --text: #e8edf7;
  --text-soft: #c3cbdb;
  --text-muted: #94a0b8;
  --text-faint: #6b778e;

  --border: #1e2737;
  --border-strong: #2b3648;

  --brand: #60a5fa;
  --brand-strong: #93c5fd;
  --brand-soft: rgba(96, 165, 250, 0.12);
  --brand-ring: rgba(96, 165, 250, 0.22);
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  --ai: #a78bfa;
  --ai-strong: #c4b5fd;
  --ai-soft: rgba(167, 139, 250, 0.14);
  --ai-border: rgba(167, 139, 250, 0.32);

  --shadow-sm: 0 2px 10px -2px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 16px 40px -20px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 40px 80px -40px rgba(0, 0, 0, 0.9);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 24px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--brand);
  text-decoration: none;
  transition: color 0.15s var(--ease);
}

a:hover {
  color: var(--brand-strong);
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--text);
}

p {
  margin: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

::selection {
  background: var(--brand-ring);
}

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

/* ---------- 图标 ---------- */
.icon {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
}

/* ---------- 布局 ---------- */
.container {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--pad-x);
}

.container--wide { max-width: var(--content-wide); }

.stack {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
}

.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }
.mono { font-family: var(--font-mono); }
.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;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  transition: all 0.18s var(--ease);
  background: transparent;
  color: var(--text-soft);
}

.btn:hover {
  color: var(--text);
}

.btn-primary {
  background: linear-gradient(180deg, #3b82f6 0%, var(--brand) 55%, var(--brand-strong) 100%);
  color: #fff;
  box-shadow: 0 1px 2px rgba(29, 78, 216, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -8px rgba(37, 99, 235, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .btn-primary {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 55%, #1d4ed8 100%);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.btn-ghost {
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-sunken);
  color: var(--text);
}

/* AI 入口按钮：紫色系，与品牌蓝按钮形成语义区分（顶栏「AI 助手」等） */
.btn-ai {
  color: var(--ai);
  border-color: var(--ai-border);
  background: var(--ai-soft);
}

.btn-ai:hover {
  color: var(--ai-strong);
  border-color: var(--ai);
  background: color-mix(in srgb, var(--ai) 14%, var(--bg-elevated));
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

[data-theme="dark"] .btn-danger {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-lg {
  height: 42px;
  padding: 0 20px;
  font-size: 15px;
  border-radius: 11px;
}

.btn-block { width: 100%; }

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

/* ---------- 表单 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.label {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-soft);
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.65;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a93a6' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-soft);
  cursor: pointer;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

/* ---------- 徽标 / 标签 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.badge-blue { background: var(--brand-soft); color: var(--brand); }
.badge-green { background: rgba(5, 150, 105, 0.1); color: var(--success); }
.badge-amber { background: rgba(217, 119, 6, 0.12); color: var(--warning); }
.badge-slate { background: var(--bg-sunken); color: var(--text-muted); }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-elevated);
}

/* ---------- 提示块 ---------- */
.callout {
  display: block;
  margin: 18px 0;
  padding: 12px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  background: var(--bg-subtle);
  font-size: 14.5px;
  color: var(--text-soft);
}

.callout__title {
  font-weight: 650;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.callout__body p:first-child { margin-top: 0; }
.callout__body p:last-child { margin-bottom: 0; }
.callout__body > p { margin: 8px 0; }

.callout--tip {
  border-left-color: var(--brand);
  background: var(--brand-soft);
}
.callout--tip .callout__title { color: var(--brand); }

.callout--info {
  border-left-color: var(--accent);
  background: rgba(8, 145, 178, 0.07);
}
.callout--info .callout__title { color: var(--accent); }

.callout--warning {
  border-left-color: var(--warning);
  background: rgba(217, 119, 6, 0.08);
}
.callout--warning .callout__title { color: var(--warning); }

.callout--danger {
  border-left-color: var(--danger);
  background: rgba(220, 38, 38, 0.07);
}
.callout--danger .callout__title { color: var(--danger); }

.callout--success {
  border-left-color: var(--success);
  background: rgba(5, 150, 105, 0.08);
}
.callout--success .callout__title { color: var(--success); }

/* ---------- 规范标准引用（下划虚线 + 悬浮 tips） ---------- */
.spec-ref {
  position: relative;
  color: var(--brand-strong);
  cursor: help;
  text-decoration: underline dotted var(--brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  border-radius: 2px;
  outline: none;
}
.spec-ref:hover,
.spec-ref:focus-visible {
  background: var(--brand-soft);
  text-decoration-style: solid;
}
.spec-ref::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(4px);
  width: min(340px, 78vw);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-inverse);
  color: var(--bg);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
  white-space: normal;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s var(--ease), transform 0.16s var(--ease);
  z-index: 60;
}
.spec-ref::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  transform: translateX(-50%) translateY(4px);
  border: 7px solid transparent;
  border-top-color: var(--bg-inverse);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s var(--ease), transform 0.16s var(--ease);
  z-index: 60;
}
.spec-ref:hover::after,
.spec-ref:hover::before,
.spec-ref:focus-visible::after,
.spec-ref:focus-visible::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
/* 首行与末行附近翻转，避免被裁切 */
.prose > :first-child .spec-ref::after { bottom: auto; top: calc(100% + 10px); }
.prose > :first-child .spec-ref::before { bottom: auto; top: calc(100% + 3px); border-top-color: transparent; border-bottom-color: var(--bg-inverse); }

/* ---------- 表格 ---------- */
.table-wrap {
  margin: 18px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 520px;
}

.table-wrap th {
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-wrap td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
  vertical-align: top;
}

.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap tbody tr:hover { background: var(--bg-subtle); }

/* ---------- 代码块 ---------- */
.code-block {
  margin: 18px 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0d1424;
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: var(--shadow-sm);
}

.code-block__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: rgba(148, 163, 184, 0.08);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.code-block__lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94a3b8;
}

.code-block__copy {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 5px;
}

.code-block__copy:hover {
  color: #e2e8f0;
  background: rgba(148, 163, 184, 0.12);
}

.code-block pre {
  margin: 0;
  padding: 14px 15px;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: #dbe4f3;
  white-space: pre;
}

/* ---------- 空状态 ---------- */
.empty {
  padding: 44px 20px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  background: var(--bg-subtle);
}

.empty .icon {
  width: 32px;
  height: 32px;
  color: var(--text-faint);
  margin-bottom: 10px;
}

/* ---------- 动效 ---------- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-soft {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 卡片（前后台通用） ---------- */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xs);
}

.card-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 13px var(--pad-card);
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  font-size: 13.5px;
  font-weight: 650;
}

.card-head .spacer { flex: 1; }

.card-body { padding: var(--pad-card); }
.card-body--flush { padding: 0; }

.card-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* ---------- 共享：提示条 / 表单网格 / 徽标变体 ---------- */
.flash {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: var(--bg-elevated);
}

.flash--success {
  border-color: rgba(5, 150, 105, 0.25);
  background: rgba(5, 150, 105, 0.07);
  color: var(--success);
}

.flash--error {
  border-color: rgba(220, 38, 38, 0.25);
  background: rgba(220, 38, 38, 0.06);
  color: var(--danger);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .full { grid-column: 1 / -1; }

.badge--soft {
  background: var(--bg-sunken);
  color: var(--text-soft);
  border: 1px solid var(--border);
}

.badge--ok { background: rgba(5, 150, 105, 0.1); color: var(--success); }
.badge--warn { background: rgba(217, 119, 6, 0.12); color: var(--warning); }

.card-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  padding: 12px var(--pad-card);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius) var(--radius);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-soft);
  line-height: 1.6;
  cursor: pointer;
}

.check input { margin-top: 3px; accent-color: var(--brand); }

.kv {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px 14px;
  margin: 0;
  font-size: 13px;
}

.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; color: var(--text-soft); }

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