/* ============================================================
   Reset & Variáveis
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #eef2ff;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-2:        #475569;
  --muted:         #94a3b8;
  --danger:        #ef4444;
  --danger-bg:     #fef2f2;
  --radius:        14px;
  --radius-sm:     8px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:        0 4px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-lg:     0 10px 30px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.6;
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
}
.brand-icon {
  width: 26px;
  height: 26px;
  color: var(--primary);
}
.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand-ai {
  color: var(--primary);
}

/* ============================================================
   Main / layout
   ============================================================ */
main {
  flex: 1;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

/* ============================================================
   Upload page
   ============================================================ */
.upload-page { max-width: 640px; margin: 0 auto; }

.upload-hero {
  text-align: center;
  margin-bottom: 2rem;
}
.hero-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: 100px;
  padding: 0.25rem 0.85rem;
  margin-bottom: 1.25rem;
}
.upload-hero h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 0.75rem;
  line-height: 1.25;
}
.upload-hero p {
  color: var(--text-2);
  font-size: 0.95rem;
  line-height: 1.7;
}

.drop-zone {
  background: var(--surface);
  border: 2px dashed #c7d2fe;
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}
.drop-zone:hover, .drop-zone.drag-over {
  background: var(--primary-light);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,.1);
}
.drop-zone-icon {
  width: 56px;
  height: 56px;
  background: var(--primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}
.drop-zone-icon svg {
  width: 26px;
  height: 26px;
  color: var(--primary);
}
.drop-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.drop-sub { color: var(--muted); font-size: 0.875rem; margin-bottom: 1rem; }
.drop-hint { font-size: 0.775rem; color: var(--muted); margin-top: 1rem; }

.features-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1.75rem;
}
.feature-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 0.35rem 0.85rem;
  box-shadow: var(--shadow-sm);
}
.feature-pill svg { width: 13px; height: 13px; color: var(--primary); }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: 0 1px 3px rgba(99,102,241,.4);
}
.btn-primary:hover  { background: var(--primary-dark); box-shadow: 0 3px 8px rgba(99,102,241,.4); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-outline:hover { background: var(--bg); border-color: #cbd5e1; }

/* ============================================================
   Loading
   ============================================================ */
#loading-section {
  display: flex;
  justify-content: center;
  padding: 5rem 1rem;
}
.loading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 380px;
  width: 100%;
}
.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-weight: 600; margin-bottom: 0.35rem; }
.loading-sub { font-size: 0.85rem; color: var(--muted); }

/* ============================================================
   Error
   ============================================================ */
#error-section { display: flex; justify-content: center; padding: 4rem 1rem; }
.error-card {
  background: var(--surface);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 100%;
}
.error-icon-wrap {
  width: 52px; height: 52px;
  background: var(--danger-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.error-icon-wrap svg { width: 24px; height: 24px; color: var(--danger); }
.error-title { font-weight: 600; margin-bottom: 0.5rem; }
.error-detail { color: var(--text-2); font-size: 0.875rem; margin-bottom: 1.5rem; line-height: 1.5; }

/* ============================================================
   Results header
   ============================================================ */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.file-info { display: flex; align-items: center; gap: 0.85rem; }
.file-icon-wrap {
  width: 42px; height: 42px;
  background: var(--primary-light);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-icon-wrap svg { width: 20px; height: 20px; color: var(--primary); }
.results-header h2 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.1rem; }

/* ============================================================
   KPI Cards
   ============================================================ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  border-top-width: 3px;
}
.kpi-card.kpi-blue   { border-top-color: #3b82f6; }
.kpi-card.kpi-purple { border-top-color: #8b5cf6; }
.kpi-card.kpi-green  { border-top-color: #10b981; }
.kpi-card.kpi-orange { border-top-color: #f59e0b; }
.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.kpi-label { font-size: 0.775rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.1rem;
}
.card-header-left {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  color: var(--text-2);
}
.card-header-left h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}
.card-subtitle { font-size: 0.8rem; color: var(--muted); margin-top: 0.1rem; }

.ai-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: 100px;
  padding: 0.2rem 0.65rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================================
   Insights
   ============================================================ */
.insights-body {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-2);
  white-space: pre-wrap;
}

/* ============================================================
   Summary table
   ============================================================ */
.summary-details > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}
.summary-details > summary svg { color: var(--muted); }
.summary-details > summary::after { content: "▾"; margin-left: auto; color: var(--muted); font-size: 0.8rem; }
.summary-details[open] > summary::after { content: "▴"; }

#summary-table { margin-top: 1.1rem; overflow-x: auto; }
#summary-table table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
#summary-table th, #summary-table td {
  padding: 0.5rem 0.85rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#summary-table th:first-child, #summary-table td:first-child { text-align: left; }
#summary-table thead th {
  background: var(--bg);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#summary-table tbody tr:hover { background: #f8fafc; }

/* ============================================================
   Charts
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s;
}
.chart-card:hover {
  box-shadow: var(--shadow);
  border-color: #cbd5e1;
  transform: translateY(-1px);
}
.chart-card h4 {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
  padding-bottom: 0.85rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.chart-card h4::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}
.chart-card > div[id^="chart-"] { width: 100%; }

/* Gráficos largos (ex: heatmap de correlação) ocupam a linha inteira */
.chart-card.chart-card--wide {
  grid-column: 1 / -1;
}

/* ============================================================
   Chat
   ============================================================ */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
  padding: 0.25rem 0 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-messages:empty::before {
  content: "Nenhuma mensagem ainda. Faça uma pergunta sobre os dados acima.";
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.chat-bubble {
  max-width: 78%;
  padding: 0.65rem 1rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 3px rgba(99,102,241,.35);
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble.thinking {
  align-self: flex-start;
  background: var(--bg);
  border: 1px dashed var(--border);
  color: var(--muted);
  font-style: italic;
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.25rem;
}
.chat-input {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.btn-send { padding: 0.65rem 1.25rem; }

/* ============================================================
   Footer
   ============================================================ */
.app-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.775rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}

/* ============================================================
   Utilities
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 720px) {
  main { padding: 1.5rem 1rem; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.chart-card--wide { grid-column: auto; }
  .upload-hero h1 { font-size: 1.45rem; }
  .hide-sm { display: none; }
  .results-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 400px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .features-row { gap: 0.4rem; }
}
