:root {
  --azul: #005eb8;
  --azul-escuro: #00447f;
  --verde: #0a8f4e;
  --bg: #eef1f5;
  --card: #ffffff;
  --texto: #1f2937;
  --muted: #6b7280;
  --borda: #e2e6ec;
  --bot: #f1f5fb;
  --user: #005eb8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
}

/* ---------- Topbar ---------- */
.topbar {
  height: 52px;
  background: var(--azul);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: #7ed957; }
.brand .sub { font-size: 12px; opacity: .8; margin-left: 6px; font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.status { font-size: 12px; opacity: .9; }
.status.err { color: #ffd7d7; }
.reset-btn {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 7px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.reset-btn:hover { background: rgba(255,255,255,.28); }
.reset-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: calc(100vh - 52px);
  padding: 12px;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

/* ---------- Chat ---------- */
.chat-col, .deliverables-col {
  background: var(--card);
  border: 1px solid var(--borda);
  border-radius: 12px;
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
/* ---------- Progress ---------- */
.progress {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--borda); background: #fafbfc;
}
.progress-track {
  flex: 1; height: 7px; background: #e2e8f0; border-radius: 20px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--verde);
  border-radius: 20px; transition: width .4s ease;
}
.progress-label {
  font-size: 12.5px; font-weight: 600; color: var(--azul-escuro); white-space: nowrap;
}

.messages { flex: 1; overflow-y: auto; padding: 18px; }

.msg { display: flex; margin-bottom: 14px; }
.msg .bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14.5px; line-height: 1.55;
  word-wrap: break-word;
}
.msg.bot .bubble { background: var(--bot); border: 1px solid var(--borda); border-top-left-radius: 4px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user); color: #fff; border-top-right-radius: 4px; }

/* markdown dentro das bolhas */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble strong { font-weight: 700; }
.bubble a { color: var(--azul); }
.msg.user .bubble a { color: #cfe4ff; }

/* ---------- System notes (Soluções Sebrae) ---------- */
.msg.system-note { justify-content: center; }
.msg.system-note .bubble.system-bubble {
  max-width: 90%;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  font-size: 13px;
  color: #92400e;
  padding: 8px 14px;
}
.msg.system-note .bubble.system-bubble a { color: var(--azul); font-weight: 600; }

/* ---------- CTA Sebrae (final) ---------- */
.msg.system-note .cta-bubble {
  max-width: 90%;
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f5e9 100%);
  border: 1px solid #c3dafe;
  border-radius: 12px;
  padding: 16px 20px;
  color: var(--texto);
  font-size: 14px;
}
.cta-sebrae p { margin: 0 0 12px; line-height: 1.5; }
.cta-btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 12px;
}
.cta-primary {
  background: var(--azul);
  color: #fff !important;
}
.cta-primary:hover { background: var(--azul-escuro); }
.cta-links {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
}
.cta-links a {
  display: inline-block;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--borda);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--azul) !important;
  text-decoration: none;
}
.cta-links a:hover { background: #f0f7ff; border-color: var(--azul); }

.typing { display: inline-block; }
.typing::after {
  content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted);
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer {
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--borda); background: #fafbfc;
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  padding: 10px 12px; border: 1px solid var(--borda); border-radius: 10px;
  font: inherit; font-size: 14.5px; line-height: 1.4;
}
.composer textarea:focus { outline: 2px solid var(--azul); border-color: var(--azul); }
.composer button {
  padding: 0 18px; background: var(--azul); color: #fff;
  border: 0; border-radius: 10px; font-weight: 600; cursor: pointer;
}
.composer button:hover { background: var(--azul-escuro); }
.composer button:disabled { background: #9db8d6; cursor: not-allowed; }

/* ---------- Deliverables ---------- */
.deliverables-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--borda);
  background: #fafbfc;
}
.deliverables-head .counter {
  background: var(--verde); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 22px; text-align: center; padding: 2px 7px; border-radius: 20px;
}
.deliverables { flex: 1; overflow-y: auto; padding: 14px; }
.deliverables .empty { color: var(--muted); font-size: 13px; line-height: 1.5; }

.deliverable {
  border: 1px solid var(--borda);
  border-left: 4px solid var(--verde);
  border-radius: 8px;
  margin-bottom: 14px;
  background: #fff;
  overflow: hidden;
}
.deliverable.streaming { border-left-color: var(--azul); }
.deliverable > h3 {
  margin: 0; padding: 10px 14px;
  background: #f5f8fc; border-bottom: 1px solid var(--borda);
  font-size: 13.5px; color: var(--azul-escuro);
  display: flex; align-items: center; gap: 8px;
}
.deliverable > h3 .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  background: #e2ecf7; color: var(--azul); padding: 2px 6px; border-radius: 4px;
  font-weight: 700;
}
.deliverable .body { padding: 12px 14px; font-size: 13.5px; line-height: 1.55; }

/* markdown dentro dos entregáveis */
.deliverable .body table {
  width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12.5px;
}
.deliverable .body th, .deliverable .body td {
  border: 1px solid var(--borda); padding: 6px 8px; text-align: left;
}
.deliverable .body th { background: #f1f5fb; }
.deliverable .body h1, .deliverable .body h2, .deliverable .body h3, .deliverable .body h4 {
  font-size: 14px; margin: 12px 0 6px; color: var(--azul-escuro);
}
.deliverable .body ul, .deliverable .body ol { padding-left: 20px; margin: 6px 0; }
.deliverable .body p { margin: 0 0 8px; }
.deliverable .body hr { border: none; border-top: 1px solid var(--borda); margin: 12px 0; }

/* --- Tipo: SWOT (quadrante 2×2 colorido) --- */
.deliverable[data-tipo="swot"] .body table { border: none; }
.deliverable[data-tipo="swot"] .body th,
.deliverable[data-tipo="swot"] .body td { border: 3px solid #fff; border-radius: 6px; vertical-align: top; width: 50%; padding: 10px; }
/* Forças (verde) — linhas 1-2 coluna 1 */
.deliverable[data-tipo="swot"] .body tr:nth-child(-n+2) td:nth-child(1),
.deliverable[data-tipo="swot"] .body tr:nth-child(-n+2) th:nth-child(1) { background: #e8f5e9; }
/* Fraquezas (laranja) — linhas 1-2 coluna 2 */
.deliverable[data-tipo="swot"] .body tr:nth-child(-n+2) td:nth-child(2),
.deliverable[data-tipo="swot"] .body tr:nth-child(-n+2) th:nth-child(2) { background: #fff3e0; }
/* Oportunidades (azul) — linhas 3+ coluna 1 */
.deliverable[data-tipo="swot"] .body tr:nth-child(n+3) td:nth-child(1),
.deliverable[data-tipo="swot"] .body tr:nth-child(n+3) th:nth-child(1) { background: #e3f2fd; }
/* Ameaças (rosa) — linhas 3+ coluna 2 */
.deliverable[data-tipo="swot"] .body tr:nth-child(n+3) td:nth-child(2),
.deliverable[data-tipo="swot"] .body tr:nth-child(n+3) th:nth-child(2) { background: #fce4ec; }

/* --- Tipo: Matriz de Priorização / Eisenhower (2×2 colorido) --- */
.deliverable[data-tipo="matriz"] .body table { border: none; }
.deliverable[data-tipo="matriz"] .body th,
.deliverable[data-tipo="matriz"] .body td { border: 3px solid #fff; border-radius: 6px; vertical-align: top; width: 50%; padding: 10px; }
/* Faça Agora (verde) — linhas 1-2 coluna 1 */
.deliverable[data-tipo="matriz"] .body tr:nth-child(-n+2) td:nth-child(1),
.deliverable[data-tipo="matriz"] .body tr:nth-child(-n+2) th:nth-child(1) { background: #e8f5e9; }
/* Agende (azul) — linhas 1-2 coluna 2 */
.deliverable[data-tipo="matriz"] .body tr:nth-child(-n+2) td:nth-child(2),
.deliverable[data-tipo="matriz"] .body tr:nth-child(-n+2) th:nth-child(2) { background: #e3f2fd; }
/* Delegue (amarelo) — linhas 3+ coluna 1 */
.deliverable[data-tipo="matriz"] .body tr:nth-child(n+3) td:nth-child(1),
.deliverable[data-tipo="matriz"] .body tr:nth-child(n+3) th:nth-child(1) { background: #fffde7; }
/* Elimine (vermelho) — linhas 3+ coluna 2 */
.deliverable[data-tipo="matriz"] .body tr:nth-child(n+3) td:nth-child(2),
.deliverable[data-tipo="matriz"] .body tr:nth-child(n+3) th:nth-child(2) { background: #fce4ec; }

/* --- Tipo: Finanças (tabela zebrada) --- */
.deliverable[data-tipo="financas"] .body table tr:nth-child(even) td { background: #f8fafc; }
.deliverable[data-tipo="financas"] .body table tr:last-child td { font-weight: 700; background: #eef6ee; }
.deliverable[data-tipo="financas"] .body strong { color: var(--azul-escuro); }

/* --- Tipo: Personas (cards visuais) --- */
.deliverable[data-tipo="personas"] .body .persona-card {
  border: 1px solid var(--borda);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.deliverable[data-tipo="personas"] .body .persona-header {
  background: var(--azul);
  color: #fff;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
}
.deliverable[data-tipo="personas"] .body .persona-body {
  padding: 12px 14px;
  background: #fafbfc;
}
.deliverable[data-tipo="personas"] .body .persona-body p { margin: 0 0 6px; }
.deliverable[data-tipo="personas"] .body .persona-body ul { margin: 4px 0; }
.deliverable[data-tipo="personas"] .body .persona-body strong { color: var(--azul-escuro); }
.deliverable[data-tipo="personas"] .body .persona-body em {
  background: #e3f2fd; color: var(--azul); font-style: normal;
  padding: 2px 8px; border-radius: 12px; font-size: 11.5px; font-weight: 600;
  display: inline-block; margin: 2px 2px;
}

/* Fallback: h3-based personas (if post-processing doesn't kick in) */
.deliverable[data-tipo="personas"] .body > h3 {
  background: var(--azul); color: #fff; padding: 8px 14px; border-radius: 8px 8px 0 0;
  font-size: 14px; margin: 16px 0 0; display: block;
}
.deliverable[data-tipo="personas"] .body > h3:first-child { margin-top: 0; }
.deliverable[data-tipo="personas"] .body > h3 ~ p,
.deliverable[data-tipo="personas"] .body > h3 ~ ul {
  border: 1px solid var(--borda); border-top: none; padding: 10px 14px; margin: 0;
  background: #fafbfc;
}
.deliverable[data-tipo="personas"] .body > h3 ~ ul { padding-left: 28px; }

/* --- Tipo: Canvas (BMC grid visual) --- */
.bmc-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 8px 0;
}
.bmc-cell {
  background: #f5f8fc;
  border: 1px solid var(--borda);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  min-height: 60px;
}
.bmc-label {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--azul);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--azul);
}
.bmc-cell ul { padding-left: 14px; margin: 4px 0; }
.bmc-cell p { margin: 2px 0; }

/* Canvas table fallback */
.deliverable[data-tipo="canvas"] .body table { border: none; }
.deliverable[data-tipo="canvas"] .body th,
.deliverable[data-tipo="canvas"] .body td {
  border: 2px solid #fff; border-radius: 6px; background: #f5f8fc;
  vertical-align: top; padding: 8px 10px; font-size: 12px;
}
.deliverable[data-tipo="canvas"] .body th { background: var(--azul); color: #fff; text-align: center; font-size: 11px; }

/* --- Tipo: Metas (checklist visual) --- */
.deliverable[data-tipo="metas"] .body li { list-style: none; position: relative; padding-left: 22px; margin-bottom: 6px; }
.deliverable[data-tipo="metas"] .body li::before {
  content: "☐"; position: absolute; left: 0; font-size: 15px; color: var(--verde);
}

/* --- Tipo: Funil de Vendas --- */
.deliverable[data-tipo="funil"] .body strong { color: var(--azul-escuro); }
.deliverable[data-tipo="funil"] { border-left-color: var(--verde); }

/* --- Tipo: Plano Consolidado --- */
.deliverable[data-tipo="plano"] { border-left-color: var(--azul-escuro); }
.deliverable[data-tipo="plano"] .body h2, .deliverable[data-tipo="plano"] .body h3 {
  border-bottom: 1px solid var(--borda); padding-bottom: 4px;
}

/* --- Tipo: Proposta de Valor --- */
.deliverable[data-tipo="proposta"] { border-left-color: var(--azul); }
.deliverable[data-tipo="proposta"] .body { font-size: 14.5px; line-height: 1.65; }

/* --- Tag colorida por tipo no header --- */
.deliverable[data-tipo="swot"] > h3 .tag { background: #e8f5e9; color: #2e7d32; }
.deliverable[data-tipo="financas"] > h3 .tag { background: #fff3e0; color: #e65100; }
.deliverable[data-tipo="personas"] > h3 .tag { background: #e3f2fd; color: #1565c0; }
.deliverable[data-tipo="metas"] > h3 .tag { background: #f3e5f5; color: #7b1fa2; }
.deliverable[data-tipo="canvas"] > h3 .tag { background: #e0f7fa; color: #00695c; }
.deliverable[data-tipo="funil"] > h3 .tag { background: #e8f5e9; color: #2e7d32; }
.deliverable[data-tipo="plano"] > h3 .tag { background: #e8eaf6; color: #283593; }
.deliverable[data-tipo="proposta"] > h3 .tag { background: #ede7f6; color: #4527a0; }
.deliverable[data-tipo="matriz"] > h3 .tag { background: #fffde7; color: #f57f17; }
