:root {
  --font-scale: 1;
  --background: #f4f7fb; --background-soft: #ffffff; --background-strong: #e9eef7;
  --text: #18212f; --text-soft: #5d6878; --border: #dbe3ef;
  --primary: #2563eb; --primary-strong: #1d4ed8; --primary-soft: #dbeafe;
  --success: #16a34a; --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --header-height: 72px;
  --user-bubble: #2563eb; --assistant-bubble: #eef4ff; --assistant-text: #162033;
}

html[data-theme="dark"] {
  --background: #0b1220; --background-soft: #121b2c; --background-strong: #1a2438;
  --text: #e8edf7; --text-soft: #9ba8bd; --border: #23314b;
  --primary: #60a5fa; --primary-strong: #3b82f6; --primary-soft: rgba(59, 130, 246, 0.14);
  --success: #22c55e; --danger: #ef4444;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  --user-bubble: #3b82f6; --assistant-bubble: #182338; --assistant-text: #e8edf7;
}

* { box-sizing: border-box; }
html, body {
  /* A MÁGICA DO A+ E A- VOLTANDO AQUI: */
  font-size: calc(16px * var(--font-scale, 1));
  
  height: 100dvh; /* Altura exata da tela, ignorando barra de endereço */
  margin: 0;
  padding: 0;
  overflow: hidden; /* Proíbe a tela inteira de rolar */
  display: flex;
  flex-direction: column;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
  background-color: var(--background);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: transparent; transition: 0.2s ease; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Topo */
.top-bar { display: flex; align-items: center; justify-content: space-between; height: var(--header-height); padding: 0 16px; background: var(--background-soft); border-bottom: 1px solid var(--border); z-index: 30; }
.brand { font-weight: 700; font-size: 1.1rem; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--background); display: flex; align-items: center; justify-content: center; font-weight: bold; }
.toolbar-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-strong); }
.cart-btn-wrapper { position: relative; }
.cart-badge { position: absolute; top: -4px; right: -4px; background: var(--danger); color: white; font-size: 0.7rem; font-weight: bold; width: 18px; height: 18px; border-radius: 50%; display: none; align-items: center; justify-content: center; }
.cart-badge.active { display: flex; }

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden; /* Garante que as abas laterais não quebrem o layout */
  position: relative;
}

.panel { background: var(--background-soft); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.left-aside { width: 280px; }
.chat-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden; /* A seção do meio também não pode rolar */
}
.right-aside { width: 340px; transition: width 0.3s ease; }
.panel-header { padding: 16px; border-bottom: 1px solid var(--border); background: var(--background); }

/* Left Aside */
.lang-select { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--background-soft); margin-bottom: 16px; }
.btn-primary { width: 100%; padding: 12px; border-radius: 8px; background: var(--primary); color: white; font-weight: 600; text-align: center; }
.btn-primary:hover { background: var(--primary-strong); }
.history-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }

/* Right Aside */
.catalog-area { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.category-group { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--background-soft); }
.category-header { width: 100%; padding: 14px 16px; text-align: left; font-weight: 600; background: var(--background); display: flex; justify-content: space-between; align-items: center; }
.category-header::after { content: '+'; font-size: 1.2rem; transition: transform 0.2s; }
.category-group.open .category-header::after { content: '-'; }
.category-body { display: none; padding: 12px; border-top: 1px solid var(--border); }
.category-group.open .category-body { display: block; }
.product-list { 
  max-height: 300px; 
  overflow-y: auto; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  padding: 2px; /* Esse é o respiro para a borda não ser "comida" no hover */
}
/* Container para inputs com ícone */
.search-wrapper { 
  position: relative; 
  width: 100%; 
}

/* O ícone/emoji flutuando */
.search-icon { 
  position: absolute; 
  left: 12px; 
  top: 50%; 
  transform: translateY(-50%); 
  font-size: 1rem; 
  pointer-events: none; /* Faz o clique passar direto pro input */
}

/* Os inputs sem background de imagem, só com o espaçamento */
.search-input { 
  width: 100%; 
  padding: 12px 16px 12px 40px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  background-color: var(--background-soft); 
}

.internal-search { 
  width: 100%; 
  padding: 10px 12px 10px 36px; 
  border-radius: 6px; 
  border: 1px solid var(--border); 
  font-size: 0.85rem; 
  background-color: var(--background); 
}

/* Ajuste de margem para as buscas internas */
.category-body .search-wrapper { margin-bottom: 12px; }

/* Produto clicável */
.product-item { padding: 10px; border: 1px solid var(--border); border-radius: 6px; display: flex; flex-direction: column; gap: 4px; background: var(--background); cursor: pointer; transition: all 0.2s ease; }
.product-item:hover { background: var(--primary-soft); border-color: var(--primary); transform: translateY(-1px); }
.product-item-name { font-weight: 600; font-size: 0.9rem; pointer-events: none; }
.product-item-price { color: var(--primary-strong); font-weight: bold; font-size: 0.85rem; pointer-events: none; }

/* Classe para ocultar a aside */
.hide-aside { display: none !important; }

/* Chat Center & Cart */
.cart-inline-panel { display: none; background: var(--background-strong); border-bottom: 1px solid var(--border); padding: 16px; box-shadow: inset 0 -4px 6px rgba(0,0,0,0.02); }
.cart-inline-panel.active { display: block; animation: slideDown 0.3s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.cart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: bold; }
.cart-items-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.cart-item-row { display: flex; justify-content: space-between; align-items: center; background: var(--background-soft); padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border); font-size: 0.9rem; }
.cart-item-remove { color: var(--danger); font-weight: bold; padding: 4px 8px; }
.cart-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; }
.cart-total { font-weight: bold; font-size: 1.1rem; }
.btn-checkout { background: var(--success); color: white; padding: 8px 16px; border-radius: 6px; font-weight: bold; }

.message-area {
  flex: 1; 
  overflow-y: auto; 
  padding: 16px;
  /* Scroll suave nos navegadores */
  scroll-behavior: smooth; 
}
.msg-row { display: flex; width: 100%; }
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }
.bubble { max-width: 80%; padding: 12px 16px; border-radius: 12px; line-height: 1.4; font-size: 0.95rem; }
.msg-row.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 2px; }
.msg-row.bot .bubble { background: var(--assistant-bubble); color: var(--assistant-text); border-bottom-left-radius: 2px; border: 1px solid var(--border); }

.chat-product-card { background: var(--background-soft); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 8px; color: var(--text); }
.chat-product-name { font-weight: bold; margin: 0 0 4px; }
.chat-product-price { color: var(--primary-strong); font-weight: bold; margin: 0 0 12px; }
.chat-product-actions { display: flex; gap: 8px; }
.btn-chat-action { flex: 1; padding: 8px; border-radius: 6px; font-size: 0.85rem; font-weight: bold; text-align: center; }
.btn-chat-details { border: 1px solid var(--primary); color: var(--primary); }
.btn-chat-add { background: var(--primary); color: white; }
.chat-product-details-content { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 0.85rem; color: var(--text-soft); }
.chat-product-details-content.show { display: block; }

/* ==========================================================================
   ÁREA DE DIGITAÇÃO (Blindada para Desktop e Mobile)
   ========================================================================== */
.chat-input-area {
  display: flex !important; /* Força o comportamento flex */
  flex-direction: row !important; /* Obriga a ficar um do lado do outro */
  align-items: center;
  gap: 12px;
  width: 100%; /* Garante que a barra vá de ponta a ponta */
  box-sizing: border-box; /* Evita que o padding faça a barra vazar da tela */
  flex-shrink: 0; 
  background: var(--background);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  z-index: 10;
}

.chat-input {
  flex: 1 1 auto !important; /* Força o input a esticar o máximo que der */
  min-width: 0; /* Previne um bug comum onde o input se recusa a encolher */
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 0.95rem;
  outline: none;
  background: var(--background-soft);
  color: var(--text);
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--primary);
}

.btn-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0; /* Proíbe o botão de ser esmagado pelo input */
  transition: 0.2s ease;
}

.btn-send:hover {
  transform: scale(1.05);
}
/* Mobile */
.mobile-toggle { display: none; font-size: 1.5rem; }
@media (max-width: 992px) {
  .mobile-toggle { display: block; }
  .btn-desktop-catalog { display: none !important; }
  .left-aside, .right-aside { position: fixed; top: var(--header-height); bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform 0.3s ease; }
  .left-aside { left: 0; border-right: 1px solid var(--border); }
  .right-aside { right: 0; left: auto; transform: translateX(100%); border-left: 1px solid var(--border); }
  .left-aside.active-mobile { transform: translateX(0); }
  .right-aside.active-mobile { transform: translateX(0); }
  .chat-center { border: none; }
}
.overlay { position: fixed; top: var(--header-height); left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 35; display: none; }
.overlay.active { display: block; }
/* Galeria de imagens do produto no Chat */
.chat-product-gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px; /* Espaço para a barrinha de rolagem */
}

/* Oculta a barra de rolagem no celular para ficar mais limpo, mas mantém a rolagem ativa */
.chat-product-gallery::-webkit-scrollbar { height: 6px; }
.chat-product-gallery::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-product-img {
  height: 120px; /* Altura fixa para alinhar todas as fotos */
  min-width: 120px; /* Evita que a foto esmague */
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover; /* Faz a foto preencher o quadrado sem distorcer */
}

/* ==========================================================================
   CARDS DO HISTÓRICO DE CONVERSAS (LEFT ASIDE)
   ========================================================================== */
.history-item {
  background: var(--background-soft);
  border-bottom: 1px solid var(--border);
  padding: 12px;
  cursor: pointer;
  transition: 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-item:hover { 
  background: var(--background); 
}

/* Visual suave para o item selecionado (Nova versão!) */
.history-item.active {
  background-color: var(--background);
  border-left: 4px solid var(--primary); /* Linha azul/primária na lateral */
}

/* Conteúdo do texto (cresce e empurra a lixeira pro canto) */
.history-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.history-item-order { font-size: 0.85rem; color: var(--text-soft); }
.history-item-order strong { color: var(--text); }
.history-item-total { font-weight: bold; font-size: 0.95rem; color: var(--text); }
.history-item-title { font-size: 0.8rem; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;}

/* Botão da Lixeira */
.btn-delete-session {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.3;
  padding: 4px;
  transition: opacity 0.2s, transform 0.2s;
}

.btn-delete-session:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* Campos do cliente no carrinho */
.cart-customer-data {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.cart-customer-data input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--background-soft);
  min-width: 0; /* Previne que o input quebre o flexbox */
  transition: all 0.2s ease;
}

.cart-customer-data input:focus {
  border-color: var(--primary);
}

/* O efeito de Erro */
.cart-customer-data input.error-shake {
  border-color: var(--danger);
  background-color: #fef2f2; /* Vermelho bem clarinho no fundo */
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Responsivo para empilhar no celular */
@media (max-width: 768px) {
  .cart-customer-data { flex-direction: column; }
}

/* ==========================================================================
   BANNER DE EXCLUSÃO E LIXEIRA
   ========================================================================== */
.delete-banner {
  display: none; /* Fica oculto por padrão */
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 16px;
  border-bottom: 1px solid #f87171;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  animation: slideDown 0.3s ease;
}

.delete-banner.active { display: flex; }

.delete-banner-actions { display: flex; gap: 8px; }
.delete-banner-actions button { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.delete-banner-actions .btn-danger { background: #ef4444; color: white; }
.delete-banner-actions .btn-danger:hover { background: #dc2626; }
.delete-banner-actions .btn-secondary { background: #e5e7eb; color: #374151; }
.delete-banner-actions .btn-secondary:hover { background: #d1d5db; }

@keyframes slideDown {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Botão de Alternar para Lixeira na Lateral */
.btn-trash-toggle {
  background: none;
  border: none;
  color: var(--text-soft);
  padding: 16px 12px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  border-top: 1px solid var(--border);
  transition: 0.2s;
  font-size: 0.85rem;
}
.btn-trash-toggle:hover { color: var(--text); background: var(--background-soft); }
.btn-trash-toggle.active { color: #ef4444; font-weight: bold; background: #fef2f2; }