/* ══════════════════════════════════════════════════════════════
   HEALTH CALCULATORS

   Pairs with template-parts/calculators/*.php and calculators.js.

   Written in the journal design language (assets/css/journal.css)
   rather than its own: the page shell is the shared one (.iw-phero,
   .iw-jsec, .iw-sec-head, .iw-jbtn), and every component here copies
   a pattern the theme already uses —

     form card        .iw-pform-card / .iw-auth-card
     labels, inputs   .iw-auth-field / .iw-auth-input
     tables           .iw-legal-table-wrap
     notes            .iw-legal-note
     sources          modules/sources (.iw-sources)
     eyebrows         .iw-label / .iw-article-card-cat
     disclaimer       the old BMI note

   Corners come from the journal radius tokens (4–6px), shadows are
   the restrained ones, and nothing is pill-round.

   Result tones carry meaning, so they are fixed colours, each dark
   enough for white text at AA contrast:
     info  blue   — informational / low
     ok    green  — healthy range
     warn  amber  — borderline
     high  orange — raised
     bad   red    — high risk
   ══════════════════════════════════════════════════════════════ */
.iw-calc-main {
  --calc-info: #1d4ed8;
  --calc-ok:   #15803d;
  --calc-warn: #b45309;
  --calc-high: #c2410c;
  --calc-bad:  #b91c1c;
}

.iw-calc [hidden],
.iw-calc[hidden] { display: none !important; }

/* ── Layout: form, then form + result side by side ── */
.iw-calc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 860px;
  margin: 0 auto;
}
.iw-calc.has-result {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr);
  max-width: 1120px;
}

/* Same card as the Contact and Submit Article forms */
.iw-calc-card {
  background: #fff;
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius);
  box-shadow: var(--iw-shadow-sm);
  padding: 34px 38px 38px;
  min-width: 0;
}

/* ── Segmented controls: unit switch and radio choices ── */
.iw-calc-seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--iw-gray-100);
  border: 1px solid var(--iw-gray-200);
  border-radius: var(--iw-radius-sm);
}
.iw-calc-units { margin-bottom: 26px; }

.iw-calc .iw-calc-seg button,
.iw-calc .iw-calc-seg label {
  flex: 1;
  display: block;
  position: relative;
  min-width: 0;
  margin: 0;
}
.iw-calc .iw-calc-seg button,
.iw-calc .iw-calc-seg label span {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--iw-radius-xs);
  background: transparent;
  box-shadow: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.35;
  text-align: center;
  color: var(--iw-muted);
  cursor: pointer;
  transition: background var(--iw-t), color var(--iw-t), box-shadow var(--iw-t);
}
.iw-calc .iw-calc-seg button:hover,
.iw-calc .iw-calc-seg label:hover span { color: var(--iw-navy); }
.iw-calc .iw-calc-seg label input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.iw-calc .iw-calc-seg button[aria-pressed="true"],
.iw-calc-seg input:checked + span {
  background: #fff;
  color: var(--iw-navy);
  font-weight: 700;
  box-shadow: var(--iw-shadow-sm), inset 0 -2px 0 var(--iw-orange);
}
.iw-calc-seg input:focus-visible + span {
  outline: 2px solid var(--iw-orange);
  outline-offset: 2px;
}

/* ── Fields — the theme's form-field pattern ── */
.iw-calc-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.iw-calc-field,
.iw-calc-choice { min-width: 0; margin: 0; padding: 0; border: 0; }
.iw-calc-field--full { grid-column: 1 / -1; }

.iw-calc-field > label,
.iw-calc-choice > legend {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--iw-gray-700);
  margin-bottom: 7px;
  padding: 0;
}
.iw-calc-opt {
  margin-left: 6px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: none;
  color: var(--iw-gray-400);
}

.iw-calc-input { position: relative; }
.iw-calc .iw-calc-input input,
.iw-calc .iw-calc-input select {
  width: 100%;
  padding: 12px 60px 12px 16px;
  border: 1.5px solid var(--iw-gray-200);
  border-radius: var(--iw-radius-xs);
  background: var(--iw-gray-50);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--iw-text);
  outline: 0;
  transition: border-color var(--iw-t), background var(--iw-t), box-shadow var(--iw-t);
  -moz-appearance: textfield;
}
.iw-calc .iw-calc-input--bare input,
.iw-calc .iw-calc-input--bare select { padding-right: 16px; }
.iw-calc .iw-calc-input select { cursor: pointer; }
.iw-calc .iw-calc-input input::-webkit-outer-spin-button,
.iw-calc .iw-calc-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.iw-calc .iw-calc-input input:focus,
.iw-calc .iw-calc-input select:focus {
  border-color: var(--iw-navy);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(30,27,75,.07);
}
.iw-calc .iw-calc-input input[aria-invalid="true"] {
  border-color: var(--calc-bad);
  background: #fef2f2;
  box-shadow: 0 0 0 4px rgba(185,28,28,.08);
}

.iw-calc-unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 8px;
  border: 1px solid var(--iw-gray-200);
  border-radius: var(--iw-radius-xs);
  background: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--iw-muted);
  pointer-events: none;
}
.iw-calc-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.iw-calc .iw-calc-pair input { padding-right: 46px; }

.iw-calc-hint {
  display: block;
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--iw-muted);
}

/* ── Actions and errors ── */
.iw-calc-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 22px;
  border-top: 1px solid var(--iw-gray-100);
}
.iw-calc-actions .iw-jbtn { cursor: pointer; font-family: inherit; line-height: 1.2; }
.iw-calc-actions .iw-jbtn--o { border: 0; }
.iw-calc-actions .iw-jbtn--line { background: #fff; }
.iw-calc-actions .iw-jbtn--line:hover { background: var(--iw-navy); }
.iw-calc-err { margin-top: 16px; }
.iw-calc-noscript { margin-top: 14px; font-size: 13px; color: var(--calc-bad); }

/* ── Result ── */
.iw-calc-result {
  text-align: center;
  padding: 0 0 30px;
  position: sticky;
  top: 24px;
  border-top: 3px solid var(--iw-navy);
  overflow: hidden;
}
.iw-calc-result > * { margin-left: 30px; margin-right: 30px; }
.iw-calc-lead {
  margin-top: 28px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--iw-orange-t, #c2410c);
}
.iw-calc-big {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.05;
  color: var(--iw-navy);
  margin-top: 10px;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}
.iw-calc-big small {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--iw-muted);
}
.iw-calc-big--text { font-size: 26px; letter-spacing: -.02em; line-height: 1.25; }

/* Category tag — square, small caps, like the theme's labels */
.iw-calc-pill {
  display: inline-block;
  padding: 7px 14px;
  border-radius: var(--iw-radius-xs);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  line-height: 1.4;
  color: #fff;
  background: var(--iw-navy);
}
.iw-calc-result > .iw-calc-pill:not(:first-child) { margin-top: 18px; }
.is-info.iw-calc-pill { background: var(--calc-info); }
.is-ok.iw-calc-pill   { background: var(--calc-ok); }
.is-warn.iw-calc-pill { background: var(--calc-warn); }
.is-high.iw-calc-pill { background: var(--calc-high); }
.is-bad.iw-calc-pill  { background: var(--calc-bad); }

.iw-calc-advice {
  font-size: 13.5px;
  color: var(--iw-gray-700);
  line-height: 1.7;
  margin-top: 14px;
  margin-bottom: 0;
}

/* Scale with marker */
.iw-calc-meter { position: relative; margin-top: 24px; margin-bottom: 6px; }
.iw-calc-meter-bar {
  display: flex;
  height: 8px;
  border-radius: 2px;
  overflow: hidden;
  gap: 2px;
}
.iw-calc-meter-bar span { display: block; min-width: 2px; }
.iw-calc-meter-bar .is-info { background: var(--calc-info); }
.iw-calc-meter-bar .is-ok   { background: var(--calc-ok); }
.iw-calc-meter-bar .is-warn { background: var(--calc-warn); }
.iw-calc-meter-bar .is-high { background: var(--calc-high); }
.iw-calc-meter-bar .is-bad  { background: var(--calc-bad); }
.iw-calc-meter-mark {
  position: absolute;
  top: -6px;
  width: 4px;
  height: 20px;
  margin-left: -2px;
  border-radius: 1px;
  background: var(--iw-navy);
  box-shadow: 0 0 0 2px #fff;
}

/* Label / value rows */
.iw-calc-rows {
  margin-top: 24px;
  margin-bottom: 0;
  text-align: left;
  border-top: 2px solid var(--iw-navy);
}
.iw-calc-rows > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--iw-gray-100);
}
.iw-calc-rows dt { font-size: 12.5px; color: var(--iw-muted); margin: 0; }
.iw-calc-rows dd { font-size: 13.5px; font-weight: 700; color: var(--iw-navy); margin: 0; text-align: right; }

/* Notes — the legal-note callout */
.iw-calc-note {
  margin-top: 16px;
  margin-bottom: 0;
  padding: 13px 16px;
  border-left: 3px solid var(--iw-navy);
  border-radius: 0 var(--iw-radius-xs) var(--iw-radius-xs) 0;
  background: var(--iw-gray-50);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--iw-gray-700);
  text-align: left;
}
.iw-calc-note.is-warn { border-left-color: var(--iw-orange); background: var(--iw-peach); }
.iw-calc-note.is-bad  { border-left-color: var(--calc-bad); background: #fef2f2; color: #7f1d1d; font-weight: 600; }

.iw-calc-flag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: var(--iw-radius-xs);
  background: #fef2f2;
  color: var(--calc-bad);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  vertical-align: 1px;
}

/* ── Tables — the legal-table pattern ── */
.iw-calc-table-wrap {
  overflow-x: auto;
  margin-top: 20px;
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius-sm);
  -webkit-overflow-scrolling: touch;
}
.iw-calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}
.iw-calc-table th,
.iw-calc-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--iw-gray-100);
  vertical-align: top;
}
.iw-calc-table thead th {
  background: var(--iw-gray-50);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--iw-navy);
  border-bottom: 2px solid var(--iw-navy);
  white-space: nowrap;
}
.iw-calc-table tbody tr:last-child th,
.iw-calc-table tbody tr:last-child td { border-bottom: 0; }
.iw-calc-table tbody th { font-weight: 600; color: var(--iw-navy); }
.iw-calc-table td { color: var(--iw-gray-700); }
.iw-calc-table tr.is-current th,
.iw-calc-table tr.is-current td { background: var(--iw-peach); color: var(--iw-navy); font-weight: 700; }
.iw-calc-table tr.is-current th { box-shadow: inset 3px 0 0 var(--iw-orange); }

/* Inside the narrow result card: tighter cells, and labels and
   numbers that never break mid-value ("Cycle 1", "120–132 bpm") */
.iw-calc-result .iw-calc-table { font-size: 12.5px; }
.iw-calc-result .iw-calc-table th,
.iw-calc-result .iw-calc-table td { padding: 10px 10px; }
.iw-calc-result .iw-calc-table thead th { font-size: 9.5px; letter-spacing: 1px; }
.iw-calc-result .iw-calc-table th[scope="row"],
.iw-calc-result .iw-calc-table td:last-child { white-space: nowrap; }

/* Reference tables on the page body */
.iw-calc-ref {
  max-width: 860px;
  margin: 0 auto;
  background: #fff;
}
.iw-calc-ref .iw-calc-table { font-size: 13.5px; }
.iw-calc-ref .iw-calc-table th,
.iw-calc-ref .iw-calc-table td { padding: 14px 18px; }
.iw-calc-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 10px;
  border-radius: 2px;
  vertical-align: 0;
}
.iw-calc-swatch.is-info { background: var(--calc-info); }
.iw-calc-swatch.is-ok   { background: var(--calc-ok); }
.iw-calc-swatch.is-warn { background: var(--calc-warn); }
.iw-calc-swatch.is-high { background: var(--calc-high); }
.iw-calc-swatch.is-bad  { background: var(--calc-bad); }

.iw-calc-subhead { max-width: 860px; margin: 40px auto 0; }
.iw-calc-subhead h3 {
  font-size: 17px;
  font-weight: 800;
  color: var(--iw-navy);
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--iw-border);
}

/* ── Healthy habits — the navy grid on the dark band ── */
.iw-calc-habits {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--iw-radius);
  overflow: hidden;
}
.iw-calc-habits li {
  background: var(--iw-navy);
  padding: 18px 20px 18px 46px;
  position: relative;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.5;
  color: rgba(255,255,255,.82);
}
.iw-calc-habits li::before {
  content: "";
  position: absolute;
  left: 21px;
  top: 22px;
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--iw-yellow);
  border-bottom: 2px solid var(--iw-yellow);
  transform: rotate(-45deg);
}

/* ── Method: formulas in a document card, sources as end matter ── */
.iw-calc-method {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.iw-calc-method-main {
  background: #fff;
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius);
  padding: 26px 32px 30px;
  min-width: 0;
}
.iw-calc-formula {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 16px;
  align-items: baseline;
  padding: 13px 0;
  border-bottom: 1px solid var(--iw-gray-100);
}
.iw-calc-formula span {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--iw-muted);
}
.iw-calc-formula code {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6;
  color: var(--iw-navy);
  white-space: normal;
  overflow-wrap: anywhere;
}
.iw-calc-method-main p { font-size: 14px; line-height: 1.78; color: var(--iw-gray-700); margin: 18px 0 0; max-width: 72ch; }

.iw-calc-sources {
  padding: 22px 24px;
  background: var(--iw-gray-50);
  border: 1px solid var(--iw-border);
  border-left: 3px solid var(--iw-navy);
  border-radius: 0 var(--iw-radius-sm) var(--iw-radius-sm) 0;
  min-width: 0;
}
.iw-calc-sources h3 {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--iw-muted);
  margin: 0 0 10px;
}
.iw-calc-sources ol { margin: 0; padding-left: 20px; list-style: decimal; }
.iw-calc-sources li { font-size: 13px; line-height: 1.6; padding: 8px 0; color: var(--iw-gray-700); }
.iw-calc-sources li + li { border-top: 1px solid var(--iw-gray-100); }
.iw-calc-sources li::marker { color: var(--iw-muted); font-size: 12px; }
.iw-calc-sources a {
  color: var(--iw-navy);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--iw-gray-300);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}
.iw-calc-sources a:hover { color: var(--iw-orange-t, #c2410c); text-decoration-color: currentColor; }

/* ── Calculator cards (index + related) ── */
.iw-calc-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--iw-border);
  border: 1px solid var(--iw-border);
  border-radius: var(--iw-radius);
  overflow: hidden;
}
.iw-calc-cardlink {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 24px 24px 26px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  transition: background var(--iw-t);
}
a.iw-calc-cardlink:hover { background: var(--iw-gray-50); }
.iw-calc-cardlink b {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--iw-navy);
  line-height: 1.32;
  transition: color var(--iw-t);
}
a.iw-calc-cardlink:hover b { color: var(--iw-orange-t, #c2410c); }
.iw-calc-cardlink span { font-size: 13px; line-height: 1.65; color: var(--iw-muted); }
.iw-calc-cardlink .iw-calc-cardlink-tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--iw-orange-t, #c2410c);
}
.iw-calc-cardlink.is-draft { background: var(--iw-gray-50); }
.iw-calc-cardlink.is-draft .iw-calc-cardlink-tag { color: var(--iw-muted); }

/* ── FAQ and disclaimer ── */
.iw-calc-faq { max-width: 860px; }
.iw-calc-disclaimer {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  max-width: 860px;
  margin: 0 auto;
  padding: 22px 26px;
  border: 1px solid var(--iw-border);
  border-left: 3px solid var(--iw-yellow);
  border-radius: 0 var(--iw-radius-sm) var(--iw-radius-sm) 0;
  background: var(--iw-gray-50);
}
.iw-calc-disclaimer svg { flex: none; color: var(--iw-yellow); margin-top: 1px; }
.iw-calc-disclaimer p { font-size: 13px; color: var(--iw-gray-700); line-height: 1.7; margin: 0; }

/* ── Responsive ── */
@media (max-width: 1080px) {
  .iw-calc.has-result { grid-template-columns: minmax(0, 1fr); max-width: 860px; }
  .iw-calc-result { position: static; }
  .iw-calc-method { grid-template-columns: minmax(0, 1fr); }
  .iw-calc-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .iw-calc-card { padding: 24px 20px 28px; }
  .iw-calc-result { padding: 0 0 24px; }
  .iw-calc-result > * { margin-left: 20px; margin-right: 20px; }
  .iw-calc-fields { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .iw-calc-big { font-size: 46px; }
  .iw-calc-big--text { font-size: 22px; }
  .iw-calc-habits { grid-template-columns: 1fr; }
  .iw-calc-cards { grid-template-columns: minmax(0, 1fr); }
  .iw-calc-method-main { padding: 22px 20px 24px; }
  .iw-calc-formula { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .iw-calc-ref .iw-calc-table th,
  .iw-calc-ref .iw-calc-table td { padding: 12px 12px; }
  .iw-calc-actions .iw-jbtn { flex: 1; justify-content: center; text-align: center; }
  .iw-calc-seg { flex-wrap: wrap; }
  .iw-calc .iw-calc-seg label, .iw-calc .iw-calc-seg button { flex: 1 1 40%; }
}
