/* ===== AstroBot — painel de chat flutuante ===== */

.astrobot-panel {
  position: fixed;
  right: 1.5rem;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 5rem);
  width: min(420px, calc(100vw - 2rem));
  height: min(620px, calc(100vh - 7rem));
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: rgba(10, 12, 30, 0.92);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 20px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 0 40px rgba(0, 212, 255, 0.15);
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease;
}
.astrobot-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Header */
.astrobot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(138, 43, 226, 0.08));
}
.astrobot-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.astrobot-avatar {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.5));
}
.astrobot-title strong {
  display: block;
  font-family: var(--font-h, 'Orbitron', sans-serif);
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  letter-spacing: 0.5px;
}
.astrobot-title small {
  display: block;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.5);
  font-family: monospace;
}
.astrobot-actions {
  display: flex;
  gap: 0.35rem;
}
.astrobot-btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.astrobot-btn-icon:hover {
  background: rgba(0, 212, 255, 0.15);
  color: #fff;
  transform: translateY(-1px);
}
.astrobot-btn-icon.astrobot-btn-active {
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.35), rgba(0, 212, 255, 0.25));
  border-color: rgba(138, 43, 226, 0.5);
  color: #fff;
  box-shadow: 0 0 10px rgba(138, 43, 226, 0.4);
}

/* Bloco de raciocínio (thinking) */
details.astrobot-think {
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(138, 43, 226, 0.1);
  border: 1px dashed rgba(138, 43, 226, 0.35);
  border-radius: 8px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}
details.astrobot-think > summary {
  cursor: pointer;
  color: #c5a0ff;
  font-weight: 600;
  user-select: none;
}
details.astrobot-think[open] > summary { margin-bottom: 0.4rem; }
details.astrobot-think > div {
  white-space: pre-wrap;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
.astrobot-think-label {
  color: #c5a0ff;
  font-size: 0.8rem;
  font-weight: 600;
  margin-right: 0.4rem;
}

/* Mensagens */
.astrobot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.3) transparent;
}
.astrobot-messages::-webkit-scrollbar { width: 6px; }
.astrobot-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.3);
  border-radius: 3px;
}

.astrobot-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  padding: 1.5rem 0.5rem;
}
.astrobot-empty-icon { font-size: 2.6rem; margin-bottom: 0.5rem; }
.astrobot-empty h4 {
  font-family: var(--font-h, 'Orbitron', sans-serif);
  font-size: 1.1rem;
  color: #fff;
  margin: 0 0 0.35rem;
}
.astrobot-empty p { font-size: 0.85rem; color: rgba(255,255,255,0.7); margin: 0 0 1rem; line-height: 1.5; }
.astrobot-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}
.astrobot-suggest button {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #a0e8ff;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s ease;
}
.astrobot-suggest button:hover {
  background: rgba(0, 212, 255, 0.2);
  color: #fff;
}

.astrobot-msg {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  animation: astroFadeIn 0.25s ease;
}
@keyframes astroFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.astrobot-msg-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
.astrobot-msg-user .astrobot-msg-avatar {
  background: rgba(0, 212, 255, 0.15);
  order: 2;
}
.astrobot-msg-user { flex-direction: row-reverse; }
.astrobot-msg-body {
  max-width: 82%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.87rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.92);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.astrobot-msg-user .astrobot-msg-body {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.22), rgba(0, 153, 204, 0.18));
  border: 1px solid rgba(0, 212, 255, 0.35);
  border-top-right-radius: 4px;
}
.astrobot-msg-assistant .astrobot-msg-body {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top-left-radius: 4px;
}

/* Markdown dentro das mensagens */
.astrobot-msg-body h1,
.astrobot-msg-body h2,
.astrobot-msg-body h3,
.astrobot-msg-body h4 {
  font-family: var(--font-h, 'Orbitron', sans-serif);
  color: #a0e8ff;
  margin: 0.5rem 0 0.3rem;
  line-height: 1.3;
}
.astrobot-msg-body h1 { font-size: 1rem; }
.astrobot-msg-body h2 { font-size: 0.95rem; }
.astrobot-msg-body h3 { font-size: 0.9rem; }
.astrobot-msg-body h4 { font-size: 0.85rem; }
.astrobot-msg-body ul,
.astrobot-msg-body ol {
  margin: 0.4rem 0 0.4rem 1.25rem;
  padding: 0;
}
.astrobot-msg-body li { margin: 0.15rem 0; }
.astrobot-msg-body strong { color: #fff; }
.astrobot-msg-body em { color: #d4b4ff; font-style: italic; }
.astrobot-msg-body code {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-family: 'Courier New', monospace;
  font-size: 0.85em;
  color: #ffd580;
}
.astrobot-msg-body pre {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  font-size: 0.8rem;
}
.astrobot-msg-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: #d4f4ff;
}
.astrobot-error { color: #ff8a8a; }
.astrobot-hint-wait {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-top: 6px;
  font-style: italic;
}

/* Indicador de "digitando" */
.astrobot-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.astrobot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a0e8ff;
  opacity: 0.6;
  animation: astroTypeBounce 1.2s infinite;
}
.astrobot-typing span:nth-child(2) { animation-delay: 0.15s; }
.astrobot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes astroTypeBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* Input */
.astrobot-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
  align-items: flex-end;
}
#astrobot-input {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 140px;
  padding: 0.55rem 0.8rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
#astrobot-input:focus {
  border-color: rgba(0, 212, 255, 0.5);
  background: rgba(255, 255, 255, 0.08);
}
.astrobot-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #00d4ff, #8a2be2);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 212, 255, 0.35);
}
.astrobot-send:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 212, 255, 0.55);
}
.astrobot-send:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ===== Botão flutuante AstroBot ===== */
.fab-trigger.fab-astrobot {
  background: linear-gradient(135deg, #00d4ff, #8a2be2) !important;
  box-shadow:
    0 8px 28px rgba(0, 212, 255, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
  animation: astroFabPulse 3s infinite;
}
@keyframes astroFabPulse {
  0%, 100% { box-shadow: 0 8px 28px rgba(0, 212, 255, 0.4), 0 0 0 1px rgba(255,255,255,0.1); }
  50%      { box-shadow: 0 8px 28px rgba(138, 43, 226, 0.55), 0 0 0 4px rgba(0, 212, 255, 0.15); }
}

/* Mobile */
@media (max-width: 520px) {
  .astrobot-panel {
    right: 0.5rem;
    left: 0.5rem;
    bottom: 4.5rem;
    width: auto;
    height: min(75vh, 560px);
    max-height: calc(100vh - 6rem);
  }
}
