/* ============================================
   TERMS & POLICY — a document page
   ============================================
   The legal text runs to several pages, so it is a page rather than a dialog.
   Everything here is token colour, so the document opens in whichever theme the
   visitor already chose — a wall of legal text in the wrong palette reads as a
   different product. */
.terms-body { min-height: 100svh; }

/* Sticky, like the reader and the app's own page headers: the way out has to
   stay reachable while the document scrolls. */
.terms-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding:
    calc(var(--space-3) + env(safe-area-inset-top, 0px))
    calc(var(--space-4) + env(safe-area-inset-right, 0px))
    var(--space-3)
    calc(var(--space-4) + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.terms-back {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.terms-back:hover { color: var(--brand-primary); background: var(--surface-hover); }
.terms-back:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  color: var(--brand-primary);
}
.terms-back svg { width: 16px; height: 16px; }

.terms-bar-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  margin-right: auto;
}

.terms-filter-wrap { position: relative; flex-shrink: 0; }
.terms-filter-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.terms-filter-btn[hidden] { display: none; }
.terms-filter-btn:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.terms-filter-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.terms-filter-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 280px;
  max-width: min(360px, 86vw);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.terms-filter-menu.active { display: block; }
.terms-filter-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-secondary);
  cursor: pointer;
}
.terms-filter-item:last-child { border-bottom: none; }
.terms-filter-item:hover,
.terms-filter-item:focus-visible { background: var(--bg-tertiary); color: var(--text-primary); }
.terms-filter-item.legal-changed { font-weight: 700; color: var(--text-primary); }
@media (max-width: 768px) {
  .terms-filter-menu { min-width: 240px; }
}

/* The switch between the two documents lives in the page, not the bar. Terms
   and privacy are one agreement, so neither is allowed to be a dead end. */
.legal-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}
.legal-tabs a {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.legal-tabs a:hover { color: var(--text-primary); background: var(--surface-hover); }
.legal-tabs a.active { color: var(--text-primary); background: var(--bg-tertiary); }
.legal-tabs a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  color: var(--brand-primary);
}

/* One column at the measure a document is actually read at, with the page's
   own gutters so nothing touches an edge on a phone. */
.terms-main {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4.5vw, 28px) clamp(56px, 9vw, 96px);
}
.terms-updated {
  margin: 0 0 var(--space-6);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.terms-note {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: center;
}
.link-muted { color: var(--brand-primary); text-decoration: none; }
.link-muted:hover { text-decoration: underline; }

/* The body arrives either as HTML typed into the CRM or converted from an
   uploaded .docx, so none of these elements can be relied on — the styles cover
   what Word emits and what the old inline rows contain. */
.terms-prose {
  font-size: var(--fs-base);
  line-height: 1.7;
  color: var(--text-primary);
  overflow-wrap: break-word;
}
.terms-prose > :first-child { margin-top: 0; }
.terms-prose h1,
.terms-prose h2,
.terms-prose h3,
.terms-prose h4 {
  margin: var(--space-8) 0 var(--space-3);
  font-weight: var(--fw-bold);
  line-height: 1.3;
  letter-spacing: var(--ls-tight);
  color: var(--text-primary);
}
.terms-prose h1 { font-size: var(--fs-xl); }
.terms-prose h2 { font-size: var(--fs-lg); }
.terms-prose h3 { font-size: var(--fs-md); }
.terms-prose h4 { font-size: var(--fs-base); }
.terms-prose p { margin: 0 0 var(--space-4); }
.terms-prose ul,
.terms-prose ol { margin: 0 0 var(--space-4); padding-left: 24px; }
.terms-prose li { margin-bottom: 6px; }
.terms-prose a { color: var(--brand-primary); text-decoration: none; }
.terms-prose a:hover { text-decoration: underline; }
.terms-prose strong { font-weight: var(--fw-bold); }
.terms-prose hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-8) 0; }
.terms-prose img { border-radius: var(--radius-md); }
.terms-prose table { width: 100%; border-collapse: collapse; margin: 0 0 var(--space-4); }
.terms-prose th,
.terms-prose td {
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-size: var(--fs-sm);
}
.terms-prose th { background: var(--bg-tertiary); font-weight: var(--fw-semibold); }

/* Section headings get ids from the shared anchor rule; the highlight marks
   the one the filter just took the reader to. */
.terms-prose .legal-section { scroll-margin-top: calc(72px + env(safe-area-inset-top, 0px)); }
.terms-prose .legal-hit {
  background: var(--brand-primary-light);
  border-radius: 6px;
  box-shadow: 0 0 0 6px var(--brand-primary-light);
}
