/* style.css — Manufacturing Quality Inspector Manual (20-chapter, text nav) */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #1f2a37;
  --muted: #5b6b7b;
  --line: #e2e8f0;
  --brand: #1f5fbf;
  --brand-d: #15468f;
  --accent: #0f766e;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background-color: var(--brand-d);
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-d) 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; color: #fff; letter-spacing: .2px; }
.brand:hover { text-decoration: none; color: #eaf2ff; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.btn-home, .btn-mail {
  background: rgba(255, 255, 255, .15); color: #fff;
  padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
}
.btn-home:hover, .btn-mail:hover { background: rgba(255, 255, 255, .28); text-decoration: none; }
.lang { position: relative; }
.lang-label { font-size: 13px; color: #dbe7ff; margin-right: 4px; }
.lang-opts { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.lang-opt {
  border: 1px solid rgba(255, 255, 255, .35); background: transparent; color: #fff;
  font-size: 12px; padding: 4px 8px; border-radius: 7px; cursor: pointer;
}
.lang-opt:hover { background: rgba(255, 255, 255, .2); }
.lang-opt.active { background: #fff; color: var(--brand-d); font-weight: 700; border-color: #fff; }

/* ---------- Chapter navigation (text labels, no numbers) ---------- */
.chapnav {
  position: sticky; top: 52px; z-index: 40;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.chapnav-inner {
  max-width: 1180px; margin: 0 auto; padding: 8px 14px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin;
}
.chip {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 999px;
  background: #eef2f7; color: var(--muted); font-size: 13px; font-weight: 600;
  white-space: nowrap; border: 1px solid transparent;
}
.chip:hover { text-decoration: none; background: #e2eaf3; color: var(--ink); }
.chip.active { background: var(--brand); color: #fff; box-shadow: var(--shadow); }

/* ---------- Layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 24px 18px 64px; }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 14px 0 6px; }
.hero h1 { font-size: 28px; margin: 0 0 6px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 820px; }
.intro {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin: 18px 0; box-shadow: var(--shadow);
}
.intro p { margin: 0; color: var(--ink); }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px;
  margin: 18px 0;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease;
  display: block; color: inherit;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15, 23, 42, .12); text-decoration: none; }
.card .icon { font-size: 26px; }
.card-tag {
  display: inline-block; margin: 8px 0 4px; font-size: 12px; font-weight: 700;
  color: var(--brand-d); background: #eaf2ff; padding: 2px 8px; border-radius: 6px;
}
.card h3 { margin: 6px 0 0; font-size: 15px; line-height: 1.4; }

.howto {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-top: 22px; box-shadow: var(--shadow);
}
.howto h2 { margin: 0 0 10px; font-size: 18px; }
.howto ol { margin: 0; padding-left: 20px; }
.howto li { margin: 6px 0; color: var(--ink); }

/* ---------- Chapter page ---------- */
.page-head { margin-bottom: 10px; }
.ch-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: var(--brand-d);
  background: #eaf2ff; padding: 4px 10px; border-radius: 8px; margin-bottom: 8px;
}
.page-head h1 { font-size: 26px; margin: 4px 0 0; }
.ch-intro {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin: 12px 0; box-shadow: var(--shadow);
}
.ch-intro p { margin: 0; }

/* ---------- Section sub-nav ---------- */
.secnav {
  position: sticky; top: 100px; z-index: 30;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: #f0f4f9; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin: 14px 0;
}
.secnav-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-right: 4px; }
.secnav a {
  font-size: 13px; font-weight: 600; color: var(--brand-d);
  background: #fff; border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px;
}
.secnav a:hover { text-decoration: none; background: var(--brand); color: #fff; border-color: var(--brand); }

.csection {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin: 16px 0; box-shadow: var(--shadow); scroll-margin-top: 150px;
}
.csection h2 { margin: 0 0 12px; font-size: 19px; border-left: 4px solid var(--brand); padding-left: 10px; }
.csection h3 { margin: 16px 0 6px; font-size: 16px; color: var(--brand-d); }
.csection p { margin: 8px 0; }
.csection ul, .csection ol { margin: 8px 0; padding-left: 22px; }
.csection li { margin: 5px 0; }

/* ---------- Note callouts ---------- */
.note {
  background: var(--warn-bg); border: 1px solid #fde2c0; border-left: 4px solid var(--warn);
  border-radius: 8px; padding: 10px 14px; margin: 12px 0; color: #7c3a06; font-size: 14px;
}

/* ---------- Figure ---------- */
.fig { margin: 18px 0; text-align: center; }
.fig-svg {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; box-shadow: var(--shadow);
}
.figsvg {
  width: 100%; max-width: 520px; height: auto; display: block; margin: 0 auto;
  stroke: var(--brand-d); stroke-width: 2; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.figsvg text { stroke: none; fill: var(--ink); font-size: 12px; font-family: inherit; }
.figsvg rect, .figsvg circle, .figsvg polygon, .figsvg polyline, .figsvg path, .figsvg line {
  vector-effect: non-scaling-stroke;
}
.fig-box {
  display: flex; align-items: center; justify-content: center;
  min-height: 130px; background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 10px, #eef2f7 10px, #eef2f7 20px);
  border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-weight: 600;
}
.fig-box span { background: rgba(255,255,255,.7); padding: 6px 12px; border-radius: 6px; }
.fig figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; }
.fig-label { color: var(--brand-d); font-weight: 700; }
.fig.anim .fig-svg { background: linear-gradient(135deg, #fbfdff, #f1f6fd); border-color: var(--brand); }
.fig.anim .fig-svg:before { content: ""; }
.fig.anim figcaption:before {
  content: "▶ "; color: var(--brand); font-weight: 700;
}
.qr { display: block; margin: 0 auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr rect { fill: var(--ink); }

/* ---------- Queryable table ---------- */
.itable-wrap { margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.itable-filter { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f7fafc; }
.itable-filter span { font-size: 13px; color: var(--muted); font-weight: 600; }
.itable-input { flex: 1; max-width: 280px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; }
.itable-scroll { overflow-x: auto; }
table.itable { border-collapse: collapse; width: 100%; font-size: 14px; }
table.itable th, table.itable td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; }
table.itable th { background: #eef2f7; color: var(--brand-d); font-weight: 700; position: sticky; top: 0; }
table.itable tbody tr:hover { background: #f7fafc; }

/* ---------- Calculator ---------- */
.calc {
  background: #f3f8ff; border: 1px solid #cfe0fb; border-radius: 12px;
  padding: 16px 18px; margin: 14px 0; box-shadow: var(--shadow);
}
.calc-title { font-weight: 700; color: var(--brand-d); margin-bottom: 10px; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.calc-field { display: flex; flex-direction: column; gap: 4px; }
.calc-field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.calc-unit { color: var(--brand); font-weight: 700; }
.calc-field input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; }
.calc-btn {
  margin-top: 12px; background: var(--brand); color: #fff; border: 0;
  padding: 9px 18px; border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.calc-btn:hover { background: var(--brand-d); }
.calc-result { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.calc-line {
  display: flex; justify-content: space-between; gap: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}
.calc-line b { color: var(--accent); font-variant-numeric: tabular-nums; }
.calc-empty { color: var(--muted); font-size: 14px; }
.calc-note { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 30px; }
.footer-inner { max-width: 1180px; margin: 0 auto; padding: 16px 18px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.footer-inner span { color: var(--muted); font-size: 13px; }
.footer-home { font-size: 13px; font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { top: 0; }
  .chapnav { top: 0; }
  .secnav { top: 0; position: static; }
  .hero h1 { font-size: 22px; }
  .page-head h1 { font-size: 22px; }
  main { padding: 16px 12px 48px; }
  .grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
}
