:root {
  --bg: #0a0c10;
  --bg2: #0f1218;
  --surface: #141720;
  --surface2: #1c2030;
  --border: rgba(255,255,255,0.07);
  --border-accent: rgba(0,200,255,0.25);
  --accent: #00c8ff;
  --accent2: #0080ff;
  --accent-glow: rgba(0,200,255,0.15);
  --text: #e8eaf0;
  --text-dim: #6b7280;
  --text-muted: #374151;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.15);
  --radius: 14px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ============================================================
   TELA CONECTAR
   ============================================================ */
#screen-connect {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(0,120,200,0.08) 0%, transparent 60%);
}

.connect-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px 36px;
  text-align: center;
}

/* Logo — anel minimalista com símbolo */
.logo-ring {
  width: 80px; height: 80px;
  margin: 0 auto 24px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.logo-ring::before {
  content: '';
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid var(--border-accent);
  animation: ring-pulse 3s ease-in-out infinite;
}
.logo-ring::after {
  content: '';
  position: absolute; inset: 10px; border-radius: 50%;
  border: 1px solid rgba(0,200,255,0.15);
}
@keyframes ring-pulse {
  0%,100% { border-color: rgba(0,200,255,0.2); box-shadow: none; }
  50% { border-color: rgba(0,200,255,0.5); box-shadow: 0 0 20px rgba(0,200,255,0.1); }
}
.logo-head {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border-accent);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  z-index: 1;
}
.logo-head .eye {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  position: absolute; top: 14px;
}
.logo-head .eye:first-child { left: 11px; }
.logo-head .eye:last-child { right: 11px; }
.logo-head .mouth {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: 16px; height: 2px; border-radius: 2px;
  background: var(--accent); opacity: 0.6;
}

h1 { font-size: 28px; font-weight: 700; letter-spacing: 4px; color: var(--text); margin-bottom: 4px; }
.subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 32px; letter-spacing: 0.3px; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; }
.field input {
  width: 100%; padding: 13px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; font-family: "SF Mono", "Consolas", monospace;
  outline: none; transition: border-color 0.2s;
}
.field input:focus { border-color: var(--border-accent); }
.field input::placeholder { color: var(--text-muted); }

.btn-primary {
  width: 100%; padding: 14px;
  background: var(--accent2);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 15px; font-weight: 600;
  letter-spacing: 0.5px; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin-bottom: 12px;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.99); }

.btn-ghost {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-dim);
  font-size: 13px; padding: 7px 16px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-ghost:hover { border-color: var(--border-accent); color: var(--text); }

.status-line { font-size: 13px; color: var(--text-dim); min-height: 20px; }
.status-line.err { color: var(--danger); }

/* ============================================================
   TELA SESSÃO — TOPBAR
   ============================================================ */
#screen-session { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; transition: background 0.3s; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(16,185,129,0.6); }
#conn-label { font-size: 13px; color: var(--text-dim); font-weight: 500; }

/* Saída de imagem gerada: blob mantido apenas em memória nesta sessão */
.generated-image-panel { width: min(100%, 440px); max-height: 28dvh; overflow: auto; margin: 6px auto; padding: 8px 16px; text-align: center; flex-shrink: 0; }
.generated-image-panel p { color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.generated-image-panel img { max-width: 100%; max-height: 24dvh; object-fit: contain; border-radius: 12px; border: 1px solid var(--border-accent); background: #000; }
.generated-image-actions { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 8px; }
.generated-image-dismiss { width: 40px; height: 40px; min-width: 40px; padding: 0; font-size: 24px; line-height: 1; background: #38232b; color: #ffb4c0; border: 1px solid #70404b; }
.generated-image-dismiss:hover { background: #56303a; }

/* DionVo: indicador permanente do microfone, sem botão de alternância */
.dionvo-auto-mic .mic-button { background: #b5475b; box-shadow: 0 0 0 5px rgba(181,71,91,.22); cursor: default; }
.dionvo-auto-mic .mic-hint { color: #ffccd3; }

/* Navegação GPS — mapa 2D visível apenas durante rota ativa */
.navigation-panel { position: fixed; z-index: 6000; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(calc(100vw - 24px), 640px); max-height: 88dvh; overflow-y: auto; margin: 0; padding: 12px 14px; border: 1px solid var(--border-accent); border-radius: 14px; background: var(--panel, #171724); box-shadow: 0 16px 48px rgba(0,0,0,.6); }
.navigation-header { display:flex; align-items:center; justify-content:space-between; gap:10px; text-align:left; }
.navigation-header p, .navigation-disclaimer { margin:4px 0; color:var(--text-dim); font-size:12px; }
.navigation-header .btn-ghost { min-height:40px; }
#navigation-map { width:100%; height:min(38dvh, 320px); min-height:180px; margin-top:8px; border-radius:10px; z-index:1; background:#ddd; }
.navigation-eta { font-size:14px; margin:8px 0 2px; }

/* Modo câmera */
.camera-panel { width: min(100%, 440px); padding: 8px 16px; margin: 0 auto; text-align: center; }
.camera-preview { display: block; width: 100%; max-height: 28dvh; object-fit: cover; border-radius: 14px; border: 1px solid var(--border-accent); background: #000; }
.camera-controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.camera-controls button { min-height: 40px; }
.camera-status { color: var(--text-dim); font-size: 12px; margin-top: 6px; }

/* ============================================================
   STAGE — VISUALIZADOR CENTRAL
   ============================================================ */
.stage {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px 24px 0;
  position: relative; overflow: hidden;
}

/* Fundo sutil com gradiente radial */
.stage::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 60% 50% at 50% 40%, rgba(0,128,255,0.04) 0%, transparent 70%);
  pointer-events: none;
}

/* Wrapper da cabeça */
.head-wrap {
  position: relative;
  width: 160px; height: 160px;
  display: flex; align-items: center; justify-content: center;
}

/* Halo de escuta */
.halo {
  position: absolute; inset: -20px; border-radius: 50%;
  opacity: 0; pointer-events: none;
  background: radial-gradient(circle, rgba(0,200,255,0.12) 0%, transparent 70%);
  transition: opacity 0.4s;
}
.listening .halo { opacity: 1; animation: halo-pulse 2s ease-in-out infinite; }
@keyframes halo-pulse {
  0%,100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.06); opacity: 1; }
}

/* Cabeça principal — design minimalista */
.head {
  position: absolute; inset: 0;
  border-radius: 38% 38% 42% 42% / 40% 40% 50% 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.listening .head { border-color: rgba(0,200,255,0.35); box-shadow: 0 0 30px rgba(0,200,255,0.08); }
.speaking .head { border-color: rgba(0,200,255,0.5); animation: speak-pulse 0.6s ease-in-out infinite alternate; }
@keyframes speak-pulse { from { box-shadow: 0 0 20px rgba(0,200,255,0.08); } to { box-shadow: 0 0 40px rgba(0,200,255,0.18); } }

/* Visor dos olhos */
.visor {
  width: 96px; height: 40px; border-radius: 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 20px;
}
.eye {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(0,200,255,0.8);
  transition: all 0.15s;
}
.blink .eye { height: 2px; border-radius: 1px; box-shadow: none; }
.speaking .eye { box-shadow: 0 0 16px rgba(0,200,255,1); }

/* Mandíbula / boca */
.jaw { height: 20px; display: flex; align-items: center; }
.mouth-bar {
  width: 32px; height: 3px; border-radius: 2px;
  background: var(--accent); opacity: 0.6;
  box-shadow: 0 0 8px rgba(0,200,255,0.4);
  transition: all 0.08s;
}
.speaking .mouth-bar { opacity: 1; animation: mouth-talk 0.2s ease-in-out infinite alternate; }
@keyframes mouth-talk {
  from { width: 18px; height: 3px; }
  to   { width: 40px; height: 10px; border-radius: 5px; }
}

/* Aneis externos */
.rings { position: absolute; inset: -28px; pointer-events: none; }
.rings i { position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(0,200,255,0.2); opacity: 0; }
.listening .rings i { animation: ring-out 2.2s ease-out infinite; }
.listening .rings i:nth-child(2) { animation-delay: 0.7s; }
.listening .rings i:nth-child(3) { animation-delay: 1.4s; }
@keyframes ring-out { 0% { transform: scale(0.7); opacity: 0.6; } 100% { transform: scale(1.3); opacity: 0; } }

/* Rótulo de estado */
.state-label {
  margin-top: 20px; font-size: 13px; color: var(--text-dim);
  letter-spacing: 0.3px; font-weight: 500; z-index: 1;
}
.listening .state-label { color: var(--accent); }
.speaking .state-label { color: var(--text); }

/* ============================================================
   MUSIC BAR
   ============================================================ */
.music-bar {
  margin: 12px 20px 0;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.music-info { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.music-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: rgba(0,200,255,0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--accent);
}
.state-playing .music-icon { animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.music-text { min-width: 0; }
.music-text strong { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.music-text span { font-size: 11px; color: var(--text-dim); }
.music-controls { display: flex; gap: 8px; flex-shrink: 0; }
.btn-round {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s;
}
.btn-round:hover { border-color: var(--border-accent); }
.btn-round.danger { color: var(--danger); }

/* ============================================================
   TRANSCRIÇÕES
   ============================================================ */
.transcripts {
  padding: 12px 20px 8px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 24dvh; overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin; scrollbar-color: var(--surface2) transparent;
}
.bubble {
  max-width: 85%; padding: 10px 14px;
  border-radius: 14px; font-size: 14px; line-height: 1.5;
  font-weight: 400;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent2);
  color: #fff; border-bottom-right-radius: 4px;
}
.bubble.dion {
  align-self: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.system {
  align-self: center;
  background: none; color: var(--text-dim);
  font-size: 12px; padding: 4px 0;
}

/* ============================================================
   MIC DOCK
   ============================================================ */
.mic-dock {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0 calc(20px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: linear-gradient(180deg, transparent 0%, var(--bg) 30%);
}

.mic-button {
  width: 72px; height: 72px; border-radius: 50%; border: none;
  background: var(--accent2);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
  box-shadow: 0 0 0 0 rgba(0,128,255,0.3);
  transition: transform 0.12s, box-shadow 0.2s;
}
.mic-button::before {
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 1px solid rgba(0,128,255,0.2);
  transition: opacity 0.2s;
}
.mic-button:active { transform: scale(0.94); }
.mic-button.on {
  background: var(--danger);
  box-shadow: 0 0 0 10px rgba(239,68,68,0.1), 0 8px 24px rgba(239,68,68,0.3);
  animation: mic-active 1.8s ease-in-out infinite;
}
.mic-button.on::before { border-color: rgba(239,68,68,0.3); }
@keyframes mic-active {
  0%,100% { box-shadow: 0 0 0 8px rgba(239,68,68,0.08), 0 8px 24px rgba(239,68,68,0.25); }
  50% { box-shadow: 0 0 0 14px rgba(239,68,68,0.04), 0 8px 28px rgba(239,68,68,0.35); }
}
.mic-hint { margin-top: 10px; font-size: 12px; color: var(--text-dim); letter-spacing: 0.2px; }

@media (min-width: 600px) {
  #screen-session { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}


/* ============================================================
   ALARMES DO CELULAR
   ============================================================ */
.phone-alarm-panel {
  margin: 10px 20px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.phone-alarm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.phone-alarm-head strong { display: block; font-size: 13px; }
.phone-alarm-head span { display: block; margin-top: 3px; color: var(--text-dim); font-size: 11px; }
.phone-alarm-form { margin-top: 12px; display: grid; gap: 8px; }
.phone-alarm-form input[type="text"],
.phone-alarm-form input[type="datetime-local"] {
  width: 100%; padding: 11px 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; outline: none;
}
.alarm-repeat { font-size: 12px; color: var(--text-dim); display: flex; gap: 8px; align-items: center; }
.alarm-add { margin: 0; padding: 11px; font-size: 13px; }
.phone-alarms { display: grid; gap: 7px; margin-top: 10px; }
.phone-alarm-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.phone-alarm-info { min-width: 0; }
.phone-alarm-info strong { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-alarm-info span { display: block; margin-top: 3px; color: var(--text-dim); font-size: 10px; }
.alarm-delete { padding: 5px 9px; font-size: 11px; flex-shrink: 0; }
.phone-alarm-panel .status-line { margin-top: 8px; }
