/* ===== ChemCalc 样式（独立一份；色板与科研导航站、Grapher、PDFTools 保持一致） =====
   本页主角是「输入行 + 结果表」：控件要密、表格要能横向滚动、同位素棒图要能拉宽。 */
:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-hover: #f0f2f5;
  --text: #2c3e50;
  --text-sub: #7f8c9b;
  --border: #e8ebef;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, .1);
  --accent-text: #fff;
  --danger: #e2544d;
  --ok: #2f9e5f;
  --shadow: 0 2px 8px rgba(30, 40, 60, .06);
  --bar-bg: #f7f8fa;
  --code-bg: #f4f6f9;
  --tag-bg: #eef2f7;
  --chart-bg: #ffffff;
  --chart-grid: #e6ecf2;
  --chart-peak: #2d70b3;
  --chart-peak-hi: #c74440;
  --chart-text: #64748b;
}

html[data-theme="dark"] {
  --bg: #060a17;
  --bg-card: #0d1424;
  --bg-hover: #1a2336;
  --text: #dce3ec;
  --text-sub: #8794a8;
  --border: #1e2a44;
  --accent: #4d94ff;
  --accent-soft: rgba(77, 148, 255, .16);
  --danger: #ff6b64;
  --ok: #4ade80;
  --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  --bar-bg: #0a1120;
  --code-bg: #101a30;
  --tag-bg: #16213a;
  --chart-bg: #0d1424;
  --chart-grid: #1d2941;
  --chart-peak: #5aa2f0;
  --chart-peak-hi: #ff7b74;
  --chart-text: #8794a8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .25s, color .25s;
}
body { font-variant-numeric: tabular-nums; }

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .back { color: var(--accent); text-decoration: none; font-size: 14px; white-space: nowrap; }
.topbar .back:hover { text-decoration: underline; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; flex: none; }
.brand-mark img { width: 24px; height: 24px; }
.brand-text h1 { font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text p { font-size: 12px; color: var(--text-sub); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-btn {
  border: none; background: var(--bg-card); color: var(--text-sub);
  padding: 6px 10px; font-size: 13px; cursor: pointer; text-decoration: none;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--accent); color: var(--accent-text); }

/* ===== 分区标签 ===== */
.chem { max-width: 1180px; margin: 0 auto; padding: 14px 16px 4px; }
.tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); margin-bottom: 12px;
  position: sticky; top: 55px; z-index: 40;
}
.tab {
  border: 1px solid transparent; background: transparent; color: var(--text-sub);
  border-radius: 8px; padding: 5px 12px; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  /* 分区导航在落地页里是真链接（<a>），默认下划线要摘掉，样式与主页的按钮一致 */
  text-decoration: none;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }

/* ===== 面板 ===== */
.panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.panel > h2 { font-size: 16px; margin-bottom: 10px; }
.panel[hidden] { display: none; }

/* ===== 输入行 ===== */
.fields { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
.field.grow { flex: 1 1 260px; }
.field > label { font-size: 12px; color: var(--text-sub); }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 14px; font-family: inherit; width: 100%;
}
.field textarea { min-height: 62px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 13px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field .mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.checks label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text); }
.checks input { accent-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--text-sub); margin: 8px 0 2px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; }
.warn { color: var(--danger); font-size: 12px; }

/* ===== 按钮 ===== */
.btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 13px; cursor: pointer; font-size: 13.5px;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-sm { padding: 2px 9px; font-size: 12px; border-radius: 6px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ===== 结果卡片 ===== */
.cards { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.card {
  flex: 1 1 150px; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px;
}
.card .k { font-size: 12px; color: var(--text-sub); }
.card .v { font-size: 19px; font-weight: 600; line-height: 1.3; word-break: break-all; }
.card .u { font-size: 12px; color: var(--text-sub); font-weight: 400; }
.card.hl .v { color: var(--accent); }

.sub { font-size: 14px; margin: 16px 0 6px; color: var(--text); font-weight: 600; }
.sub:first-child { margin-top: 12px; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 6px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 5px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th {
  background: var(--bar-bg); color: var(--text-sub); font-weight: 600; font-size: 12px;
  position: sticky; top: 0; z-index: 1;
}
table.data th:first-child, table.data td:first-child,
table.data th.left, table.data td.left { text-align: left; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data tr.dim td { color: var(--text-sub); }
table.data tr.best td { background: var(--accent-soft); }
/* 组成表的「残基合计 / 两端基团」两行：靠上边框和加粗和明细行分开 */
table.data tr.sum td { font-weight: 600; border-top: 1px solid var(--border); }
table.data td.bad { color: var(--danger); }
table.data td.good { color: var(--ok); }
table.data .mf { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.tall { max-height: 460px; overflow-y: auto; }
.count { font-size: 12px; color: var(--text-sub); margin: 4px 0 0; }

/* ===== 同位素图 ===== */
.chart-box { margin-top: 8px; background: var(--chart-bg); border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
canvas.chart { display: block; width: 100%; height: 300px; }

/* ===== 说明区 ===== */
.doc { max-width: 1180px; margin: 10px auto 40px; padding: 18px 20px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.doc h2 { font-size: 16px; margin: 18px 0 6px; }
.doc h2:first-child { margin-top: 0; }
.doc p { font-size: 14px; color: var(--text); margin-bottom: 8px; }
.doc ul, .doc ol { margin: 0 0 8px 20px; font-size: 14px; }
.doc li { margin-bottom: 5px; }
.doc li b { display: inline; }
.doc dl.faq dt { font-weight: 600; font-size: 14px; margin-top: 10px; }
.doc dl.faq dd { font-size: 14px; color: var(--text-sub); margin-left: 0; }
.doc .rel-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.doc .rel-links a {
  display: inline-block; padding: 4px 12px; background: var(--tag-bg);
  border-radius: 999px; color: var(--accent); text-decoration: none; font-size: 13px;
}
.doc .rel-links a:hover { background: var(--accent-soft); text-decoration: none; }
.doc .ver { font-size: 12px; color: var(--text-sub); border-top: 1px solid var(--border); padding-top: 10px; margin-top: 14px; }
/* 分区落地页（/chemcalc/<slug>.html）的说明区：首段是分区说明、隐私条与 CTA，其余沿用 .doc */
.landing-doc .lead { font-size: 15px; color: var(--text-sub); }
.landing-doc .landing-privacy { font-size: 13px; color: var(--text-sub); }
.landing-doc .landing-cta-row { margin: 10px 0 4px; }
.landing-doc .landing-body p { margin-bottom: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(12px);
  background: var(--text); color: var(--bg-card); padding: 8px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 90;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  /* 顶栏一行装不下（返回链接 + 品牌 + 登录位 + 主题 + 三语），换成两行：
     nowrap 时子项会被压到 min-content，语言按钮的文字不收缩 → 直接溢出屏幕外 */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .topbar .back { font-size: 13px; }
  .brand { flex: 1 1 auto; }
  .spacer { display: none; }
  .brand-text p { display: none; }
  .chem { padding: 10px 10px 0; }
  .tabs { position: static; }
  .panel { padding: 12px; }
  .card .v { font-size: 17px; }
  canvas.chart { height: 240px; }
}
