/* ════════════════════════════════════════════════════════════════
   Design System — TOTVS TDN Knowledge Base
   Tema: Claro | Cor primária: Azul Petróleo #1D7882
   ════════════════════════════════════════════════════════════════ */

:root {
  /* ── Cores Primárias ── */
  --primary:           #1D7882;
  --primary-hover:     #166069;
  --primary-light:     #E8F4F5;
  --primary-contrast:  #FFFFFF;

  /* ── Cores Semânticas ── */
  --accent-success:    #16A34A;
  --accent-success-bg: #F0FDF4;
  --accent-danger:     #DC2626;
  --accent-danger-bg:  #FEF2F2;
  --accent-warning:    #D97706;
  --accent-warning-bg: #FFFBEB;

  /* ── Fundos ── */
  --bg-body:           #F5F6FA;
  --bg-card:           #FFFFFF;
  --bg-sidebar:        #FFFFFF;
  --bg-header:         #FFFFFF;
  --bg-input:          #F8F9FC;
  --bg-hover:          #F0F1F5;

  /* ── Textos ── */
  --text-primary:      #1E293B;
  --text-secondary:    #64748B;
  --text-muted:        #94A3B8;
  --text-inverse:      #FFFFFF;

  /* ── Bordas & Sombras ── */
  --border:            #E2E8F0;
  --border-light:      #F1F5F9;
  --shadow-sm:         0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:         0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:         0 8px 30px rgba(0,0,0,0.12);

  /* ── Tipografia ── */
  --font-family:       'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* ── Dimensões ── */
  --sidebar-width:     280px;
  --header-height:     64px;
  --radius-sm:         8px;
  --radius-md:         12px;
  --radius-lg:         16px;
  --radius-full:       9999px;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #root {
  height: 100%;
  font-family: var(--font-family);
  background: var(--bg-body);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout Principal ── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 30;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #2A9DA8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-contrast);
  box-shadow: 0 2px 8px rgba(29,120,130,0.3);
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-body {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.sidebar-footer span {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: var(--font-family);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: 0 2px 6px rgba(29,120,130,0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(29,120,130,0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-new-chat {
  width: 100%;
  margin-bottom: 24px;
}

/* ── Filtro de Produto ── */
.filter-group label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.filter-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-family);
  appearance: none;
  cursor: pointer;
  transition: border-color 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── Área Principal ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-body);
}

/* ── Header ── */
.header {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--accent-success-bg);
  color: var(--accent-success);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.header-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-success);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

/* ── Chat Container ── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  scroll-behavior: smooth;
}

.chat-messages-inner {
  max-width: 780px;
  margin: 0 auto;
}

/* ── Welcome Screen ── */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary-light), #D4EEEF);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 4px 16px rgba(29,120,130,0.15);
}

.welcome-icon svg {
  color: var(--primary);
}

.welcome h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.welcome p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 460px;
  line-height: 1.6;
  margin-bottom: 40px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 560px;
  width: 100%;
}

.welcome-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  font-family: var(--font-family);
  box-shadow: var(--shadow-sm);
}

.welcome-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: var(--text-primary);
}

.welcome-card svg {
  flex-shrink: 0;
  color: var(--primary);
  margin-top: 2px;
}

/* ── Mensagens ── */
.msg-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}

.msg-user-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 75%;
}

.msg-user-bubble {
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 14px 18px;
  border-radius: 16px 16px 4px 16px;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(29,120,130,0.2);
}

.msg-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-user-avatar svg {
  color: var(--primary);
}

.msg-assistant {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 32px;
}

.msg-assistant-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 85%;
}

.msg-assistant-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-light), #D4EEEF);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(29,120,130,0.15);
}

.msg-assistant-avatar svg {
  color: var(--primary);
}

.msg-assistant-body {
  flex: 1;
  min-width: 0;
}

.msg-assistant-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  padding: 18px 22px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.msg-assistant-content h1,
.msg-assistant-content h2,
.msg-assistant-content h3 {
  font-weight: 700;
  margin: 16px 0 8px 0;
  color: var(--text-primary);
}

.msg-assistant-content h3 { font-size: 15px; }
.msg-assistant-content h2 { font-size: 17px; }

.msg-assistant-content p { margin-bottom: 12px; }

.msg-assistant-content ul,
.msg-assistant-content ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.msg-assistant-content li { margin-bottom: 4px; }

.msg-assistant-content code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--primary);
}

.msg-assistant-content pre {
  background: #1E293B;
  color: #E2E8F0;
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
}

.msg-assistant-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.msg-assistant-content strong { color: var(--text-primary); }

.msg-assistant-content a {
  color: var(--primary);
  text-decoration: underline;
}

/* ── Source Cards ── */
.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 10px;
  transition: all 0.2s ease;
}

.source-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.source-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.source-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.source-card-title svg { color: var(--text-muted); }

.source-card-link {
  font-size: 11px;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  transition: color 0.2s;
}

.source-card-link:hover { color: var(--primary-hover); }

.source-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.badge-protheus { background: var(--accent-success-bg); color: var(--accent-success); }
.badge-rm       { background: var(--accent-warning-bg); color: var(--accent-warning); }
.badge-datasul  { background: #F3F0FF; color: #7C3AED; }
.badge-fluig    { background: #ECFEFF; color: #0891B2; }
.badge-default  { background: var(--primary-light); color: var(--primary); }
.badge-module   { background: var(--bg-input); color: var(--text-secondary); }

.source-card-preview {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-card-score {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

/* ── Loading Dots ── */
.loading-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 4px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: bounce-dot 1.4s infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Chat Input ── */
.chat-input-wrapper {
  padding: 16px 32px 24px;
  background: var(--bg-body);
}

.chat-input-box {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light), var(--shadow-md);
}

.chat-input-box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-primary);
  background: transparent;
  padding: 8px 0;
  max-height: 120px;
  line-height: 1.5;
}

.chat-input-box textarea::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-contrast);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(29,120,130,0.25);
}

.chat-send-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(29,120,130,0.35);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chat-input-footer {
  text-align: center;
  margin-top: 8px;
}

.chat-input-footer p {
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Mobile header ── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.mobile-header button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

.mobile-header span {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}

/* ── Overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 20;
  backdrop-filter: blur(2px);
}

/* ── Responsividade ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0;
    width: 280px;
    transform: translateX(-100%);
  }

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

  .sidebar-overlay.open {
    display: block;
  }

  .mobile-header {
    display: flex;
  }

  .header {
    display: none;
  }

  .welcome-grid {
    grid-template-columns: 1fr;
  }

  .chat-messages { padding: 20px 16px; }
  .chat-input-wrapper { padding: 12px 16px 20px; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
