/* ROS2 Doku — czytnik dokumentacji w ramie kitu (C2). Arkusz PO shared; wyłącznie tokeny kitu.
   Lokalne klasy mają prefiks .rd-*, lokalne tokeny --rd-*. Wyjątek domenowy (D71 m, do zgłoszenia przy STOP 1):
   kolumna czytania — trzy poziomy nagłówków w treści, blok kodu krojem stałej szerokości, tabela, lista definicji.
   Jeden układ (wybór użytkownika 11.11.2026): pulpit = spis w lewej kolumnie; telefon = tytuł w pasku otwiera spis. */

.rd-app {
  --rd-mono: Consolas, "SF Mono", Menlo, "DejaVu Sans Mono", "Liberation Mono", ui-monospace, monospace;
  --rd-img-bg: #FFFFFF; /* zrzuty i diagramy oryginału są rysowane pod jasne tło — także w motywach ciemnych */
  --rd-side-w: 280px;
  --rd-toc-w: 220px;
  --rd-read: 47rem;
  --rd-top: calc(var(--platform-header-h, 48px) + 16px);
}

/* ── układ ─────────────────────────────────────────────────────────────────────────────────────── */
.rd-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.rd-page { min-width: 0; max-width: var(--rd-read); }
.rd-toc { display: none; }

@container frame (min-width: 860px) {
  .rd-layout { grid-template-columns: var(--rd-side-w) minmax(0, 1fr); }
}
@container frame (min-width: 1160px) {
  .rd-layout { grid-template-columns: var(--rd-side-w) minmax(0, 1fr) var(--rd-toc-w); }
  .rd-toc:not([hidden]) { display: block; }
}

/* ── spis treści (kolumna albo panel) ──────────────────────────────────────────────────────────── */
.rd-side {
  position: sticky;
  top: var(--rd-top);
  max-height: calc(100dvh - var(--rd-top) - 16px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  padding: 2px;
  font-size: var(--text-base);
}
.rd-side__head { display: none; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.rd-side__title { margin: 0; font-size: var(--text-md); font-weight: 600; color: var(--fg); }
.rd-search { margin: 0 0 12px; }
.rd-search .platform-field { width: 100%; }

/* tryb panelu: telefon albo rama węższa niż 860 px — element leży wtedy w <body> (app.js) */
.rd-side.rd-side--panel {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-overlay);
  width: min(92vw, 400px);
  max-height: none;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-widget);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-float);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.18s ease, visibility 0s linear 0.18s;
}
.rd-side.rd-side--panel[data-open="true"] { transform: none; visibility: visible; transition: transform 0.18s ease; }
.rd-side.rd-side--panel .rd-side__head { display: flex; }
.rd-side:not(.rd-side--panel) .rd-side__close { display: none; }
.rd-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-overlay) - 1);
  background: color-mix(in srgb, var(--fg) 32%, transparent);
}
@media (prefers-reduced-motion: reduce) {
  .rd-side.rd-side--panel, .rd-side.rd-side--panel[data-open="true"] { transition: none; }
}

.rd-tree ul { list-style: none; margin: 0; padding: 0; }
.rd-tree ul ul { margin-left: 12px; padding-left: 6px; border-left: 1px solid var(--border); }
.rd-tree li { margin: 0; }
.rd-tree__row { display: flex; align-items: stretch; gap: 2px; border-radius: var(--radius-sm); }
.rd-tree__row:hover { background: var(--bg-hover); }
.rd-tree__row[data-current="true"] { background: var(--bg-selected); }
.rd-tree__link {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--platform-control-h);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  text-decoration: none;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.rd-tree__row[data-current="true"] .rd-tree__link,
.rd-tree__row[data-branch="true"] > .rd-tree__link { color: var(--fg); }
.rd-tree__row[data-current="true"] .rd-tree__link { font-weight: 600; }
.rd-tree__toggle {
  flex: 0 0 auto;
  width: var(--platform-control-h);
  min-height: var(--platform-control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
}
.rd-tree__toggle svg { width: 14px; height: 14px; transition: transform 0.12s ease; }
.rd-tree__toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.rd-tree__en {
  flex: 0 0 auto;
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--fg-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  line-height: 1.5;
}

.rd-tree__extra { margin-top: 12px !important; padding-top: 12px !important; border-top: 1px solid var(--border); }
.rd-glos__q { width: 100%; max-width: 360px; margin: 0 0 12px; }
.rd-results { margin: 0 0 12px; }
.rd-results__count { margin: 0 0 6px; color: var(--fg-muted); font-size: var(--text-sm); }
.rd-results ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rd-results a {
  display: block;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  text-decoration: none;
}
.rd-results a:hover { background: var(--bg-hover); }
.rd-results__t { display: block; font-weight: 600; line-height: 1.3; }
.rd-results__s { display: block; margin-top: 2px; color: var(--fg-muted); font-size: var(--text-sm); line-height: 1.4; }
.rd-results mark { background: var(--warn-bg); color: var(--fg); border-radius: 2px; padding: 0 1px; }

/* ── „Na tej stronie” ──────────────────────────────────────────────────────────────────────────── */
.rd-toc {
  position: sticky;
  top: var(--rd-top);
  max-height: calc(100dvh - var(--rd-top) - 16px);
  overflow: hidden auto;
  font-size: var(--text-sm);
}
.rd-toc__title { margin: 0 0 6px; padding: 0 8px; font-weight: 600; color: var(--fg); font-size: var(--text-sm); }
.rd-toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.rd-toc a {
  display: block;
  padding: 4px 8px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--fg-muted);
  text-decoration: none;
  line-height: 1.35;
}
.rd-toc a[data-l="3"] { padding-left: 20px; }
.rd-toc a:hover { color: var(--fg); }
.rd-toc a[aria-current="true"] { color: var(--fg); border-left-color: var(--fg); font-weight: 600; }

/* ── nagłówek strony i wiersz stanu ────────────────────────────────────────────────────────────── */
.rd-head { margin-bottom: 12px; }
.rd-head .platform-page-head__title:focus { outline: none; }
.rd-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 var(--space-3); }
.rd-meta__chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rd-meta__tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.rd-notice { margin: 0 0 var(--space-3); }

/* ── kolumna czytania ──────────────────────────────────────────────────────────────────────────── */
.rd-content { font-size: var(--text-md); line-height: 1.6; color: var(--fg); overflow-wrap: break-word; }
.rd-content > section > :first-child, .rd-content > :first-child { margin-top: 0; }
.rd-content p, .rd-content ul, .rd-content ol, .rd-content dl, .rd-content blockquote { margin: 0 0 12px; }
.rd-content li > p { margin-bottom: 6px; }
.rd-content li > p:last-child { margin-bottom: 0; }
.rd-content ul, .rd-content ol { padding-left: 1.5em; }
.rd-content li { margin: 0 0 4px; line-height: 1.6; }
.rd-content li > ul, .rd-content li > ol { margin: 4px 0 6px; }
.rd-content h2, .rd-content h3, .rd-content h4 {
  position: relative;
  color: var(--fg);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: normal;
  scroll-margin-top: var(--rd-top);
}
.rd-content section { scroll-margin-top: var(--rd-top); }
.rd-content h2 { font-size: var(--text-lg); margin: 32px 0 12px; }
.rd-content h3 { font-size: var(--text-md); margin: 24px 0 8px; }
.rd-content h4 { font-size: var(--text-base); margin: 18px 0 6px; }
.rd-content a { color: var(--accent-ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.rd-content a:hover { text-decoration-thickness: 2px; }
.rd-content a.rd-ext::after { content: " ↗"; font-size: 0.8em; text-decoration: none; display: inline-block; }
.rd-content strong { font-weight: 600; }
.rd-content hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.rd-content blockquote { padding-left: 12px; border-left: 2px solid var(--border-subtle); color: var(--fg); }
.rd-content dl { display: grid; gap: 4px; }
.rd-content dt { font-weight: 600; margin-top: 8px; scroll-margin-top: var(--rd-top); }
.rd-content dd { margin: 0 0 0 1.5em; }
.rd-content dd > :last-child { margin-bottom: 0; }
.rd-content img { max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--rd-img-bg); }
.rd-content figure { margin: 0 0 12px; }
.rd-content figcaption { margin-top: 4px; color: var(--fg-muted); font-size: var(--text-sm); }
.rd-content kbd { font-family: var(--rd-mono); font-size: 0.87em; padding: 1px 5px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); background: var(--bg-widget); }
.rd-content code {
  font-family: var(--rd-mono);
  font-size: 0.87em;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  background: var(--tag-bg);
  overflow-wrap: anywhere;
}
.rd-content a code { color: inherit; }

.rd-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: 4px;
  vertical-align: middle;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  opacity: 0;
}
.rd-anchor svg { width: 14px; height: 14px; }
.rd-content h2:hover .rd-anchor, .rd-content h3:hover .rd-anchor, .rd-content h4:hover .rd-anchor, .rd-anchor:focus-visible { opacity: 1; }
@media (hover: none) { .rd-anchor { display: none; } }

/* kod */
.rd-code {
  position: relative;
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
}
.rd-code pre, .rd-content pre {
  margin: 0;
  padding: 12px 16px;
  overflow-x: auto;
  font-family: var(--rd-mono);
  font-size: var(--text-base);
  line-height: 1.5;
  tab-size: 4;
  white-space: pre;
  color: var(--fg);
}
.rd-code pre { padding-right: 52px; }
.rd-code__caption { margin: 0; padding: 6px 16px; border-bottom: 1px solid var(--border); color: var(--fg-muted); font-size: var(--text-sm); font-family: var(--rd-mono); }
.rd-code__copy { position: absolute; top: 4px; right: 4px; background: var(--bg-hover); }
.rd-code:has(.rd-code__caption) .rd-code__copy { top: 36px; }
.rd-content pre.rd-math, .rd-diagram pre { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-hover); margin: 0 0 12px; }
/* tokeny Pygments → tony kitu (komentarz, słowo kluczowe, napis, liczba, nazwa wbudowana, znak zachęty, wyjście) */
.rd-code .c, .rd-code .c1, .rd-code .cm, .rd-code .ch, .rd-code .cs, .rd-code .sd { color: var(--fg-muted); font-style: italic; }
.rd-code .k, .rd-code .kn, .rd-code .kd, .rd-code .kc, .rd-code .kr, .rd-code .kt, .rd-code .ow, .rd-code .cp, .rd-code .nt, .rd-code .nb, .rd-code .bp { color: var(--info-fg); }
.rd-code .s, .rd-code .s1, .rd-code .s2, .rd-code .sa, .rd-code .sb, .rd-code .sc, .rd-code .se, .rd-code .si, .rd-code .sh, .rd-code .sx, .rd-code .sr { color: var(--pass-fg); }
.rd-code .m, .rd-code .mi, .rd-code .mf, .rd-code .mh, .rd-code .mo, .rd-code .mb, .rd-code .il, .rd-code .na, .rd-code .nv, .rd-code .no { color: var(--warn-fg); }
.rd-code .nf, .rd-code .nc, .rd-code .nd, .rd-code .fm { font-weight: 600; }
.rd-code .gp { color: var(--fg-muted); user-select: none; }
.rd-code .go { color: var(--fg-muted); }

/* tabela */
.rd-table-wrap { margin: 0 0 12px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.rd-table { width: 100%; border-collapse: collapse; font-size: var(--text-base); line-height: 1.45; }
.rd-table th, .rd-table td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.rd-table tr:last-child > td { border-bottom: 0; }
.rd-table th { background: var(--bg-hover); font-weight: 600; }
.rd-table p { margin: 0 0 4px; }
.rd-table p:last-child { margin-bottom: 0; }

/* uwagi (komunikat kitu) */
.rd-adm { margin: 0 0 12px; }
.rd-adm .platform-banner__body > :last-child { margin-bottom: 0; }
.rd-adm .platform-banner__title { display: block; margin: 0 0 2px; }

/* zakładki */
.rd-tabs { margin: 0 0 12px; }
.rd-tab__label { font-weight: 600; margin: 12px 0 6px; }
.rd-tabs--on > .rd-tab > .rd-tab__label { display: none; }
.rd-tabs--on > .platform-seg { margin: 0 0 8px; max-width: 100%; }
.rd-tab > :last-child { margin-bottom: 0; }

/* drobne */
.rd-related { columns: 2 16rem; column-gap: 24px; }
.rd-related li { break-inside: avoid; }
.rd-pominiete { padding: 8px 12px; border: 1px dashed var(--border-subtle); border-radius: var(--radius); color: var(--fg-muted); font-size: var(--text-base); }
.rd-zdalny { margin: 0 0 12px; padding: 12px; border: 1px dashed var(--border-subtle); border-radius: var(--radius); display: grid; gap: 6px; justify-items: start; }
.rd-zdalny__opis { margin: 0; color: var(--fg-muted); font-size: var(--text-base); }
.rd-diagram figcaption { margin: 0 0 4px; }
/* prosty schemat z dyrektywy mermaid: wiersz = skąd —podpis→ dokąd */
.rd-content .rd-flow { list-style: none; margin: 0 0 12px; padding: 12px; display: grid; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.rd-flow li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr); align-items: center; gap: 8px; margin: 0; }
.rd-flow__n { padding: 6px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); background: var(--bg-widget); text-align: center; font-size: var(--text-base); font-weight: 600; line-height: 1.3; }
.rd-flow__e { display: flex; align-items: center; gap: 6px; color: var(--fg-muted); font-size: var(--text-sm); line-height: 1.3; text-align: center; }
.rd-flow__e::before { content: "—"; }
.rd-flow__e::after { content: "→"; }
.rd-flow li[data-kierunek="obie"] .rd-flow__e::before { content: "←"; }
.rd-flow li[data-kierunek="zwrot"] .rd-flow__e::before { content: "- -"; }
.rd-lines { margin: 0 0 12px; }
.rd-en { margin: 2px 0 12px; padding: 6px 10px; border-left: 2px solid var(--border-subtle); color: var(--fg-muted); font-size: var(--text-base); line-height: 1.5; }

/* uwagi do oryginału (strony PL) */
.rd-uwagi { margin: 32px 0 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-widget); font-size: var(--text-base); }
.rd-uwagi > summary { cursor: pointer; padding: 10px 12px; font-weight: 600; min-height: var(--platform-control-h); }
.rd-uwagi__lede { margin: 0 12px 8px; color: var(--fg-muted); }
.rd-content .rd-uwagi ul { margin: 0 12px 12px; padding-left: 1.25em; }
.rd-content .rd-uwagi li { margin-bottom: 10px; }
.rd-content .rd-uwagi blockquote { margin: 4px 0 0; }
.rd-uwagi__en { margin: 0; color: var(--fg-muted); font-size: var(--text-sm); overflow-wrap: anywhere; }

/* poprzednia / następna, stopka */
.rd-prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 36px 0 0; }
.rd-prevnext a {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
  line-height: 1.35;
  min-width: 0;
}
.rd-prevnext a:hover { border-color: var(--border-hover); background: var(--bg-hover); }
.rd-prevnext a[data-k="next"] { text-align: right; grid-column: 2; }
.rd-prevnext__k { display: block; color: var(--fg-muted); font-size: var(--text-sm); }
.rd-prevnext__t { display: block; font-weight: 600; overflow-wrap: anywhere; }
.rd-about {
  margin: 24px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.rd-about p { margin: 0 0 4px; }
.rd-about a { color: var(--accent-ink); }

/* ── telefon (≤ 760 px) ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .rd-content pre, .rd-code pre { font-size: var(--text-sm); }
  .rd-prevnext { grid-template-columns: 1fr; }
  .rd-prevnext a[data-k="next"] { grid-column: 1; }
  .rd-related { columns: 1; }

  /* Tytuł strony niesie pasek — w treści zostaje dla czytników ekranu (D75) */
  .rd-head .platform-page-head__title {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .rd-head { margin-bottom: 8px; }
  .rd-head .platform-page-head__lede { margin-top: 0; }

  /* Tytuł w pasku jest kontrolką (otwiera spis treści) i ma linię stanu — wariant V1, wybór użytkownika 11.11.2026.
     Lokalnie na API paska; do przepięcia na klocki kitu „tytuł-przełącznik” i „druga linia tytułu” (runda -c2-9). */
  .platform-header .platform-header__title[data-rd-stan] {
    position: relative;
    display: block;
    min-width: 0;
    padding-right: 18px;
    cursor: pointer;
    line-height: 1.2;
  }
  .platform-header .platform-header__title[data-rd-stan]::after {
    content: attr(data-rd-stan);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--fg-muted);
    font-size: var(--text-xs);
    font-weight: 400;
    line-height: 1.3;
  }
  .platform-header .platform-header__title[data-rd-stan]::before {
    content: "";
    position: absolute;
    right: 2px;
    top: 0.3em;
    width: 7px;
    height: 7px;
    border-right: 1.75px solid var(--fg-muted);
    border-bottom: 1.75px solid var(--fg-muted);
    transform: rotate(45deg);
  }
  /* stan tłumaczenia jest w pasku — w treści zostają poziom, rodzaj i przełącznik języka */
  .rd-meta [data-rd-chip="stan"] { display: none; }
}
/* Przełącznik PL / EN ma etykiety dwuznakowe (opcje 36 i 39 px). Kit podnosi na dotyku samo pole trafienia do 44 px
   nakładką, a krótkim etykietom każe dać szerokość w aplikacji — ten sam warunek mediów co nakładka kitu
   (jak CV Studio w szufladzie wyglądu); bez tego nakładki sąsiednich opcji nachodzą na siebie. */
@media (pointer: coarse), (max-width: 760px) {
  .rd-meta__tools .platform-seg button { min-width: 44px; }
}

@media print {
  .rd-side, .rd-toc, .rd-meta__tools, .rd-prevnext, .rd-code__copy, .rd-anchor, .rd-scrim { display: none !important; }
  .rd-layout { display: block; }
  .rd-page { max-width: none; }
}
