/* plink UI (spec 003, spec 022) — wspólny system wizualny aplikacji i strony głównej.
   Tokeny poniżej obowiązują w aplikacji (index.html), na landingu (landing.html)
   i w panelu admina (admin.html), żeby wszystkie trzy widoki wyglądały jak jedno miejsce. */

/* ==================== typografia (hostowana lokalnie, bez zapytań do CDN) ==================== */

@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/dm-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+030B, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/dm-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+030B, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Gabarito";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("/static/fonts/gabarito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+030B, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Gabarito";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("/static/fonts/gabarito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+030B, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ==================== tokeny: motyw jasny ==================== */

:root {
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F2ED;
  --tint: #E3F1EC;
  --tint-2: #FAEDE2;
  --tint-3: #EDEBF7;
  --border: #E4E2DC;
  --border-strong: #D2CFC6;
  --text: #131318;
  --text-muted: #5D5C6B;
  --primary: #0B7A6B;
  --primary-hover: #0A6A5D;
  --primary-fg: #FFFFFF;
  --accent: #0B7A6B;
  --accent-soft: #E3F1EC;
  --accent-2: #B4552F;
  --good: #0F7A55;
  --danger: #B3261E;
  --danger-soft: #FBEDE9;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(19, 19, 24, 0.05), 0 12px 30px -12px rgba(19, 19, 24, 0.12);
  --sidebar-w: 232px;
  --font-sans: "DM Sans", ui-sans-serif, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-display: "Gabarito", var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
}

:root {
  /* paleta akcentów modułów (spec 003, N3a) — przystrojona pod paletę marki:
     stonowane, ciepłe odcienie zamiast nasyconych kolorów systemowych */
  --p-blue: #3F5BA9;    /* Tekst */
  --p-violet: #6B4FA8;  /* Kod */
  --p-teal: #0B7A6B;    /* Obrazy */
  --p-green: #4F7A28;   /* QR */
  --p-amber: #9A6410;
  --p-rose: #B4552F;    /* PDF */
  --p-cyan: #12718C;    /* Audio */
  --p-orange: #9A6410;  /* Wideo */
}

/* Ciemny motyw: automatycznie wg systemu, chyba że użytkownik wybrał motyw ręcznie
   (przełącznik ustawia [data-theme] na <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --p-blue: #93B0F5;
    --p-violet: #BCA2F0;
    --p-teal: #4ED6BC;
    --p-green: #A8CE7C;
    --p-amber: #E3B24E;
    --p-rose: #E4956B;
    --p-cyan: #63C6DF;
    --p-orange: #E3B24E;

    --bg: #0E1213;
    --surface: #161B1C;
    --surface-2: #1C2324;
    --tint: #132320;
    --tint-2: #231A15;
    --tint-3: #1A1A26;
    --border: #26302F;
    --border-strong: #37413F;
    --text: #F0F3F2;
    --text-muted: #93A09D;
    --primary: #4ED6BC;
    --primary-hover: #6FE0CA;
    --primary-fg: #0E1213;
    --accent: #4ED6BC;
    --accent-soft: #132320;
    --accent-2: #E4956B;
    --good: #4ADE80;
    --danger: #F87171;
    --danger-soft: #2E1A1A;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 18px 40px -16px rgba(0, 0, 0, 0.7);
  }
}

:root[data-theme="dark"] {
  --p-blue: #93B0F5;
  --p-violet: #BCA2F0;
  --p-teal: #4ED6BC;
  --p-green: #A8CE7C;
  --p-amber: #E3B24E;
  --p-rose: #E4956B;
  --p-cyan: #63C6DF;
  --p-orange: #E3B24E;

  --bg: #0E1213;
  --surface: #161B1C;
  --surface-2: #1C2324;
  --tint: #132320;
  --tint-2: #231A15;
  --tint-3: #1A1A26;
  --border: #26302F;
  --border-strong: #37413F;
  --text: #F0F3F2;
  --text-muted: #93A09D;
  --primary: #4ED6BC;
  --primary-hover: #6FE0CA;
  --primary-fg: #0E1213;
  --accent: #4ED6BC;
  --accent-soft: #132320;
  --accent-2: #E4956B;
  --good: #4ADE80;
  --danger: #F87171;
  --danger-soft: #2E1A1A;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 18px 40px -16px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { color-scheme: light dark; }
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Nagłówki idą krojem displayowym (jak na stronie głównej) — jeden charakter pisma
   w całym produkcie: landing, aplikacja, panel admina. */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

::selection { background: var(--accent); color: var(--primary-fg); }

/* ==================== app shell ==================== */

.app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 10px;
  text-decoration: none;
  color: var(--text);
}

/* Logotyp: dwa warianty kolorystyczne, przełączane razem z motywem. */
.brand-logo { display: block; width: auto; height: 26px; }

.brand-logo-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo-light { display: none; }
  :root:not([data-theme="light"]) .brand-logo-dark { display: block; }
}

:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }

/* Znacznik środowiska/etapu obok logo — uczciwie komunikuje, że produkt jest młody. */
.brand-tag {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;      /* pozwala flexowi zmniejszyć nav poniżej rozmiaru treści */
  overflow-y: auto;   /* rozwinięte listy "Więcej" przewijają się w obrębie nawigacji */
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.nav::-webkit-scrollbar-track { background: transparent; }

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 10px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}

.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-link:hover { background: var(--surface-2); color: var(--text); }

.nav-link.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.nav-link.active svg { color: var(--accent); }

/* ---------- nav "Więcej" (spec 006, F17) ---------- */

.nav-more summary { list-style: none; cursor: pointer; position: relative; }
.nav-more summary::-webkit-details-marker { display: none; }

.nav-more .chev {
  width: 14px; height: 14px;
  margin-left: auto;
  transition: transform 0.15s;
}

.nav-more[open] .chev { transform: rotate(180deg); }

.nav-sub { display: flex; flex-direction: column; gap: 2px; padding-left: 18px; }

.nav-sub .nav-link { font-size: 0.88rem; padding: 6px 10px; }

/* ---------- pola formularzy narzędzi ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }

.field > label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input[type="text"], .field input[type="password"],
.field input[type="number"], .field input[type="email"], .field select {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  width: 100%;
}

.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.5;
  width: 100%;
  min-height: 140px;
  resize: vertical;
}

.field textarea:focus-visible,
.field input:focus-visible, .field select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Pole wyłączone przez inne ustawienie widoku — np. liczba kopii, gdy arkusz ma się
   zapełnić sam (spec 045, F6). Bez tego wygląda jak zwykłe pole, które nie reaguje. */
.field input:disabled, .field select:disabled, .field textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }

.field-hint { font-size: 0.82rem; color: var(--text-muted); margin: 0; }

/* Pole koloru (spec 003, F8): próbnik otwierający paletę + hex do wpisania.
   Wysokość próbnika bierze się z pola tekstowego, żeby oba stały równo. */
.color-field { display: flex; align-items: stretch; gap: 8px; }
.color-field input[type="text"] { flex: 1; min-width: 0; font-family: var(--font-mono); }

.color-field input[type="color"] {
  flex: 0 0 auto;
  width: 44px;
  /* `height: auto` jest tu konieczne: bez niego przeglądarka trzyma własną wysokość
     próbnika i ten stoi niżej niż pole tekstowe obok. */
  align-self: stretch;
  height: auto;
  min-height: 40px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }
.color-field input[type="color"]::-moz-color-swatch { border: none; border-radius: 6px; }

.color-field input[aria-invalid="true"] { border-color: var(--danger); }

/* Pole liczbowe z widgetem (spec 031): ramka do wpisania zostaje, obok suwak
   (zakres domknięty z obu stron) albo uchwyt do przeciągania (zakres otwarty). */
.num-field {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  /* Suwak dłuższy niż kilkaset pikseli już nic nie wnosi, a rozjeżdża kartę. */
  max-width: 460px;
  /* Wypełnienie toru suwaka do bieżącej wartości; JS podmienia to przy każdej zmianie.
     Zmienna siedzi na opakowaniu, bo własna deklaracja na `.num-slider` przykryłaby
     wartość ustawianą z JS-a. */
  --num-fill: 0%;
}

/* `min-width: 0` jest tu konieczne: domyślne `min-width: auto` trzyma pole na jego
   szerokości własnej (atrybut `size`), więc zamiast się zwęzić, nachodziło na widget. */
.num-field input[type="number"] { flex: 0 0 5.5rem; width: 5.5rem; min-width: 0; }
/* Uchwyt ma zostać przy ramce także w wąskiej kolumnie, więc pole liczbowe dostaje
   mały rozmiar bazowy i rośnie dopiero tym, co zostanie. */
.num-field[data-num-mode="scrub"] input[type="number"] { flex: 1 1 4rem; width: auto; }

.num-slider {
  /* Krótszy tor niż 120 px nie daje się już celnie ustawić, więc w wąskiej kolumnie
     (rząd czterech pól) suwak zawija się pod ramkę zamiast się ścieśniać. */
  flex: 1 1 120px;
  min-width: 120px;
  height: 20px;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
  -webkit-appearance: none;
  appearance: none;
}

.num-slider::-webkit-slider-runnable-track { height: 6px; border-radius: var(--radius-pill);
  background: linear-gradient(to right,
    var(--accent) var(--num-fill), var(--border-strong) var(--num-fill)); }
.num-slider::-moz-range-track { height: 6px; border-radius: var(--radius-pill);
  background: linear-gradient(to right,
    var(--accent) var(--num-fill), var(--border-strong) var(--num-fill)); }

.num-slider::-webkit-slider-thumb {
  width: 16px; height: 16px; border: 2px solid var(--surface); border-radius: 50%;
  background: var(--accent); box-shadow: 0 1px 3px rgba(19, 19, 24, 0.3);
  cursor: ew-resize; -webkit-appearance: none; appearance: none;
  /* Kciuk wyśrodkowany na torze: (16 - 6) / 2 w górę. */
  margin-top: -5px;
}
.num-slider::-moz-range-thumb {
  width: 16px; height: 16px; border: 2px solid var(--surface); border-radius: 50%;
  background: var(--accent); box-shadow: 0 1px 3px rgba(19, 19, 24, 0.3);
  cursor: ew-resize;
}

.num-slider:hover::-webkit-slider-thumb { background: var(--primary-hover); }
.num-slider:hover::-moz-range-thumb { background: var(--primary-hover); }

.num-scrub {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  align-self: stretch;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: ew-resize;
  /* Bez tego przeciągnięcie palcem po uchwycie przewija stronę zamiast zmieniać wartość. */
  touch-action: none;
}

.num-scrub svg { width: 20px; height: 20px; }

.num-scrub:hover { color: var(--accent); border-color: var(--accent); }

.num-field.num-dragging .num-scrub {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.segmented[data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.segmented[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.segmented[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }

/* Trzy i cztery kolumny z podpisami w rodzaju „zmieści się więcej" mają min-content
   szersze niż pas na telefonie, a komórki siatki domyślnie nie zwężają się poniżej tej
   granicy — cała strona dostawała wtedy poziome przewijanie. Wariant czterokolumnowy
   („Strony PDF") łamał się tak od zawsze, poniżej ~373 px; trzykolumnowy przyszedł
   z kreatorem arkusza. Poniżej 480 px opcje układają się jedna pod drugą — klikalny
   obszar na telefonie tylko na tym zyskuje. */
@media (max-width: 480px) {
  .segmented[data-cols="3"], .segmented[data-cols="4"] { grid-template-columns: 1fr; }
}

.text-preview {
  max-height: 320px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.84rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.sidebar-foot a { color: var(--text-muted); text-decoration: none; }
.sidebar-foot a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.health-row { display: inline-flex; align-items: center; gap: 6px; }

.health { color: var(--text-muted); font-size: 0.7rem; }
.health.ok { color: var(--good); }
.health.bad { color: var(--danger); }

/* ---------- main area ---------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 14px 40px;
  min-height: 72px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }

/* ---------- wyszukiwarka narzędzi (spec 012) ---------- */

.search {
  position: relative;
  margin-left: auto;
  width: min(340px, 45vw);
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 13px;
  width: 15px; height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding: 9px 60px 9px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.search input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.search-kbd {
  position: absolute;
  right: 10px;
  font-family: inherit;
  font-size: 0.68rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--surface-2);
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 420px;
  overflow-y: auto;
  padding: 5px;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.search-item.active { background: var(--surface-2); }

.search-item .tile-icon { width: 30px; height: 30px; }
.search-item .tile-icon svg { width: 16px; height: 16px; }

.search-item-text { min-width: 0; display: flex; flex-direction: column; }

.search-item-title { font-weight: 600; font-size: 0.9rem; }

.search-item-sub {
  color: var(--text-muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-item mark {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit;
  border-radius: 2px;
}

.search-item-module {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.search-empty {
  padding: 14px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

@media (max-width: 800px) {
  .search-kbd { display: none; }
}

.content { padding: 32px 40px 56px; max-width: 920px; width: 100%; }

.view { display: flex; flex-direction: column; gap: 24px; }

.lead { color: var(--text-muted); font-size: 1rem; max-width: 560px; }

/* ---------- home: zakładki modułów (spec 009, F1) ---------- */

/* Zakładki jako „pigułki" — ten sam język co nawigacja na stronie głównej. */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap; /* bez scrollbarów: na wąskim ekranie zakładki się zawijają */
}

.tab {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 8px 15px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); background: var(--surface-2); }

.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* kolor modułu na aktywnej zakładce (spec 003, N3a) */
.tab.active[data-module="pdf"] { color: var(--p-rose); background: color-mix(in srgb, var(--p-rose) 12%, transparent); }
.tab.active[data-module="image"] { color: var(--p-teal); background: color-mix(in srgb, var(--p-teal) 12%, transparent); }
.tab.active[data-module="text"] { color: var(--p-blue); background: color-mix(in srgb, var(--p-blue) 12%, transparent); }
.tab.active[data-module="code"] { color: var(--p-violet); background: color-mix(in srgb, var(--p-violet) 12%, transparent); }
.tab.active[data-module="video"] { color: var(--p-orange); background: color-mix(in srgb, var(--p-orange) 14%, transparent); }
.tab.active[data-module="audio"] { color: var(--p-cyan); background: color-mix(in srgb, var(--p-cyan) 12%, transparent); }
.tab.active[data-module="qr"] { color: var(--p-green); background: color-mix(in srgb, var(--p-green) 13%, transparent); }

.video-preview {
  max-width: 100%;
  max-height: 380px;
  align-self: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #000;
}

.tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---------- home: tiles ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, opacity 0.15s;
}

.tile:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-3px);
}

.tile-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px;
  padding-right: 46px; /* miejsce na gwiazdkę */
  text-decoration: none;
  color: var(--text);
}

/* gwiazdka / usuwanie ulubionych (spec 009, F3, F5) */

.tile-star {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
}

.tile-star svg { width: 17px; height: 17px; fill: none; }

.tile-star:hover { background: var(--surface-2); color: var(--text); }

.tile-star.active { color: var(--accent); }
.tile-star.active svg { fill: var(--accent); }

.tile-star:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.tile-remove:hover { color: var(--danger); background: var(--danger-soft); }

.tile-fav { cursor: grab; }
.tile-fav:active { cursor: grabbing; }
.tile-fav.dragging { opacity: 0.45; border-style: dashed; }
.tile-fav.drop-target { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.fav-empty {
  color: var(--text-muted);
  font-size: 0.92rem;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}

.fav-empty svg {
  width: 30px; height: 30px;
  color: var(--accent);
  margin-bottom: 10px;
}

.fav-empty-title {
  font-weight: 650;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.tile-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.tile-icon svg { width: 19px; height: 19px; }

/* kolory chipów ikon (spec 003, N3a) */
.c-blue   { color: var(--p-blue);   background: color-mix(in srgb, var(--p-blue) 13%, transparent); }
.c-violet { color: var(--p-violet); background: color-mix(in srgb, var(--p-violet) 13%, transparent); }
.c-teal   { color: var(--p-teal);   background: color-mix(in srgb, var(--p-teal) 13%, transparent); }
.c-green  { color: var(--p-green);  background: color-mix(in srgb, var(--p-green) 13%, transparent); }
.c-amber  { color: var(--p-amber);  background: color-mix(in srgb, var(--p-amber) 15%, transparent); }
.c-rose   { color: var(--p-rose);   background: color-mix(in srgb, var(--p-rose) 13%, transparent); }
.c-cyan   { color: var(--p-cyan);   background: color-mix(in srgb, var(--p-cyan) 13%, transparent); }
.c-orange { color: var(--p-orange); background: color-mix(in srgb, var(--p-orange) 14%, transparent); }

.tile-title { font-weight: 600; font-size: 0.98rem; }

.tile-desc { color: var(--text-muted); font-size: 0.88rem; }

/* ---------- tools list (moduły z API) ---------- */

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: -12px;
}

.tool-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.tool-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
}

.tool-item .tool-name {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.tool-item .tool-name::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.tool-item .tool-desc { color: var(--text-muted); margin-top: 2px; font-size: 0.84rem; }

/* ==================== komponenty narzędzi ==================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card-head h2 { font-size: 1.4rem; }

.card-desc { color: var(--text-muted); margin-top: 4px; font-size: 0.92rem; }

/* ---------- dropzone ---------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.dropzone-icon { width: 30px; height: 30px; color: var(--text-muted); margin-bottom: 8px; }

.dropzone:hover .dropzone-icon, .dropzone.dragover .dropzone-icon { color: var(--accent); }

.dropzone-title { font-weight: 600; font-size: 0.95rem; }

.dropzone-hint { color: var(--text-muted); font-size: 0.87rem; margin-top: 2px; }

.link-like { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- file chip ---------- */

.file-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
}

.file-chip svg { width: 17px; height: 17px; color: var(--text-muted); flex-shrink: 0; }

.file-chip-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-chip-size { color: var(--text-muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.file-chip-clear {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.file-chip-clear:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- quality segmented control ---------- */

.quality { border: none; }

.quality .section-label { margin-bottom: 10px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.segmented label { cursor: pointer; }

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 11px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 600;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}

.segmented span:hover { border-color: var(--border-strong); }

.segmented small { font-weight: 400; color: var(--text-muted); font-size: 0.74rem; }

.segmented input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.segmented input:checked + span small { color: color-mix(in srgb, var(--accent) 75%, var(--text-muted)); }

.segmented input:focus-visible + span {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ---------- buttons ---------- */

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
  padding: 13px 26px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  align-self: flex-start;
  min-width: 220px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border: 1px solid var(--primary);
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Nieaktywny przycisk jest neutralny, a nie „wyblakle zielony" — na pierwszy rzut oka
   widać, że to stan wyłączony, a nie po prostu jaśniejszy wariant akcji. */
.btn-primary:disabled {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-primary:focus-visible, .btn-secondary:focus-visible,
.file-chip-clear:focus-visible, .merge-remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-spinner {
  width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, var(--primary-fg) 35%, transparent);
  border-top-color: var(--primary-fg);
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}

.btn-primary.loading .btn-spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- merge list (spec 005, F9-F10) ---------- */

.merge-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.merge-list:empty { display: none; }

.merge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.9rem;
  cursor: grab;
  transition: border-color 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.merge-item:active { cursor: grabbing; }

.merge-item.dragging { opacity: 0.45; border-style: dashed; }

.merge-item.drop-target { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.merge-handle {
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: -1px;
  user-select: none;
  flex-shrink: 0;
}

.merge-index {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.merge-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.merge-size {
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
}

.merge-remove {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.merge-remove:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- alerts & result ---------- */

.alert {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
}

/* ---------- interaktywny edytor kadru (spec 007, F17) ---------- */

.crop-stage {
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.crop-stage img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

.crop-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 9999px color-mix(in srgb, #000 45%, transparent);
  cursor: move;
  touch-action: none;
}

.crop-h {
  position: absolute;
  width: 11px; height: 11px;
  background: var(--accent);
  border: 1.5px solid #fff;
  border-radius: 3px;
  box-sizing: border-box;
}

/* Nakładka (spec 007, F18): ta sama scena, ale bez przygaszania tła — liczy się
   to, jak obrazy wyglądają razem. */
.overlay-box {
  position: absolute;
  border: 1.5px dashed var(--accent);
  cursor: move;
  touch-action: none;
}

.overlay-box img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.h-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.h-n  { top: -6px; left: calc(50% - 5.5px); cursor: ns-resize; }
.h-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.h-e  { top: calc(50% - 5.5px); right: -6px; cursor: ew-resize; }
.h-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.h-s  { bottom: -6px; left: calc(50% - 5.5px); cursor: ns-resize; }
.h-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.h-w  { top: calc(50% - 5.5px); left: -6px; cursor: ew-resize; }

/* ---------- kreator krok po kroku (spec 045, F12) ---------- */

.wizard { display: flex; flex-direction: column; gap: 18px; }

.wizard-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.wizard-step:disabled { opacity: 0.45; cursor: not-allowed; }
.wizard-step:not(:disabled):hover { border-color: var(--border-strong); color: var(--text); }

.wizard-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.wizard-step.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

.wizard-step.is-active .wizard-num { background: var(--accent); color: #fff; }
.wizard-step.is-done { color: var(--text); }
/* Odhaczony krok mówi „to masz już za sobą" bez zmiany szerokości pigułki. */
.wizard-step.is-done .wizard-num { background: var(--accent-soft); color: var(--accent); }

.wizard-panel { display: flex; flex-direction: column; gap: 14px; }
.wizard-title { margin: 0; font-size: 1.02rem; }

.wizard-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

/* Przyciski akcji mają globalne `min-width: 220px`, bo zwykle stoją same jako CTA.
   W nawigacji kreatora są dwa obok siebie i to minimum rozpychało wiersz poza kartę —
   na telefonie poziomy pasek przewijania dostawała cała strona. Zostawiamy 220 px jako
   rozmiar wyjściowy, ale pozwalamy się zwęzić, kiedy nie ma miejsca. */
.wizard-nav .btn-secondary {
  flex: 0 1 220px;
  min-width: 0;
  align-self: center;
  padding-left: 16px;
  padding-right: 16px;
}

/* Krok pierwszy i ostatni wygaszają swój przycisk — bez tego „Dalej" na końcu wygląda
   jak przycisk, który po prostu nie działa. */
.wizard-nav .btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--text-muted);
}
.wizard-progress { flex: 1 1 auto; text-align: center; font-size: 0.82rem; color: var(--text-muted); }

/* Wąski ekran: licznik kroku dostaje własny wiersz, a przyciski dzielą się szerokością
   po równo. Wciśnięty między nie łamał się na cztery linijki. */
@media (max-width: 560px) {
  .wizard-progress { flex-basis: 100%; order: -1; }
  .wizard-nav .btn-secondary { flex: 1 1 0; }
}

/* ---------- kafelki wyboru (spec 045, F12) ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
}

.tile { position: relative; display: block; }
.tile input { position: absolute; opacity: 0; pointer-events: none; }

.tile-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  height: 100%;
  padding: 12px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}

.tile-body:hover { border-color: var(--accent); }
.tile input:checked + .tile-body { border-color: var(--accent); background: var(--accent-soft); }
.tile input:focus-visible + .tile-body {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Kształt niesie połowę informacji: „35×45" nabiera sensu dopiero, gdy widać, że to
   wąski pionowy prostokąt, a odbitka 13×18 jest od niego wyraźnie większa. Proporcje
   idą z `--tw`/`--th`, względna wielkość z `--ts` (liczona w JS pierwiastkiem, patrz
   `sheetShapeScale`). Rezerwujemy pełną wysokość, żeby nazwy stały w jednej linii
   niezależnie od tego, jak mały jest kafelek obok. */
.tile-shape-slot { flex: 0 0 auto; display: grid; place-items: end center; height: 48px; }

.tile-shape {
  height: calc(48px * var(--ts, 1));
  aspect-ratio: var(--tw) / var(--th);
  max-width: 100%;
  border: 1.5px solid var(--text-muted);
  border-radius: 2px;
  background: var(--surface-2);
}

/* „Własny rozmiar" nie ma jednego kształtu — przerywana ramka mówi „cokolwiek podasz". */
.tile-shape-any { border-style: dashed; background: none; }

.tile input:checked + .tile-body .tile-shape { border-color: var(--accent); }
.tile-name { font-size: 0.86rem; font-weight: 600; line-height: 1.25; }
.tile-note { font-size: 0.78rem; color: var(--text-muted); }
.tile-hint { font-size: 0.72rem; color: var(--text-muted); line-height: 1.3; }
.tile-hint:empty, .tile-note:empty { display: none; }

/* Podgląd arkusza (spec 045, F11): rysowany na canvasie, bo to ta sama grafika
   powielona kilkanaście razy — kilkanaście elementów DOM z `overflow: hidden`
   przerysowywałoby się przy każdym ruchu ramki kadru. Szare tło wokół pokazuje,
   gdzie kończy się kartka, gdy arkusz jest biały. */
.sheet-canvas {
  display: block;
  align-self: flex-start;
  /* Oba ograniczenia naraz: canvas ma proporcje wewnętrzne, więc przeglądarka
     dopasowuje drugi bok sama. Bez limitu wysokości arkusz 10×15 zajmuje pół
     karty i wypycha ustawienia poza ekran — a rzecz w tym, żeby widzieć jedno
     i drugie równocześnie. */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 340px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* Scena kadru w arkuszu jest niższa niż w Kadrowaniu — pod nią stoi jeszcze
   podgląd arkusza i oba mają się mieścić naraz. */
#img-sheet-stage img { max-height: 300px; }

.img-preview {
  max-width: 100%;
  max-height: 360px;
  align-self: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  /* Szachownica pod podglądem (spec 007, F20): na jednolitym tle przezroczysty
     wynik „usuwania tła" wygląda tak samo jak oryginał i nie da się na oko
     sprawdzić, czy operacja się udała. Obraz bez alfy i tak ją zasłania. */
  background-color: var(--surface-2);
  background-image:
    conic-gradient(rgb(128 128 128 / 22%) 25%, transparent 0 50%,
      rgb(128 128 128 / 22%) 0 75%, transparent 0);
  background-size: 16px 16px;
}

.result-name { max-width: 380px; }

.result {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--border);
  padding-top: 22px;
}

.result-stats {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; }

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-accent { color: var(--accent); }

.stat-good { color: var(--good); }

.stat-arrow { color: var(--text-muted); font-size: 1.1rem; }

.result-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.result-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.6s ease;
}

/* ==================== czytelny wynik zamiast JSON-a (spec 041) ==================== */

.rr { display: flex; flex-direction: column; gap: 14px; }

.rr-head {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
  margin: 0;
}

.rr-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Bez wersalików — tytułem karty bywa nazwa pliku, a „WIFI.PNG” czyta się gorzej
   niż „wifi.png”. Rolę etykiety niosą tu rozmiar i kolor. */
.rr-card-title {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
  word-break: break-word;
}

.rr-list { display: flex; flex-direction: column; gap: 8px; margin: 0; }

.rr-row {
  display: grid;
  grid-template-columns: minmax(140px, 34%) 1fr;
  gap: 6px 16px;
  align-items: baseline;
}

.rr-row dt { color: var(--text-muted); font-size: 0.86rem; }

.rr-row dd {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.rr-row-mono dd { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.rr-row-mono code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

.rr-copy { padding: 4px 10px; font-size: 0.78rem; }

.rr-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.rr-item:first-of-type { border-top: 0; padding-top: 0; }

.rr-badge {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
}

.rr-big {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.rr-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.rr-note,
.rr-empty {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.rr-warn {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.rr-verdict {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
}

.rr-ok { color: var(--good); }
.rr-bad { color: var(--danger); }

.rr-top {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding-left: 22px;
}

.rr-top li { font-size: 0.92rem; }

.rr-top-count { color: var(--text-muted); font-size: 0.84rem; margin-left: 8px; }

.rr-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rr-tags li {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
}

.rr-block { display: flex; flex-direction: column; gap: 6px; }

.rr-block-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.rr-block pre {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.rr-raw > summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 4px 0;
}

.rr-raw > summary:hover { color: var(--text); }

.rr-raw[open] > summary { margin-bottom: 10px; }

@media (max-width: 560px) {
  .rr-row { grid-template-columns: 1fr; gap: 2px; }
}

/* ==================== responsywność ==================== */

@media (max-width: 800px) {
  .app { flex-direction: column; }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .nav { flex-direction: row; align-items: center; }

  .nav-label { display: none; }

  .sidebar-foot { margin-top: 0; margin-left: auto; flex-direction: row; gap: 14px; white-space: nowrap; }

  .topbar { padding: 14px 20px; }

  .content { padding: 20px 20px 40px; }

  .card { padding: 18px; }

  .segmented { grid-template-columns: 1fr; }

  .btn-primary, .btn-secondary { align-self: stretch; }
}

/* ---------- historia operacji (spec 017) ---------- */

.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.history-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }

.history-title { font-weight: 600; font-size: 0.94rem; }

.history-time { color: var(--text-muted); font-weight: 400; font-size: 0.8rem; margin-left: 8px; }

.history-sub {
  color: var(--text-muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-open { padding: 8px 14px; font-size: 0.85rem; flex-shrink: 0; }

.history-remove { position: static; flex-shrink: 0; }

/* ---------- ścieżki: wyslij dalej (spec 017) ---------- */

.send-row { align-items: center; }

.send-row select {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  max-width: 280px;
}

/* ---------- dostepnosc (spec 018) ---------- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -48px; left: 12px;
  z-index: 100;
  background: var(--primary);
  color: var(--primary-fg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  transition: top 0.15s;
}

.skip-link:focus { top: 12px; }

#page-title:focus-visible { outline: none; }

.dropzone-formats {
  color: var(--text-muted);
  font-size: 0.76rem;
  margin-top: 6px;
}

.move-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.move-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: var(--surface); }
.move-btn:disabled { opacity: 0.35; cursor: default; }
.move-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.tile-move { position: absolute; bottom: 10px; right: 10px; display: flex; gap: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.6s !important; /* spinner: stan, nie dekoracja */
  }
  .tile:hover { transform: none; }
  .result-bar-fill { transition: none !important; }
}

/* ---------- nawigacja gorna bez sidebara (spec 003) ---------- */

.content { margin: 0 auto; }

.topbar { gap: 14px; flex-wrap: wrap; }

.topbar .brand { padding: 0; flex-shrink: 0; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.back-btn svg { width: 14px; height: 14px; }

.back-btn:hover { color: var(--text); border-color: var(--border-strong); }

.back-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.top-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.top-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
}

.top-link:hover { background: var(--surface-2); color: var(--text); }

.top-link.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.top-links .health-row { padding-left: 6px; }

.health-text { font-size: 0.8rem; color: var(--text-muted); }

@media (max-width: 1100px) {
  .health-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

@media (max-width: 800px) {
  .topbar { padding: 12px 16px; }
  /* pole wyszukiwania na cala szerokosc w osobnym wierszu */
  .search { order: 10; flex-basis: 100%; width: 100%; margin-left: 0; }
  #page-title { font-size: 0.98rem; }
}

/* ---------- przelacznik motywu ---------- */

.theme-btn {
  flex-shrink: 0;
  margin-left: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

.theme-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.theme-icon { width: 18px; height: 18px; }

/* w jasnym motywie pokazujemy ksiezyc (akcja: wlacz ciemny), w ciemnym slonce */
.theme-icon-sun { display: none; }
.theme-btn[aria-pressed="true"] .theme-icon-sun { display: block; }
.theme-btn[aria-pressed="true"] .theme-icon-moon { display: none; }

/* ---------- menu hamburger (mobile) ---------- */

.menu-wrap { position: relative; display: none; margin-left: auto; }

.menu-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.menu-btn svg { width: 18px; height: 18px; }

.menu-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.mobile-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
}

.mobile-menu-link {
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
}

.mobile-menu-link:hover { background: var(--surface-2); }

@media (max-width: 800px) {
  .top-links { display: none; }
  .menu-wrap { display: block; }
  .search { margin-left: 0; }
}

/* mobile: przy logo tylko hamburger — bez tytulu widoku i tekstu Wstecz */
@media (max-width: 800px) {
  #page-title {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

}

/* przycisk Wstecz pod paskiem nawigacji (staly topbar) */
.back-row { margin-bottom: 4px; }
.back-row:has(#back-btn[hidden]) { display: none; }
/* tytul widoku nie jest pokazywany w headerze — zostaje dla czytnikow ekranu
   (fokus po nawigacji) i dla document.title */
#page-title {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* zakladki widoczne we wszystkich widokach — odstep od tresci */
.content > .tabs { margin-bottom: 20px; }

/* baner ścieżki (spec 017, F9) */
.pipe-note {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
}

.pipe-note-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pipe-note .file-chip-clear { margin-left: auto; }

/* popover "Wyslij dalej" */
.send-wrap { position: relative; align-self: flex-start; }

.send-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 40;
  min-width: 300px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.send-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.send-item:hover, .send-item:focus-visible { background: var(--surface-2); outline: none; }

.send-item .tile-icon { width: 28px; height: 28px; flex-shrink: 0; }
.send-item .tile-icon svg { width: 15px; height: 15px; }

.send-item-title { font-weight: 600; flex: 1; }

/* ---------- lancuchy i ścieżki (spec 019) ---------- */

.hist-tabs { margin-bottom: 18px; }

#history-ops, #history-chains { display: flex; flex-direction: column; gap: 18px; }

.chain-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.chain-steps, .chain-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chain-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 0.86rem;
  font-weight: 600;
}

.chain-step .tile-icon { width: 24px; height: 24px; border-radius: 999px; }
.chain-step .tile-icon svg { width: 13px; height: 13px; }

.chain-arrow { color: var(--text-muted); }

.chain-step .step-status { font-size: 0.8rem; }
.chain-step[data-status="running"] { border-color: var(--accent); }
.chain-step[data-status="running"] .step-status::before { content: "…"; color: var(--accent); }
.chain-step[data-status="ok"] { border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.chain-step[data-status="ok"] .step-status::before { content: "✓"; color: var(--good); }
.chain-step[data-status="error"] { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.chain-step[data-status="error"] .step-status::before { content: "✕"; color: var(--danger); }

.chain-result { font-size: 0.9rem; color: var(--danger); }
.chain-result a { color: var(--text); }
.chain-result-ok { color: var(--text-muted); }

/* ---------- gotowe ścieżki (spec 029) ---------- */

.pipe-group { display: flex; flex-direction: column; gap: 14px; margin-top: 26px; }

.pipe-group-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  margin: 0;
}

.pipe-group .lead { margin: -6px 0 0; }

/* Karta wskazana z podstrony ścieżki ("#/pipelines/<preset>") — użytkownik ma od razu
   widzieć, w który z pięciu ścieżek kliknął. */
.chain-card-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.chain-options { margin: 2px 0; max-width: 620px; }

/* Komplet ustawień narzędzi ścieżki (spec 029, F3) — zwinięty, bo lista pięciu
   gotowych ścieżek musi dać się przejrzeć okiem, zanim ktoś zacznie kręcić gałkami. */
.chain-settings {
  max-width: 620px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.chain-settings > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius-sm);
}

.chain-settings > summary::-webkit-details-marker { display: none; }
.chain-settings > summary::before { content: "▸"; color: var(--text-muted); }
.chain-settings[open] > summary::before { content: "▾"; }

.chain-settings > summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.chain-settings-count {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chain-settings-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 2px 14px 16px;
}

.chain-step-opts { display: flex; flex-direction: column; gap: 8px; }

.chain-step-opts-head {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.chain-step-opts-none { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

/* Karta ścieżki to nie widok narzędzia — pole wielolinijkowe nie ma tu zjadać ekranu. */
.chain-settings-body .field textarea { min-height: 62px; }

/* Przełącznik ("Pozwól powiększać…") bierze cały wiersz — inaczej ściska sąsiadów. */
.chain-settings-body .field-row > .check { flex-basis: 100%; }

/* Drugi plik kroku i krok wyłączalny (spec 032, F2-F3) — stoją nad ustawieniami,
   bo bez wskazanego pliku ścieżka w ogóle nie ruszy. */
.chain-extra { max-width: 620px; }
.chain-extra input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.88rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
}
.chain-extra input[type="file"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.chain-optional { font-size: 0.88rem; }

.chain-hint { font-size: 0.85rem; color: var(--text-muted); }

.chain-more {
  align-self: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
}

.chain-more:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- stopka aplikacji (spec 022) — domyka pętlę aplikacja ↔ strona główna ---------- */

.app-foot {
  border-top: 1px solid var(--border);
  margin-top: 48px;
  padding: 26px 40px 40px;
}

.app-foot-inner {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.app-foot nav { display: flex; gap: 18px; flex-wrap: wrap; margin-left: auto; }

.app-foot a { color: var(--text-muted); text-decoration: none; }

.app-foot a:hover { color: var(--accent); }

/* Spec 039, F14: próg 24×24 px z WCAG 2.2 AA (2.5.8) — nawigacja stopki nie
   korzysta z wyjątku dla linków wplecionych w zdanie. */
.app-foot nav a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}

.app-foot .brand-logo { height: 22px; }

@media (max-width: 800px) {
  .app-foot { padding: 22px 16px 32px; }
  .app-foot nav { margin-left: 0; gap: 14px; }
}

/* ---------- postęp i anulowanie długich operacji (spec 025, F1) ---------- */

.progress-note {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: -8px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text-muted);
  font-size: 0.88rem;
}

.progress-note-text { flex: 1; min-width: 200px; }

.progress-cancel {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.progress-cancel:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

.progress-cancel:disabled { opacity: 0.5; cursor: default; }

.progress-cancel:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
