:root {
  --bg: #0b1220;
  --panel: #111b31;
  --border: #22345d;
  --text: #e7eefc;
  --subtext: #a8b3cf;
  --accent: #2a58ff;
}

body.light {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #d6dbea;
  --text: #1a1f36;
  --subtext: #4a5568;
  --accent: #4f46e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  width: 100%;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex: 0 0 auto;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .2px;
}

.right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 13px;
}

.themeBtn {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.stage {
  flex: 1 1 auto;
  min-height: 0; /* IMPORTANT: allows children to scroll instead of pushing footer off-screen */
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.videoCol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.panelTitle {
  font-size: 13px;
  opacity: .85;
  margin-bottom: 8px;
}

.remoteWrap video {
  width: 100%;
  height: 320px;
  background: #000;
  border-radius: 10px;
  object-fit: cover;
}

.localWrap video {
  width: 100%;
  height: 220px;
  background: #000;
  border-radius: 10px;
  object-fit: cover;
}

.controlsPanel .row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input, button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

button {
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

button[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

.small {
  margin-top: 8px;
  font-size: 13px;
  opacity: .75;
}

/* ---------------- Chat sizing fixes ---------------- */
.chatPanel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;   /* IMPORTANT */
  overflow: hidden;/* prevents chatRow being pushed out */
}

.chatLog {
  flex: 1 1 auto;
  min-height: 0;   /* IMPORTANT */
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.chatRow {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--panel);
  padding-top: 8px;
}

#chatInput {
  flex: 1 1 auto;  /* ✅ makes input wide on desktop */
  min-width: 0;
}

#btnSend {
  flex: 0 0 auto;
}

.msg {
  padding: 6px 8px;
  border-radius: 10px;
  margin: 4px 0;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}

/* ✅ Mobile-only overlay: local video on top-right of remote, chat below */
@media (max-width: 980px) {
  .stage { grid-template-columns: 1fr; }

  /* Make videoCol overlap first two panels */
  .videoCol { display: grid; gap: 12px; }

  .remoteWrap { grid-row: 1; grid-column: 1; }
  .localWrap  {
    grid-row: 1;
    grid-column: 1;
    justify-self: end;
    align-self: start;
    width: 130px;
    padding: 6px;
    margin: 12px;
    border-radius: 12px;
    z-index: 5;
  }
  .localWrap .panelTitle { display: none; }
  .localWrap video {
    width: 100%;
    height: 90px;
    border-radius: 10px;
  }
  .remoteWrap video { height: 360px; }

  /* ✅ Ensure chat input never hides behind browser UI */
  .chatRow { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
