/* ==========================================================
   VUELVA USTED MAÑANA — Páginas legales
   Necesita ../css/tokens.css (y usa style.css + ui-components.css).
   Todo dentro de @layer: el orden de capas lo declara tokens.css.
   ========================================================== */
@view-transition { navigation: auto; }

@layer screens {
  body.legal-page {
    padding: 0 0 max(32px, env(safe-area-inset-bottom, 0px));
    background: var(--canvas);
  }
  /* Con el aviso de cookies abierto, el final de la página sigue alcanzable */
  body.legal-page.cc-open { padding-bottom: calc(var(--cc-h, 0px) + 16px); }

  /* ---------------- Cabecera: sello + marca + volver ---------------- */
  .lg-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 16px;
    max-width: 808px;
    margin: 0 auto;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(var(--gutter), env(safe-area-inset-right, 0px)) 8px max(var(--gutter), env(safe-area-inset-left, 0px));
  }
  .lg-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    color: var(--ink);
    font: 700 15px/1 var(--ui);
    letter-spacing: -.01em;
    white-space: nowrap;
  }
  .lg-brand .wm-m {
    font-family: var(--stamp-f);
    font-weight: 400;
    font-size: 18px;
    color: var(--red);
    letter-spacing: 0;
  }
  .back {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 4px;
    color: var(--ink-2);
    font: 600 var(--fs-sm)/1.2 var(--ui);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
  }
  .back:hover { color: var(--ink); text-decoration-thickness: 2px; }

  /* ---------------- El oficio ---------------- */
  .doc {
    position: relative;
    max-width: 760px;
    margin: 4px auto 0;
    padding: clamp(24px, 5vw, 48px) clamp(18px, 5vw, 48px) clamp(24px, 4vw, 40px);
    border-radius: var(--r-lg);
    background: var(--paper);
    box-shadow: var(--e2);
    overflow: hidden;
    view-transition-name: paper;
  }
  /* Filete institucional de 2 px (rojo / gualda / rojo) */
  .doc::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, var(--red) 0 25%, var(--marker) 25% 75%, var(--red) 75%);
  }
  .doc .doc-kicker {
    margin: 0 0 8px;
    color: var(--ink-3);
    font: 600 var(--fs-cap)/1.3 var(--ui);
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .doc h1 {
    margin: 0 0 6px;
    color: var(--ink);
    font: 800 clamp(1.75rem, 4vw + 1rem, 2.5rem)/1.1 var(--ui);
    letter-spacing: -.025em;
  }
  .doc h2 {
    margin: 32px 0 8px;
    color: var(--ink);
    font: 700 1.1875rem/1.3 var(--ui);
    letter-spacing: -.01em;
  }
  .doc p, .doc li {
    font-family: var(--read);
    font-size: var(--fs-read);
    line-height: 1.6;
    max-width: 66ch;
  }
  .doc p { margin: 0 0 14px; }
  .doc ul, .doc ol { padding-left: 22px; margin: 0 0 14px; }
  .doc li { margin-bottom: 6px; }
  .doc a { color: var(--ink); font-weight: 600; text-underline-offset: 3px; }
  .doc code { font-family: var(--mono); font-size: .875em; background: var(--sunken); padding: .05em .35em; border-radius: var(--r-xs); }
  .doc .upd { margin: 0 0 24px; color: var(--ink-3); font-family: var(--ui); font-size: .8125rem; }

  /* Ficha de datos del titular */
  .box {
    margin: 12px 0 16px;
    padding: 14px 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    background: var(--surface);
    font: 400 var(--fs-md)/1.7 var(--ui);
    box-shadow: var(--e1);
  }
  .box, td, code { overflow-wrap: anywhere; }

  /* Tablas */
  .doc table {
    width: 100%;
    margin: 12px 0 16px;
    border-collapse: collapse;
    font: 400 var(--fs-sm)/1.45 var(--ui);
  }
  .doc th, .doc td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
  }
  .doc th {
    background: var(--sunken);
    color: var(--ink-2);
    font: 600 var(--fs-cap)/1.3 var(--ui);
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  /* ---------------- Pie: el resto de páginas ---------------- */
  nav.legal {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 12px;
    max-width: 760px;
    margin: 20px auto 0;
    padding: 0 var(--gutter);
    color: var(--ink-3);
    font: 500 var(--fs-sm)/1.4 var(--ui);
  }
  nav.legal a, nav.legal button {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 4px;
    border: 0;
    background: none;
    color: var(--ink-2);
    font: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    cursor: pointer;
  }
  nav.legal a:hover, nav.legal button:hover { color: var(--ink); }
  nav.legal [aria-current="page"] { color: var(--ink); font-weight: 700; text-decoration: none; }
  .lg-sep { display: none; }

  /* ---------------- Móvil: papel de borde a borde y tablas en fichas ---------------- */
  @media (max-width: 599px) {
    .doc { border-radius: 0; box-shadow: 0 1px 0 var(--line), 0 -1px 0 var(--line); }
    .doc p, .doc li { font-size: var(--fs-md); line-height: 1.625; }
    .doc table, .doc tbody, .doc tr, .doc td { display: block; width: 100%; }
    .doc tr:first-child:has(th) { display: none; }
    .doc th { display: none; }
    .doc tr {
      margin: 0 0 10px;
      padding: 10px 14px;
      border: 1px solid var(--line);
      border-radius: var(--r-md);
      background: var(--surface);
      box-shadow: var(--e1);
    }
    .doc td { padding: 4px 0; border: 0; }
    .doc td::before {
      content: attr(data-label);
      display: block;
      color: var(--ink-3);
      font: 600 var(--fs-cap)/1.4 var(--ui);
      letter-spacing: .06em;
      text-transform: uppercase;
    }
    .doc td:first-child { font-weight: 700; }
  }
  @media (max-width: 360px) {
    .doc p, .doc li { line-height: 1.6; }
    .lg-brand { font-size: 14px; }
    .lg-brand .wm-m { font-size: 17px; }
  }

  @media print {
    body.legal-page { background: #fff; }
    .lg-top .back, nav.legal, .cc-banner { display: none; }
    .doc { box-shadow: none; max-width: none; padding: 0; }
  }
}
