/* Stage 3 component styles, built on components/tokens-final.css (the 0.3 final palette).
 * Fixture-only until Stage 5. Colours reference tokens, never raw hex, so the contrast gate covers
 * them and Stage 5 adoption is a matter of loading the same values site-wide.
 */

/* Self-contained box-sizing: the site sets `* { box-sizing: border-box }` globally, but a component
 * must not depend on its host doing so, or its 100%-width + padding rules overflow (the mobile table
 * clipping bug). Scope a low-specificity reset to every Truewise component element. */
[class^="tw-"],
[class*=" tw-"] {
  box-sizing: border-box;
}

.tw-search {
  font-family: var(--font);
  max-width: 620px;
}
.tw-search__label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 6px;
}
.tw-search__box {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  padding: 4px 6px 4px 14px;
  background: var(--paper);
  transition: border-color 0.15s;
}
.tw-search__box:focus-within {
  border-color: var(--brand);
}
.tw-search__icon {
  color: var(--text-muted);
  flex: 0 0 auto;
}
.tw-search__input {
  border: 0;
  outline: 0;
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  padding: 11px 0;
  background: transparent;
  color: var(--text);
}
/* Focus ring on the input keeps the mandatory 2px offset (0.3 section 4). */
.tw-search__input:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.tw-search__list {
  list-style: none;
  margin: 8px 0 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--paper);
  box-shadow: 0 12px 32px rgba(12, 21, 18, 0.10);
}
.tw-search__opt {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  cursor: pointer;
}
.tw-search__opt.is-active,
.tw-search__opt:hover {
  background: var(--sand);
}
.tw-search__title {
  font-weight: 600;
  color: var(--text);
}
.tw-search__meta {
  color: var(--text-secondary);
  font-size: 0.88rem;
}
.tw-search__why {
  color: var(--text-muted);
  font-size: 0.78rem;
}
.tw-search__empty {
  padding: 12px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.tw-search__empty a {
  color: var(--brand-strong); /* links on a tinted surface use brand-strong (0.3 rule 5.1) */
  font-weight: 600;
}
.tw-search__status {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---- Program / comparison table (B5) ---- */
.tw-table__coverage {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--text);
}
.tw-table__covnote {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.tw-table__baseline {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.tw-table__scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.tw-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
}
.tw-table__caption {
  caption-side: top;
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.tw-th,
.tw-td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.tw-th {
  background: var(--sand);
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}
.tw-th--num,
.tw-td--num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tw-th__sort {
  font: inherit;
  font-weight: 700;
  color: var(--text-secondary);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.tw-th__sort:hover {
  color: var(--brand-strong);
}
.tw-th__sort.is-active {
  color: var(--brand-strong);
}
.tw-th__sort:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.tw-td--program {
  font-weight: 600;
  color: var(--text);
}
.tw-tr--insuf .tw-td {
  background: var(--sand);
}
.tw-td__insuf {
  color: var(--text-muted);
  font-style: italic;
  border-bottom: 1px dashed var(--line);
}
.tw-verdict {
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}
.tw-verdict--pass {
  color: var(--good);
}
.tw-verdict--fail {
  color: var(--bad);
}
.tw-verdict--insuf {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}
.tw-prem {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}
.tw-prem__bar {
  display: inline-block;
  height: 8px;
  width: 42px;
  border-radius: var(--r-sm);
}
.tw-prem__bar--pos {
  background: var(--good);
}
.tw-prem__bar--neg {
  background: var(--bad);
}
.tw-prem__val {
  font-variant-numeric: tabular-nums;
}
.tw-showall {
  margin: 12px 0 0;
  font: inherit;
  font-weight: 600;
  color: var(--brand-strong);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 16px;
  cursor: pointer;
}
.tw-showall:hover {
  border-color: var(--brand);
}
.tw-showall:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.tw-showall[disabled] {
  opacity: 0.6;
  cursor: default;
}
.tw-table__status {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Mobile: stack each row into labelled key/value pairs. Every value keeps its column label via the
   data-label attribute, so a phone never shows a headerless column of numbers. */
@media (max-width: 768px) {
  .tw-table__scroll {
    border: 0;
  }
  .tw-table__scroll {
    overflow-x: visible; /* stacked cards do not scroll horizontally */
  }
  .tw-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .tw-table,
  .tw-table tbody,
  .tw-tr,
  .tw-td {
    display: block;
    width: 100%;
  }
  .tw-table__caption {
    display: block;
    width: 100%;
    padding: 0 0 10px;
  }
  .tw-tr {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    margin-bottom: 12px;
    padding: 6px 4px;
  }
  .tw-td {
    border: 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 6px 12px;
    text-align: right;
  }
  /* Value can wrap under its label if long; label never gets squeezed to a vertical column. */
  .tw-td::before {
    flex: 0 0 auto;
    max-width: 55%;
  }
  .tw-td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
  }
  .tw-td--program {
    font-size: 1.05rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
  }
  .tw-td--program::before {
    content: "";
  }
}

/* ---- Small UI components (B2-B4, B6-B14) ---- */
.tw-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* B8 status pill */
.tw-pill {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.tw-pill--pass {
  color: var(--good);
  background: var(--good-bg);
}
.tw-pill--fail {
  color: var(--bad);
  background: var(--bad-bg);
}
.tw-pill--caution {
  color: var(--caution);
  background: var(--caution-bg);
}
.tw-pill--insuf {
  color: var(--text-muted);
  background: var(--sand);
  border: 1px dashed var(--line);
  font-weight: 400;
}
/* Inline "1-year earnings" marker: an earnings figure measured 1 year after completion, not 4. Reuses
   the caution palette; sits under the number so it does not read as part of the dollar amount. */
.tw-oneyr {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--caution);
  white-space: nowrap;
}

/* B14 suppressed value */
.tw-insuf {
  color: var(--text-muted);
  font-style: italic;
}

/* B6 coverage note */
.tw-coverage {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 0.95rem;
}
.tw-coverage__note {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.tw-coverage--low b {
  color: var(--bad);
}

/* B7 source note */
.tw-source {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

/* B3 empty state */
.tw-empty {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--sand);
  color: var(--text-secondary);
}
.tw-empty__routes a {
  color: var(--brand-strong); /* links on the surface-backed empty state (0.3 rule 5.1) */
  font-weight: 600;
}

/* B12 loading skeleton */
.tw-skel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tw-skel__row {
  height: 16px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--sand), var(--line), var(--sand));
  background-size: 200% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .tw-skel__row {
    animation: tw-shimmer 1.2s ease-in-out infinite;
  }
}
@keyframes tw-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* B13 error state */
.tw-error {
  padding: 14px 16px;
  border: 1px solid var(--bad);
  border-radius: var(--r-lg);
  background: var(--bad-bg);
  color: var(--bad);
}
.tw-error a {
  color: var(--brand-strong);
  font-weight: 700;
}

/* B4 state chips + B9 filters */
.tw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.tw-chips__label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-right: 4px;
}
.tw-chip {
  font: inherit;
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text-secondary);
  cursor: pointer;
}
.tw-chip:hover {
  border-color: var(--brand);
  color: var(--text);
}
.tw-chip.is-on {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-on-brand);
  font-weight: 600;
}
.tw-chip:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.tw-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}
.tw-filters__label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.tw-filters__select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper);
  color: var(--text);
}
.tw-filters__select:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.tw-filters__check {
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* B11 disclosure */
.tw-disclosure {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 0 14px;
}
.tw-disclosure > summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  color: var(--brand-strong);
}
.tw-disclosure > summary:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.tw-disclosure__body {
  padding: 0 0 14px;
  color: var(--text-secondary);
  font-size: 0.92rem;
}
