:root {
  --bg: #0f1216;
  --bg-card: #1a1f26;
  --bg-elev: #232a33;
  --text: #e8edf2;
  --text-dim: #9aa6b2;
  --accent: #4f8cff;
  --accent-2: #34d399;
  --danger: #ef4444;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.view { min-height: 100%; }

/* ═══════════ INICIO ═══════════ */
#home {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2b45 0%, var(--bg) 60%);
}

.home-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid #2a323d;
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}

.logo { text-align: center; margin-bottom: 6px; }
.logo-icon { font-size: 34px; }
.logo h1 { font-size: 30px; letter-spacing: .5px; margin-top: 4px; }
.logo p { color: var(--text-dim); font-size: 14px; margin-top: 6px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-dim); }

input[type="text"] {
  background: var(--bg-elev);
  border: 1px solid #2e3842;
  border-radius: 10px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus { border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  transition: transform .05s, filter .15s, background .15s;
}
.btn:active { transform: scale(.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid #34404c; }
.btn-ghost:hover { background: var(--bg-elev); }

.btn-small {
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid #2e3842;
}
.btn-small:hover { filter: brightness(1.15); }

.hint { font-size: 14px; color: var(--text-dim); line-height: 1.5; }
.hint b { color: var(--accent-2); }

.error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid var(--danger);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}

.invite-chip {
  background: var(--bg-elev);
  border: 1px dashed #3b4a5c;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent-2);
  text-align: center;
  letter-spacing: 2px;
  font-size: 20px;
}

.preview-box {
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid #2e3842;
}
.preview-box video { width: 100%; display: block; transform: scaleX(-1); }

/* ═══════════ SALA ═══════════ */
#meeting { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid #232b34;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.room-chip {
  background: var(--bg-elev);
  border: 1px solid #2e3842;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent-2);
}
.topbar-center { display: flex; gap: 12px; color: var(--text-dim); font-size: 14px; font-variant-numeric: tabular-nums; }

.meeting-main {
  flex: 1;
  overflow: auto;
  padding: 16px;
  position: relative;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  height: 100%;
  align-content: center;
}

.tile {
  position: relative;
  background: var(--bg-card);
  border: 1px solid #242d37;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 180px;
}
.tile .tile-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 54px;
  background: var(--bg-elev);
  color: var(--text-dim);
}
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.tile.local video { transform: scaleX(-1); }
.tile .tile-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, .55);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  max-width: 80%;
}
.tile .tile-label b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .crown { color: #fbbf24; }
.tile .mic-off { color: #f87171; }
.tile .screen-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--accent-2);
  color: #06281c;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 3px 8px;
}

.peer-state {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 3px 8px;
  background: #f59e0b;
  color: #451a03;
}
.peer-state.ok { background: var(--accent-2); color: #06281c; }
.peer-state.bad { background: var(--danger); color: #fff; }

/* ═══════════ CONTROLES ═══════════ */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-top: 1px solid #232b34;
  flex-shrink: 0;
}
.ctl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid #2e3842;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .05s, background .15s, filter .15s;
}
.ctl:hover { filter: brightness(1.15); }
.ctl:active { transform: scale(.95); }
.ctl.off { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl-leave { background: var(--danger); border-color: var(--danger); color: #fff; transform: rotate(135deg); }
.ctl-leave:hover { filter: brightness(1.1); }
.ctl-chat-on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ═══════════ CHAT ═══════════ */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 88vw;
  background: var(--bg-card);
  border-left: 1px solid #232b34;
  display: flex;
  flex-direction: column;
  z-index: 50;
  animation: slideIn .18s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #232b34;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; }
.msg .who { font-size: 12px; color: var(--text-dim); margin-bottom: 3px; }
.msg .body {
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.me { align-self: flex-end; }
.msg.me .who { text-align: right; }
.msg.me .body { background: var(--accent); color: #fff; }
.msg.system .body { background: transparent; color: var(--text-dim); font-size: 13px; text-align: center; padding: 0; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #232b34;
}
.chat-form input { flex: 1; }

@media (max-width: 640px) {
  .tiles { grid-template-columns: 1fr; }
  .controls { gap: 8px; }
  .ctl { width: 46px; height: 46px; font-size: 19px; }
  .topbar-center { display: none; }
}
