/* ==========================================================================
   Therapy Mends 2.0 — design tokens, header and footer.
   Loaded on every page, including legacy pages, so every rule here is
   scoped to .tm-* classes and sets its own font, colour and box model.
   Component styles for new pages live in tm-system.css.
   ========================================================================== */

:root {
  /* Palette: warm ivory, sand, sage, forest, clay */
  --tm-ivory: #fbf7f0;
  --tm-ivory-2: #f4ede2;
  --tm-paper: #fffdf9;
  --tm-sand: #e9ddcb;
  --tm-sand-2: #d6c5ac;
  --tm-sage: #a9b9a0;
  --tm-sage-soft: #e4eadd;
  --tm-sage-ink: #4b6245;
  --tm-forest: #22463a;
  --tm-forest-deep: #16302a;
  --tm-forest-tint: #2f5a4b;
  --tm-clay: #c27b5b;
  --tm-clay-soft: #f3e2d7;
  --tm-clay-ink: #94492d;
  --tm-ink: #26231f;
  --tm-ink-2: #514b44;
  --tm-ink-3: #665e55;
  --tm-line-strong: #8f8170; /* 3:1+ against paper, for form controls */
  --tm-danger: #a12f24;
  --tm-danger-soft: #f8e3df;
  --tm-success: #2f5d3a;
  --tm-success-soft: #e2ecdd;

  /* Type */
  --tm-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --tm-sans: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --tm-step--1: clamp(0.84rem, 0.82rem + 0.1vw, 0.9rem);
  --tm-step-0: clamp(1rem, 0.97rem + 0.15vw, 1.075rem);
  --tm-step-1: clamp(1.14rem, 1.08rem + 0.3vw, 1.3rem);
  --tm-step-2: clamp(1.32rem, 1.18rem + 0.7vw, 1.75rem);
  --tm-step-3: clamp(1.65rem, 1.36rem + 1.45vw, 2.55rem);
  --tm-step-4: clamp(2.05rem, 1.55rem + 2.5vw, 3.7rem);

  /* Space (mobile first) */
  --tm-space-1: 0.25rem;
  --tm-space-2: 0.5rem;
  --tm-space-3: 0.75rem;
  --tm-space-4: 1rem;
  --tm-space-5: 1.5rem;
  --tm-space-6: 2rem;
  --tm-space-7: 3rem;
  --tm-space-8: 4rem;
  --tm-space-9: 6rem;
  --tm-gutter: 16px;
  --tm-max: 1200px;

  /* Shape and depth */
  --tm-radius-sm: 8px;
  --tm-radius: 14px;
  --tm-radius-lg: 22px;
  --tm-shadow-sm: 0 1px 2px rgba(38, 35, 31, 0.05);
  --tm-shadow: 0 1px 2px rgba(38, 35, 31, 0.04), 0 14px 34px -16px rgba(38, 35, 31, 0.18);
  --tm-shadow-lg: 0 2px 4px rgba(38, 35, 31, 0.04), 0 28px 60px -24px rgba(38, 35, 31, 0.28);
  --tm-focus: 0 0 0 3px var(--tm-paper), 0 0 0 6px var(--tm-clay-ink);

  --tm-header-h: 68px;
  --tm-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (min-width: 640px) {
  :root { --tm-gutter: 24px; }
}

@media (min-width: 1024px) {
  :root { --tm-gutter: 32px; --tm-header-h: 76px; }
}

/* ---------- Shared helpers ---------- */

.tm-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.tm-skip {
  position: absolute;
  left: var(--tm-gutter);
  top: -100px;
  z-index: 2000;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  background: var(--tm-forest);
  color: var(--tm-ivory);
  font: 700 0.95rem/1 var(--tm-sans);
  text-decoration: none;
}

.tm-skip:focus {
  top: 12px;
  outline: none;
  box-shadow: var(--tm-focus);
}

/* ---------- Header ---------- */

.tm-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0;
  background: rgba(251, 247, 240, 0.92);
  border-bottom: 1px solid var(--tm-sand);
  font-family: var(--tm-sans);
  color: var(--tm-ink);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  backdrop-filter: saturate(1.2) blur(10px);
}

.tm-header *,
.tm-header *::before,
.tm-header *::after { box-sizing: border-box; }

.tm-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--tm-max);
  min-height: var(--tm-header-h);
  margin: 0 auto;
  padding: 0 var(--tm-gutter);
}

.tm-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  color: var(--tm-forest);
  text-decoration: none;
  border-radius: var(--tm-radius-sm);
}

.tm-brand img {
  display: block;
  width: 46px;
  height: auto;
  margin: 0;
}

.tm-brand__name {
  font-family: var(--tm-serif);
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--tm-forest);
}

.tm-brand:focus-visible { outline: none; box-shadow: var(--tm-focus); }

.tm-nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 0.85rem;
  border: 1px solid var(--tm-sand-2);
  border-radius: 999px;
  background: var(--tm-paper);
  color: var(--tm-forest);
  font: 700 0.9rem/1 var(--tm-sans);
  cursor: pointer;
}

.tm-nav-toggle:focus-visible { outline: none; box-shadow: var(--tm-focus); }

.tm-nav-toggle__icon {
  position: relative;
  display: block;
  width: 18px;
  height: 12px;
}

.tm-nav-toggle__icon::before,
.tm-nav-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.25s var(--tm-ease), top 0.25s var(--tm-ease);
}

.tm-nav-toggle__icon::before { top: 2px; }
.tm-nav-toggle__icon::after { top: 8px; }

.tm-nav-toggle[aria-expanded="true"] .tm-nav-toggle__icon::before { top: 5px; transform: rotate(45deg); }
.tm-nav-toggle[aria-expanded="true"] .tm-nav-toggle__icon::after { top: 5px; transform: rotate(-45deg); }

/* Without JS the toggle is useless, so hide it and show the menu inline. */
html:not(.tm-js) .tm-nav-toggle { display: none; }

.tm-nav {
  font-family: var(--tm-sans);
}

.tm-nav__list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tm-nav__list li { margin: 0; padding: 0; list-style: none; }
.tm-nav__list li::before,
.tm-nav__list li::marker { content: none; }

.tm-nav .tm-nav__link {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--tm-ink);
  font-family: var(--tm-serif);
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  border-radius: var(--tm-radius-sm);
}

.tm-nav .tm-nav__link[aria-current="page"] { color: var(--tm-forest); }

.tm-nav .tm-nav__link[aria-current="page"]::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 0.6rem;
  border-radius: 50%;
  background: var(--tm-clay);
}

.tm-nav .tm-nav__link:hover { color: var(--tm-forest); }
.tm-nav .tm-nav__link:focus-visible { outline: none; box-shadow: var(--tm-focus); }

.tm-nav .tm-nav__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.75rem 1.4rem;
  border: 1.5px solid var(--tm-forest);
  border-radius: 999px;
  background: var(--tm-forest);
  color: var(--tm-ivory);
  font: 700 0.98rem/1.1 var(--tm-sans);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s var(--tm-ease), transform 0.2s var(--tm-ease);
}

.tm-nav .tm-nav__cta:hover { background: var(--tm-forest-deep); color: var(--tm-ivory); }
.tm-nav .tm-nav__cta:active { transform: translateY(1px); }
.tm-nav .tm-nav__cta:focus-visible { outline: none; box-shadow: var(--tm-focus); }

.tm-nav__support {
  margin: 1.25rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--tm-sand);
  color: var(--tm-ink-2);
  font: 400 0.95rem/1.6 var(--tm-sans);
}

.tm-nav__support a {
  color: var(--tm-forest);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Mobile and tablet: menu is a panel under the header. */
@media (max-width: 1023.98px) {
  .tm-header__inner { flex-wrap: wrap; }

  .tm-nav {
    flex-basis: 100%;
    padding: 0.5rem 0 1.5rem;
  }

  .tm-js .tm-nav { display: none; }
  .tm-js .tm-header.is-open .tm-nav {
    display: block;
    max-height: calc(100vh - var(--tm-header-h));
    max-height: calc(100dvh - var(--tm-header-h));
    overflow-y: auto;
    animation: tm-nav-in 0.22s var(--tm-ease);
  }

  .tm-nav__list li + li { border-top: 1px solid var(--tm-sand); }
  .tm-nav .tm-nav__cta { width: 100%; margin-top: 1rem; }
}

@keyframes tm-nav-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* Desktop: inline menu. */
@media (min-width: 1024px) {
  .tm-nav-toggle,
  html:not(.tm-js) .tm-nav-toggle { display: none; }

  .tm-nav {
    display: flex;
    align-items: center;
    gap: 1.75rem;
  }

  .tm-nav__list {
    flex-direction: row;
    align-items: center;
    gap: 1.6rem;
  }

  .tm-nav .tm-nav__link {
    min-height: 44px;
    padding: 0;
    color: var(--tm-ink-2);
    font-family: var(--tm-sans);
    font-size: 0.97rem;
    font-weight: 600;
  }

  .tm-nav .tm-nav__link::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    height: 2px;
    border-radius: 2px;
    background: var(--tm-clay);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.25s var(--tm-ease);
  }

  .tm-nav .tm-nav__link:hover::before,
  .tm-nav .tm-nav__link[aria-current="page"]::before { transform: scaleX(1); }
  .tm-nav .tm-nav__link[aria-current="page"]::after { content: none; }

  .tm-nav .tm-nav__cta { min-height: 44px; padding: 0.65rem 1.3rem; font-size: 0.95rem; }
  .tm-nav__support { display: none; }
}

/* ---------- Footer (markup in /footer.html) ---------- */

.tm-footer {
  box-sizing: border-box;
  margin: 0;
  padding: var(--tm-space-8) 0 var(--tm-space-6);
  background: var(--tm-forest-deep);
  color: rgba(251, 247, 240, 0.86);
  font: 400 0.98rem/1.65 var(--tm-sans);
}

.tm-footer *,
.tm-footer *::before,
.tm-footer *::after { box-sizing: border-box; }

.tm-footer__inner {
  max-width: var(--tm-max);
  margin: 0 auto;
  padding: 0 var(--tm-gutter);
}

.tm-footer__grid {
  display: grid;
  gap: var(--tm-space-6);
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .tm-footer__grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .tm-footer__grid { grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: var(--tm-space-7); }
}

.tm-footer__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--tm-ivory);
  text-decoration: none;
  border-radius: var(--tm-radius-sm);
}

.tm-footer__brand img { width: 46px; height: auto; filter: invert(1) brightness(1.1); }

.tm-footer__brand span {
  font: 600 1.4rem/1 var(--tm-serif);
  color: var(--tm-ivory);
}

.tm-footer__tagline {
  margin: 1rem 0 0;
  font: italic 400 1.1rem/1.5 var(--tm-serif);
  color: rgba(251, 247, 240, 0.9);
}

.tm-footer h2 {
  margin: 0 0 0.9rem;
  color: var(--tm-sage);
  font: 800 0.78rem/1.2 var(--tm-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tm-footer ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tm-footer li { margin: 0; padding: 0; list-style: none; }
.tm-footer li::before,
.tm-footer li::marker { content: none; }

.tm-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  color: var(--tm-ivory);
  text-decoration: none;
  border-radius: 4px;
}

.tm-footer a:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }
.tm-footer a:focus-visible { outline: 2px solid var(--tm-sage); outline-offset: 3px; }

.tm-footer__social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 1.25rem;
}

.tm-footer__social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  color: rgba(251, 247, 240, 0.8);
}
.tm-footer__social svg { width: 22px; height: 22px; }

.tm-footer__crisis {
  margin: var(--tm-space-7) 0 0;
  padding: 1.1rem 1.25rem;
  border: 1px solid rgba(251, 247, 240, 0.18);
  border-radius: var(--tm-radius);
  background: rgba(251, 247, 240, 0.05);
  font-size: 0.95rem;
}

.tm-footer__crisis strong { color: var(--tm-ivory); }
.tm-footer__crisis a { display: inline; min-height: 0; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.tm-footer__bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-top: var(--tm-space-6);
  padding-top: var(--tm-space-5);
  border-top: 1px solid rgba(251, 247, 240, 0.14);
  font-size: 0.9rem;
  color: rgba(251, 247, 240, 0.72);
}

.tm-footer__bottom p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .tm-header *,
  .tm-footer * { animation: none !important; transition: none !important; }
}

/* Phase 8: next steps on resource articles (generated between tm:related markers) */
.tm-next { box-sizing: border-box; width: calc(100% - 32px); max-width: 760px; margin: 2.5rem auto; padding: 1.4rem 1.5rem; border: 1px solid var(--tm-sand); border-radius: var(--tm-radius); background: var(--tm-ivory); font-family: var(--tm-sans); color: var(--tm-ink); }
.tm-next h2 { margin: 0 0 0.5rem; font-family: var(--tm-serif); font-size: 1.35rem; line-height: 1.25; }
.tm-next p { margin: 0 0 0.75rem; line-height: 1.6; }
.tm-next ul { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin: 0 0 0.9rem; padding: 0; list-style: none; }
.tm-next li { margin: 0; padding: 0; }
.tm-next li::before { content: none; }
.tm-next a { display: inline-flex; align-items: center; min-height: 44px; color: var(--tm-forest); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.tm-next .tm-next__note { margin: 0; font-size: 0.9rem; color: var(--tm-ink-2); }
