/**
 * ORIZON OS - Assistente de IA Operacional
 * Chat flutuante, gravação de áudio, anexos e bottom-sheet no celular.
 * Segue o design system "Horizonte" (tokens em styles.css).
 */

/* ============================================================
   1. BOTÃO FLUTUANTE (FAB)
   ============================================================ */
.ai-fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 990;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-fab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--n-0);
  color: var(--n-800);
  border: 1px solid var(--n-200);
  padding: 9px 14px 9px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  position: relative;
  overflow: visible;
}

.ai-fab-btn:hover {
  background: var(--n-50);
  border-color: var(--n-300);
  box-shadow: var(--shadow-lg);
}

.ai-fab-btn:focus-visible {
  outline: 2px solid var(--a-500);
  outline-offset: 2px;
}

.ai-fab-btn:active {
  transform: scale(0.97);
}

.ai-fab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--a-600);
}

.ai-fab-icon svg {
  width: 18px;
  height: 18px;
}

.ai-fab-label {
  letter-spacing: 0;
  font-size: 13px;
}

.ai-fab-badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--s-500);
  border: 1.5px solid var(--n-0);
}

/* ============================================================
   2. PAINEL DO CHAT
   ============================================================ */
.ai-chat-panel {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 400px;
  height: 560px;
  max-height: calc(100vh - 110px);
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: 14px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 995;
  overflow: hidden;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: bottom right;
}

.ai-chat-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 12px 16px;
  background: var(--n-0);
  border-bottom: 1px solid var(--n-200);
  flex-shrink: 0;
}

.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ai-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--a-50);
  color: var(--a-600);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-header-avatar svg {
  width: 18px;
  height: 18px;
}

.ai-header-titles {
  min-width: 0;
}

.ai-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--n-900);
  line-height: 1.25;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-header-subtitle {
  font-size: 12px;
  color: var(--n-500);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--s-500);
  display: inline-block;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.ai-icon-btn {
  background: none;
  border: none;
  color: var(--n-500);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
  font-size: 18px;
}

.ai-icon-btn svg {
  width: 17px;
  height: 17px;
}

.ai-icon-btn:hover {
  background: var(--n-100);
  color: var(--n-900);
}

.ai-guardrail-banner {
  padding: 6px 16px;
  background: var(--n-50);
  border-bottom: 1px solid var(--n-200);
  font-size: 11.5px;
  color: var(--n-600);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ai-guardrail-banner strong {
  color: var(--n-800);
}

/* ============================================================
   3. MENSAGENS
   ============================================================ */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--n-25);
  scrollbar-width: thin;
  scrollbar-color: var(--n-300) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--n-300);
  border-radius: 4px;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: ai-msg-appear 0.18s ease-out;
}

@keyframes ai-msg-appear {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg.user {
  align-self: flex-end;
}

.ai-msg.assistant {
  align-self: flex-start;
}

.ai-msg-bubble {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.ai-msg.user .ai-msg-bubble {
  background: var(--a-600);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.ai-msg.assistant .ai-msg-bubble {
  background: var(--n-0);
  color: var(--n-800);
  border: 1px solid var(--n-200);
  border-bottom-left-radius: 4px;
}

.ai-msg-time {
  font-size: 11px;
  color: var(--n-500);
  margin-top: 4px;
  align-self: flex-end;
}

.ai-msg.assistant .ai-msg-time {
  align-self: flex-start;
}

.ai-quick-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ai-quick-chip {
  background: var(--n-0);
  border: 1px solid var(--n-300);
  color: var(--n-700);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  font-family: inherit;
}

.ai-quick-chip:hover {
  background: var(--a-50);
  border-color: var(--a-200);
  color: var(--a-700);
}

.ai-action-card {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--s-50);
  border: 1px solid var(--s-200);
  border-radius: 8px;
}

.ai-action-card.card-blocked {
  background: var(--d-50);
  border-color: var(--d-200);
}

.ai-action-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--n-900);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.ai-action-desc {
  font-size: 12px;
  color: var(--n-600);
  line-height: 1.4;
}

.ai-action-btn-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.ai-action-btn {
  background: var(--a-600);
  color: #ffffff;
  border: none;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.ai-action-btn:hover {
  background: var(--a-700);
}

.ai-audio-player-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.14);
  padding: 6px 10px;
  border-radius: 8px;
  margin-top: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.ai-msg.assistant .ai-audio-player-wrap {
  background: var(--n-50);
  border-color: var(--n-200);
}

.ai-audio-play-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--n-0);
  color: var(--a-600);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
}

.ai-audio-transcript {
  font-size: 12px;
  font-style: italic;
  opacity: 0.9;
  margin-top: 4px;
}

.ai-attachment-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 4px;
}

.ai-msg.assistant .ai-attachment-badge {
  background: var(--n-50);
  border-color: var(--n-200);
  color: var(--n-700);
}

.ai-attachment-img-preview {
  max-width: 100%;
  max-height: 140px;
  border-radius: 6px;
  border: 1px solid var(--n-200);
  margin-bottom: 4px;
  display: block;
}

/* ============================================================
   4. ENTRADA (TEXTO + ÁUDIO + ANEXO)
   ============================================================ */
.ai-chat-input-area {
  padding: 10px 12px;
  background: var(--n-0);
  border-top: 1px solid var(--n-200);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.ai-pending-attachments-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.ai-pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--n-100);
  border: 1px solid var(--n-200);
  color: var(--n-700);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.ai-pending-chip-remove {
  cursor: pointer;
  color: var(--d-600);
  font-weight: 600;
  margin-left: 2px;
}

.ai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  position: relative;
}

.ai-chat-textarea {
  flex: 1;
  min-height: 38px;
  max-height: 90px;
  background: var(--n-0) !important;
  border: 1px solid var(--n-300);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--n-900) !important;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  line-height: 1.4;
}

.ai-chat-textarea::placeholder {
  color: var(--n-500);
  font-size: 13px;
}

.ai-tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--n-200);
  background: var(--n-0);
  color: var(--n-600);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
  font-size: 16px;
}

.ai-tool-btn svg,
.ai-send-btn svg {
  width: 17px;
  height: 17px;
}

.ai-tool-btn:hover {
  background: var(--n-50);
  color: var(--n-900);
  border-color: var(--n-300);
}

.ai-tool-btn:active {
  transform: scale(0.95);
}

.ai-tool-btn.btn-mic:hover {
  background: var(--d-50);
  border-color: var(--d-200);
  color: var(--d-600);
}

.ai-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--a-600);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
  font-size: 15px;
}

.ai-send-btn:hover {
  background: var(--a-700);
}

.ai-send-btn:disabled {
  background: var(--n-200);
  color: var(--n-500);
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   5. GRAVAÇÃO DE ÁUDIO ATIVA
   ============================================================ */
.ai-recording-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--d-50);
  border: 1px solid var(--d-200);
  border-radius: 8px;
  padding: 6px 10px;
  gap: 8px;
}

.ai-recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.ai-recording-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--d-600);
  animation: ai-dot-blink 1s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes ai-dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.ai-recording-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--d-700);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.ai-recording-transcript-live {
  font-size: 12px;
  color: var(--n-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
  min-width: 0;
  flex: 1;
}

.ai-recording-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ai-rec-btn-cancel {
  background: var(--n-0);
  border: 1px solid var(--n-300);
  color: var(--n-700);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.ai-rec-btn-send {
  background: var(--d-600);
  border: none;
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================
   6. CELULAR (<= 768px)
   ============================================================ */
@media (max-width: 768px) {
  .ai-fab-container {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    right: 12px;
  }

  .ai-fab-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .ai-fab-label {
    display: none !important;
  }

  .ai-chat-panel {
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: calc(100vh - 48px) !important;
    max-height: 92vh !important;
    border-radius: 14px 14px 0 0 !important;
    border-bottom: none !important;
    box-shadow: var(--shadow-xl) !important;
  }

  .ai-chat-panel.hidden {
    transform: translateY(100%) !important;
  }

  .ai-chat-textarea {
    font-size: 16px !important;
  }

  .ai-chat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }
}
