:root {
  --bg: #070c16;
  --bg-2: #0b1220;
  --panel: #0f1726;
  --panel-2: #121d31;
  --panel-3: #17243c;
  --line: #1e2b45;
  --line-2: #263856;
  --text: #e8eefc;
  --muted: #8fa1c0;
  --muted-2: #6b7f9f;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --accent-3: #fbbf24;
  --own: #0d3b5c;
  --own-2: #0b3350;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(56, 189, 248, 0.13), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(34, 197, 94, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Topo ---------- */
.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 15, 27, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.2), rgba(34, 197, 94, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 8px 24px rgba(56, 189, 248, 0.12);
}

.brandText { min-width: 0; }

.brandName {
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 16px;
}

.roomLine {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roomLine strong { color: var(--accent); font-weight: 600; }

.topActions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  white-space: nowrap;
}

.conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-3);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.15);
}

.conn.online .dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.conn.offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  color: #04121f;
  background: linear-gradient(145deg, #7dd3fc, #38bdf8 55%, #0ea5e9);
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 8px 22px rgba(56, 189, 248, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn.primary:hover { filter: brightness(1.05); }

.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border-color: var(--line);
}

.btn.ghost:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--line-2); }
.btn.icon { padding: 8px; width: 34px; height: 34px; border-radius: 10px; }
.btn.wide { width: 100%; padding: 12px 16px; font-size: 14px; }
.btn.send { width: 44px; height: 44px; padding: 0; border-radius: 13px; font-size: 17px; flex-shrink: 0; }

/* ---------- Estrutura ---------- */
.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

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

/* ---------- Mensagens ---------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px clamp(14px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.messages:empty::before {
  content: "Ainda não há mensagens. Diz olá à aliança! 👋";
  margin: auto;
  color: var(--muted-2);
  font-size: 14px;
  text-align: center;
}

.msg {
  max-width: min(720px, 88%);
  align-self: flex-start;
  animation: pop 0.18s ease both;
}

.msg.own { align-self: flex-end; }

@keyframes pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg .meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 4px 4px;
  font-size: 11px;
  color: var(--muted-2);
}

.msg.own .meta { justify-content: flex-end; }
.msg .who { color: var(--muted); font-weight: 600; }
.msg.own .who { color: #7dd3fc; }

.msg .bubble {
  padding: 10px 14px;
  border-radius: 15px 15px 15px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
}

.msg.own .bubble {
  border-radius: 15px 15px 5px 15px;
  background: linear-gradient(145deg, var(--own), var(--own-2));
  border-color: rgba(56, 189, 248, 0.26);
}

.sys {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted-2);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.typing {
  min-height: 18px;
  padding: 0 clamp(14px, 3vw, 34px);
  font-size: 12px;
  color: var(--muted-2);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px clamp(14px, 3vw, 34px) max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(9, 15, 27, 0.65);
  backdrop-filter: blur(10px);
}

#input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
  outline: none;
  line-height: 1.4;
  font-size: 14.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#input::placeholder { color: var(--muted-2); }
#input:focus { border-color: rgba(56, 189, 248, 0.55); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12); }

/* ---------- Popover online ---------- */
.pop {
  position: absolute;
  top: calc(100% - 6px);
  right: 18px;
  width: min(260px, calc(100vw - 36px));
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: rgba(15, 23, 38, 0.98);
  box-shadow: var(--shadow);
  z-index: 40;
}

.pop h3 {
  margin: 4px 6px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted-2);
}

.pop .person {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 9px;
  font-size: 13px;
}

.pop .person:hover { background: rgba(255, 255, 255, 0.04); }

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #062033;
  background: linear-gradient(145deg, #7dd3fc, #38bdf8);
  flex-shrink: 0;
}

/* ---------- Voz ---------- */
.voicePane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 29, 49, 0.75), rgba(10, 16, 28, 0.9));
}

.voiceHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}

.voiceTitle { font-weight: 700; font-size: 14px; }

.voiceStatus {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
  text-transform: lowercase;
}

.voiceStatus.live { color: var(--accent-2); }
.voiceStatus.error { color: var(--danger); }

.voiceIntro {
  padding: 16px 14px;
  overflow-y: auto;
}

.voiceIntro p { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.voiceIntro strong { color: var(--text); }

.voiceChoices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.voiceChoices .btn { padding: 11px 12px; }

.micTest { margin-bottom: 12px; }
.micTest > .btn { width: 100%; padding: 11px 12px; }

.micTestPanel {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.03);
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.meterFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent-2);
  transition: width 80ms linear;
}

.meterFill.loud { background: var(--accent); }

.micTestPanel .tiny { margin: 8px 0 !important; }
.micTestPanel .btn { padding: 8px 12px; font-size: 12.5px; }

.tiny { font-size: 11.5px !important; color: var(--muted-2) !important; line-height: 1.45 !important; }

.voiceTips {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
  color: var(--muted-2);
}

.voiceTips span { margin-right: 4px; }

.voiceFallback {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  font-size: 12.5px;
  color: var(--muted);
}

.voiceFallback p { margin: 0 !important; font-size: 12.5px !important; }
.voiceFallback a { color: var(--accent); font-weight: 600; }

.voiceBackdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(3, 7, 14, 0.7);
  backdrop-filter: blur(3px);
}

/* ---------- Overlay de entrada ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(56, 189, 248, 0.16), transparent 60%),
    rgba(4, 8, 16, 0.82);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.card {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 22px;
  border: 1px solid var(--line-2);
  background: linear-gradient(180deg, rgba(18, 29, 49, 0.98), rgba(11, 18, 32, 0.98));
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cardLogo {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 28px;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.22), rgba(34, 197, 94, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.card h1 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0.2px;
}

.card > .muted { text-align: center; margin: 0 0 20px; font-size: 13.5px; }
.muted { color: var(--muted); }

.card label {
  display: block;
  margin: 12px 2px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(7, 12, 22, 0.7);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.card input:focus { border-color: rgba(56, 189, 248, 0.6); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12); }
.card .btn { margin-top: 18px; }
.card .tiny { margin: 16px 0 0; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 120;
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: rgba(18, 29, 49, 0.98);
  box-shadow: var(--shadow);
  font-size: 13px;
  text-align: center;
  animation: toastIn 0.2s ease both;
}

.toast.error { border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Scrollbars ---------- */
.messages, .pop, .voiceIntro {
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.messages::-webkit-scrollbar, .pop::-webkit-scrollbar, .voiceIntro::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .pop::-webkit-scrollbar-thumb, .voiceIntro::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 999px;
}

/* ---------- Desktop com voz ---------- */
@media (min-width: 901px) {
  body.voice-open .main { grid-template-columns: minmax(0, 1fr) 380px; }
  .voiceBackdrop { display: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .logo { width: 38px; height: 38px; font-size: 20px; }
  .brandName { font-size: 14.5px; }
  .roomLine { font-size: 11px; }
  .wideOnly { display: none; }
  .conn span:last-child { display: none; }
  .conn { padding: 8px; }
  .topActions { gap: 6px; }
  .btn.ghost, .btn.primary { padding: 9px 11px; }
  .btn.send { width: 44px; height: 44px; }

  .voicePane {
    position: fixed;
    inset: 0;
    z-index: 60;
    border-left: 0;
    border-radius: 0;
  }

  .voiceHead { padding-top: max(14px, env(safe-area-inset-top)); }
  .messages { padding: 16px 12px; }
  .msg { max-width: 92%; }
  .card { padding: 22px 18px; }
}

@media (max-width: 380px) {
  .brandName { display: none; }
  .roomLine { font-size: 12px; }
}
