/* components.css — 卡片 / 按钮 / 输入 / 徽章 / 表格 / 提示 */

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-flat { box-shadow: none; }
.card-pad-lg { padding: 28px; }

.card-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 14px;
}
.card-title h3 { margin: 0; }
.card-title .tag { margin-left: auto; }

/* 模块入口卡（首页） */
.tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  color: var(--ink);
  transition: transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.tile:hover {
  text-decoration: none;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.tile-icon {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--accent);
}
.tile-icon svg { width: 22px; height: 22px; }
.tile h3 { margin: 2px 0 0; font-size: 1rem; }
.tile p { margin: 0; color: var(--ink-mute); font-size: var(--fs-small); line-height: 1.6; }
.tile-meta {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  min-height: 38px;
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.btn:hover {
  border-color: var(--ink-faint);
  background: var(--bg-sunken);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--bg-sunken); border-color: var(--line); }

.btn-sm { padding: 6px 11px; min-height: 32px; font-size: var(--fs-tiny); }
.btn-icon {
  padding: 0;
  width: 36px; height: 36px;
  min-height: 36px;
  border-radius: var(--r-md);
}
.btn-icon.btn-sm { width: 30px; height: 30px; min-height: 30px; }
.btn-icon svg { width: 17px; height: 17px; }

.btn-group {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-raised);
}
.btn-group .btn {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: transparent;
}
.btn-group .btn:last-child { border-right: 0; }
.btn-group .btn[aria-pressed="true"] {
  background: var(--re-soft);
  color: var(--re);
  font-weight: 600;
}

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label {
  font-size: var(--fs-tiny);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
  text-transform: uppercase;
  font-family: var(--mono);
}
.hint { font-size: var(--fs-tiny); color: var(--ink-faint); line-height: 1.5; }

.input, .select, textarea.input {
  width: 100%;
  padding: 9px 12px;
  min-height: 38px;
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--ink-faint); }
.input:hover, .select:hover { border-color: var(--ink-faint); }
.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--re-soft);
}
.input[aria-invalid="true"] {
  border-color: var(--warn);
  background: var(--warn-soft);
}
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--warn-soft); }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  font-family: var(--sans);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-mute) 50%),
    linear-gradient(135deg, var(--ink-mute) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) calc(50% + 1px),
    calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

textarea.input { min-height: 76px; resize: vertical; line-height: 1.6; }

/* 滑块 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-raised);
  box-shadow: var(--shadow-sm);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-raised);
}
input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* 复选 */
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-small);
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.check input {
  width: 16px; height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- 输出读数 ---------- */
.readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 14px;
  align-items: baseline;
  padding: 14px 16px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}
.readout dt { color: var(--ink-mute); font-size: var(--fs-tiny); letter-spacing: 0.04em; }
.readout dd { margin: 0; color: var(--ink); word-break: break-all; }
.readout dd.big { font-size: 1.05rem; font-weight: 600; }

.readout-list { display: flex; flex-direction: column; gap: 10px; }

/* 结果大字 */
.result-hero {
  padding: 22px 20px;
  background: var(--res-soft);
  border: 1px solid var(--res);
  border-radius: var(--r-lg);
  text-align: center;
}
.result-hero .value {
  font-family: var(--math);
  font-size: clamp(1.4rem, 4.5vw, 2.1rem);
  font-weight: 500;
  color: var(--res);
  line-height: 1.3;
  word-break: break-word;
}
.result-hero .caption {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  color: var(--ink-mute);
  letter-spacing: 0.05em;
}

/* ---------- 徽章 / 标签 ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.tag-re  { color: var(--re);  background: var(--re-soft);  border-color: transparent; }
.tag-im  { color: var(--im);  background: var(--im-soft);  border-color: transparent; }
.tag-res { color: var(--res); background: var(--res-soft); border-color: transparent; }
.tag-warn{ color: var(--warn);background: var(--warn-soft);border-color: transparent; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  color: var(--ink-soft);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
}

/* ---------- 表格 ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raised);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
table.data caption {
  padding: 12px 14px;
  text-align: left;
  color: var(--ink-mute);
  font-size: var(--fs-tiny);
  border-bottom: 1px solid var(--line);
}
table.data th, table.data td {
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data thead th {
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: var(--bg-sunken);
  white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--bg-sunken); }
table.data td.num, table.data th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* ---------- 提示条 ---------- */
.callout {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-faint);
  background: var(--bg-sunken);
  font-size: var(--fs-small);
  color: var(--ink-soft);
}
.callout-info { border-left-color: var(--re); background: var(--re-soft); border-color: transparent; }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.callout-res  { border-left-color: var(--res); background: var(--res-soft); border-color: transparent; }
.callout p { margin: 0; }
.callout p + p { margin-top: 6px; }
.callout-icon { flex: 0 0 auto; width: 18px; height: 18px; color: currentColor; opacity: 0.8; }

/* ---------- 首访欢迎气泡 ----------
 * 默认 hidden（渐进增强：无 JS 时永不显示）；ui.js 在首访时揭示并挂关闭。
 * 注意：组件设了 display 会复活 UA 的 [hidden]{display:none}，故显式防护。 */
.welcome {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 0 0 18px;
  padding: 13px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--bg-sunken);
  font-size: var(--fs-small);
  color: var(--ink-soft);
  animation: welcome-in var(--dur) var(--ease) both;
}
.welcome[hidden] { display: none; }
.welcome p { margin: 0; }
.welcome p + p { margin-top: 5px; }
.welcome b { color: var(--ink); }
.welcome-icon { flex: 0 0 auto; width: 20px; height: 20px; color: var(--accent); margin-top: 1px; }
.welcome-x {
  flex: 0 0 auto;
  margin-left: auto;
  align-self: center;
  min-width: 30px;
  min-height: 30px;
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--r-md);
}
.welcome-x:hover { color: var(--ink); background: var(--bg-raised); }
@keyframes welcome-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .welcome { animation: none; }
}

/* 错误提示 */
.error-text {
  display: none;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  color: var(--warn);
}
.error-text[data-show="true"] { display: flex; }

/* ---------- 代码块 ---------- */
pre.code {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  line-height: 1.7;
  color: var(--ink-soft);
}
code.inline {
  padding: 1px 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--im);
}

/* ---------- 步骤条 ---------- */
.steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  position: relative;
  padding: 0 0 18px 34px;
  counter-increment: step;
  font-size: var(--fs-small);
  color: var(--ink-soft);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 1px;
  width: 22px; height: 22px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  color: var(--accent);
  background: var(--re-soft);
  border-radius: 50%;
}
.steps li::after {
  content: "";
  position: absolute;
  left: 10.5px; top: 25px; bottom: 2px;
  width: 1px;
  background: var(--line);
}
.steps li:last-child { padding-bottom: 0; }
.steps li:last-child::after { display: none; }

/* ---------- 空态 / 载入 ---------- */
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-faint);
  font-size: var(--fs-small);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
}

[hidden] { display: none !important; }
