/* ==========================================================================
   TotalCalcHub design system — public site
   Tokens are derived from the official logo (see docs/DESIGN-SYSTEM.md).
   All shell components are namespaced .tch-* so they never collide with the
   legacy calculator CSS, which is scoped under .tch-legacy by the compiler.
   ========================================================================== */

:root {
  /* Brand (sampled from the logo) */
  --tch-navy-950: #050f24;
  --tch-navy-900: #071735;   /* wordmark ink */
  --tch-navy-800: #0c2149;
  --tch-navy-700: #14306a;
  --tch-navy-600: #1f4290;
  --tch-navy-100: #e7ecf6;
  --tch-navy-50:  #f3f6fb;
  --tch-orange-700: #c2410c;  /* orange text on white (AA) */
  --tch-orange-600: #e85d04;  /* brand orange, large text / fills */
  --tch-orange-500: #ff6a00;
  --tch-amber-400: #ffa41b;
  --tch-orange-100: #fff1e6;
  --tch-slate-600: #4a5a6e;   /* ".com" grey */
  --tch-gradient: linear-gradient(100deg, #ff5a00 0%, #ff8a00 55%, #ffa41b 100%);

  /* Neutrals & semantic */
  --tch-bg: #f5f7fb;
  --tch-surface: #ffffff;
  --tch-surface-2: #f9fafc;
  --tch-border: #e2e7ef;
  --tch-border-strong: #c9d2e0;
  --tch-text: #0f1b2d;
  --tch-text-muted: #4a5a6e;
  --tch-success: #0e7a4d;
  --tch-success-bg: #e8f6ef;
  --tch-warning: #9a4a03;
  --tch-warning-bg: #fff4e5;
  --tch-danger: #b42318;
  --tch-danger-bg: #fdecea;
  --tch-info: #1d4ed8;
  --tch-info-bg: #eaf1ff;
  --tch-focus: #ff8a00;

  /* Typography */
  --tch-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --tch-fs-xs: .75rem; --tch-fs-sm: .875rem; --tch-fs-md: 1rem; --tch-fs-lg: 1.125rem;
  --tch-fs-xl: 1.25rem; --tch-fs-2xl: 1.5rem; --tch-fs-3xl: 1.875rem; --tch-fs-4xl: 2.25rem;

  /* Spacing (4px grid) */
  --tch-s1: .25rem; --tch-s2: .5rem; --tch-s3: .75rem; --tch-s4: 1rem;
  --tch-s5: 1.5rem; --tch-s6: 2rem; --tch-s7: 3rem; --tch-s8: 4rem;

  /* Shape & depth */
  --tch-r-sm: 6px; --tch-r-md: 10px; --tch-r-lg: 16px; --tch-r-xl: 24px; --tch-r-pill: 999px;
  --tch-shadow-sm: 0 1px 2px rgba(7, 23, 53, .06), 0 1px 3px rgba(7, 23, 53, .08);
  --tch-shadow-md: 0 6px 18px -6px rgba(7, 23, 53, .16);
  --tch-shadow-lg: 0 18px 40px -12px rgba(7, 23, 53, .25);

  /* Layout */
  --tch-container: 1240px;
  --tch-gutter: 16px;
  --tch-header-h: 64px;

  /* Motion */
  --tch-dur: .16s;
  --tch-ease: cubic-bezier(.2, .7, .3, 1);
}
@media (min-width: 768px) { :root { --tch-gutter: 24px; } }

/* ---------- Base (document level only) ---------- */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--tch-header-h) + 12px); }
body.tch {
  margin: 0;
  font-family: var(--tch-font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--tch-text);
  background: var(--tch-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.tch *, .tch *::before, .tch *::after { box-sizing: border-box; }
.tch img { max-width: 100%; height: auto; }
.tch :focus-visible { outline: 3px solid var(--tch-focus); outline-offset: 2px; border-radius: 4px; }
.tch-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.tch-container { width: 100%; max-width: var(--tch-container); margin: 0 auto; padding: 0 var(--tch-gutter); }
.tch-skip {
  position: absolute; left: var(--tch-s4); top: -100px; z-index: 1000;
  background: var(--tch-navy-900); color: #fff; padding: var(--tch-s2) var(--tch-s4);
  border-radius: var(--tch-r-md); font-weight: 600; text-decoration: none;
}
.tch-skip:focus { top: var(--tch-s3); }
.tch-icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -.15em; }

/* ---------- Announcement ---------- */
.tch-announce { background: var(--tch-navy-900); color: #fff; font-size: var(--tch-fs-sm); text-align: center; padding: var(--tch-s2) var(--tch-gutter); }
.tch-announce a { color: var(--tch-amber-400); }

/* ---------- Header ---------- */
.tch-header {
  position: sticky; top: 0; z-index: 60;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--tch-border);
}
.tch-header__bar { display: flex; align-items: center; gap: var(--tch-s4); min-height: var(--tch-header-h); }
.tch-logo { display: inline-flex; align-items: center; flex: none; line-height: 0; border-radius: var(--tch-r-sm); }
.tch-logo img { width: 208px; height: auto; display: block; }
@media (min-width: 1024px) { .tch-logo img { width: 236px; } }

/* Search */
.tch-search { position: relative; flex: 1 1 auto; max-width: 520px; margin-left: auto; }
.tch-search__field { position: relative; display: flex; align-items: center; }
.tch-search input[type="search"] {
  width: 100%; height: 44px; font: inherit; font-size: var(--tch-fs-md); color: var(--tch-text);
  padding: 0 48px 0 var(--tch-s4); border: 1.5px solid var(--tch-border-strong); border-radius: var(--tch-r-pill);
  background: var(--tch-surface-2); transition: border-color var(--tch-dur), box-shadow var(--tch-dur), background var(--tch-dur);
  -webkit-appearance: none; appearance: none;
}
.tch-search input[type="search"]::placeholder { color: #66758a; }
.tch-search input[type="search"]:focus { outline: none; border-color: var(--tch-orange-500); background: #fff; box-shadow: 0 0 0 4px rgba(255, 106, 0, .16); }
.tch-search__btn {
  position: absolute; right: 4px; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--tch-gradient); color: var(--tch-navy-900); display: grid; place-items: center; cursor: pointer;
}
.tch-search__results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 70;
  background: #fff; border: 1px solid var(--tch-border); border-radius: var(--tch-r-lg);
  box-shadow: var(--tch-shadow-lg); padding: var(--tch-s2); margin: 0; list-style: none;
  max-height: min(70vh, 460px); overflow-y: auto;
}
.tch-search__results[hidden] { display: none; }
.tch-search__option a, .tch-search__empty { display: block; padding: var(--tch-s2) var(--tch-s3); border-radius: var(--tch-r-md); color: var(--tch-text); text-decoration: none; }
.tch-search__option a[aria-selected="true"], .tch-search__option a:hover { background: var(--tch-navy-50); }
.tch-search__name { display: block; font-weight: 600; }
.tch-search__meta { display: block; font-size: var(--tch-fs-xs); color: var(--tch-text-muted); }
.tch-search__empty { color: var(--tch-text-muted); font-size: var(--tch-fs-sm); }
.tch-search__all { border-top: 1px solid var(--tch-border); margin-top: var(--tch-s1); padding-top: var(--tch-s1); }

/* Menu toggle (mobile) */
.tch-menu-toggle {
  display: none; align-items: center; gap: var(--tch-s2); height: 44px; padding: 0 var(--tch-s3);
  font: inherit; font-weight: 600; color: var(--tch-navy-900); background: #fff;
  border: 1.5px solid var(--tch-border-strong); border-radius: var(--tch-r-pill); cursor: pointer; flex: none;
}

/* Primary navigation */
.tch-nav { border-top: 1px solid var(--tch-border); background: #fff; }
.tch-nav__list { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tch-s1); margin: 0; padding: var(--tch-s1) 0; list-style: none; }
.tch-nav__link, .tch-dd > summary {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: 0 var(--tch-s3);
  font-size: var(--tch-fs-sm); font-weight: 600; color: var(--tch-navy-800); text-decoration: none;
  border-radius: var(--tch-r-pill); cursor: pointer; list-style: none; white-space: nowrap;
}
.tch-dd > summary::-webkit-details-marker { display: none; }
.tch-dd > summary::after { content: ""; width: .45em; height: .45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg) translateY(-2px); margin-left: 2px; }
.tch-dd[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.tch-nav__link:hover, .tch-dd > summary:hover, .tch-dd[open] > summary { background: var(--tch-navy-50); color: var(--tch-navy-900); }
.tch-nav__link[aria-current="page"] { background: var(--tch-orange-100); color: var(--tch-orange-700); }
.tch-dd { position: relative; }
.tch-dd__panel {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 65; min-width: 260px;
  background: #fff; border: 1px solid var(--tch-border); border-radius: var(--tch-r-lg);
  box-shadow: var(--tch-shadow-lg); padding: var(--tch-s2); margin: 0; list-style: none;
}
.tch-dd__panel--grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 420px; }
.tch-dd__panel a {
  display: flex; align-items: center; gap: var(--tch-s2); padding: var(--tch-s2) var(--tch-s3);
  border-radius: var(--tch-r-md); color: var(--tch-text); text-decoration: none; font-size: var(--tch-fs-sm); font-weight: 500;
}
.tch-dd__panel a:hover, .tch-dd__panel a[aria-current="page"] { background: var(--tch-navy-50); }
.tch-dd__panel a[aria-current="page"] { font-weight: 700; }
.tch-dd__panel .fa-solid, .tch-dd__panel .fas { width: 1.2em; text-align: center; color: var(--tch-orange-600); }
.tch-dd__all { grid-column: 1 / -1; border-top: 1px solid var(--tch-border); margin-top: var(--tch-s1); padding-top: var(--tch-s1); }
.tch-flag { font-size: 1.15em; line-height: 1; }
.tch-nav__context { margin-left: auto; font-size: var(--tch-fs-sm); color: var(--tch-text-muted); display: inline-flex; align-items: center; gap: var(--tch-s2); }
.tch-nav__context a { color: var(--tch-navy-700); font-weight: 600; }

@media (max-width: 899px) {
  .tch-menu-toggle { display: inline-flex; }
  .tch-search { order: 3; flex-basis: 100%; max-width: none; margin: 0 0 var(--tch-s3); }
  .tch-header__bar { flex-wrap: wrap; gap: var(--tch-s2) var(--tch-s3); padding-top: var(--tch-s2); }
  .tch-logo { margin-right: auto; }
  .tch-logo img { width: 184px; }
  .js .tch-nav:not(.is-open) { display: none; }
  .tch-nav__list { flex-direction: column; align-items: stretch; padding: var(--tch-s2) 0 var(--tch-s4); }
  .tch-nav__link, .tch-dd > summary { width: 100%; justify-content: space-between; min-height: 48px; font-size: var(--tch-fs-md); border-radius: var(--tch-r-md); }
  .tch-dd__panel, .tch-dd__panel--grid { position: static; min-width: 0; box-shadow: none; border: 0; padding: 0 0 var(--tch-s2) var(--tch-s2); grid-template-columns: 1fr 1fr; }
  .tch-nav__context { margin: var(--tch-s2) 0 0; padding: 0 var(--tch-s3); }
}
@media (max-width: 420px) { .tch-dd__panel, .tch-dd__panel--grid { grid-template-columns: 1fr; } }

/* ---------- Breadcrumbs ---------- */
.tch-crumbs { padding: var(--tch-s4) 0 0; font-size: var(--tch-fs-sm); }
.tch-crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tch-s1) var(--tch-s2); margin: 0; padding: 0; list-style: none; }
.tch-crumbs li { display: inline-flex; align-items: center; gap: var(--tch-s2); color: var(--tch-text-muted); }
.tch-crumbs li + li::before { content: ""; width: .4em; height: .4em; border: solid var(--tch-border-strong); border-width: 2px 2px 0 0; transform: rotate(45deg); }
.tch-crumbs a { display: inline-block; padding: .2rem 0; color: var(--tch-navy-700); text-decoration: none; font-weight: 500; }
.tch-crumbs a:hover { text-decoration: underline; text-underline-offset: 3px; }
.tch-crumbs [aria-current="page"] { color: var(--tch-text); font-weight: 600; max-width: 60ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Page layout ---------- */
.tch-page { padding-bottom: var(--tch-s7); }
.tch-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--tch-s6); padding-top: var(--tch-s3); }
@media (min-width: 1100px) {
  .tch-layout--aside { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .tch-aside { position: sticky; top: calc(var(--tch-header-h) + 56px); }
}
.tch-content { min-width: 0; outline: none; }

/* ---------- Aside & cards ---------- */
.tch-card {
  background: var(--tch-surface); border: 1px solid var(--tch-border); border-radius: var(--tch-r-lg);
  box-shadow: var(--tch-shadow-sm); padding: var(--tch-s5);
}
.tch-aside { display: grid; gap: var(--tch-s4); }
.tch-aside__title { margin: 0 0 var(--tch-s3); font-size: var(--tch-fs-md); font-weight: 700; color: var(--tch-navy-900); display: flex; align-items: center; gap: var(--tch-s2); }
.tch-aside__title .fas, .tch-aside__title .fa-solid { color: var(--tch-orange-600); }
.tch-linklist { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.tch-linklist a {
  display: block; padding: var(--tch-s2) var(--tch-s3); margin: 0 calc(-1 * var(--tch-s3));
  border-radius: var(--tch-r-md); color: var(--tch-navy-800); text-decoration: none; font-size: var(--tch-fs-sm); font-weight: 500; line-height: 1.35;
}
.tch-linklist a:hover { background: var(--tch-navy-50); color: var(--tch-navy-900); }
.tch-chips { display: flex; flex-wrap: wrap; gap: var(--tch-s2); margin: 0; padding: 0; list-style: none; }
.tch-chip {
  display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; padding: 0 var(--tch-s3);
  border: 1px solid var(--tch-border-strong); border-radius: var(--tch-r-pill); background: #fff;
  color: var(--tch-navy-800); font-size: var(--tch-fs-sm); font-weight: 600; text-decoration: none;
}
.tch-chip:hover { border-color: var(--tch-orange-500); color: var(--tch-orange-700); }
.tch-more { display: inline-flex; align-items: center; gap: .35rem; margin-top: var(--tch-s3); font-size: var(--tch-fs-sm); font-weight: 700; color: var(--tch-orange-700); text-decoration: none; }
.tch-more:hover { text-decoration: underline; text-underline-offset: 3px; }
.tch-note { font-size: var(--tch-fs-xs); color: var(--tch-text-muted); margin: 0; }

/* ---------- Buttons ---------- */
.tch-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--tch-s2);
  min-height: 44px; padding: 0 var(--tch-s5); border-radius: var(--tch-r-pill); border: 1.5px solid transparent;
  font: inherit; font-weight: 700; font-size: var(--tch-fs-md); text-decoration: none; cursor: pointer;
  transition: transform var(--tch-dur) var(--tch-ease), box-shadow var(--tch-dur), background var(--tch-dur);
}
.tch-btn--primary { background: var(--tch-gradient); color: var(--tch-navy-950); box-shadow: 0 6px 16px -6px rgba(255, 106, 0, .55); }
.tch-btn--primary:hover { transform: translateY(-1px); box-shadow: 0 10px 20px -8px rgba(255, 106, 0, .6); }
.tch-btn--secondary { background: #fff; color: var(--tch-navy-900); border-color: var(--tch-border-strong); }
.tch-btn--secondary:hover { border-color: var(--tch-navy-700); }

/* ---------- System pages (search, 404) ---------- */
.tch-hero { padding: var(--tch-s7) 0 var(--tch-s5); }
.tch-hero h1 { margin: 0 0 var(--tch-s3); font-size: clamp(1.75rem, 4vw, 2.5rem); line-height: 1.15; letter-spacing: -.02em; color: var(--tch-navy-900); }
.tch-hero p { margin: 0; color: var(--tch-text-muted); font-size: var(--tch-fs-lg); max-width: 60ch; }
.tch-eyebrow { display: inline-block; margin-bottom: var(--tch-s3); font-size: var(--tch-fs-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--tch-orange-700); }
.tch-search--page { max-width: 640px; margin: var(--tch-s5) 0 0; }
.tch-results { display: grid; gap: var(--tch-s3); margin: var(--tch-s5) 0 0; padding: 0; list-style: none; }
.tch-result { display: block; padding: var(--tch-s4) var(--tch-s5); background: #fff; border: 1px solid var(--tch-border); border-radius: var(--tch-r-lg); text-decoration: none; color: var(--tch-text); transition: border-color var(--tch-dur), box-shadow var(--tch-dur); }
.tch-result:hover { border-color: var(--tch-orange-500); box-shadow: var(--tch-shadow-md); }
.tch-result__title { display: block; font-weight: 700; color: var(--tch-navy-800); font-size: var(--tch-fs-lg); }
.tch-result__meta { display: block; margin-top: 2px; font-size: var(--tch-fs-xs); color: var(--tch-text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.tch-result__desc { display: block; margin-top: var(--tch-s2); color: var(--tch-text-muted); font-size: var(--tch-fs-sm); }
.tch-grid { display: grid; gap: var(--tch-s4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); margin: var(--tch-s4) 0 0; padding: 0; list-style: none; }
.tch-tile { display: flex; align-items: center; gap: var(--tch-s3); padding: var(--tch-s4); background: #fff; border: 1px solid var(--tch-border); border-radius: var(--tch-r-lg); text-decoration: none; color: var(--tch-navy-900); font-weight: 600; }
.tch-tile:hover { border-color: var(--tch-orange-500); box-shadow: var(--tch-shadow-md); }
.tch-tile .fas, .tch-tile .fa-solid { color: var(--tch-orange-600); width: 1.4em; text-align: center; }
.tch-section-title { margin: var(--tch-s7) 0 0; font-size: var(--tch-fs-xl); color: var(--tch-navy-900); }

/* ---------- Footer ---------- */
.tch-footer { background: #fff; border-top: 1px solid var(--tch-border); margin-top: var(--tch-s7); }
.tch-footer__grid { display: grid; gap: var(--tch-s6); padding: var(--tch-s7) 0 var(--tch-s6); grid-template-columns: 1fr; }
@media (min-width: 640px) { .tch-footer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .tch-footer__grid { grid-template-columns: 1.6fr repeat(4, minmax(0, 1fr)); } }
.tch-footer__brand img { width: 260px; max-width: 100%; height: auto; display: block; }
.tch-footer__brand p { margin: var(--tch-s4) 0 0; color: var(--tch-text-muted); font-size: var(--tch-fs-sm); max-width: 36ch; }
.tch-footer h2 { margin: 0 0 var(--tch-s3); font-size: var(--tch-fs-xs); text-transform: uppercase; letter-spacing: .12em; color: var(--tch-navy-900); }
.tch-footer ul { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--tch-s1); }
.tch-footer a { display: inline-block; padding: .2rem 0; color: var(--tch-slate-600); text-decoration: none; font-size: var(--tch-fs-sm); }
.tch-footer a:hover { color: var(--tch-orange-700); text-decoration: underline; text-underline-offset: 3px; }
.tch-footer__bottom { border-top: 1px solid var(--tch-border); padding: var(--tch-s5) 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--tch-s3); font-size: var(--tch-fs-xs); color: var(--tch-text-muted); }
.tch-footer__social { display: flex; gap: var(--tch-s3); }

/* ==========================================================================
   Legacy content harmonisation
   The legacy pages share one token set (--primary, --accent …). Remapping the
   tokens moves every calculator onto the brand palette without touching its
   markup. Specificity .tch-legacy.tch-legacy (0,2,0) beats the scoped legacy
   :root rule (0,1,0).
   ========================================================================== */
.tch-legacy.tch-legacy {
  --primary: var(--tch-navy-700);
  --primary-light: var(--tch-navy-600);
  --primary-soft: var(--tch-navy-100);
  --primary-dark: var(--tch-navy-900);
  --accent: var(--tch-orange-600);
  --accent-light: var(--tch-orange-100);
  --text-dark: var(--tch-text);
  --text-muted: var(--tch-text-muted);
  --border-light: var(--tch-border);
  --gray-bg: var(--tch-surface-2);
  background: transparent;
}
/* The shell provides the page gutters; legacy containers must not add more. */
.tch-legacy.tch-legacy .container { max-width: none; padding-left: 0; padding-right: 0; }
.tch-legacy.tch-legacy main, .tch-legacy.tch-legacy > section { max-width: none; }
.tch-legacy.tch-legacy .main-header, .tch-legacy.tch-legacy .hamburger { display: none; }
/* Wide content (tables, code) scrolls inside the content column instead of the page. */
.tch-legacy table { max-width: 100%; }
.tch-legacy.tch-legacy pre { overflow-x: auto; }
.tch-legacy :where(input, select, textarea, button) { font: inherit; }
/* Many legacy calculators remove the focus outline; a visible focus indicator is
   required (WCAG 2.4.7), so this is one of the few deliberate !important rules. */
.tch-legacy :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--tch-focus) !important; outline-offset: 2px !important;
}
.tch-legacy :where(a) { text-underline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .tch *, .tch *::before, .tch *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .tch-header, .tch-footer, .tch-aside, .tch-crumbs, .tch-skip, .tch-announce { display: none !important; }
  body.tch { background: #fff; }
}
