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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f4f8;
  color: #1a1a2e;
  min-height: 100vh;
}

header {
  background: #1a1a2e;
  color: white;
  padding: 0.7rem 2rem;
  text-align: center;
}

header h1 {
  font-size: 1.3rem;
  margin-bottom: 0.2rem;
}

header p {
  color: #a0aec0;
}

.back-link {
  display: inline-block;
  color: #63b3ed;
  text-decoration: none;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.back-link:hover {
  text-decoration: underline;
}

/* ── Main menu ── */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  padding: 2.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.card img {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.card h2 {
  font-size: 1.3rem;
  color: #2d3748;
}

.card p {
  font-size: 0.9rem;
  color: #718096;
  line-height: 1.5;
}

/* ── Language selector ── */
.lang-selector {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  display: flex;
  gap: 0.4rem;
}
.lang-selector a {
  color: #a0aec0;
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid #4a5568;
  transition: background 0.15s;
}
.lang-selector a:hover,
.lang-selector a.lang-active {
  background: #2d3748;
  color: white;
  border-color: #63b3ed;
}
header { position: relative; }

/* ── Compact 2-col field grid ── */
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0.75rem;
}
.fields-grid .span2 { grid-column: span 2; }

/* ── Fin-and-tube layout ── */
.fat-layout {
  display: grid;
  grid-template-columns: 1.0fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1700px;
  margin: 0 auto;
}
.fat-layout .inputs-panel { grid-row: span 2; }
.fat-layout .pdf-panel,
.fat-layout .chart-panel {
  background: white;
  border-radius: 12px;
  padding: 0.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.fat-layout .chart-panel { grid-column: span 2; }
@media (max-width: 900px) {
  .fat-layout { grid-template-columns: 1fr; }
  .fat-layout .inputs-panel { grid-row: auto; }
  .fat-layout .chart-panel { grid-column: auto; }
}

/* ── Computed display fields ── */
.computed-row {
  display: flex; gap: 1.5rem; align-items: center;
  color: #555; font-size: 0.82em; padding: 2px 0 4px;
  grid-column: span 2;
}
.computed-row b { color: #222; }

/* ── Input with inline unit selector ── */
.input-with-unit { display: flex; gap: 4px; }
.input-with-unit input { flex: 1; min-width: 0; text-align: right; }
.input-with-unit select { width: auto; padding: 0 4px; }
.unit-label { font-size: 0.85rem; color: #718096; white-space: nowrap; align-self: center; }

/* ── Quantity input: number field + switchable unit selector (ṁ, Q̇, v_fr) ── */
.qty-input { display: flex; flex: 1; min-width: 0; gap: 4px; }
.qty-input input[type="number"] { flex: 1; min-width: 70px; text-align: right; }
.qty-input select { flex: 0 0 auto; appearance: none; -webkit-appearance: none; background-image: none; padding-right: 0.4rem; }
/* beats fat-layout generic select rules */
.fat-layout .fields-grid label:not(.span2) .qty-input select { flex: 0 0 auto; appearance: none; -webkit-appearance: none; background-image: none; padding-right: 0.4rem; }

/* ── Two side-by-side charts ── */
.chart-row { display: flex; gap: 1rem; }
.chart-box { flex: 1; min-width: 0; }
.chart-box h3 { font-size: 0.88em; margin: 0 0 4px; color: #444; font-weight: 600; }

/* ── Calculator page (generic) ── */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  padding: 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 720px) {
  .calculator-layout {
    grid-template-columns: 1fr;
  }
}

.inputs-panel,
.results-panel {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.inputs-panel {
  min-width: 750px;
}

h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: #2d3748;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 0.5rem;
  padding-left: 0.7rem;
}

fieldset {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

legend {
  font-weight: 600;
  color: #4a5568;
  padding: 0 0.5rem;
  font-size: 0.9rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: #4a5568;
  margin-bottom: 0.75rem;
}

.field-hint {
  font-size: 0.75rem;
  color: #a0aec0;
  margin-top: 0.2rem;
}

input[type="number"],
select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.95rem;
  width: 100%;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ── Fin-and-tube: inline label (text + input together, left-aligned) ── */
.fat-layout .fields-grid label:not(.span2) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}
.fat-layout .fields-grid label:not(.span2) input {
  width: 90px;
  flex-shrink: 0;
  text-align: right;
}

/* ── Parameter tooltip (ⓘ icon with hover popup, appears to the right) ── */
.tip {
  font-style: normal;
  font-size: 0.68rem;
  color: #b0bec5;
  cursor: default;
  position: relative;
  display: inline-block;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  bottom: auto;
  background: #2d3748;
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 400;
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  width: 250px;
  white-space: normal;
  line-height: 1.4;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.12s;
}
.tip:hover::after {
  opacity: 1;
}

/* ── 3-column grid (fin-geom / fluid sections) ── */
.fields-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
  column-gap: 1.2rem;
}
.fields-grid.cols-3 .span2,
.fields-grid.cols-3 .computed-row {
  grid-column: span 3;
}
/* Select stretches to fill remaining space when inside a flex label row */
.fat-layout .fields-grid label:not(.span2) select {
  flex: 1;
  min-width: 0;
  width: auto;
}
/* Except inside inline-inputs-row where it should stay natural width */
.fat-layout .fields-grid .inline-inputs-row label:not(.span2) select {
  flex: 0 0 auto;
  width: auto;
}
/* input-with-unit (ṁ / Q̇) stretches to fill remaining label space in cols-3 */
.fat-layout .fields-grid.cols-3 label:not(.span2) .input-with-unit {
  flex: 1;
  min-width: 0;
}
.fat-layout .fields-grid.cols-3 label:not(.span2) .input-with-unit input {
  flex: 1;
  width: auto;
  min-width: 55px;
}
.fat-layout .fields-grid.cols-3 label:not(.span2) .input-with-unit select {
  flex: 0 0 auto;
}

/* ── 4-column tube-geometry grid ── */
.fields-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
  column-gap: 1.2rem;
}
.fields-grid.cols-4 label:not(.span2) {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
}
.fields-grid.cols-4 label:not(.span2) input {
  width: 90px;
  flex-shrink: 0;
}
.fields-grid.cols-4 .computed-row,
.fields-grid.cols-4 .span2 {
  grid-column: span 4;
}

/* ── Fluid fieldsets: 35% fluid col + 3 equal cols ── */
.fields-grid.fluid-grid {
  grid-template-columns: 25% 1fr 1fr 1fr;
  column-gap: 0.8rem;
}
.fields-grid.fluid-grid .span2 {
  grid-column: span 4;
}
/* Flex row per label, label text pinned left and never wraps */
.fields-grid.fluid-grid label:not(.span2) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}
/* Labels that hold a fixed-width input-unit-wrap (T, P): grid layout so the
   input is always right-aligned at the same position regardless of label text */
.fields-grid.fluid-grid label:not(.span2):has(.input-unit-wrap) {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem;
}
.fields-grid.fluid-grid label:not(.span2) > span {
  white-space: nowrap;
  flex-shrink: 0;
}
/* Fluid dropdown fills its column */
.fields-grid.fluid-grid label:not(.span2) > select {
  flex: 1;
  min-width: 0;
  width: auto;
}

/* ── Inline row: fin geom / tube fluid inputs on one line ── */
.inline-inputs-row {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.fat-layout .fields-grid .inline-inputs-row label:not(.span2) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  margin-bottom: 0;
}
.inline-inputs-row .computed-row {
  grid-column: unset;
  padding: 0;
  font-size: 0.82rem;
}

/* ── Input with inline unit suffix ── */
.input-unit-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 90px;
  flex-shrink: 0;
}
.input-unit-wrap input {
  width: 100%;
  text-align: right;
  padding-right: 2.0rem !important;
}
.input-unit-suffix {
  position: absolute;
  right: 0.4rem;
  font-size: 0.74rem;
  color: #a0aec0;
  font-weight: 400;
  pointer-events: none;
  user-select: none;
  line-height: 1;
  white-space: nowrap;
}
.fat-layout .fields-grid label.span2 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}
.fat-layout .fields-grid label.span2 select {
  width: auto;
  min-width: 0;
  flex-shrink: 1;
}
#tube_fluid, select[name="air_fluid"] {
  min-width: 110px;
}

/* ── Custom-styled dropdowns ── */
.fat-layout select {
  -webkit-appearance: none;
  appearance: none;
  background-color: #f8fafc;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23718096' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 10px 6px;
  padding-right: 1.8rem;
  cursor: pointer;
}

/* ── Integer spinner widget (N_rows, N_tubes, N_serpentines) ── */
.int-spinner {
  display: inline-flex;
  align-items: stretch;
  width: 90px;
  flex-shrink: 0;
}
.int-spinner input[type="number"] {
  flex: 1;
  min-width: 0;
  width: auto !important;
  border-right: none;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.int-spinner-btns {
  display: flex;
  flex-direction: column;
  border: 1px solid #cbd5e0;
  border-left: none;
  border-radius: 0 6px 6px 0;
  overflow: hidden;
  flex-shrink: 0;
}
.int-spin-up,
.int-spin-dn {
  background: #f7fafc;
  border: none;
  cursor: pointer;
  width: 20px;
  flex: 1;
  font-size: 7px;
  color: #4a5568;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  padding: 0;
}
.int-spin-up { border-bottom: 1px solid #e2e8f0; }
.int-spin-up:hover,
.int-spin-dn:hover { background: #e2e8f0; }
.int-spin-up:active,
.int-spin-dn:active { background: #cbd5e0; }

/* ── Fin-and-tube: tighter fieldsets ── */
.fat-layout fieldset {
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.55rem;
}
.fat-layout .fields-grid {
  column-gap: 1.8rem;
}
.fat-layout input[type="number"],
.fat-layout select {
  padding: 0.3rem 0.45rem;
  font-size: 0.88rem;
}
.fat-layout button[type="submit"] {
  padding: 0.55rem;
}

/* ── Detail results collapsible ── */
details.detail-section {
  margin-top: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}
details.detail-section summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #4a5568;
  padding: 0.3rem 0;
  user-select: none;
}
details.detail-section summary:hover { color: #2d3748; }

input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66,153,225,0.2);
}

button.btn-calculate {
  width: 100%;
  padding: 0.7rem 1rem;
  background: linear-gradient(135deg, #1a1a2e 0%, #2d2d4e 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  margin-top: 0.5rem;
  box-shadow: 0 2px 8px rgba(26,26,46,0.35);
  transition: transform 0.1s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
button.btn-calculate::before {
  content: '▶';
  font-size: 0.7em;
  opacity: 0.85;
}
button.btn-calculate:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(26,26,46,0.45);
}
button.btn-calculate:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(26,26,46,0.3);
}
button.btn-calculate:disabled {
  background: linear-gradient(135deg, #a0aec0 0%, #718096 100%);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

/* ── Method section pill toggle ── */
.method-toggle {
  display: flex;
  margin-bottom: 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  overflow: hidden;
  width: fit-content;
}
.method-opt input[type="radio"] { display: none; }
.method-opt span {
  display: block;
  padding: 0.3rem 1.1rem;
  font-size: 0.84rem;
  cursor: pointer;
  background: #fff;
  color: #4a5568;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.method-opt:not(:last-child) span { border-right: 1px solid #cbd5e0; }
.method-opt input[type="radio"]:checked + span {
  background: #1a1a2e;
  color: #fff;
}
.btn-pdf {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding: 0.35rem 0.9rem;
  background: #f7fafc;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  color: #2d3748;
  font-size: 0.85rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn-pdf::before { content: '📄'; font-size: 0.9em; }
.btn-pdf:hover {
  background: #edf2f7;
  border-color: #a0aec0;
}

/* ── Results ── */
.results-panel[hidden] {
  display: none;
}

/* ── Result tabs ── */
.result-tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1rem;
}
.result-tab {
  padding: 0.38rem 1.1rem;
  font-size: 0.83rem;
  font-weight: 600;
  border: none;
  background: none;
  color: #718096;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.result-tab:hover { color: #2d3748; }
.result-tab.active { color: #2b6cb0; border-bottom-color: #2b6cb0; }
.result-tab-content[hidden] { display: none; }
.no-advanced-msg { color: #a0aec0; font-size: 0.85rem; padding: 0.5rem 0; }

/* Generic results: 2 columns so rows stay compact */
#results-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 1.2rem;
}
/* Structured (annular) res-block spans both columns and uses its own 2×2 grid */
#results-content .res-block {
  grid-column: span 2;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  border-bottom: 1px solid #f7fafc;
  font-size: 0.85rem;
}

.result-row:last-child {
  border-bottom: none;
}

.result-key {
  color: #4a5568;
}

.result-value {
  font-weight: 600;
  color: #2b6cb0;
}

/* ── KPI cards (main results) ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}

.kpi-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-top: 3px solid var(--kpi-color, #4299e1);
  border-radius: 10px;
  padding: 0.85rem 0.5rem 0.7rem;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  transition: box-shadow 0.15s;
}

.kpi-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #718096;
  line-height: 1.2;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--kpi-color, #2b6cb0);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 0.7rem;
  color: #a0aec0;
  font-weight: 500;
  margin-top: 0.05rem;
}

/* ── Structured result rows ── */
.fat-layout .results-panel { background: #f0f4f8; padding: 0.85rem 1rem; }

.res-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
}

.res-row {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.4rem 0.65rem 0.4rem 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  border-left: 3px solid #cbd5e0;
}
.res-row--q    { border-left-color: #dd6b20; }
.res-row--tube { border-left-color: #c05621; }
.res-row--air  { border-left-color: #2b6cb0; }
.res-row--dims { border-left-color: #2c7a7b; }

.res-row-header {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #a0aec0;
  margin-bottom: 0.25rem;
  padding-bottom: 0.18rem;
  border-bottom: 1px solid #f0f4f8;
  text-align: left;
}
.res-row--q    .res-row-header { color: #dd6b20; }
.res-row--tube .res-row-header { color: #c05621; }
.res-row--air  .res-row-header { color: #2b6cb0; }
.res-row--dims .res-row-header { color: #2c7a7b; }

.res-q-value { display: flex; align-items: baseline; gap: 0.3rem; }
.res-q-num   { font-size: 1.45rem; font-weight: 700; color: #dd6b20; letter-spacing: -0.02em; }
.res-q-unit  { font-size: 0.9rem; color: #718096; }
.res-q-meta  { font-size: 0.75rem; color: #718096; margin-top: 0.1rem; }

.res-trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.res-quad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }

.rc-cell  { text-align: center; padding: 0.15rem 0.05rem; }
.rc-label { font-size: 0.72rem; font-weight: 600; color: #718096; margin-bottom: 0.05rem; }
.rc-val   { font-size: 0.95rem; font-weight: 700; color: #2d3748; line-height: 1.2; }
.rc-unit  { font-size: 0.68rem; color: #a0aec0; margin-top: 0.02rem; }

/* ── Advanced result unit badge ── */
.result-value-with-unit { display: flex; align-items: baseline; gap: 0.25rem; }
.result-unit { font-size: 0.72rem; color: #a0aec0; font-weight: 400; }

/* ── Advanced results compact table ── */
.adv-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.adv-cell {
  padding: 0.15rem 0.3rem;
  border: 1px solid #e2e8f0;
  vertical-align: top;
  width: 12.5%;
}
.adv-cell-empty { background: #fafafa; }
.adv-cell-label {
  display: block;
  color: #718096;
  font-size: 0.63rem;
  margin-bottom: 0.05rem;
  white-space: nowrap;
}
.adv-cell-value {
  display: inline;
  font-weight: 600;
  color: #2b6cb0;
  font-size: 0.75rem;
}
.adv-cell-unit {
  display: inline;
  color: #a0aec0;
  font-size: 0.6rem;
  margin-left: 0.15rem;
}

/* ── Save / Load cases bar ── */
.cases-bar {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.btn-case {
  flex: 1;
  padding: 0.3rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  background: #fff;
  color: #4a5568;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-case:hover { background: #edf2f7; border-color: #a0aec0; }

/* ── Cases dropdown panel ── */
.cases-panel {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.65rem;
  margin-top: 0.4rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.cases-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 0.45rem;
}

.btn-close-panel {
  background: none;
  border: none;
  cursor: pointer;
  color: #a0aec0;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.btn-close-panel:hover { color: #4a5568; }

.cases-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}

.case-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #f7fafc;
  font-size: 0.78rem;
}
.case-item:last-child { border-bottom: none; }

.case-name { flex: 1; font-weight: 600; color: #2d3748; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-date { font-size: 0.68rem; color: #a0aec0; white-space: nowrap; }

.btn-case-load {
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
  background: #ebf8ff;
  color: #2b6cb0;
  border: 1px solid #bee3f8;
  border-radius: 4px;
  cursor: pointer;
}
.btn-case-load:hover { background: #bee3f8; }

.btn-case-del {
  padding: 0.15rem 0.35rem;
  font-size: 0.72rem;
  background: #fff5f5;
  color: #e53e3e;
  border: 1px solid #fed7d7;
  border-radius: 4px;
  cursor: pointer;
}
.btn-case-del:hover { background: #fed7d7; }

.cases-empty {
  padding: 0.65rem;
  text-align: center;
  color: #a0aec0;
  font-size: 0.78rem;
  font-style: italic;
}

.btn-case-upload {
  width: 100%;
  padding: 0.3rem;
  font-size: 0.75rem;
  background: #f7fafc;
  border: 1px dashed #cbd5e0;
  border-radius: 6px;
  color: #4a5568;
  cursor: pointer;
}
.btn-case-upload:hover { background: #edf2f7; }

/* ── Word report button ── */
.btn-report {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid #bee3f8;
  border-radius: 6px;
  background: #ebf8ff;
  color: #2b6cb0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-report:hover    { background: #bee3f8; border-color: #90cdf4; }
.btn-report:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Reference + Circuit side-by-side layout ── */
.diagram-row {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}
.method-section { display: none; }
.diagram-row > .pdf-panel:not(.circuit-panel) {
  flex: 1 1 0;
  min-width: 0;
}
.diagram-row > .circuit-panel {
  flex: 0 0 42%;
  max-width: 42%;
}
@media (max-width: 900px) {
  .diagram-row { flex-wrap: wrap; }
  .diagram-row > .circuit-panel { flex: 1 1 100%; max-width: 100%; }
}

/* ── Action bar (Save / Load / Report) ── */
.action-bar {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.btn-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.32rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-action-save  { background: #f0fff4; border-color: #9ae6b4; color: #276749; }
.btn-action-save:hover  { background: #c6f6d5; border-color: #68d391; }
.btn-action-load  { background: #fffff0; border-color: #faf089; color: #744210; }
.btn-action-load:hover  { background: #fefcbf; border-color: #f6e05e; }
.btn-action-report { background: #ebf8ff; border-color: #bee3f8; color: #2b6cb0; }
.btn-action-report:hover { background: #bee3f8; border-color: #90cdf4; }
.btn-action:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Fluid temperature range hint ── */
.fluid-range-note {
  font-size: 0.72rem;
  color: #a0aec0;
  padding: 1px 0 4px;
  min-height: 1em;
}

/* ── Custom modal dialog ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: white;
  border-radius: 14px;
  padding: 1.6rem 2rem 1.4rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.22);
}

.modal-msg {
  font-size: 0.95rem;
  color: #2d3748;
  margin: 0 0 1.1rem;
  line-height: 1.55;
  min-height: 1.2em;
}

.modal-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 7px;
  font-size: 0.93rem;
  margin-bottom: 1rem;
  box-sizing: border-box;
}
.modal-input:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66,153,225,0.2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.modal-btn {
  padding: 0.42rem 1.1rem;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.modal-btn-ok {
  background: #1a1a2e;
  color: white;
  border-color: #1a1a2e;
}
.modal-btn-ok:hover { background: #2d2d4e; }

.modal-btn-cancel {
  background: white;
  color: #4a5568;
  border-color: #cbd5e0;
}
.modal-btn-cancel:hover { background: #edf2f7; border-color: #a0aec0; }

.modal-btn-secondary {
  background: #f7fafc;
  color: #2d3748;
  border-color: #cbd5e0;
}
.modal-btn-secondary:hover { background: #edf2f7; border-color: #a0aec0; }

.error-message {
  color: #e53e3e;
  background: #fff5f5;
  border: 1px solid #feb2b2;
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.9rem;
}

.loading {
  color: #718096;
  font-style: italic;
}

.inline-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.inline-field .field-name {
  display: inline;
}

@media (max-width: 900px) {
  .fields-grid.fluid-grid {
    grid-template-columns: 35% 1fr 1fr;
  }
}