.frat-section3 {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  max-height: 0;
  transform: translateY(20px);
  transition: opacity 1s ease, max-height 1.2s ease, transform 1s ease;
  overflow: hidden;
}

.frat-section3.visible {
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
  max-height: 5000px;
  transform: translateY(0);
}

.frat-section3 h2 {
  margin-bottom: 8px;
}

.wb-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background-color: #ffffff;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #ccc;
  margin-bottom: 1.5rem;
}

.wb-table {
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
}

.wb-table th, .wb-table td {
  padding: 8px;
  font-size: 0.9rem;
}

.wb-table input {
  width: 100%;
  max-width: 100px;
}

.wb-table th {
  background-color: #003366;
  color: white;
  text-align: left;
  font-size: 0.85rem;
}

.wb-table tr:nth-child(even) {
  background-color: #f9f9f9;
}

.wb-table tr:hover {
  background-color: #eef5ff;
}

.locked-input {
  background-color: #f5f5f5;
  color: #555;
  pointer-events: none;
}

.envelope-plot-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin: 20px 0;
}

.envelope-plot-container .chart-wrapper {
  flex: 1 1 100%;
  max-width: 100%;
  width: 100%;
  border: 1px solid #ccc;
  padding: 12px;
  background: #f4f4f4;
  border-radius: 8px;
  box-sizing: border-box;
  margin: 0 auto;
}

.chart-inner {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #ccc;
  border-radius: 6px;
}


.ref-reset-btn {
  margin-top: 10px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background-color: #003366;
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.ref-reset-btn:hover {
  background-color: #00509e;
}

#stationDiagramButton {
  margin-left: 12px;
  padding: 6px 10px;
  background-color: #003366;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#stationDiagramModal {
  display: none;
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border: 2px solid #003366;
  border-radius: 8px;
  padding: 16px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  max-width: 90%;
  max-height: 80%;
  overflow: auto;
}

#stationDiagramModal img {
  width: 100%;
  height: auto;
}

#stationDiagramModalClose {
  position: absolute;
  top: 8px;
  right: 12px;
  background-color: rgba(255, 255, 255, 0.9);
  border: 2px solid #003366;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  color: #003366;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}


#loadingGraphCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

#loadingGraphSection {
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.4s ease;
  max-height: 1500px;
  opacity: 1;
  width: 100%;
  margin: 0 auto;
  background-color: #f4f4f4;
}

#loadingGraphSection.hidden {
  max-height: 0;
  opacity: 0;
}

.diagram-graph-flex {
  display: block;
}

#chartGrid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  margin: 20px auto;
  max-width: 100%;
}

@media (min-width: 768px) {
  #chartGrid {
    flex-direction: row;
    gap: 24px;
  }

  #chartGrid > div {
    width: 48%;
    max-width: 48%;
    flex: 1 1 48%;
  }
}


#cgEnvelopePlot,
#momentWeightPlot {
  display: block;
  width: 400px !important;
  height: 517px !important;
  max-width: 100%;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
}

@media (max-width: 768px) {
  #chartGrid {
    flex-direction: column;
    align-items: center;
  }
  #chartGrid > div {
    width: 100%;
    max-width: 100%;
  }
}

.wb-status-box {
  margin-top: 1rem;
  margin-bottom: 1rem;
  padding: 10px 16px;
  font-weight: bold;
  border-radius: 6px;
  text-align: center;
  font-size: 1rem;
  background-color: #eee;
  color: #333;
}

.wb-status-ok {
  background-color: #dff0d8;
  color: #3c763d;
  border: 2px solid #3c763d;
}

.wb-status-utility {
  background-color: #fff3cd;
  color: #856404;
  border: 2px solid #856404;
}

.wb-status-bad {
  background-color: #f8d7da;
  color: #721c24;
  border: 2px solid #721c24;
}

.wb-valid {
  background-color: #d4edda !important;
}

.wb-invalid {
  background-color: #f8d7da !important;
}

#momentLineSelector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

#momentLineSelector label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

#weightLineControls button {
  width: 48px;
  height: 48px;
  font-size: 24px;
  border-radius: 8px;
  border: none;
  background-color: #003366;
  color: white;
  font-weight: bold;
  transition: background 0.3s ease;
}

#weightLineControls button:hover {
  background-color: #00509e;
}

#momentLineSelector button {
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: bold;
  background-color: #888;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s ease;
}

#momentLineSelector button:hover {
  background-color: #555;
}
.envelope-plot-container .chart-wrapper.hidden {
  display: none !important;
}


@media (min-width: 768px) {
  .envelope-plot-container {
    flex-wrap: nowrap;
  }

  .envelope-plot-container .chart-wrapper {
    flex: 1 1 50%;
    max-width: 50%;
  }
}

@media (max-width: 767px) {
  .envelope-plot-container {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .envelope-plot-container .chart-wrapper {
    flex: 1 1 100% !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: auto;
  }

  #cgEnvelopePlot,
  #momentWeightPlot {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
  }

  #loadingGraphControlsWrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 1rem;
  }

  #momentLineSelector,
  #weightLineControls {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
  }

  #loadingGraphSection {
    display: block !important;
    margin-top: 0;
  }

  #loadingGraphSection .chart-wrapper {
    width: 100% !important;
    height: auto !important;
    overflow-x: auto;
  }

  #loadingGraphCanvas {
    width: 100% !important;
    max-width: 100% !important;
    height: 300px !important;
  }

  #chartGrid > div {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

@media (max-width: 767px) {
  #loadingGraphRow {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
}

@media (min-width: 768px) {
  #loadingGraphRow {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
  }
}

/* Loading Graph Flex Container */
.loading-graph-flex-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: stretch;
}

/* Keep the colorblind toggle visually grouped */
.colorblind-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

/* Mobile: stack (controls → colorblind → chart) */
@media (max-width: 767px) {
  .loading-graph-flex-container {
    flex-direction: column;
    align-items: stretch;
  }

  .loading-graph-flex-container > #loadingGraphControlsWrapper {
    order: 1;
    width: 100% !important;
  }

  .loading-graph-flex-container > .colorblind-wrapper {
    order: 2;
    width: 100% !important;
    text-align: center;
    margin: 0 auto 16px auto;
  }

  .loading-graph-flex-container > .chart-wrapper {
    order: 3;
    width: 100% !important;
    margin-top: 0;
  }
}

/* Desktop: row layout (controls left, chart right, colorblind next to controls) */
@media (min-width: 768px) {
  .loading-graph-flex-container {
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: nowrap;
  }

  /* Controls column */
  .loading-graph-flex-container > #loadingGraphControlsWrapper {
    order: 1;
    flex: 0 0 260px;
    min-width: 240px;
    max-width: 320px;
  }

  /* Chart column grows */
  .loading-graph-flex-container > .chart-wrapper {
    order: 2;
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Colorblind toggle stays near controls but does not force wrapping */
  .loading-graph-flex-container > .colorblind-wrapper {
    order: 3;
    flex: 0 0 auto;
    margin-top: 0;
    margin-bottom: 0;
    text-align: left;
  }
}


/* --- Fix aspect ratio when only the CG chart is shown --- */
.single-cg-only .chart-wrapper {
  flex: 1 1 100% !important;
  max-width: 100% !important;
}

.single-cg-only #cgEnvelopePlot {
  width: 100% !important;
  height: 560px !important;
  min-height: 560px !important;
}

.single-cg-only #momentWeightPlot {
  display: none !important;
}

/* Weight & Balance helpers (moved from wbLoader.js) */
.derived-arm {
  background-color: #f5f5f5;
  color: #333;
  font-style: italic;
  border: 1px dashed #ccc;
}

.required-field {
  border: 2px solid #e74c3c;
  background: #fff5f5;
}

.landing-opt-tag {
  color: #666;
  font-weight: normal;
}

/* =========================
   Phase D: Units switch & conversion row styling
   ========================= */
/* Units switch container (moved from inline) */
.wb-units-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.75rem;
  font-size: 0.9rem;
  vertical-align: middle;
  white-space: nowrap;
}
.wb-units-switch .wb-toggle input {
  display: none;
}
.wb-units-switch .labels {
  user-select: none;
  display: inline-flex;
  gap: 0.5rem;
  line-height: 1.2;
}
.wb-units-switch .imperial,
.wb-units-switch .metric {
  opacity: 0.6;
  transition: opacity 0.2s ease, font-weight 0.2s ease;
}
.wb-units-switch .wb-toggle input:not(:checked) ~ .labels .imperial {
  opacity: 1;
  font-weight: 600;
}
.wb-units-switch .wb-toggle input:checked ~ .labels .metric {
  opacity: 1;
  font-weight: 600;
}
/* Make sure the switch wraps nicely on narrow screens */
@media (max-width: 480px) {
  .wb-units-switch {
    display: inline-flex;
    gap: 0.35rem;
    font-size: 0.85rem;
    margin-left: 0.5rem;
    white-space: normal;
  }
  .wb-units-switch .labels {
    gap: 0.35rem;
    flex-wrap: wrap;
  }
}

/* Converted Totals (Metric) row visuals */
#wb-conversion-row {
  background: rgba(0, 0, 0, 0.04);
  border-top: 2px solid #ccc;
}
#wb-conversion-row td.label {
  font-weight: 600;
  color: #003366;
}
#wb-conversion-row td.value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Utility: soften hover on read-only rows */
.wb-table tr.readonly-row:hover,
#wb-conversion-row:hover {
  background-color: rgba(0,0,0,0.06);
}

/* Respect reduced motion preferences for Section 3 transitions */
@media (prefers-reduced-motion: reduce) {
  .frat-section3 {
    transition: none;
  }
  #loadingGraphSection {
    transition: none;
  }
}
