/* Floating Chat Widget */
.chat-fab{
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 9999;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border: 0 !important;
  background: var(--primary) !important;
  color: #fff !important;
  cursor: pointer !important;
  font-weight: 700 !important;
  padding: 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  line-height: 1 !important;
  user-select: none;
}

.chat-fab.hidden{ display:none; }

.chat-panel{
  position: fixed;
  right: 14px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 9999;
  width: min(92vw, 360px);
  height: min(70vh, 520px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 55px rgba(0,0,0,.20);
  display: none;
  overflow: hidden;
  flex-direction: column;
}

.chat-panel.open{ display:flex; }

.chat-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.22);
  z-index: 9998;
  display: none;
  touch-action: none;
}

.chat-backdrop.open{ display:block; }

body.chat-open{
  overflow: hidden;
}


.chat-head{
  padding: 10px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom: 1px solid rgba(0,0,0,.08);
}

.chat-close{
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,.15);
  background: #fff;
  color: #111;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-compose{
  padding: 10px 12px;
  display:flex;
  gap: 8px;
  border-bottom: 1px solid rgba(0,0,0,.08);
}

.chat-compose textarea{
  flex:1;
  min-height: 44px;
  max-height: 120px;
  border-radius: 10px;
  border:1px solid rgba(0,0,0,.15);
  padding: 10px;
  font-size: 16px; /* evita zoom iOS */
  line-height: 1.25;
  color: #111;
  background: #fff;
  caret-color: #111;
  resize: none;
}

.chat-compose button{
  height: 38px;
  border-radius:10px;
  padding: 0 12px;
  white-space: nowrap;
}

.chat-body{
  padding: 12px;
  flex: 1;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  font-size: 14px;
}

.chat-msg{ margin: 10px 0; }
.chat-msg.user{ text-align:right; }

.chat-bubble{
  display:inline-block;
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  background: #f3f4f6;
  color:#111;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg.user .chat-bubble{ background:#111; color:#fff; }

/* (chat-foot removido; input fica no topo para evitar teclado a sobrepor) */

/* Mobile: bottom-sheet, full-width, melhor espaço e teclado */
@media (max-width: 520px){
  /* Botão pequeno a meio do ecrã, lado direito */
  .chat-fab{
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    right: 6px !important;
    width: 26px !important;
    height: 26px !important;
    border-radius: 999px;
    font-size: 12px;
    padding: 0 !important;
    line-height: 1;
  }

  /* Chat compacto (não ocupa o ecrã todo) */
  .chat-panel{
    left: auto;
    right: 10px;
    top: 10px;
    bottom: auto;
    width: min(86vw, 320px);
    height: min(62vh, 420px);
    border-radius: 16px;
  }

  .chat-head{ padding: 10px; }
  .chat-compose{ padding: 10px; flex-direction: column; align-items: stretch; }
  .chat-compose button{ width: 100%; }
  .chat-body{ padding: 10px; font-size: 14px; }
}

/* Extra small phones */
@media (max-width: 360px){
  .chat-compose button{ padding: 0 10px; }
}