/* ============================================================
   组件：卡片 / 分类 chips / 表单 / 按钮 / 结果 / 表格 / 折叠 / Toast
   ============================================================ */

/* ---------- 计算器卡片网格（首页） ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(224px, 1fr));
  gap: var(--sp-4);
}
.calc-card {
  display: block;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.calc-card:hover {
  border-color: #f2b8c1;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.calc-card .card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-size: var(--fs-15);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.calc-card .card-name {
  margin-top: var(--sp-3);
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--c-text);
}
.calc-card .card-desc {
  margin-top: 5px;
  /* 卡片描述是「内容」不是「注脚」：12px 中文在 1x 屏上笔画会糊成一团，
   * 提到 13px 并放宽行高，是这一屏观感提升最直接的一处。 */
  font-size: var(--fs-13);
  color: var(--c-text-3);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* 固定两行高度，使描述一行的卡片与两行的卡片等高，网格更整齐。
   * 数值与上面的 font-size / line-height 保持同一组系数，改字号时不会脱节。 */
  min-height: calc(var(--fs-13) * 1.6 * 2);
}

/* ---------- 面包屑 ---------- */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--fs-13);
  color: var(--c-text-3);
  margin-bottom: var(--sp-3);
}
.breadcrumb a { color: var(--c-text-2); }
.breadcrumb a:hover { color: var(--c-brand); }
.breadcrumb .sep { color: var(--c-border-strong); }

/* ---------- 计算器页标题 ---------- */
.calc-head { margin-bottom: var(--sp-5); }
.calc-head h1 {
  font-size: var(--fs-24);
  font-weight: 700;
  line-height: 1.35;
}
.calc-head .calc-desc {
  margin-top: 6px;
  color: var(--c-text-2);
  font-size: var(--fs-14);
}

/* ---------- 双栏布局 ---------- */
.calc-grid {
  display: grid;
  /* 输入栏给一个上界（不再让内容撑到 450），余下宽度全给结果区——
   * 结果区里的表格需要宽度，输入框不需要那么宽 */
  grid-template-columns: minmax(320px, 34%) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}
/* Grid 项默认最小尺寸 = min-content，会让表格的 overflow-x 滚动容器失效：
 * 窄屏下结果面板撑到表格宽度，整页横向溢出。置 0 后滚动条归属表格自身。 */
.calc-grid > * { min-width: 0; }
.panel, .form-host, .result-host, .table-frame, .table-wrap { min-width: 0; }

/* ---------- 面板卡片 ---------- */
.panel {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
}
.panel-title {
  font-size: var(--fs-15);
  font-weight: 700;
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

/* ---------- 表单字段 ---------- */
.field { margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--fs-13);
  color: var(--c-text-2);
  margin-bottom: 6px;
}
.field-label .label-hint { color: var(--c-text-3); font-size: var(--fs-12); }
.field-control { display: flex; }
.field-control input[type="number"],
.field-control input[type="text"],
.field-control input[type="date"],
.field-control input[type="time"],
.field-control select {
  width: 100%;
  height: var(--control-h);
  padding: 0 12px;
  font-size: var(--fs-15);
  color: var(--c-text);
  background: var(--c-bg);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field-control input:focus,
.field-control select:focus {
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px var(--c-brand-soft);
}
.field-control input.is-error,
.field-control select.is-error {
  border-color: var(--c-error);
  box-shadow: none;
}
.field-control.has-unit input,
.field-control.has-unit select {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}
.field-unit {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-strong);
  border-left: none;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--c-text-3);
  font-size: var(--fs-13);
  white-space: nowrap;
}
.field-error {
  margin-top: 5px;
  color: var(--c-error);
  /* 报错和参数说明都属于「必须看清才能用」的文字，与卡片描述统一 13px */
  font-size: var(--fs-13);
  line-height: 1.5;
}
.field-hint {
  margin-top: 5px;
  color: var(--c-text-3);
  font-size: var(--fs-13);
  line-height: 1.5;
}
select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 L6 8 L9.5 4.5' fill='none' stroke='%235b6570' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px !important;
}

/* ---------- 分段选择 ---------- */
.segmented {
  display: flex;
  background: var(--c-bg-track);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: var(--fs-13);
  color: var(--c-text-2);
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.segmented button.is-active {
  background: var(--c-bg);
  color: var(--c-brand);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  height: var(--control-h);
  padding: 0 18px;
  font-size: var(--fs-15);
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary {
  background: var(--c-brand);
  color: #fff;
}
.btn-primary:hover { background: var(--c-brand-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--c-bg);
  border-color: var(--c-border-strong);
  color: var(--c-text-2);
}
.btn-ghost:hover { border-color: var(--c-text-3); color: var(--c-text); }
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--fs-13); border-radius: var(--r-sm); }
.btn-icon {
  appearance: none;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  height: 30px;
  padding: 0 10px;
  font-size: var(--fs-12);
  color: var(--c-text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all .15s ease;
}
.btn-icon:hover { border-color: var(--c-border-strong); color: var(--c-text); }
.btn-icon svg { width: 14px; height: 14px; flex: none; }
.panel-tools { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; font-weight: 400; }
.form-actions {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
.form-actions .btn-primary { flex: 1; }

/* ---------- 结果区 ---------- */
.result-panel { min-height: 220px; }
.result-placeholder {
  color: var(--c-text-3);
  font-size: var(--fs-14);
  text-align: center;
  padding: var(--sp-12) 0;
}
.result-main {
  padding-bottom: var(--sp-4);
  border-bottom: 1px dashed var(--c-border);
  margin-bottom: var(--sp-4);
}
.result-main .result-label {
  color: var(--c-text-2);
  font-size: var(--fs-13);
}
.result-main .result-value {
  margin-top: 4px;
  font-family: var(--font-num);
  font-size: var(--fs-34);
  font-weight: 700;
  color: var(--c-brand);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.result-main .result-value .unit {
  font-size: var(--fs-15);
  font-weight: 400;
  color: var(--c-text-3);
  margin-left: 5px;
  font-family: var(--font);
}
.result-main .result-sub {
  margin-top: 4px;
  color: var(--c-text-3);
  font-size: var(--fs-13);
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2);
}
.result-stats.cols-3 { grid-template-columns: repeat(3, 1fr); }
.stat {
  background: var(--c-bg-subtle);
  border-radius: var(--r-md);
  padding: 10px 12px;
}
.stat .stat-label {
  /* 指标名要跟着数字一起被读，12px 太吃力，与卡片描述统一到 13px */
  font-size: var(--fs-13);
  color: var(--c-text-3);
}
.stat .stat-value {
  margin-top: 2px;
  font-size: var(--fs-16);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.stat .stat-value .unit {
  font-size: var(--fs-12);
  font-weight: 400;
  color: var(--c-text-3);
  margin-left: 3px;
}

/* ---------- 结果块（多组结果卡） ---------- */
.result-block { margin-bottom: var(--sp-4); }
.result-block:last-child { margin-bottom: 0; }
.result-view > * + * { margin-top: var(--sp-4); }
.result-block-title {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--c-text-2);
  margin-bottom: var(--sp-2);
}
/* 结果区内的散文与要点列表（如星座寓意、性格特质）。
 * base.css 把 ul 的圆点与缩进去掉了，这里按折叠面板的口径恢复。 */
.result-block p {
  color: var(--c-text-2);
  line-height: 1.8;
}
.result-block p + p { margin-top: var(--sp-2); }
.result-block ul {
  list-style: disc;
  padding-left: 1.2em;
  color: var(--c-text-2);
  line-height: 1.8;
}
.result-block li { margin-bottom: 3px; }
.result-block li:last-child { margin-bottom: 0; }

/* ---------- 表格 ---------- */
/* 表格横向可滚动时，在右侧压一层渐隐提示（窄屏表格普遍超出可视宽度） */
.table-frame { position: relative; }
.table-frame.is-scrollable::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  width: 42px;
  pointer-events: none;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), var(--c-bg) 88%);
}
.table-wrap {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
  min-width: 100%;
}
.data-table th {
  background: var(--c-bg-subtle);
  color: var(--c-text-3);
  font-weight: 500;
  font-size: var(--fs-12);
  text-align: left;
  padding: 9px 12px;
  white-space: nowrap;
  border-bottom: 1px solid var(--c-border);
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #eef0f2;
  color: var(--c-text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; }
.data-table th.num { text-align: right; }
.data-table tr.is-total td { font-weight: 700; background: var(--c-bg-subtle); }

/* ---------- 提示条 ---------- */
.notice {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: var(--fs-13);
  line-height: 1.6;
}
.notice-info { background: var(--c-bg-subtle); color: var(--c-text-2); }
.notice-warn { background: var(--c-warning-soft); color: #8a4b00; }
.notice-error { background: var(--c-error-soft); color: var(--c-error); }
.notice-ok { background: var(--c-success-soft); color: var(--c-success); }
.notice .notice-icon { flex: none; font-weight: 700; }
.notice + .notice { margin-top: var(--sp-2); }
.result-notices { margin-top: var(--sp-4); }

/* ---------- 折叠说明 ---------- */
.accordion {
  margin-top: var(--sp-5);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-bg);
}
.accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 14px var(--sp-5);
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--c-text-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  user-select: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 1.8px solid var(--c-text-3);
  border-bottom: 1.8px solid var(--c-text-3);
  transform: rotate(45deg);
  transition: transform .2s ease;
  flex: none;
  margin-top: -3px;
}
.accordion[open] summary::after { transform: rotate(-135deg); margin-top: 3px; }
.accordion .accordion-body {
  padding: 0 var(--sp-5) var(--sp-5);
  color: var(--c-text-2);
  font-size: var(--fs-13);
  line-height: 1.8;
}
.accordion .accordion-body p { margin-bottom: var(--sp-2); }
.accordion .accordion-body p:last-child { margin-bottom: 0; }
.accordion .accordion-body ul { list-style: disc; padding-left: 1.2em; margin: var(--sp-2) 0; }
.accordion .accordion-body li { margin-bottom: 3px; }
.accordion .accordion-body strong { color: var(--c-text); }

/* ---------- 相关计算器 ---------- */
.related {
  margin-top: var(--sp-6);
}
.related-title {
  font-size: var(--fs-14);
  font-weight: 700;
  margin-bottom: var(--sp-3);
}
.related-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.related-pill {
  border: 1px solid var(--c-border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: var(--fs-13);
  color: var(--c-text-2);
  background: var(--c-bg);
  transition: all .15s ease;
}
.related-pill:hover { border-color: #f2b8c1; color: var(--c-brand); }

/* ---------- 空状态 ---------- */
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-4);
}
.empty-title { font-size: var(--fs-16); font-weight: 600; }
.empty-sub { margin-top: 6px; color: var(--c-text-3); font-size: var(--fs-13); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%) translateY(8px);
  background: #1a1d21;
  color: #fff;
  font-size: var(--fs-13);
  padding: 10px 18px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 999;
  pointer-events: none;
  max-width: 84vw;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 计算器键盘（标准/科学） ---------- */
.calc-display {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  margin-bottom: var(--sp-3);
}
.expr-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
  font-family: var(--font-num);
  font-size: var(--fs-20);
  color: var(--c-text);
  padding: 6px 0;
}
.expr-input::placeholder { color: var(--c-text-3); font-family: var(--font); font-size: var(--fs-14); }
.expr-result {
  text-align: right;
  font-family: var(--font-num);
  font-size: var(--fs-14);
  color: var(--c-text-3);
  min-height: 20px;
}
.expr-result.is-ok { color: var(--c-brand); font-weight: 600; }
.expr-result.is-error { color: var(--c-error); font-family: var(--font); }
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}
.keypad + .keypad { margin-top: var(--sp-2); }
.keypad.fn-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: var(--sp-2); }
.calc-key {
  appearance: none;
  height: 46px;
  border: 1px solid var(--c-border);
  background: var(--c-bg);
  border-radius: var(--r-md);
  font-size: var(--fs-16);
  color: var(--c-text);
  cursor: pointer;
  transition: all .12s ease;
  font-family: var(--font-num);
}
.calc-key.fn { font-family: var(--font); font-size: var(--fs-14); color: var(--c-text-2); }
.calc-key:hover { border-color: var(--c-border-strong); background: var(--c-bg-subtle); }
.calc-key:active { transform: translateY(1px); }
.calc-key.op { color: var(--c-brand); font-weight: 600; }
.calc-key.eq { background: var(--c-brand); border-color: var(--c-brand); color: #fff; font-family: var(--font); }
.calc-key.eq:hover { background: var(--c-brand-hover); }
.calc-key.span3 { grid-column: span 3; }
.display-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.display-toolbar .display-label { font-size: var(--fs-13); color: var(--c-text-2); }
.segmented.segmented-sm { padding: 2px; }
.segmented.segmented-sm button { padding: 5px 12px; font-size: var(--fs-12); }
.examples { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.example-chip {
  appearance: none;
  border: 1px dashed var(--c-border-strong);
  background: var(--c-bg);
  color: var(--c-text-2);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: var(--fs-12);
  cursor: pointer;
  font-family: var(--font-num);
  transition: all .15s ease;
}
.example-chip:hover { border-color: var(--c-brand); border-style: solid; color: var(--c-brand); }

/* ---------- 大段说明 ---------- */
.calc-basis strong { color: var(--c-text); }
.formula {
  font-family: var(--font-num);
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 2px 7px;
  font-size: var(--fs-12);
  color: var(--c-text);
}

/* ---------- 数码工具：等宽结果框 / 颜色预览 ---------- */
.mono-box {
  font-family: var(--font-num);
  font-size: var(--fs-13);
  line-height: 1.75;
  color: var(--c-text);
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 10px var(--sp-3);
  word-break: break-all;
  overflow-wrap: anywhere;
}
.mono-box + .mono-box { margin-top: var(--sp-2); }

.color-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 88px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: var(--fs-15);
  font-weight: 600;
  letter-spacing: .04em;
  font-family: var(--font-num);
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.swatch { flex: 1 1 104px; min-width: 92px; }
.swatch-chip {
  height: 46px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
}
.swatch-name {
  margin-top: var(--sp-1);
  font-size: var(--fs-12);
  color: var(--c-text-3);
}
.swatch-val {
  font-family: var(--font-num);
  font-size: var(--fs-12);
  color: var(--c-text-2);
}

/* ---------- 回到顶部（滚动超过约 1.5 屏后淡入） ---------- */
.back-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  cursor: pointer;
  color: var(--c-text-2);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease, border-color .15s ease, color .15s ease;
}
.back-top.is-show { opacity: 1; pointer-events: auto; transform: none; }
.back-top:hover { border-color: var(--c-border-strong); color: var(--c-brand); }
.back-top svg { width: 18px; height: 18px; }

/* ---------- 响应式 ---------- */
@media (max-width: 960px) {
  .calc-grid { grid-template-columns: 1fr; }
  .result-panel { min-height: 0; }
}
@media (max-width: 720px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: var(--sp-2); }
  .calc-card { padding: var(--sp-3); }
  .calc-card .card-icon { width: 32px; height: 32px; font-size: var(--fs-13); }
  .calc-card .card-name { font-size: var(--fs-14); margin-top: 10px; }
  .calc-card .card-desc { display: none; }
  .panel { padding: var(--sp-4); }
  .result-main .result-value { font-size: var(--fs-28); }
  .result-stats, .result-stats.cols-3 { grid-template-columns: repeat(2, 1fr); }
  /* 防 iOS 聚焦缩放 */
  .field-control input, .field-control select { font-size: var(--fs-16); }
  .calc-head h1 { font-size: var(--fs-20); }
  .back-top { right: 14px; bottom: 14px; width: 38px; height: 38px; }
}

/* ---------- 打印：只留「输入参数 + 计算结果」 ---------- */
@media print {
  .site-header, .site-footer, .breadcrumb, .related, .back-top, .toast,
  .form-actions, .notice, .accordion, .panel-tools { display: none !important; }
  body { background: #fff; color: #000; }
  #app { padding: 0; }
  .container { max-width: none; padding: 0; }
  .calc-grid { display: block !important; }
  .panel {
    border: none;
    padding: 0;
    margin-bottom: var(--sp-6);
    break-inside: avoid;
  }
  .result-panel { min-height: 0; }
  .calc-head h1 { font-size: 20pt; }
  .result-main .result-value { font-size: 22pt; color: #000; }
  .table-frame.is-scrollable::after { display: none; }
  .table-wrap { overflow: visible !important; border-color: #999; }
  table.data-table { font-size: 9pt; }
  .data-table th { background: #f2f2f2 !important; color: #333 !important; }
  .result-block { break-inside: avoid; }
  a { text-decoration: none; color: #000; }
}
