/* legal.css — the public legal pages (/privacy, /terms: templates/legal/*),
 * in the EUDR platform's legal design (EUDR css/legal.css:6-175,
 * html/privacy-policy.html; handbook S1 §2.7 and §4.16, S4 §4.1):
 *   - a sticky top bar on the chrome colour with "← Back to platform";
 *   - a head on the page's ground: the icon disc, the "Legal" kicker, the h1
 *     over an accent rule, and "Last updated · Version";
 *   - a 240px contents list, sticky at 84px, beside the document card; the
 *     headings keep 84px clear above them (scroll-margin-top), so a contents
 *     link lands with its heading below the top bar;
 *   - callouts with an accent edge, tables in a box that scrolls sideways
 *     (never the page), the change history at the end, a footer of links;
 *   - one column under 860px, the contents list no longer sticky;
 *   - print: only the document (no bars, no contents, no footer), dark on
 *     white even when the screen is dark.
 * The pages follow the app's dark mode (theme-boot.js / theme-body.js, as
 * EUDR's do): every colour is a token that dark.css flips, and the chrome
 * tokens are the same in both themes. Nothing here may touch another page:
 * this sheet is linked on every page (base.html), so each rule sits under
 * .ct-legal. */

.ct-legal {
  /* body text: between the ink and the muted grey, like EUDR's --lg-body */
  --legal-body: color-mix(in srgb, var(--text) 72%, var(--text-muted));
  min-height: 100vh;
  color: var(--text);
  line-height: 1.7;
}

/* ── Top bar ── */
.ct-legal-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 10px 24px;
  background: var(--chrome-bg);
  color: var(--chrome-ink);
  box-shadow: 0 1px 0 var(--chrome-line);
}
.ct-legal-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--chrome-ink);
  text-decoration: none;
}
.ct-legal-brand:hover {
  color: var(--chrome-ink);
}
.ct-legal-brand img {
  display: block;
  width: auto;
  height: 36px;
}
.ct-legal-brand span {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.ct-legal-topbar-end {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}
.ct-legal-back,
.ct-legal-lang {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--chrome-ink) 28%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--chrome-ink);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.ct-legal-back:hover,
.ct-legal-lang:hover {
  background: var(--chrome-hover);
  color: var(--chrome-ink);
}
.ct-legal-topbar :focus-visible {
  outline: 2px solid var(--chrome-active-ink);
  outline-offset: 2px;
}

/* ── Layout ── */
.ct-legal-wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

/* the head, on the ground: icon disc, kicker, title over the accent rule, meta */
.ct-legal-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.ct-legal-head-icon {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--page-badge);
  color: var(--page-badge-ink);
}
.ct-legal-head-text {
  flex: 1;
  min-width: 0;
}
.ct-legal-kicker,
.ct-legal-toc-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ct-legal-kicker {
  color: var(--canvas-text-muted);
}
.ct-legal-head h1 {
  margin: 2px 0 6px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--page-rule);
  color: var(--canvas-text);
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.ct-legal-meta {
  margin: 0;
  color: var(--canvas-text-muted);
  font-size: 0.85rem;
}

.ct-legal-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

/* ── Contents ── */
.ct-legal-toc {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px;
  border: 1px solid var(--page-card-edge);
  border-radius: 12px;
  background: var(--page-card);
}
.ct-legal-toc-title {
  margin-bottom: 8px;
  color: var(--text-muted);
}
.ct-legal-toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.ct-legal-toc li {
  margin: 0;
}
.ct-legal-toc a {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--legal-body);
  font-size: 0.84rem;
  line-height: 1.4;
  text-decoration: none;
}
.ct-legal-toc a:hover,
.ct-legal-toc a:focus-visible {
  background: var(--primary-soft);
  color: var(--text);
}

/* ── The document ── */
.ct-legal-card {
  padding: 32px 40px;
  border: 1px solid var(--page-card-edge);
  border-radius: 12px;
  background: var(--page-card);
  box-shadow: var(--page-card-shadow);
}
.ct-legal-card h2 {
  margin: 32px 0 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.35;
  scroll-margin-top: 84px;
}
.ct-legal-card > h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.ct-legal-card > .ct-legal-callout:first-child + h2 {
  margin-top: 24px;
}
.ct-legal-card h3 {
  margin: 20px 0 8px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.4;
  scroll-margin-top: 84px;
}
.ct-legal-card p,
.ct-legal-card li {
  color: var(--legal-body);
  font-size: 0.93rem;
}
.ct-legal-card p {
  margin: 0 0 12px;
}
.ct-legal-card ul,
.ct-legal-card ol {
  margin: 0 0 14px;
  padding-left: 22px;
}
.ct-legal-card li {
  margin-bottom: 6px;
}
.ct-legal-card li::marker {
  color: var(--accent);
}
.ct-legal-card strong {
  color: var(--text);
}
.ct-legal-card a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.ct-legal-card a:hover {
  color: var(--link-hover);
}

/* callouts (EUDR .highlight-box / .legal-lead) */
.ct-legal-callout {
  margin: 14px 0;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--legal-body);
  font-size: 0.9rem;
}
.ct-legal-card > .ct-legal-callout:first-child {
  margin-top: 0;
}

/* tables: a wide one scrolls inside its box on a phone, never the page
   (EUDR subprocessors.html:120-128). The box is focusable and named, so the
   keyboard can scroll it too. */
.ct-legal-table-wrap {
  margin: 12px 0 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  overscroll-behavior-x: contain;
}
.ct-legal-table-wrap:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.ct-legal-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.ct-legal-table th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--table-head-edge);
  background: var(--table-head);
  color: var(--table-head-ink);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.ct-legal-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--legal-body);
  vertical-align: top;
}
.ct-legal-table td:first-child {
  color: var(--text);
  font-weight: 600;
}
.ct-legal-table tr:last-child td {
  border-bottom: none;
}

/* the change history (EUDR privacy-policy.html:527-567) */
.ct-legal-history li strong {
  white-space: nowrap;
}

/* ── Footer, on the ground ── */
.ct-legal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin-top: 24px;
  color: var(--canvas-text-muted);
  font-size: 0.84rem;
}
.ct-legal-foot a {
  color: var(--canvas-text-muted);
  text-decoration: none;
}
.ct-legal-foot a:hover,
.ct-legal-foot a:focus-visible,
.ct-legal-foot a[aria-current="page"] {
  color: var(--canvas-text);
  text-decoration: underline;
}
.ct-legal-foot-copy {
  margin-right: auto;
}

/* ── Two languages, one shown ──
   Both language versions ship; the one matching <html lang> shows
   (pages/legal-boot.js sets it before the first paint, core/i18n.js keeps
   it). English when nothing has set it, so the page is never blank. */
.ct-legal [data-legal-lang="el"],
html[lang="el"] .ct-legal [data-legal-lang="en"] {
  display: none;
}
html[lang="el"] .ct-legal [data-legal-lang="el"] {
  display: block;
}

/* ── Narrow screens ── */
/* The window scrolls, not the body. At ≤768px mobile.css sets html and body
   to overflow-x: hidden, which turns the 100%-high body (app.css) into a
   scroll box of its own: the address bar never slides away, Back cannot put
   the reader back where they were, and the sticky top bar pins to the body.
   `clip` cuts sideways without making a scroll box, as the shell does
   (mobile.css "here the window scrolls"). */
@media (max-width: 768px) {
  body:has(> .ct-legal) {
    height: auto;
    overflow: visible;
    overflow-x: clip;
  }
}
@media (max-width: 860px) {
  .ct-legal-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .ct-legal-toc {
    position: static;
    max-height: none;
  }
}
@media (max-width: 600px) {
  .ct-legal-topbar {
    gap: 10px;
    min-height: 56px;
    padding: 8px 16px;
  }
  .ct-legal-brand span {
    display: none;
  }
  .ct-legal-brand img {
    height: 32px;
  }
  .ct-legal-back,
  .ct-legal-lang {
    min-height: 40px;
    padding: 0 12px;
  }
  .ct-legal-wrap {
    padding: 20px 16px 40px;
  }
  .ct-legal-head {
    gap: 12px;
  }
  .ct-legal-head-icon {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }
  .ct-legal-head h1 {
    font-size: 1.3rem;
  }
  .ct-legal-card {
    padding: 20px 18px;
  }
}

/* ── Print: only the document, dark on white ── */
@media print {
  /* dark.css gives a dark page `color-scheme: dark`, which paints the
     canvas dark even with every background off */
  html:has(.ct-legal),
  html:has(.ct-legal) body {
    color-scheme: light !important;
    background: var(--brand-white) !important;
  }
  body:has(.ct-legal)::before {
    display: none !important;
  }
  .ct-legal {
    /* paper-light whatever the screen's theme: the palette's fixed inks */
    --text: var(--storm-deep);
    --text-muted: var(--storm-72);
    --canvas-text: var(--storm-deep);
    --canvas-text-muted: var(--storm-72);
    --link: var(--cyan-ink);
    --accent: var(--cyan-deep);
    --border: var(--storm-14);
    --page-rule: var(--cyan-deep);
    --primary-soft: transparent;
    --table-head: transparent;
    --table-head-ink: var(--storm-deep);
    --table-head-edge: var(--storm-25);
    min-height: 0;
    color: var(--text);
  }
  .ct-legal-topbar,
  .ct-legal-toc,
  .ct-legal-foot {
    display: none !important;
  }
  .ct-legal-wrap {
    max-width: none;
    padding: 0;
  }
  .ct-legal-grid {
    display: block;
  }
  .ct-legal-card {
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
  }
  .ct-legal-head-icon {
    display: none;
  }
  .ct-legal-table-wrap {
    overflow: visible;
  }
  .ct-legal-card h2,
  .ct-legal-card h3 {
    break-after: avoid;
  }
  .ct-legal-callout,
  .ct-legal-table tr {
    break-inside: avoid;
  }
}
