/* ==========================================================
   DESIGN TOKENS: PALETA DE CORES (LIGHT / DARK)
   ========================================================== */

/* TEMA CLARO (Default) */
:root, [data-theme="light"], [data-bs-theme="light"] {
  --primary-color: #1A365D;       /* Azul petróleo institucional */
  --primary-hover: #152C4D;
  --accent-color: #0F766E;        /* Verde esmeralda escuro */
  
  --bg-app: #F8FAFC;              /* Fundo geral gelo */
  --bg-surface: #FFFFFF;          /* Superfície de cards e cabeçalhos */
  --bg-sidebar: #FFFFFF;          /* Fundo da barra lateral */
  --border-color: #E2E8F0;        /* Linhas divisórias sutis */
  
  --text-main: #1E293B;           /* Texto preto azulado de alto contraste */
  --text-muted: #64748B;          /* Texto secundário */
  --section-title: #475569;
  
  --chat-bg: #F1F5F9;             /* Fundo da rolagem das mensagens */
  --bubble-user-bg: #1A365D;      /* Balão do usuário */
  --bubble-user-text: #FFFFFF;
  --bubble-bot-bg: #FFFFFF;       /* Balão do assistente */
  --bubble-bot-text: #1E293B;
  --bubble-bot-border: #E2E8F0;
  
  --input-bg: #FFFFFF;
  --input-border: #CBD5E1;
  --input-text: #1E293B;
  
  --item-hover: #F1F5F9;
  --item-active: #E2E8F0;
  --btn-action-bg: #F1F5F9;
}

/* TEMA ESCURO (Dark Mode - Alto Contraste & Leitura Harmoniosa) */
[data-theme="dark"], [data-bs-theme="dark"] {
  --primary-color: #38BDF8;       /* Ciano vibrante para botões e links */
  --primary-hover: #0EA5E9;
  --accent-color: #2DD4BF;
  
  --bg-app: #0B1120;              /* Fundo preto azulado profundo */
  --bg-surface: #1E293B;          /* Cinza ardósia escuro */
  --bg-sidebar: #0F172A;          /* Sidebar escura elegante */
  --border-color: #334155;        /* Bordas bem definidas */
  
  --text-main: #F8FAFC;           /* Texto branco gelo legível */
  --text-muted: #94A3B8;          /* Texto secundário cinza claro */
  --section-title: #CBD5E1;
  
  --chat-bg: #0B132B;             /* Fundo escuro imersivo */
  --bubble-user-bg: #0284C7;      /* Azul vibrante com contraste AAA */
  --bubble-user-text: #FFFFFF;
  --bubble-bot-bg: #1E293B;       /* Card do robô destacado */
  --bubble-bot-text: #F1F5F9;
  --bubble-bot-border: #334155;
  
  --input-bg: #1E293B;
  --input-border: #475569;
  --input-text: #FFFFFF;
  
  --item-hover: #1E293B;
  --item-active: #334155;
  --btn-action-bg: #334155;
}

/* ==========================================================
   ESTRUTURA GERAL COM SUPORTE A TECLADO MOBILE (100dvh)
   ========================================================== */
html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-wrapper {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  transition: transform 0.3s ease;
  z-index: 1050;
}

.header-bar {
  background-color: var(--bg-surface) !important;
  border-color: var(--border-color) !important;
}

.brand-title {
  color: var(--text-main);
}

.section-title {
  color: var(--section-title);
  font-size: 0.7rem;
}

.sidebar-footer {
  background-color: var(--bg-surface);
  border-color: var(--border-color) !important;
}

/* Botão de Troca de Tema */
.btn-theme-toggle {
  background-color: var(--btn-action-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-theme-toggle:hover {
  filter: brightness(1.1);
  color: var(--primary-color);
}

.btn-action {
  background-color: var(--btn-action-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

/* Avatares */
.agent-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.agent-avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.agent-avatar-xs {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.badge-pulse {
  width: 8px;
  height: 8px;
  background-color: #10B981;
  border-radius: 50%;
  display: inline-block;
}

/* Histórico de Conversas */
.chat-history-item {
  border-radius: 8px !important;
  border: none !important;
  margin-bottom: 4px;
  padding: 8px 12px;
  cursor: pointer;
  background-color: transparent;
  color: var(--text-main);
  font-size: 0.88rem;
  transition: background-color 0.15s ease;
}

.chat-history-item:hover {
  background-color: var(--item-hover);
}

.chat-history-item.active {
  background-color: var(--item-active);
  font-weight: 600;
  color: var(--primary-color);
}

.delete-chat-btn {
  opacity: 0.6;
}
.delete-chat-btn:hover {
  opacity: 1;
}

/* Área de Mensagens */
.chat-messages {
  background-color: var(--chat-bg);
}

.message-row {
  display: flex;
  margin-bottom: 12px;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
  align-items: flex-start;
}

.message-bubble {
  max-width: 85%;
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.48;
  word-break: break-word;
}

.message-row.user .message-bubble {
  background-color: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.message-row.assistant .message-bubble {
  background-color: var(--bubble-bot-bg);
  color: var(--bubble-bot-text);
  border: 1px solid var(--bubble-bot-border);
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  white-space: normal;
}

/* Espaçamento Limpo de Markdown */
.message-bubble p {
  margin-bottom: 0.4rem;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble ul, .message-bubble ol {
  margin-top: 0.2rem;
  margin-bottom: 0.4rem;
  padding-left: 1.25rem;
}
.message-bubble li {
  margin-bottom: 0.2rem;
}
.message-bubble h1, .message-bubble h2, .message-bubble h3, .message-bubble h4 {
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-color);
}
.message-bubble hr {
  margin: 0.5rem 0;
  opacity: 0.15;
}

.message-time {
  font-size: 0.68rem;
  margin-top: 4px;
  opacity: 0.6;
}

/* Digitação */
.typing-pill {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

/* Footer / Input Fixo */
.chat-footer {
  background-color: var(--bg-surface);
  border-color: var(--border-color) !important;
  position: sticky;
  bottom: 0;
  z-index: 100;
}

.chat-input {
  background-color: var(--input-bg);
  border-color: var(--input-border);
  color: var(--input-text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  max-height: 120px;
}

.chat-input:focus {
  background-color: var(--input-bg);
  color: var(--input-text);
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.btn-send {
  height: 44px;
  border-radius: 10px;
}

.footer-caption {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* ==========================================================
   REGRAS ESPECÍFICAS PARA CELULAR / MOBILE
   ========================================================== */
@media (max-width: 767.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 15px rgba(0,0,0,0.25);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }

  .sidebar-backdrop.show {
    display: block;
  }

  /* Botão Hambúrguer em destaque */
  .btn-hamburger {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }

  .header-name {
    font-size: 1rem;
  }

  .header-subtitle {
    font-size: 0.72rem;
  }

  .agent-avatar {
    width: 38px;
    height: 38px;
  }

  /* Mensagens mais compactas no celular */
  .message-bubble {
    max-width: 90%;
    padding: 8px 12px;
    font-size: 0.88rem;
    line-height: 1.42;
  }

  .chat-footer {
    padding: 6px 10px !important;
  }

  .chat-input {
    font-size: 0.85rem;
    padding: 8px 10px;
  }

  .btn-send {
    height: 40px;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}
