/* ════════════════════════════════════════════════════════════════
   X3 TECNOLOGIA — DESIGN SYSTEM
   Evolução do layout original: mesma marca (azul + logo X3),
   tratamento visual mais maduro, sóbrio e corporativo.
   ════════════════════════════════════════════════════════════════ */

:root {
  /* Marca — azul aprofundado, menos saturado que o original (#1B6CA8) */
  --x3-brand: #0F3A5C;
  --x3-brand-dark: #0A2940;
  --x3-brand-soft: #3A6E94;
  --x3-brand-muted: #6E97B5;

  /* Superfícies — neutro frio em vez de azul-bebê (#EEF7FD) */
  --x3-bg-page: #F7F9FB;
  --x3-bg-surface: #FFFFFF;
  --x3-bg-subtle: #F1F4F7;

  /* Texto */
  --x3-text-primary: #1A2733;
  --x3-text-secondary: #5B6573;
  --x3-text-tertiary: #8A96A3;
  --x3-text-on-brand: #FFFFFF;

  /* Bordas */
  --x3-border: #E3E8EE;
  --x3-border-strong: #CBD3DC;

  /* Estados semânticos */
  --x3-success: #2F6E4F;
  --x3-success-bg: #EAF3EE;
  --x3-warning: #8A5A0E;
  --x3-warning-bg: #FBF2E2;
  --x3-danger: #A23B3B;
  --x3-danger-bg: #FBEAEA;

  /* Espaçamento / forma */
  --x3-radius-sm: 6px;
  --x3-radius-md: 10px;
  --x3-radius-lg: 14px;
  --x3-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --x3-shadow-md: 0 4px 10px rgba(16, 24, 40, 0.06);

  --x3-sidebar-w: 264px;
  --x3-sidebar-w-collapsed: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* o scroll acontece dentro de cada aba, nunca na página */
}

body {
  background: var(--x3-bg-page);
  color: var(--x3-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Tela de login: única tela que pode rolar a página normalmente,
   pois fica fora de #app-screen ────────────────────────────────── */
#login-screen { height: 100%; overflow-y: auto; }

/* ── Casca do app: topbar com altura natural + área de conteúdo que
   ocupa o restante exato da tela, sem nenhum valor fixo em pixel ── */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--x3-bg-page);
}
#app-content {
  flex: 1;
  min-height: 0; /* essencial: permite que os filhos rolem dentro do espaço restante */
  display: flex;
  flex-direction: column;
}
/* Dashboard e Análise: a aba inteira rola normalmente dentro do espaço disponível */
.x3-tab-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
/* Chat: a aba ocupa 100% do espaço e delega o scroll para dentro
   (sidebar e rodapé de input ficam fixos; só as mensagens rolam) */
.x3-tab-panel-fixed {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Tipografia base ────────────────────────────────────────────── */
.x3-h1 { font-size: 22px; font-weight: 600; color: var(--x3-text-primary); letter-spacing: -0.01em; }
.x3-h2 { font-size: 16px; font-weight: 600; color: var(--x3-text-primary); }
.x3-h3 { font-size: 13px; font-weight: 600; color: var(--x3-text-primary); }
.x3-eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--x3-text-tertiary);
}
.x3-body { font-size: 14px; color: var(--x3-text-secondary); line-height: 1.6; }
.x3-caption { font-size: 12px; color: var(--x3-text-tertiary); }

/* ── Top navigation (abas) ─────────────────────────────────────── */
/* Sempre full-bleed (sem caixa centralizada) em todas as abas —
   alinhado com o sidebar do chat e o conteúdo das demais telas. */
.x3-topbar {
  background: var(--x3-bg-surface);
  border-bottom: 1px solid var(--x3-border);
  flex-shrink: 0;
}
.x3-topbar-inner {
  padding: 0 24px;
}
.x3-topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}
.x3-brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}
.x3-brand-mark img { height: 28px; width: auto; display: block; }
.x3-brand-divider { width: 1px; height: 18px; background: var(--x3-border-strong); margin: 0 4px; }
.x3-product-name { font-size: 13px; color: var(--x3-text-tertiary); font-weight: 500; }

.x3-tabs {
  display: flex;
  gap: 28px;
}
.x3-tab {
  position: relative;
  padding: 11px 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--x3-text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.x3-tab:hover { color: var(--x3-text-primary); }
.x3-tab.is-active {
  color: var(--x3-brand);
  border-bottom-color: var(--x3-brand);
}

.x3-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--x3-text-tertiary);
}
.x3-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--x3-success);
}

.x3-usage-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--x3-bg-subtle);
  color: var(--x3-brand);
}

/* ── Cards ──────────────────────────────────────────────────────── */
.x3-card {
  background: var(--x3-bg-surface);
  border: 1px solid var(--x3-border);
  border-radius: var(--x3-radius-md);
  box-shadow: var(--x3-shadow-sm);
}
.x3-card-pad { padding: 20px; }

.x3-metric-card {
  background: var(--x3-bg-surface);
  border: 1px solid var(--x3-border);
  border-radius: var(--x3-radius-md);
  padding: 16px 18px;
}
.x3-metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--x3-text-tertiary);
}
.x3-metric-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--x3-text-primary);
  margin-top: 6px;
  letter-spacing: -0.01em;
}
.x3-metric-foot {
  font-size: 11px;
  color: var(--x3-text-tertiary);
  margin-top: 4px;
}

/* ── Botões ─────────────────────────────────────────────────────── */
.x3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--x3-radius-sm);
  padding: 8px 16px;
  cursor: pointer;
  transition: all .15s ease;
  border: 1px solid transparent;
}
.x3-btn-primary { background: var(--x3-brand); color: var(--x3-text-on-brand); }
.x3-btn-primary:hover { background: var(--x3-brand-dark); }
.x3-btn-primary:disabled { opacity: .5; cursor: default; }

.x3-btn-secondary {
  background: var(--x3-bg-surface);
  color: var(--x3-text-secondary);
  border-color: var(--x3-border-strong);
}
.x3-btn-secondary:hover { background: var(--x3-bg-subtle); color: var(--x3-text-primary); }

.x3-btn-ghost {
  background: none;
  color: var(--x3-text-tertiary);
  border-color: transparent;
}
.x3-btn-ghost:hover { color: var(--x3-text-primary); background: var(--x3-bg-subtle); }

.x3-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--x3-radius-sm);
  border: 1px solid var(--x3-border);
  background: var(--x3-bg-surface);
  color: var(--x3-text-tertiary);
  cursor: pointer;
  transition: all .15s ease;
  flex-shrink: 0;
}
.x3-icon-btn:hover { border-color: var(--x3-brand-soft); color: var(--x3-brand); }

/* ── Inputs ─────────────────────────────────────────────────────── */
.x3-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--x3-border-strong);
  border-radius: var(--x3-radius-sm);
  font-size: 13px;
  color: var(--x3-text-primary);
  background: var(--x3-bg-surface);
  outline: none;
  transition: border-color .15s ease;
}
.x3-input:focus { border-color: var(--x3-brand); }
.x3-input::placeholder { color: var(--x3-text-tertiary); }

/* ── Period chips (aba Análise) ────────────────────────────────── */
.x3-chip {
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--x3-border-strong);
  background: var(--x3-bg-surface);
  color: var(--x3-text-secondary);
  cursor: pointer;
  transition: all .15s ease;
}
.x3-chip:hover { border-color: var(--x3-brand-soft); color: var(--x3-brand); }
.x3-chip.is-active {
  background: var(--x3-brand);
  border-color: var(--x3-brand);
  color: var(--x3-text-on-brand);
}

/* ── Layout de página com sidebar fixa (Chat) ──────────────────── */
/* height:100% (herdado de .x3-tab-panel-fixed, já calculado sem
   números fixos): é o que permite que só #chat-messages role
   internamente — sidebar e rodapé de input ficam sempre visíveis,
   igual ao comportamento do ChatGPT/Claude. */
.x3-chat-layout {
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0;
  position: relative;
}

.x3-sidebar {
  width: var(--x3-sidebar-w);
  flex-shrink: 0;
  background: var(--x3-bg-surface);
  border-right: 1px solid var(--x3-border);
  display: flex;
  flex-direction: column;
  transition: width .2s ease;
  overflow: hidden;
  height: 100%;
  min-height: 0;
}
.x3-sidebar.is-collapsed { width: var(--x3-sidebar-w-collapsed); }

.x3-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--x3-border);
  flex-shrink: 0;
  min-height: 49px;
}

.x3-sidebar-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.x3-chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.x3-chat-canvas {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.x3-chat-canvas-inner {
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* ── Conversa: itens da lista ───────────────────────────────────── */
.x3-hist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--x3-radius-sm);
  cursor: pointer;
  margin-bottom: 1px;
  position: relative;
  border-left: 2px solid transparent;
}
.x3-hist-item:hover { background: var(--x3-bg-subtle); }
.x3-hist-item.is-active {
  background: var(--x3-bg-subtle);
  border-left-color: var(--x3-brand);
}
.x3-hist-item .conv-actions { display: none; gap: 2px; flex-shrink: 0; }
.x3-hist-item:hover .conv-actions { display: flex; }

/* ── Mensagens do chat ──────────────────────────────────────────── */
.x3-msg-user {
  max-width: 640px;
  padding: 11px 16px;
  border-radius: var(--x3-radius-md);
  background: var(--x3-brand);
  color: #fff;
  font-size: 14px;
  line-height: 1.55;
}
.x3-msg-assistant {
  max-width: 760px;
  padding: 14px 18px;
  border-radius: var(--x3-radius-md);
  background: var(--x3-bg-surface);
  border: 1px solid var(--x3-border);
  font-size: 14px;
  color: var(--x3-text-primary);
  line-height: 1.6;
}

/* ── Dimensiona e desativa o azul-bebê herdado do Tailwind antigo ─ */
.border-blue-100 { border-color: var(--x3-border) !important; }

/* ── Scrollbar discreta ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--x3-border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Tabelas de dados (dashboard / análise) ─────────────────────── */
.x3-table { width: 100%; border-collapse: collapse; }
.x3-table th {
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--x3-text-tertiary);
  padding: 8px 12px;
  border-bottom: 1px solid var(--x3-border);
}
.x3-table th:first-child { text-align: left; }
.x3-table td {
  text-align: right;
  font-size: 13px;
  color: var(--x3-text-primary);
  padding: 9px 12px;
  border-bottom: 1px solid var(--x3-bg-subtle);
}
.x3-table td:first-child { text-align: left; color: var(--x3-text-secondary); }
.x3-table tr:hover td { background: var(--x3-bg-subtle); }

/* ── Skeleton de loading ────────────────────────────────────────── */
.x3-skeleton {
  background: linear-gradient(90deg, var(--x3-bg-subtle) 25%, var(--x3-border) 37%, var(--x3-bg-subtle) 63%);
  background-size: 400% 100%;
  animation: x3-shimmer 1.4s ease infinite;
  border-radius: var(--x3-radius-sm);
}
@keyframes x3-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ── Aba Análise: cards de destaque (insights estáticos) ─────────── */
.x3-insight-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 8px;
}
.x3-insight-card {
  background: var(--x3-bg-surface);
  border: 1px solid var(--x3-border);
  border-radius: var(--x3-radius-lg);
  padding: 18px;
  box-shadow: var(--x3-shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.x3-insight-card:hover {
  box-shadow: var(--x3-shadow-md);
  transform: translateY(-1px);
}
.x3-insight-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.x3-insight-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--x3-text-tertiary);
  margin-bottom: 6px;
}
.x3-insight-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--x3-text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}
.x3-insight-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.x3-insight-detail {
  font-size: 12px;
  color: var(--x3-text-tertiary);
  line-height: 1.4;
}

/* ── Aba Análise: ranking por dimensão (barras horizontais) ──────── */
.x3-rank-header,
.x3-rank-row {
  display: grid;
  grid-template-columns: 180px 1fr 70px 90px;
  align-items: center;
  gap: 14px;
}
.x3-rank-header { padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--x3-border); }
.x3-rank-row { padding: 9px 0; border-bottom: 1px solid var(--x3-bg-subtle); }
.x3-rank-row:last-child { border-bottom: none; }
.x3-rank-name {
  font-size: 13px;
  color: var(--x3-text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.x3-rank-bar-track {
  height: 8px;
  background: var(--x3-bg-subtle);
  border-radius: 4px;
  overflow: hidden;
}
.x3-rank-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s ease;
}
.x3-rank-conv {
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}
.x3-rank-receita {
  font-size: 12px;
  font-weight: 600;
  color: var(--x3-text-primary);
  text-align: right;
}

@media (max-width: 1024px) {
  .x3-insight-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .x3-insight-grid { grid-template-columns: 1fr; }
  .x3-rank-header, .x3-rank-row { grid-template-columns: 110px 1fr 56px 70px; gap: 8px; }
}

/* ── Responsivo ─────────────────────────────────────────────────── */
@media (max-width: 860px) {
  /* position:absolute relativo a .x3-chat-layout (position:relative) —
     cobre exatamente a área do chat, sem depender da altura da topbar. */
  .x3-sidebar { position: absolute; top: 0; left: 0; bottom: 0; z-index: 35; box-shadow: var(--x3-shadow-md); }
  .x3-sidebar.is-collapsed { width: 0; border-right: none; }
  .x3-tabs { gap: 16px; }
}

/* ── Fallback mínimo de utilitários, caso o CDN do Tailwind falhe ─
   (a aplicação não deve quebrar visualmente sem rede ao CDN)      */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.grid { display: grid; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.min-h-screen { min-height: 100vh; }
.w-full { width: 100%; }
.mx-auto { margin-left: auto; margin-right: auto; }
.text-center { text-align: center; }
