/* Results table: right-align all data columns */
.thp-table td,
.thp-table thead th:not(:first-child) {
  text-align: right;
  padding-right: 15px;
}

/* Stack the results table into labelled rows on small screens rather than
   forcing a five-column horizontal scroll. */
@media (max-width: 575.98px) {
  .thp-table,
  .thp-table tbody,
  .thp-table tr,
  .thp-table th,
  .thp-table td {
    display: block;
    width: 100%;
  }

  .thp-table thead {
    display: none;
  }

  .thp-table tbody tr {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
  }

  .thp-table tbody th {
    text-align: left;
    padding: 0 0 0.35rem;
    font-size: 1rem;
    border: 0;
  }

  .thp-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    text-align: right;
    padding: 0.15rem 0;
    border: 0;
  }

  /* Restore the column headings the <thead> would have carried. */
  .thp-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    text-align: left;
    padding-right: 1rem;
    color: var(--bs-secondary-color, #6c757d);
  }
}

/* Headline rates */
.thp-stat {
  border: 1px solid var(--bs-border-color);
  border-radius: 0.5rem;
  padding: 0.85rem 0.75rem;
}

.thp-stat-value {
  font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.5rem);
  font-weight: 300;
  line-height: 1.1;
}

.thp-stat-label {
  font-weight: 600;
}

.thp-stat-note {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color, #6c757d);
  margin-top: 0.15rem;
}

/* Where your money goes.
   Categorical palette validated with the data-viz palette checker: all five
   slots pass the lightness band, chroma floor, CVD separation and
   normal-vision floor against a white surface. Colours are bound to the
   entity, not to position, so a segment appearing or disappearing never
   repaints the others. Segment fills sit below 3:1 against the surface, which
   is why every segment is also named and valued in the key below it. */
.thp-viz {
  --thp-surface: #fff;
  --thp-take: #1baf7a;
  --thp-tax: #2a78d6;
  --thp-ni: #eb6834;
  --thp-loan: #4a3aa7;
  --thp-pension: #e87ba4;
}

.thp-split {
  display: flex;
  height: 1.5rem;
  border-radius: 4px;
  overflow: hidden;
  background: var(--thp-surface);
}

.thp-split-seg {
  box-sizing: border-box;
  min-width: 3px;
}

/* 2px of surface between fills so adjacent segments never bleed together. */
.thp-split-seg + .thp-split-seg {
  border-left: 2px solid var(--thp-surface);
}

.thp-seg-take    { background: var(--thp-take); }
.thp-seg-tax     { background: var(--thp-tax); }
.thp-seg-ni      { background: var(--thp-ni); }
.thp-seg-loan    { background: var(--thp-loan); }
.thp-seg-pension { background: var(--thp-pension); }

.thp-split-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-size: 0.875rem;
}

.thp-split-key li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.thp-key-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  flex: 0 0 auto;
}

.thp-key-pct {
  color: var(--bs-secondary-color, #6c757d);
}

/* Bootstrap has no responsive width utilities, so the w-lg-auto the search
   forms have always carried did nothing - w-100 applied at every width, which
   is why the Search button stretched across the row on desktop. Supply the
   utility the markup already assumes. */
@media (min-width: 992px) {
  .w-lg-auto {
    width: auto !important;
  }
}

/* The home page offers five periods, which is too many to sit in one row on a
   narrow screen. Wrap them into spaced pills there and leave the connected
   group intact from sm up. */
@media (max-width: 575.98px) {
  .thp-period-group {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .thp-period-group > .btn {
    flex: 1 1 auto;
    border-radius: 0.375rem !important;
    margin-left: 0 !important;
  }
}

/* The header search sits in the same flex row as the nav links. Left
   unconstrained it squeezes them; give it a ceiling from lg up and let the
   links keep their space. Below lg it is inside the collapsed menu and should
   stay full width. */
@media (min-width: 992px) {
  .thp-header-search {
    max-width: 26rem;
  }

  /* A number input has a narrow intrinsic width, so w-lg-auto alone collapses
     the amount field until its placeholder is clipped. Let it take the space
     the period buttons and submit do not need, with a floor that keeps
     "Search Wage..." readable. */
  .thp-amount-field {
    flex: 1 1 auto;
    min-width: 14rem;
  }

  /* The header has far less room than the page body: the same floor there
     pushes the row past the cap above and clips the submit button. */
  .thp-header-search .thp-amount-field {
    min-width: 10rem;
  }

  /* Stop the home page row stretching the full container width once the amount
     field is allowed to grow. */
  #homeForm {
    max-width: 44rem;
  }
}

/* Advanced Options: the switch is much shorter than the inputs and selects
   beside it, so on its own it floats above their baseline. Give it the same
   height as a form control and centre it, so all four controls line up. */
.thp-options .thp-switch-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0;
  min-height: calc(1.5em + 0.75rem + 2px);
}

.thp-options .thp-switch-field .form-check-input {
  float: none;
  margin: 0;
  flex: 0 0 auto;
}

.thp-options .thp-switch-field .form-check-label {
  margin: 0;
}

/* With all four fields on one row, a label that wraps to two lines would push
   its control below the others. Reserve two lines for every label and hint so
   the controls share a baseline whatever the wording. */
@media (min-width: 992px) {
  .thp-options .form-label {
    min-height: 3em;
  }

  .thp-options .form-text {
    min-height: 2.5em;
  }
}

/* A wrapped btn-group renders with broken corners and seams, because
   Bootstrap's negative margins and corner rules assume a single row. Any group
   that is allowed to wrap gets spaced pills instead. */
.btn-group.flex-wrap {
  gap: 0.35rem;
}

.btn-group.flex-wrap > .btn {
  border-radius: 0.375rem !important;
  margin-left: 0 !important;
}

/* House ad card reserves its height at every breakpoint so layout doesn't
   shift as it loads - see include/house_ads.php. */
.thp-house-ad {
  display: block;
  min-height: 132px;
}

.thp-house-ad-link {
  display: flex;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  background-color: rgba(0, 85, 136, 0.06);
  border: 1px solid rgba(0, 85, 136, 0.15);
  text-decoration: none;
  color: inherit;
}

.thp-house-ad-logo {
  flex-shrink: 0;
}

.thp-house-ad-headline {
  color: #005588;
}

/* .text-muted's grey (#6c757d) is fine against plain white (4.69:1) but drops
   under the WCAG AA 4.5:1 floor against this card's tinted background
   (4.26:1) - a touch darker restores it (5.64:1). */
.thp-house-ad-desc {
  color: #5a6268;
}

.thp-house-ad-cta {
  background-color: #005588;
  color: #fff;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .thp-house-ad {
    min-height: 96px;
  }
}

/* Top bar: same rotating campaigns as .thp-house-ad, but a slim single-line
   strip above the header. The header is sticky-top; this bar sits above it in
   normal flow so it scrolls away first, leaving the header pinned. */
.thp-topbar {
  background-color: rgba(0, 85, 136, 0.06);
  border-bottom: 1px solid rgba(0, 85, 136, 0.15);
}

.thp-topbar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  text-decoration: none;
  color: inherit;
  font-size: 0.8125rem;
  line-height: 1.3;
}

.thp-topbar-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thp-topbar-text strong {
  color: #005588;
  font-weight: 600;
}

.thp-topbar-cta {
  flex-shrink: 0;
  color: #005588;
  text-decoration: underline;
  white-space: nowrap;
}

@media print {
  header,
  footer,
  .social-sharing,
  .quick-adjust,
  .thp-no-print,
  form {
    display: none !important;
  }

  a[href]::after {
    content: none !important;
  }

  .thp-split-seg {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
