/* ===========================================================================
   Context Lab — system designu CloudBots (cloudbots.eu).
   Miętowy akcent (#00CED1 / #22d3ee), heksagony + poświaty + siatka w tle,
   szklany topbar, OSTRE KRAWĘDZIE (sharp edges) jako sygnatura marki.
   Typografia: Exo 2 (logo), Space Grotesk (nagłówki), Inter (UI), IBM Plex Mono (dane).
   Spektrum warstw kontekstu zachowane jako wizualizacja danych.
   =========================================================================== */

:root {
  color-scheme: dark;

  /* tlo / powierzchnie (slate + glass) */
  --bg: #0f172a;
  --bg-2: #1e293b;     /* panel */
  --bg-3: #273449;     /* panel-2 / hover */
  --bg-raise: #3a4a63; /* panel-3 */
  --line: rgba(255,255,255,.10);
  --line-soft: rgba(255,255,255,.055);

  /* tekst */
  --fg: #f1f5f9;
  --fg-mut: #cbd5e1;
  --fg-faint: #94a3b8;
  --code-fg: #cbd5e1;   /* kolor tekstu w blokach kodu */
  --prose: #cbd5e1;     /* kolor tekstu w dokumentacji */
  --grid: rgba(255,255,255,.05);    /* linie siatki w tle dekoracyjnym */
  --overlay: rgba(2, 6, 23, .7);    /* przyciemnienie pod modalem */
  --topbar-bg: rgba(15, 23, 42, .72);
  --panel-bg: var(--bg-2);

  /* akcent marki CloudBots (mięta) */
  --mint: #22d3ee;       /* fill / glow / border, tekst na ciemnym */
  --navy: #5eead4;       /* czytelny teal — tekst akcentowy */
  --navy-2: #0e7490;
  --glow: rgba(34, 211, 238, .42);

  /* warstwy kontekstu (spektrum) — wizualizacja danych, zachowana */
  --c-system: #38bdf8;
  --c-tools:  #fbbf24;
  --c-memory: #2dd4bf;
  --c-user:   #fb7185;
  --c-rag:    #a78bfa;
  --c-assistant: #5eead4;

  /* sygnaly */
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;

  /* OSTRE KRAWEDZIE — sygnatura CloudBots */
  --radius: 0px;
  --radius-sm: 0px;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 26px 52px -38px rgba(0,0,0,.7);

  --grad-primary: linear-gradient(135deg, var(--mint), var(--navy-2));

  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --disp: "Space Grotesk", var(--sans);
  --brandfont: "Exo 2", "Space Grotesk", sans-serif;

  /* pelne spektrum warstw - uzywane w akcentach wizualizacji */
  --spectrum: linear-gradient(90deg, var(--c-system), var(--c-tools), var(--c-memory), var(--c-user), var(--c-rag), var(--c-assistant));
  /* tlo logo/awatara - miętowy heksagon (glif bialy) */
  --logo-bg: linear-gradient(150deg, var(--mint), var(--navy-2));
}

/* =========================== MOTYW JASNY ================================
   CloudBots light: chłodne, lekko niebieskawe tlo, atramentowy tekst,
   pogłębiona mięta (#00CED1) i teal jako akcent czytelny na bieli.
   Tryb 'auto' rozwiazuje sie w JS do data-theme="light"|"dark".
   ====================================================================== */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f5f8fb;
  --bg-2: #ffffff;
  --bg-3: #eef3f8;
  --bg-raise: #e2e8f0;
  --line: rgba(15,23,42,.10);
  --line-soft: rgba(15,23,42,.06);

  --fg: #0f172a;
  --fg-mut: #475569;
  --fg-faint: #64748b;
  --code-fg: #0f172a;
  --prose: #334155;
  --grid: rgba(15,23,42,.04);
  --overlay: rgba(15, 23, 42, .42);
  --topbar-bg: rgba(245, 248, 251, .72);
  --panel-bg: var(--bg-2);

  /* akcent marki — pogłębiony dla kontrastu na bieli */
  --mint: #00ced1;
  --navy: #0e7490;
  --navy-2: #0b5566;
  --glow: rgba(0, 206, 209, .5);

  /* spektrum warstw - poglebione, by tekst i cienkie paski czytaly sie na bieli */
  --c-system: #0284c7;
  --c-tools:  #b5710a;
  --c-memory: #0e9c97;
  --c-user:   #d8456a;
  --c-rag:    #7c4ddb;
  --c-assistant: #0e7490;

  --ok: #0f9d6b;
  --warn: #b5710a;
  --err: #e2553f;

  --shadow: 0 1px 2px rgba(8,18,40,.05), 0 24px 48px -34px rgba(8,18,40,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .35s ease;
}
.main { background: transparent; position: relative; z-index: 2; }

/* ===== dekoracyjne tlo marki CloudBots (heksagony + poswiata + siatka) =====
   Statyczny element <div class="bg-decor"> w index.html, fixed za trescia. */
.bg-decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-decor .hex { position: absolute; opacity: .13; }
.bg-decor .hex svg { width: 100%; height: 100%; }
.bg-decor .h1 { top: -72px; right: -56px; width: 300px; height: 300px; }
.bg-decor .h2 { bottom: -96px; left: -84px; width: 440px; height: 440px; opacity: .14; }
.bg-decor .h3 { top: 34%; left: -34px; width: 200px; height: 200px; opacity: .09; }
.bg-decor .glow { position: absolute; border-radius: 50%; filter: blur(90px); }
.bg-decor .g1 { top: -130px; right: 6%; width: 400px; height: 400px; background: rgba(34,211,238,.16); }
.bg-decor .g2 { bottom: -150px; left: 4%; width: 440px; height: 440px; background: rgba(59,130,246,.12); }
.bg-decor .grid {
  position: absolute; inset: 0; opacity: .05;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 60px 60px;
  -webkit-mask-image: radial-gradient(circle at 50% 30%, #000, transparent 85%);
  mask-image: radial-gradient(circle at 50% 30%, #000, transparent 85%);
}
[data-theme="light"] .bg-decor .g1 { background: rgba(0,206,209,.20); }
[data-theme="light"] .bg-decor .g2 { background: rgba(59,130,246,.13); }
[data-theme="light"] .bg-decor .grid { opacity: .04; }
.animate-float { animation: float 6s ease-in-out infinite; }
.animate-float-delayed { animation: float 7.5s ease-in-out 1s infinite; }
.animate-float-slow { animation: float 9s ease-in-out 2s infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-22px); } }

h2 { font-family: var(--disp); font-size: 13.5px; letter-spacing: .02em; text-transform: uppercase; margin: 0; color: var(--fg); font-weight: 600; }

/* ------------------------------- NAGLOWEK (glass) ------------------------ */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; flex-shrink: 0; }
.brand__mark {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--mint), var(--navy-2));
  box-shadow: 0 6px 18px -5px var(--glow);
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}
.brand__mark svg { width: 20px; height: 20px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-family: var(--brandfont); font-weight: 700; font-size: 15px; letter-spacing: .05em; text-transform: uppercase; }
.brand__text strong { color: var(--fg); }
.brand__text span { font-family: var(--mono); font-size: 9.5px; color: var(--fg-faint); letter-spacing: .2em; text-transform: uppercase; }

.tabs { display: flex; gap: 6px; margin-left: 10px; }
.tab {
  font-family: var(--sans); font-weight: 600; font-size: 12.5px; letter-spacing: .01em;
  color: var(--fg-mut); background: var(--bg-2); border: 1px solid var(--line);
  padding: 8px 16px; cursor: pointer; transition: .18s; white-space: nowrap;
}
.tab:hover { color: var(--navy); border-color: var(--mint); box-shadow: 0 8px 20px -12px var(--glow); }
.tab.is-active { color: var(--bg); background: var(--fg); border-color: transparent; }

.status { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* kredyt: zbudowane przez CloudBots (cloudbots.eu) */
.credit { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; padding: 4px 11px 4px 4px;
  border: 1px solid var(--line); background: var(--bg-2); transition: .18s; white-space: nowrap; }
.credit:hover { border-color: var(--mint); box-shadow: 0 8px 20px -12px var(--glow); }
.credit__mark { width: 24px; height: 24px; flex: none; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--mint), var(--navy-2)); box-shadow: 0 4px 12px -4px var(--glow);
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); }
.credit__mark svg { width: 14px; height: 14px; }
.credit__txt { font-family: var(--sans); font-size: 11px; font-weight: 500; color: var(--fg-mut); letter-spacing: .01em; }
.credit__txt b { font-family: var(--brandfont); font-weight: 700; color: var(--navy); letter-spacing: .03em; }

.doclink {
  font-family: var(--sans); font-weight: 500; font-size: 11.5px; color: var(--fg-mut); text-decoration: none;
  border: 1px solid var(--line); background: var(--bg-2); padding: 6px 12px; transition: .18s; white-space: nowrap;
}
.doclink:hover { color: var(--navy); border-color: var(--mint); box-shadow: 0 8px 20px -12px var(--glow); }
.chip {
  font-family: var(--sans); font-weight: 500; font-size: 11.5px; color: var(--fg-mut);
  border: 1px solid var(--line); background: var(--bg-2); padding: 6px 12px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--fg-faint); }
.chip.is-ok::before { background: var(--mint); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 22%, transparent); }
.chip.is-warn::before { background: var(--warn); }
.chip.is-err { color: var(--err); border-color: var(--err); }
.chip.is-err::before { background: var(--err); }

/* selektor motywu (auto / jasny / ciemny) */
.theme-switch { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); padding: 2px; gap: 2px; }
.theme-switch button { font-family: var(--mono); font-size: 12px; line-height: 1; color: var(--fg-mut); background: transparent; border: none; width: 27px; height: 24px; cursor: pointer; display: grid; place-items: center; transition: .15s; }
.theme-switch button:hover { color: var(--navy); }
.theme-switch button.is-active { background: var(--fg); color: var(--bg); }

/* ------------------------------- WIDOKI ---------------------------------- */
.view { display: none; }
.view.is-active { display: grid; }
.view--agent {
  grid-template-columns: 360px minmax(420px, 1fr) 440px;
  gap: 16px; padding: 16px; align-items: start;
  height: calc(100vh - 61px);
}
.col { min-width: 0; display: flex; flex-direction: column; gap: 16px; height: 100%; overflow: hidden; }
.col--config, .col--log { overflow-y: auto; }
.col--center { overflow: hidden; }

/* ------------------------------- PANELE ---------------------------------- */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  box-shadow: var(--shadow);
}
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; padding-bottom: 11px; border-bottom: 1px solid var(--line-soft); }
/* sygnatura CloudBots: miętowa kreska gradientowa przed tytułem panelu */
.panel__head h2 { display: flex; align-items: center; gap: 9px; }
.panel__head h2::before {
  content: ""; width: 3px; height: 13px; flex: none;
  background: linear-gradient(var(--mint), var(--navy-2)); box-shadow: 0 0 6px -1px var(--glow);
}
/* pasek akcji konfiguracji (preset / import / eksport) */
.cfg-actions { flex-wrap: wrap; row-gap: 6px; }
.input--xs { font-size: 11px; padding: 4px 7px; width: auto; max-width: 160px; }
/* numerowana sciezka sygnalu: 01 konfiguracja -> 02 kontekst -> 03 dziennik
   — numer zastepuje kreske gradientowa (ta sama pozycja, ::before). */
.panel[data-step] .panel__head h2::before {
  content: attr(data-step); width: auto; height: auto; box-shadow: none;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: .04em; color: var(--bg); background: var(--mint);
  padding: 2px 6px; transform: translateY(-1px);
}
.panel__actions { display: flex; gap: 6px; }
.panel__note { font-size: 11.5px; color: var(--fg-mut); margin: -4px 0 12px; }
.count { font-family: var(--mono); font-size: 11px; color: var(--bg); background: var(--c-tools); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }

.panel--stack { flex: 0 0 auto; position: relative; }
.stack-head-right { display: flex; align-items: center; gap: 8px; }
/* zwijanie okna kontekstu - robi miejsce na rozmowe, zostaje zwiezle
   podsumowanie (miernik + chipy). Przyciski widoku ZOSTAJA widoczne, a wybrany
   widok pokazuje sie jako OVERLAY (dropdown) nad rozmowa - pozycja liczona w JS
   i trzymana w --ov-* na panelu (fixed, bo kolumna ma overflow:hidden). */
.panel--stack.is-collapsed .stack-detail { display: none; }
.panel--stack.is-collapsed .gauge__chips { display: flex; }
/* Overlay szczegolow (dropdown nad rozmowa) - OSOBNY element doczepiony do
   <body>, zeby position:fixed liczyl sie wzgledem viewportu. Kolumna ma
   resztkowy transform (matrix identity z animacji fadeInUp z fill:both), ktory
   inaczej stalby sie blokiem zawierajacym i przesuwal overlay. */
.stack-overlay {
  position: fixed; z-index: 80; max-height: 78vh; overflow: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 22px 60px rgba(0,0,0,.45); padding: 14px 16px;
  animation: stackDrop .16s ease;
}
.stack-overlay[hidden] { display: none; }
@keyframes stackDrop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.panel--chat { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 240px; }
.panel--log { height: 100%; display: flex; flex-direction: column; min-height: 0; }

/* ------------------------------- POLA ------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field--row { flex-direction: row; gap: 10px; }
.field--row > .field { flex: 1; margin-bottom: 0; }
.field--end { justify-content: flex-end; }
.field__label { font-size: 11px; color: var(--fg-mut); letter-spacing: .03em; display: flex; align-items: center; gap: 8px; }
.field__hint { font-size: 10.5px; color: var(--fg-faint); }

.input {
  width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; font-family: var(--sans); font-size: 13px; transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--mint); box-shadow: 0 0 0 3px rgba(34,211,238,.18); }
.input--area { resize: vertical; line-height: 1.5; }
.input--mono { font-family: var(--mono); font-size: 12px; }
.input--bare { background: transparent; border-color: transparent; padding: 4px 6px; font-weight: 600; }
.input--bare:hover { border-color: var(--line); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--fg-mut) 50%), linear-gradient(135deg, var(--fg-mut) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }

.tk { font-family: var(--mono); font-size: 10px; color: var(--c-tools); background: rgba(245,166,35,.10); border: 1px solid rgba(245,166,35,.28); padding: 1px 6px; border-radius: 999px; }

/* --------------------- wyszukiwalny picker modelu ----------------------- */
.mpick { position: relative; }
.mpick__trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; font-family: var(--sans); font-size: 13px; cursor: pointer; text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.mpick__trigger:hover { border-color: var(--fg-faint); }
.mpick__trigger[aria-expanded="true"] { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(34,211,238,.18); }
.mpick__current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mpick__caret { color: var(--fg-mut); flex: none; font-size: 11px; }

.mpick__pop {
  position: fixed; z-index: 80; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden;
}
.mpick__pop[hidden] { display: none; }
.mpick__search { padding: 8px; border-bottom: 1px solid var(--line-soft); }
.mpick__input {
  width: 100%; background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px; font-family: var(--sans); font-size: 13px; outline: none;
}
.mpick__input:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(34,211,238,.15); }
.mpick__list { overflow-y: auto; padding: 4px; }
.mgroup { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-faint); padding: 9px 8px 4px; }
.mempty { color: var(--fg-faint); font-size: 12px; text-align: center; padding: 18px 12px; }

.mrow { display: grid; grid-template-columns: 26px 1fr 26px; align-items: center; gap: 2px; border-radius: 7px; }
.mrow:hover { background: var(--bg-3); }
.mrow.is-selected { background: color-mix(in srgb, var(--c-system) 16%, transparent); }
.mrow__star, .mrow__default { background: transparent; border: none; cursor: pointer; color: var(--fg-faint); font-size: 14px; line-height: 1; padding: 7px 0; transition: .12s; }
.mrow__star:hover, .mrow__default:hover { color: var(--fg); transform: scale(1.18); }
.mrow__star.is-on { color: var(--c-tools); }
.mrow__default.is-on { color: var(--c-system); }
.mrow__pick { display: flex; flex-direction: column; gap: 1px; align-items: flex-start; background: transparent; border: none; cursor: pointer; padding: 7px 4px; min-width: 0; width: 100%; text-align: left; color: var(--fg); }
.mrow__name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.mrow__meta { display: flex; gap: 6px; align-items: center; }
.mrow__ctx { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); }
.mrow__price { font-family: var(--mono); font-size: 10px; color: var(--navy); border: 1px solid var(--line); padding: 0 6px; white-space: nowrap; }
.mrow__price.is-free { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.mrow__defbadge { font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: .05em; color: var(--c-system); border: 1px solid rgba(34,211,238,.4); border-radius: 999px; padding: 0 6px; }

/* ------------------------------- PRZYCISKI (sharp + mint glow) ----------- */
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 12.5px; letter-spacing: .01em;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--fg);
  padding: 9px 16px; cursor: pointer; transition: .18s; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { border-color: var(--mint); color: var(--navy); box-shadow: 0 8px 20px -12px var(--glow); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--fg); border-color: transparent; color: var(--bg); box-shadow: 0 12px 28px -10px var(--glow); }
.btn--primary:hover { background: var(--mint); color: #06262b; box-shadow: 0 14px 30px -8px var(--glow); }
.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--bg-2); }
.btn--danger { background: transparent; border-color: color-mix(in srgb, var(--err) 45%, var(--line)); color: var(--err); }
.btn--danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); border-color: var(--err); color: var(--err); box-shadow: none; }
.btn--sm { padding: 6px 11px; font-size: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* =================== SYGNATURA: STOS OKNA KONTEKSTU ===================== */
#context-stack { display: flex; flex-direction: column; gap: 14px; }

.gauge { display: flex; flex-direction: column; gap: 8px; }
.gauge__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.gauge__used { font-family: var(--disp); font-weight: 700; font-size: 30px; line-height: 1; letter-spacing: .01em; }
.gauge__used small { font-size: 13px; font-weight: 600; color: var(--fg-mut); margin-left: 6px; }
.gauge__window { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); text-align: right; }
.gauge__pct { color: var(--fg-mut); }
.gauge__pct b { color: var(--c-system); font-weight: 700; font-size: 12.5px; }

/* podsumowanie KOSZTU CALEGO PRZEBIEGU (Okno kontekstu): wejscie/wyjscie/rozumowanie
   + cennik za 1M (in/out/rozum.). Dwie linie. */
.gauge__cost { display: flex; flex-direction: column; gap: 5px; font-family: var(--mono); font-size: 11px; color: var(--fg-mut);
  border: 1px solid var(--line); border-left: 3px solid var(--mint); background: color-mix(in srgb, var(--mint) 7%, var(--bg-2)); padding: 7px 10px; }
.gauge__cost-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.gauge__cost-ic { width: 16px; height: 16px; flex: none; display: grid; place-items: center; font-family: var(--disp); font-weight: 700; font-size: 11px; color: var(--bg); background: var(--mint); }
.gauge__cost-lbl { font-weight: 600; color: var(--fg-mut); }
.gauge__cost-io b { font-weight: 700; }
.gauge__cost-io--in b { color: var(--c-system); }
.gauge__cost-io--out b { color: var(--c-assistant); }
.gauge__cost-io--rea b { color: var(--c-rag); }
.gauge__cost-empty { color: var(--fg-faint); font-style: italic; }
.gauge__cost-tag { font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 40%, var(--line)); padding: 1px 6px; }
.gauge__cost-run { margin-left: auto; color: var(--fg-mut); }
.gauge__cost-run b { color: var(--navy); font-weight: 700; font-size: 12.5px; }
.gauge__cost-price { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 9px; padding-left: 22px; font-size: 10px; color: var(--fg-faint); }
.gauge__cost-price-lbl { text-transform: uppercase; letter-spacing: .04em; }

.muted { color: var(--fg-mut); }

.gauge__track {
  position: relative; height: 32px; border-radius: 8px; overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
  /* graticule: pionowe podzialki co 25% jak na przyrzadzie pomiarowym */
  background-image: linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 25% 100%;
}
.gauge__fill { position: absolute; inset: 0; display: flex; height: 100%; box-shadow: 1px 0 0 rgba(255,255,255,.12) inset; }
.gauge__seg { height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 0 5px; transition: width .5s cubic-bezier(.2,.7,.2,1), filter .15s; min-width: 0; border-right: 1px solid rgba(0,0,0,.18); }
.gauge__seg:last-child { border-right: none; }
.gauge__seg.is-hl { filter: brightness(1.18) saturate(1.2); }
/* etykieta warstwy wprost na slupku wykresu */
.gauge__seg-lbl { font-family: var(--mono); font-size: 10px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 1.5px rgba(0,0,0,.45); letter-spacing: .01em; }
.gauge__seg-lbl b { font-weight: 700; }
.gauge__scale { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 9.5px; color: var(--fg-faint); padding: 0 1px; }

/* chipy warstw w stylu ChatGPT - kompaktowe pigulki (nazwa · tokeny · udzial %).
   Widoczne po zwinieciu panelu jako zwiezle podsumowanie kontekstu. */
.gauge__chips { display: none; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.gauge__chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10px; line-height: 1; color: var(--fg-mut);
  background: var(--bg-3); border: 1px solid var(--line-soft); border-radius: 999px; padding: 4px 8px;
}
.gauge__chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: 0 0 auto; }
.gauge__chip-lbl { font-weight: 600; color: var(--fg-mut); }
.gauge__chip b { color: var(--fg); font-weight: 700; }
.gauge__chip em { font-style: normal; color: var(--c-system); font-weight: 700; }
.gauge__chip--empty { color: var(--fg-faint); border-style: dashed; }

.legend { display: flex; flex-direction: column; gap: 3px; }
.layer {
  display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: default; transition: background .15s;
  border: 1px solid transparent;
}
.layer:hover { background: var(--bg-3); border-color: var(--line); }
.layer__dot { width: 10px; height: 10px; border-radius: 3px; }
.layer__main { min-width: 0; }
.layer__name { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.layer__name .layer__count { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); font-weight: 400; }
.layer__bar { height: 4px; border-radius: 2px; margin-top: 5px; background: currentColor; opacity: .9; }
.layer__preview { font-size: 10.5px; color: var(--fg-faint); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer__tok { font-family: var(--mono); font-size: 12px; color: var(--fg-mut); text-align: right; }
.layer__tok b { color: var(--fg); }
.layer__pct { display: block; font-size: 10.5px; color: var(--c-system); font-weight: 700; margin-top: 1px; }

/* warstwy: kolory */
.l-system { color: var(--c-system); }
.l-tools { color: var(--c-tools); }
.l-memory { color: var(--c-memory); }
.l-user { color: var(--c-user); }
.l-rag, .l-tool_results { color: var(--c-rag); }
.l-assistant { color: var(--c-assistant); }

.stack-toggle, .stack-raw { font-family: var(--mono); }
.stack-toggle { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); background: transparent; border: none; padding: 4px 11px; border-radius: 999px; cursor: pointer; }
.seg.is-active { background: var(--bg-raise); color: var(--fg); }
.stack-raw { display: none; max-height: 68vh; overflow: auto; font-size: 11.5px; line-height: 1.6; }
.stack-raw.is-on { display: block; }
/* podswietlanie skladni JSON w widoku "Surowy" */
.stack-raw .js-key { color: var(--c-system); font-weight: 600; }
.stack-raw .js-str { color: var(--ok); }
.stack-raw .js-num { color: var(--c-tools); }
.stack-raw .js-bool { color: var(--c-user); font-weight: 600; }
.stack-raw .js-null { color: var(--fg-faint); font-style: italic; }

/* obszar szczegolow pod miernikiem (Spektrum / Tasma / Surowy) */
.stack-detail { margin-top: 14px; max-height: 32vh; overflow: auto; padding-right: 2px; }

/* "Prompt": zlozony prompt jako JEDEN BLOK z podswietlonymi i podkreslonymi
   czesciami (jak chunki w RAG) - kazda czesc w kolorze swojej warstwy. */
.ctx-prompt-note { font-family: var(--mono); font-size: 10.5px; color: var(--fg-faint); margin-bottom: 8px; }
.ctx-prompt {
  font-family: var(--mono); font-size: 12px; line-height: 2; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; white-space: pre-wrap; word-break: break-word;
}
.ctx-seg {
  --seg: var(--c-assistant);
  background: color-mix(in srgb, var(--seg) 15%, transparent);
  border-bottom: 2px solid var(--seg);
  border-radius: 4px 4px 0 0; padding: 2px 5px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.ctx-seg__tag {
  font-size: 8.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--seg); margin-right: 7px; vertical-align: 1px;
}
.ctx-seg__sub { color: var(--fg-faint); }
.ctx-seg__empty { color: var(--fg-faint); font-style: italic; }
.ctx-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-family: var(--mono); font-size: 10.5px; color: var(--fg-mut); }
.ctx-leg { display: inline-flex; align-items: center; gap: 6px; }
.ctx-leg i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ------------------------------- NARZEDZIA ------------------------------- */
.tools-list { display: flex; flex-direction: column; gap: 8px; }
.tool { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden; }
.tool.is-off { opacity: .55; }
/* zrodlo narzedzia (serwer MCP/HTTP): akcent po lewej + pasek "MCP · host".
   Wspolny kolor per host => narzedzia z jednego serwera grupuja sie wzrokowo. */
.tool.is-sourced { border-left: 3px solid var(--src); }
.tool__src { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px; color: var(--fg-mut); padding: 0 11px 7px; }
.tool__src i { width: 7px; height: 7px; border-radius: 50%; background: var(--src); flex: none; }
.tool__src b { color: var(--fg); font-weight: 700; letter-spacing: .04em; }
.tool__head { display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 8px; padding: 8px 10px; }
.tool__type { font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--fg-mut); }
.tool__type[data-t="rag"] { color: var(--c-rag); border-color: rgba(176,124,245,.4); }
.tool__type[data-t="mcp"] { color: var(--c-tools); border-color: rgba(245,166,35,.4); }
.tool__type[data-t="http"] { color: var(--c-memory); border-color: rgba(45,212,191,.4); }
.tool__type[data-t="docs"] { color: var(--c-system); border-color: rgba(34,211,238,.4); }
.tool__type[data-t="code"] { color: var(--c-user); border-color: rgba(255,122,147,.4); }
.tool__expand { background: transparent; border: none; color: var(--fg-mut); cursor: pointer; font-size: 14px; transition: transform .15s; }
.tool.is-open .tool__expand { transform: rotate(90deg); }
.tool__body { display: none; padding: 4px 12px 12px; border-top: 1px solid var(--line-soft); }
.tool.is-open .tool__body { display: block; }
.tool__extra { margin-bottom: 10px; }
.tool__extra .field { margin-bottom: 8px; }
/* Instrukcja calego serwera MCP (server-level instructions z initialize). */
.mcp-instr__body { font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--fg-mut);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-top: 4px;
  max-height: 150px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* switch */
.switch { position: relative; display: inline-block; width: 32px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__slot { position: absolute; inset: 0; background: var(--bg-raise); border: 1px solid var(--line); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch__slot::before { content: ""; position: absolute; width: 12px; height: 12px; left: 2px; top: 2px; background: var(--fg-mut); border-radius: 50%; transition: .15s; }
.switch input:checked + .switch__slot { background: rgba(52,211,153,.25); border-color: var(--ok); }
.switch input:checked + .switch__slot::before { transform: translateX(14px); background: var(--ok); }

/* ------------------------------- ROZMOWA (styl ChatGPT) ------------------ */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding-right: 6px; margin-bottom: 12px; }

.turn { display: flex; gap: 12px; align-items: flex-start; }
.turn--user { justify-content: flex-end; }
.turn__avatar { width: 30px; height: 30px; border-radius: 9px; flex: none; background: var(--logo-bg); box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); display: grid; place-items: center; }
.turn__avatar svg { width: 19px; height: 19px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.28)); }
.turn__main { min-width: 0; flex: 1; }
.turn__who { font-family: var(--disp); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--fg-mut); margin: 4px 0 6px; }
.turn__bubble { font-size: 13.5px; line-height: 1.62; color: var(--fg); word-break: break-word; }
.turn__bubble--user { max-width: 80%; background: var(--bg-3); border: 1px solid var(--line); border-radius: 18px 18px 5px 18px; padding: 11px 15px; white-space: pre-wrap; }

/* markdown w odpowiedzi asystenta */
.turn__bubble p { margin: 0 0 10px; }
.turn__bubble p:last-child { margin-bottom: 0; }
.turn__bubble ul, .turn__bubble ol { margin: 6px 0 12px; padding-left: 22px; }
.turn__bubble li { margin: 4px 0; }
.turn__bubble strong { font-weight: 700; }
.turn__bubble .md-h { font-weight: 700; font-size: 14px; margin: 4px 0 8px; }
.turn__bubble a { color: var(--c-system); text-decoration: underline; text-underline-offset: 2px; }
.md-code { font-family: var(--mono); font-size: .86em; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.md-pre { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; overflow: auto; margin: 6px 0 12px; }
.md-pre code { background: none; border: none; padding: 0; }
.md-table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; font-size: 13px; display: block; overflow-x: auto; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md-table th { background: var(--bg-3); font-weight: 600; font-size: 12px; }
.md-table tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-3) 45%, transparent); }

/* pusta rozmowa: powitanie + siatka kart (jak ChatGPT) */
.chat-empty { display: flex; flex-direction: column; gap: 18px; padding: 6px 2px; }
.chat-empty__hero { text-align: center; padding: 10px 0 2px; }
.chat-empty__mark { width: 42px; height: 42px; border-radius: 13px; background: var(--logo-bg); margin: 0 auto 14px; box-shadow: var(--shadow); display: grid; place-items: center; }
.chat-empty__mark svg { width: 27px; height: 27px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.28)); }
.chat-empty__hero h3 { font-family: var(--disp); font-size: 19px; font-weight: 700; margin: 0 0 4px; color: var(--fg); }
.chat-empty__hero p { color: var(--fg-mut); font-size: 13px; margin: 0; }
.suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.suggest {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; cursor: pointer; transition: .15s;
}
.suggest:hover { border-color: var(--c-system); background: var(--bg-3); transform: translateY(-2px); box-shadow: var(--shadow); }
.suggest__label { font-weight: 600; font-size: 12px; color: var(--fg); }
.suggest__hint { font-size: 10.5px; color: var(--fg-mut); line-height: 1.35; }

/* kompozytor w stylu ChatGPT: zaokraglone pole + okragly przycisk wysylki */
.composer { display: flex; flex-direction: column; gap: 7px; }
.composer__box { display: flex; align-items: flex-end; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 22px; padding: 7px 7px 7px 16px; transition: border-color .15s, box-shadow .15s; }
.composer__box:focus-within { border-color: color-mix(in srgb, var(--mint) 45%, var(--line)); }
.composer__input { flex: 1; border: none; background: transparent; resize: none; color: var(--fg); font-family: var(--sans); font-size: 13.5px; line-height: 1.5; padding: 7px 0; max-height: 160px; outline: none; overflow-y: hidden; }
/* pole nie pokazuje globalnego mint-outline (zbedna wewnetrzna ramka) - fokus widac na .composer__box */
.composer__input:focus, .composer__input:focus-visible { outline: none; box-shadow: none; }
.composer__input::placeholder { color: var(--fg-faint); }
.composer__send { position: relative; flex: none; width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--grad-primary); color: #fff; cursor: pointer; display: grid; place-items: center; transition: .15s; box-shadow: 0 4px 14px rgba(34,211,238,.3); }
.composer__send:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.composer__send:disabled { cursor: not-allowed; }
.composer__send.is-busy { color: transparent; }
.composer__send.is-busy::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer__hint { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); text-align: center; }
@media (max-width: 1280px) { .suggest-grid { grid-template-columns: 1fr; } }

/* ===================== DZIENNIK DZIALAN - PRZEPLYW (workflow) =============
   Pionowy graf wezlow: kroki to "przystanki" na kregoslupie, kazde zdarzenie
   przebiegu to wezel (n8n-owy node) z kolorowym znacznikiem na linii przeplywu.
   Linie laczace rysowane sa pseudo-elementem ::before za znacznikami, dzieki
   czemu kregoslup jest ciagly niezaleznie od wysokosci kart.
   ======================================================================== */
.flow { flex: 1; overflow-y: auto; position: relative; display: flex; flex-direction: column; padding: 6px 4px 18px 2px; }
.flow .empty, .empty { color: var(--fg-faint); font-size: 12px; text-align: center; padding: 24px 12px; }

/* --- przystanek kroku (lane marker na kregoslupie) --- */
.flow-mark { position: relative; min-height: 30px; display: flex; align-items: center; padding-left: 38px; margin-top: 8px; }
.flow-mark:first-child { margin-top: 2px; }
.flow-mark::before { content: ''; position: absolute; left: 16px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.flow-mark:first-child::before { top: 15px; }                 /* nie wystawaj nad pierwszy przystanek */
.flow-mark:last-child::before { bottom: auto; height: 15px; } /* znacznik chwilowo ostatni (streaming) - nie zwisaj */
.flow-mark__ring { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--fg-faint); background: var(--bg); box-shadow: 0 0 0 4px var(--bg); z-index: 2; }
.flow-mark:first-child .flow-mark__ring { border-color: var(--ok); background: radial-gradient(circle at 50% 50%, var(--ok) 0 40%, var(--bg) 42%); }
.flow-mark__label { font-family: var(--disp); font-weight: 700; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-mut); }

/* --- wezel przeplywu --- */
.flow-node { position: relative; padding-left: 38px; padding-bottom: 12px; animation: fadeInUp .3s cubic-bezier(.2,.7,.2,1) both; }
.flow-node::before { content: ''; position: absolute; left: 16px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.flow-node:last-child::before { bottom: auto; height: 15px; }  /* utnij ogon kregoslupa pod ostatnim wezlem */
.flow-node__badge { position: absolute; left: 4px; top: 2px; z-index: 2; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.flow-node__badge svg { width: 15px; height: 15px; }

.flow-node__card { border: 1px solid var(--line-soft); border-left: 3px solid var(--line); border-radius: 9px; background: var(--bg-2); overflow: hidden; transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease; }
.flow-node:not(.is-leaf) .flow-node__card:hover { box-shadow: 0 8px 22px rgba(0,0,0,.22); transform: translateX(1px); }
.flow-node__head { display: flex; align-items: center; gap: 8px; padding: 9px 11px; font-size: 12px; }
.flow-node:not(.is-leaf) .flow-node__head { cursor: pointer; }
.flow-node__head:focus-visible { outline: 2px solid var(--mint); outline-offset: -2px; border-radius: 7px; }
.flow-node__title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-node__meta { font-family: var(--mono); font-size: 10px; color: var(--fg-mut); white-space: nowrap; flex: none; }
.flow-node__chev { color: var(--fg-faint); transition: transform .18s ease; flex: none; font-size: 11px; }

/* znacznik KIERUNKU przeplywu (mocno podkreslony): wysylka (→ do) vs odbior (← z) */
.flow-dir { font-family: var(--mono); font-size: 8.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; white-space: nowrap; flex: none; display: inline-flex; align-items: center; gap: 3px; border: 1px solid currentColor; }
.flow-dir--out { color: var(--c-system); background: color-mix(in srgb, var(--c-system) 12%, transparent); }
.flow-dir--in { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
/* lewy akcent karty wg KIERUNKU (wyzsza specyficznosc niz kolor rodzaju):
   ciagly sygnal "wysylka vs odbior" na lewej krawedzi; plakietka = kolor rodzaju */
.flow-node.flow-node--out .flow-node__card { border-left-color: var(--c-system); }
.flow-node.flow-node--in .flow-node__card { border-left-color: var(--ok); }
.flow-node.is-open .flow-node__chev { transform: rotate(90deg); }
.flow-node__body { display: none; padding: 2px 11px 11px; }
.flow-node.is-open .flow-node__body { display: block; animation: fadeIn .2s ease both; }

/* kolory wezlow wg rodzaju (spektrum warstw kontekstu) */
.flow-node--req .flow-node__badge { background: var(--c-system); }
.flow-node--req .flow-node__card { border-left-color: var(--c-system); }
.flow-node--res .flow-node__badge { background: var(--ok); color: #062013; }
.flow-node--res .flow-node__card { border-left-color: var(--ok); }
.flow-node--ctx .flow-node__badge { background: var(--c-tools); color: #2a1c03; }
.flow-node--ctx .flow-node__card { border-left-color: var(--c-tools); }
.flow-node--tool .flow-node__badge { background: var(--c-rag); }
.flow-node--tool .flow-node__card { border-left-color: var(--c-rag); }
.flow-node--assistant .flow-node__badge { background: var(--c-assistant); color: #08111c; }
.flow-node--assistant .flow-node__card { border-left-color: var(--c-assistant); }
.flow-node--err .flow-node__badge { background: var(--err); }
.flow-node--err .flow-node__card { border-left-color: var(--err); border-color: rgba(248,113,113,.4); }

/* wezel koncowy - domkniecie przeplywu (okragly znacznik z ptaszkiem) */
.flow-node--end .flow-node__badge { border-radius: 50%; background: var(--ok); color: #062013; box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent), 0 2px 8px rgba(0,0,0,.35); }

pre.code { font-family: var(--mono); font-size: 11px; line-height: 1.55; color: var(--code-fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow: auto; max-height: 320px; white-space: pre; margin: 6px 0 0; }
/* widok "Surowy": zawijaj dlugie wartosci JSON (np. pelny system prompt) zamiast scrolla w poziomie.
   Musi byc po regule pre.code (ta sama specyficznosc) - tu zostaje pre-wrap. */
pre.stack-raw { white-space: pre-wrap; overflow-wrap: anywhere; }
.kv { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.kv b { color: var(--fg); font-weight: 600; }
.tag { font-family: var(--mono); font-size: 10px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg-mut); }
.tag--ok { color: var(--ok); border-color: rgba(52,211,153,.4); }
.tag--amber { color: var(--c-tools); border-color: rgba(245,166,35,.4); }
.tag--err { color: var(--err); border-color: rgba(248,113,113,.4); }

/* ------------------------------- RAG LAB --------------------------------- */
.view--rag { grid-template-columns: 380px 1fr; gap: 16px; padding: 16px; height: calc(100vh - 61px); }
.col--rag-controls { overflow-y: auto; }
.col--rag-view { overflow-y: auto; }
.rag-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.rag-actions .btn { flex: 1; }
.rag-meta { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); margin-bottom: 10px; min-height: 16px; }
.rag-chip { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); }

.rag-chunk-view { display: flex; flex-direction: column; gap: 12px; }
.chunk-text { font-family: var(--mono); font-size: 12px; line-height: 1.7; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }
.chunk-seg { border-radius: 3px; padding: 1px 0; }
.chunk-list { display: flex; flex-direction: column; gap: 6px; }
.chunk-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--bg); border-left-width: 3px; }
.chunk-card__head { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--fg-mut); margin-bottom: 4px; }
.chunk-card__text { font-size: 12px; color: var(--fg); max-height: 64px; overflow: hidden; }

/* prosty interfejs bazy: lista kolekcji + podglad elementow */
.rag-collections { display: flex; flex-direction: column; gap: 6px; }
.coll-row { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden; }
.coll-row__head { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; background: transparent; border: none; cursor: pointer; color: var(--fg); text-align: left; }
.coll-row__head:hover { background: var(--bg-3); }
.coll-row__name { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.coll-row__name::before { content: "▸ "; color: var(--fg-faint); }
.coll-row.is-open .coll-row__name::before { content: "▾ "; }
.coll-row__count { font-family: var(--mono); font-size: 10.5px; color: var(--c-rag); background: rgba(176,124,245,.12); border: 1px solid rgba(176,124,245,.3); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.coll-row__peek { display: flex; flex-direction: column; gap: 4px; padding: 0 11px; }
.coll-row.is-open .coll-row__peek { padding: 4px 11px 10px; }
.coll-item { display: grid; grid-template-columns: 26px 1fr; gap: 8px; font-size: 11.5px; color: var(--fg-mut); border-top: 1px solid var(--line-soft); padding-top: 6px; }
.coll-item__n { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); }
.coll-item__text { line-height: 1.5; max-height: 60px; overflow: hidden; }

.rag-rank-view { display: flex; flex-direction: column; gap: 8px; }

/* baner dydaktyczny nad rankingiem (tryb lokalny / niezgodnosc wymiarow) */
.rag-note { display: flex; gap: 9px; align-items: flex-start; font-size: 11.5px; line-height: 1.5; color: var(--prose);
  border: 1px solid color-mix(in srgb, var(--c-system) 35%, var(--line)); border-left: 3px solid var(--c-system);
  background: color-mix(in srgb, var(--c-system) 9%, var(--bg-2)); border-radius: var(--radius-sm); padding: 9px 11px; }
.rag-note--warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, var(--bg-2)); }
.rag-note__ic { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--disp); font-weight: 700; font-size: 11px; color: #fff; background: var(--c-system); }
.rag-note--warn .rag-note__ic { background: var(--warn); color: #2a1c03; }
.rag-note b { color: var(--fg); }

.rank-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--bg); }
.rank-row.is-retrieved { border-color: var(--ok); background: rgba(52,211,153,.06); }
.rank-row__head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.rank-row__rank { font-family: var(--disp); font-weight: 700; font-size: 14px; color: var(--fg-mut); width: 26px; }
.rank-row.is-retrieved .rank-row__rank { color: var(--ok); }
.rank-row__score { font-family: var(--mono); font-size: 11px; color: var(--fg); }
.rank-row__badge { margin-left: auto; font-family: var(--mono); font-size: 10px; color: var(--ok); border: 1px solid rgba(52,211,153,.4); border-radius: 999px; padding: 1px 8px; }
.rank-bar { height: 6px; border-radius: 3px; background: var(--bg-raise); overflow: hidden; margin-bottom: 6px; }
.rank-bar__fill { height: 100%; background: var(--grad-primary); border-radius: 3px; }
.rank-row.is-retrieved .rank-bar__fill { background: linear-gradient(90deg, var(--ok), var(--c-memory)); }
.rank-row__text { font-size: 12px; color: var(--fg-mut); max-height: 56px; overflow: hidden; }
.rank-row--text .rank-bar__fill { background: linear-gradient(90deg, var(--c-tools), var(--c-user)); }
.rank-row__text mark.hl { background: color-mix(in srgb, var(--c-tools) 35%, transparent); color: var(--fg); border-radius: 3px; padding: 0 1px; }

/* demistyfikacja cosinusa (odleglosc + kat) pod paskiem rankingu wektorowego */
.rank-row__math { font-family: var(--mono); font-size: 10.5px; color: var(--fg-faint); margin-bottom: 6px; }
.rank-row__math b { color: var(--fg-mut); font-weight: 600; }

/* znaczniki pochodzenia wyniku w trybie hybrydowym (RRF) */
.rrf-tags { display: inline-flex; gap: 5px; }
.rrf-tag { font-family: var(--mono); font-size: 9.5px; font-weight: 600; border-radius: 999px; padding: 1px 7px; border: 1px solid currentColor; }
.rrf-tag--vec { color: var(--c-system); }
.rrf-tag--txt { color: var(--c-tools); }
.rank-row--hybrid .rank-bar__fill { background: linear-gradient(90deg, var(--c-system), var(--c-rag), var(--c-tools)); }
.rank-row--hybrid.is-retrieved .rank-bar__fill { background: linear-gradient(90deg, var(--ok), var(--c-memory)); }

/* tryb wyszukiwania + porownanie wektorowe vs tekstowe */
.ragmode .seg.is-active { color: var(--fg); }
.rank-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rank-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rank-col__head { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding-bottom: 4px; border-bottom: 1px solid var(--line-soft); }
.rank-col__head--vec { color: var(--c-system); }
.rank-col__head--txt { color: var(--c-tools); }
@media (max-width: 1100px) { .rank-compare { grid-template-columns: 1fr; } }

/* ------------------------------- DOKUMENTACJA ---------------------------- */
.view--docs { display: none; }
.view--docs.is-active { display: block; padding: 32px 20px 64px; }
.docs { max-width: 860px; margin: 0 auto; }
.docs h1 { font-family: var(--disp); font-size: 30px; font-weight: 700; letter-spacing: .01em; margin: 0 0 4px; }
.docs .lead { color: var(--fg-mut); font-size: 15px; margin-bottom: 28px; }
.docs h2 { font-size: 16px; text-transform: none; letter-spacing: 0; margin: 30px 0 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.docs h3 { font-family: var(--disp); font-size: 14px; margin: 18px 0 6px; }
.docs p, .docs li { color: var(--prose); font-size: 13.5px; line-height: 1.65; }
.docs ul, .docs ol { padding-left: 20px; }
.docs code { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--c-memory); }
.docs .doc-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin: 14px 0; }
.docs .doc-flow { display: grid; gap: 8px; }
.docs .doc-step { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; }
.docs .doc-step__n { font-family: var(--disp); font-weight: 700; color: var(--c-system); }

/* ------------------------------- RESPONSYWNOSC --------------------------- */
@media (max-width: 1280px) {
  .view--agent { grid-template-columns: 320px 1fr; height: auto; }
  .col--log { grid-column: 1 / -1; height: 520px; }
  .col { height: auto; }
  .col--center { height: auto; }
}
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .status { width: 100%; order: 3; }
  .view--agent, .view--rag { grid-template-columns: 1fr; height: auto; }
  .col--log { height: 480px; }
}

/* ------------------------------- USTAWIENIA (modal) ---------------------- */
.iconbtn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--fg-mut);
  border-radius: 999px; cursor: pointer; transition: .15s;
}
.iconbtn:hover { color: var(--fg); border-color: var(--fg-faint); transform: rotate(30deg); }
.iconbtn--sm { width: 26px; height: 26px; font-size: 13px; }
.iconbtn--sm:hover { transform: none; }

.modal {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: var(--overlay); backdrop-filter: blur(4px); padding: 20px;
  animation: modalIn .15s ease;
}
@keyframes modalIn { from { opacity: 0; } to { opacity: 1; } }
.modal__card {
  width: min(560px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal__close { background: transparent; border: none; color: var(--fg-mut); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.modal__close:hover { color: var(--fg); }
.modal__body { padding: 16px 20px; overflow-y: auto; }
.modal__note { font-size: 11.5px; color: var(--fg-mut); line-height: 1.6; background: var(--bg); border: 1px solid var(--line); border-left: 3px solid var(--c-tools); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0 0 14px; }
.set-status { font-family: var(--mono); font-size: 10.5px; color: var(--fg-mut); margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.srv { color: var(--fg-faint); }
.srv--ok { color: var(--ok); }
.set-group { margin-bottom: 14px; }
.set-group h3 { font-family: var(--disp); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--c-system); margin: 0 0 8px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.modal__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal__foot-right { display: flex; gap: 8px; }
.modal__card--wide { width: min(680px, 100%); }

/* ----------------------- przegladarka narzedzi MCP --------------------- */
.mcp-conn { display: flex; gap: 8px; margin-bottom: 8px; }
.mcp-conn .input { flex: 1; }
.mcp-key { width: 100%; margin-bottom: 12px; }
.mcp-status { font-family: var(--mono); font-size: 11px; color: var(--fg-mut); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mcp-tools { display: flex; flex-direction: column; gap: 8px; }
.mcp-tool {
  display: flex; gap: 11px; align-items: flex-start; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
  cursor: pointer; transition: border-color .15s, background .15s; animation: fadeInUp .25s ease both;
}
.mcp-tool:hover { border-color: var(--c-system); }
.mcp-tool.is-added { opacity: .62; cursor: default; }
.mcp-tool.is-added:hover { border-color: var(--line); }
.mcp-tool input { margin-top: 3px; accent-color: var(--c-system); width: 15px; height: 15px; flex: none; }
.mcp-tool__main { min-width: 0; }
.mcp-tool__name { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--fg); display: flex; align-items: center; gap: 8px; }
.mcp-tool__badge { font-family: var(--mono); font-size: 9.5px; font-weight: 600; color: var(--ok); border: 1px solid rgba(52,211,153,.4); border-radius: 999px; padding: 1px 7px; }
.mcp-tool__desc { font-size: 12px; color: var(--fg-mut); line-height: 1.55; margin-top: 4px; white-space: pre-line; }
.mcp-tool__params { font-family: var(--mono); font-size: 10.5px; color: var(--c-tools); margin-top: 5px; }
.mcp-all { font-size: 11.5px; color: var(--fg-mut); display: flex; align-items: center; gap: 7px; cursor: pointer; }
.mcp-all input { accent-color: var(--c-system); }

/* lista narzedzi serwera MCP w karcie narzedzia ("tools to include" jak w n8n) */
.mcp-toollist__hint { font-family: var(--mono); font-size: 10px; font-weight: 400; color: var(--fg-faint); margin-left: 6px; }
.mcp-toollist { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.mcp-toolrow { display: flex; gap: 9px; align-items: flex-start; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-2); cursor: pointer; transition: opacity .15s, border-color .15s; }
.mcp-toolrow:hover { border-color: var(--c-tools); }
.mcp-toolrow.is-off { opacity: .5; }
.mcp-toolrow input { margin-top: 2px; accent-color: var(--c-tools); width: 14px; height: 14px; flex: none; }
.mcp-toolrow__main { min-width: 0; }
.mcp-toolrow__name { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--fg); }
.mcp-toolrow__tk { font-family: var(--mono); font-size: 9.5px; font-weight: 400; color: var(--c-tools); margin-left: 4px; }
.mcp-toolrow__desc { font-size: 10.5px; color: var(--fg-mut); line-height: 1.4; margin-top: 2px; }
.mcp-refresh { margin-top: 8px; }

/* scrollbar */
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--bg-raise); border-radius: 6px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-track { background: transparent; }

[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

/* =============================== ANIMACJE ================================
   Subtelne, spojne wejscia komponentow. Wszystko wylaczane przez
   prefers-reduced-motion (regula na koncu pliku).
   ======================================================================= */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes barGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes spectrumSlide { from { background-position: 0 0; } to { background-position: 200% 0; } }

/* przelaczanie widokow */
.view.is-active { animation: fadeIn .25s ease; }

/* wejscie kolumn (delikatny stagger) */
.col { animation: fadeInUp .45s cubic-bezier(.2,.7,.2,1) both; }
.view--agent .col:nth-child(2) { animation-delay: .06s; }
.view--agent .col:nth-child(3) { animation-delay: .12s; }
.view--rag .col:nth-child(2) { animation-delay: .06s; }

/* nowe wiadomosci i wezly przeplywu (animacja wezlow jest przy .flow-node) */
.turn { animation: fadeInUp .3s ease both; }

/* "generujacy sie" ranking - paski rosna przy kazdym odswiezeniu */
.rank-bar__fill { transform-origin: left center; animation: barGrow .5s cubic-bezier(.2,.7,.2,1) both; }
.rank-row { animation: fadeInUp .28s ease both; }

/* karty przykladow w pustej rozmowie (stagger) */
.suggest { animation: fadeInUp .35s ease both; }
.suggest:nth-child(2) { animation-delay: .05s; }
.suggest:nth-child(3) { animation-delay: .10s; }
.suggest:nth-child(4) { animation-delay: .15s; }
.suggest:nth-child(5) { animation-delay: .20s; }

/* podglad elementow kolekcji + modal */
.coll-item { animation: fadeIn .25s ease both; }
.modal__card { animation: popIn .2s cubic-bezier(.2,.9,.3,1.1); }

/* miekkie podniesienie paneli na hover (bez ruchu w panelu kontekstu) */
.panel:not(.panel--stack):not(.panel--chat):not(.panel--log):hover { box-shadow: 0 10px 28px rgba(0,0,0,.16); }
.panel { transition: box-shadow .2s ease; }

/* ===== OSTRE KRAWEDZIE (sharp edges) — sygnatura CloudBots =================
   Wieksze powierzchnie (panele, inputy) sa juz ostre przez --radius:0.
   Ponizej zerujemy literalne zaokraglenia (pigulki, karty, dymki, badge).
   Zachowane okregi: kropki statusu, pierscienie kroku, przelacznik, spinner,
   heksagon logo/kredytu, awatar bota. ======================================= */
.tab, .doclink, .credit, .chip, .tk, .count, .theme-switch, .theme-switch button,
.btn, .stack-toggle, .seg, .mrow, .mrow__defbadge, .gauge__track, .gauge__chip,
.coll-row__count, .turn__bubble--user, .composer__box, .composer__send, .iconbtn,
.rrf-tag, .rank-row__badge, .tag, .mcp-tool__badge, .suggest, .md-pre, .md-code,
.flow-node__card, .modal__card, .modal__card--wide, .modal__note, .chunk-seg,
.rank-bar, .layer__dot, .turn__avatar, .chat-empty__mark
{ border-radius: 0 !important; }
/* wezel koncowy przeplywu zostaje okraglym znacznikiem (domkniecie) */
.flow-node--end .flow-node__badge { border-radius: 50% !important; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
