/* ==========================================================================
   legal.css — Long-form legal documents (Privacy, Terms)
   Levii Portal · Design System

   Builds on .prose (typography.css). Adds a document shell with a sticky
   table of contents, a plain-language summary card, callouts, a definitions
   grid and a closing contact card. Zero hardcoded colors/spacing — all tokens.
   ========================================================================== */

/* ---- Page shell ------------------------------------------------------- */
/* The generic .section reserves a large top rhythm meant for the home page's
   full-bleed hero. Under the sticky nav on an interior document that reads as
   dead space, so tighten the top gap while keeping a comfortable bottom. */
[data-legal-root].section {
  padding-top: var(--space-md);
}
@media (min-width: 1024px) {
  [data-legal-root].section {
    padding-top: var(--space-lg);
  }
}

/* ---- Document header -------------------------------------------------- */
.legal-header {
  max-width: var(--container-wide);
  margin-inline: auto;
}
.legal-header h1 {
  margin-top: var(--space-xs);
}
.legal-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs) var(--space-md);
  margin-top: var(--space-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.legal-meta__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
.legal-meta__item svg {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  opacity: 0.85;
}
.legal-meta__dot {
  width: 4px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

/* ---- Two-column shell (TOC + content) -------------------------------- */
.legal-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-xl);
  max-width: var(--container-wide);
  margin-inline: auto;
  margin-top: var(--space-xl);
  align-items: start;
}
@media (min-width: 1024px) {
  .legal-layout {
    grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
    gap: var(--space-2xl);
  }
}

/* ---- Table of contents ----------------------------------------------- */
.legal-toc {
  position: static;
}
@media (min-width: 1024px) {
  .legal-toc {
    position: sticky;
    top: calc(var(--nav-height) + var(--space-md));
    max-height: calc(100vh - var(--nav-height) - var(--space-xl));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}
.legal-toc__card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.legal-toc__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.legal-toc__summary::-webkit-details-marker {
  display: none;
}
.legal-toc__summary .legal-toc__chevron {
  width: 1.1em;
  height: 1.1em;
  transition: transform var(--dur-fast) var(--ease-out);
}
@media (min-width: 1024px) {
  /* On desktop the TOC is always open; hide the disclosure affordance. */
  .legal-toc__chevron {
    display: none;
  }
  .legal-toc__summary {
    cursor: default;
  }
}
.legal-toc[open] .legal-toc__chevron {
  transform: rotate(180deg);
}
.legal-toc__nav {
  padding: 0 var(--space-xs) var(--space-sm);
}
.legal-toc__list {
  list-style: none;
  counter-reset: toc;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.legal-toc__list a {
  counter-increment: toc;
  display: flex;
  gap: 0.6em;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.35;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.legal-toc__list a::before {
  content: counter(toc, decimal-leading-zero);
  color: var(--brand-blue-500);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  opacity: 0.7;
}
.legal-toc__list a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.legal-toc__list a[aria-current='true'] {
  background: color-mix(in srgb, var(--brand-blue-500) 12%, transparent);
  color: var(--text);
  font-weight: 500;
}
.legal-toc__list a[aria-current='true']::before {
  opacity: 1;
}

/* ---- Content column -------------------------------------------------- */
.legal-content {
  min-width: 0;
}
/* Numbered top-level sections for a formal legal feel. */
.legal-content .prose {
  max-width: 74ch;
  counter-reset: legal-section;
}
.legal-content .prose h2 {
  counter-increment: legal-section;
  display: flex;
  gap: 0.55em;
  align-items: baseline;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}
.legal-content .prose h2::before {
  content: counter(legal-section);
  font-size: 0.72em;
  font-variant-numeric: tabular-nums;
  color: var(--brand-blue-500);
  font-weight: 700;
  flex: none;
}
.legal-content .prose > h2:first-child {
  border-top: none;
  padding-top: 0;
}

/* ---- Plain-language summary card ------------------------------------- */
.legal-summary {
  position: relative;
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  isolation: isolate;
}
.legal-summary::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--gradient-aurora);
  opacity: 0.5;
  pointer-events: none;
}
.legal-summary__label {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--brand-blue-500);
}
.legal-summary h2 {
  margin-top: var(--space-2xs);
  font-size: var(--text-xl);
  color: var(--text);
}
.legal-summary__grid {
  display: grid;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}
@media (min-width: 640px) {
  .legal-summary__grid {
    grid-template-columns: 1fr 1fr;
  }
}
.legal-summary__item {
  display: flex;
  gap: 0.7em;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-secondary);
}
.legal-summary__item svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  margin-top: 0.1em;
  color: var(--brand-teal-500);
}
.legal-summary__item strong {
  color: var(--text);
  display: block;
  font-weight: 600;
}

/* ---- Callouts -------------------------------------------------------- */
.legal-callout {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-secondary);
}
.legal-callout svg {
  width: 1.4rem;
  height: 1.4rem;
  flex: none;
  margin-top: 0.15em;
  color: var(--brand-blue-500);
}
.legal-callout strong {
  color: var(--text);
}
.legal-callout--warn {
  background: color-mix(in srgb, var(--warning) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
}
.legal-callout--warn svg {
  color: var(--warning);
}

/* ---- Definitions grid ------------------------------------------------ */
.legal-defs {
  display: grid;
  gap: var(--space-sm);
  margin: 0;
  padding: 0;
}
@media (min-width: 640px) {
  .legal-defs {
    grid-template-columns: 1fr 1fr;
  }
}
.legal-def {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.legal-def dt {
  font-weight: 600;
  color: var(--text);
  font-size: var(--text-base);
}
.legal-def dd {
  margin: 0.35em 0 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.55;
}

/* ---- Data-use table -------------------------------------------------- */
.legal-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}
.legal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 34rem;
}
.legal-table th,
.legal-table td {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  vertical-align: top;
  line-height: 1.5;
  border-bottom: 1px solid var(--border);
}
.legal-table thead th {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}
.legal-table tbody tr:last-child td {
  border-bottom: none;
}
.legal-table td:first-child {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

/* ---- Closing contact card -------------------------------------------- */
.legal-contact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-top: var(--space-2xl);
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-xl);
  background: var(--gradient-brand);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-lg);
}
.legal-contact h2 {
  color: var(--text-on-brand);
  font-size: var(--text-xl);
  margin: 0;
}
.legal-contact p {
  margin-top: 0.35em;
  color: color-mix(in srgb, var(--text-on-brand) 88%, transparent);
  font-size: var(--text-base);
  max-width: 44ch;
}
.legal-contact .btn {
  flex: none;
}
/* Solid light button that stays legible on the brand gradient. */
.btn--light {
  --btn-bg: var(--white);
  --btn-fg: var(--slate-900);
  --btn-border: transparent;
  box-shadow: var(--shadow-sm);
}
@media (hover: hover) {
  .btn--light:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
}

/* Back-to-top pill inside prose sections */
.legal-backtop {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-decoration: none;
  margin-top: 0.5em;
}
.legal-backtop:hover {
  color: var(--text);
}
.legal-backtop svg {
  width: 1em;
  height: 1em;
}
