/* ==========================================================================
   IVF Outcome Calculator — Design System
   Warm, sophisticated, gender-neutral aesthetic
   ========================================================================== */

/* --- Design Tokens --- */
:root {
  --color-bg: #FAF8F5;
  --color-bg-alt: #F2EFEB;
  --color-text: #333334;
  --color-text-muted: #6B6B6C;
  --color-accent: #2B5E49;
  --color-accent-light: #3A7A60;
  --color-accent-bg: rgba(43, 94, 73, 0.08);
  --color-border: rgba(51, 51, 52, 0.15);
  --color-highlight: #C4553A;
  --color-white: #FFFFFF;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', monospace;
  --space-xs: 8px;
  --space-sm: 16px;
  --space-md: 32px;
  --space-lg: 56px;
  --space-xl: 80px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

/* --- Reset --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- Page Load Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Base Typography --- */
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  padding: var(--space-sm);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Layout Container --- */
.container {
  max-width: 880px;
  margin: 0 auto;
  animation: fadeIn 0.5s ease-out;
}

/* --- Medical Disclaimer Banner --- */
.disclaimer-banner {
  background: var(--color-accent-bg);
  border: 1px solid rgba(43, 94, 73, 0.18);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) 20px;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  font-size: 13px;
  color: var(--color-accent);
  line-height: 1.5;
  animation: fadeInUp 0.5s ease-out;
}

.disclaimer-banner p {
  flex: 1;
}

.disclaimer-banner strong {
  font-weight: 600;
}

.disclaimer-close {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.disclaimer-close:hover {
  background: rgba(43, 94, 73, 0.12);
}

/* --- Header --- */
.header {
  padding: var(--space-xl) 0 var(--space-lg) 0;
  animation: fadeInUp 0.5s ease-out 0.1s both;
}

.header h1 {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 400;
  line-height: 1.15;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.01em;
}

.header p {
  font-size: 17px;
  color: var(--color-text-muted);
  font-weight: 400;
  max-width: 520px;
}

/* --- Content Area --- */
.content {
  padding: 0;
}

/* --- Stage Indicator (Timeline) --- */
.stage-indicator {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
  margin-bottom: var(--space-xl);
  padding: 0 var(--space-sm);
  animation: fadeInUp 0.5s ease-out 0.2s both;
}

/* Connecting line behind the circles */
.stage-indicator::before {
  content: '';
  position: absolute;
  top: 16px;
  left: calc(var(--space-sm) + 16px);
  right: calc(var(--space-sm) + 16px);
  height: 2px;
  background: var(--color-border);
  z-index: 0;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
  flex: 1;
  text-align: center;
  padding: 0;
  background: none;
  border-radius: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  gap: var(--space-xs);
  transition: color 0.3s ease;
}

.stage.active {
  color: var(--color-accent);
  background: none;
}

.stage-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  border: 2px solid var(--color-border);
  transition: all 0.3s ease;
}

.stage.active .stage-number {
  background: var(--color-accent);
  color: var(--color-white);
  border-color: var(--color-accent);
}

/* --- Input Sections --- */
.input-section {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.3s both;
}

.input-section h3,
.section-heading {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: 20px;
  line-height: 1.3;
}

/* --- Input Groups --- */
.input-group {
  margin-bottom: 28px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group > label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.input-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* --- Range Sliders --- */
.input-row input[type="range"] {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  outline: none;
  -webkit-appearance: none;
  transition: background 0.2s ease;
}

.input-row input[type="range"]:hover {
  background: rgba(51, 51, 52, 0.25);
}

.input-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.input-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(43, 94, 73, 0.3);
}

.input-row input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.05);
}

.input-row input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.input-row input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(43, 94, 73, 0.3);
}

.input-row input[type="range"]:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.input-row input[type="range"]:disabled::-webkit-slider-thumb {
  background: var(--color-text-muted);
  cursor: default;
}

.input-row input[type="range"]:disabled::-moz-range-thumb {
  background: var(--color-text-muted);
  cursor: default;
}

/* --- Number Inputs --- */
.input-row input[type="number"] {
  width: 80px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
  text-align: center;
  color: var(--color-accent);
  background: var(--color-white);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-row input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-bg);
}

/* --- Value Display --- */
.value-display {
  min-width: 60px;
  text-align: right;
  font-weight: 700;
  font-size: 16px;
  color: var(--color-accent);
  font-family: var(--font-body);
}

/* --- AMH Estimator --- */
.amh-toggle {
  display: inline-block;
  font-size: 14px;
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  transition: all 0.2s ease;
}

.amh-toggle:hover {
  background: var(--color-accent-bg);
  text-decoration: none;
}

.amh-panel {
  background: var(--color-accent-bg);
  border: 1px solid rgba(43, 94, 73, 0.18);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.amh-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.amh-input-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 4px;
}

.amh-input-group input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--color-white);
}

/* --- Help Text --- */
.help-text {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* --- Summary Stats Row (inline in input-section) --- */
.summary-stats {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-top: var(--space-sm);
}

.summary-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-sm);
  font-size: 13px;
}

.summary-stat-label {
  color: var(--color-text-muted);
  margin-bottom: 4px;
  font-size: 13px;
}

.summary-stat-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  color: var(--color-accent);
}

/* --- Grade Inputs Grid --- */
.grade-input-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.grade-input-group label {
  display: block;
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.grade-input-group input[type="number"] {
  width: 100%;
  padding: var(--space-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.grade-input-group input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-bg);
}

/* --- Genetics Section --- */
.genetics-section {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.35s both;
}

.genetics-section h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-sm);
}

.genetics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-sm);
}

.genetics-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  transition: border-color 0.2s ease;
}

.genetics-card:hover {
  border-color: rgba(43, 94, 73, 0.3);
}

.genetics-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.genetics-prob {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  color: var(--color-accent);
}

.genetics-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* --- Results Section --- */
.results-section {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.4s both;
}

.results-section h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-md);
  text-align: left;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.stat-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  border-color: rgba(43, 94, 73, 0.3);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 400;
  color: var(--color-accent);
  margin-bottom: 6px;
  line-height: 1.1;
}

.stat-label {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Grade Breakdown inside results */
.grade-breakdown-panel {
  background: var(--color-accent-bg);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  margin-top: var(--space-sm);
}

.grade-breakdown-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: var(--space-xs);
}

.grade-breakdown-content {
  font-size: 13px;
  color: var(--color-text);
  line-height: 1.8;
}

/* --- Chart Sections --- */
.chart-section {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.45s both;
}

.chart-section h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

/* --- Funnel Chart (Monochromatic Teal) --- */
.funnel-stage {
  margin-bottom: 20px;
}

.funnel-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  padding: 0 2px;
}

.funnel-count {
  font-weight: 700;
  color: var(--color-text);
  font-family: var(--font-body);
}

.funnel-rate {
  color: var(--color-text-muted);
  font-size: 12px;
}

.funnel-bar-container {
  background: var(--color-bg-alt);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  height: 48px;
}

/* Override the inline gradient backgrounds set by JS */
.funnel-bar {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 var(--space-sm);
  color: var(--color-white);
  font-weight: 600;
  font-size: 14px;
  transition: width 0.5s ease;
  justify-content: space-between;
  border-radius: var(--radius-sm);
}

/* Monochromatic teal funnel: override JS inline backgrounds via specificity */
.funnel-stage:nth-child(1) .funnel-bar { background: var(--color-accent) !important; opacity: 1; }
.funnel-stage:nth-child(2) .funnel-bar { background: var(--color-accent) !important; opacity: 0.87; }
.funnel-stage:nth-child(3) .funnel-bar { background: var(--color-accent) !important; opacity: 0.74; }
.funnel-stage:nth-child(4) .funnel-bar { background: var(--color-accent) !important; opacity: 0.61; }
.funnel-stage:nth-child(5) .funnel-bar { background: var(--color-accent) !important; opacity: 0.48; }
.funnel-stage:nth-child(6) .funnel-bar { background: var(--color-accent) !important; opacity: 0.34; }

/* Ensure funnel bar text stays readable at low opacities */
.funnel-stage:nth-child(5) .funnel-bar,
.funnel-stage:nth-child(6) .funnel-bar {
  color: var(--color-text);
}

/* --- Probability Bars --- */
.probability-bar {
  margin-bottom: 20px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--color-text-muted);
}

.bar-container {
  height: 28px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: var(--color-accent);
  transition: width 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: var(--space-sm);
  color: var(--color-white);
  font-weight: 600;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.bar-fill.highlight {
  background: var(--color-highlight);
}

/* --- Info Box --- */
.info-box {
  background: var(--color-bg);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-top: var(--space-md);
}

.info-box h4 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.info-box p {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.7;
}

/* --- Pregnancy / Transfer Section --- */
.pregnancy-section {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.5s both;
  color: var(--color-text);
}

.pregnancy-section h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-md);
  text-align: left;
}

.transfer-input {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.transfer-input label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.transfer-input .help-text {
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

.pregnancy-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-sm);
}

/* Re-style stat-cards inside pregnancy-section */
.pregnancy-stats .stat-card {
  background: var(--color-accent-bg);
  border-color: rgba(43, 94, 73, 0.15);
}

/* --- Pregnancy Outcomes --- */
.pregnancy-outcomes {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.55s both;
}

.pregnancy-outcomes h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

.outcome-card {
  background: var(--color-bg);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
  transition: border-color 0.2s ease;
}

.outcome-card:hover {
  border-left-color: var(--color-accent-light);
}

.outcome-card h4 {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.outcome-prob {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--color-accent);
  flex-shrink: 0;
  margin-left: var(--space-sm);
}

.outcome-description {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

/* --- Responsive: Tablet --- */
@media (max-width: 768px) {
  body {
    padding: var(--space-sm);
  }

  .header {
    padding: var(--space-lg) 0 var(--space-md) 0;
  }

  .header h1 {
    font-size: 34px;
  }

  .header p {
    font-size: 15px;
  }

  .stage-indicator {
    gap: 2px;
    margin-bottom: var(--space-lg);
    padding: 0;
  }

  .stage {
    font-size: 11px;
  }

  .stage-number {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .grade-input-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .genetics-grid {
    grid-template-columns: 1fr;
  }

  .pregnancy-stats {
    grid-template-columns: 1fr 1fr;
  }
}

/* --- Responsive: Phone --- */
@media (max-width: 480px) {
  body {
    padding: var(--space-sm);
  }

  .header {
    padding: var(--space-md) var(--space-xs);
  }

  .header h1 {
    font-size: 28px;
  }

  .stage-indicator {
    flex-wrap: nowrap;
    gap: 2px;
    justify-content: space-between;
    padding: 0;
  }

  .stage-indicator::before {
    display: none;
  }

  .stage {
    flex: 1;
    width: auto;
    font-size: 9px;
  }

  .stage-number {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 28px;
  }

  .grade-input-grid {
    grid-template-columns: 1fr;
  }

  .outcome-card h4 {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .outcome-prob {
    margin-left: 0;
  }

  .pregnancy-stats {
    grid-template-columns: 1fr;
  }

  .input-row {
    flex-wrap: wrap;
  }

  .input-row input[type="range"] {
    width: 100%;
    flex: 1 1 100%;
  }

  .value-display {
    text-align: left;
    min-width: auto;
    font-size: 18px;
    margin-top: 4px;
  }
}

/* --- Smooth Transitions for Interactive Elements --- */
a,
button,
input,
.stat-card,
.genetics-card,
.outcome-card {
  transition: all 0.2s ease;
}

/* --- Selection Style --- */
::selection {
  background: var(--color-accent-bg);
  color: var(--color-text);
}

/* --- Scrollbar (Webkit) --- */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* --- Accessibility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Visible focus indicators */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.glossary-term:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Override the outline: none on range inputs */
.input-row input[type="range"]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* --- Toggle Switch (Fresh/Frozen) --- */
.toggle-group {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
}

.toggle-group > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toggle-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border);
  transition: 0.3s;
  border-radius: 26px;
}

.slider-toggle::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: var(--color-white);
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.switch input:checked + .slider-toggle {
  background-color: var(--color-accent);
}

.switch input:checked + .slider-toggle::before {
  transform: translateX(22px);
}

.switch input:focus + .slider-toggle {
  box-shadow: 0 0 0 3px var(--color-accent-bg);
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  animation: fadeInUp 0.5s ease-out 0.15s both;
}

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--color-border);
  line-height: 1.4;
}

.btn-secondary {
  background: var(--color-white);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg-alt);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-copied {
  background: var(--color-accent) !important;
  color: var(--color-white) !important;
  border-color: var(--color-accent) !important;
}

/* --- Glossary Tooltips --- */
.glossary-term {
  border-bottom: 1px dotted var(--color-accent);
  cursor: help;
  position: relative;
  display: inline;
}

.glossary-term::after {
  content: attr(data-tooltip);
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #333334;
  color: #FFFFFF;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  max-width: 280px;
  min-width: 180px;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  text-align: left;
}

.glossary-term::before {
  content: '';
  display: none;
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #333334;
  z-index: 201;
}

.glossary-term:hover::after,
.glossary-term:focus::after,
.glossary-term:hover::before,
.glossary-term:focus::before {
  display: block;
}

/* Ensure tooltip is visible even at edge of container */
.glossary-term:first-child::after {
  left: 0;
  transform: none;
}

/* --- Citation References --- */
.cite-ref {
  font-size: 11px;
  line-height: 1;
  vertical-align: super;
  margin-left: 1px;
}

.cite-ref a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
  position: relative;
  cursor: pointer;
}

.cite-ref a:hover {
  color: var(--color-accent-light);
  text-decoration: underline;
}

/* Citation tooltip on hover */
.cite-ref a .cite-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-white);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  max-width: 320px;
  min-width: 200px;
  z-index: 100;
  pointer-events: none;
  margin-bottom: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.cite-ref a .cite-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-text);
}

.cite-ref a:hover .cite-tooltip,
.cite-ref a:focus .cite-tooltip {
  display: block;
}

/* --- References Section --- */
.references-section {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.5s ease-out 0.6s both;
}

.references-section h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-md);
  text-align: left;
}

.reference-item {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  line-height: 1.7;
  color: var(--color-text-muted);
}

.reference-item:last-child {
  border-bottom: none;
}

.reference-number {
  font-weight: 700;
  color: var(--color-accent);
  margin-right: 4px;
}

.reference-item a {
  color: var(--color-accent);
  text-decoration: none;
  word-break: break-all;
}

.reference-item a:hover {
  text-decoration: underline;
}

.reference-group-title {
  font-weight: 600;
  color: var(--color-text);
  font-size: 14px;
  margin-bottom: 4px;
}

/* --- Print Media Query --- */
@media print {
  * {
    animation: none !important;
    transition: none !important;
  }

  body {
    background: white !important;
    padding: 0;
    font-size: 12px;
    color: #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .disclaimer-banner,
  .disclaimer-close,
  .toolbar,
  .stage-indicator {
    display: none !important;
  }

  .container {
    max-width: 100%;
  }

  .header {
    padding: var(--space-sm) 0;
  }

  .content {
    background: white !important;
  }

  .input-section,
  .results-section,
  .chart-section,
  .pregnancy-section,
  .pregnancy-outcomes,
  .genetics-section,
  .references-section {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #ddd;
    box-shadow: none;
    background: white !important;
    margin-bottom: 16px;
  }

  .stat-card,
  .genetics-card,
  .outcome-card {
    box-shadow: none;
    border: 1px solid #ddd;
    background: white !important;
  }

  .summary-stats {
    background: white !important;
  }

  /* Hide sliders, show only value displays */
  input[type="range"] {
    display: none !important;
  }

  .input-row input[type="number"] {
    border: none;
    background: transparent;
    font-size: 14px;
  }

  .value-display {
    font-size: 14px;
  }

  /* Hide toggle switches in print */
  .toggle-switch {
    display: none;
  }

  /* Ensure bar charts are visible */
  .funnel-bar,
  .bar-fill {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Glossary tooltips: show inline in print */
  .glossary-term {
    border-bottom: none;
  }

  .glossary-term::after,
  .glossary-term::before {
    display: none !important;
  }

  /* Citation tooltips hidden in print */
  .cite-tooltip {
    display: none !important;
  }

  /* URL footer for print */
  .container::after {
    content: "Generated by IVF Outcome Calculator — ivf-outcome-calculator.com";
    display: block;
    text-align: center;
    font-size: 10px;
    color: #999;
    padding-top: 16px;
    margin-top: 24px;
    border-top: 1px solid #ddd;
  }

  /* Page setup */
  @page {
    margin: 1.5cm;
  }

  /* Avoid page breaks inside important sections */
  .stat-grid,
  .pregnancy-stats,
  .genetics-grid {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
