:root {
  --bg: #0d0d0d;
  --bg-elevated: #171717;
  --bg-hover: #262626;
  --border: #2e2e2e;
  --text: #ececec;
  --text-muted: #a1a1a1;
  --accent: #8b0000;
  --accent-soft: rgba(139, 0, 0, 0.2);
  --accent-hover: #a50000;
  --ivory: #faf7f2;
  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;
  --radius: 12px;
  --sidebar-w: 280px;
  --font: 'Inter', system-ui, sans-serif;
  --font-serif: 'Merriweather', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.sidebar-header { margin-bottom: 20px; }

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

.logo-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.logo strong {
  display: block;
  font-size: 1rem;
}

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

.sidebar-section { margin-bottom: 20px; }

.section-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.mode-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn:hover { color: var(--text); background: var(--bg-hover); }
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.slides-config .slide-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.82rem;
  margin-bottom: 12px;
}

.slides-config .slide-input:focus,
.slides-config .slide-input.input-error {
  outline: none;
  border-color: #B8956B;
}

.slides-config .slide-input.input-error {
  border-color: #c45c5c;
  box-shadow: 0 0 0 2px rgba(196, 92, 92, 0.25);
}

.slide-count-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.slide-count-row input[type="range"] {
  flex: 1;
  accent-color: #8B5E5E;
}

.slide-count-label {
  font-size: 0.78rem;
  color: #e8c4a0;
  min-width: 58px;
  text-align: right;
}

.slides-config .slide-textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.78rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 88px;
  margin-bottom: 8px;
}

.slides-config .slide-textarea:focus {
  outline: none;
  border-color: #B8956B;
}

.slides-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.4;
}

.btn-gerar-slides {
  width: 100%;
  border: none;
  background: linear-gradient(135deg, #B8956B, #8B5E5E);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-gerar-slides:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-gerar-slides:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.slides-gen-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 6px 0 10px;
}

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

.quick-btn {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.quick-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.sidebar-status { margin-top: auto; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-loading { background: var(--bg-hover); color: var(--text-muted); }
.status-ok { background: rgba(34, 197, 94, 0.12); color: var(--success); }
.status-warn { background: rgba(234, 179, 8, 0.12); color: var(--warning); }
.status-error { background: rgba(239, 68, 68, 0.12); color: var(--error); }

.stats-info {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}

.main-header h1 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 600;
}

.main-header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.welcome-card {
  max-width: 640px;
  padding: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.welcome-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--ivory);
}

.welcome-card p {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.welcome-card p:last-child { margin-bottom: 0; }

.msg {
  max-width: 780px;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-user {
  align-self: flex-end;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  max-width: 85%;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}

.msg-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-body {
  font-size: 0.92rem;
  line-height: 1.65;
}

.msg-body p { margin: 0 0 0.75em; }
.msg-body p:last-child { margin-bottom: 0; }

.msg-body strong { color: var(--ivory); }

.msg-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.typing {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Sources — painel minimizado e acolhedor */
.sources-panel {
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(139, 0, 0, 0.08) 0%, var(--bg-elevated) 100%);
  transition: background 0.2s ease;
}

.sources-panel.expanded {
  background: linear-gradient(180deg, rgba(139, 0, 0, 0.12) 0%, var(--bg-elevated) 100%);
}

.sources-toggle {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 12px 20px;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: inherit;
}

.sources-toggle:hover {
  background: rgba(255, 255, 255, 0.03);
}

.sources-toggle-icon {
  font-size: 1rem;
  opacity: 0.9;
}

.sources-toggle-text {
  flex: 1;
  font-weight: 500;
  color: #f5e6d3;
}

.sources-badge {
  background: rgba(139, 0, 0, 0.35);
  color: #ffd4d4;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(139, 0, 0, 0.5);
}

.sources-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  font-size: 0.9rem;
}

.sources-panel.expanded .sources-chevron {
  transform: rotate(180deg);
}

.sources-list {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 280px;
  overflow-y: auto;
}

.sources-list[hidden] {
  display: none !important;
}

.source-item {
  border: 1px solid rgba(196, 160, 53, 0.2);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.source-item.open {
  border-color: rgba(196, 160, 53, 0.45);
  background: rgba(26, 10, 10, 0.35);
}

.source-header {
  width: 100%;
  border: none;
  background: transparent;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
  color: inherit;
}

.source-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.source-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e8c4a0;
  line-height: 1.35;
}

.source-ref {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.source-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.source-relevance {
  font-size: 0.68rem;
  color: #c4a035;
  background: rgba(196, 160, 53, 0.12);
  padding: 2px 7px;
  border-radius: 999px;
}

.source-expand-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.source-body {
  padding: 0 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.source-body[hidden] {
  display: none;
}

.source-text {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: rgba(250, 247, 242, 0.06);
  border-left: 3px solid #8b0000;
  border-radius: 0 8px 8px 0;
  font-size: 0.8rem;
  line-height: 1.65;
  color: #ececec;
  font-family: Merriweather, Georgia, serif;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.source-card {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
}

.source-card strong {
  color: var(--accent-hover);
  display: block;
  margin-bottom: 4px;
}

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

/* Input */
.chat-input-bar {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
}

#chatInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  outline: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  margin: 6px 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Slides modal */
.slides-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.slides-modal[hidden] { display: none !important; }

.slides-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.slides-modal-panel {
  position: relative;
  width: min(960px, 100%);
  height: min(85vh, 720px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.quick-btn.docs-btn { margin-top: 4px; }
.quick-btn.secondary { opacity: 0.85; font-size: 0.78rem; }

.slides-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.slides-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slides-close {
  border: none;
  background: var(--bg-hover);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}

#slidesFrame {
  flex: 1;
  border: none;
  background: #fff;
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: 40vh;
    overflow-y: auto;
  }
}
