/* Reset & tipografia */
* { margin:0; padding:0; box-sizing:border-box; }
html, body { height:100%; background:#f7f7f7; -webkit-text-size-adjust:100%; }
:root{
  --brand:#B8001F;
  --brand-light:#c8102e;
  --on-brand:#ffffff;
  --bg:#ffffff;
  --border:#e0e4e7;
  --text:#1f2328;
  --muted:#6b7280;
  --bubble-bot:#f8f9fa;
  --bubble-user:#ECECEC;
  --shadow:0 6px 20px rgba(0,0,0,.12);
  --shadow-light:0 2px 8px rgba(0,0,0,.08);
}
body, button, input { touch-action:manipulation; }


/* === SPLASH SCREEN === */
#splash {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--brand) 0%, #920018 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: white; z-index: 1000;
}

.bradesco-logo-splash {
  width: 320px;
  height: auto;
  margin-bottom: 15px;
  filter: drop-shadow(0 4px 20px rgba(0,0,0,0.3));
}

#splash p {
  font: 500 12px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: rgba(255,255,255,0.9); margin-bottom: 20px;
  background: none;
  text-shadow: none;
}

.loading-dots {
  display: flex; gap: 8px;
}

.loading-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.7);
  animation: loadingPulse 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loadingPulse {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

#sessionEnd {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--brand) 0%, #920018 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: white; z-index: 1000; text-align: center;
}

#sessionEnd .bradesco-logo-splash { width: 320px; max-width: none; margin-bottom: 15px; }
#sessionEnd p { font: 500 18px/1.4 system-ui; color: rgba(255,255,255,0.9); }

.skip-btn {
  margin-top: 30px; padding: 12px 32px; 
  background: white; 
  border: none;
  border-radius: 25px; color: var(--brand);
  font: 600 16px system-ui; cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  min-width: 120px;
}

.skip-btn:hover {
  background: #f5f5f5;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

/* Container principal */
.chat-container{
  display:flex; flex-direction:column;
  height:100dvh; min-height:100vh;
  max-width:600px; margin:0 auto; 
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  border:1px solid var(--border); border-radius:20px; overflow:hidden;
  position: relative;
  box-shadow: var(--shadow);
}
@media (max-width:600px){ .chat-container{ border-radius:0; border:none; } }

/* Header */
.chat-header{ background:var(--brand); color:var(--on-brand); flex-shrink:0; }
.status-safe-area{ padding-top: env(safe-area-inset-top); }
.header-inner{ padding:8px 10px; display:flex; align-items:center; gap:12px; }

.bradesco-header-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  flex-shrink: 0;
  object-fit: cover;
}
.header-content{ flex:1; }
.header-title{
  font:700 13.5px/1 -apple-system,BlinkMacSystemFont,Helvetica Neue,SF Pro Display,system-ui,sans-serif;
  letter-spacing:.4px; text-transform:uppercase; margin-bottom: 2px;
}
.status-indicator{
  display:flex; align-items:center; justify-content:center; gap:4px; font-size:11px; opacity:0.9;
  margin-top: 2px;
}
.status-dot{
  width:6px; height:6px; background:#00ff88; border-radius:50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.1); }
  100% { opacity: 1; transform: scale(1); }
}
.close-btn{
  background:transparent; border:none; color:#fff; font-size:26px; line-height:1;
  width:36px; height:36px; border-radius:8px; cursor:pointer;
}
.close-btn:active{ transform:translateY(1px); }

/* Corpo do chat */
.chat-body{
  flex:1; 
  overflow-y:auto;
  overflow-x: hidden;
  padding:14px 12px 80px;
  background:
    radial-gradient(1200px 600px at 120% -10%, rgba(184,0,31,.08), transparent 60%),
    radial-gradient(900px 500px at -20% 10%, rgba(184,0,31,.05), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Forçar barra de rolagem visível em desktop */
.chat-body::-webkit-scrollbar {
  width: 8px;
}

.chat-body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Mensagens */
.message{
  max-width:74%;
  margin:14px 0;
  padding:12px 16px; border-radius:18px;
  line-height:1.5; color:var(--text); box-shadow:var(--shadow-light);
  position:relative; word-wrap:break-word;
  font:500 14px/1.5 -apple-system,BlinkMacSystemFont,Helvetica Neue,SF Pro Display,Segoe UI,system-ui,sans-serif;
  animation: messageSlideIn 0.4s ease-out;
  transform-origin: bottom left;
}

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

.user-message {
  animation: messageSlideInRight 0.4s ease-out;
  transform-origin: bottom right;
}

@keyframes messageSlideInRight {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.bot-message{ 
  background:var(--bubble-bot); 
  margin-right:auto; 
  border-top-left-radius:6px;
  margin-left: 44px;
  position: relative;
}

.bot-message::before {
  content: 'BIA';
  position: absolute;
  left: -44px;
  top: 0;
  width: 32px;
  height: 32px;
  background: #B8001F;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  color: white;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.user-message{ 
  background:var(--bubble-user); 
  margin-left:auto; 
  border-top-right-radius:6px;
  box-shadow: var(--shadow);
}

.bot-message::after, .user-message::after{
  content:""; position:absolute; bottom:0; width:10px; height:10px; background:inherit;
}
.bot-message::after{ left:-4px; clip-path:polygon(0 100%,100% 0,100% 100%); }
.user-message::after{ right:-4px; clip-path:polygon(0 0,100% 100%,0 100%); }

/* Timestamp */
.message time{
  display:block; margin-top:6px; font-size:11px; color:#9aa1a9;
  font-weight:500;
}

/* Divisor de dia */
.day-divider{
  display:flex; align-items:center; gap:12px; margin:10px 0;
  color:#6b7280; font-weight:600; font-size:12px;
}
.day-divider::before, .day-divider::after{
  content:""; flex:1; height:1px; background:var(--border);
}

/* Estados/feedback */
.typing{ text-align:center; color:var(--muted); font-size:12px; margin:8px 0; }
.typing-indicator {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px; margin: 8px 0;
  color: var(--muted); font-size: 12px;
}
.typing-dots {
  display: flex; gap: 4px;
}
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); opacity: 0.4;
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}
.spinner{
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px; margin: 8px 0;
  color: var(--muted); font-size: 12px;
}
.spinner-dots {
  display: flex; gap: 4px;
}
.spinner-dots .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand); opacity: 0.4;
  animation: spinnerBounce 1.4s ease-in-out infinite;
}
.spinner-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.spinner-dots .dot:nth-child(2) { animation-delay: -0.16s; }
.spinner-dots .dot:nth-child(3) { animation-delay: 0s; }
@keyframes spinnerBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}

/* Loader centralizado (não é mensagem da BIA) */
.centered-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  margin: 12px 0;
}
.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.loader-spinner {
  width: 40px;
  height: 40px;
  position: relative;
}
.spinner-ring {
  width: 100%;
  height: 100%;
  border: 3px solid rgba(184, 0, 31, 0.1);
  border-top: 3px solid var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.loader-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  text-align: center;
}

/* Barra de progresso NOVA (para etapas de autenticação) */
.progress-bar-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 16px;
  margin: 12px 0;
}
.progress-container-new {
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e0e4e7;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-light) 100%);
  border-radius: 10px;
  transition: width 0.1s linear;
}
.progress-text-small {
  font-size: 11px;
  color: #9aa1a9;
  font-weight: 500;
  opacity: 0.7;
  margin-top: 4px;
}
.progress-emoji {
  font-size: 14px;
  margin-left: 6px;
}

/* Barra de progresso antiga (mantida para compatibilidade) */
.progress-container {
  padding: 16px;
  background: #f8f9fa;
  border-radius: 12px;
  margin: 8px 0;
}
.progress-text {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 500;
}
.progress-percent {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

/* Área de entrada */
.chat-input{
  position:fixed; bottom:0; left:50%; transform:translateX(-50%);
  width:100%; max-width:600px; z-index:10;
  padding:10px 10px calc(10px + env(safe-area-inset-bottom));
  background:linear-gradient(to top,#fff 90%,rgba(255,255,255,.9) 100%);
  border-top:1px solid var(--border);
  display:flex; gap:10px; align-items:center;
  backdrop-filter: blur(8px);
}
.chat-input input{
  flex:1; padding:12px 14px; font-size:16px; /* >=16px evita zoom iOS */
  border:1px solid var(--border); border-radius:999px; outline:none; background:#fff;
  transition:border .2s, box-shadow .2s;
  touch-action: manipulation; /* Previne zoom duplo no mobile */
  -webkit-user-select: text;
  user-select: text;
}
.chat-input input:focus{
  border-color:color-mix(in srgb,var(--brand) 45%,#d1d5db);
  box-shadow:0 0 0 4px color-mix(in srgb,var(--brand) 15%,transparent);
}
.btn-send{
  padding:10px 16px; border:none; border-radius:999px; cursor:pointer;
  background:var(--brand); color:var(--on-brand); font-weight:700; letter-spacing:.2px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(200,16,46,.3);
}
.btn-send:hover{
  background: #a80e26;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(200,16,46,.4);
}
.btn-send:active{ 
  transform:translateY(1px); 
  transition: none;
}

/* Rodapé */
.chat-footer{
  text-align:center; 
  color:#7a7a7a; 
  font-size:13px; 
  background:#f5f5f5;
  padding:12px 16px env(safe-area-inset-bottom); 
  border-top:1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.chat-footer p {
  margin: 0;
  line-height: 1.5;
}

.end-chat-btn {
  background: #c8102e;
  border: none;
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.end-chat-btn:hover {
  background: #a00d24;
  transform: translateY(-1px);
}

/* Botão de encerrar dentro do chat */
.end-button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 20px auto 10px;
  padding: 16px 16px 8px;
  text-align: center;
  max-width: 90%;
}

.footer-text {
  color: #999;
  font-size: 11px;
  line-height: 1.4;
  margin: 0;
  order: 2;
}

.end-chat-btn-inline {
  background: #c8102e;
  border: none;
  color: white;
  padding: 10px 28px;
  border-radius: 22px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(200, 16, 46, 0.25);
  order: 1;
}

.end-chat-btn-inline:hover {
  background: #a00d24;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(200, 16, 46, 0.4);
}

.end-chat-btn-inline:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(200, 16, 46, 0.3);
}

/* Splash & Final */
#splash,#sessionEnd{
  position:fixed; inset:0; background:#B8001F; color:#fff;
  display:flex; flex-direction:column; align-items:center; justify-content:center; z-index:9999;
  padding:env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
#splash p{ margin-top:10px; font-size:18px; font-weight:800; opacity:.9; animation:fade 1.8s infinite; background:none; }
#sessionEnd p{ margin-top:16px; font-size:18px; font-weight:800; opacity:.95; }
@keyframes fade{0%,100%{opacity:.35}50%{opacity:1}}

/* IMPORTANTÍSSIMO: se estiver hidden, some de verdade */
#splash[hidden],
#sessionEnd[hidden],
#endModal[hidden]{ display:none !important; }

/* Modal confirmação */
.modal{
  position:fixed; inset:0; background:rgba(0,0,0,.35);
  display:flex; align-items:center; justify-content:center;
  z-index:9998;
}
.modal-card{
  background:#fff; padding:16px; border-radius:12px;
  width:min(92vw,360px); box-shadow:var(--shadow);
}
.modal-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:12px; }
.btn-secondary{
  border:1px solid var(--border); background:#fff; padding:8px 12px; border-radius:8px;
}
.btn-danger{
  background:var(--brand); color:#fff; border:none; padding:8px 12px; border-radius:8px;
}

/* Desktop premium */
@media(min-width:900px){
  body{
    display:flex; justify-content:center; align-items:stretch;
    min-height:100dvh; padding:24px;
    background:radial-gradient(1200px 600px at 120% -10%,rgba(200,16,46,.05),transparent 60%),#f3f4f6;
  }
  .chat-container{ border-radius:16px; border:1px solid #ececec; box-shadow:0 10px 30px rgba(0,0,0,.06); }
}

/* === TECLADO VIRTUAL BANCÁRIO === */
.virtual-keyboard {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  border: 2px solid var(--brand);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  z-index: 10000;
  animation: popIn 0.3s ease;
  max-width: 90vw;
  width: 340px;
}

.keyboard-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.keyboard-row:last-child {
  margin-bottom: 0;
}

@keyframes popIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.keyboard-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.keyboard-header {
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.keyboard-title {
  font: 600 13px system-ui;
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.keyboard-title::before {
  content: "🔒";
  font-size: 14px;
}

.keyboard-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: all 0.2s ease;
}

.keyboard-close:hover {
  color: var(--brand);
  transform: scale(1.1);
}

.keyboard-display {
  background: #f8f9fa;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  font: 600 20px monospace;
  letter-spacing: 6px;
  text-align: center;
  color: var(--text);
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.keyboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.keyboard-btn {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font: 700 18px system-ui;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.keyboard-btn:hover {
  background: linear-gradient(135deg, var(--brand-light) 0%, var(--brand) 100%);
  color: white;
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(184,0,31,0.3);
}

.keyboard-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.keyboard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.keyboard-btn.delete-btn {
  background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
  color: white;
  border-color: #cc0000;
  font-size: 13px;
  padding: 12px;
}

.keyboard-btn.delete-btn:hover {
  background: linear-gradient(135deg, #ff6666 0%, #ff4444 100%);
  border-color: #ff4444;
}

.keyboard-btn.send-btn {
  background: linear-gradient(135deg, #00c853 0%, #00a843 100%);
  color: white;
  border-color: #00c853;
  font-size: 13px;
  padding: 12px;
  font-weight: 700;
}

.keyboard-btn.send-btn:hover {
  background: linear-gradient(135deg, #00e676 0%, #00c853 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,200,83,0.4);
}

.keyboard-info {
  text-align: center;
  font: 400 10px system-ui;
  color: var(--muted);
}

/* Mobile: teclado menor */
@media (max-width: 767px) {
  .virtual-keyboard {
    width: 300px;
    padding: 14px;
  }
  
  .keyboard-btn {
    padding: 12px;
    font-size: 16px;
  }
  
  .keyboard-display {
    font-size: 18px;
    padding: 10px;
  }
}

/* === MELHORIAS ADICIONAIS === */

/* Loader simples - só texto */
.simple-loader-wrapper {
  text-align: center;
  margin: 16px auto;
  width: fit-content;
  animation: fadeIn 0.3s ease;
}

.loader-content {
  font-size: 14px;
  color: var(--brand-light);
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Animação de fade in para mensagens */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  animation: fadeIn 0.4s ease;
}

/* Timestamp nas mensagens */
.message-timestamp {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
  display: block;
  opacity: 0.8;
}

/* Box destacado para protocolo */
.protocol-box {
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border: 2px solid var(--brand);
  border-radius: 10px;
  padding: 12px;
  margin: 12px auto;
  max-width: 80%;
  text-align: center;
  box-shadow: 0 3px 10px rgba(200, 16, 46, 0.15);
  animation: fadeIn 0.5s ease;
}

.protocol-number {
  font-size: 16px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: 1px;
  margin: 6px 0;
  font-family: 'Courier New', monospace;
}

.protocol-label {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.copy-protocol-btn {
  margin-top: 10px;
  padding: 7px 18px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(200, 16, 46, 0.3);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 2px 6px rgba(200, 16, 46, 0.3);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(200, 16, 46, 0.5);
  }
}

.copy-protocol-btn:hover {
  background: #a80e26;
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 4px 10px rgba(200, 16, 46, 0.4);
  animation: none;
}

.copy-protocol-btn:active {
  transform: translateY(0);
}

.copy-protocol-btn.copied {
  background: #00c853;
  pointer-events: none;
  animation: none;
}

.copy-protocol-btn.copied::before {
  content: '✓ ';
}
