/* --------------------------------------------------------------------------
   Chat IA flutuante — MVP-1, Fase 1b (UI + backend mock)
   Reaproveita os tokens de :root definidos em styles.css
   -------------------------------------------------------------------------- */

.chat-fab {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 20px 0 18px;
  border-radius: 999px;
  background: var(--blue-900);
  color: var(--white);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 650;
  box-shadow: 0 16px 40px rgba(20, 34, 87, .26);
  transition: transform 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}

.chat-fab:hover {
  background: var(--blue-700);
  transform: translateY(-2px);
  box-shadow: 0 20px 52px rgba(20, 34, 87, .32);
}

.chat-fab .chat-fab-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 17px;
  line-height: 1;
}

.chat-fab.is-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(.9);
}

.chat-panel {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 46;
  display: flex;
  flex-direction: column;
  width: clamp(320px, 92vw, 404px);
  height: min(72vh, 620px);
  overflow: hidden;
  border: 1px solid rgba(232, 236, 242, .9);
  border-radius: 22px;
  background: var(--white);
  box-shadow: 0 34px 100px rgba(6, 19, 55, .28);
  font-family: var(--font);
  transform-origin: bottom right;
  animation: chatPanelIn 200ms var(--ease);
}

.chat-panel[hidden] {
  display: none;
}

@keyframes chatPanelIn {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
  display: grid;
  gap: 3px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle at 92% 0%, rgba(238, 245, 255, .9), transparent 60%),
    var(--white);
}

.chat-header h2 {
  margin: 0;
  color: var(--blue-900);
  font-size: 17px;
  letter-spacing: -.02em;
}

.chat-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.chat-close {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-size: 19px;
  line-height: 1;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}

.chat-close:hover {
  background: var(--blue-soft);
  color: var(--blue-900);
}

.chat-demo-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.chat-log {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(20, 34, 87, .3) transparent;
}

.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(20, 34, 87, .28);
  background-clip: content-box;
}

.chat-msg {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-msg.is-user {
  align-self: flex-end;
  background: var(--blue-900);
  color: var(--white);
  border-bottom-right-radius: 6px;
}

.chat-msg.is-bot {
  align-self: flex-start;
  background: var(--surface-soft);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.chat-msg strong { font-weight: 680; }

.chat-msg .chat-msg-label {
  display: block;
  margin: 10px 0 3px;
  color: var(--blue-700);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.chat-msg .chat-msg-label:first-child { margin-top: 0; }

.chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.chat-source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid rgba(23, 57, 182, .2);
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-900);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms var(--ease), transform 150ms var(--ease);
}

.chat-source:hover {
  background: #e0ecff;
  transform: translateY(-1px);
}

.chat-source::before {
  content: "↗";
  font-size: 11px;
  opacity: .7;
}

.chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 14px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: var(--surface-soft);
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatDot 1.1s var(--ease) infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes chatDot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 4px;
}

.chat-suggestion {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms var(--ease), color 150ms var(--ease), background 150ms var(--ease);
}

.chat-suggestion:hover {
  border-color: rgba(23, 76, 222, .3);
  background: var(--blue-soft);
  color: var(--blue-900);
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--white);
}

.chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 14px;
  border: 1px solid rgba(209, 216, 232, .96);
  border-radius: 14px;
  outline: 0;
  resize: none;
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.45;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
}

.chat-input:focus {
  border-color: rgba(23, 76, 222, .34);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(23, 76, 222, .08);
}

.chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: var(--blue-900);
  color: var(--white);
  font-size: 17px;
  transition: background 150ms var(--ease), transform 150ms var(--ease);
}

.chat-send:hover { background: var(--blue-700); transform: translateY(-1px); }
.chat-send:disabled { opacity: .45; cursor: default; transform: none; }

/* Indisponível enquanto o portal está travado pelo PIN */
body.is-locked .chat-fab,
body.is-locked .chat-panel {
  display: none !important;
}

@media (max-width: 600px) {
  .chat-panel {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    height: min(82vh, 640px);
  }
  .chat-fab { right: 14px; bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel,
  .chat-typing span { animation: none; }
  .chat-fab,
  .chat-source,
  .chat-send { transition: none; }
}
