/* components.css —— 公共组件：卡片 / 徽标 / 表格 / 表单 / 指标 / 进度条 / 提示条
   全部 p- 前缀。组件只消费传入的数据，不做业务判定。 */

/* ---------- 卡片 ---------- */
.p-card {
  background: var(--p-panel);
  border: 1px solid var(--p-line);
  border-radius: var(--p-radius);
  box-shadow: var(--p-shadow);
  padding: 12px 14px;
  margin: 0 0 12px;
}
.p-card--flat { box-shadow: none; }
.p-card__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.p-card__title { font-weight: 700; font-size: 14.5px; margin: 0; }
.p-card__desc { color: var(--p-muted); font-size: 12px; margin: 0; }
.p-card__tools { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.p-grid { display: grid; gap: 12px; }
.p-grid--2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.p-grid--3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.p-grid--4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------- 指标卡 ---------- */
.p-metric { background: #fff; border: 1px solid var(--p-line); border-radius: var(--p-radius); padding: 10px 12px; }
.p-metric__label { color: var(--p-muted); font-size: 12px; }
.p-metric__value { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.p-metric__unit { font-size: 12px; font-weight: 500; color: var(--p-muted); margin-left: 3px; }
.p-metric__note { color: var(--p-muted); font-size: 11.5px; margin-top: 2px; }
.p-metric.is-brand .p-metric__value { color: var(--p-brand); }
.p-metric.is-info .p-metric__value { color: var(--p-info); }
.p-metric.is-flat .p-metric__value { color: var(--p-muted); }

/* ---------- 徽标 ---------- */
.p-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11.5px;
  line-height: 1.7;
  border: 1px solid var(--p-line);
  background: #f9fafb;
  color: var(--p-ink-2);
  white-space: nowrap;
}
.p-badge.is-brand { background: #e8f2ec; border-color: #b7d7c3; color: var(--p-brand); }
.p-badge.is-info { background: #e8effd; border-color: #bfd3f8; color: var(--p-info); }
.p-badge.is-accent { background: #fdf1e3; border-color: #f0d3ab; color: var(--p-warn); }
.p-badge.is-muted { background: #f3f4f6; color: var(--p-muted); }
.p-badge.is-outline { background: #fff; }

/* ---------- 表格 ---------- */
.p-tablewrap { width: 100%; overflow-x: auto; }
.p-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.p-table th, .p-table td {
  border-bottom: 1px solid var(--p-line-2);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}
.p-table th { background: #fafbfc; color: var(--p-muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.p-table tbody tr:hover { background: #fcfdfe; }
.p-table td.p-num, .p-table th.p-num { text-align: right; font-variant-numeric: tabular-nums; }
.p-table--click tbody tr { cursor: pointer; }
.p-table__actions { white-space: nowrap; }

/* ---------- 键值定义列表 ---------- */
.p-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; }
.p-kv__k { color: var(--p-muted); white-space: nowrap; }
.p-kv__v { overflow-wrap: anywhere; }

/* ---------- 列表（现场页用卡片列表，不用宽表） ---------- */
.p-list { list-style: none; margin: 0; padding: 0; }
.p-list__item {
  border: 1px solid var(--p-line);
  border-radius: var(--p-radius-sm);
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #fff;
}
.p-list__row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.p-list__row--between { justify-content: space-between; }
.p-list__spacer { flex: 1 1 auto; }
.p-list__main { font-weight: 600; overflow-wrap: anywhere; }
.p-list__sub { color: var(--p-muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }

/* ---------- 表单 ---------- */
.p-field { margin-bottom: 10px; }
.p-field__label { display: block; font-size: 12.5px; color: var(--p-ink-2); margin-bottom: 4px; font-weight: 600; }
.p-input, .p-select, .p-textarea {
  width: 100%;
  border: 1px solid var(--p-line);
  border-radius: var(--p-radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--p-ink);
  background: #fff;
}
.p-input:focus, .p-select:focus, .p-textarea:focus { outline: 2px solid #cfe3d7; border-color: var(--p-brand-2); }
.p-input--code { font-family: var(--p-mono); font-size: 16px; letter-spacing: .04em; }
.p-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.p-inline > .p-field { flex: 1 1 160px; margin-bottom: 0; }
.p-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin: 0 12px 6px 0; }
.p-check input { width: 16px; height: 16px; }

.p-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--p-line);
  background: #fff;
  color: var(--p-ink-2);
  border-radius: var(--p-radius-sm);
  padding: 8px 13px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}
.p-btn:hover { border-color: var(--p-brand-2); }
.p-btn--primary { background: var(--p-brand); border-color: var(--p-brand); color: #fff; font-weight: 600; }
.p-btn--primary:hover { background: var(--p-brand-2); }
.p-btn--ghost { background: #fff; }
.p-btn--danger { color: var(--p-warn); border-color: #f0d3ab; background: #fdf8f2; }
.p-btn--sm { padding: 4px 9px; font-size: 12.5px; }
.p-btn--block { width: 100%; }
.p-btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 进度条 / 对比条 ---------- */
.p-bar { height: 8px; border-radius: 999px; background: #eceff2; overflow: hidden; }
.p-bar__fill { height: 100%; background: var(--p-brand-2); border-radius: 999px; }
.p-bar__fill.is-info { background: #3b82f6; }
.p-bar__fill.is-accent { background: #d97706; }
.p-bar__fill.is-muted { background: #9ca3af; }
.p-barcap { display: flex; justify-content: space-between; font-size: 12px; color: var(--p-muted); margin-top: 4px; }

/* ---------- 提示条 ---------- */
.p-note {
  border: 1px solid var(--p-line);
  border-left: 3px solid var(--p-muted);
  background: #fafbfc;
  border-radius: var(--p-radius-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--p-ink-2);
  margin: 0 0 10px;
}
.p-note--brand { border-left-color: var(--p-brand); background: #f3f8f5; }
.p-note--info { border-left-color: var(--p-info); background: #f4f7fe; }
.p-note--flat { border-left-color: #cbd5e1; }
.p-empty { text-align: center; color: var(--p-muted); padding: 18px 8px; font-size: 13px; }

/* DemoAPI 未就绪 / 接口错误：明确错误态，绝不伪造数据 */
.p-fail {
  border: 1px solid #f0d3ab;
  background: #fdf8f2;
  border-radius: var(--p-radius);
  padding: 14px;
  margin: 4px 0 12px;
}
.p-fail__title { font-weight: 700; color: var(--p-warn); margin-bottom: 6px; }
.p-fail__hint { font-size: 12.5px; color: var(--p-ink-2); }

/* ---------- 标签页 ---------- */
.p-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--p-line); margin-bottom: 10px; overflow-x: auto; }
.p-tabs__btn {
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  padding: 7px 10px;
  font-size: 13.5px;
  color: var(--p-muted);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.p-tabs__btn.is-active { color: var(--p-brand); border-bottom-color: var(--p-brand); font-weight: 600; }

/* ---------- 码块 ---------- */
.p-codeblock {
  font-family: var(--p-mono);
  font-size: 15px;
  letter-spacing: .06em;
  background: #f8fafc;
  border: 1px dashed var(--p-line);
  border-radius: var(--p-radius-sm);
  padding: 6px 8px;
  overflow-wrap: anywhere;
}

/* ---------- 扫码计数器（中性：只计数，不判定） ---------- */
.p-counter {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: #f3f8f5;
  border: 1px solid #b7d7c3;
  border-radius: var(--p-radius);
  padding: 10px 12px;
}
.p-counter__num { font-size: 26px; font-weight: 800; color: var(--p-brand); font-variant-numeric: tabular-nums; }
.p-counter__label { color: var(--p-ink-2); font-size: 13px; }
.p-counter__note { margin-left: auto; color: var(--p-muted); font-size: 11.5px; }

/* ---------- 扫码结果行（永远是成功态，无红/无弹窗） ---------- */
.p-saved { display: flex; align-items: center; gap: 6px; color: var(--p-brand); font-weight: 600; font-size: 13px; }

/* ---------- toast ---------- */
.p-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 22px;
  z-index: 60;
  background: #111827;
  color: #f9fafb;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .22);
  max-width: 92vw;
}

/* ---------- 弹层（原型只用于“新建/选择”表单） ---------- */
.p-modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; background: rgba(17, 24, 39, .38); }
.p-modal__panel {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 12px 12px 0 0;
  padding: 14px;
  max-height: 86vh;
  overflow: auto;
}
@media (min-width: 700px) {
  .p-modal { align-items: center; }
  .p-modal__panel { border-radius: 12px; }
}

/* ---------- 全宽滚动条友好 ---------- */
.p-scrollx { overflow-x: auto; }
