/*
 * Public legal pages nebel-it.ch/datenschutz/ and /impressum/ (plan docs/plans/2026-10-30-shared-legal-pages.md): page layer
 * on top of the shared platform CSS, after the PO's "FogForge Legal Pages Mockup" (desktop privacy policy, phone legal
 * notice, phone privacy policy with contents sheet). Dark only (E5 = A). Small upper-case mono labels are the exception D11
 * (docs/design/01-marke.md); body text stays 16 px or more, every link and button at least 44 px high. Only design tokens,
 * no colour values (tools/css_check.py). Upper case only through text-transform: the HTML keeps normal writing.
 */
@layer page {
  .ff-legal {
    --legal-guide: color-mix(in srgb, var(--ff-text) 10%, transparent);
    --legal-link-line: color-mix(in srgb, var(--ff-accent-text) 45%, transparent);
    --ff-wordmark-size: 14px;
    --ff-wordmark-tracking: 0.35em;
    --ff-spark-size: 26px;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .ff-legal__inner {
    max-width: var(--ff-content-max);
    margin: 0 auto;
    padding: 0 var(--ff-page-pad);
  }

  .ff-legal a {
    color: var(--ff-accent-text);
    text-decoration-color: var(--legal-link-line);
  }

  .ff-legal a:hover {
    text-decoration-color: var(--ff-accent-text);
  }

  .ff-legal__eyebrow,
  .ff-legal__updated,
  .ff-legal__site,
  .ff-legal__num,
  .ff-legal__built,
  .ff-legal__footer nav {
    font-family: var(--ff-font-mono);
  }

  .ff-legal__eyebrow {
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--ff-text-muted);
  }

  /* Header: the photo is decoration only (aria-hidden), dimmed and fading into the page colour */
  /* no overflow: hidden here: an open language menu may reach below the header (all layers stay inside by inset: 0) */
  .ff-legal__hero {
    position: relative;
    height: 320px;
  }

  .ff-legal__photo {
    position: absolute;
    inset: 0;
    /* the photo is not versioned by a ?v= number: a new photo gets a new file name */
    background: var(--ff-bg) url("platform/img/login-bg.jpg") 50% 30% / cover no-repeat;
    transform: scaleX(-1);
  }

  .ff-legal__photo::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--ff-bg);
    opacity: 0.35;
  }

  /* thin guide lines of the mockup */
  .ff-legal__photo::before {
    content: "";
    position: absolute;
    inset: 0 40px;
    z-index: 1;
    border-inline: 1px solid var(--legal-guide);
  }

  .ff-legal__hero::before {
    content: "";
    position: absolute;
    top: 72px;
    left: 40px;
    right: 40px;
    z-index: 1;
    height: 1px;
    background: var(--legal-guide);
  }

  /* darker at the top (the sun glow of the photo sits behind the wordmark) and fading into the page at the bottom */
  .ff-legal__hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--ff-bg) 70%, transparent), transparent 40%, transparent 50%, var(--ff-bg));
  }

  .ff-legal__hero-inner {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .ff-legal__topbar {
    display: flex;
    align-items: center;
    gap: var(--ff-space-6);
    height: 72px;
  }

  .ff-legal .ff-legal__home {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: var(--ff-target-min);
    color: var(--ff-text);
    text-decoration: none;
  }

  .ff-legal__home .ff-spark path {
    stroke-width: 8;
  }

  .ff-legal__site {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: auto;
    font-size: 11px;
    color: var(--ff-text-muted);
  }

  .ff-legal__site::before,
  .ff-legal__built::before {
    content: "";
    width: 24px;
    height: 2px;
    background: var(--ff-accent);
  }

  /* language menu: the look of the login page (language-menu.css); its options are links here, so undo the page's link
     colours, mark the current one like aria-checked there, and give the button a soft dark backing over the photo */
  .ff-legal__langs {
    position: relative;
    z-index: 5;
  }

  .ff-legal__langs .ff-lang__current {
    background: var(--ff-scrim);
  }

  .ff-legal .ff-lang__option {
    color: var(--ff-text-muted);
    text-decoration: none;
  }

  .ff-legal .ff-lang__option:hover,
  .ff-legal .ff-lang__option[aria-current="true"] {
    color: var(--ff-text);
  }

  .ff-legal .ff-lang__option[aria-current="true"]::before {
    background: var(--ff-accent);
  }

  .ff-legal__heading {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: auto;
    padding-bottom: 44px;
  }

  .ff-legal__heading h1 {
    font-size: 46px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.01em;
    color: var(--ff-text);
    overflow-wrap: break-word;
    hyphens: auto;
  }

  .ff-legal__updated {
    font-size: 12px;
    letter-spacing: 0.04em;
    color: var(--ff-text-muted);
  }

  /* Body: table of contents and text side by side, wrapping below each other when narrow */
  .ff-legal__layout {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--ff-space-12);
    padding-top: var(--ff-space-2);
    padding-bottom: 80px;
  }

  .ff-legal__toc {
    position: sticky;
    top: var(--ff-space-6);
    flex: 1 1 220px;
    max-width: 260px;
    padding-top: var(--ff-space-2);
  }

  .ff-legal__toc .ff-legal__eyebrow {
    margin-bottom: var(--ff-space-3);
  }

  .ff-legal__toc ol,
  .ff-legal__sheet ol,
  .ff-legal__sheet ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .ff-legal .ff-legal__toc a {
    display: flex;
    align-items: baseline;
    gap: 14px;
    min-height: var(--ff-target-min);
    padding: 10px 0;
    border-top: 1px solid var(--ff-divider);
    font-size: var(--ff-text-sm);
    line-height: 1.4;
    color: var(--ff-text-muted);
    text-decoration: none;
  }

  .ff-legal .ff-legal__toc a:hover {
    color: var(--ff-text);
  }

  .ff-legal__num {
    font-size: 11px;
    font-weight: 400;
    color: var(--ff-accent-text);
  }

  .ff-legal__main {
    flex: 999 1 560px;
    min-width: 0;
    max-width: 820px;
  }

  .ff-legal__panel,
  .ff-legal__card {
    background: var(--ff-surface);
    border: var(--ff-border-width) solid var(--ff-divider);
    border-radius: 2px;
  }

  .ff-legal__panel {
    padding: 48px 56px 56px;
  }

  .ff-legal__text {
    color: var(--ff-text);
    overflow-wrap: break-word;
  }

  .ff-legal__text p {
    margin: 0 0 var(--ff-space-4);
    line-height: 1.7;
  }

  .ff-legal__text section > :last-child,
  .ff-legal__card > :last-child {
    margin-bottom: 0;
  }

  .ff-legal__text ul {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 20px;
    padding-left: 20px;
  }

  .ff-legal__text li {
    padding-left: var(--ff-space-1);
    line-height: 1.7;
  }

  .ff-legal__text li::marker {
    color: var(--ff-accent);
  }

  .ff-legal__text strong {
    font-weight: 600;
  }

  .ff-legal__text h3 {
    margin: 28px 0 var(--ff-space-3);
    font-size: 17px;
    font-weight: 600;
  }

  .ff-legal__lead p {
    font-size: 18px;
    line-height: 1.65;
  }

  .ff-legal__panel section {
    padding-top: 40px;
    scroll-margin-top: var(--ff-space-6);
  }

  .ff-legal__text h2 {
    display: flex;
    align-items: baseline;
    gap: var(--ff-space-4);
    margin: 0 0 18px;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
  }

  .ff-legal__panel h2 .ff-legal__num {
    font-size: 13px;
  }

  /* Legal notice: one card per section */
  .ff-legal__cards {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .ff-legal__card {
    padding: 32px 36px;
    scroll-margin-top: var(--ff-space-6);
  }

  .ff-legal__card h2 {
    font-size: 20px;
  }

  .ff-legal__binding {
    margin: 0 0 var(--ff-space-4);
    padding: var(--ff-space-3) var(--ff-space-4);
    background: var(--ff-surface);
    border: var(--ff-border-width) solid var(--ff-divider);
    border-radius: 2px;
    line-height: 1.6;
    color: var(--ff-text-muted);
  }

  /* Footer as on the login page */
  .ff-legal__footer {
    border-top: 1px solid var(--ff-divider);
  }

  .ff-legal__footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ff-space-4) var(--ff-space-6);
    min-height: 64px;
  }

  .ff-legal__built {
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ff-text-muted);
  }

  .ff-legal__footer nav {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--ff-text-muted);
  }

  .ff-legal .ff-legal__footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--ff-target-min);
    padding: 0 var(--ff-space-2);
    color: var(--ff-text-muted);
    text-decoration: none;
  }

  .ff-legal .ff-legal__footer a:hover,
  .ff-legal .ff-legal__footer a[aria-current="page"] {
    color: var(--ff-text);
  }

  /* Phone bar and contents sheet: only on narrow screens, see below */
  .ff-legal__pagebar,
  .ff-legal__sheet {
    display: none;
  }

  @media (max-width: 959px) {
    .ff-legal {
      --ff-wordmark-size: 13px;
      --ff-spark-size: 24px;
    }

    .ff-legal__hero {
      height: 240px;
    }

    .ff-legal__photo {
      background-position: 76% 25%;
      transform: none;
    }

    .ff-legal__photo::before {
      inset: 0 16px;
    }

    .ff-legal__hero::before {
      top: 64px;
      left: 0;
      right: 0;
    }

    .ff-legal__hero-inner {
      padding: 0 max(24px, var(--ff-page-pad));
    }

    .ff-legal__topbar {
      height: 64px;
    }

    .ff-legal__site {
      display: none;
    }

    .ff-legal__langs {
      margin-left: auto;
      margin-right: calc(var(--ff-space-2) * -1);
    }

    .ff-legal__heading {
      gap: 10px;
      padding-bottom: 28px;
    }

    .ff-legal__heading h1 {
      /* "Datenschutzerklärung" must fit on one line down to 360 px */
      font-size: clamp(24px, 7.4vw, 34px);
    }

    .ff-legal__updated {
      font-size: 11px;
    }

    .ff-legal__layout {
      padding-top: var(--ff-space-1);
      padding-bottom: var(--ff-space-8);
    }

    .ff-legal__toc {
      display: none;
    }

    .ff-legal__main {
      flex-basis: 100%;
    }

    .ff-legal__panel {
      padding: 24px 20px 28px;
    }

    .ff-legal__panel section {
      padding-top: var(--ff-space-8);
    }

    .ff-legal__text h2 {
      gap: var(--ff-space-3);
      font-size: 20px;
    }

    .ff-legal__lead p {
      font-size: 17px;
    }

    .ff-legal__card {
      padding: 22px 20px;
    }

    .ff-legal__card h2 {
      font-size: 19px;
    }

    .ff-legal__footer-inner {
      justify-content: center;
      padding-top: var(--ff-space-2);
      padding-bottom: var(--ff-space-4);
    }

    .ff-legal__built {
      display: none;
    }

    /* the bar must never cover the end of the text or the footer */
    .ff-legal--privacy {
      padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }

    .ff-legal__pagebar {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 10;
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      height: calc(64px + env(safe-area-inset-bottom));
      padding-bottom: env(safe-area-inset-bottom);
      background: var(--ff-bg);
      border-top: 1px solid var(--ff-divider);
    }

    .ff-legal .ff-legal__pagebar a {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: var(--ff-space-1);
      min-height: var(--ff-target-min);
      font-size: 12px;
      font-weight: 600;
      color: var(--ff-text-muted);
      text-decoration: none;
    }

    .ff-legal__pagebar svg {
      width: 22px;
      height: 22px;
    }

    /* the sheet opens through :target (no JavaScript); a link in it moves the target and so closes it */
    .ff-legal__sheet:target {
      position: fixed;
      inset: 0;
      z-index: 20;
      display: block;
    }

    .ff-legal__scrim {
      position: absolute;
      inset: 0;
      background: var(--ff-scrim);
    }

    .ff-legal__sheet-panel {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      display: flex;
      flex-direction: column;
      max-height: 82%;
      overflow-y: auto;
      padding-bottom: calc(var(--ff-space-3) + env(safe-area-inset-bottom));
      background: var(--ff-surface);
      border-top: 1px solid var(--ff-divider);
      border-radius: 12px 12px 0 0;
    }

    .ff-legal__sheet-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 12px 6px 20px;
    }

    .ff-legal__sheet-head h2 {
      font-size: 18px;
      font-weight: 600;
    }

    .ff-legal .ff-legal__close {
      display: flex;
      align-items: center;
      justify-content: center;
      width: var(--ff-target-min);
      height: var(--ff-target-min);
      color: var(--ff-text-muted);
    }

    .ff-legal__close svg {
      width: 22px;
      height: 22px;
    }

    .ff-legal .ff-legal__sheet li a {
      display: flex;
      align-items: center;
      gap: 14px;
      min-height: 46px;
      padding: var(--ff-space-1) 20px;
      color: var(--ff-text);
      text-decoration: none;
    }

    .ff-legal .ff-legal__sheet li a:hover {
      background: var(--ff-surface-hover);
    }

    .ff-legal__sheet .ff-legal__num {
      flex: none;
      width: 20px;
      font-size: 12px;
    }

    .ff-legal__sheet .ff-legal__eyebrow {
      margin-top: 10px;
      padding: var(--ff-space-4) 20px 6px;
      border-top: 1px solid var(--ff-divider);
    }
  }
}
