/*
 * ESP (Static Pressure) calculator.
 *
 * Loaded with the front-page calculator, on top of style.css, which
 * provides the CSS custom properties (--primary-color, --text-color, ...) and
 * the base reset. Enqueued from inc/enqueue.php under the `esp_calculator`
 * section.
 *
 * Everything is namespaced .esp-* on purpose: the base stylesheet ships broad
 * `input, select { ... }` rules globally, so unscoped selectors here would
 * fight them.
 *
 * Breakpoints match the rest of the theme: 600px, 768px (tablet), 992px
 * (laptop).
 */

/* ---------- Product Selection popup ---------- */
#staticPressureModal {
  padding: 16px;
}
#staticPressureModal .esp-calc {
  position: relative;
  margin: auto;
  width: 100%;
  max-width: 1120px;
  max-height: 95vh;
  overflow-y: auto;
}
.esp-calc [hidden] {
  display: none !important;
}
.esp-calc .popup__close-btn {
  top: 8px;
  right: 8px;
  font-size: 28px;
}
.esp-calc__title {
  padding-right: 32px;
}

/* ---------- Calculator card ---------- */
.esp-calc {
  background: var(--white);
  border: 1px solid #e4e7ea;
  border-radius: var(--border-radius);
  padding: 24px 16px;
}
@media (min-width: 768px) {
  .esp-calc {
    padding: 40px;
  }
}
.esp-calc__header {
  margin-bottom: 32px;
}
.esp-calc__title {
  font-size: 26px;
  margin: 0 0 8px;
}
.esp-calc__description {
  color: #6c757d;
  margin: 0 0 12px;
}
.esp-calc__formula {
  display: inline-block;
  margin: 0;
  padding: 10px 16px;
  background: #f4f6f7;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
}
.esp-calc__disclaimer {
  margin-top: 16px;
  padding: 14px 18px;
  border: 1px solid #e7d6a8;
  border-left: 4px solid #c9a227;
  border-radius: var(--border-radius);
  background: #fdf8e9;
  color: #5d4f22;
}
.esp-calc__disclaimer-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b5a1f;
}
.esp-calc__disclaimer-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}
.esp-calc__disclaimer-list li + li {
  margin-top: 4px;
}

/* ---------- Blocks and grid ---------- */
.esp-block {
  padding-top: 24px;
  margin-bottom: 8px;
  border-top: 1px solid #e4e7ea;
}
.esp-block:first-of-type {
  border-top: 0;
  padding-top: 0;
}
.esp-block__title {
  font-size: 18px;
  margin: 0 0 4px;
}
.esp-block__hint {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.6;
  color: #6d7b7d;
}

.esp-grid {
  display: grid;
  gap: 24px;
  margin-bottom: 24px;
}
@media (min-width: 768px) {
  .esp-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Fields, inputs, messages ---------- */
.esp-field {
  min-width: 0;
}
.esp-field--sm {
  flex: 1 1 150px;
}
.esp-field--xs {
  flex: 0 1 110px;
}
.esp-field--grow {
  flex: 1 1 190px;
}
.esp-field--static {
  display: flex;
  flex-direction: column;
}
.esp-field.has-error .esp-input {
  border-color: var(--primary-color);
}

.esp-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #6d7b7d;
}
.esp-label sup {
  color: var(--primary-color);
}

.esp-input-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.esp-calc .esp-input,
.esp-calc select.esp-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #cfd3dd;
  border-radius: 8px;
  background: var(--white);
  font-family: inherit;
  font-size: 16px;
  color: var(--text-color);
  outline: none;
  appearance: auto;
}
.esp-calc .esp-input:focus,
.esp-calc select.esp-input:focus {
  border-color: var(--primary-color);
}
.esp-calc .esp-input:disabled,
.esp-calc select.esp-input:disabled {
  background: #f4f6f7;
  color: #a0aaac;
}

/* Inside an input group the value field takes the free space and the unit
   control keeps its own width. min-width:0 stops the number input collapsing. */
.esp-calc .esp-input-group > .esp-input {
  flex: 1 1 auto;
  min-width: 0;
}

.esp-calc .esp-input-group > select.esp-input--unit {
  flex: 0 0 auto;
  width: auto;
  min-width: 96px;
}

.esp-unit {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  padding: 0 14px;
  border: 1px solid #cfd3dd;
  border-radius: 8px;
  background: #f4f6f7;
  font-size: 15px;
  color: #515b5d;
  white-space: nowrap;
}

.esp-output {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px dashed #cfd3dd;
  border-radius: 8px;
  background: #f9fafb;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
}

.esp-note {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: #6d7b7d;
}
.esp-note--limit {
  color: var(--text-color);
}
.esp-note--override {
  color: #8a6d1f;
}

.esp-disclaimer {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-left: 3px solid #cfd3dd;
  background: #f9fafb;
  font-size: 13px;
  line-height: 1.6;
  color: #515b5d;
}

.esp-error {
  display: none;
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--primary-color);
}
.esp-error.is-visible {
  display: block;
}

.esp-warning {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-left: 3px solid #d98b00;
  background: #fdf7ec;
  font-size: 13px;
  line-height: 1.6;
  color: #7a5600;
}
.esp-warning--inline {
  margin-top: 12px;
}

.esp-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary-color);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Duct sections ---------------------------------------------------------- */
/* ---------- Duct sections and diagram ---------- */
.esp-duct {
  display: grid;
  gap: 24px;
}
@media (min-width: 992px) {
  .esp-duct {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }
}
.esp-duct__diagram {
  margin: 0;
  padding: 16px;
  border: 1px dashed #cfd3dd;
  border-radius: 16px;
  text-align: center;
}
.esp-duct__diagram img {
  display: block;
  width: 100%;
  max-width: 400px;
  height: auto;
  margin: 0 auto;
}
.esp-duct__diagram figcaption {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #6d7b7d;
}

.esp-section {
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid #e4e7ea;
  border-radius: 12px;
  background: #fcfcfd;
}
.esp-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.esp-section__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.esp-section__inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.esp-section__readout {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px dashed #e4e7ea;
}
.esp-section__readout > div {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.esp-section__readout dt {
  font-size: 13px;
  color: #6d7b7d;
}
.esp-section__readout dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
}
.esp-section__unit {
  font-weight: 400 !important;
  color: #6d7b7d !important;
}

/* Fittings --------------------------------------------------------------- */
/* ---------- Fittings ---------- */
.esp-fitting {
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid #e4e7ea;
  border-radius: 12px;
  background: #fcfcfd;
}
.esp-fitting__main {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}

.esp-fittings__empty {
  margin: 0 0 12px;
  font-size: 14px;
  color: #6d7b7d;
}
.esp-fittings__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
}
.esp-fittings__total {
  margin: 0;
  font-size: 15px;
  color: #6d7b7d;
}
.esp-fittings__total strong {
  font-size: 18px;
  color: var(--text-color);
}

/* Result ----------------------------------------------------------------- */
/* ---------- Result ---------- */
.esp-result {
  padding: 20px;
  border: 1px solid #e4e7ea;
  border-radius: 12px;
  background: #fcfcfd;
}
.esp-result.is-stale {
  opacity: 0.55;
}
.esp-result.is-stale::after {
  content: "Inputs changed. Press Calculate to update the result.";
  display: block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--primary-color);
}
.esp-result__rows {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}
.esp-result__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-size: 15px;
  color: #515b5d;
}
.esp-result__row strong {
  color: var(--text-color);
}
.esp-result__total {
  padding: 18px 20px;
  border-radius: 10px;
  background: var(--primary-color);
  color: var(--white);
  text-align: center;
}
.esp-result__total-label {
  display: block;
  font-size: 14px;
  opacity: 0.9;
}
.esp-result__total-value {
  display: block;
  margin-top: 4px;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
}
.esp-result__total-converted {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.9;
}

.esp-warnings {
  margin-top: 16px;
}

.esp-legal {
  margin: 24px 0 0;
  font-size: 13px;
  color: #515b5d;
}
.esp-legal sup {
  color: var(--primary-color);
}

/* Actions ---------------------------------------------------------------- */
/* ---------- Actions ---------- */
.esp-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #e4e7ea;
}
@media (min-width: 600px) {
  .esp-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}
.esp-actions__right {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column-reverse;
  gap: 12px;
}
@media (min-width: 600px) {
  .esp-actions__right {
    flex-direction: row;
  }
}

.esp-btn {
  padding: 12px 22px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-color);
  cursor: pointer;
  transition: background-color var(--animation), color var(--animation), border-color var(--animation);
}
.esp-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.esp-btn--primary {
  background: var(--primary-color);
  color: var(--white);
}
.esp-btn--secondary {
  border-color: var(--primary-color);
  color: var(--primary-color);
}
.esp-btn--ghost {
  border-color: #cfd3dd;
  color: #515b5d;
}
.esp-btn--add {
  padding: 10px 18px;
  border-style: dashed;
  border-color: var(--primary-color);
  color: var(--primary-color);
  font-size: 14px;
}
.esp-btn--remove {
  padding: 8px 14px;
  border-color: #cfd3dd;
  font-size: 13px;
  color: #6d7b7d;
}

/* Report ----------------------------------------------------------------- */
/* ---------- PDF report ---------- */
.esp-report-host {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 794px;
  overflow: hidden;
}

/* Fluid on purpose. html2pdf clones this element into its own container sized
   to the printable page width, so a fixed pixel width would overflow and be
   cut off on the right. The host above gives it its on-screen width. */
.esp-report {
  width: 100%;
  max-width: 794px;
  padding: 32px;
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #292e2f;
}
.esp-report__header {
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--primary-color);
}
.esp-report__header h1 {
  margin: 0 0 6px;
  font-size: 19px;
}
.esp-report__meta {
  display: flex;
  justify-content: space-between;
  margin: 0;
  font-size: 11px;
  color: #6d7b7d;
}
.esp-report h2 {
  margin: 22px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e4e7ea;
  font-size: 14px;
}
.esp-report h3 {
  margin: 14px 0 4px;
  font-size: 13px;
}
.esp-report__dims {
  margin: 0 0 6px;
  font-size: 11px;
  color: #6d7b7d;
}
.esp-report__table {
  width: 100%;
  margin-bottom: 10px;
  border-collapse: collapse;
  page-break-inside: avoid;
}
.esp-report__table th,
.esp-report__table td {
  padding: 6px 8px;
  border: 1px solid #e4e7ea;
  text-align: left;
  vertical-align: top;
}
.esp-report__table thead th {
  background: #f4f6f7;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.esp-report__table tbody th {
  width: 30%;
  font-weight: 500;
}
.esp-report__formula {
  font-family: "Courier New", monospace;
  font-size: 11px;
  color: #515b5d;
}
.esp-report__value {
  width: 22%;
  font-weight: 700;
  text-align: right;
}
.esp-report__final {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 2px solid var(--primary-color);
  background: #f4f6f7;
  page-break-inside: avoid;
}
.esp-report__final-formula {
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: #515b5d;
}
.esp-report__final-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary-color);
}
.esp-report__warnings {
  margin: 0;
  padding-left: 18px;
}
.esp-report__warnings li {
  margin-bottom: 4px;
}
.esp-report__footer {
  margin-top: 24px;
  padding-top: 10px;
  border-top: 1px solid #e4e7ea;
  font-size: 10px;
  color: #6d7b7d;
}
.esp-report__disclaimer {
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid #e7d6a8;
  border-left: 3px solid #c9a227;
  background: #fdf8e9;
  color: #5d4f22;
  page-break-inside: avoid;
}
.esp-report__disclaimer-title {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.esp-report__disclaimer-list {
  margin: 0;
  padding-left: 14px;
  font-size: 10px;
  line-height: 1.5;
}
.esp-report__footnote {
  margin: 0;
}
