/* =========================================================================
   shell.css — o shell "Caderno de campo" (spec 0050): trilho lateral fixo no
   desktop, gaveta no celular, grade de leitura, sumário na margem.
   Só tokens de styles.css. Camadas: layout > components. Sem gradiente,
   sem sombra fora da gaveta, raio 4 px (papel), borda dupla (caderno).
   ========================================================================= */
  :root {
    --rail-w: 264px;
    --toc-w: 220px;
    --rail-bg: #EBE1CD;          /* creme um tom abaixo do fundo (tema kraft) */
    --topbar-h: 56px;
  }
  body[data-theme="kraft"] { --rail-bg: #EBE1CD; }

  /* a grade: trilho | leitura | margem */
  body.shell { margin: 0; }
  body.shell > main, body.shell > .shell-main { min-width: 0; }
  @media (min-width: 1024px) {
    body.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); }
    body.shell > .topbar { display: none; }
    body.shell > .rail { position: sticky; top: 0; height: 100vh; overflow-y: auto; grid-column: 1; grid-row: 1 / span 12; }
    body.shell > main, body.shell > .shell-main, body.shell > .site-footer, body.shell > .sticky-cta, body.shell > .dispatch-float { grid-column: 2; }
    body.shell > .rail-backdrop { display: none !important; }
  }
  /* páginas longas: coluna de leitura + margem com sumário */
  @media (min-width: 1280px) {
    body.shell main .container { max-width: calc(var(--maxw) - var(--toc-w)); }
    body.shell main .has-toc { display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 40px; align-items: start; }
  }
  @media (max-width: 1023.98px) {
    body.shell { padding-top: var(--topbar-h); }
  }

  /* ---- barra superior (só < 1024) ------------------------------------ */
  .topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 40; display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; background: rgba(var(--bg-rgb), 0.96); border-bottom: 1px solid var(--border-strong); backdrop-filter: saturate(140%) blur(6px); }
  .topbar-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 0.98rem; text-decoration: none; }
  .topbar-brand svg { color: var(--primary); }
  .topbar-menu { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--border-strong); border-radius: 4px;
    background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; }
  .topbar-menu[aria-expanded="true"] { border-color: var(--ink); }

  /* ---- trilho / gaveta ---------------------------------------------- */
  .rail { background: var(--rail-bg); border-right: 3px double var(--border-strong); color: var(--ink); }
  .rail-inner { padding: 22px 20px 28px; display: flex; flex-direction: column; gap: 22px; }
  .rail-brand { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; color: var(--ink); text-decoration: none; }
  .rail-brand svg { color: var(--primary); grid-row: span 2; }
  .rail-brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; }
  .rail-brand-sub { font-family: var(--font-serif, Georgia, serif); font-style: italic; font-size: 0.82rem; color: var(--muted); }
  .rail-close { display: none; position: absolute; top: 8px; right: 12px; width: 44px; height: 44px; border: 1.5px solid var(--border-strong); border-radius: 4px; background: var(--surface); font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--ink); }
  .rail-h, .journal h2.rail-h, .journal h3.rail-h, .journal .rail-h { font-family: var(--font-sans); font-size: 0.7rem; line-height: 1.3; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--primary-text); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
  .rail-tag { font-size: 0.6rem; letter-spacing: 0.08em; border: 1.5px solid var(--cta-hover); color: var(--cta-hover); border-radius: 3px; padding: 2px 5px; }
  .rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
  .rail-list a { display: block; padding: 6px 8px; margin: 0 -8px; border-radius: 4px; color: var(--ink); text-decoration: none; font-size: 0.92rem; line-height: 1.35; min-height: 24px; }
  .rail-list a:hover { background: rgba(var(--shadow-rgb), 0.06); }
  .rail-list a[aria-current="page"] { background: var(--surface); border: 1px solid var(--border-strong); font-weight: 600; }
  .rail-list a small, .rail-list li.soon small { display: block; font-size: 0.74rem; color: var(--muted); font-weight: 500; }
  .rail-list li.soon { padding: 6px 0; color: var(--muted); font-size: 0.92rem; display: grid; grid-template-columns: auto 1fr; gap: 10px; }
  .rail-chapters a { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
  .rail-num { font-family: var(--font-serif, Georgia, serif); font-style: italic; color: var(--muted); }
  .rail-list a[data-read="true"]::after { content: " ✓"; color: var(--primary-text); }
  .rail-week { background: var(--surface); border: 3px double var(--border-strong); border-radius: 4px; padding: 12px 14px; }
  .rail-week-date { font-family: var(--font-serif, Georgia, serif); font-style: italic; margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }
  .rail-week-text { margin: 0 0 8px; font-size: 0.9rem; line-height: 1.45; color: var(--ink); }
  .rail-week-link { font-size: 0.88rem; font-weight: 600; color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
  .rail-continue a { display: block; font-size: 0.9rem; color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
  .rail-fine { font-size: 0.74rem; color: var(--muted); margin: 6px 0 0; }
  .rail-updated { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-strong); }
  .rail-dispatch { border: 3px double var(--border-strong); border-radius: 4px; padding: 12px 14px; background: var(--surface); margin: 0; }
  .rail-dispatch p { font-size: 0.86rem; color: var(--muted); margin: 0 0 8px; }
  .rail-dispatch form { display: grid; gap: 8px; }
  .rail-dispatch input[type="email"] { width: 100%; font: inherit; font-size: 0.95rem; padding: 8px 10px; border: 0; border-bottom: 2px solid var(--border-strong); background: transparent; border-radius: 0; }
  .rail-dispatch .btn { width: 100%; padding: 9px 12px; font-size: 0.9rem; }

  /* gaveta (celular): o trilho vira painel deslizante, padrão disclosure (aria-expanded no botão) */
  @media (max-width: 1023.98px) {
    /* sem JS o trilho fica no fluxo, antes do conteúdo (o skip-link pula); com JS vira gaveta */
    .js .rail { position: fixed; top: 0; left: 0; bottom: 0; width: min(88vw, 360px); z-index: 60; overflow-y: auto; transform: translateX(-104%);
      transition: transform 0.28s var(--ease); box-shadow: var(--shadow-lg); border-right: 3px double var(--border-strong); }
    .rail[data-open="true"] { transform: none; }
    .js .rail-close { display: block; }
    html:not(.js) .topbar-menu { display: none; }
    .rail-inner { padding-top: 56px; }
    .rail-backdrop { position: fixed; inset: 0; background: rgba(35, 41, 31, 0.45); z-index: 50; }
    .rail-backdrop[hidden] { display: none; }
    body.rail-open { overflow: hidden; }
  }
  @media (prefers-reduced-motion: reduce) { .rail { transition: none; } }

  /* ---- contexto de capítulo abaixo do título (celular e desktop) ------ */
  .page-context { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; font-size: 0.82rem; color: var(--muted); margin: -6px 0 18px; }
  .page-context a { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }

  /* ---- sumário na margem (≥ 1280) -------------------------------------- */
  .toc { display: none; }
  @media (min-width: 1280px) {
    .toc { display: block; position: sticky; top: 24px; font-size: 0.86rem; border-left: 3px double var(--border-strong); padding-left: 16px; }
    .toc .rail-h { margin-bottom: 10px; }
    .toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
    .toc a { color: var(--muted); text-decoration: none; display: block; line-height: 1.35; }
    .toc a[aria-current="true"] { color: var(--ink); font-weight: 600; }
    .toc a:hover { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
  }

  /* ---- home "mesa do caderno" ----------------------------------------- */
  .desk { display: grid; gap: var(--space-4); }
  .desk-row { display: grid; grid-template-columns: 1fr; gap: 24px; }
  @media (min-width: 900px) { .desk-row { grid-template-columns: 1.2fr 0.8fr; } }
  .desk-list { list-style: none; margin: 0; padding: 0; }
  .desk-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .desk-list li:first-child { border-top: 3px double var(--border-strong); }
  .desk-list .n { font-family: var(--font-serif, Georgia, serif); font-style: italic; color: var(--muted); min-width: 1.6rem; }
  .desk-list a { color: var(--ink); text-decoration: none; font-weight: 600; }
  .desk-list a:hover { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
  .desk-list small { display: block; font-weight: 400; color: var(--muted); font-size: 0.86rem; }
  .desk-list .meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .desk-list .tag { font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; border: 1.5px solid var(--cta-hover); color: var(--cta-hover); border-radius: 3px; padding: 2px 5px; }
  .paths { display: grid; grid-template-columns: 1fr; gap: 14px; }
  @media (min-width: 720px) { .paths { grid-template-columns: repeat(3, 1fr); } }
  .path { border: 3px double var(--border-strong); border-radius: 4px; padding: 14px 16px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
  .path .rail-h { margin: 0; }
  .path h3 { margin: 0; font-family: var(--font-serif, Georgia, serif); font-weight: 500; font-size: 1.15rem; }
  .path p { margin: 0; color: var(--muted); font-size: 0.9rem; flex: 1; }
  .path a { color: var(--primary-text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; font-size: 0.92rem; }

  /* links dentro de texto sempre sublinhados (a11y: link-in-text-block) */
  body.shell main p a:not(.btn), body.shell main li a:not(.btn) { text-decoration: underline; text-underline-offset: 3px; }

  /* palavras longas (e-mails, URLs) quebram em vez de estourar a 320 px */
  body.shell main a, body.shell main strong, body.shell main code { overflow-wrap: anywhere; }

  /* rodapé mais discreto no shell */
  body.shell .site-footer { border-top: 3px double var(--border-strong); }
  @media print { .topbar, .rail, .rail-backdrop, .toc { display: none !important; } body.shell { display: block; padding-top: 0; } }
