:root {
  --primary: #1e3a8a;
  --primary-light: #3b82f6;
  --primary-dark: #1e1b4b;
  --accent: #d97706;
  --accent-light: #f59e0b;
  --success: #059669;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-white: #f8fafc;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  /* Use dynamic viewport height if available, fallback to vh */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background-color: var(--primary-dark);
  color: var(--text-white);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Mobile Menu Button - Hidden on desktop */
.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  margin-right: 4px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #059669, #10b981);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  letter-spacing: 1px;
}

.brand-info h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.brand-info p {
  font-size: 0.78rem;
  color: #94a3b8;
}

/* Buttons */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.btn-primary {
  background: var(--primary-light);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-primary:hover {
  background: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: #ffffff;
  width: 90%;
  max-width: 480px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1rem;
  color: var(--primary-dark);
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

.modal-body p {
  font-size: 0.9rem;
  margin-bottom: 12px;
  color: var(--text-main);
}

.modal-body input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.modal-help {
  font-size: 0.78rem !important;
  color: var(--text-muted);
}

.modal-footer {
  padding: 14px 20px;
  background: var(--bg-main);
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border-color);
}

/* Main Layout */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none; /* Only used on mobile */
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: var(--bg-sidebar);
  color: var(--text-white);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.05);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.sidebar-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #94a3b8;
  margin-bottom: 12px;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  color: #cbd5e1;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.mode-btn.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--primary-light);
  color: #fff;
}

.mode-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.mode-text strong {
  display: block;
  font-size: 0.88rem;
}

.mode-text small {
  font-size: 0.75rem;
  color: #94a3b8;
  display: block;
  margin-top: 2px;
}

.quick-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.3;
}

.chip-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
  color: #64748b;
  text-align: center;
}

/* Chat Area */
.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  min-width: 0;
}

.chat-history {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message-wrapper {
  display: flex;
  gap: 12px;
  max-width: 85%;
}

.message-wrapper.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-wrapper.assistant {
  align-self: flex-start;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user .avatar {
  background: var(--primary);
  color: #fff;
}

.assistant .avatar {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.user .message-content {
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.assistant .message-content {
  background: #f1f5f9;
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.assistant .message-content h1,
.assistant .message-content h2,
.assistant .message-content h3,
.assistant .message-content h4 {
  color: var(--primary-dark);
  font-weight: 700;
  margin-top: 14px;
  margin-bottom: 8px;
  line-height: 1.35;
}

.assistant .message-content h1:first-child,
.assistant .message-content h2:first-child,
.assistant .message-content h3:first-child,
.assistant .message-content h4:first-child {
  margin-top: 0;
}

.assistant .message-content h1 { font-size: 1.12rem; }
.assistant .message-content h2 { font-size: 1.05rem; }
.assistant .message-content h3 { font-size: 0.98rem; }
.assistant .message-content h4 { font-size: 0.92rem; }

.assistant .message-content p {
  margin-bottom: 10px;
}

.assistant .message-content p:last-child {
  margin-bottom: 0;
}

.assistant .message-content strong {
  color: var(--primary-dark);
}

.assistant .message-content ul, .assistant .message-content ol {
  margin-left: 22px;
  margin-top: 6px;
  margin-bottom: 12px;
  padding-left: 4px;
}

.assistant .message-content li {
  margin-bottom: 6px;
  line-height: 1.55;
}

.assistant .message-content li:last-child {
  margin-bottom: 0;
}

.assistant .message-content code {
  background: #e2e8f0;
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: Consolas, monospace;
}

.assistant .message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 10px 0;
  color: #475569;
  background: #fff;
  padding: 8px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Quick Mode Action Buttons in Messages */
.quick-actions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
}

.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 38px;
}

.quick-action-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.quick-action-btn:active {
  transform: translateY(0);
}

.quick-action-btn.mode-roteiro {
  border-color: #a7f3d0;
  color: #065f46;
  background: #ecfdf5;
}
.quick-action-btn.mode-roteiro:hover {
  background: #d1fae5;
  border-color: #34d399;
}

.quick-action-btn.mode-simulador {
  border-color: #bfdbfe;
  color: #1e40af;
  background: #eff6ff;
}
.quick-action-btn.mode-simulador:hover {
  background: #dbeafe;
  border-color: #60a5fa;
}

.quick-action-btn.mode-duvidas {
  border-color: #fde68a;
  color: #92400e;
  background: #fffbeb;
}
.quick-action-btn.mode-duvidas:hover {
  background: #fef3c7;
  border-color: #f59e0b;
}

.quick-action-btn.generic-action {
  border-color: #e2e8f0;
  color: var(--primary);
  background: #f8fafc;
}
.quick-action-btn.generic-action:hover {
  background: #f1f5f9;
  border-color: var(--primary);
}

@media (max-width: 768px) {
  .quick-actions-container {
    flex-direction: column;
    gap: 8px;
  }
  .quick-action-btn {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
    font-size: 0.88rem;
  }
}

.assistant .message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.85rem;
  display: block;
  overflow-x: auto;
}

.assistant .message-content th, .assistant .message-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

.assistant .message-content th {
  background: #e2e8f0;
  font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 12px 18px;
  background: #f1f5f9;
  border-radius: var(--radius-md);
  width: fit-content;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* Chat Input Bar */
.chat-input-container {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
  flex-shrink: 0;
}

.chat-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  transition: border-color 0.2s ease;
}

.chat-form:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 0.95rem;
  outline: none;
  max-height: 120px;
  padding: 6px 0;
  color: var(--text-main);
}

.btn-send {
  background: var(--primary-light);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--primary);
}

.btn-send:disabled {
  background: var(--border-color);
  cursor: not-allowed;
}

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

.input-footer small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* RESPONSIVE DESIGN FOR MOBILE */
@media screen and (max-width: 768px) {
  .app-header {
    padding: 10px 16px;
  }
  
  .mobile-menu-btn {
    display: block;
  }
  
  .brand-logo {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }
  
  .desktop-only {
    display: none;
  }
  
  .header-actions .btn-secondary {
    padding: 8px;
  }
  
  /* Sidebar Drawer Style */
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    z-index: 100;
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-overlay {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }
  
  /* Chat History adjustments */
  .chat-history {
    padding: 16px;
    gap: 16px;
  }
  
  .message-wrapper {
    max-width: 95%; /* Wider on small screens */
  }
  
  .avatar {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }
  
  .message-content {
    padding: 12px 14px;
    font-size: 0.9rem;
  }
  
  .chat-input-container {
    padding: 12px 16px;
  }
}

/* --- Novos Estilos: Botões de Ação e Acordeão de Contexto --- */

.header-actions {
  display: flex;
  gap: 10px;
}

.btn-icon {
  background: rgba(255,255,255,0.1);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.2);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.btn-copy {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s ease;
}

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

.btn-copy svg {
  width: 14px;
  height: 14px;
}

.context-accordion {
  margin: 16px 24px 0 24px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  overflow: hidden;
}

.context-toggle {
  width: 100%;
  background: var(--bg-main);
  border: none;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 0.95rem;
}

.context-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.context-toggle .chevron {
  transition: transform 0.3s ease;
}

.context-toggle.active .chevron {
  transform: rotate(180deg);
}

.context-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out, padding 0.3s ease;
  background: var(--bg-card);
}

.context-panel.open {
  max-height: 800px;
  padding: 16px;
}

.context-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-group textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.9rem;
  resize: vertical;
  color: var(--text-main);
  font-family: inherit;
}

.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

@media screen and (max-width: 768px) {
  .context-accordion {
    margin: 12px 16px 0 16px;
  }
}
