:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --panel-3: #2a3942;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-2: #005c4b;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --danger: #f15c6d;
  --warn: #ffb547;
  --chat-bg: #0b141a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.icon-btn {
  background: transparent; border: 0; border-radius: 50%; width: 40px; height: 40px;
  display: inline-grid; place-items: center; color: var(--muted); font-size: 19px; flex: none;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn.active { color: var(--accent); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input, .field input, .field textarea, .field select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; outline: none;
}
.input:focus, .field input:focus, .field textarea:focus { border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.badge {
  background: var(--accent); color: #111; border-radius: 10px; padding: 0 6px;
  font-size: 11px; font-weight: 700; min-width: 18px; text-align: center; display: inline-block;
}
.badge.red { background: var(--danger); color: #fff; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-3); color: var(--muted); }
.tag.green { background: var(--accent-2); color: #d9fdd3; }
.tag.red { background: #5c1d26; color: #ffb3bd; }
.tag.yellow { background: #5c4310; color: #ffd98a; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px;
  width: min(460px, 100%); max-height: 90vh; overflow: auto;
}
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin: 0 0 12px; font-size: 19px; }
pre.terms {
  white-space: pre-wrap; background: var(--panel-2); border-radius: 8px; padding: 14px;
  max-height: 45vh; overflow: auto; font: 13px/1.5 system-ui, sans-serif;
}

#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: grid; gap: 8px; }
.toast {
  background: var(--panel-2); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 8px;
  max-width: 340px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.toast-error { border-color: var(--danger); }
.toast-warn { border-color: var(--warn); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(var(--accent-2) 0 220px, var(--bg) 220px); }
.auth-card { background: var(--panel); border-radius: 12px; padding: 28px; width: min(420px, 100%);
  box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin: 18px 0; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px; color: var(--muted);
  border-bottom: 3px solid transparent; font-weight: 600; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.err { color: var(--danger); min-height: 20px; font-size: 14px; }

/* ---------- app ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { width: 380px; max-width: 100%; display: flex; flex-direction: column; background: var(--panel);
  border-right: 1px solid var(--border); flex: none; }
.side-head { background: var(--panel-2); padding: 10px 12px; display: flex; align-items: center; gap: 8px; height: 60px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--panel-3); display: grid; place-items: center;
  font-weight: 700; color: #fff; flex: none; position: relative; text-transform: uppercase; }
.avatar.lg { width: 96px; height: 96px; font-size: 36px; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel); }
.side-tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--border); }
.side-tabs button { flex: 1; background: none; border: 0; padding: 12px 4px; color: var(--muted); font-size: 14px;
  border-bottom: 3px solid transparent; }
.side-tabs button.active { color: var(--accent); border-color: var(--accent); }
.search { padding: 8px 12px; }
.list { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 12px; padding: 10px 14px; align-items: center; cursor: pointer; border-bottom: 1px solid #1d2a31; }
.item:hover { background: var(--panel-2); }
.item.active { background: var(--panel-3); }
.item .meta { flex: 1; min-width: 0; }
.item .title { display: flex; justify-content: space-between; gap: 8px; }
.item .title b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; justify-content: space-between; gap: 8px; }
.empty { padding: 30px 20px; text-align: center; color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); position: relative; }
.welcome { flex: 1; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted);
  border-bottom: 6px solid var(--accent); }
.welcome h2 { color: var(--text); font-weight: 300; font-size: 30px; }
.chat-head { background: var(--panel-2); height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 12px; flex: none; }
.chat-head .info { flex: 1; min-width: 0; }
.chat-head .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .info small { color: var(--muted); }
.call-banner { background: var(--accent-2); padding: 8px 14px; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 3px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(255,255,255,.025) 1px, transparent 1px); background-size: 18px 18px; }
.day-note { align-self: center; background: var(--panel-2); color: var(--muted); font-size: 12px; padding: 5px 12px;
  border-radius: 8px; margin: 8px 0; text-align: center; }
.msg { max-width: min(75%, 560px); padding: 6px 9px 8px; border-radius: 8px; background: var(--bubble-in);
  align-self: flex-start; position: relative; word-wrap: break-word; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg .who { font-size: 12.5px; font-weight: 600; color: #53bdeb; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .time { font-size: 11px; color: rgba(233,237,239,.6); float: right; margin: 6px 0 -4px 10px; }
.msg img, .msg video { max-width: 100%; max-height: 340px; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer; }
.msg audio { width: 260px; max-width: 100%; display: block; }
.msg .file { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.15); padding: 8px; border-radius: 6px; }
.msg .actions { position: absolute; top: 2px; right: 2px; display: none; gap: 2px; background: inherit; border-radius: 6px; }
.msg:hover .actions { display: flex; }
.msg .actions button { background: rgba(0,0,0,.25); border: 0; border-radius: 5px; padding: 2px 6px; font-size: 12px; }
.typing { color: var(--accent); font-size: 12px; }

.composer { background: var(--panel-2); padding: 8px 12px; display: flex; gap: 6px; align-items: flex-end; flex: none; }
.composer textarea { flex: 1; resize: none; background: var(--panel-3); border: 0; border-radius: 8px; padding: 10px 12px;
  max-height: 140px; outline: none; }
.blocked-bar { background: #5c1d26; color: #ffd6dc; padding: 12px; text-align: center; font-size: 14px; }
.edit-bar { background: var(--panel-3); padding: 6px 14px; font-size: 13px; display: flex; gap: 8px; align-items: center;
  border-left: 4px solid var(--accent); }
.rec { display: flex; align-items: center; gap: 10px; flex: 1; padding: 10px; color: var(--danger); }
.rec .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

/* ---------- chamada ---------- */
.call { position: fixed; inset: 0; background: #000; z-index: 90; display: flex; flex-direction: column; }
.call.mini { inset: auto 16px 16px auto; width: 320px; height: 220px; border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.call-top { padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,.5); }
.grid { flex: 1; display: grid; gap: 6px; padding: 6px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: minmax(180px, 1fr); overflow: auto; }
.call.mini .grid { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; padding: 2px; gap: 2px; }
/* modo destaque (tela compartilhada ou vídeo escolhido): o destaque ocupa a altura exata da janela,
   os demais ficam numa coluna ao lado (--side = quantos são) */
.grid { min-height: 0; }
.call.featured .grid { grid-template-columns: minmax(0, 1fr) 220px; grid-template-rows: repeat(var(--side, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr); overflow: hidden; }
.call.featured .tile.main { grid-column: 1; grid-row: 1 / -1; }
.call.featured.solo .grid { grid-template-columns: minmax(0, 1fr); }
.tile { position: relative; background: #1b1f22; border-radius: 10px; overflow: hidden; display: grid; place-items: center; min-height: 0; min-width: 0; cursor: pointer; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.main { outline: 2px solid var(--accent); outline-offset: -2px; }
.call.mini.featured .grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.call.mini.featured .tile:not(.main) { display: none; }
.call.featured .tile:not(.main) .avatar.lg { width: 56px; height: 56px; font-size: 22px; }
.tile.screen video, .tile.self.screen video { object-fit: contain; }
.tile.self:not(.screen) video { transform: scaleX(-1); }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 6px; font-size: 13px; }
.tile .avatar { position: absolute; }
.tile .conn { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65); padding: 3px 9px; border-radius: 6px; font-size: 12px; z-index: 1; }
.tile .conn.bad { background: #5c1d26; color: #ffd6dc; }
.tile.speaking { outline: 3px solid var(--accent); }
.call-ctrl { display: flex; justify-content: center; gap: 14px; padding: 14px; background: rgba(0,0,0,.5); }
.call.mini .call-ctrl { padding: 4px; gap: 4px; }
.round { width: 54px; height: 54px; border-radius: 50%; border: 0; background: #3b4a54; display: grid; place-items: center; }
.round svg { width: 24px; height: 24px; fill: #fff; }
.round.off { background: #fff; } .round.off svg { fill: #111; }
.round.on { background: var(--accent); }
.round.hang { background: var(--danger); }
.call.mini .round { width: 36px; height: 36px; } .call.mini .round svg { width: 18px; height: 18px; }
.ring { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 95; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 18px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); }

/* ---------- admin ---------- */
.admin { display: flex; height: 100vh; }
.admin nav { width: 230px; background: var(--panel); border-right: 1px solid var(--border); padding: 12px 0; flex: none; }
.admin nav h1 { font-size: 17px; padding: 6px 18px 16px; margin: 0; }
.admin nav button { display: flex; width: 100%; text-align: left; padding: 11px 18px; background: none; border: 0;
  color: var(--muted); justify-content: space-between; align-items: center; }
.admin nav button.active, .admin nav button:hover { background: var(--panel-2); color: var(--text); }
.admin main { flex: 1; overflow: auto; padding: 22px 28px; }
.admin h2 { margin-top: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:hover td { background: rgba(255,255,255,.02); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat b { display: block; font-size: 26px; }
.word-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.word { background: var(--panel-3); border-radius: 14px; padding: 4px 6px 4px 12px; display: flex; align-items: center; gap: 4px; }
.word button { background: none; border: 0; color: var(--muted); }
.admin-msg { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); margin-bottom: 6px; }
.admin-msg.deleted { border-left: 3px solid var(--danger); }
.admin-msg.flagged { border-left: 3px solid var(--warn); }
.admin-msg img, .admin-msg video { max-width: 320px; max-height: 240px; border-radius: 6px; display: block; margin-top: 4px; }
textarea.terms-edit { width: 100%; min-height: 360px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; font: 14px/1.5 system-ui, sans-serif; }

@media (max-width: 760px) {
  .sidebar { width: 100%; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .main { display: none; }
  .messages { padding: 12px; }
  .chat-head { gap: 4px; padding: 0 4px; }
  .chat-head .avatar { display: none; }
  .chat-head .icon-btn { width: 34px; height: 34px; }
  .chat-head .info small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .msg { max-width: 85%; }
  .admin { flex-direction: column; height: auto; min-height: 100vh; }
  .admin nav { width: 100%; display: flex; overflow-x: auto; padding: 0; }
  .admin nav h1 { display: none; }
  .admin nav button { white-space: nowrap; width: auto; }
  .admin main { padding: 14px; }
  .call.featured .grid { grid-template-columns: repeat(var(--side, 1), minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr) 110px; }
  .call.featured .tile.main { grid-column: 1 / -1; grid-row: 1; }
  .call.featured.solo .grid { grid-template-rows: minmax(0, 1fr); }
}
@media (min-width: 761px) { .only-mobile { display: none !important; } }
