/* Widget RIA — site Rational Innovation */
.ria-chat-root {
  --ria-navy: #0b3d5c;
  --ria-gold: #f5a623;
  --ria-bg: #f4f7fa;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.ria-chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  z-index: 10050;
  background: var(--ria-navy);
  box-shadow: 0 8px 28px rgba(11, 61, 92, 0.45);
  overflow: visible;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.ria-chat-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 12px 36px rgba(11, 61, 92, 0.55);
}
.ria-chat-fab.is-open {
  transform: scale(0.92);
  opacity: 0;
  pointer-events: none;
}
.ria-chat-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid #fff;
  display: block;
}
.ria-chat-fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(245, 166, 35, 0.7);
  animation: riaPulse 2s ease infinite;
  pointer-events: none;
}
@keyframes riaPulse {
  0% { transform: scale(1); opacity: 0.9; }
  70% { transform: scale(1.2); opacity: 0; }
  100% { opacity: 0; }
}

/* Fundo escurecido (telemóvel) */
.ria-chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10049;
  background: rgba(8, 28, 42, 0.45);
  border: 0;
  padding: 0;
  cursor: pointer;
}
.ria-chat-root.is-open .ria-chat-backdrop {
  display: block;
}

.ria-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 100px;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 120px));
  max-height: calc(100dvh - 100px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(11, 61, 92, 0.28);
  z-index: 10051;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(11, 61, 92, 0.08);
  box-sizing: border-box;
}
.ria-chat-panel[hidden] {
  display: none !important;
}
.ria-chat-panel *,
.ria-chat-panel *::before,
.ria-chat-panel *::after {
  box-sizing: border-box;
}

.ria-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #0b3d5c, #145a7a);
  color: #fff;
  flex: 0 0 auto;
}
.ria-chat-head-av {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.85);
  flex-shrink: 0;
}
.ria-chat-head-text {
  flex: 1;
  min-width: 0;
}
.ria-chat-head strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  margin: 0;
  padding: 0;
}
.ria-chat-head span {
  display: block;
  font-size: 12px;
  opacity: 0.85;
  margin: 0;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ria-chat-close {
  margin-left: 4px;
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
}

.ria-chat-msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 14px;
  background: var(--ria-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}

.ria-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.ria-msg.is-me {
  align-self: flex-end;
  background: var(--ria-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ria-msg.is-ria {
  align-self: flex-start;
  background: #fff;
  color: #1a2a33;
  border-bottom-left-radius: 4px;
  border: 1px solid #e2ebf2;
}
.ria-msg.is-staff {
  align-self: flex-start;
  background: #fff8eb;
  border: 1px solid #f0d9a8;
  border-bottom-left-radius: 4px;
}
.ria-msg.is-sys {
  align-self: center;
  background: transparent;
  box-shadow: none;
  color: #6a7a88;
  font-size: 12px;
  text-align: center;
  max-width: 95%;
}
.ria-msg-who {
  font-size: 11px;
  font-weight: 700;
  color: #5a7a90;
  margin-bottom: 2px;
}

.ria-chat-footer {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid #e8eef3;
  position: relative;
  z-index: 3;
}
.ria-chat-actions {
  flex: 0 0 auto;
  padding: 8px 12px 0;
  background: #fff;
}
.ria-chat-human {
  width: 100%;
  border: 1px solid #f0d9a8;
  background: #fff8eb;
  color: var(--ria-navy);
  font-weight: 700;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin: 0;
}
.ria-chat-human:disabled {
  opacity: 0.65;
  cursor: default;
}
.ria-chat-human:not(:disabled):hover {
  border-color: var(--ria-gold);
  background: #ffefd2;
}

.ria-chat-form {
  flex: 0 0 auto;
  padding: 10px 12px 12px;
  background: #fff;
  border-top: 0;
  position: relative;
  z-index: 2;
}
.ria-chat-name {
  width: 100%;
  border: 1px solid #d7e1ea;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  margin: 0 0 8px;
}
.ria-chat-name.is-hidden {
  display: none !important;
}
.ria-chat-compose {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ria-chat-compose input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid #d7e1ea;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 16px;
  outline: none;
  margin: 0;
  background: #fff;
  color: #1a2a33;
}
.ria-chat-compose input:focus {
  border-color: #8eb4cc;
}
.ria-chat-compose button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--ria-gold);
  color: var(--ria-navy);
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
}

.ria-chat-attach {
  width: 40px !important;
  height: 40px !important;
  background: #e8eef3 !important;
  color: var(--ria-navy) !important;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.ria-chat-attach.is-open {
  background: var(--ria-navy) !important;
  color: #fff !important;
}
.ria-chat-sheet {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 12px;
  background: #f7fafc;
  border-top: 1px solid #e8eef3;
  flex: 0 0 auto;
}
.ria-chat-sheet[hidden],
.ria-chat-pending[hidden] {
  display: none !important;
}
.ria-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: #334;
  padding: 6px 4px;
  margin: 0;
}
.ria-sheet-ico {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
}
.ria-ico-gallery { background: #5b7cfa; }
.ria-ico-camera { background: #25d366; }
.ria-ico-loc { background: #1da851; }

.ria-chat-pending {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid #e8eef3;
  overflow-x: auto;
  flex: 0 0 auto;
}
.ria-pending-img {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}
.ria-pending-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.ria-pending-img button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #333;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.ria-atts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.ria-att-img img {
  max-width: 220px;
  max-height: 180px;
  border-radius: 10px;
  display: block;
}
.ria-loc {
  display: flex;
  gap: 8px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  background: rgba(0,0,0,.04);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 4px;
}
.ria-msg.is-me .ria-loc { background: rgba(255,255,255,.12); color: #fff; }
.ria-loc-ico { font-size: 22px; }
.ria-loc strong { display: block; font-size: 13px; }
.ria-loc em { font-style: normal; font-size: 11px; opacity: .8; }

.ria-chat-head-calls {
  display: flex;
  gap: 4px;
  margin-left: 4px;
  flex-shrink: 0;
}
.ria-chat-call-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  margin: 0;
  padding: 0;
}
.ria-chat-call-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.ria-chat-call-btn:not(:disabled):hover {
  background: rgba(255,255,255,.3);
}

/* —— Telemóvel: bottom sheet (não ecrã inteiro rígido) —— */
@media (max-width: 640px) {
  .ria-chat-fab {
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
  }

  .ria-chat-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(88dvh, 720px);
    max-height: calc(100dvh - 48px);
    border-radius: 18px 18px 0 0;
    border: 0;
    box-shadow: 0 -10px 40px rgba(11, 61, 92, 0.22);
  }

  .ria-chat-head {
    padding-top: 14px;
    border-radius: 18px 18px 0 0;
  }

  .ria-chat-form {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }

  /* No telemóvel o nome fica escondido (usa "Visitante" / localStorage) */
  .ria-chat-name {
    display: none !important;
  }

  .ria-chat-human {
    font-size: 12px;
    padding: 7px 8px;
  }

  .ria-att-img img {
    max-width: min(220px, 70vw);
    max-height: 160px;
  }

  .ria-chat-head-text span {
    font-size: 11px;
  }
}

/* Impedir scroll do site por baixo — sem bloquear toques no chat */
body.ria-chat-lock {
  overflow: hidden !important;
  overscroll-behavior: none;
}
body.ria-chat-lock .ria-chat-msgs {
  touch-action: pan-y;
}

/* Atalhos comerciais — funil guiado */
.ria-chat-quick {
  flex: 0 1 auto;
  max-height: 38%;
  overflow-y: auto;
  padding: 8px 12px 4px;
  background: var(--ria-bg, #f4f7fa);
}
.ria-chat-quick-hint {
  font-size: 12px;
  font-weight: 600;
  color: #5a6b7d;
  margin: 0 0 6px;
}
.ria-chat-quick-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ria-chat-quick button {
  border: 1px solid #d5dee8;
  background: #fff;
  color: #0b3d5c;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
}
.ria-chat-quick button:hover {
  border-color: #f5a623;
  background: #fff8ec;
}
.ria-chat-quick button.is-back {
  background: transparent;
  border-style: dashed;
  color: #8896a6;
  font-weight: 500;
}

/* —— Hostess: RIA sempre animada + bolha máquina de escrever —— */
.ria-chat-fab.is-hostess {
  animation: riaHostessFloat 3.2s ease-in-out infinite;
}
.ria-chat-fab.is-hostess .ria-chat-fab-pulse {
  animation: riaPulse 1.6s ease infinite;
}
@keyframes riaHostessFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.ria-hostess {
  position: fixed;
  right: 16px;
  bottom: 100px;
  z-index: 10051;
  max-width: min(260px, calc(100vw - 96px));
  pointer-events: none;
}
.ria-hostess[hidden] {
  display: none !important;
}

.ria-hostess-bubble {
  pointer-events: auto;
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 14px 14px;
  border: 0;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: #0b3d5c;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(11, 61, 92, 0.22);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.ria-hostess-bubble.is-show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.ria-hostess-bubble:hover {
  box-shadow: 0 12px 32px rgba(11, 61, 92, 0.3);
}
.ria-hostess-bubble::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -8px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 3px 3px 6px rgba(11, 61, 92, 0.08);
  border-radius: 2px;
}
.ria-hostess-bubble {
  position: relative;
}

.ria-hostess-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.ria-hostess-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: #f5a623;
  animation: riaCaretBlink 0.75s step-end infinite;
}
@keyframes riaCaretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@media (max-width: 480px) {
  .ria-hostess {
    right: 12px;
    bottom: 96px;
    max-width: min(220px, calc(100vw - 88px));
  }
  .ria-hostess-bubble {
    font-size: 13px;
    padding: 10px 12px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ria-chat-fab.is-hostess,
  .ria-chat-fab.is-hostess .ria-chat-fab-pulse,
  .ria-hostess-caret {
    animation: none;
  }
  .ria-hostess-bubble {
    transition: none;
  }
}
