/* 32-legal.css — privacy.html and terms.html.
   Long-form reading on the app's own tokens (01-tokens.css), so the pages
   theme (dark / light) and mirror (RTL / LTR) exactly like the rest of
   TradePad. Each page carries its text in all four languages; only the
   article matching <html data-lang> (set before paint by js/app/preboot.js,
   then by js/legal/legal-page.js) is shown. Without script, English. */

.legal-body {
  --legal-text: color-mix(in srgb, var(--ink) 84%, var(--bg));
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Which language ───────────────────────────────────────────────────── */

.legal-doc { display: none; }
html:not([data-lang]) .legal-doc[data-lang="en"],
html[data-lang="en"] .legal-doc[data-lang="en"],
html[data-lang="fa"] .legal-doc[data-lang="fa"],
html[data-lang="ar"] .legal-doc[data-lang="ar"],
html[data-lang="tr"] .legal-doc[data-lang="tr"] { display: block; }

/* ── Top bar ──────────────────────────────────────────────────────────── */

.legal-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.legal-bar-in {
  max-width: 820px;
  margin: 0 auto;
  height: 58px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding-inline-end: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--fs-lg);
  border-radius: var(--r-md);
}
.legal-back .ic { width: 18px; height: 18px; color: var(--dim); }
html[dir="rtl"] .legal-back .ic { transform: scaleX(-1); }
.legal-back img { width: 28px; height: 28px; border-radius: 8px; }
.legal-back:hover .ic { color: var(--acc); }
.legal-back:focus-visible,
.legal-tabs a:focus-visible,
.legal-lang select:focus-visible,
.legal-toc a:focus-visible { outline: none; box-shadow: var(--ring); }

.legal-lang { position: relative; display: inline-flex; align-items: center; }
.legal-lang .ic {
  position: absolute;
  inset-inline-start: 11px;
  width: 16px;
  height: 16px;
  color: var(--dim);
  pointer-events: none;
}
.legal-lang select {
  -webkit-appearance: none;
  appearance: none;
  height: 38px;
  padding-block: 0;
  padding-inline: 34px 14px;
  border: 1px solid var(--line2);
  border-radius: var(--r-pill);
  background: var(--surf2);
  color: var(--ink);
  font: 600 var(--fs-sm) / 1 var(--sans);
  cursor: pointer;
}
.legal-lang select option { background: var(--surf2); color: var(--ink); }

/* ── Page ─────────────────────────────────────────────────────────────── */

.legal-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 22px 16px calc(64px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
  .legal-main { padding: 36px 24px 96px; }
}

.legal-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  max-width: 100%;
}
.legal-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  color: var(--dim);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.legal-tabs a:hover { color: var(--ink); }
.legal-tabs a[aria-current="page"] {
  background: var(--surf3);
  color: var(--ink);
  box-shadow: var(--hl);
}

/* ── Article ──────────────────────────────────────────────────────────── */

.legal-head { margin-top: 26px; }
.legal-head h1 {
  font-size: clamp(26px, 6vw, 36px);
  line-height: 1.25;
  font-weight: 800;
  color: var(--ink);
}
html[dir="ltr"] .legal-head h1 { letter-spacing: -.015em; }
.legal-date {
  margin-top: 8px;
  color: var(--mute);
  font-size: var(--fs-sm);
}
.legal-lead {
  margin-top: 16px;
  color: var(--legal-text);
  font-size: 16px;
  line-height: 1.75;
}

.legal-sum {
  margin-top: 26px;
  padding: 18px 20px 18px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--acc);
  border-radius: var(--r-lg);
  box-shadow: var(--hl);
}
.legal-sum h2 {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}
.legal-sum ul { list-style: none; display: grid; gap: 8px; }
.legal-sum li {
  position: relative;
  padding-inline-start: 26px;
  color: var(--legal-text);
  font-size: 15px;
  line-height: 1.7;
}
.legal-sum li::before {
  content: "";
  position: absolute;
  inset-inline-start: 2px;
  top: .55em;
  width: 13px;
  height: 7px;
  border-inline-start: 2px solid var(--acc);
  border-bottom: 2px solid var(--acc);
  transform: rotate(-45deg);
}
html[dir="rtl"] .legal-sum li::before { transform: rotate(45deg); }

/* Contents — filled by legal-page.js from the article's own headings. */
.legal-toc {
  margin-top: 18px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.legal-toc:empty { display: none; }
.legal-toc summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 0 18px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  font-size: var(--fs-md);
  color: var(--ink);
}
.legal-toc summary::-webkit-details-marker { display: none; }
.legal-toc summary .ic { width: 16px; height: 16px; color: var(--mute); transition: transform var(--t2) var(--ease); }
.legal-toc details[open] summary .ic { transform: rotate(180deg); }
.legal-toc ol {
  list-style: none;
  padding: 0 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}
@media (min-width: 720px) {
  .legal-toc ol { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 8px; }
}
.legal-doc .legal-toc a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--dim);
  font-size: var(--fs-sm);
  line-height: 1.5;
  text-decoration: none;
}
.legal-doc .legal-toc a:hover { background: var(--hover); color: var(--ink); }
.legal-toc a b { color: var(--mute); font-weight: 600; min-width: 1.4em; font-variant-numeric: tabular-nums; }

.legal-doc section { scroll-margin-top: calc(76px + env(safe-area-inset-top)); padding-top: 34px; }
.legal-doc section h2 {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 20px;
  line-height: 1.4;
  font-weight: 750;
  color: var(--ink);
}
.legal-doc section h2 .n {
  flex: 0 0 auto;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: var(--acc-dim);
  color: var(--acc);
  font-size: var(--fs-sm);
  font-weight: 700;
  transform: translateY(-2px);
}
.legal-doc h3 {
  margin-top: 18px;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--ink);
}
.legal-doc section p,
.legal-doc section li {
  color: var(--legal-text);
  font-size: 15.5px;
  line-height: 1.8;
}
html[dir="rtl"] .legal-doc section p,
html[dir="rtl"] .legal-doc section li,
html[dir="rtl"] .legal-lead,
html[dir="rtl"] .legal-sum li { line-height: 1.95; }
.legal-doc section p { margin-top: 10px; }
.legal-doc section ul { margin-top: 8px; padding-inline-start: 22px; display: grid; gap: 6px; }
.legal-doc section li::marker { color: var(--mute); }
.legal-doc strong { color: var(--ink); font-weight: 700; }
.legal-doc a { color: var(--acc); text-underline-offset: 3px; }
.legal-mail[hidden] { display: none; }

/* ── Footer ───────────────────────────────────────────────────────────── */

.legal-foot {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 20px;
  color: var(--mute);
  font-size: var(--fs-sm);
}
.legal-foot nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.legal-foot a { color: var(--dim); text-decoration: none; }
.legal-foot a:hover { color: var(--acc); }

/* ── Print: just the text ─────────────────────────────────────────────── */

@media print {
  .legal-bar, .legal-tabs, .legal-toc, .legal-foot nav { display: none !important; }
  body.legal-body { background: #fff; color: #000; --legal-text: #111; }
  body.legal-body::before { display: none; }
  .legal-doc section h2, .legal-head h1, .legal-doc strong, .legal-sum h2 { color: #000; }
  .legal-sum { border-color: #999; box-shadow: none; background: none; }
  .legal-doc section h2 .n { background: none; color: #000; }
  .legal-doc section { break-inside: avoid-page; }
}

@media (prefers-reduced-motion: reduce) {
  .legal-toc summary .ic { transition: none; }
}
