:root {
  --bg-rail: #0e0f11;
  --bg-sidebar: #16171a;
  --bg-main: #1e1f23;
  --bg-elev: #26272c;
  --bg-input: #121316;
  --bg-hover: #2e3036;
  --border: #2a2c31;
  --text-1: #f2f3f5;
  --text-2: #b5bac1;
  --text-3: #7e838c;
  --brand: #00e08a;
  --brand-hover: #00c47a;
  --brand-dim: #00e08a22;
  --brand-line: #00e08a40;
  --on-brand: #04140d;
  --danger: #f23f43;
  --danger-hover: #d8343a;
  --danger-dim: #f23f4322;
  --warning: #f0b232;
  --overlay: #000000b3;
  --scrim: #000000a6;
  --shadow: 0 16px 48px #00000080;
  --radius: 8px;
}
body.light {
  --bg-rail: #e3e5e8;
  --bg-sidebar: #f2f3f5;
  --bg-main: #ffffff;
  --bg-elev: #ebedef;
  --bg-input: #e3e5e8;
  --bg-hover: #dfe1e5;
  --border: #d9dbdf;
  --text-1: #060607;
  --text-2: #4e5058;
  --text-3: #6d6f78;
  --brand: #00a866;
  --brand-hover: #008f57;
  --brand-dim: #00a8661f;
  --brand-line: #00a86659;
  --on-brand: #ffffff;
  --danger: #da373c;
  --danger-hover: #b92e33;
  --danger-dim: #da373c1f;
  --warning: #b7791f;
  --scrim: #00000066;
  --shadow: 0 16px 48px #00000033;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-main);
  color: var(--text-1);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
input { font-family: inherit; }
.hidden { display: none !important; }
.ico { width: 18px; height: 18px; flex-shrink: 0; display: block; }
.ico.sm { width: 14px; height: 14px; }
.ico.lg { width: 20px; height: 20px; }

/* === Entrada === */
#screenJoin {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse 70% 80% at 50% 35%, var(--brand-dim), transparent 70%), var(--bg-rail);
  overflow-y: auto;
}
.join-card {
  width: 100%; max-width: 480px; background: var(--bg-main); border-radius: 12px; padding: 32px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 20px;
}
.join-head { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.logo { display: flex; align-items: center; justify-content: center; background: var(--brand); color: var(--on-brand); flex-shrink: 0; }
.logo-lg { width: 56px; height: 56px; border-radius: 18px; }
.logo-lg .ico { width: 28px; height: 28px; }
.logo-sm { width: 28px; height: 28px; border-radius: 8px; }
.logo-sm .ico { width: 16px; height: 16px; }
.wordmark { font-size: 26px; font-weight: 800; padding-top: 8px; cursor: pointer; user-select: none; }
.wordmark span { color: var(--brand); }
.join-sub { color: var(--text-2); line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 12px; font-weight: 700; letter-spacing: 0.5px; color: var(--text-2); }
.field-label em { font-style: normal; font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.input {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px; border-radius: var(--radius);
  background: var(--bg-input); border: 1px solid transparent; color: var(--text-3); transition: border-color 0.15s;
}
.input:focus-within { border-color: var(--brand); }
.input input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text-1); font-size: 15px; }
.input input::placeholder { color: var(--text-3); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: var(--radius); background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 14px; transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-primary.block { width: 100%; height: 46px; font-size: 15px; }
.btn-ghost { height: 40px; padding: 0 16px; border-radius: var(--radius); font-weight: 600; color: var(--text-1); }
.btn-ghost:hover { text-decoration: underline; }
.btn-danger {
  display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 24px;
  background: var(--danger); color: #fff; font-weight: 600; transition: background 0.15s;
}
.btn-danger:hover { background: var(--danger-hover); }
.error-msg { color: var(--danger); font-size: 13px; }
.join-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.conn { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.conn.ok .dot { background: var(--brand); }
.conn.off .dot { background: var(--danger); }
.credits { position: fixed; left: 0; right: 0; bottom: 16px; display: flex; justify-content: center; gap: 16px; font-size: 12px; color: var(--text-3); }
.credits a { color: var(--brand); text-decoration: none; font-weight: 600; }
.credits a:hover { text-decoration: underline; }

/* === Sala === */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr) 340px; height: 100dvh; }
.app.chat-closed { grid-template-columns: 248px minmax(0, 1fr); }
.app.chat-closed .chat { display: none; }
.bar { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.bar-title { font-size: 15px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); position: relative; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-1); }
.icon-btn.off { color: var(--danger); }
.icon-btn .badge-dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: none; }
.icon-btn.has-unread .badge-dot { display: block; }
.only-mobile { display: none; }

/* Sidebar */
.sidebar { background: var(--bg-sidebar); display: flex; flex-direction: column; min-height: 0; }
.side-body { flex: 1; overflow-y: auto; padding: 16px 8px; display: flex; flex-direction: column; gap: 4px; }
.side-label { padding: 12px 8px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.6px; color: var(--text-3); }
.live-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; text-align: left; width: 100%; color: var(--text-3); }
.live-item.on { background: var(--bg-hover); color: var(--text-1); }
.live-item.clickable:hover { background: var(--bg-elev); }
.live-item:disabled { opacity: 1; cursor: default; }
.live-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.live-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-item:not(.on) .live-title { font-weight: 500; }
.live-meta { font-size: 12px; color: var(--text-3); }
.live-badge { padding: 2px 6px; border-radius: 4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; letter-spacing: 0.4px; flex-shrink: 0; }
.user-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; }
.member:hover { background: var(--bg-elev); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0; position: relative; transition: box-shadow 0.12s;
}
[data-uid].speaking .avatar, .avatar.speaking { box-shadow: 0 0 0 2px var(--bg-sidebar), 0 0 0 4px var(--brand); }
.member-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.member-name { color: var(--text-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member.speaking .member-name { color: var(--text-1); }
.member-status { font-size: 11px; font-weight: 500; color: var(--brand); }
.member-status.vote { color: var(--danger); }
.owner-ico { display: inline-flex; vertical-align: -2px; margin-left: 4px; color: var(--warning); }
.member .state { color: var(--danger); }
.member .icon-btn { width: 28px; height: 28px; color: var(--text-3); }
.member .icon-btn.off { color: var(--danger); }
.voice-status { padding: 10px 12px; background: var(--bg-rail); border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.voice-status .conn { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; flex-direction: column; align-items: flex-start; gap: 1px; color: var(--text-2); }
.voice-status .conn.ok { color: var(--brand); }
.voice-status .conn.off { color: var(--warning); }
.voice-status .conn small { font-size: 11px; font-weight: 400; color: var(--text-3); }
.me-panel { height: 56px; padding: 0 8px; background: var(--bg-rail); display: flex; align-items: center; gap: 8px; }
.me-panel .avatar::after {
  content: ''; position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--bg-rail);
}
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.me-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-sub { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Palco */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-main); }
.stage .bar { padding: 0 20px; }
.stage-body { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; justify-content: center; gap: 20px; }
.stage-view { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.viewer-count { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 600; font-size: 13px; }
.sep { width: 1px; height: 20px; background: var(--border); }
/* --cols/--rows vêm do JS; a largura máxima faz todas as linhas (16:10)
   caberem na altura do palco, descontando cabeçalho, CTA e controles. */
.tiles {
  --cols: 1; --rows: 1; --avail-h: calc(100dvh - 270px);
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 16px;
  width: 100%; margin: 0 auto;
  max-width: min(
    calc(var(--cols) * 480px + (var(--cols) - 1) * 16px),
    calc((var(--avail-h) - (var(--rows) - 1) * 16px) / var(--rows) * 1.6 * var(--cols) + (var(--cols) - 1) * 16px)
  );
}
.tile {
  aspect-ratio: 16 / 10; border-radius: 12px; background: var(--bg-elev); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; border: 2px solid transparent; transition: border-color 0.12s; min-width: 0; padding: 8px;
}
.tile.speaking { border-color: var(--brand); }
.tile .avatar { width: 80px; height: 80px; font-size: 26px; }
.tile.speaking .avatar { box-shadow: none; }
.tile-name { display: flex; align-items: center; gap: 6px; font-weight: 600; max-width: 100%; }
.tile-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-name .ico { color: var(--danger); }
/* webcam: o vídeo cobre o tile e o nome vira um selo no canto */
.tile { position: relative; overflow: hidden; }
.tile-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile-video.mirror { transform: scaleX(-1); }
.tile.has-video .avatar { display: none; }
.tile.has-video .tile-name {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px);
  padding: 4px 8px; border-radius: 6px; background: var(--overlay); color: #fff; font-size: 13px;
}
.cta {
  display: flex; align-items: center; gap: 16px; padding: 16px 20px; border-radius: 12px;
  background: var(--brand-dim); border: 1px solid var(--brand-line);
}
.cta-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--brand); color: var(--on-brand); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cta-icon .ico { width: 22px; height: 22px; }
.cta-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cta-title { font-size: 15px; font-weight: 700; }
.cta-sub { font-size: 13px; color: var(--text-2); }
.video-box {
  position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100dvh - 52px - 40px - 68px);
  background: #000; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; margin: 0 auto;
}
.video-box video { width: 100%; height: 100%; object-fit: contain; display: block; }
.video-box:fullscreen { border-radius: 0; max-height: none; }
.placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #9aa0a8; text-align: center; padding: 20px; }
.placeholder button { padding: 8px 14px; border-radius: 6px; background: var(--danger); color: #fff; font-weight: 600; font-size: 13px; }
.chip {
  position: absolute; display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px;
  background: var(--overlay); color: #fff; font-size: 12px; font-weight: 600; pointer-events: none;
}
.chip.tl { top: 16px; left: 16px; }
.chip.tr { top: 16px; right: 16px; }
.chip.bl { bottom: 16px; left: 16px; padding: 6px 10px 6px 6px; }
.chip .dot { background: var(--brand); }
.chip.off .dot { background: var(--danger); }
.chip .avatar { width: 22px; height: 22px; font-size: 9px; }
.chip:empty { display: none; }

/* Controles */
.controls { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctrl {
  width: 48px; height: 48px; border-radius: 24px; background: var(--bg-elev); color: var(--text-1);
  display: inline-flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.ctrl:hover:not(:disabled) { background: var(--bg-hover); }
.ctrl.off { background: var(--danger-dim); color: var(--danger); }
.ctrl.red { background: var(--danger); color: #fff; }
.ctrl.red:hover { background: var(--danger-hover); }
.ctrl .ico { width: 20px; height: 20px; }
.volume { display: inline-flex; align-items: center; gap: 10px; height: 48px; padding: 0 16px; border-radius: 24px; background: var(--bg-elev); }
.volume input { width: 120px; accent-color: var(--brand); }
.volume span { font-size: 12px; font-weight: 600; color: var(--text-2); width: 34px; text-align: right; }
[data-show] { display: none !important; }
.stage[data-mode="idle"] [data-show~="idle"],
.stage[data-mode="viewer"] [data-show~="viewer"],
.stage[data-mode="transmitter"] [data-show~="transmitter"] { display: inline-flex !important; }

/* Chat */
.chat { background: var(--bg-sidebar); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.chat-messages > :first-child { margin-top: auto; }
.msg { display: flex; gap: 12px; }
.msg .avatar { width: 36px; height: 36px; }
.msg-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-name { font-weight: 600; }
.msg-time { font-size: 11px; color: var(--text-3); }
.msg-line { color: var(--text-2); line-height: 1.4; word-break: break-word; }
.sys { display: flex; align-items: flex-start; gap: 10px; padding: 0 4px; font-size: 12px; color: var(--text-3); line-height: 1.4; }
.sys .ico { margin-top: 1px; }
.sys strong { color: var(--text-2); font-weight: 600; }
.sys.error { color: var(--danger); }
.composer { padding: 0 16px 20px; }
.composer .input { padding: 0 8px 0 14px; }
.send-btn { width: 30px; height: 30px; border-radius: 6px; background: var(--brand); color: var(--on-brand); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn .ico { width: 16px; height: 16px; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal { width: 100%; max-width: 520px; border-radius: 12px; background: var(--bg-main); overflow: hidden; box-shadow: var(--shadow); }
.modal-head { display: flex; gap: 12px; padding: 24px 24px 8px; }
.modal-head h2 { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.modal-head p { color: var(--text-2); font-size: 13px; line-height: 1.45; }
.modal-body { padding: 16px 24px 24px; display: flex; flex-direction: column; gap: 12px; }
.res-options { display: flex; gap: 12px; }
.res-option { flex: 1; cursor: pointer; }
.res-option input { position: absolute; opacity: 0; pointer-events: none; }
.res-card {
  height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); transition: border-color 0.15s, background 0.15s;
}
.res-top { display: flex; align-items: center; justify-content: space-between; }
.res-top strong { font-size: 22px; font-weight: 800; }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--text-3); display: flex; align-items: center; justify-content: center; }
.res-desc { font-size: 12px; color: var(--text-2); line-height: 1.4; }
.res-rate { font-size: 12px; font-weight: 700; color: var(--text-3); }
.res-option input:checked + .res-card { background: var(--brand-dim); border: 2px solid var(--brand); padding: 15px; }
.res-option input:checked + .res-card .radio { border-color: var(--brand); }
.res-option input:checked + .res-card .radio::after { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.res-option input:checked + .res-card .res-rate { color: var(--brand); }
.res-option input:focus-visible + .res-card { outline: 2px solid var(--brand); outline-offset: 2px; }
.note { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--bg-input); color: var(--text-3); font-size: 12px; line-height: 1.4; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 16px 24px; background: var(--bg-sidebar); }

.scrim { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 248px minmax(0, 1fr); }
  .chat { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 88vw); z-index: 30; transform: translateX(100%); transition: transform 0.2s; }
  .app.chat-closed .chat { display: flex; }
  .app.chat-open .chat { transform: none; }
  .app.chat-open .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 20; }
}
@media (max-width: 760px) {
  .app, .app.chat-closed { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(280px, 85vw); z-index: 30; transform: translateX(-100%); transition: transform 0.2s; }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 20; }
  .stage .bar { padding: 0 12px; }
  .stage-body { padding: 12px; justify-content: flex-start; }
  .tiles { grid-template-columns: repeat(min(var(--cols), 2), minmax(0, 1fr)); gap: 10px; max-width: none; }
  .tile .avatar { width: 56px; height: 56px; font-size: 18px; }
  .cta { flex-wrap: wrap; }
  .cta .btn-primary { width: 100%; }
  .volume input { width: 80px; }
  .video-box { max-height: none; }
  .res-options { flex-direction: column; }
  .join-card { padding: 24px; }
  .credits { position: static; margin-top: 16px; }
  #screenJoin { flex-direction: column; }
}
