/*
  Chat Dona Assuncao
  Widget publico da Acao Social Semear.
*/

:root {
  --dona-green: #238744;
  --dona-green-dark: #166534;
  --dona-green-soft: #e9f7ed;
  --dona-surface: #ffffff;
  --dona-paper: #fafaf6;
  --dona-line: rgba(15, 23, 42, 0.1);
  --dona-text: #111827;
  --dona-muted: #6b7280;
  --dona-shadow: 0 24px 70px rgba(15, 23, 42, 0.26);
}

.dona-fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  z-index: 30000;
  width: 66px;
  height: 66px;
  border: 0;
  border-radius: 999px;
  padding: 3px;
  cursor: pointer;
  background: linear-gradient(145deg, #1f8f46, #2fb35a);
  box-shadow: 0 16px 34px rgba(35, 135, 68, 0.36);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease,
    opacity 0.22s ease;
  animation: donaFabPulse 4s ease-in-out infinite;
}

.dona-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 20px 44px rgba(35, 135, 68, 0.44);
}

.dona-fab.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.94);
}

.dona-fab__photo {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  background: #eef7ee;
  border: 2px solid rgba(255, 255, 255, 0.88);
}

.dona-fab__status {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #22c55e;
  border: 3px solid #fff;
}

.dona-fab__hint {
  position: absolute;
  right: 78px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  color: #12311f;
  background: #fff;
  border: 1px solid rgba(35, 135, 68, 0.16);
  border-radius: 999px;
  padding: 9px 12px;
  font: 700 0.78rem/1 "DM Sans", Arial, sans-serif;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.dona-fab__hint::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -5px;
  width: 10px;
  height: 10px;
  transform: translateY(-50%) rotate(45deg);
  background: #fff;
  border-top: 1px solid rgba(35, 135, 68, 0.16);
  border-right: 1px solid rgba(35, 135, 68, 0.16);
}

@keyframes donaFabPulse {
  0%,
  100% {
    box-shadow: 0 16px 34px rgba(35, 135, 68, 0.36);
  }
  50% {
    box-shadow: 0 18px 42px rgba(35, 135, 68, 0.5);
  }
}

.dona-chat {
  position: fixed;
  top: max(18px, env(safe-area-inset-top, 0px));
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  z-index: 30001;
  width: min(430px, calc(100vw - 28px));
  max-height: min(760px, calc(100dvh - 36px));
  display: none;
  flex-direction: column;
  overflow: hidden;
  color: var(--dona-text);
  background: var(--dona-surface);
  border: 1px solid var(--dona-line);
  border-radius: 20px;
  box-shadow: var(--dona-shadow);
  font-family: "DM Sans", Arial, sans-serif;
}

.dona-chat.active {
  display: flex;
  animation: donaChatIn 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes donaChatIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dona-chat-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 13px;
  align-items: center;
  padding: 17px 18px;
  background: #fff;
  border-bottom: 1px solid var(--dona-line);
}

.dona-avatar {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  overflow: hidden;
  background: #eef7ee;
  box-shadow: inset 0 0 0 1px rgba(35, 135, 68, 0.12);
}

.dona-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dona-info {
  min-width: 0;
}

.dona-info strong {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #111827;
  font-size: 1rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.dona-info strong::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background:
    linear-gradient(#1fa463, #1fa463),
    #1fa463;
  box-shadow: inset 0 0 0 4px #e7f7ee;
}

.dona-info small {
  display: block;
  margin-top: 3px;
  color: var(--dona-muted);
  font-size: 0.79rem;
  line-height: 1.25;
}

.dona-presence {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  color: #1f7a3c;
  font-size: 0.78rem;
  font-weight: 700;
}

.dona-presence::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #22a447;
  box-shadow: 0 0 0 4px rgba(34, 164, 71, 0.12);
}

.dona-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  color: #374151;
  background: transparent;
  font-size: 1.08rem;
  transition:
    background 0.18s ease,
    color 0.18s ease;
}

.dona-close:hover {
  color: #111827;
  background: #f3f4f6;
}

.dona-messages {
  flex: 1;
  min-height: 0;
  max-height: 490px;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  background:
    radial-gradient(circle at 12px 12px, rgba(35, 135, 68, 0.035) 0 2px, transparent 2px 22px),
    var(--dona-paper);
}

.dona-messages::-webkit-scrollbar {
  width: 8px;
}

.dona-messages::-webkit-scrollbar-thumb {
  background: rgba(17, 24, 39, 0.16);
  border-radius: 999px;
}

.dona-msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  animation: donaMsgIn 0.2s ease both;
}

.dona-msg__bubble {
  padding: 11px 13px;
  border-radius: 14px;
  font-size: 0.91rem;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.dona-msg__time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #8a8f99;
  font-size: 0.68rem;
  line-height: 1;
  padding: 0 4px;
}

.dona-msg.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.dona-msg.bot .dona-msg__bubble {
  color: #1f2937;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 5px;
}

.dona-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.dona-msg.user .dona-msg__bubble {
  color: #18311f;
  background: #dcf8d3;
  border: 1px solid rgba(35, 135, 68, 0.12);
  border-bottom-right-radius: 5px;
}

.dona-msg.user .dona-msg__time::after {
  content: "✓✓";
  color: #238744;
  letter-spacing: -2px;
}

@keyframes donaMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dona-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: max-content;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 14px 14px 14px 5px;
  background: #fff;
}

.dona-typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #8fb99a;
  animation: donaTyping 1.2s infinite ease-in-out;
}

.dona-typing span:nth-child(2) {
  animation-delay: 0.16s;
}

.dona-typing span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes donaTyping {
  0%,
  70%,
  100% {
    opacity: 0.34;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.dona-actions {
  display: grid;
  gap: 8px;
  align-self: flex-start;
  width: min(100%, 300px);
  margin-top: 2px;
}

.dona-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid rgba(35, 135, 68, 0.72);
  border-radius: 10px;
  color: #1f7a3c;
  background: #fff;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 800;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.dona-cta:hover {
  color: #fff;
  background: var(--dona-green);
  transform: translateY(-1px);
}

.dona-sugestoes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px 14px;
  background: var(--dona-paper);
  border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.dona-sug-btn {
  border: 1px solid #d6eadb;
  border-radius: 999px;
  padding: 8px 12px;
  color: #376246;
  background: #fff;
  font: 800 0.78rem/1.15 "DM Sans", Arial, sans-serif;
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.dona-sug-btn:hover {
  border-color: rgba(35, 135, 68, 0.34);
  background: var(--dona-green-soft);
  transform: translateY(-1px);
}

.dona-input-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 14px 18px;
  background: #fff;
  border-top: 1px solid var(--dona-line);
}

.dona-input-icon {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: #4b5563;
  border: 1px solid #edf0f2;
  border-radius: 999px;
  background: #fff;
}

.dona-input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  outline: 0;
  color: var(--dona-text);
  background: #fff;
  font: 500 0.9rem/1.2 "DM Sans", Arial, sans-serif;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.dona-input:focus {
  border-color: rgba(35, 135, 68, 0.6);
  box-shadow: 0 0 0 4px rgba(35, 135, 68, 0.1);
}

.dona-input::placeholder {
  color: #9ca3af;
}

.dona-send {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--dona-green), #2da34e);
  cursor: pointer;
  font-size: 1rem;
  box-shadow: 0 10px 20px rgba(35, 135, 68, 0.24);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    opacity 0.18s ease;
}

.dona-send:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 12px 26px rgba(35, 135, 68, 0.3);
}

.dona-send:disabled,
.dona-input:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

body.etapa1 .dona-fab,
body.etapa1 .dona-chat {
  right: calc(280px + 1.5rem);
  bottom: 1.5rem;
}

@media (max-width: 1023px) {
  body.etapa1 .dona-fab,
  body.etapa1 .dona-chat {
    right: 18px;
    bottom: calc(70px + 18px);
  }
}

@media (max-width: 560px) {
  .dona-fab {
    width: 62px;
    height: 62px;
    right: 14px;
    bottom: 14px;
  }

  .dona-fab__hint {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    right: 70px;
    max-width: calc(100vw - 98px);
    padding: 8px 11px;
    font-size: 0.74rem;
  }

  .dona-chat,
  body.etapa1 .dona-chat {
    inset: 72px 8px 8px 8px;
    width: auto;
    max-height: calc(100dvh - 80px);
    border-radius: 18px;
  }

  .dona-chat-header {
    padding: 14px;
  }

  .dona-messages {
    min-height: 280px;
    max-height: none;
    padding: 14px;
  }

  .dona-msg {
    max-width: 88%;
  }

  .dona-sugestoes {
    padding: 10px 14px 12px;
  }

  .dona-input-bar {
    grid-template-columns: 36px minmax(0, 1fr) 46px;
    padding: 12px 14px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .dona-input {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dona-fab,
  .dona-chat.active,
  .dona-msg,
  .dona-typing span {
    animation: none;
  }

  .dona-fab,
  .dona-send,
  .dona-sug-btn,
  .dona-cta {
    transition: none;
  }
}
