/* Calculator integrity layer 1.34.00
   Unified scale geometry, mobile containment and UI for corrected calculator semantics. */

/* --- Scale geometry corrections that must match the numeric marker system --- */
/* Child BMI 5–18 uses a -3.5..+3.5 visual domain. WHO category boundaries therefore sit at
   -3 = 7.14%, -2 = 21.43%, +1 = 64.29%, +2 = 78.57%, +3 = 92.86%. */
.child-bmi-sds-scale::before{
  background:linear-gradient(90deg,
    #e5b3a8 0 7.14%,
    #e6d9b4 7.14% 21.43%,
    #d6e0c7 21.43% 64.29%,
    #eadcaa 64.29% 78.57%,
    #e6b895 78.57% 92.86%,
    #df9b91 92.86% 100%);
}

/* Combined child growth calculator uses the same -3.5..+3.5 marker domain. */
.child-sds-scale:not(.child-sds-scale--bmi)::before{
  background:linear-gradient(90deg,
    #e6c3b4 0 7.14%,
    #e7ddbd 7.14% 21.43%,
    #dce7cd 21.43% 78.57%,
    #e7ddbd 78.57% 92.86%,
    #e6c3b4 92.86% 100%);
}
.child-sds-scale--bmi::before{
  background:linear-gradient(90deg,
    #e6c3b4 0 7.14%,
    #e7ddbd 7.14% 21.43%,
    #dce7cd 21.43% 64.29%,
    #eadcaa 64.29% 78.57%,
    #e6b895 78.57% 92.86%,
    #df9b91 92.86% 100%);
}

/* 0–5 calculator combines different WHO indicators. Avoid implying one universal
   red/yellow clinical classification; show a neutral reference band -2..+2 SDS. */
.c05-scale::before{
  background:linear-gradient(90deg,
    #eee8dc 0 16.67%,
    #dce5cf 16.67% 83.33%,
    #eee8dc 83.33% 100%);
}

/* Growth velocity is a trajectory display, not a separate diagnostic cutoff.
   The visual reference band follows -2..+2 SDS on the -3.5..+3.5 domain. */
.velocity-sds-scale__bar span{width:21.43%;background:#e8ddd2}
.velocity-sds-scale__bar i{left:21.43%;width:57.14%;background:#dfe5d0}
.velocity-sds-scale__bar b{width:21.43%;background:#e8ddd2}

/* FINDRISC axis is 0..26. Segment widths must be 7,5,3,6,5 points (not 7,5,3,6,6). */
.findrisc-scale__bar{grid-template-columns:7fr 5fr 3fr 6fr 5fr}
.findrisc-scale__labels{position:relative;display:block;height:1rem;margin-top:.38rem}
.findrisc-scale__labels span{position:absolute;top:0;transform:translateX(-50%);white-space:nowrap}
.findrisc-scale__labels span:nth-child(1){left:0;transform:none}
.findrisc-scale__labels span:nth-child(2){left:26.923%}
.findrisc-scale__labels span:nth-child(3){left:46.154%}
.findrisc-scale__labels span:nth-child(4){left:57.692%}
.findrisc-scale__labels span:nth-child(5){left:80.769%}
.findrisc-scale__labels span:nth-child(6){right:0;left:auto;transform:none}

/* eGFR axis is 0..120+. Labels must sit over their true numerical positions. */
.egfr-scale__labels{position:relative;display:block;height:1rem;margin-top:.45rem}
.egfr-scale__labels span{position:absolute;top:0;transform:translateX(-50%);white-space:nowrap}
.egfr-scale__labels span:nth-child(1){left:0;transform:none}
.egfr-scale__labels span:nth-child(2){left:12.5%}
.egfr-scale__labels span:nth-child(3){left:25%}
.egfr-scale__labels span:nth-child(4){left:37.5%}
.egfr-scale__labels span:nth-child(5){left:50%}
.egfr-scale__labels span:nth-child(6){left:75%}
.egfr-scale__labels span:nth-child(7){right:0;left:auto;transform:none}

/* FIB-4 has four labels and three zones. Place labels by actual dynamic thresholds. */
.fib4-scale__labels{position:relative;display:block;height:1rem;margin-top:.55rem}
.fib4-scale__labels span{position:absolute;top:0;transform:translateX(-50%);white-space:nowrap}
.fib4-scale__labels span:nth-child(1){left:0;transform:none}
.fib4-scale__labels span:nth-child(2){left:var(--fib4-lower)}
.fib4-scale__labels span:nth-child(3){left:var(--fib4-upper)}
.fib4-scale__labels span:nth-child(2),.fib4-scale__labels span:nth-child(3){transform:translateX(-50%)}
.fib4-scale__labels span:nth-child(4){right:0;left:auto;transform:none;text-align:right}

/* Standard SCORE2 also has dynamic age-dependent thresholds. */
.score2-scale__labels:not(.score2-scale__labels--diabetes){position:relative;display:block;height:1rem;margin-top:.38rem}
.score2-scale__labels:not(.score2-scale__labels--diabetes) span{position:absolute;top:0;transform:translateX(-50%);white-space:nowrap}
.score2-scale__labels:not(.score2-scale__labels--diabetes) span:nth-child(1){left:0;transform:none}
.score2-scale__labels:not(.score2-scale__labels--diabetes) span:nth-child(2){left:var(--score2-low)}
.score2-scale__labels:not(.score2-scale__labels--diabetes) span:nth-child(3){left:var(--score2-high)}
.score2-scale__labels:not(.score2-scale__labels--diabetes) span:nth-child(4){right:0;left:auto;transform:none}

.target-height-scale__mobile-legend{display:none}

/* --- Mobile containment and readable result cards --- */
@media (max-width:760px){
  .calculator-form,
  .calculator-result,
  .calculator-layout,
  .calculator-fields,
  .form-control,
  .input-with-unit,
  .input-with-unit>input,
  .input-with-unit>select,
  .bmi-input-card,.bmi-result-card,
  .whr-input-card,.whr-result-card,
  .mets-input-card,.mets-result-card,
  .energy-input-card,.energy-result-card,
  .child-input-card,.child-result-card,
  .target-input-card,.target-result-card,
  .velocity-input-card,.velocity-result-card,
  .homa-input-card,.homa-result-card,
  .a1c-input-card,.a1c-result-card,
  .lipid-input-card,.lipid-result-card,
  .tyg-input-card,.tyg-result-card,
  .c05-form,.c05-result,
  .child-bmi-form,.child-bmi-result,
  .findrisc-form,.findrisc-result,
  .egfr-form,.egfr-result,
  .thyroid-volume-form,.thyroid-volume-result,
  .fib4-form,.fib4-result,
  .calcium-form,.calcium-result,
  .score2-form,.score2-result{
    min-width:0;
    max-width:100%;
    box-sizing:border-box;
  }

  .form-control,
  input[type="number"],input[type="date"],input[type="text"],
  select,textarea{
    min-width:0;
    max-width:100%;
    box-sizing:border-box;
  }

  .calculator-submit,
  .calculator-form .btn,
  .bmi-submit,.whr-submit,.mets-submit,.energy-submit,
  .homa-submit,.a1c-submit,.lipid-submit,.tyg-submit{
    max-width:100%;
  }

  /* Mobile scale tracks must never create a second horizontal coordinate system. */
  .whr-full-scale,
  .child-bmi-sds-scale,
  .child-sds-scale,
  .c05-scale,
  .velocity-sds-scale,
  .findrisc-scale,
  .egfr-scale,
  .fib4-scale,
  .score2-scale,
  .target-height-scale{
    width:100%;
    min-width:0;
    max-width:100%;
    overflow:visible;
  }

  .whr-full-scale{padding-bottom:2.4rem}
  .whr-full-scale__marker span{top:4.15rem}

  .child-bmi-sds-scale>div,
  .child-sds-scale>div,
  .c05-scale div,
  .velocity-sds-labels{
    font-size:clamp(.52rem,2.4vw,.64rem);
  }

  /* Two SDS points can be almost identical. Stagger them vertically on phones. */
  .velocity-sds-scale{min-height:6.8rem;padding-top:1.2rem}
  .velocity-sds-marker.is-first{top:.65rem}
  .velocity-sds-marker.is-second{top:2.55rem}
  .velocity-sds-labels{margin-top:3.5rem}

  /* Parent/target marker labels collide easily on a narrow track. Keep the lines exact
     and move textual values into a dedicated mobile legend. */
  .target-height-scale{min-height:7.2rem;padding-top:1.3rem}
  .target-height-scale__axis{top:3rem}
  .target-height-scale__range{top:2.65rem}
  .target-height-scale__marker{top:.15rem}
  .target-height-scale__marker.is-target{top:-.2rem}
  .target-height-scale__marker b,
  .target-height-scale__marker span{display:none}
  .target-height-scale__marker i{height:2.45rem}
  .target-height-scale__marker.is-target i{height:2.8rem}
  .target-height-scale__limits{bottom:.25rem}
  .target-height-scale__mobile-legend{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:.45rem;
    margin-top:.65rem;
  }
  .target-height-scale__mobile-legend span{
    display:grid;
    gap:.12rem;
    min-width:0;
    padding:.5rem .42rem;
    border:1px solid rgba(92,106,73,.12);
    border-radius:.65rem;
    background:#f7f7f1;
    text-align:center;
  }
  .target-height-scale__mobile-legend b{color:#58634f;font-size:.66rem}
  .target-height-scale__mobile-legend small{color:#777f73;font-size:.67rem;white-space:nowrap}

  .findrisc-scale__labels,
  .egfr-scale__labels,
  .fib4-scale__labels,
  .score2-scale__labels{
    font-size:clamp(.53rem,2.35vw,.64rem);
  }

  /* Very large values must shrink instead of forcing result cards wider than viewport. */
  .bmi-result-main strong,.whr-result-main strong,
  .energy-result-main strong,.homa-result-main strong,.tyg-result-main strong,
  .findrisc-score strong,.egfr-result-main strong,.fib4-result__main strong,
  .thyroid-volume-result__main strong,.score2-result__value strong,
  .calcium-result__number strong{
    max-width:100%;
    overflow-wrap:anywhere;
    line-height:.94;
  }

  .score2-result__value{min-width:0;max-width:100%}
  .score2-result__metrics strong,
  .egfr-method strong,
  .fib4-input-summary strong,
  .score2-input-summary strong,
  .calcium-result__metrics strong{
    overflow-wrap:anywhere;
    word-break:normal;
  }
}

@media (max-width:480px){
  .score2-options--three{grid-template-columns:1fr}
  .target-height-scale__mobile-legend{grid-template-columns:1fr}
  .egfr-scale{margin-left:.1rem;margin-right:.1rem}
  .egfr-scale__labels span:nth-child(2),
  .egfr-scale__labels span:nth-child(3),
  .egfr-scale__labels span:nth-child(4),
  .egfr-scale__labels span:nth-child(5),
  .egfr-scale__labels span:nth-child(6){font-size:.52rem}
}

@media (max-width:380px){
  .calcium-analyte__control{grid-template-columns:1fr}
  .calcium-analyte__control select{width:100%}
  .score2-result__value strong{font-size:clamp(3.6rem,19vw,5rem)}
  .egfr-result-main strong{font-size:clamp(3.5rem,18vw,4.8rem)}
  .findrisc-score strong{font-size:clamp(3.8rem,19vw,5rem)}
  .fib4-result__main strong{font-size:clamp(3.8rem,19vw,5rem)}
}

/* 1.34.00 — calculator logic/UI integrity additions */
.whr-input-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}
.whr-input-grid .whr-input-row{min-width:0}
.whr-input-row em{font-style:normal;font-size:.78rem;line-height:1.35;color:var(--muted,#697066);display:block;margin-top:6px}
.whr-applicability-note{margin:16px 0;padding:14px 16px;border:1px solid rgba(107,116,76,.22);border-radius:16px;background:rgba(246,244,232,.86);font-size:.92rem;line-height:1.55}
.whr-applicability-note strong{display:block;margin-bottom:4px;color:var(--olive-dark,#4f5836)}
.whr-full-scale.is-reference-only .whr-full-scale__bar{filter:saturate(.18);opacity:.72}
.whr-full-scale.is-reference-only .whr-full-scale__marker{filter:none;opacity:1}

.c05-prematurity-fields{display:none;margin:-2px 0 16px;padding:15px;border-radius:16px;background:rgba(246,244,232,.82);border:1px solid rgba(107,116,76,.18)}
.c05-prematurity-fields.is-visible{display:block}
.c05-prematurity-help{display:block;margin-top:8px;line-height:1.5;color:var(--muted,#687064)}
.c05-corrected-age{margin:12px 0 14px;padding:12px 14px;border-radius:14px;background:rgba(238,241,226,.92);font-size:.9rem;line-height:1.45}
.c05-corrected-age strong{color:var(--olive-dark,#4f5836)}
.c05-corrected-age span{color:var(--muted,#687064)}

.findrisc-validation-note{margin:14px 0;padding:14px 15px;border-radius:15px;background:rgba(248,245,234,.94);border:1px solid rgba(112,117,78,.22)}
.findrisc-validation-note strong{display:block;margin-bottom:5px;color:var(--olive-dark,#4f5836)}
.findrisc-validation-note p{margin:0;font-size:.9rem;line-height:1.5}

.tyg-result-metrics--primary{grid-template-columns:repeat(2,minmax(0,1fr))}
.tyg-technical-note{margin:14px 0;border:1px solid rgba(112,117,78,.2);border-radius:15px;background:rgba(248,245,234,.72);overflow:hidden}
.tyg-technical-note summary{cursor:pointer;padding:13px 15px;font-weight:700;color:var(--olive-dark,#4f5836)}
.tyg-technical-note div{padding:0 15px 14px}
.tyg-technical-note p{margin:8px 0 0;line-height:1.5}

@media(max-width:760px){
  .whr-input-grid{grid-template-columns:1fr}
  .tyg-result-metrics--primary{grid-template-columns:1fr}
  .c05-prematurity-fields{padding:13px}
}
.findrisc-field-help{display:block;margin-top:6px;font-style:normal;font-size:.76rem;line-height:1.4;color:var(--muted,#687064)}
