/* --------------------------------------------------------------------------
   LEGAL PAGES (/legal/terms/…, /legal/privacy/…)

   Ported from the "Policies" design artifact, which reuses the blog article
   layout: a sticky bar under the site header that switches between the two
   policies, a table of contents beside the text on wide screens, and a
   680px reading column.

   The page is <main>: its <header> is the Policies bar (title, contents
   button and dropdown, and the links between the policies), then a <div>
   laid out on a grid holds the document's <header>, the contents <nav> and
   the <article class="prose"> of imported text.

   The design is built on the Pagelove UI kit tokens. Only the ones these
   pages use are defined below, at the values the kit resolves them to, and
   scoped to .legal so they cannot leak into the rest of the site.
   -------------------------------------------------------------------------- */

.legal {
  --text-strong: #020617;
  --text-regular: #334155;
  --text-light: #64748B;
  --text-information: #174EDE;
  --text-warning: #C64808;
  --border-light: #F1F5F9;
  --border-regular: #CBD5E1;
  --border-strong: #94A3B8;
  --border-focused: #59A6FF;
  --border-warning: #FFDBA8;
  --background-warning-light: #FFF8ED;
  --icon-light: #64748B;
  --link-text-default: #1F64F1;
  --link-text-hover: #174EDE;
  --borderless-text-default: #475569;
  --borderless-text-disabled: #94A3B8;
  --borderless-text-hovered: #1E293B;
  --borderless-text-pressed: #0F172A;
  --gradient-purple-storm: linear-gradient(to left, #666550 0%, #6C66C5 100%);
  --motion-hover: 0.3s ease-in-out;

  /* Site header (64px bar + 1px border) and this page's own 64px bar */
  --header-height: 65px;
  --legal-bar-height: 64px;
  --legal-gutter: 16px;

  /* The side padding that keeps content in the 1150px zone */
  --legal-pad: var(--grid-margin);

  background-color: var(--color-background-white);
}

@media (min-width: 901px) {
  .legal {
    --legal-pad: max(var(--grid-margin), calc((100% - var(--content-max-width)) / 2));
  }
}

@media (min-width: 1024px) {
  .legal {
    --legal-gutter: 24px;
  }
}

.legal :focus-visible {
  outline: 2px solid var(--border-focused);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- Main nav slides away on scroll down, returns on scroll up --------- */

.legal > header {
  transition: transform var(--motion-hover);
}

.legal.nav-up > header:not(:has([aria-expanded="true"])) {
  transform: translateY(-100%);
}

/* --- Policies bar ------------------------------------------------------- */

.legal main > header {
  position: sticky;
  top: var(--header-height);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: calc(var(--legal-bar-height) + 1px);
  padding-inline: var(--legal-pad);
  background-color: var(--color-background-mask);
  backdrop-filter: blur(var(--blur-background-mask));
  -webkit-backdrop-filter: blur(var(--blur-background-mask));
  border-bottom: 1px solid var(--color-border-neutral);
  transition: top var(--motion-hover);
}

.legal.nav-up main > header {
  top: 0;
}

.legal main > header > :is(p, button),
.legal main > header nav a {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.04em;
}

/* "Policies", which the contents button replaces on narrow screens */
.legal main > header > p {
  min-width: 0;
  margin: 0;
  color: var(--text-strong);
}

.legal main > header > :is(p, button) {
  transition: opacity var(--motion-hover), transform var(--motion-hover);
}

.legal main > header > button {
  position: absolute;
  left: var(--legal-pad);
  top: 50%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-strong);
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(-50% + 4px));
}

.legal main > header > button:hover {
  color: var(--borderless-text-hovered);
}

.legal main > header.toc-on > p {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.legal main > header.toc-on > button {
  opacity: 1;
  transform: translateY(-50%);
  pointer-events: auto;
}

/* The chevron */
.legal main > header > button::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--motion-hover);
}

.legal main > header > button[aria-expanded="true"]::after {
  transform: translateY(2px) rotate(-135deg);
}

/* Each label has a long form and a short one, for narrow screens */
.legal main > header :is(button, a) > span:last-child {
  display: none;
}

.legal main > header nav {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
}

/* Borderless/subtle button: the current policy is the default state, the
   others use the disabled colour but stay hoverable and clickable. */
.legal main > header nav a {
  color: var(--borderless-text-disabled);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--motion-hover);
}

.legal main > header nav a:hover {
  color: var(--borderless-text-hovered);
}

.legal main > header nav a:active {
  color: var(--borderless-text-pressed);
}

.legal main > header nav a[aria-current] {
  color: var(--borderless-text-default);
}

/* --- Contents lists: beside the text, and in the bar's dropdown ---------- */

.legal :is(#toc-panel, main > div > nav > ul) {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legal :is(#toc-panel, main > div > nav > ul) li {
  min-width: 0;
}

/* Borderless/subtle small button. One line per entry; long titles truncate
   and the full title is in the tooltip. */
.legal :is(#toc-panel, main > div > nav > ul) a {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--borderless-text-default);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: -0.04em;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--motion-hover);
}

.legal :is(#toc-panel, main > div > nav > ul) a:hover {
  color: var(--borderless-text-hovered);
}

.legal :is(#toc-panel, main > div > nav > ul) a[aria-current],
.legal :is(#toc-panel, main > div > nav > ul) a[aria-current]:hover {
  color: var(--text-information);
}

/* Part labels (entries with no link) group the Terms' clauses */
.legal :is(#toc-panel, main > div > nav > ul) li:not(:has(a)) {
  padding-top: 12px;
  color: var(--text-light);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legal :is(#toc-panel, main > div > nav > ul) li:first-child:not(:has(a)) {
  padding-top: 0;
}

/* The dropdown under the bar, on narrow screens */
.legal #toc-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  display: block;
  max-height: min(60vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px var(--legal-pad) 32px;
  columns: 3 240px;
  column-gap: 40px;
  background-color: var(--color-background-white);
  border-bottom: 1px solid var(--color-border-neutral);
  box-shadow: inset 0 1px 0 var(--color-border-neutral), 0 16px 24px -16px rgba(15, 23, 42, 0.2);
}

.legal #toc-panel[hidden] {
  display: none;
}

.legal #toc-panel li {
  break-inside: avoid;
  padding-block: 6px;
}

.legal #toc-panel a {
  font-size: 14px;
  line-height: 22px;
}

/* --- Layout -------------------------------------------------------------- */

.legal main > div {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--legal-gutter);
  align-items: start;
  width: 100%;
  padding: 80px var(--grid-margin) 96px;
}

@media (min-width: 901px) {
  .legal main > div {
    max-width: calc(var(--content-max-width) + (2 * var(--grid-margin)));
    margin-inline: auto;
  }
}

/* The document's head: its dates, title and lede */
.legal main > div > header {
  grid-column: 5 / span 7;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 680px;
  min-width: 0;
  padding-bottom: 64px;
  text-align: center;
}

/* The text: the "In short" summary, on the Terms and Privacy Policy, then
   the article */
.legal main > div > :is(section, article) {
  grid-column: 5 / span 7;
  max-width: 680px;
  min-width: 0;
}

.legal main > div > section {
  grid-row: 2;
}

.legal main > div > article {
  grid-row: 3;
}

/* --- Table of contents (wide screens) ------------------------------------ */

.legal main > div > nav {
  grid-column: 1 / span 4;
  grid-row: 1 / span 3;
  align-self: start;
  position: sticky;
  top: calc(var(--header-height) + var(--legal-bar-height) + 32px);
  max-height: calc(100vh - var(--header-height) - var(--legal-bar-height) - 64px);
  overflow-y: auto;
  min-width: 0;
  padding-right: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  transition: top var(--motion-hover), max-height var(--motion-hover);
}

.legal.nav-up main > div > nav {
  top: calc(var(--legal-bar-height) + 32px);
  max-height: calc(100vh - var(--legal-bar-height) - 64px);
}

.legal main > div > nav > h2 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 24px;
  line-height: 28px;
  letter-spacing: -0.04em;
}

/* --- Document head ------------------------------------------------------- */

.legal main > div > header > p:first-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 8px;
  margin: 0;
  color: var(--text-light);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.legal main > div > header > p:first-child > [aria-hidden] {
  color: var(--border-strong);
}

.legal main > div > header > h1 {
  margin: 8px 0 0;
  max-width: 100%;
  padding-bottom: 4px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 64px;
  line-height: 66px;
  letter-spacing: -0.04em;
  text-wrap: balance;
  background: var(--gradient-purple-storm);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.legal main > div > header > h1 + p {
  margin: 24px 0 0;
  max-width: 56ch;
  color: var(--text-light);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  letter-spacing: -0.02em;
  text-wrap: pretty;
}

/* --- "In short" summary -------------------------------------------------- */

.summary {
  margin-bottom: 48px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.summary-icon {
  flex: none;
  width: 24px;
  height: 24px;
  overflow: hidden;
  color: var(--icon-light);
}

.summary-head-text {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.summary-title,
.summary-sub {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.04em;
}

.summary-title {
  color: var(--text-regular);
}

.summary-sub {
  color: var(--text-light);
}

.summary-box,
.form-box {
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding-block: 4px;
}

.summary-body,
.form-box {
  display: flex;
  flex-direction: column;
  gap: 22px;
  color: var(--text-regular);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  letter-spacing: -0.02em;
}

.summary-body {
  padding: 10px 16px;
}

.form-box {
  gap: 8px;
  padding: 14px 16px;
}

.summary-body p,
.form-box p {
  margin: 0;
}

/* --- Prose ---------------------------------------------------------------- */

.prose {
  color: var(--text-regular);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 28px;
  letter-spacing: -0.02em;
}

.prose section > * {
  margin: 0;
}

.prose section > * + * {
  margin-top: 24px;
}

.prose > * + * {
  margin-top: 56px;
}

.prose > :first-child {
  margin-top: 0;
}

.prose h2 {
  display: flex;
  gap: 12px;
  align-items: baseline;
  color: var(--text-strong);
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 28px;
  line-height: 32px;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.prose section > h2 + * {
  margin-top: 16px;
}

/* Section numbers: same face and size as the heading, in text-information */
.cl-n {
  flex-shrink: 0;
  color: var(--text-information);
  font-variant-numeric: tabular-nums;
}

/* Part A to Part E: a quieter label between groups of clauses */
.prose > h2.part-heading {
  display: block;
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--border-regular);
  color: var(--text-light);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 22px;
  font-weight: 500;
  letter-spacing: -0.04em;
}

.prose > h2.part-heading:first-child {
  margin-top: 0;
}

.prose > h2.part-heading + section {
  margin-top: 32px;
}

.prose h3 {
  color: var(--text-strong);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.prose section > h3 {
  margin-top: 32px;
}

/* Clause numbers (1.1, 2.3) */
.cl {
  display: inline-block;
  min-width: 2.6em;
  margin-right: 4px;
  color: var(--text-light);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Lettered sub-clauses (a), (b) */
.prose ol.alpha {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prose ol.alpha li {
  display: flex;
  gap: 8px;
  padding-left: 24px;
}

.prose ol.alpha .cl {
  min-width: 1.8em;
  margin: 0;
}

.prose ol.alpha .li-body {
  min-width: 0;
}

.prose ol.alpha ol.alpha {
  margin-top: 12px;
}

.prose ol.alpha ol.alpha li {
  padding-left: 0;
}

/* Bulleted lists (the Vulnerability Disclosure Policy) */
.prose ul {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 24px;
}

.prose ul li {
  padding-left: 4px;
}

.prose ul li::marker {
  color: var(--text-light);
}

/* Hostnames and other literal values */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

.prose a,
.summary a {
  color: var(--link-text-default);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  border-radius: 3px;
}

.prose a:hover,
.summary a:hover {
  color: var(--link-text-hover);
}

.prose strong,
.summary strong {
  color: var(--text-strong);
  font-weight: 500;
}

/* Clear the sticky header and bar when jumping to a clause */
.prose [id],
.summary [id] {
  scroll-margin-top: calc(var(--header-height) + var(--legal-bar-height) + 24px);
}

/* --- Tables ---------------------------------------------------------------- */

.prose .table-wrap {
  overflow-x: auto;
  margin-block: 32px;
  border-top: 1px solid var(--border-regular);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 22px;
}

.prose th {
  text-align: left;
  font-weight: 500;
  color: var(--text-strong);
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--border-regular);
  vertical-align: bottom;
}

.prose td {
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.prose td:first-child {
  width: 34%;
  color: var(--text-strong);
  font-weight: 500;
}

.prose th:last-child,
.prose td:last-child {
  padding-right: 0;
}

/* Label and value tables (contact details): the label is a row header */
.prose table.kv th {
  width: 38%;
  vertical-align: top;
  border-bottom-color: var(--border-light);
}

.prose table.kv td:first-of-type {
  width: auto;
  color: inherit;
  font-weight: 400;
}

/* Visible placeholders for details still to be filled in */
mark.todo {
  background: var(--background-warning-light);
  color: var(--text-warning);
  box-shadow: inset 0 0 0 1px var(--border-warning);
  border-radius: 4px;
  padding: 0 4px;
  font-weight: 500;
}

/* --- Responsive ------------------------------------------------------------- */

@media (max-width: 1099px) {
  .legal main > div {
    max-width: calc(680px + 2 * var(--grid-margin));
    grid-template-columns: minmax(0, 1fr);
    padding-top: 40px;
  }

  .legal main > div > :is(header, nav, section, article) {
    grid-column: 1;
    grid-row: auto;
    padding-right: 0;
  }

  .legal main > div > header {
    padding-bottom: 40px;
  }

  /* No room beside the text: the contents live in the bar dropdown */
  .legal main > div > nav {
    display: none;
  }
}

@media (max-width: 767px) {
  /* Three policy names fit in the bar only when shortened */
  .legal main > header nav a > span:last-child {
    display: inline;
  }

  .legal main > header nav a > span:first-child {
    display: none;
  }

  .legal main > div > header > h1 {
    font-size: 44px;
    line-height: 48px;
  }
}

@media (max-width: 599px) {
  .prose table,
  .prose tbody,
  .prose tr,
  .prose td,
  .prose th {
    display: block;
    width: auto !important;
  }

  .prose thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .prose tr {
    padding-block: 12px;
    border-bottom: 1px solid var(--border-light);
  }

  .prose td,
  .prose th {
    border: 0;
    padding: 0;
  }

  .prose td + td,
  .prose th + td {
    margin-top: 4px;
  }

  .prose .table-wrap {
    border-top-color: var(--border-light);
  }
}

@media (max-width: 519px) {
  /* Keep both policy names in the bar on phones */
  .legal main > header > button > span:first-child {
    display: none;
  }

  .legal main > header > button > span:last-child {
    display: inline;
  }

  .legal main > header nav {
    gap: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .legal > header,
  .legal main > header,
  .legal main > header > :is(p, button),
  .legal main > header > button::after,
  .legal main > div > nav {
    transition: none;
  }
}
