:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #dde5ee;
  --text: #152232;
  --text-muted: #5a6b7d;
  --primary: #0f4c81;
  --primary-hover: #0b3a63;
  --accent: #0f9d76;
  --accent-soft: #e6f7f1;
  --danger: #c93737;
  --danger-soft: #fdf0f0;
  --shadow-sm: 0 2px 8px rgba(15, 34, 58, 0.06);
  --shadow-md: 0 12px 32px rgba(15, 34, 58, 0.1);
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* BOTÕES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-danger-outline {
  background: transparent;
  border-color: #f1c3c3;
  color: var(--danger);
  padding: 7px 12px;
  font-size: 0.84rem;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-full {
  width: 100%;
}

/* TOASTS */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  background: var(--text);
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--accent);
}

.toast.error {
  border-left-color: var(--danger);
}

/* AUTH SHELL */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 40px;
  align-items: center;
  max-width: 1120px;
  margin: 0 auto;
  padding: 36px 24px;
}

.brand-pill {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #0b6e53;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 18px;
}

.auth-hero h1 {
  font-size: 2.35rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 14px;
  color: var(--text);
}

.hero-lead {
  font-size: 1.02rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  max-width: 560px;
}

.feature-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.feature-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.feature-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 7px;
  flex-shrink: 0;
}

.feature-list strong {
  display: block;
  font-size: 0.95rem;
}

.feature-list p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-subtle);
  padding: 5px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.inline-alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.87rem;
  margin-bottom: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f5c6c6;
}

.inline-alert.success {
  background: var(--accent-soft);
  color: #0b6e53;
  border-color: #b7e8d8;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

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

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.field input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.94rem;
  color: var(--text);
  background: var(--surface);
}

.field input:focus {
  outline: 2px solid rgba(15, 76, 129, 0.2);
  border-color: var(--primary);
}

.auth-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.env-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* APP WORKSPACE */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

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

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  font-weight: 800;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.04em;
}

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

.topbar-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-info {
  text-align: right;
}

.user-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.user-email {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 330px 1fr;
  min-height: 0;
}

/* SIDEBAR */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 14px;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h2 {
  font-size: 1rem;
}

.count-pill {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}

.dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 2px dashed #b9cadb;
  border-radius: var(--radius);
  background: var(--surface-subtle);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: #edf4fb;
}

.dropzone-icon {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: #e1ecf7;
  color: var(--primary);
  font-weight: 800;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.dropzone-text span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.upload-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #edf4fb;
  color: var(--primary);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 9px;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(15, 76, 129, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.documents-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-docs {
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 12px;
  background: var(--surface-subtle);
  border-radius: var(--radius);
}

.doc-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-item:hover {
  border-color: #9cb8d4;
  background: var(--surface-subtle);
}

.doc-item.active {
  border-color: var(--primary);
  background: #eef5fc;
}

.doc-item-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.doc-item-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* CHAT PANEL */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.empty-chat-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  gap: 10px;
}

.empty-icon {
  font-size: 2.6rem;
}

.empty-chat-state h3 {
  color: var(--text);
  font-size: 1.2rem;
}

.empty-chat-state p {
  max-width: 440px;
  font-size: 0.92rem;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-doc-meta h2 {
  font-size: 1.02rem;
  word-break: break-word;
}

.chat-doc-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.meta-chip {
  font-size: 0.76rem;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chat-empty-history {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 420px;
}

.qa-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 82%;
  padding: 13px 16px;
  border-radius: 14px;
  font-size: 0.93rem;
  box-shadow: var(--shadow-sm);
}

.bubble-user {
  align-self: flex-end;
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble-meta {
  font-size: 0.74rem;
  opacity: 0.75;
  margin-top: 6px;
}

.sources-details {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
}

.sources-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
}

.source-item {
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.source-score {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  color: #0b6e53;
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: 999px;
  margin-bottom: 5px;
}

.source-text {
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.quick-prompts {
  padding: 8px 22px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.quick-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn:hover {
  background: #edf4fb;
  border-color: var(--primary);
}

.query-form {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.query-form textarea {
  flex: 1;
  resize: none;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.93rem;
  color: var(--text);
}

.query-form textarea:focus {
  outline: 2px solid rgba(15, 76, 129, 0.2);
  border-color: var(--primary);
}

.thinking-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* RESPONSIVO */
@media (max-width: 900px) {
  .auth-shell {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .auth-hero h1 {
    font-size: 1.85rem;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 290px;
  }

  .bubble {
    max-width: 94%;
  }
}
