/* ═══════════════════════════════════════════════════════════════════
   Videoatendimento — janela flutuante azulada com avatar PixiJS
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg-0: #060d1f;
  --bg-1: #0b1730;
  --bg-2: #13294f;
  --glass: rgba(13, 24, 48, 0.62);
  --glass-soft: rgba(21, 36, 68, 0.55);
  --glass-brd: rgba(126, 168, 255, 0.16);
  --ink: #eaf1ff;
  --muted: #93a7cf;
  --accent: #57a8ff;
  --accent-2: #8fc3ff;
  --ok: #3ecf8e;
  --ok-deep: #1e9e6a;
  --err: #ff6b6b;
  --err-deep: #d64545;
  --warn: #ffc94d;
  --shadow: 0 34px 90px -22px rgba(2, 8, 23, 0.85);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--ink);
  min-height: 100dvh;
  display: grid;
  place-items: safe center;
  padding: calc(env(safe-area-inset-top) + 20px) 18px
           calc(env(safe-area-inset-bottom) + 20px);
  -webkit-font-smoothing: antialiased;
  overflow-y: auto;
  overflow-x: hidden;
}

/* fundo azulado profundo com brilhos suaves */
.page-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 50% at 18% 8%, rgba(87, 168, 255, 0.16) 0%, transparent 70%),
    radial-gradient(55% 45% at 85% 20%, rgba(90, 110, 255, 0.12) 0%, transparent 70%),
    radial-gradient(70% 60% at 50% 105%, rgba(38, 84, 160, 0.22) 0%, transparent 70%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 60%, #04081a 100%);
}

/* textura de grão por cima do fundo */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.stage {
  position: relative; z-index: 2;
  width: 100%; max-width: 980px;
  display: flex; flex-direction: column; align-items: center;
  gap: 18px;
}

/* ── Janela flutuante da videochamada ─────────────────────────── */
.videocall {
  width: 100%;
  border-radius: 24px;
  overflow: hidden;
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(180, 210, 255, 0.08);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  animation:
    rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both,
    float 7s ease-in-out 0.8s infinite;
}

/* barra de título estilo app de chamada */
.vc-titlebar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(160, 195, 255, 0.08);
}
.vc-dots { display: inline-flex; gap: 7px; }
.vc-dots i {
  width: 11px; height: 11px; border-radius: 50%;
  background: #46608f;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25);
}
.vc-dots i:nth-child(2) { background: #5d7cae; }
.vc-dots i:nth-child(3) { background: #7fa0d4; }

.vc-peer {
  flex: 1; display: flex; align-items: baseline; justify-content: center;
  gap: 8px; min-width: 0;
}
.vc-avatar-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); align-self: center;
  box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.18);
  animation: pulse-dot 2.4s ease-in-out infinite;
}
.vc-peer-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600; font-size: 17px; letter-spacing: 0.01em;
}
.vc-peer-role {
  font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.vc-iconbtn {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.vc-iconbtn svg { width: 17px; height: 17px; }
.vc-iconbtn:hover {
  color: var(--accent-2);
  background: rgba(126, 168, 255, 0.1);
  border-color: rgba(126, 168, 255, 0.2);
}

/* ── Viewport (onde o PixiJS desenha a atendente) ─────────────── */
.vc-viewport {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #0b1730;
  overflow: hidden;
}
/* navegadores antigos sem aspect-ratio (mobile): mantém a proporção
   com o truque do padding, senão o viewport colapsa em altura zero */
@supports not (aspect-ratio: 16 / 10) {
  .vc-viewport { height: 0; padding-top: 62.5%; }
}
#avatarCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: pointer;
}
.vc-fallback {
  position: absolute; inset: 0;
  display: none;
  place-items: center; align-content: center; text-align: center;
  padding: 24px; color: var(--muted); font-size: 14px;
}
.vc-fallback small {
  display: block; margin-top: 8px;
  font-size: 11.5px; opacity: 0.65;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.vc-fallback small:empty { display: none; }
.vc-viewport.no-webgl .vc-fallback { display: grid; }

/* chips de status e cronômetro */
.vc-chip {
  position: absolute; z-index: 3;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px;
  background: rgba(8, 16, 36, 0.62);
  border: 1px solid rgba(126, 168, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px; font-weight: 500; color: var(--ink);
  max-width: min(72%, 460px);
}
.vc-chip-status { left: 14px; top: 14px; }
.vc-chip-status span:last-child {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vc-chip-timer {
  right: 14px; top: 14px;
  font-variant-numeric: tabular-nums;
  font-size: 14px; letter-spacing: 0.04em;
}
.vc-live-dot {
  width: 8px; height: 8px; flex: none; border-radius: 50%;
  background: var(--muted); transition: background 0.3s ease;
}
body.is-connecting .vc-live-dot {
  background: var(--warn);
  animation: pulse-dot 1s ease-in-out infinite;
}
body.in-call .vc-live-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.2);
}

/* ── teclado DTMF: "janelinha" flutuante (abre pelo botão na barra) ── */
.keypad {
  position: absolute; z-index: 4;
  right: 14px; bottom: 14px;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px 12px;
  border-radius: 18px;
  background: rgba(8, 16, 36, 0.85);
  border: 1px solid rgba(126, 168, 255, 0.22);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 44px -14px rgba(2, 8, 23, 0.7);
  animation: keypad-in 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes keypad-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* barra de título da janelinha + botão minimizar (−) */
.keypad-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 0 2px;
}
.keypad-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
}
.keypad-min {
  width: 24px; height: 24px; border-radius: 8px;
  display: grid; place-items: center;
  border: 1px solid rgba(126, 168, 255, 0.25);
  background: rgba(126, 168, 255, 0.08);
  color: var(--muted); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.keypad-min svg { width: 12px; height: 12px; }
.keypad-min:hover { background: rgba(126, 168, 255, 0.2); color: var(--ink); }

.keypad-grid {
  display: grid; grid-template-columns: repeat(3, 58px);
  gap: 8px;
}
.key {
  width: 58px; height: 42px;
  border: 1px solid rgba(126, 168, 255, 0.22);
  border-radius: 11px;
  background: rgba(126, 168, 255, 0.08);
  color: var(--ink);
  font: inherit; font-size: 18px; font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}
.key:hover { background: rgba(126, 168, 255, 0.18); }
.key:active { background: rgba(126, 168, 255, 0.3); transform: scale(0.95); }

/* visor "LCD" do que foi digitado (linha fixa no topo da janelinha) */
.dtmf-display {
  min-height: 36px;
  display: flex; align-items: center; justify-content: center;
  padding: 4px 12px;
  border-radius: 10px;
  background: rgba(87, 168, 255, 0.08);
  border: 1px solid rgba(126, 168, 255, 0.18);
  box-shadow: inset 0 2px 8px rgba(2, 8, 23, 0.5);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 19px; letter-spacing: 0.3em;
  color: #d6e7ff;
  text-shadow: 0 0 12px rgba(87, 168, 255, 0.5);
}
/* placeholder quando o visor está vazio */
.dtmf-display:empty::before {
  content: "digite…";
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 11.5px; letter-spacing: 0.08em;
  color: var(--muted); opacity: 0.75;
  text-shadow: none;
}

/* ── popover de credenciais ───────────────────────────────────── */
.login-pop {
  position: absolute; z-index: 5;
  right: 12px; top: 12px;
  width: min(250px, calc(100% - 24px));
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(8, 16, 36, 0.85);
  border: 1px solid rgba(126, 168, 255, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 44px -14px rgba(2, 8, 23, 0.7);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 12px; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding-left: 2px;
}
.input {
  font: inherit; font-size: 14px; color: var(--ink);
  background: rgba(126, 168, 255, 0.07);
  border: 1px solid rgba(126, 168, 255, 0.18);
  border-radius: 11px;
  padding: 9px 12px; width: 100%;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.input::placeholder { color: rgba(147, 167, 207, 0.55); }
.input:focus {
  outline: none; border-color: var(--accent);
  background: rgba(126, 168, 255, 0.12);
  box-shadow: 0 0 0 3px rgba(87, 168, 255, 0.16);
}
.login-note { font-size: 11.5px; color: var(--muted); }

/* caixa de erro */
.errbox {
  position: absolute; z-index: 6;
  left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 16px; border-radius: 12px;
  background: rgba(70, 18, 18, 0.72);
  border: 1px solid rgba(255, 107, 107, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13.5px; font-weight: 500; color: #ffc9c9;
  text-align: center;
}

/* ── barra de controles da chamada ────────────────────────────── */
.vc-controls {
  display: flex; justify-content: center; align-items: center;
  gap: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid rgba(160, 195, 255, 0.08);
}

.vc-btn {
  position: relative;
  width: 62px; height: 62px;
  border: none; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.3s ease;
}
.vc-btn .ic { width: 27px; height: 27px; }
.vc-btn:disabled { cursor: default; }

.vc-call {
  background: radial-gradient(120% 120% at 30% 25%, #6fe3ae, var(--ok) 55%, var(--ok-deep));
  box-shadow: 0 14px 34px -10px rgba(62, 207, 142, 0.55),
              inset 0 2px 4px rgba(255, 255, 255, 0.35);
}
.vc-call:hover:not(:disabled) { transform: scale(1.06); }
.vc-call:active:not(:disabled) { transform: scale(0.96); }

/* anel convidativo ao redor do telefone (só quando ocioso) */
.vc-btn-ring {
  position: absolute; inset: -7px;
  border-radius: 50%;
  border: 1.5px solid rgba(62, 207, 142, 0.55);
  opacity: 0;
  animation: ripple 2.4s ease-out infinite;
  pointer-events: none;
}
body.is-connecting .vc-btn-ring,
body.in-call .vc-btn-ring { animation: none; opacity: 0; }

/* spinner durante "conectando…" */
.spinner { display: none; }
body.is-connecting .vc-call .ic-phone { display: none; }
body.is-connecting .vc-call .spinner {
  display: block; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
body.is-connecting .vc-call {
  background: radial-gradient(120% 120% at 30% 25%, #ffd98a, var(--warn) 60%, #e0a92e);
  box-shadow: 0 14px 34px -10px rgba(255, 201, 77, 0.5),
              inset 0 2px 4px rgba(255, 255, 255, 0.35);
}

/* em chamada: o botão verde sai de cena e o vermelho assume */
body.in-call .vc-call { display: none; }
.vc-end {
  background: radial-gradient(120% 120% at 30% 25%, #ff9d9d, var(--err) 55%, var(--err-deep));
  box-shadow: 0 14px 34px -10px rgba(255, 107, 107, 0.55),
              inset 0 2px 4px rgba(255, 255, 255, 0.3);
  /* reage sutilmente à voz da atendente (--lvl vem do app.js) */
  transform: scale(calc(1 + var(--lvl, 0) * 0.07));
}
.vc-end:hover { box-shadow: 0 16px 38px -10px rgba(255, 107, 107, 0.7),
              inset 0 2px 4px rgba(255, 255, 255, 0.3); }

/* botão do teclado DTMF na barra de controles (só em chamada) */
.vc-dial {
  width: 48px; height: 48px;
  background: rgba(126, 168, 255, 0.1);
  border: 1px solid rgba(126, 168, 255, 0.28);
  color: var(--accent-2);
}
.vc-dial .ic { width: 22px; height: 22px; }
.vc-dial:hover { background: rgba(126, 168, 255, 0.2); }
.vc-dial.active {
  background: rgba(87, 168, 255, 0.32);
  border-color: var(--accent);
  color: #fff;
}
body:not(.in-call) .vc-dial { display: none; }

.hint {
  font-size: 13px; color: var(--muted); text-align: center;
  animation: rise 0.7s 0.15s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

/* ── animações ────────────────────────────────────────────────── */
@keyframes ripple {
  0%   { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.55); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ── responsivo ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { padding-inline: 10px; }
  .videocall { border-radius: 18px; }
  .vc-peer-role { display: none; }

  /* Teclado DTMF no mobile: o viewport 16/10 fica com ~200px de altura
     num celular, mas a janelinha vertical do desktop mede ~228px — ela
     estourava pelo TOPO e o overflow:hidden do viewport cortava a barra
     e o visor "LED" (só a grade de teclas, ancorada embaixo, aparecia).
     Aqui ela vira uma faixa larga e baixa (2 linhas × 6 teclas) que
     cabe inteira no viewport, com o visor sempre visível. */
  .keypad {
    left: 10px; right: 10px; bottom: 10px;
    gap: 6px;
    padding: 8px 10px 10px;
    border-radius: 14px;
  }
  .keypad-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .key { width: auto; height: 38px; font-size: 16px; }
  .dtmf-display { min-height: 30px; font-size: 16px; letter-spacing: 0.22em; }

  .vc-dial { width: 44px; height: 44px; }
  .vc-chip { font-size: 12px; padding: 6px 11px; }
}

/* telas baixas: compacta os controles */
@media (max-height: 720px) {
  .vc-btn { width: 54px; height: 54px; }
  .vc-controls { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .videocall, .hint, .vc-btn-ring, .vc-avatar-dot, .vc-live-dot, .keypad {
    animation: none !important;
  }
}