/* IMECA3D — Snap-Fit Calculator (loaded only on /snap-fit-calculator). Script: src/js/snap-fit.js */

.sf { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 28px; align-items: start; }

/* ---------- inputs ---------- */
.sf-form { padding: 28px; border-radius: 20px; background: var(--frost-bg); border: 1px solid var(--frost-border);
  box-shadow: var(--frost-shadow); -webkit-backdrop-filter: blur(14px) saturate(150%); backdrop-filter: blur(14px) saturate(150%); }
.sf-group { border: 0; padding: 0; margin: 0 0 26px; min-width: 0; }
.sf-group legend { display: flex; align-items: center; gap: 10px; padding: 0; margin-bottom: 14px;
  font-family: var(--font-head); font-size: 1.2rem; font-weight: 600; color: var(--text); }
.sf-n { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--dark); color: #fff; font-size: 0.85rem; }
.sf-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 14px; }
.sf-field label, .sf-label { font-size: 0.86rem; font-weight: 600; color: var(--text-2); }
.sf-label { margin: 2px 0 8px; }
.sf-field abbr { text-decoration: none; font-family: var(--font-head); color: var(--accent); margin-left: 2px; }
.sf-field select, .sf-unit input { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; font: inherit; font-size: 0.98rem; color: var(--text); }
.sf-field select:focus, .sf-unit input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194,65,12,0.15); }
.sf-unit { position: relative; display: block; }
.sf-unit input { padding-right: 44px; -moz-appearance: textfield; }
.sf-unit input::-webkit-outer-spin-button, .sf-unit input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sf-unit i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 0.85rem; color: var(--text-3); pointer-events: none; }
.sf-unit input[aria-invalid="true"] { border-color: #B91C1C; background: #FEF2F2; }
.sf-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; align-items: end; }
.sf-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sf-hint { margin: -4px 0 14px; font-size: 0.84rem; color: var(--text-3); line-height: 1.5; }

/* orientation cards */
.sf-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.sf-card { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; background: #fff;
  border: 1.5px solid var(--border); cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; }
.sf-card:hover { border-color: rgba(194,65,12,0.5); }
.sf-card input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sf-card strong { font-size: 0.92rem; color: var(--text); line-height: 1.25; }
.sf-card small { font-size: 0.78rem; color: var(--text-3); line-height: 1.35; }
.sf-card__ic { width: 64px; height: 40px; margin-bottom: 4px; }
.sf-ic-bed { fill: var(--light-2); }
.sf-ic-part { fill: var(--text-3); }
.sf-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194,65,12,0.14); }
.sf-card:has(input:checked) .sf-ic-part { fill: var(--accent); }
.sf-card:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

/* two-way switch */
.sf-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 12px; background: var(--light-2); }
.sf-seg label { position: relative; cursor: pointer; }
.sf-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sf-seg span { display: block; padding: 9px 10px; border-radius: 8px; text-align: center; font-size: 0.88rem; font-weight: 600; color: var(--text-2); transition: background 0.2s, color 0.2s; }
.sf-seg input:checked + span { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(11,27,46,0.12); }
.sf-seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

.sf-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sf-actions .sf-hint { margin: 0; flex: 1 1 200px; }

/* ---------- results ---------- */
.sf-out { position: sticky; top: calc(var(--nav-h) + 16px); display: flex; flex-direction: column; gap: 16px; padding: 24px; border-radius: 20px;
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow); scroll-margin-top: calc(var(--nav-h) + 16px); }

.sf-verdict { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 2px 12px; padding: 16px 18px; border-radius: 14px;
  background: var(--light); border-left: 5px solid var(--text-3); --sf-c: var(--text-3); }
.sf-verdict--pass { --sf-c: #15803D; background: #F0FDF4; }
.sf-verdict--marginal { --sf-c: #B45309; background: #FFFBEB; }
.sf-verdict--fail { --sf-c: #B91C1C; background: #FEF2F2; }
.sf-verdict { border-left-color: var(--sf-c); }
.sf-verdict__label { font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; color: var(--sf-c); }
.sf-verdict__pct { grid-row: span 2; font-family: var(--font-head); font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--sf-c); }
.sf-verdict__sub { font-size: 0.84rem; color: var(--text-2); }
.sf-meter { grid-column: 1 / -1; position: relative; height: 8px; margin-top: 10px; border-radius: 4px; background: rgba(11,27,46,0.08); overflow: hidden; }
.sf-meter > span { display: block; height: 100%; border-radius: 4px; background: var(--sf-c); transition: width 0.25s ease; }
.sf-meter i { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }

/* drawing */
.sf-draw svg { display: block; width: 100%; height: auto; border-radius: 12px; background: var(--light); }
.sf-arm { fill: #fff; }
.sf-arm-o { fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linejoin: round; }
.sf-lines line { stroke: rgba(91,107,125,0.35); stroke-width: 0.8; }
.sf-root { opacity: 0.35; }
.sf-wall { fill: var(--light-2); }
.sf-hatch { stroke: rgba(91,107,125,0.35); stroke-width: 1.2; }
.sf-defl { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: 5 4; }
.sf-fillet { fill: none; stroke: var(--accent); stroke-width: 1.4; }
.sf-d { stroke: var(--text-3); stroke-width: 1; color: var(--text-3); }
.sf-arrow { fill: var(--text-3); }
.sf-dt, .sf-at { font: 600 13px var(--font-body); fill: var(--text); }
.sf-at { fill: var(--accent); }
.sf-cap { font: 11px var(--font-body); fill: var(--text-3); }

/* numbers */
.sf-nums { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.sf-nums > div { padding: 10px 12px; border-radius: 10px; background: var(--light); }
.sf-nums dt { font-size: 0.76rem; color: var(--text-3); line-height: 1.3; }
.sf-nums dd { margin: 2px 0 0; font-family: var(--font-head); font-weight: 600; font-size: 1.02rem; color: var(--text); line-height: 1.3; }

.sf-panel h3 { margin-bottom: 8px; font-family: var(--font-head); font-size: 1rem; font-weight: 600; color: var(--text); }
.sf-panel ul { display: flex; flex-direction: column; gap: 6px; }
.sf-fix li, .sf-slicer li { position: relative; padding-left: 18px; font-size: 0.9rem; color: var(--text-2); line-height: 1.5; }
.sf-fix li::before, .sf-slicer li::before { content: ""; position: absolute; left: 2px; top: 0.6em; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }
.sf-check { display: flex; gap: 10px; font-size: 0.9rem; color: var(--text-2); line-height: 1.5; }
.sf-check__dot { flex: none; width: 10px; height: 10px; margin-top: 0.45em; border-radius: 50%; background: var(--text-3); }
.sf-check--ok .sf-check__dot { background: #15803D; }
.sf-check--info .sf-check__dot { background: #1D4ED8; }
.sf-check--warn .sf-check__dot { background: #B45309; }
.sf-check--bad .sf-check__dot { background: #B91C1C; }
.sf-note { font-size: 0.8rem; color: var(--text-3); line-height: 1.5; }
.sf-quote { align-self: flex-start; }

/* mobile result bar */
.sf-mini { display: none; }

/* ---------- explanation ---------- */
.sf-how__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 40px; margin: 28px 0; }
.sf-how__grid h3 { margin-bottom: 8px; font-family: var(--font-head); font-size: 1.1rem; font-weight: 600; }
.sf-how__grid p { margin-bottom: 10px; color: var(--text-2); }
.sf-formula { display: inline-block; padding: 8px 14px; border-radius: 8px; background: var(--light); font-family: var(--font-head); font-weight: 600; color: var(--text) !important; }
.sf-formula--inline { padding: 2px 8px; }
.sf-list { display: flex; flex-direction: column; gap: 4px; padding-left: 18px; list-style: disc; color: var(--text-2); }
.sf-how__limit { max-width: 900px; margin-bottom: 20px; }
.sf-ref-wrap { margin: 8px 0 20px; border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; background: #fff; }
.sf-ref-wrap summary { cursor: pointer; font-weight: 600; color: var(--text); }
.sf-ref-scroll { overflow-x: auto; margin: 14px 0 8px; }
.sf-ref { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 0.86rem; }
.sf-ref th, .sf-ref td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.sf-ref thead th { font-size: 0.76rem; color: var(--text-3); font-weight: 600; }
.sf-ref td:last-child { color: var(--text-3); }
.sf-how__more { color: var(--text-2); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .sf { grid-template-columns: 1fr; }
  .sf-out { position: static; }
  .sf-section .sf-mini { display: flex; }
  .sf-mini { position: fixed; left: 12px; right: 84px; bottom: 16px; z-index: 40; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 14px; border-radius: 12px; background: var(--dark); color: #fff; box-shadow: 0 6px 24px rgba(11,27,46,0.3); font-size: 0.88rem; }
  .sf-mini b { font-weight: 600; }
  .sf-mini a { color: var(--accent-bright); font-weight: 600; white-space: nowrap; }
  .sf-mini--pass b::before, .sf-mini--marginal b::before, .sf-mini--fail b::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; }
  .sf-mini--pass b::before { background: #4ADE80; }
  .sf-mini--marginal b::before { background: #FBBF24; }
  .sf-mini--fail b::before { background: #F87171; }
}
@media (max-width: 640px) {
  .sf-form, .sf-out { padding: 18px; }
  .sf-cards { grid-template-columns: 1fr; }
  .sf-card { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 12px; }
  .sf-card__ic { width: 48px; height: 30px; margin: 0; }
  .sf-card small { flex-basis: 100%; }
  .sf-row--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sf-how__grid { grid-template-columns: 1fr; }
  .sf-verdict__pct { font-size: 1.8rem; }
}

/* ---------- v2: section figure, extra rows ---------- */
.sf-sec { display: flex; align-items: center; gap: 14px; margin-top: -6px; padding: 10px 12px; border-radius: 12px; background: var(--light); }
.sf-sec__fig { flex: none; width: 150px; }
.sf-sec__fig svg { display: block; width: 100%; height: auto; }
.sf-sec__txt { margin: 0; font-size: 0.86rem; color: var(--text-2); line-height: 1.5; }
.sf-sec__txt strong { color: var(--text); }
.sf-sec__txt span { display: block; color: var(--text-3); font-size: 0.8rem; }
.sf-sec-solid { fill: #fff; }
.sf-sec-core { fill: var(--light-2); }
.sf-sec-hatch { stroke: rgba(91,107,125,0.45); stroke-width: 1; }
.sf-hum-row { margin-bottom: 14px; }
.sf-excluded { margin-top: 4px; }
@media (max-width: 640px) {
  .sf-sec { flex-direction: column; align-items: flex-start; }
}
.sf-form [hidden] { display: none !important; }
@media (max-width: 640px) {
  .sf-row:has(select) { grid-template-columns: 1fr; }
}

/* ---------- v2.1: sticky result, scale, meaning, change highlight, slicer effect, orientation pictures ---------- */
/* the result box scrolls with the page; the slim bar below takes over once it has gone */
.sf-out { position: static; }
.sf-section .sf-mini { display: none !important; }
.sf-bar { position: fixed; left: 0; right: 0; top: var(--nav-h); z-index: 99; background: var(--dark); color: #fff;
  border-top: 1px solid rgba(255,255,255,0.08); box-shadow: 0 6px 18px rgba(11,27,46,0.25);
  transform: translateY(-110%); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform 0.28s ease, opacity 0.2s ease, visibility 0s linear 0.28s; --sf-b: #94A3B8; }
.sf-bar--on { transform: none; opacity: 1; visibility: visible; pointer-events: auto; transition: transform 0.28s ease, opacity 0.2s ease; }
.sf-bar--pass { --sf-b: #4ADE80; }
.sf-bar--marginal { --sf-b: #FBBF24; }
.sf-bar--fail { --sf-b: #F87171; }
.sf-bar__in { display: flex; align-items: center; gap: 14px; min-height: 52px; padding-top: 8px; padding-bottom: 8px; }
.sf-bar__pct { white-space: nowrap; font-family: var(--font-head); font-size: 1.35rem; font-weight: 700; color: var(--sf-b); line-height: 1; }
.sf-bar__label { font-weight: 600; font-size: 0.92rem; white-space: nowrap; }
.sf-bar__meter { position: relative; flex: 0 0 140px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.15); overflow: hidden; }
.sf-bar__meter > span { display: block; height: 100%; background: var(--sf-b); transition: width 0.25s ease; }
.sf-bar__meter i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--dark); }
.sf-bar__keys { display: flex; gap: 14px; flex: 1 1 auto; min-width: 0; font-size: 0.82rem; color: rgba(255,255,255,0.75); overflow: hidden; }
.sf-bar__keys span { white-space: nowrap; }
.sf-bar__go { margin-left: auto; flex: none; color: var(--accent-bright); font-weight: 600; font-size: 0.86rem; white-space: nowrap; }
@media (max-width: 1100px) { .sf-bar__keys span:nth-child(n+2) { display: none; } }
@media (max-width: 760px) { .sf-bar__keys, .sf-bar__meter { display: none; } .sf-bar__in { min-height: 46px; gap: 10px; } .sf-bar__label { font-size: 0.85rem; white-space: normal; } }
@media (prefers-reduced-motion: reduce) { .sf-bar, .sf-bar--on { transition: none; } }
.sf-scale { grid-column: 1 / -1; position: relative; height: 16px; margin-top: 2px; font-size: 0.7rem; color: var(--text-3); }
.sf-scale b { position: absolute; top: 0; font-weight: 500; white-space: nowrap; transform: translateX(-50%); }
.sf-scale b:first-child { transform: none; }
.sf-scale b:nth-child(2) { transform: translateX(calc(-100% - 5px)); }
.sf-scale b:nth-child(3) { transform: translateX(5px); }
.sf-keys { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(11,27,46,0.08);
  font-size: 0.82rem; color: var(--text-2); }
.sf-keys span { white-space: nowrap; }
.sf-meaning { margin: -6px 0 0; font-size: 0.86rem; color: var(--text-2); line-height: 1.55; }
@keyframes sfFlash { from { background-color: rgba(240,122,46,0.28); } to { background-color: var(--light); } }
.sf-nums > .sf-chg { animation: sfFlash 1.4s ease-out; }
@keyframes sfPulse { from { box-shadow: 0 0 0 4px rgba(240,122,46,0.45), 0 8px 24px rgba(11,27,46,0.10); } to { box-shadow: 0 0 0 0 rgba(240,122,46,0), 0 8px 24px rgba(11,27,46,0.10); } }
.sf-verdict.sf-chg { animation: sfPulse 1.2s ease-out; }
.sf-effect { margin: -4px 0 14px; padding: 10px 12px; border-radius: 10px; background: #fff; border: 1px dashed var(--border);
  font-size: 0.84rem; color: var(--text-2); line-height: 1.5; }
.sf-effect::before { content: "→ "; color: var(--accent); font-weight: 700; }
.sf-orient-help { margin: -6px 0 16px; font-size: 0.86rem; }
.sf-orient-help summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.sf-iso { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.sf-iso figure { margin: 0; padding: 8px; border-radius: 10px; background: #fff; border: 1px solid var(--border); }
.sf-iso svg { display: block; width: 100%; height: 96px; }
.sf-iso figcaption { margin-top: 6px; font-size: 0.78rem; color: var(--text-2); line-height: 1.4; }
.sf-iso figcaption strong { display: block; color: var(--text); }
.sf-iso-bed { fill: var(--light-2); }
.sf-iso-top { fill: #FDBA74; stroke: #7C2D12; stroke-width: 0.7; }
.sf-iso-l { fill: #F97316; stroke: #7C2D12; stroke-width: 0.7; }
.sf-iso-r { fill: #C2410C; stroke: #7C2D12; stroke-width: 0.7; }
.sf-iso-ly { stroke: rgba(255,255,255,0.55); stroke-width: 0.8; }
.sf-iso-ar { stroke: var(--dark); stroke-width: 2.2; }
.sf-iso-arh { fill: var(--dark); }
@media (max-width: 640px) {
  .sf-iso { grid-template-columns: 1fr; }
  .sf-iso figure { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; }
  .sf-iso figcaption { margin: 0; }
}
@media (prefers-reduced-motion: reduce) { .sf-nums > .sf-chg, .sf-verdict.sf-chg { animation: none; } }
