/* TikTok Reader — panel webowy.
 *
 * Jeden arkusz na oba układy. Makiety przyszły jako dwa pliki (mobile + desktop),
 * ale to ten sam design system, a panel jest jedną aplikacją pod jednym adresem
 * (PWA), więc różnicę robi wyłącznie breakpoint 900 px:
 *   < 900 px  — nagłówek + dolna nawigacja z FAB, detal jako pełny ekran
 *   >= 900 px — sidebar + master-detail, detal jako panel po prawej
 * Ten sam węzeł DOM detalu obsługuje oba przypadki, więc render jest jeden.
 */

/* ==================================================================== */
/* tokeny                                                               */
/* ==================================================================== */
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel2: #f6f8fa;
  --border: #dde2e8;
  --text: #1f2933;
  --muted: #6b7684;
  --accent: #3e63dd;
  --accent-soft: #e8edfb;
  --green: #2e9e6b;
  --green-soft: rgba(46, 158, 107, .1);
  --amber: #c98a2b;
  --amber-soft: rgba(201, 138, 43, .11);
  --red: #d64541;
  --red-soft: #fdeeee;
  --on-accent: #fff;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06);
  --nav-bg: rgba(255, 255, 255, .92);
  --sheet-shadow: 0 -8px 34px rgba(0, 0, 0, .2);
}

body.dark {
  --bg: #0e1014;
  --panel: #161a21;
  --panel2: #1d222b;
  --border: #262d38;
  --text: #e8ebf0;
  --muted: #8b93a2;
  --accent: #6b8afd;
  --accent-soft: #1f2942;
  --green: #3ec98d;
  --green-soft: rgba(62, 201, 141, .13);
  --amber: #e0b15c;
  --amber-soft: rgba(224, 177, 92, .13);
  --red: #f07a70;
  --red-soft: rgba(240, 122, 112, .13);
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
  --nav-bg: rgba(22, 26, 33, .92);
  --sheet-shadow: 0 -8px 34px rgba(0, 0, 0, .5);
}

/* ==================================================================== */
/* baza                                                                 */
/* ==================================================================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .25s, color .25s;
}

button, input, select, textarea { font-family: inherit; }
a { color: var(--accent); }

.ic { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic-s { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic-xs { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.row-flex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ==================================================================== */
/* powłoka: sidebar / kolumna główna                                    */
/* ==================================================================== */
#app { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.sidebar { display: none; }

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

header {
  padding: 14px 18px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
header .t { font-size: 18px; font-weight: 750; letter-spacing: -.01em; }

.chrome { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }

.status-pill {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 650;
  color: var(--green); background: var(--green-soft);
  border: none; padding: 6px 12px; border-radius: 99px;
  cursor: pointer; white-space: nowrap;
}
.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-pill.run { color: var(--accent); background: var(--accent-soft); }
.status-pill.run i { animation: blink 1s infinite; }
.status-pill.err { color: var(--red); background: var(--red-soft); }
.status-pill.on { box-shadow: 0 0 0 2px var(--accent); font-weight: 800; }
@keyframes blink { 50% { opacity: .3; } }

.icon-btn {
  width: 36px; height: 36px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:hover { color: var(--text); }
.icon-btn:active { transform: scale(.94); }

.counters { display: flex; gap: 8px; padding: 0 18px 10px; overflow-x: auto; flex: none; scrollbar-width: none; }
.counters::-webkit-scrollbar { display: none; }
/* na wąskim ekranie czat potrzebuje każdego piksela wysokości */
@media (max-width: 899px) { body.view-chat .counters { display: none; } }
.cnt {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 99px;
  padding: 5px 12px; font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.cnt b { color: var(--text); }
.cnt .ic-xs { color: var(--muted); }
.cnt.warn b { color: var(--amber); }

/* ==================================================================== */
/* widoki                                                               */
/* ==================================================================== */
main { flex: 1; min-height: 0; position: relative; }

.view {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 18px 110px;
  display: none;
  scrollbar-width: none;
}
.view::-webkit-scrollbar { display: none; }
/* Wejście widoku bez `transform`: element z animacją transformacji staje się
   blokiem zawierającym dla `position: fixed` potomków, a wtedy pełnoekranowy
   detal na telefonie zamyka się w ramce widoku zamiast przykryć ekran. */
.view.active { display: block; animation: fade .22s cubic-bezier(.3, 1, .4, 1); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
  transition: background .25s, border-color .25s;
}
.card.flush { padding: 4px 16px; }
.card h3 {
  margin: 0 0 12px; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.card h3.plain { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); overflow-wrap: anywhere; }
.card h3 .link {
  text-transform: none; letter-spacing: 0; font-size: 12px;
  color: var(--accent); font-weight: 650; cursor: pointer; background: none; border: none;
  white-space: nowrap;
}
.card .hint { margin: -6px 0 10px; font-size: 12px; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 13px 15px; box-shadow: var(--shadow); }
.stat .l { font-size: 11.5px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 800; margin-top: 2px; letter-spacing: -.01em; }

/* ==================================================================== */
/* komponenty                                                           */
/* ==================================================================== */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; border-radius: 12px; padding: 13px;
  font-size: 14px; font-weight: 650; cursor: pointer; transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-ghost { background: var(--panel); border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 12.5px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; margin-bottom: 12px; }
.btn-row .btn { flex: 1; }

.dz {
  border: 1.5px dashed var(--border); border-radius: 14px; padding: 26px 16px;
  text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px;
  background: var(--panel); cursor: pointer; transition: border-color .2s, background .2s;
}
.dz.hover { border-color: var(--accent); background: var(--accent-soft); }
.dz b { color: var(--text); display: block; font-size: 14.5px; margin-bottom: 4px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--panel2); }
.row.clickable:active { background: var(--panel2); }
.row.sel { background: var(--accent-soft); border-radius: 10px; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-bottom-color: transparent; }
.row.dim { opacity: .68; }
.row .fi {
  width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft);
  display: grid; place-items: center; color: var(--accent); flex: none; overflow: hidden;
}
.row .fi img { width: 100%; height: 100%; object-fit: cover; }
.row .fi.amber { background: var(--amber-soft); color: var(--amber); }
.row .fi.red { background: var(--red-soft); color: var(--red); }
.row .mid { min-width: 0; flex: 1; }
/* dwie linijki maksimum: wiersze mają równą wysokość, więc lista czyta się
   jak lista, a nie jak akapity różnej długości */
.row .nm {
  font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row .mt { font-size: 11.5px; color: var(--muted); margin-top: 1px; overflow-wrap: anywhere; }
.row .right { margin-left: auto; text-align: right; font-size: 11.5px; color: var(--muted); flex: none; display: flex; align-items: center; gap: 8px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.b-ok { color: var(--green); background: var(--green-soft); }
.b-new { color: var(--accent); background: var(--accent-soft); }
.b-err { color: var(--red); background: var(--red-soft); }
.b-run { color: var(--amber); background: var(--amber-soft); }
.b-mute { color: var(--muted); background: var(--panel2); }

.bar { height: 6px; background: var(--panel2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .4s ease; }
.bar i.run { background: var(--accent); }
.bar i.warn { background: var(--amber); }

.stage { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); }
.stage b { color: var(--text); font-weight: 650; }

.search { display: flex; align-items: center; gap: 9px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; color: var(--muted); margin-bottom: 12px; }
.search input { border: none; background: none; outline: none; color: var(--text); font-size: 14px; width: 100%; }

.chips { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  border-radius: 99px; padding: 7px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 32px;
}
.chips button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.field { margin: 12px 0; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 13.5px; outline: none; background: var(--panel2); color: var(--text); resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.field.pick select { margin-bottom: 6px; }

.checkline { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 8px 0; cursor: pointer; color: var(--text); }
.checkline input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.checkline code { font-family: ui-monospace, monospace; font-size: 12px; width: 34px; flex: none; color: var(--muted); }

.setrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.setrow:last-child { border: none; }
.setrow .val { margin-left: auto; color: var(--muted); font-size: 13px; }

.switch {
  margin-left: auto; width: 46px; height: 28px; border-radius: 99px; background: var(--green);
  position: relative; flex: none; cursor: pointer; transition: background .2s; border: none; padding: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: right .18s, left .18s;
}
.switch.off { background: var(--border); }
.switch.off::after { right: auto; left: 3px; }

details.group { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); margin-bottom: 10px; overflow: hidden; box-shadow: var(--shadow); }
details.group summary { padding: 13px 16px; font-size: 13.5px; font-weight: 650; cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
details.group summary::-webkit-details-marker { display: none; }
details.group summary::after { content: '›'; color: var(--muted); transition: transform .2s; font-size: 16px; }
details.group[open] summary::after { transform: rotate(90deg); }
details.group .gbody { padding: 0 16px 14px; }
details.group .field { margin: 8px 0; }
details.group .field label { font-size: 11.5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border: none; }
.kv span { color: var(--muted); }
.kv b { font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.kv b.ok { color: var(--green); }
.kv b.warn { color: var(--amber); }
.kv b.err { color: var(--red); }

pre.pre {
  font-family: ui-monospace, monospace; font-size: 11px; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  overflow-x: auto; color: var(--muted); margin: 0; max-height: 340px; overflow-y: auto;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.log { font-family: ui-monospace, monospace; font-size: 11px; line-height: 1.75; color: var(--muted); max-height: 190px; overflow-y: auto; }
/* pusta karta loga wyglądała na zepsutą — mówi wprost, na co czeka */
.log:empty::before {
  content: "Log pojawi się po uruchomieniu przebiegu.";
  font-family: Inter, "Segoe UI", system-ui, sans-serif; font-size: 13px;
}
.log .ok { color: var(--green); }
.log .warn { color: var(--amber); }
.log .error { color: var(--red); }
.log .stage-line { color: var(--accent); font-weight: 650; }
.log .t { opacity: .7; margin-right: 6px; }

.empty { color: var(--muted); font-size: 13px; padding: 14px 0; }
.count-line { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0; }

/* ==================================================================== */
/* master-detail: panel po prawej (desktop) = pełny ekran (mobile)      */
/* ==================================================================== */
.split { display: block; }
.col-l, .col-r { min-width: 0; }

/* `.sheet` = kolumna, która na wąskim ekranie jest pełnoekranowym detalem.
   Kolumny bez tej klasy (log przebiegu, lista inboxa) zostają w potoku strony,
   bo nie są detalem niczego — mają być widoczne od razu. */
.col-r.sheet {
  position: fixed; inset: 0; z-index: 30;
  background: var(--bg);
  display: none; flex-direction: column;
  padding: 0 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: slidein .24s cubic-bezier(.3, 1, .4, 1);
}
.col-r.sheet.open { display: flex; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.detail-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 0 10px; margin: 0 0 4px;
  background: var(--bg);
}
.detail-head .back {
  display: flex; align-items: center; gap: 6px; background: none; border: none;
  color: var(--accent); font-size: 14px; font-weight: 650; cursor: pointer; padding: 6px 0;
}

.panel-empty {
  background: var(--panel); border: 1px dashed var(--border); border-radius: 14px;
  padding: 48px 24px; text-align: center; color: var(--muted); font-size: 13.5px;
}
.panel-empty .ic { width: 38px; height: 38px; margin-bottom: 10px; opacity: .5; }

/* Nagłówek materiału: pionowa miniatura obok tytułu i metadanych. Materiał
   z TikToka jest w kadrze 9:16, więc miniatura ma ten kształt — poziomy pas
   pokazywał z klatki wąski plaster albo sam czarny letterbox. */
.unit-head { display: flex; gap: 14px; align-items: flex-start; }
.unit-head .thumb {
  width: 104px; aspect-ratio: 9 / 16; flex: none; position: relative;
  border-radius: 12px; overflow: hidden; background: #0b0d11;
  display: grid; place-items: center;
}
.unit-head .thumb img { width: 100%; height: 100%; object-fit: cover; }
.unit-head .head-main { flex: 1; min-width: 0; }
.unit-head .head-main h3.plain { margin-top: 0; }
.unit-head .dur {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .6); color: #fff;
  font-size: 10.5px; font-weight: 650; padding: 2px 7px; border-radius: 6px; white-space: nowrap;
}

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin-bottom: 12px; }
.meta-grid .m { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; }
.meta-grid .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.meta-grid .v { font-size: 13px; font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }

.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.frames img { width: 100%; border-radius: 8px; display: block; background: var(--panel2); }
.frames .meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
img.grid { width: 100%; border-radius: 10px; margin-bottom: 8px; display: block; background: var(--panel2); }
audio { width: 100%; }

.tag {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 650; padding: 3px 10px; border-radius: 99px; margin: 0 6px 6px 0;
  cursor: pointer; border: none; overflow-wrap: anywhere;
}
.tag.green, .tag.ok { background: var(--green-soft); color: var(--green); }
.tag.amber, .tag.warn { background: var(--amber-soft); color: var(--amber); }
.tag.red, .tag.err { background: var(--red-soft); color: var(--red); }
.tag.flat { cursor: default; }

/* ==================================================================== */
/* treść notatki i Markdown                                             */
/* ==================================================================== */
.note-body { font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }
.note-body h1, .note-body h2, .note-body h3, .note-body h4 { margin: 16px 0 6px; font-size: 15px; font-weight: 700; }
.note-body h1 { font-size: 18px; }
.note-body h2 { font-size: 16px; }
/* proza dostaje limit długości wiersza — tabele, kod i siatki zostają pełne */
.note-body p { margin: 8px 0; max-width: 80ch; }
.note-body ul, .note-body ol { margin: 6px 0; padding-left: 20px; }
.note-body li { margin: 4px 0; max-width: 80ch; }
.note-body hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.note-body blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.note-body code { font-family: ui-monospace, monospace; font-size: 12.5px; background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }
.note-body pre, .note-body pre.mdcode { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: 12px; }
.note-body pre code { background: none; border: none; padding: 0; }
.note-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.note-body th, .note-body td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; }
.note-body th { background: var(--panel2); font-weight: 650; }
.wikilink { color: var(--accent); font-weight: 600; cursor: pointer; }

/* ==================================================================== */
/* czat                                                                 */
/* ==================================================================== */
#chatView.active { display: flex; flex-direction: column; padding-bottom: 8px; overflow: hidden; }
.chat-split { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.chat-side {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 41; width: 82%; max-width: 320px;
  background: var(--panel); border-right: 1px solid var(--border);
  display: none; flex-direction: column;
  animation: slideleft .24s cubic-bezier(.3, 1, .4, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
}
.chat-side.open { display: flex; }
@keyframes slideleft { from { transform: translateX(-100%); } }
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4); display: none; animation: fadein .2s; }
.drawer-backdrop.open { display: block; }
@keyframes fadein { from { opacity: 0; } }

.chat-side .dhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.chat-side .dhead b { font-size: 14.5px; }
.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item { padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.chat-item:hover, .chat-item.active { background: var(--panel2); }
.chat-item .t { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .m { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-item .del { margin-left: auto; color: var(--muted); background: none; border: none; cursor: pointer; padding: 8px; margin: -4px; flex: none; border-radius: 8px; }
.chat-item .del:hover { color: var(--red); }

.mem-box { border-top: 1px solid var(--border); padding: 12px 14px; max-height: 48%; overflow-y: auto; }
.mem-box h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mem-box textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 12.5px; background: var(--panel2); color: var(--text); resize: vertical; }
.episode { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.episode:last-child { border: none; }
.episode .meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

.chat-main { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }
.chat-top { display: flex; align-items: center; gap: 10px; padding: 2px 0 10px; flex: none; }
/* to nie tytuł, tylko stan wyszukiwarki — ma nie konkurować z wyborem modelu */
.chat-title { font-size: 12.5px; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.model-btn {
  margin-left: auto; display: flex; align-items: center; gap: 7px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px;
  font-size: 12.5px; font-weight: 650; color: var(--text); cursor: pointer; max-width: 46%;
}
.model-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-btn:active { transform: scale(.97); }
.model-btn .ic-xs { color: var(--accent); flex: none; }

#messages { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; padding-bottom: 6px; }
#messages::-webkit-scrollbar { display: none; }

/* `width: fit-content` jest tu istotne: bez niego krótkie pytanie i tak zajmuje
   pełne 84% kolumny, bo blok domyślnie rozpycha się na całą szerokość */
.msg {
  width: fit-content; max-width: 84%; padding: 11px 14px; border-radius: 16px;
  font-size: 14px; line-height: 1.55;
  margin-bottom: 10px; animation: up .2s ease; position: relative; overflow-wrap: anywhere;
}
.msg.user { margin-left: auto; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 5px; padding-right: 34px; min-width: 120px; }
.msg.assistant.err { border-color: var(--red); color: var(--red); }
.msg .sources { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg.md > :first-child { margin-top: 0; }
.msg.md > :last-child { margin-bottom: 0; }

.src-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650;
  padding: 4px 10px; border-radius: 99px; background: var(--green-soft); color: var(--green);
  cursor: pointer; border: none; text-decoration: none; overflow-wrap: anywhere;
}
.src-chip.web { background: var(--accent-soft); color: var(--accent); }
.src-chip.graph { background: var(--amber-soft); color: var(--amber); }
.note-updates { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }

.copy-btn { position: absolute; top: 6px; right: 6px; background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; opacity: .6; }
.copy-btn:hover { opacity: 1; }

.agent-steps { border-left: 2px solid var(--border); padding-left: 10px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.agent-steps div { padding: 2px 0; }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: tp 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tp { 30% { transform: translateY(-4px); } }

.chat-bottom { flex: none; padding-top: 8px; border-top: 1px solid var(--border); position: relative; }
.composer { display: flex; gap: 9px; align-items: flex-end; }
.composer textarea {
  flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 22px;
  padding: 12px 17px; font-size: 14px; outline: none; color: var(--text); resize: none; max-height: 120px;
}
.composer textarea:focus { border-color: var(--accent); }
.send { background: var(--accent); border: none; color: #fff; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; cursor: pointer; }
.send:active { transform: scale(.93); }
.send.stop { background: var(--red); }

.dropup {
  position: absolute; z-index: 36; left: 0; right: 0; bottom: calc(100% + 8px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--sheet-shadow); padding: 8px; display: none;
  animation: du .18s cubic-bezier(.3, 1, .4, 1); transform-origin: bottom left;
  max-height: 60vh; overflow-y: auto;
}
.dropup.open { display: block; }
@keyframes du { from { opacity: 0; transform: scale(.96) translateY(-6px); } to { opacity: 1; transform: none; } }
.dropup .dhead { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; padding: 8px 12px 6px; }
.du-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 11px; cursor: pointer; border: none; background: none; width: 100%; text-align: left; color: var(--text); }
.du-item:hover { background: var(--panel2); }
.du-item .du-name { font-size: 13.5px; font-weight: 650; overflow-wrap: anywhere; }
.du-item .du-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.du-item .check { margin-left: auto; color: var(--accent); opacity: 0; flex: none; }
.du-item.on { background: var(--accent-soft); }
.du-item.on .check { opacity: 1; }
.du-filter { padding: 4px 8px 8px; }
.du-filter input { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 13px; background: var(--panel2); color: var(--text); outline: none; }

/* ==================================================================== */
/* nakładki: toast, login, modal                                        */
/* ==================================================================== */
.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 99px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s;
  z-index: 60; max-width: 86%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); color: #fff; }

.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: none; align-items: center; justify-content: center; padding: 24px; }
.login.active { display: flex; }
.login .box { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
.login .mark { width: 52px; height: 52px; border-radius: 15px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 800; margin: 0 auto 14px; }
.login h1 { margin: 0 0 4px; font-size: 19px; }
.login p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login input { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; font-size: 14px; background: var(--panel2); color: var(--text); outline: none; margin-bottom: 12px; text-align: center; }
.login .err { color: var(--red); font-size: 12px; min-height: 16px; margin-top: 8px; }

.modal { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .45); display: none; align-items: center; justify-content: center; padding: 24px; animation: fadein .15s; }
.modal.open { display: flex; }
.modal .box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: var(--sheet-shadow); }
.modal h4 { margin: 0 0 8px; font-size: 15px; }
.modal p { margin: 0 0 16px; font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }

/* ==================================================================== */
/* dolna nawigacja (mobile)                                             */
/* ==================================================================== */
.navwrap {
  flex: none; position: relative; background: var(--nav-bg); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); transition: background .25s; z-index: 20;
}
.navwrap nav { display: flex; padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); }
.navwrap nav button {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 650; padding: 6px 0 2px; cursor: pointer; min-height: 48px; justify-content: center;
}
.navwrap nav button.on { color: var(--accent); }
.navwrap nav button .ic { transition: transform .2s cubic-bezier(.34, 1.56, .64, 1); }
.navwrap nav button.on .ic { transform: translateY(-1px) scale(1.12); }
.navwrap .fab .fab-ic {
  width: 38px; height: 28px; border-radius: 10px; background: var(--accent);
  display: grid; place-items: center; box-shadow: 0 3px 10px rgba(62, 99, 221, .35); transition: transform .15s;
}
.navwrap .fab:active .fab-ic { transform: scale(.92); }
.navwrap .fab.on .fab-ic { transform: scale(1.08); }

/* ==================================================================== */
/* >= 900 px: sidebar + master-detail                                   */
/* ==================================================================== */
@media (min-width: 900px) {
  body { flex-direction: row; }
  #app { flex-direction: row; }
  .navwrap { display: none; }

  .sidebar {
    width: 240px; flex: none; display: flex; flex-direction: column;
    background: var(--panel); border-right: 1px solid var(--border);
    transition: width .2s, background .25s, border-color .25s;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 18px 16px 14px; }
  .sidebar .brand .mark { width: 36px; height: 36px; border-radius: 11px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 800; flex: none; }
  .sidebar .brand .bt { line-height: 1.2; min-width: 0; }
  .sidebar .brand .bt b { font-size: 14.5px; display: block; white-space: nowrap; }
  .sidebar .brand .bt span { font-size: 11px; color: var(--muted); white-space: nowrap; }
  .sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; overflow-y: auto; }
  .sidebar nav button {
    display: flex; align-items: center; gap: 11px; background: none; border: none; color: var(--muted);
    font-size: 13.5px; font-weight: 600; padding: 10px 12px; border-radius: 10px; cursor: pointer;
    text-align: left; position: relative; transition: background .15s, color .15s; white-space: nowrap;
  }
  .sidebar nav button:hover { background: var(--panel2); color: var(--text); }
  .sidebar nav button.on { color: var(--accent); background: var(--accent-soft); }
  .sidebar nav button.on::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
  .sidebar nav button .ic { flex: none; }
  .sidebar nav .lbl { overflow: hidden; text-overflow: ellipsis; }
  .sidebar .upload-cta {
    margin: 4px 10px 10px; display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--accent); color: #fff; border: none; border-radius: 11px; padding: 11px;
    font-size: 13.5px; font-weight: 650; cursor: pointer; box-shadow: 0 3px 10px rgba(62, 99, 221, .3);
    transition: transform .12s; white-space: nowrap;
  }
  .sidebar .upload-cta:active { transform: scale(.98); }
  .sidebar .sfoot { border-top: 1px solid var(--border); padding: 10px; }
  /* Stopka sidebara na siatce, nie na zawijanym flexie: przy 240 px pigułka
     statusu i trzy ikony nie mieściły się w jednym rzędzie i logout spadał
     na drugą linijkę, rozjeżdżając całą stopkę. */
  .sidebar .sfoot .chrome {
    margin-left: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; flex-wrap: nowrap;
  }
  .sidebar .sfoot .chrome .status-pill { grid-column: 1 / -1; min-width: 0; }
  .sidebar .sfoot .chrome .status-pill .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .sfoot .chrome .icon-btn { justify-self: center; }

  body.sb-collapsed .sidebar { width: 64px; }
  body.sb-collapsed .sidebar .sfoot .chrome { grid-template-columns: 1fr; justify-items: center; }
  body.sb-collapsed .sidebar .status-pill { justify-content: center; padding: 6px 10px; }
  body.sb-collapsed .sidebar .bt,
  body.sb-collapsed .sidebar nav .lbl,
  body.sb-collapsed .sidebar .upload-cta .lbl,
  body.sb-collapsed .sidebar .sfoot .lbl { display: none; }
  body.sb-collapsed .sidebar .brand { justify-content: center; padding: 18px 0 14px; }
  body.sb-collapsed .sidebar nav button { justify-content: center; padding: 10px 0; }
  body.sb-collapsed .sidebar .upload-cta { padding: 11px 0; }
  body.sb-collapsed .sidebar .status-pill .lbl { display: none; }

  header { padding: 14px 22px 10px; }
  header .t { font-size: 19px; }
  .counters { padding: 0 22px 10px; overflow: visible; flex-wrap: wrap; }

  .view { padding: 6px 22px 24px; }

  /* detal wraca na swoje miejsce: kolumna obok listy, nie nakładka */
  /* `minmax(0, 1fr)`, nie `1fr`: ścieżka `1fr` nie schodzi poniżej min-content,
     a długi JSON encji albo szeroka tabela rozpychały wtedy całą stronę */
  .split { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .log { min-height: 140px; }
  #model-fields input[data-setting] { font-family: ui-monospace, monospace; font-size: 12.5px; }
  .col-r.sheet {
    position: sticky; top: 0; inset: auto; z-index: 1;
    display: block; background: none; padding: 0;
    max-height: calc(100vh - 110px); overflow-y: auto; animation: none;
  }
  .detail-head { display: none; }

  .chat-split { flex-direction: row; display: flex; gap: 18px; }
  .chat-side {
    position: static; display: flex; width: 280px; max-width: none; flex: none;
    border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
    animation: none;
  }
  .drawer-backdrop, #chatDrawerOpen, #chat-drawer-close { display: none !important; }
  .msg { max-width: 78%; }
  .dropup { left: auto; right: 0; width: 380px; transform-origin: bottom right; }

  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; align-items: start; }
  .stat-grid { max-width: 520px; }
  .log { max-height: 300px; }
  .toast { bottom: 28px; }
}

/* Okno na pół ekranu (~960 px): sidebar schodzi do ikon — JS ustawia klasę
   `sb-collapsed` automatycznie w tym zakresie, chyba że sam go rozwiniesz.
   Odzyskane 176 px idzie w całości na kolumnę detalu, która bez tego miała
   ~320 px i była nie do czytania. */
@media (min-width: 900px) and (max-width: 1180px) {
  .split { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); gap: 14px; }
  .chat-side { width: 240px; }
  .grid2 { grid-template-columns: 1fr; }
  header { padding: 14px 16px 10px; }
  .counters { padding: 0 16px 10px; }
  .view { padding: 6px 16px 24px; }
}

/* Tuż nad progiem zwijania sidebar wraca z etykietami i zabiera 176 px. Gdyby
   lista trzymała tu swoje 400 px, detal skurczyłby się z 750 do 479 px przy
   poszerzeniu okna o jeden piksel — dlatego w tym pasie lista jest węższa. */
@media (min-width: 1181px) and (max-width: 1400px) {
  .split { grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); }
}

@media (min-width: 1500px) {
  .split { grid-template-columns: minmax(360px, 460px) minmax(0, 1fr); }
}

/* Ultrawide: treść przestaje się rozciągać w nieskończoność i zostaje wyśrodkowana. */
@media (min-width: 1900px) {
  .split, .grid2 { max-width: 1700px; margin-inline: auto; }
}
