/* ==========================================================
   KCOOE - Wideokonferencja
   ========================================================== */

:root {
  --bg-dark: #0f1015;
  --panel-bg: #1e1e24;
  --red: #d3111b;
  --red-bright: #f51322;
  --red-glow: rgba(211, 17, 27, 0.40);
  --text-main: #ffffff;
  --text-muted: #9ba1a6;
  --chat-received: #2a2a32;
  --green: #00d26a;
  --amber: #f5a524;
  --line: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-dark);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font-family: inherit; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ==========================================================
   STRONA STARTOWA (jasna)
   ========================================================== */

.page-start { background: #fff; color: #111827; min-height: 100vh; display: flex; flex-direction: column; }
.page-start .btn-ghost { background: transparent; color: #111827; border-color: #e5e7eb; }
.page-start .btn-ghost:hover { background: #f9fafb; }
.page-start .foot { border-top: 1px solid #e5e7eb; padding: 26px 0; margin-top: auto; }
.page-start .foot p { margin: 0; font-size: 12px; color: #6b7280; }

.topbar-light {
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  position: sticky; top: 0; z-index: 20;
}
.topbar-light .topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.brand-light { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: var(--red); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; font-weight: 800; }
.brand-text small { font-size: 9px; text-transform: uppercase; letter-spacing: .14em; color: #6b7280; margin-top: 2px; }

.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 11px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; line-height: 1.2;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #b00e16; }
.btn-secondary { background: #111827; color: #fff; }
.btn-secondary:hover { background: #1f2937; }
.btn-block { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.start-main { padding: 56px 20px 72px; text-align: center; }
.start-title { font-size: 40px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 10px; }
.start-sub { color: #6b7280; margin: 0 auto 40px; max-width: 560px; font-size: 15px; line-height: 1.6; }

.cards { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); text-align: left; }
.card { border: 1px solid #e5e7eb; border-radius: 18px; padding: 28px; background: #fff; }
.card h2 { margin: 0 0 6px; font-size: 19px; }
.card-sub { margin: 0 0 22px; font-size: 13px; color: #6b7280; line-height: 1.55; }

label { display: block; font-size: 12px; font-weight: 600; margin: 0 0 6px; }
input { width: 100%; padding: 11px 13px; font-size: 14px; border: 1px solid #e5e7eb; border-radius: 10px; background: #fff; font-family: inherit; }
input:focus { outline: 2px solid rgba(211, 17, 27, .18); border-color: var(--red); }
form label:not(:first-of-type) { margin-top: 16px; }
.hint { font-size: 11px; color: #6b7280; margin: 6px 0 0; }

.link-row { display: flex; gap: 10px; margin-bottom: 14px; }

/* --- rozdzielenie ról --- */
.card-organizer { border-top: 3px solid var(--red); }
.role-tag {
  display: inline-block; margin-bottom: 10px; padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: var(--red); color: #fff;
}
.role-tag-guest { background: #4b5563; }

/* --- lista "Moje pokoje" --- */
.my-rooms { margin: 0 auto 36px; max-width: 760px; text-align: left; }
.my-rooms-title { margin: 0 0 4px; font-size: 17px; }
.my-rooms-sub { margin: 0 0 14px; font-size: 12px; color: #6b7280; }
.myrooms-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.myrooms-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff;
}
.myrooms-item.is-expired { border-color: #fde68a; background: #fffbeb; }
.myrooms-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.myrooms-meta { font-size: 11px; color: #6b7280; margin-left: auto; text-align: right; flex: 0 0 auto; }
.myrooms-item .btn-sm { padding: 8px 14px; font-size: 13px; flex: 0 0 auto; }
.myrooms-remove {
  background: none; border: 0; color: #9ca3af; font-size: 20px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex: 0 0 auto;
}
.myrooms-remove:hover { color: var(--red); }

@media (max-width: 520px) {
  .myrooms-item { flex-wrap: wrap; }
  .myrooms-meta { margin-left: 0; width: 100%; text-align: left; order: 3; }
}
.error { margin: 24px auto 0; max-width: 620px; padding: 13px 16px; border-radius: 10px; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; font-size: 13px; text-align: left; }

/* ==========================================================
   POKOJ
   ========================================================== */

.page-room {
  height: 100vh; overflow: hidden;
  background-color: var(--bg-dark);
  background-image: radial-gradient(circle at 50% 50%, #1a1a24 0%, #0f1015 100%);
  display: flex; flex-direction: column;
}
html { height: 100%; }

.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 30px; height: 70px; flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; font-weight: bold; letter-spacing: 1px; }
.brand .logo-mark { color: var(--red); font-size: 24px; }
.brand .logo-sep { width: 1px; height: 22px; background: rgba(255,255,255,.16); }

.room-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 20px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-chip b { color: var(--text-main); font-weight: 600; }

.status-indicator { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; }
.status-dot { width: 8px; height: 8px; background: var(--amber); border-radius: 50%; box-shadow: 0 0 8px var(--amber); flex: 0 0 auto; }
.status-indicator.ok .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-indicator.bad .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

.main-container { display: flex; flex: 1; padding: 0 30px 30px; gap: 25px; min-height: 0; }

.video-section { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }

.video-grid {
  flex: 1; min-height: 0;
  display: grid; gap: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: rgba(20, 20, 25, .6);
  border: 1px solid rgba(211, 17, 27, .2);
  border-radius: 16px; padding: 20px;
  box-shadow: 0 0 30px var(--red-glow);
  overflow-y: auto;
}
/* dwoje: wasz widok wokol, rozmowca na duzym polu */
.video-grid[data-count="2"] { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.video-grid[data-count="1"] { grid-template-columns: minmax(0, 1fr); }
.video-grid[data-count="5"], .video-grid[data-count="6"],
.video-grid[data-count="7"], .video-grid[data-count="8"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* przy duzej liczbie osób kafelki mniejsze */
.video-grid.many { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }

.video-wrapper {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  min-height: 0; aspect-ratio: 16 / 9;
}
/* Przy jednej, dwóch lub trzech osobach kafelki rozciągają się na
   cala wysokosc okna - dopiero przy wiekszej liczbie osob siatka
   przelicza kafelki w wielokrot wierszy z zachowaniem proporcji 16:9. */
.video-grid[data-count="1"] .video-wrapper,
.video-grid[data-count="2"] .video-wrapper,
.video-grid[data-count="3"] .video-wrapper {
  height: 100%;
  aspect-ratio: auto;
  min-height: 0;
}
.video-wrapper video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-wrapper.is-screen video { object-fit: contain; background: #000; }
.video-wrapper.is-screen { grid-column: 1 / -1; }

.video-label {
  position: absolute; bottom: 15px; left: 15px;
  background: rgba(0, 0, 0, .6); padding: 6px 12px; border-radius: 6px;
  font-size: 13px; backdrop-filter: blur(4px); max-width: calc(100% - 30px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.video-label .role-badge {
  background: var(--red); color: #fff; font-size: 9px; text-transform: uppercase;
  letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; margin-right: 7px;
}

.camera-off-icon {
  font-size: 40px; color: var(--text-muted);
  background: rgba(255, 255, 255, .1); width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.camera-off-icon .initials { font-size: 30px; font-weight: 700; color: var(--text-muted); }

.tile-muted { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.tile-muted span {
  background: rgba(0,0,0,.6); border-radius: 6px; padding: 5px 7px;
  display: flex; align-items: center; color: #fca5a5;
}

/* --- Pasek kontrolny --- */

.controls-bar {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 30, 36, .85); backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .1);
  padding: 12px 24px; border-radius: 50px;
  display: flex; gap: 15px; align-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); z-index: 5;
}

.btn-icon {
  width: 45px; height: 45px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, .1); color: #fff; cursor: pointer;
  transition: background .2s; display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover:not(:disabled) { background: rgba(255, 255, 255, .2); }
.btn-icon:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon.active-red { background: var(--red); }
.btn-icon.active-red:hover:not(:disabled) { background: #b00e16; }

.btn-end {
  background: var(--red); color: #fff; border: none;
  padding: 0 24px; height: 45px; border-radius: 25px;
  font-weight: 600; font-size: 14px; cursor: pointer; margin-left: 10px;
  transition: background .2s;
}
.btn-end:hover { background: #b00e16; }
.btn-end:disabled { opacity: .5; cursor: not-allowed; }

/* --- Panel boczny (czat + uczestnicy) --- */

.chat-section {
  width: 350px; flex: 0 0 350px;
  background: var(--panel-bg); border-radius: 16px;
  display: flex; flex-direction: column;
  border: 1px solid rgba(255, 255, 255, .05); overflow: hidden; min-height: 0;
}

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.panel-tab {
  flex: 1; padding: 16px 8px; background: transparent; border: 0;
  color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.panel-tab:hover { color: var(--text-main); }
.panel-tab.active { color: var(--text-main); border-bottom-color: var(--red); }

.side-pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.side-pane.active { display: flex; }

.chat-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }

.message { max-width: 82%; padding: 12px 16px; border-radius: 12px; font-size: 13px; line-height: 1.5; position: relative; word-wrap: break-word; }
.msg-received { background: var(--chat-received); align-self: flex-start; border-bottom-left-radius: 4px; margin-left: 35px; }
.msg-sent { background: linear-gradient(135deg, var(--red-bright), var(--red)); align-self: flex-end; border-bottom-right-radius: 4px; box-shadow: 0 4px 15px var(--red-glow); }
.msg-system { align-self: center; background: transparent; color: var(--text-muted); font-size: 11px; text-align: center; max-width: 90%; font-style: italic; }

.msg-avatar {
  position: absolute; left: -35px; bottom: 0; width: 25px; height: 25px;
  border-radius: 50%; background: #444; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--text-muted);
}
.msg-meta { display: block; font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.msg-sent .msg-meta { color: rgba(255, 255, 255, .7); text-align: right; }

.chat-input-area { padding: 15px; background: rgba(0, 0, 0, .2); display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.chat-input-area input { flex: 1; background: transparent; border: none; color: #fff; font-size: 14px; outline: none; padding: 10px; }
.chat-input-area input::placeholder { color: var(--text-muted); }
.chat-action-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; transition: color .2s; }
.chat-action-btn:hover { color: #fff; }
.chat-send-btn { color: var(--red); }
.chat-send-btn:hover { color: var(--red-bright); }
.chat-send-btn:disabled { color: #555; cursor: not-allowed; }

/* --- Lista uczestnikow --- */

.plist { list-style: none; margin: 0; padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.pitem { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; background: #26262e; }
.pitem .av { width: 30px; height: 30px; border-radius: 8px; background: #3a3a44; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.pitem .nm { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pitem .nm small { display: block; color: var(--text-muted); font-size: 10px; }
.pitem .acts { display: flex; gap: 4px; }
.pitem .acts button { background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--text-muted); border-radius: 6px; width: 28px; height: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.pitem .acts button:hover { background: rgba(255,255,255,.14); color: #fff; }
.pitem .acts button.off { color: #fca5a5; }
.pitem .acts button.kick:hover { background: var(--red); border-color: var(--red); color: #fff; }

.empty { color: var(--text-muted); font-size: 12px; text-align: center; padding: 32px 14px; line-height: 1.6; }

.side-toggle { display: none; background: rgba(255,255,255,.08); border: 1px solid var(--line); color: #fff; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; align-items: center; justify-content: center; }

/* --- zapraszanie uczestnikow (tylko organizator) --- */
.invite-wrap { position: relative; }
.btn-invite {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--red); color: #fff; border: 0; cursor: pointer;
  padding: 9px 16px; border-radius: 22px; font-size: 12px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
}
.btn-invite:hover { background: #b00e16; }
.btn-invite:disabled { opacity: .4; cursor: not-allowed; }

.invite-panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 50;
  width: min(330px, 78vw); padding: 16px;
  background: #1e1e24; border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.55);
}
.invite-panel p { margin: 0 0 10px; font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.invite-row { display: flex; gap: 8px; }
.invite-row input {
  flex: 1; min-width: 0; background: #101017; border: 1px solid var(--line);
  color: var(--text-main); font-size: 12px; padding: 9px 11px; border-radius: 8px;
}
.btn-sm { padding: 9px 14px; font-size: 13px; border-radius: 8px; white-space: nowrap; }

/* --- Nakladka --- */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 16, 21, .97);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay-box { text-align: center; max-width: 420px; }
.overlay-box h2 { font-size: 20px; margin: 0 0 8px; }
.overlay-box p { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; line-height: 1.6; }
.overlay-box input { background: #26262e; border-color: var(--line); color: #fff; text-align: left; }
.overlay-box input + input { margin-top: 10px; }

.spinner { width: 34px; height: 34px; margin: 0 auto 18px; border: 3px solid #2a2a32; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .main-container { flex-direction: column; min-height: 0; }
  .video-section { min-height: 0; }

  /* Na waskich ekranach kafelki wracaja do proporcji 16:9
     i ukladaja sie w kolumnie, a pasek sterowania nie zaslania tresci. */
  .video-grid,
  .video-grid[data-count="2"],
  .video-grid[data-count="3"] {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
    align-content: start;
  }
  .video-grid[data-count="1"] .video-wrapper,
  .video-grid[data-count="2"] .video-wrapper,
  .video-grid[data-count="3"] .video-wrapper {
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .controls-bar {
    position: sticky; bottom: 12px; left: auto; transform: none;
    margin: 0 auto; z-index: 6;
  }

  .chat-section { width: 100%; flex: 0 0 auto; height: 46vh; }
}

@media (max-width: 820px) {
  .top-bar { padding: 0 16px; height: 60px; }
  .main-container { padding: 0 12px 16px; gap: 12px; }
  .room-chip { display: none; }
  .status-indicator { font-size: 10px; }
  .side-toggle { display: flex; }
  .chat-section {
    position: fixed; inset: 60px 0 0 auto; width: min(350px, 92vw); z-index: 40;
    height: auto; transform: translateX(100%); transition: transform .2s; border-radius: 0;
  }
  .chat-section.open { transform: translateX(0); }
  .btn-end { padding: 0 16px; font-size: 13px; }
  .controls-bar { gap: 10px; padding: 10px 16px; flex-wrap: wrap; justify-content: center; }
}