:root {
  --bg: #0c0e12;
  --surface: #141820;
  --surface-2: #1b212c;
  --border: #262e3d;
  --text: #e6ebf2;
  --muted: #8b95a7;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ================= LANDING (STEALTH) ================= */
.landing-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.landing-grid {
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  font-family: inherit;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: #3d485e; }
.btn-danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border-color: rgba(239, 68, 68, 0.38); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #dc2626; }
.btn-success { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.35); }
.btn-success:hover { background: rgba(16, 185, 129, 0.26); }
.btn-warning { background: rgba(245, 158, 11, 0.16); color: #fcd34d; border-color: rgba(245, 158, 11, 0.35); }
.btn-warning:hover { background: rgba(245, 158, 11, 0.26); }
.btn-sm { padding: 7px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.alert-ok {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

/* ================= DASHBOARD / ADMIN ================= */
.dash-wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge-admin {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
}

.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-family: var(--mono); }

.purge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}

th, td {
  text-align: left;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
}

tr:last-child td { border-bottom: none; }

.code-pill {
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 12px;
  letter-spacing: 0.06em;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

/* ================= SALA: CHAT + VÍDEO/VOZ (ZOOM/TEAMS) ================= */
.room-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.room-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.room-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.call-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  background: rgba(16, 185, 129, 0.12);
  border-bottom: 1px solid rgba(16, 185, 129, 0.32);
  color: #a7f3d0;
  font-size: 13px;
  flex-shrink: 0;
}

.room-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Stage de Vídeo (estilo Zoom / Teams) */
.call-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #080a0e;
}

.video-grid {
  flex: 1;
  min-height: 0;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: center;
  justify-content: center;
  overflow-y: auto;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.video-grid.count-1 {
  grid-template-columns: minmax(0, 960px);
}

.video-grid.count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.video-grid.count-3,
.video-grid.count-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.video-grid.count-5,
.video-grid.count-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.video-grid.has-spotlight {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.video-tile {
  position: relative;
  background: #131822;
  border: 1.5px solid #263042;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
  min-height: 150px;
}

.video-tile.spotlight {
  grid-column: 1 / -1;
  aspect-ratio: 16 / 9;
  max-height: 58dvh;
  border-color: var(--accent);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0b0e14;
}

.video-tile.local-mirror video {
  transform: scaleX(-1);
}

.video-tile.video-off video {
  display: none;
}

.avatar-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.avatar-circle {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #1e3a8a);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.tile-overlay {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.tile-name {
  background: rgba(12, 14, 18, 0.78);
  backdrop-filter: blur(6px);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  max-width: 75%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-icons {
  display: flex;
  gap: 5px;
}

.tile-pill {
  background: rgba(12, 14, 18, 0.78);
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11px;
  color: #e6ebf2;
}

.tile-pill.muted {
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
}

/* Barra de Controles de Chamada estilo Zoom/Teams */
.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.ctrl-btn:hover { background: #242c3b; }
.ctrl-btn.off { background: rgba(239, 68, 68, 0.22); border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.ctrl-btn.active { background: rgba(59, 130, 246, 0.22); border-color: var(--accent); color: #93c5fd; }
.ctrl-btn.hangup { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctrl-btn.hangup:hover { background: #dc2626; }

.unread-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* Painel Lateral de Chat + Participantes */
.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  background: var(--bg);
}

.room-workspace.in-call .chat-panel {
  flex: 0 0 350px;
  border-left: 1px solid var(--border);
}

.room-workspace.in-call .chat-panel.collapsed {
  display: none;
}

.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.room-workspace.in-call .chat-panel-header {
  display: flex;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  -webkit-overflow-scrolling: touch;
}

.msg-item {
  max-width: 82%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  align-self: flex-start;
  word-break: break-word;
}

.msg-item.own {
  align-self: flex-end;
  background: #17253d;
  border-color: #25406b;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.msg-sender { font-weight: 600; color: var(--text); }
.msg-text { white-space: pre-wrap; font-size: 14px; }

.msg-system {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  text-align: center;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-input-bar textarea {
  resize: none;
  height: 44px;
  max-height: 110px;
  font-size: 15px;
}

.peers-sidebar {
  width: 240px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  flex-shrink: 0;
}

.room-workspace.in-call .peers-sidebar {
  display: none;
}

.peer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 8px;
  font-size: 13px;
}

.peer-status {
  font-size: 11px;
  color: var(--muted);
}

.peer-status.live {
  color: #6ee7b7;
  font-weight: 600;
}

/* ================= RESPONSIVO MOBILE ================= */
@media (max-width: 860px) {
  .landing-grid { grid-template-columns: 1fr; }
  .dash-wrap { padding: 12px; }
  .peers-sidebar { display: none; }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px;
  }

  .room-header { padding: 8px 10px; }
  .room-header-right .btn { padding: 7px 9px; font-size: 12px; }

  .video-grid { padding: 8px; gap: 8px; }
  .video-grid.count-2,
  .video-grid.count-3,
  .video-grid.count-4,
  .video-grid.count-5,
  .video-grid.count-6 {
    grid-template-columns: 1fr;
  }

  .video-tile { min-height: 180px; }

  .room-workspace.in-call .chat-panel {
    position: absolute;
    inset: 0;
    flex: none;
    width: 100%;
    height: 100%;
    z-index: 30;
    border-left: none;
  }

  .call-controls {
    gap: 7px;
    padding: 9px 8px;
    padding-bottom: max(9px, env(safe-area-inset-bottom));
  }

  .ctrl-btn {
    padding: 9px 11px;
    font-size: 12px;
  }

  .hide-mobile { display: none !important; }
}
