/* Base, tipografia e acessibilidade */

:root {
  color-scheme: dark;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  background: #101319;
  color: #f5f7fa;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

:focus-visible {
  outline: 3px solid #8bbcff;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.muted {
  color: #9ca5b4;
}

/* Entrada, formulário e prévia da câmera */

.entry {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.entry-card {
  width: min(100%, 430px);
  padding: 32px;
  background: #1a1f28;
  border: 1px solid #303947;
  border-radius: 22px;
  box-shadow: 0 20px 70px #0005;
}

.brand {
  font-weight: 750;
  letter-spacing: 0.02em;
  font-size: 0.92rem;
  color: #dbe5f3;
}

.brand-mark {
  color: #83b6ff;
  font-size: 1.35rem;
  margin-right: 7px;
  vertical-align: -2px;
}

h1 {
  font-size: 2rem;
  line-height: 1.2;
  margin: 26px 0 8px;
}

.entry p {
  margin: 0 0 24px;
}

.entry form > label {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  margin: 17px 0 8px;
}

input:not([type='checkbox']),
select {
  background: #11161d;
  color: #f5f7fa;
  border: 1px solid #3a4554;
  border-radius: 10px;
  padding: 12px;
  min-height: 44px;
}

input:not([type='checkbox']) {
  width: 100%;
}

input::placeholder {
  color: #8691a1;
}

.preview {
  height: 190px;
  background: #11161d;
  border-radius: 14px;
  overflow: hidden;
  margin-top: 22px;
  position: relative;
  border: 1px solid #303947;
}

.preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #aab4c2;
}

.preview-icon {
  font-size: 2rem;
  color: #6d7c8f;
}

.entry-options {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 22px;
  flex-wrap: wrap;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  margin-right: auto;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: #77aeff;
}

.entry-options select {
  max-width: 160px;
  font-size: 0.84rem;
}

.primary {
  width: 100%;
  min-height: 52px;
  background: #7eb4ff;
  border: 0;
  border-radius: 12px;
  color: #0b1729;
  font-weight: 760;
  font-size: 1.05rem;
}

.primary:hover {
  background: #9ac5ff;
}

.message,
.room-message {
  padding: 12px 15px;
  border-radius: 10px;
  margin: 8px 0 16px;
}

.error,
.room-message {
  background: #44232a;
  color: #ffdfe3;
}

/* Sala: cabeçalho, conexão e área principal */

.room-view {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 88px;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 82px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #27303b;
}

.topbar h1 {
  font-size: 1rem;
  margin: 3px 0 0;
  color: #aab5c5;
  font-weight: 500;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection {
  font-size: 0.85rem;
  color: #cbd5e2;
  white-space: nowrap;
}

.connection::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e0a85f;
  margin-right: 8px;
}

.connection.connected::before {
  background: #54d69b;
}

.connection.offline::before {
  background: #f57983;
}

.quiet {
  min-height: 44px;
  border: 1px solid #354253;
  border-radius: 10px;
  background: #1b222c;
  color: #ecf2fa;
  padding: 0 14px;
}

.quiet:hover {
  background: #273343;
}

.room-message {
  margin: 12px 24px;
}

.stage {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 20px 24px;
  min-height: 0;
  overflow: hidden;
}

.stage.sharing .screen-area {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.stage.sharing .camera-grid {
  width: min(230px, 22vw);
  display: flex;
  flex-direction: column;
  align-content: start;
  flex: 0 0 auto;
  overflow-y: auto;
}

.camera-grid {
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  grid-auto-rows: minmax(180px, 1fr);
  gap: 16px;
  align-content: center;
}

/* Vídeos, avatares e tela compartilhada */

.tile {
  background: #1b222c;
  border: 1px solid #34404d;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  min-height: 160px;
  aspect-ratio: 16/9;
}

.tile video {
  height: 100%;
  width: 100%;
  object-fit: cover;
}

.tile.camera.self video {
  transform: scaleX(-1);
}

.tile.screen video {
  object-fit: contain;
  background: #080a0e;
}

.tile .avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 5rem);
  color: #a7c9ff;
  background: #263749;
}

.tile.has-video .avatar {
  display: none;
}

.tile .caption {
  position: absolute;
  bottom: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  background: #080b11c9;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screen-area .tile {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  min-height: 300px;
}

.fullscreen {
  position: absolute;
  right: 12px;
  top: 12px;
  background: #080b11bd;
  color: #fff;
  border: 1px solid #ffffff55;
  border-radius: 8px;
  min-height: 44px;
  min-width: 44px;
  font-size: 1.3rem;
}

/* Lista de participantes */

.people-panel {
  position: fixed;
  right: 18px;
  top: 74px;
  z-index: 5;
  background: #202833;
  border: 1px solid #3d4b5d;
  border-radius: 14px;
  padding: 18px;
  width: min(320px, calc(100vw - 36px));
  box-shadow: 0 16px 44px #0008;
}

.people-panel h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.people-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.people-panel li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 0;
  color: #dbe4ef;
}

.person-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #34495f;
  color: #b7d6ff;
  flex: none;
  font-weight: 700;
}

.person-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-state {
  font-size: 0.78rem;
  color: #aab7c7;
  white-space: nowrap;
}

/* Controles fixos da sala */

.toolbar {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 88px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #151a22ef;
  border-top: 1px solid #303a47;
  backdrop-filter: blur(10px);
}

.tool {
  border: 1px solid #465366;
  background: #26303d;
  color: #eef4fb;
  border-radius: 12px;
  min-height: 58px;
  min-width: 145px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 650;
}

.tool:hover {
  background: #344253;
}

.tool.active {
  background: #183e35;
  border-color: #4ece9e;
  color: #b9f5da;
}

.tool.leave {
  background: #3c252c;
  border-color: #74414d;
  color: #ffd7dc;
}

.tool-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.share-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-control select {
  font-size: 0.78rem;
  min-height: 44px;
  max-width: 118px;
  padding: 7px;
}

.screen-area:fullscreen .tile {
  height: 100%;
  border: 0;
  border-radius: 0;
}

/* Instalação da PWA */

.install-area {
  margin-top: 18px;
  text-align: center;
}

.install-area p {
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 12px 0 0;
}

/* Adaptação para celular */

@media (max-width: 760px) {
  .room-view {
    padding-bottom: 112px;
  }

  .entry-card {
    padding: 24px;
  }

  .topbar {
    padding: 12px 16px;
    height: auto;
    min-height: 76px;
  }

  .top-actions {
    gap: 6px;
  }

  .top-actions .quiet {
    padding: 0 9px;
    font-size: 0.8rem;
  }

  .connection {
    font-size: 0;
  }

  .connection::before {
    margin: 0;
    width: 12px;
    height: 12px;
  }

  .stage {
    padding: 12px;
    flex-direction: column;
  }

  .stage.sharing .screen-area {
    flex: 1 1 auto;
    height: auto;
  }

  .stage.sharing .camera-grid {
    width: 100%;
    flex-direction: row;
    flex: 0 0 112px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
  }

  .stage.sharing .camera-grid .tile {
    flex: 0 0 160px;
    min-height: 100px;
  }

  .camera-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    grid-auto-rows: auto;
    align-content: start;
  }

  .toolbar {
    padding: 8px;
    gap: 6px;
  }

  .tool {
    min-width: 0;
    flex-direction: column;
    min-height: 64px;
    padding: 7px 9px;
    font-size: 0.72rem;
    gap: 1px;
  }

  .toolbar > .tool {
    flex: 1;
  }

  .share-control {
    flex: 1;
    flex-direction: column;
    gap: 2px;
  }

  .share-control .tool {
    width: 100%;
  }

  .share-control select {
    width: 100%;
    max-width: none;
    min-height: 28px;
    padding: 2px 5px;
    font-size: 0.68rem;
  }

  .tool-icon {
    font-size: 1.25rem;
  }
}
