/* ============================================================
   FRB Pipe Connection Calculator — Scoped CSS
   All rules are scoped to .frb-calc to avoid theme conflicts
   ============================================================ */

.frb-calc {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  line-height: 1.5;
}
.frb-calc *, .frb-calc *::before, .frb-calc *::after {
  box-sizing: border-box;
}

/* ── Header ── */
.frb-calc .frb-header {
  background: #222;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.frb-calc .frb-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 2px;
  color: #fff;
  border: none;
  padding: 0;
  line-height: 1.3;
}
.frb-calc .frb-header span {
  font-size: 13px;
  color: #aaa;
  display: block;
}

/* ── Tabs ── */
.frb-calc .tabs-bar {
  display: flex;
  background: #fff;
  border-bottom: 2px solid #e0e0e0;
  padding: 0 24px;
}
.frb-calc .tab-btn {
  padding: 14px 22px;
  font-size: 14px;
  font-weight: 500;
  color: #555;
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  outline: none;
  box-shadow: none;
  border-radius: 0;
  text-decoration: none;
}
.frb-calc .tab-btn.active {
  color: #0079c2;
  border-bottom-color: #0079c2;
}
.frb-calc .tab-btn:hover {
  color: #333;
  background: none;
  border-bottom-color: transparent;
}
.frb-calc .tab-btn.active:hover {
  border-bottom-color: #0079c2;
}

/* ── Sections ── */
.frb-calc .frb-section {
  display: none;
    padding: 24px 0 0 0;
}
.frb-calc .frb-section.active {
  display: block;
}

/* ── Selector card ── */
.frb-calc .selector-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

/* ── List boxes (reusable) ── */
.frb-calc .list-box {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fafafa;
  padding: 0;
  margin: 0;
}
.frb-calc .list-box li {
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.frb-calc .list-box li:last-child { border-bottom: none; }
.frb-calc .list-box li:hover { background: #e8f4fd; }
.frb-calc .list-box li.active { background: #0079c2; color: #fff; }

/* ── Type grid ── */
.frb-calc .type-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 4px 0;
}
.frb-calc .type-card {
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 10px 8px;
  cursor: pointer;
  background: #fff;
  width: 130px;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.frb-calc .type-card:hover { border-color: #0079c2; }
.frb-calc .type-card.active {
  border-color: #0079c2;
  box-shadow: 0 0 0 3px rgba(0,121,194,.2);
}
.frb-calc .type-card img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border: none;
  box-shadow: none;
}
.frb-calc .type-card .tc-name {
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  line-height: 1.3;
  color: #333;
}

/* ── Buttons ── */
.frb-calc .btn-primary {
  padding: 10px 32px;
  background: #0079c2;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.frb-calc .btn-primary:hover { background: #005fa3; }
.frb-calc .btn-primary:disabled { background: #aaa; cursor: not-allowed; }
.frb-calc .btn-back {
  padding: 8px 20px;
  background: #fff;
  color: #555;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  margin-right: 12px;
}
.frb-calc .btn-back:hover { background: #f0f0f0; }

/* ── RF / RTJ facing toggle ── */
.frb-calc .rf-rtj {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.frb-calc .facing-btn {
  padding: 6px 18px;
  background: #fff;
  color: #0079c2;
  border: 1px solid #0079c2;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.frb-calc .facing-btn:hover { background: #eaf4fb; }
.frb-calc .facing-btn.active {
  background: #0079c2;
  color: #fff;
}

/* Companion block that exists only on paper (e.g. the RF table printed
   alongside RTJ). Never shown on screen. */
.frb-calc .print-only { display: none; }
.frb-calc .print-subhead {
  font-size: 15px;
  font-weight: 700;
  margin: 22px 0 10px;
}

/* ── Result card ── */
.frb-calc .result-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 24px;
  display: none;
}
.frb-calc .result-card.show { display: block; }
.frb-calc .result-header {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}
.frb-calc .result-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}
.frb-calc .result-img {
  max-width: 100%;
  height: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  background: #fafafa;
  display: block;
}

/* ── Dimension table ── */
.frb-calc table.dim-table {
  width: 100%;
  border-collapse: collapse;
}
.frb-calc table.dim-table th,
.frb-calc table.dim-table td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  font-size: 13px;
  text-align: left;
}
.frb-calc table.dim-table th {
  background: #f6f6f6;
  font-weight: 600;
}

/* ── Sub heading ── */
.frb-calc .sub-head {
  font-size: 12px;
  font-weight: 700;
  color: #555;
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ── Fit selectors row ── */
.frb-calc .fit-selectors {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.frb-calc .fit-selectors label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #444;
}
.frb-calc select,
.frb-calc input[type="number"] {
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid #ccc;
  border-radius: 5px;
  min-width: 160px;
  background: #fff;
  color: #222;
  height: auto;
}
.frb-calc input[type="number"] {
  min-width: 120px;
  -moz-appearance: textfield;
}
.frb-calc input[type="number"]::-webkit-outer-spin-button,
.frb-calc input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: inner-spin-button;
}
.frb-calc input[type="number"][readonly] {
  background: #f5f5f5;
  color: #888;
  cursor: default;
}

/* ── Pills ── */
.frb-calc .pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.frb-calc .pill {
  padding: 3px 12px;
  border: 1px solid #ddd;
  border-radius: 999px;
  font-size: 12px;
  background: #fff;
}

/* ── Weight calculator: fields + product diagram ── */
.frb-calc .wc-grid {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.frb-calc .wc-fields {
  flex: 1 1 340px;
  min-width: 0;
}
.frb-calc .wc-diagram {
  flex: 0 0 720px;
  align-self: center;
  background: #fafcfe;
  border: 1px solid #e2e8ee;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.frb-calc .wc-diagram:empty { display: none; }
.frb-calc .wc-diagram img {
  width: 100%;
  max-width: 720px;
  height: auto;
  display: block;
  margin: 0 auto;
  border: none;
  box-shadow: none;
}
@media (max-width: 640px) {
  .frb-calc .wc-diagram { flex-basis: 100%; order: -1; }
}

/* ── DIN deviation highlighting (val_din differs from val_en) ── */
.frb-calc table.dim-table td.dim-deviation {
  color: #c0392b;
  font-weight: 600;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .frb-calc .result-grid { grid-template-columns: 1fr; }
}
@media (max-width: 580px) {
  .frb-calc .frb-section { padding: 16px; }
  .frb-calc .fit-selectors { flex-direction: column; }
  .frb-calc select,
  .frb-calc input[type="number"] { min-width: 100%; }
  .frb-calc .tabs-bar { padding: 0 12px; }
  .frb-calc .tab-btn { padding: 12px 14px; font-size: 13px; }
}

/* ── Print: only the calculator, none of the surrounding page ──
   Theme-agnostic: hide everything, then reveal only .frb-calc and its
   descendants. Works regardless of the theme's header/footer/sidebar markup. */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; }

  /* Print only the calculator. Hide every element that is neither an ancestor
     of nor inside .frb-calc, using display:none (not visibility:hidden) so the
     site header/nav/footer reserve NO space — otherwise their hidden boxes push
     the calculator down and leave large blank gaps and empty trailing pages. */
  body :not(:has(.frb-calc)):not(.frb-calc):not(.frb-calc *) { display: none !important; }

  /* Strip spacing/background from the surviving ancestor chain so the calculator
     sits flush at the top of the page. */
  body :has(.frb-calc) {
    margin: 0 !important;
    padding: 0 !important;
    background: none !important;
  }

  .frb-calc {
    /* Normal flow so tall results paginate across pages instead of clipping. */
    width: 100%;
    margin: 0;
    padding: 0;
    /* Print the accent colours and header as designed, not stripped to white. */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Show the active tab's content; the inactive tab stays display:none. */
  .frb-calc .frb-section.active { display: block !important; }

  /* Reveal any result cards even if they were toggled via inline display. */
  .frb-calc .result-card,
  .frb-calc .result-card.show { display: block !important; }

  /* Hide interactive chrome that has no meaning on paper. */
  .frb-calc .tabs-bar,
  .frb-calc .btn-primary,
  .frb-calc .rf-rtj,
  .frb-calc .btn-back { display: none !important; }

  /* Reveal print-only companion blocks once JS has filled them. */
  .frb-calc .print-only.has-content { display: block !important; }

  /* Unclip scrollable areas so nothing is cut off. */
  .frb-calc .list-box {
    max-height: none !important;
    overflow: visible !important;
  }

  /* Keep related blocks from splitting across pages. */
  .frb-calc .selector-card,
  .frb-calc .result-card,
  .frb-calc .type-card,
  .frb-calc table.dim-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  @page { margin: 12mm; }
}
