/* ============================================================
   Body Fat Calculator — Nahnu Media v2.8.0
   ============================================================ */

/* ---------- Reset & box model ---------- */
.bfc-wrap,
.bfc-wrap *,
.bfc-wrap *::before,
.bfc-wrap *::after {
  box-sizing: border-box;
}

/* ---------- CSS custom properties ---------- */
.bfc-wrap {
  --primary:        #FF6A00;
  --primary-dark:   #e05800;
  --surface:        #1a1a1a;
  --surface-2:      #222222;
  --surface-3:      #2a2a2a;
  --border:         #2e2e2e;
  --text:           #ffffff;
  --text-muted:     #8a8a8a;
  --text-secondary: #b0b0b0;
  --error:          #ff4d4d;
  --radius-card:    18px;
  --radius-input:   12px;
  --radius-pill:    999px;

  width: 100%;
  max-width: 1200px;
  margin: 24px auto;
  /* Padding prevents content touching viewport edge on any screen */
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  /* Ensure the wrapper itself never overflows its container */
  min-width: 0;
  overflow: hidden;
}

/* ---------- Two-column layout (desktop only) ---------- */
.bfc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  /* Critical: prevent grid children from blowing out width */
  min-width: 0;
}

@media (min-width: 900px) {
  .bfc-grid {
    grid-template-columns: 380px 1fr;
    align-items: start;
    gap: 20px;
  }
}

/* All direct grid children must not overflow */
.bfc-grid > * {
  min-width: 0;
  width: 100%;
}

/* ---------- Cards ---------- */
.bfc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  min-width: 0;
}

.bfc-form {
  padding: 18px;
}

/* ---------- Results panel ---------- */
.bfc-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  min-width: 0;
}

.bfc-results.is-hidden { display: none; }

.res-head {
  background: #000;
  border-bottom: 2px solid var(--primary);
  padding: 16px 20px;
}
.res-head h3 {
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.res-head .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}
.res-body {
  padding: 16px 18px;
}

/* ---------- Metric / Imperial toggle ---------- */
.bfc-system {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-pill);
  margin-bottom: 18px;
  border: 1px solid var(--border);
}
.sys-btn {
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s, transform 0.04s;
  /* Prevent text overflow breaking layout */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sys-btn:hover { color: var(--text); }
.sys-btn:active { transform: translateY(1px); }
.sys-btn[aria-selected='true'] {
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

/* ---------- Form field grids ---------- */
.bfc-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
  /* Children must not overflow */
  min-width: 0;
}

/* Stack to single column on narrow cards */
@media (max-width: 540px) {
  .bfc-grid-2 {
    grid-template-columns: 1fr;
  }
}

.bfc-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  min-width: 0;
}

/* Only go 3-col inside the desktop sidebar (it's ~380px wide) */
@media (min-width: 900px) {
  .bfc-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.bfc-field {
  display: flex;
  flex-direction: column;
  /* Prevent field overflowing its grid cell */
  min-width: 0;
}

.bfc-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
  min-width: 0;
}
.bfc-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  /* Don't let label push unit off screen */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bfc-unit,
.bfc-unit-chip {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Inputs & selects */
.bfc-input,
.bfc-select select {
  /* width:100% + box-sizing:border-box = never overflows parent */
  width: 100%;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 15px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
.bfc-input::placeholder { color: var(--text-muted); }
.bfc-input:hover,
.bfc-select select:hover { border-color: #444; }
.bfc-input:focus,
.bfc-select select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 106, 0, 0.18);
}
.bfc-input.is-invalid {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.15) !important;
}

.bfc-select { position: relative; min-width: 0; }
.bfc-select select { padding-right: 34px; }
.bfc-select .chev {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  font-size: 12px;
}

.dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 0;
}

/* ---------- Tool tabs (None / Tape / Caliper) ---------- */
.bfc-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-input);
  margin-top: 8px;
  border: 1px solid var(--border);
  min-width: 0;
}
.bfc-tabs .tab {
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.bfc-tabs .tab:hover { color: var(--text); }
.bfc-tabs .tab[aria-selected='true'] {
  background: var(--primary);
  color: #fff;
}

/* ---------- Method list ---------- */
.bfc-list { display: grid; gap: 7px; margin-top: 8px; min-width: 0; }
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  min-width: 0;
}
.list-row:hover { border-color: #444; color: var(--text); }
.list-row.active {
  background: rgba(255, 106, 0, 0.08);
  border-color: var(--primary);
  color: var(--text);
}

.panel-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 14px 0 6px;
}

/* ---------- Actions ---------- */
.bfc-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.btn {
  border: none;
  padding: 11px 22px;
  border-radius: var(--radius-pill);
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.04s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: translateY(1px); }
.primary { background: var(--primary); color: #fff; }
.ghost {
  background: var(--surface-3);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.ghost:hover { color: var(--text); border-color: #444; }

/* ---------- Result blocks ---------- */
.hero {
  margin: 0 0 14px;
  padding: 18px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  text-align: center;
}
.hero-val {
  font-size: 52px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}
.hero-cap { font-size: 13px; color: var(--text-muted); }

.block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 14px;
  margin-bottom: 12px;
  min-width: 0;
}
.block-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.kv { display: grid; gap: 3px; min-width: 0; }
.kv > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  transition: background 0.12s;
  min-width: 0;
  gap: 8px;
}
.kv > div:hover { background: var(--surface-3); }
.kv > div span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.kv > div strong { color: var(--text); font-weight: 800; white-space: nowrap; flex-shrink: 0; }

.canvas { position: relative; width: 100%; height: 230px; min-width: 0; }

/* ---------- Notes, hints, errors ---------- */
.bfc-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.bfc-note {
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 14px;
  color: var(--text-muted);
}
.bfc-note strong { color: var(--text-secondary); }
.bfc-error {
  color: var(--error);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 600;
}

/* ---------- Focus a11y ---------- */
.bfc-wrap :focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Small screen tweaks ---------- */
@media (max-width: 480px) {
  .bfc-form { padding: 14px; }
  .res-body  { padding: 12px 14px; }
  .hero-val  { font-size: 40px; }

  .bfc-actions {
    flex-direction: column;
  }
  .bfc-actions .btn {
    width: 100%;
    text-align: center;
  }
}
