/* ==========================================================================
   Fixture Design Handbook - Global Stylesheet
   Engineering reference for jigs & fixtures. Self-contained, works offline.
   ========================================================================== */

:root {
  --navy: #16283c;
  --navy-2: #1f3a56;
  --steel: #2c5f8a;
  --blue: #1c6fb8;
  --accent: #e8a33d;
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #dde3ea;
  --text: #26313d;
  --muted: #5d6b7a;
  --ok: #2e7d4f;
  --warn: #b05a12;
  --bad: #b03a2e;
  --code-bg: #f0f3f7;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial,
    "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Noto Sans JP",
    "Noto Sans KR", "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

/* ---------- Top utility bar ---------- */
.topbar {
  background: var(--navy);
  color: #eaf1f8;
  font-size: 13.5px;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}
.topbar .brand {
  font-weight: 600;
  letter-spacing: .3px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand .gear { font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,.35);
  background: transparent;
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease;
}
.btn:hover { background: rgba(255,255,255,.14); }
.btn .ico { font-size: 14px; }

.lang-sel {
  background: var(--navy-2);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Site search ---------- */
.search-wrap { position: relative; }
.site-search {
  width: 190px;
  max-width: 46vw;
  padding: 6px 10px;
  font-size: 13px;
  color: #fff;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 6px;
  outline: none;
  transition: width .15s ease, background .15s ease;
}
.site-search::placeholder { color: rgba(255,255,255,.65); }
.site-search:focus {
  background: #fff;
  color: var(--text);
  width: 240px;
}
.search-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 260px;
  max-width: 340px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(20,40,60,.18);
  z-index: 300;
  overflow: hidden;
}
.search-panel a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  padding: 9px 12px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}
.search-panel a:last-child { border-bottom: none; }
.search-panel a:hover { background: var(--bg); color: var(--blue); }
.search-panel .sico { font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.search-panel .none { padding: 12px 14px; font-size: 13px; color: var(--muted); }

/* ---------- Main navigation ---------- */
.mainnav {
  background: var(--navy-2);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.mainnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0 8px;
}
.mainnav a {
  color: #cfe0f0;
  text-decoration: none;
  padding: 11px 13px;
  font-size: 14px;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.mainnav a.active { color: #fff; border-bottom-color: var(--accent); }

.nav-toggle {
  display: none;
  margin-left: auto;
  background: none;
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 15px;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 16px 40px; }

.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 6px; font-size: 28px; color: var(--navy); }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.lead { color: var(--muted); font-size: 16px; max-width: 78ch; margin: 0; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(20,40,60,.06);
}
.card h2, .card h3 { margin-top: 0; }
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 19px;
  color: var(--navy);
}
.card-title .num {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 7px;
  background: var(--navy);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}
.card-title .ico { font-size: 20px; }
.card p { margin: 6px 0; }
.card ul { margin: 6px 0; padding-left: 20px; }
.card li { margin: 4px 0; }

/* callout boxes */
.callout {
  border-left: 4px solid var(--blue);
  background: #eef5fc;
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin: 14px 0;
}
.callout.warn { border-color: var(--warn); background: #fdf3e5; }
.callout.ok { border-color: var(--ok); background: #ecf6f0; }
.callout.bad { border-color: var(--bad); background: #fbeeec; }
.callout .ct-title { font-weight: 700; display: block; margin-bottom: 4px; color: inherit; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 12px 0; }
table.tbl {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.tbl th, .tbl td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.tbl th { background: var(--navy); color: #fff; font-weight: 600; white-space: nowrap; }
.tbl tr:nth-child(even) td { background: #f7f9fb; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl caption { caption-side: top; text-align: left; font-weight: 600; padding-bottom: 6px; color: var(--navy); }

/* formulas */
.formula {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: "Cambria Math", Cambria, Georgia, "Times New Roman", serif;
  font-size: 15.5px;
  margin: 8px 0;
  overflow-x: auto;
}
.formula .lbl { font-family: inherit; font-weight: 700; color: var(--steel); }

/* input / calculator */
fieldset.calc {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  margin: 12px 0;
  padding: 12px 14px;
}
fieldset.calc legend { font-weight: 700; color: var(--navy); padding: 0 8px; }
.frow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px 12px; align-items: center; margin: 8px 0; }
.frow label { font-size: 14px; }
.frow input, .frow select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
  background: #fff;
}
.frow input:focus, .frow select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.frow .unit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.frow.full { grid-template-columns: 1fr auto; }

.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--steel); }

.result-box {
  border: 1px dashed var(--steel);
  background: #eef5fc;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 15px;
}
.result-box .big { font-size: 22px; font-weight: 700; color: var(--navy); }

.small { font-size: 13px; color: var(--muted); }
.eq-label { font-weight: 700; color: var(--steel); }

/* ---------- GD&T symbol SVG ---------- */
.gdtsym { width: 28px; height: 28px; vertical-align: middle; display: inline-block; }
.gdt-tbl td:first-child { text-align: center; width: 50px; }

/* ---------- accordion (power clamping) ---------- */
.acc details { margin: 6px 0; }
.acc summary { font-weight: 600; cursor: pointer; padding: 6px 0; color: var(--navy); }
.acc summary::-webkit-details-marker { color: var(--steel); }
.acc details p { margin: 4px 0 8px 22px; }

/* ---------- numbered steps (design cases) ---------- */
ol.steps { list-style: none; counter-reset: step; padding: 0; }
ol.steps li { counter-increment: step; padding: 4px 0 4px 32px; position: relative; }
ol.steps li::before { content: counter(step); position: absolute; left: 0; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 22px; }

/* ---------- inline SVG figures ---------- */
.fig { max-width: 100%; height: auto; display: block; margin: 10px 0; }

/* hero (home) */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--steel) 100%);
  color: #fff;
  border-radius: 14px;
  padding: 34px 30px;
  margin-bottom: 24px;
}
.hero h1 { margin: 0 0 10px; font-size: 32px; }
.hero p { margin: 6px 0; max-width: 75ch; color: #dbe7f3; font-size: 16px; }
.hero .chips { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
}

/* footer */
.footer {
  background: var(--navy);
  color: #b9c9da;
  margin-top: 30px;
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  justify-content: space-between;
  font-size: 13px;
}
.footer a { color: #d6e4f2; }
.footer .disc { max-width: 72ch; }

/* responsive nav */
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .mainnav-inner { padding: 6px 8px; }
  #navLinks {
    display: none;
    width: 100%;
    flex-direction: column;
    padding-bottom: 6px;
  }
  #navLinks.open { display: flex; }
  .mainnav a { border-bottom: none; border-left: 3px solid transparent; }
  .mainnav a.active { border-bottom: none; border-left-color: var(--accent); }
  .frow { grid-template-columns: 1fr; }
  .topbar-inner { flex-direction: column; align-items: stretch; gap: 6px; }
  .topbar-actions { justify-content: center; }
  .site-search { width: 100%; }
  .site-search:focus { width: 100%; }
}

/* narrower phones */
@media (max-width: 540px) {
  body { font-size: 15px; }
  .wrap { padding: 14px 10px 30px; }
  .page-head h1 { font-size: 22px; }
  .lead { font-size: 14px; }
  .card { padding: 12px 14px; }
  .card-title { font-size: 17px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .topbar-actions { flex-wrap: wrap; gap: 4px; }
  .topbar-actions .btn { font-size: 12px; padding: 4px 8px; }
  .search-wrap { width: 100%; }
  .search-panel { min-width: auto; max-width: 100%; right: 0; left: 0; }
  .hero h1 { font-size: 24px; }
  .chips { gap: 4px; }
  .chip { font-size: 12px; padding: 3px 10px; }
  .tbl-wrap { overflow-x: auto; }
  .tbl { font-size: 13px; }
  .formula { font-size: 14px; padding: 8px 12px; }
  .calc { padding: 12px; }
  .frow { grid-template-columns: 1fr; }
  .frow label { font-size: 13px; }
}

@media print {
  .topbar, .mainnav, .footer, .btn-primary, .lang-sel, .search-wrap,
  .nav-toggle, .btn { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .wrap { max-width: 100%; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .hero { background: #fff; color: #000; border: 1px solid #000; }
  .hero h1 { color: #000; }
  .hero p { color: #000; }
  .tbl th { background: #ddd; color: #000; }
  a { color: #000; text-decoration: none; }
  .page-head h1 { font-size: 18pt; }
  .crumb { display: none; }
  .callout { border: 1px solid #999; }
  .num { background: #ddd; color: #000; }
  .steps li { break-inside: avoid; }
  h2 { break-after: avoid; }
  img, svg { max-width: 100% !important; }
}

/* ---------- Theme toggle & favorites ---------- */
.fav-wrap { position: relative; }
.theme-btn, .fav-btn { min-width: 36px; justify-content: center; }
.fav-btn { font-size: 15px; line-height: 1; }
.fav-panel a { justify-content: space-between; }
.fav-panel .fav-item { border-bottom: 1px solid var(--line); }
.fav-panel .fav-note {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 8px;
  margin: 0 8px 8px;
  font-size: 12px;
}
.fav-panel .fav-note:focus { outline: none; border-color: var(--blue); }
.fav-panel .fav-note::placeholder { color: var(--muted); opacity: 1; }
.fav-panel .fav-x {
  color: var(--muted);
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 4px;
  flex: 0 0 auto;
}
.fav-panel .fav-x:hover { background: var(--bad); color: #fff; }
.fav-panel .fav-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  text-align: right;
}
.fav-panel .fav-clear {
  background: none;
  border: none;
  color: var(--bad);
  cursor: pointer;
  font-size: 12px;
}
.fav-panel .fav-clear:hover { text-decoration: underline; }

/* ---------- Dark theme ---------- */
html[data-theme="dark"] {
  --navy: #0e1a28;
  --navy-2: #173050;
  --steel: #3d74a6;
  --blue: #4a9fe0;
  --bg: #10151c;
  --card: #18202a;
  --line: #2a3644;
  --text: #dbe4ee;
  --muted: #93a3b3;
  --ok: #58b57e;
  --warn: #e0a15a;
  --bad: #e0705f;
  --code-bg: #1b2530;
}
html[data-theme="dark"] .topbar { background: #0a121c; }
html[data-theme="dark"] .mainnav { background: #0f1b29; }
html[data-theme="dark"] .footer { background: #0a121c; }
html[data-theme="dark"] .search-panel { background: var(--card); }
html[data-theme="dark"] .site-search:focus { color: var(--text); }
html[data-theme="dark"] .callout { background: #16222e; }
html[data-theme="dark"] .callout.warn { background: #2a2015; }
html[data-theme="dark"] .callout.ok { background: #12241b; }
html[data-theme="dark"] .callout.bad { background: #2a1714; }
html[data-theme="dark"] .tbl tr:nth-child(even) td { background: #141c26; }
html[data-theme="dark"] .tbl caption { color: var(--accent); }
html[data-theme="dark"] fieldset.calc { background: #141c26; }
html[data-theme="dark"] .frow input,
html[data-theme="dark"] .frow select {
  background: #1c2733;
  color: var(--text);
  border-color: var(--line);
}
html[data-theme="dark"] .frow select option { background: #1c2733; }
html[data-theme="dark"] .result-box { background: #16222e; }
html[data-theme="dark"] .result-box .big { color: var(--accent); }
html[data-theme="dark"] .code, html[data-theme="dark"] pre { background: #141c26; }
html[data-theme="dark"] .page-head .lead, html[data-theme="dark"] .crumb { color: var(--muted); }
