/**
 * WI Serial Family Support Calculator — styles.
 * All selectors scoped under .wi-sf-calc to avoid Divi collisions.
 * Conventions copied from the approved series CSS (WI-HIGH/WI-SPLIT):
 * Divi neutralization, $ overlay, ::picker-icon hide, stacked-card table.
 * Serial-specific: obligation row cards, ledger table, summary block.
 * Specificity guards + !important on form controls: Divi ships aggressive
 * input/select styling on .et_pb_* pages; these overrides are intentional
 * and proven necessary (visual regression on dev, 2026-08-28).
 */

.wi-sf-calc {
  max-width: 720px;
  margin: 2em auto;
  padding: 1.75em;
  background: #fff;
  border: 1px solid #dfe3e6;
  border-radius: 8px;
  font-family: Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #293e4d;
  box-sizing: border-box;
}

.wi-sf-calc *,
.wi-sf-calc *::before,
.wi-sf-calc *::after {
  box-sizing: border-box;
}

.wi-sf-calc__title {
  margin-top: 0;
  font-family: 'Roboto Slab', Roboto, serif;
  color: #293e4d;
}

/* ---------- Fields: identical geometry for every control ---------- */

.wi-sf-calc__field {
  margin: 0 0 1.25em;
}

.wi-sf-calc__field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4em;
}

/* One shared control style: same width, height, border, radius.
   Divi resets neutralized via explicit properties + !important.
   NOTE: background-COLOR (not shorthand `background`) so the select's
   chevron background-image below isn't clobbered, and so Divi's own
   select background-image (its double-caret) stays overridden. */
.wi-sf-calc__field input,
.wi-sf-calc__field select,
.wi-sf-calc__ob-grid input:not([type=checkbox]),
.wi-sf-calc__ob-grid select {
  display: block !important;
  width: 100% !important;
  height: 48px !important;
  margin: 0 !important;
  padding: 0 14px !important;
  border: 1px solid #c9c9c9 !important;
  border-radius: 6px !important;
  background: #fff !important;
  color: #222 !important;
  font-family: inherit !important;
  font-size: 1em !important;
  line-height: 46px !important;
  box-shadow: none !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: textfield !important;
}

/* Custom chevron for selects — drawn AFTER the background reset above.
   `background` shorthand (not background-color) fully clears any Divi
   select background-image (the source of the double-caret bug). */
.wi-sf-calc__field select,
.wi-sf-calc__ob-grid select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23555' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 14px center !important;
  background-color: #fff !important;
  padding-right: 36px !important;
}

/* Chrome 135+ renders the native select arrow as a ::picker-icon
   pseudo-element that appearance:none no longer hides — it stacked on
   top of our custom chevron (user-visible double caret). Hide it. */
.wi-sf-calc__field select::picker-icon,
.wi-sf-calc__ob-grid select::picker-icon {
  display: none !important;
}

/* Legacy Edge/IE select arrow */
.wi-sf-calc__field select::-ms-expand,
.wi-sf-calc__ob-grid select::-ms-expand {
  display: none !important;
}

.wi-sf-calc__field input:focus,
.wi-sf-calc__field select:focus,
.wi-sf-calc__ob-grid input:focus:not([type=checkbox]),
.wi-sf-calc__ob-grid select:focus {
  outline: none !important;
  border-color: #0071e3 !important;
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15) !important;
}

.wi-sf-calc__field input::placeholder,
.wi-sf-calc__ob-grid input::placeholder {
  color: #9a9a9a;
  opacity: 1;
}

/* ---------- Currency fields: $ overlaid INSIDE the input ----------
   No attached prefix component = no seams, no height mismatch, no
   width difference. The input spans the full row exactly like a select;
   the symbol is absolutely positioned over the padding area. */
.wi-sf-calc__money {
  position: relative;
  display: block;
}

.wi-sf-calc__symbol {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 400;
  font-size: 1em;
  color: #9a9a9a;
  pointer-events: none;
  line-height: 1;
}

.wi-sf-calc__money input {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-left: 28px !important;
}

/* Date inputs: line-height 46px breaks Chrome's internal date layout —
   the mm/dd/yyyy text rides too high and the picker icon misaligns.
   Re-center date inputs vertically like every other control. */
.wi-sf-calc__ob-grid input[type=date] {
  line-height: normal !important;
  padding-right: 8px !important;
}

/* ---------- Required / optional markers ---------- */

.wi-sf-calc__required {
  color: #c0392b;
  font-weight: 700;
}

.wi-sf-calc__legend {
  font-size: 0.88em;
  color: #555;
  margin: 0.25em 0 1.25em;
}

.wi-sf-calc__hint {
  font-size: 0.88em;
  color: #576f81;
  margin: 0.45em 0 0;
  line-height: 1.45;
}

.wi-sf-calc__optional {
  font-weight: 400;
  color: #777;
}

/* ---------- Submit ---------- */

.wi-sf-calc__submit {
  display: inline-block !important;
  width: auto !important;
  height: auto !important;
  background: #0071e3 !important;
  color: #fff !important;
  border: 0 !important;
  border-radius: 6px !important;
  padding: 0.75em 1.6em !important;
  font-family: Roboto, Arial, sans-serif !important;
  font-size: 1em !important;
  font-weight: 600 !important;
  line-height: 1.4 !important;
  cursor: pointer;
  box-shadow: none !important;
}

.wi-sf-calc__submit:hover,
.wi-sf-calc__submit:focus {
  background: #005bbf !important;
}

.wi-sf-calc__submit:focus {
  outline: 2px solid #0071e3;
  outline-offset: 2px;
}

/* ---------- Result area ---------- */

.wi-sf-calc__result {
  margin-top: 1em;
}

.wi-sf-calc__error {
  background: #fdecea;
  border-left: 4px solid #c0392b;
  padding: 0.8em 1em;
  border-radius: 4px;
  margin: 1em 0;
}

.wi-sf-calc__warning {
  background: #fff8e1;
  border: 1px solid #f0c36d;
  border-radius: 6px;
  padding: 1em 1.25em;
  margin: 1em 0;
}

.wi-sf-calc__basis {
  background: #eef4fb;
  border-left: 4px solid #0071e3;
  padding: 0.6em 1em;
  border-radius: 4px;
  margin: 0 0 1em;
}

.wi-sf-calc__table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  /* Ledger has 5 columns in a ~660px card — fixed layout with explicit
     widths keeps long cells ("3 children — existing order") on one line. */
  table-layout: fixed;
  font-size: 0.95em;
}

.wi-sf-calc__table th:nth-child(1) { width: 16%; }
.wi-sf-calc__table th:nth-child(2) { width: 20%; }
.wi-sf-calc__table th:nth-child(3) { width: 26%; }
.wi-sf-calc__table th:nth-child(4) { width: 16%; }
.wi-sf-calc__table th:nth-child(5) { width: 22%; }

.wi-sf-calc__table-title {
  font-weight: 700;
  font-size: 1.05em;
  margin: 0 0 0.5em;
  line-height: 1.4;
}

.wi-sf-calc__table th,
.wi-sf-calc__table td {
  border: 1px solid #dcdcdc;
  /* !important: Divi .entry-content tr td (6px 24px, higher specificity)
     overrides em padding and squeezes columns into wrapping */
  padding: 0.5em 0.6em !important;
  text-align: left;
}

.wi-sf-calc__table thead th {
  white-space: nowrap;
  background: #f5f5f5;
}

.wi-sf-calc__table tfoot th,
.wi-sf-calc__table tfoot td {
  font-weight: 700;
  background: #f9f9f9;
}

.wi-sf-calc__source {
  font-size: 0.9em;
  color: #555;
  margin-top: 1em;
}

.wi-sf-calc__route-link {
  display: inline-block;
  margin-top: 0.5em;
  font-weight: 600;
  /* styled as a link (it's a <button> that opens the consult modal) */
  background: none;
  border: none;
  padding: 0;
  color: #0071e3;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  text-decoration: underline;
}
.wi-sf-calc__route-link:hover {
  color: #293e4d;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .wi-sf-calc {
    padding: 1.1em;
  }
}

/* ---------- Results table on mobile ----------
   Standard responsive-table pattern: each row becomes a stacked
   card. Column headers hide; every cell shows its data-label as an
   inline caption. Table headers (scope=row) act as the card title. */
@media (max-width: 768px) {
  .wi-sf-calc__table,
  .wi-sf-calc__table tbody,
  .wi-sf-calc__table tr,
  .wi-sf-calc__table th,
  .wi-sf-calc__table td {
    display: block;
    width: 100%;
  }

  .wi-sf-calc__table {
    border: 0;
  }

  .wi-sf-calc__table thead {
    /* Visually hidden but kept for screen readers */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .wi-sf-calc__table-title {
    font-size: 1.05em;
    margin-bottom: 0.6em;
  }

  .wi-sf-calc__table tr {
    border: 1px solid #dcdcdc;
    border-radius: 6px;
    margin-bottom: 0.75em;
    padding: 0.25em 0;
    background: #fff;
  }

  .wi-sf-calc__table tbody th {
    background: #f5f5f5;
    font-weight: 700;
    padding: 0.55em 0.75em;
    border-bottom: 1px solid #dcdcdc;
  }

  .wi-sf-calc__table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1em;
    padding: 0.45em 0.75em;
    border: 0;
  }

  .wi-sf-calc__table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #576f81;
    text-align: left;
  }

  .wi-sf-calc__table td {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  /* Totals: label + value on one line (flex row) */
  .wi-sf-calc__table tfoot tr {
    display: flex;
    align-items: baseline;
    gap: 0.75em;
    border: 0;
    border-top: 1px solid #dcdcdc;
    border-radius: 0;
    margin-bottom: 0;
  }
  .wi-sf-calc__table tfoot th,
  .wi-sf-calc__table tfoot td {
    width: auto !important;
    border: 0;
    background: transparent !important;
  }
  .wi-sf-calc__table tfoot th {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.45em 0.5em;
    text-align: left;
  }
  .wi-sf-calc__table tfoot td {
    flex: 0 0 auto;
    min-width: 0;
    padding: 0.45em 0.5em 0.55em;
    text-align: right;
    white-space: nowrap;
  }
  .wi-sf-calc__table tfoot th[colspan] {
    border-bottom: 0;
    padding-bottom: 0.1em;
  }
}
/* ---------- Serial-family specifics ---------- */

.wi-sf-calc__obligations {
  border: 1px solid #dfe3e6;
  border-radius: 6px;
  padding: 1em;
  margin: 0 0 1.25em;
  background: #fafbfc;
}

.wi-sf-calc__obligations-title {
  font-weight: 700;
  margin: 0 0 0.75em;
  color: #293e4d;
}

.wi-sf-calc__ob-row {
  border: 1px solid #dfe3e6;
  border-radius: 6px;
  background: #fff;
  padding: 0.9em;
  margin-bottom: 0.9em;
  position: relative;
}

.wi-sf-calc__ob-row-title {
  font-weight: 700;
  font-size: 0.92em;
  color: #576f81;
  margin: 0 0 0.6em;
}

.wi-sf-calc__ob-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75em;
}

.wi-sf-calc__ob-grid label {
  display: block;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 0.3em;
}

.wi-sf-calc__ob-grid .wi-sf-calc__hint {
  margin-top: 0.25em;
}

.wi-sf-calc__ob-check {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.5em;
}

/* Checkbox wrapper spans the full grid width — squeezed into one column
   its label wraps into a tall unreadable sliver. */
.wi-sf-calc__ob-grid > div:has(> .wi-sf-calc__ob-check) {
  grid-column: 1 / -1;
}

.wi-sf-calc__ob-check input[type=checkbox] {
  appearance: auto !important;
  -webkit-appearance: checkbox !important;
  width: 16px !important;
  height: 16px !important;
  line-height: normal !important;
  padding: 0 !important;
}

.wi-sf-calc__ob-check label {
  font-weight: 400;
  margin: 0;
}

.wi-sf-calc__add-btn {
  background: #fff !important;
  color: #0071e3 !important;
  border: 1px solid #0071e3 !important;
  border-radius: 6px !important;
  padding: 0.5em 1em !important;
  font-family: inherit !important;
  font-size: 0.95em !important;
  font-weight: 600 !important;
  cursor: pointer;
  width: auto !important;
  height: auto !important;
  line-height: 1.4 !important;
}

.wi-sf-calc__add-btn:hover {
  background: #f0f7ff !important;
}

.wi-sf-calc__summary {
  background: #eef4fb;
  border-left: 4px solid #0071e3;
  border-radius: 4px;
  padding: 0.9em 1em;
  margin: 0 0 1em;
}

.wi-sf-calc__summary dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3em 1em;
}

.wi-sf-calc__summary dt {
  font-weight: 600;
  color: #293e4d;
}

.wi-sf-calc__summary dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wi-sf-calc__summary .wi-sf-calc__remaining-dd {
  font-weight: 700;
  font-size: 1.1em;
}

.wi-sf-calc__final {
  background: #eef7ee;
  border: 1px solid #b7dfc0;
  border-radius: 6px;
  padding: 1em 1.25em;
  margin: 1em 0;
  font-size: 1.05em;
}

.wi-sf-calc__final strong {
  font-size: 1.15em;
}

@media (max-width: 480px) {
  .wi-sf-calc__ob-grid {
    grid-template-columns: 1fr;
  }

  .wi-sf-calc__summary dl {
    grid-template-columns: 1fr;
  }

  .wi-sf-calc__summary dd {
    text-align: left;
  }
}
