:root {
  --bg: #1e1f22;
  --panel: #2b2d31;
  --panel-2: #313338;
  --line: #3f4147;
  --text: #f2f3f5;
  --muted: #a5a9b1;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --live: #ed4245;
  --ok: #23a55a;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:hover { background: #3a3c42; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); }
button.danger { background: var(--live); border-color: var(--live); }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 4px 8px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
label.check { flex-direction: row; align-items: center; text-transform: none; font-size: 14px; color: var(--text); }
label.check input { width: auto; }
.card { background: var(--panel); border-radius: 14px; padding: 24px; box-shadow: 0 10px 40px #0006; }

/* Dołączanie */
.join { height: 100%; display: grid; place-items: center; padding: 16px; }
.join .card { width: min(380px, 100%); }
.join h1 { margin: 0 0 4px; font-size: 26px; }
.join button { width: 100%; margin-top: 8px; padding: 10px; }

/* Układ */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.sidebar { background: var(--panel); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid #0003; }
.room-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; border-bottom: 1px solid #0003; }
.room-name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { padding: 14px 14px 6px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.members { list-style: none; margin: 0; padding: 0 8px; }
.members li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; }
.members li:hover { background: var(--panel-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.members .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-live { background: var(--live); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }

.chat-log { flex: 1; overflow-y: auto; padding: 0 14px; min-height: 80px; }
.chat-log .msg { margin: 6px 0; word-wrap: break-word; }
.chat-log .msg b { color: #c9cdfb; }
.chat-log .sys { color: var(--muted); font-size: 12px; font-style: italic; }
.chat-form { padding: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #111214; }
.stage {
  flex: 1; min-height: 0; padding: 12px; display: grid; gap: 12px;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-auto-rows: 1fr;
}
/* Układ "Główny": duży stream + kolumna z resztą (z prawej lub lewej) */
.stage.spotlight { grid-template-columns: minmax(0, 1fr) clamp(180px, 22%, 420px); grid-template-rows: minmax(0, 1fr); grid-auto-rows: auto; }
.stage.spotlight.side-left { grid-template-columns: clamp(180px, 22%, 420px) minmax(0, 1fr); }
.stage.spotlight.side-left .side { order: -1; }
.side { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; }
.side .tile { flex: none; aspect-ratio: 16 / 9; cursor: pointer; }
.side .tile:hover { outline: 2px solid #ffffff55; outline-offset: -2px; }
.side .tile .tile-bar, .side .tile .stats, .side .tile .paused-msg button, .side .tile .popped-msg .row { display: none; }
.tile .fkey { background: #ffffff22; border-radius: 4px; padding: 0 5px; font: 11px Consolas, monospace; }
.tile .fkey:empty { display: none; }
.empty { grid-column: 1 / -1; display: grid; place-content: center; text-align: center; gap: 6px; color: var(--text); }
.empty-icon { font-size: 48px; }

.tile { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile.paused video { opacity: .15; }
.tile .label {
  position: absolute; left: 10px; bottom: 10px; background: #000a; padding: 3px 8px;
  border-radius: 6px; font-weight: 600; display: flex; gap: 6px; align-items: center;
}
.tile .stats {
  position: absolute; left: 10px; top: 10px; background: #000a; padding: 3px 8px; border-radius: 6px;
  font: 12px/1.4 Consolas, monospace; color: #d6d9de; pointer-events: none;
}
.tile .tile-bar {
  position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-bar { opacity: 1; }
.tile .tile-bar button { background: #000b; border: none; padding: 6px 9px; }
.tile .tile-bar input[type=range] { width: 90px; padding: 0; }
.tile .vol { display: flex; align-items: center; gap: 4px; background: #000b; border-radius: 8px; padding: 0 8px; }
.tile .paused-msg {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center;
}
.tile.self { outline: 2px solid var(--accent); outline-offset: -2px; }

.controls {
  display: flex; justify-content: center; gap: 10px; padding: 12px; background: var(--panel);
  flex-wrap: wrap;
}
.ctrl { padding: 10px 16px; border-radius: 24px; }
.ctrl.on { background: var(--ok); border-color: var(--ok); }
.ctrl.off { background: #4e5058; }
.ctrl.live { background: var(--live); border-color: var(--live); }

/* Modal */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; padding: 16px; z-index: 10; }
.settings-card { width: min(440px, 100%); max-height: 90vh; overflow-y: auto; }
.settings-card h2 { margin: 0 0 4px; }
.row-end { display: flex; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #000d; padding: 10px 16px; border-radius: 8px; z-index: 20;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 34vh; }
  .ctrl span { display: none; }
  .stage.spotlight, .stage.spotlight.side-left { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .stage.spotlight .side { flex-direction: row; overflow-x: auto; order: 0; }
  .side .tile { width: 160px; }
}

/* --- v2: głos, zakładki, błędy --- */
.error { background: #ed42452b; border: 1px solid var(--live); color: #ffb3b5; padding: 8px 10px; border-radius: 8px; margin-top: 8px; }
.conn { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.conn.bad { color: #ffb3b5; }
.members li { flex-wrap: wrap; }
.members .icons { display: flex; gap: 4px; align-items: center; }
.members .pvol { display: none; width: 100%; align-items: center; gap: 6px; padding: 4px 0 2px 36px; font-size: 12px; color: var(--muted); }
.members li:hover .pvol, .members li.open .pvol { display: flex; }
.members .pvol input { padding: 0; }
.members li.speaking .avatar { box-shadow: 0 0 0 2px var(--ok); }
.tile.speaking { outline: 3px solid var(--ok); outline-offset: -3px; }
.tile .quality { background: #000b; border: none; border-radius: 8px; padding: 4px 6px; width: auto; font-size: 12px; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { background: transparent; border-color: transparent; }
.tab.active { background: var(--panel-2); border-color: var(--line); }
.sep { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.key-btn { font-family: Consolas, monospace; min-width: 120px; text-align: center; align-self: flex-start; }
.key-btn.waiting { outline: 2px solid var(--accent); }
.ctrl.deaf { background: var(--live); border-color: var(--live); }
.ctrl.ptt { background: #4e5058; }
.ctrl.ptt.talking { background: var(--ok); border-color: var(--ok); }

/* --- osobne okna --- */
.tile.popped video, .tile.popped .stats { visibility: hidden; }
.tile .popped-msg { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; }
.tile .popped-msg .row { display: flex; gap: 8px; justify-content: center; }

/* --- czat z historią i przypiętymi --- */
.chat-head { display: flex; align-items: center; justify-content: space-between; padding-right: 8px; }
.pins-btn { font-size: 12px; color: var(--muted); padding: 2px 8px; text-transform: none; letter-spacing: 0; }
.pins-btn.has-pins { color: var(--text); }
.pins-panel { margin: 0 8px 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 40vh; overflow-y: auto; }
.pins-title { font-weight: 700; font-size: 12px; margin-bottom: 6px; }
.pin { padding: 6px; border-radius: 6px; background: var(--panel); margin-bottom: 6px; }
.pin-meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; margin-top: 4px; }
button.link { background: none; border: none; padding: 0; color: #00a8fc; font-size: 11px; }
button.link:hover { background: none; text-decoration: underline; }
.chat-log .msg { position: relative; margin: 2px -6px; padding: 4px 6px; border-radius: 6px; }
.chat-log .msg:hover { background: #0000001f; }
.chat-log .msg.pinned { border-left: 2px solid #f0b232; padding-left: 8px; }
.chat-log .msg.flash { background: #f0b23233; transition: background .3s; }
.msg-head { display: flex; gap: 8px; align-items: baseline; }
.msg-head b { font-weight: 600; }
.msg-head time { font-size: 11px; color: var(--muted); }
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-text a { color: #00a8fc; }
.msg-pin { position: absolute; right: 4px; top: 2px; display: none; padding: 2px 6px; font-size: 12px; background: var(--panel-2); }
.chat-log .msg:hover .msg-pin { display: block; }
.chat-log .msg.pinned .msg-pin { display: block; opacity: .55; }

/* --- jak w Discordzie: połączenie głosowe + panel użytkownika --- */
.voice-panel { border-top: 1px solid #0003; background: #232428; padding: 6px 8px 4px; }
.vp-status { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; padding: 4px 6px; text-align: left; border-radius: 6px; }
.vp-status:hover { background: #ffffff0d; }
.vp-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.vp-title { font-weight: 700; font-size: 13px; }
.vp-title.ok { color: #23a55a; }
.vp-title.warn { color: #f0b232; }
.vp-title.bad { color: #f23f43; }
.vp-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp-ping { font: 12px Consolas, monospace; color: var(--muted); }
.bars { display: inline-flex; flex: none; }
.bars rect { fill: #4e5058; }
.bars.q-good rect { fill: #23a55a; }
.bars.q-mid .b1, .bars.q-mid .b2 { fill: #f0b232; }
.bars.q-bad .b1 { fill: #f23f43; }
.bars.mini svg { width: 12px; height: 12px; }
.conn-details { margin: 4px 6px 6px; padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 12px; }
.cd-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; color: var(--muted); }
.cd-row b { color: var(--text); font-weight: 600; }
.cd-note { margin-top: 6px; color: #f0b232; }
.user-panel { display: flex; align-items: center; gap: 4px; padding: 8px; background: #232428; }
.user-panel .avatar { width: 32px; height: 32px; }
.up-text { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-left: 4px; }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-status { font-size: 12px; color: var(--muted); }
.icon-btn { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; background: none; border: none; border-radius: 6px; color: #b5bac1; }
.icon-btn:hover { background: #ffffff14; color: var(--text); }
.icon-btn .slash { stroke: transparent; }
.icon-btn.muted { color: #f23f43; }
.icon-btn.muted .slash { stroke: #f23f43; }
.members .ico-off { color: #f23f43; flex: none; }

/* --- lista osób: główny stream, F-klawisze, nieoglądany --- */
.members li.streaming { cursor: pointer; }
.members li.is-main { background: #5865f22e; box-shadow: inset 3px 0 0 var(--accent); }
.members li.is-main .nm { font-weight: 700; }
.members .fkey { background: #ffffff1f; border-radius: 4px; padding: 0 5px; font: 11px Consolas, monospace; color: var(--text); }
.members li.is-main .fkey { background: var(--accent); }
.members .ico-eye { color: var(--muted); flex: none; }

/* --- siatka z dwoma streamami: przeciągany podział --- */
.stage.split-row, .stage.split-col { gap: 0; }
.splitter { background: transparent; position: relative; z-index: 2; touch-action: none; }
.split-row .splitter { cursor: col-resize; }
.split-col .splitter { cursor: row-resize; }
.splitter::after { content: ''; position: absolute; border-radius: 2px; background: #ffffff22; transition: background .15s; }
.split-row .splitter::after { left: 3px; width: 2px; top: 20%; bottom: 20%; }
.split-col .splitter::after { top: 3px; height: 2px; left: 20%; right: 20%; }
.splitter:hover::after, .splitter:active::after { background: var(--accent); }

/* --- jeden pokój, pasek udostępniania, AFK --- */
.join-room { margin: 12px 0 0; color: var(--muted); }
.join-room b { color: var(--text); }
.share-bar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: #ed42451f; border-bottom: 1px solid #ed424566; }
.share-thumb { width: 96px; height: 54px; object-fit: contain; background: #000; border-radius: 4px; cursor: pointer; flex: none; }
.share-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--live); margin-right: 8px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.afk-btn.active { color: #f0b232; background: #f0b2321f; }
.members li.afk .nm, .members li.afk .avatar { opacity: .55; }
.members .ico-afk { color: #f0b232; flex: none; }
.up-status, .up-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- tryb tylko streamowanie --- */
body.no-voice .voice-only { display: none !important; }
body:not(.no-voice) .no-voice-only { display: none !important; }

/* --- "Udostępniasz" pod stanem połączenia (nie zasłania streamów) --- */
.share-status { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px; padding: 6px; border-radius: 8px; background: #ed42451a; border: 1px solid #ed424555; }
.share-status .share-thumb { width: 64px; height: 36px; }
.ss-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ss-title { font-weight: 700; font-size: 12px; color: #ffb3b5; display: flex; align-items: center; }
.ss-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-status .icon-btn { width: 28px; height: 28px; font-size: 14px; }
.share-status .icon-btn.active { background: #ffffff1a; color: var(--text); }
.share-status .ss-stop:hover { background: var(--live); color: #fff; }

/* --- czat: akcje, usuwanie --- */
.msg-actions { position: absolute; right: 4px; top: 2px; display: none; gap: 2px; }
.msg-actions .msg-pin, .msg-actions .msg-del { position: static; display: block; padding: 2px 6px; font-size: 12px; background: var(--panel-2); }
.msg-del:hover { background: var(--live) !important; }
.chat-log .msg:hover .msg-actions { display: flex; }
.chat-log .msg.pinned .msg-actions { display: flex; }
.chat-log .msg.pinned:not(:hover) .msg-del { display: none; }
.chat-log .msg.pinned:not(:hover) .msg-pin { opacity: .55; }

/* --- nazwa kanału --- */
.room-head { gap: 2px; }
.room-name { flex: 1; min-width: 0; }
.rename-input { font-size: 15px; font-weight: 600; padding: 2px 6px; width: calc(100% - 16px); }

/* --- wyciszony stream --- */
.tile .vol .smute { background: none; border: none; padding: 2px; font-size: 14px; }
.tile.stream-muted .label::after { content: '🔇'; }

/* --- zwinięty panel (F8): wąski pasek z avatarami, klawiszami F i przyciskami --- */
.app.collapsed { grid-template-columns: 76px 1fr; }
.app.collapsed .room-name, .app.collapsed #renameBtn, .app.collapsed #copyLink,
.app.collapsed .section-title, .app.collapsed .pins-panel, .app.collapsed .chat-log, .app.collapsed .chat-form,
.app.collapsed .members .nm, .app.collapsed .members .pvol, .app.collapsed .vp-text, .app.collapsed .conn-details,
.app.collapsed .ss-text, .app.collapsed .up-text, .app.collapsed .user-panel .avatar, .app.collapsed .members .bars { display: none !important; }
.app.collapsed .room-head { justify-content: center; padding: 10px 4px; }
.app.collapsed .members { flex: 1; overflow-y: auto; padding: 6px 4px; }
.app.collapsed .members li { flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; flex-wrap: nowrap; }
.app.collapsed .members .avatar { width: 36px; height: 36px; }
.app.collapsed .members .icons { flex-wrap: wrap; justify-content: center; gap: 2px; }
.app.collapsed .members .badge-live { font-size: 0; width: 8px; height: 8px; padding: 0; border-radius: 50%; }
.app.collapsed .members .fkey { font-size: 12px; padding: 1px 6px; }
.app.collapsed .voice-panel { padding: 6px 4px; }
.app.collapsed .vp-status { flex-direction: column; gap: 2px; padding: 4px 0; align-items: center; }
.app.collapsed .share-status { flex-direction: column; padding: 4px; }
.app.collapsed .user-panel { flex-direction: column; padding: 6px 4px; }

/* --- logowanie: zapamiętaj kod --- */
label.check.remember { margin-top: 0; font-size: 13px; color: var(--muted); }

/* --- aplikacja desktopowa --- */
body:not(.is-desktop) .desktop-only { display: none !important; }
body.is-desktop .web-only { display: none !important; }
a.button { display: inline-block; text-decoration: none; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
a.button.primary { background: var(--accent); border-color: var(--accent); }
a.button.disabled { opacity: .45; pointer-events: none; }
.desktop-features, .desktop-steps { padding-left: 20px; line-height: 1.6; }
.desktop-steps li { margin-bottom: 10px; }
