/* ================================================
   CHAT ASSISTANT - SIAPE
   Estilos do botao flutuante e painel de chat
   Usa variaveis CSS do design system Comerc
   ================================================ */

/* --- FAB (Floating Action Button) --- */
.chat-fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
}

.chat-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--comerc-green, #94D600);
  border: none;
  color: #FFFFFF;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-lg, 0 8px 20px rgba(0,0,0,0.15));
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-fab:hover {
  background: var(--comerc-green-dark, #6BA800);
  box-shadow: var(--shadow-xl, 0 12px 28px rgba(0,0,0,0.18));
  transform: scale(1.05);
}

.chat-fab:active {
  transform: scale(0.95);
}

@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(148, 214, 0, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(148, 214, 0, 0); }
}

.chat-fab-pulse {
  animation: chat-pulse 2s ease-in-out 3;
}

/* --- Chat Hidden (non-admin) --- */
.chat-hidden {
  display: none !important;
}

/* --- Chat Panel --- */
.chat-panel-container {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  height: 100vh;
  z-index: 9998;
  transition: transform 0.3s ease;
  transform: translateX(100%);
  display: flex;
  flex-direction: column;
  background: var(--comerc-white, #FFFFFF);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

/* --- Panel Header --- */
.chat-header {
  background: linear-gradient(135deg, #1A1A1A 0%, #2D3436 100%);
  color: #FFFFFF;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 56px;
}

.chat-header-title {
  flex: 1;
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-size: var(--font-size-base, 1rem);
  font-weight: 500;
  margin: 0;
}

.chat-header-icon {
  color: var(--comerc-green, #94D600);
  font-size: 18px;
}

.chat-header-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.chat-header-btn:hover {
  color: #FFFFFF;
  background: rgba(255,255,255,0.1);
}

/* --- Model Dropdown (inside dark header) --- */
.chat-model-dropdown {
  width: 160px;
  flex-shrink: 0;
}

.chat-model-dropdown .Select-control {
  background: rgba(255,255,255,0.1) !important;
  border: 1px solid rgba(255,255,255,0.2) !important;
  border-radius: 4px !important;
  min-height: 28px !important;
  height: 28px !important;
}

.chat-model-dropdown .Select-value-label,
.chat-model-dropdown .Select-placeholder {
  color: rgba(255,255,255,0.9) !important;
  font-size: 11px !important;
  line-height: 26px !important;
}

.chat-model-dropdown .Select-arrow-zone {
  padding: 0 4px !important;
}

.chat-model-dropdown .Select-arrow {
  border-color: rgba(255,255,255,0.5) transparent transparent !important;
}

.chat-model-dropdown .Select-menu-outer {
  z-index: 10000 !important;
}

/* Menu aberto: texto escuro no fundo branco */
.chat-model-dropdown .VirtualizedSelectOption,
.chat-model-dropdown .Select-option {
  color: #2D3436 !important;
  font-size: 12px !important;
}

.chat-model-dropdown .VirtualizedSelectFocusedOption,
.chat-model-dropdown .Select-option.is-focused {
  background: #F5F7FA !important;
  color: #2D3436 !important;
}

.chat-model-dropdown .VirtualizedSelectSelectedOption,
.chat-model-dropdown .Select-option.is-selected {
  background: #94D600 !important;
  color: #1A1A1A !important;
}

/* Input de busca dentro do dropdown */
.chat-model-dropdown .Select-input input {
  color: #2D3436 !important;
}

/* --- Messages Area --- */
.chat-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--comerc-very-light, #F5F7FA);
}

.chat-messages-area::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-area::-webkit-scrollbar-thumb {
  background: var(--comerc-gray-light, #B0BEC5);
  border-radius: 3px;
}

/* --- Message Bubbles --- */
.chat-message {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-size: var(--font-size-sm, 0.875rem);
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message-user {
  align-self: flex-end;
  background: var(--comerc-green, #94D600);
  color: #1A1A1A;
  border-bottom-right-radius: 4px;
}

.chat-message-assistant {
  align-self: flex-start;
  background: var(--comerc-white, #FFFFFF);
  color: var(--comerc-dark-gray, #2D3436);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
}

.chat-welcome {
  background: linear-gradient(135deg, #FFFFFF 0%, #F5F7FA 100%);
  border-left: 3px solid var(--comerc-green, #94D600);
}

/* --- Inline Charts & Tables --- */
.chat-message-figure,
.chat-message-table {
  align-self: stretch;
  max-width: 100%;
  background: var(--comerc-white, #FFFFFF);
  border-radius: 8px;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
  padding: 8px;
  overflow: hidden;
}

.chat-graph-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
}

.chat-table-title {
  font-weight: 500;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--comerc-dark-gray, #2D3436);
  padding: 4px 8px 8px;
}

/* --- Markdown inside messages --- */
.chat-markdown p {
  margin: 0 0 8px;
}

.chat-markdown p:last-child {
  margin-bottom: 0;
}

.chat-markdown code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.85em;
}

.chat-markdown pre {
  background: #2D3436;
  color: #F5F7FA;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.8em;
  margin: 8px 0;
}

.chat-markdown pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* --- Input Area --- */
.chat-input-area {
  padding: 12px 16px;
  background: var(--comerc-white, #FFFFFF);
  border-top: 1px solid var(--comerc-light-gray, #ECEFF1);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input-wrapper {
  flex: 1;
}

.chat-input {
  width: 100%;
  border: 1px solid var(--comerc-gray-light, #B0BEC5);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font-primary, 'Roboto', sans-serif);
  font-size: var(--font-size-sm, 0.875rem);
  resize: none;
  min-height: 38px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--comerc-green, #94D600);
}

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--comerc-green, #94D600);
  border: none;
  color: #FFFFFF;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
  background: var(--comerc-green-dark, #6BA800);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-cancel-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--comerc-red, #EE5A52);
  border: none;
  color: #FFFFFF;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-cancel-btn:hover {
  background: #D32F2F;
}

/* --- Streaming text --- */
.chat-streaming {
  border-left: 2px solid var(--comerc-green, #94D600);
  animation: chat-stream-pulse 1s ease-in-out infinite;
  min-height: 20px;
}

@keyframes chat-stream-pulse {
  0%, 100% { border-left-color: var(--comerc-green, #94D600); }
  50% { border-left-color: transparent; }
}

/* --- Spinner --- */
.chat-spinner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--comerc-gray, #636E72);
  font-size: var(--font-size-xs, 0.75rem);
}

.chat-spinner-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--comerc-green, #94D600);
  animation: chat-bounce 1.4s ease-in-out infinite both;
}

.chat-spinner-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-spinner-dot:nth-child(2) { animation-delay: -0.16s; }
.chat-spinner-dot:nth-child(3) { animation-delay: 0s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* --- Error Message --- */
.chat-error {
  color: var(--comerc-red, #EE5A52);
  font-size: var(--font-size-xs, 0.75rem);
  padding: 4px 0;
  min-height: 16px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .chat-panel-container {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .chat-fab {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .chat-fab-container {
    bottom: 16px;
    right: 16px;
  }
}

/* --- Token Usage & Context Display --- */
.chat-token-display {
  border-top: 1px solid var(--comerc-light-gray, #ECEFF1);
  min-height: 0;
}

.chat-token-badge {
  display: block;
  font-size: 0.65rem;
  color: var(--comerc-gray, #636E72);
  margin-top: 4px;
  text-align: right;
  opacity: 0.7;
  font-family: 'Roboto Mono', monospace;
}

/* Session footer com progress bar */
.chat-session-footer {
  padding: 4px 0 2px;
}

.chat-ctx-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
}

.chat-ctx-bar-track {
  flex: 1;
  height: 6px;
  background: var(--comerc-light-gray, #ECEFF1);
  border-radius: 3px;
  overflow: hidden;
}

.chat-ctx-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
  min-width: 2px;
}

.chat-ctx-pct {
  font-size: 0.65rem;
  font-family: 'Roboto Mono', monospace;
  font-weight: 500;
  min-width: 32px;
  text-align: right;
}

.chat-ctx-green  { color: var(--comerc-green, #94D600); }
.chat-ctx-yellow { color: var(--comerc-yellow, #FFB74D); }
.chat-ctx-red    { color: var(--comerc-red, #EE5A52); }

.chat-ctx-stats {
  font-size: 0.65rem;
  color: var(--comerc-gray, #636E72);
  text-align: center;
  padding: 2px 0 0;
  font-family: 'Roboto Mono', monospace;
}
