:root {
  --bg: #0a0b0f;
  --bg-elev: #121420;
  --bg-elev-2: #171a28;
  --border: #232739;
  --border-soft: #1b1e2c;
  --text: #e7e9f0;
  --text-dim: #9aa0b4;
  --text-faint: #646b84;
  --accent: #6d5cff;
  --accent-2: #00d4ff;
  --accent-grad: linear-gradient(135deg, #6d5cff 0%, #00d4ff 100%);
  --ok: #2ee6a6;
  --warn: #ffb020;
  --err: #ff5d6c;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(900px 500px at 85% -10%, rgba(109, 92, 255, 0.14), transparent 60%),
    radial-gradient(700px 500px at -5% 110%, rgba(0, 212, 255, 0.1), transparent 55%);
  background-attachment: fixed;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: linear-gradient(180deg, rgba(18, 20, 32, 0.9), rgba(10, 11, 15, 0.9));
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--accent-grad);
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #0a0b0f;
  box-shadow: 0 6px 20px rgba(109, 92, 255, 0.45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 17px; letter-spacing: 0.2px; }
.brand-text span { font-size: 12px; color: var(--text-faint); }

.run-panel { display: flex; flex-direction: column; gap: 10px; }

.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 16px;
  border: none; border-radius: var(--radius-sm);
  background: var(--accent-grad);
  color: #06070c; font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s;
  box-shadow: 0 8px 24px rgba(109, 92, 255, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(109, 92, 255, 0.5); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-icon { font-size: 11px; }

.btn-ghost {
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); background: rgba(109, 92, 255, 0.08); }

.btn-mini {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-faint); font-size: 11px; padding: 3px 10px;
  border-radius: 6px; cursor: pointer;
}
.btn-mini:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------------- Pipeline ---------------- */
.pipeline-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pipeline-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--text-faint); margin-bottom: 14px;
}
.pipeline { list-style: none; display: flex; flex-direction: column; }

.step {
  position: relative;
  display: flex; gap: 14px;
  padding: 2px 0 20px 0;
}
.step:last-child { padding-bottom: 0; }
.step::before {
  content: "";
  position: absolute;
  left: 13px; top: 30px; bottom: -4px;
  width: 2px;
  background: var(--border);
}
.step:last-child::before { display: none; }

.step-dot {
  position: relative; z-index: 1;
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-elev);
  display: grid; place-items: center;
  font-size: 12px; color: var(--text-faint);
  transition: all 0.3s ease;
}
.step-body { padding-top: 2px; }
.step-title { font-size: 13.5px; font-weight: 600; color: var(--text-dim); transition: color 0.3s; }
.step-desc { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; line-height: 1.4; }
.step-meta { font-size: 11px; color: var(--text-faint); margin-top: 5px; font-family: var(--mono); }

.step.running .step-dot {
  border-color: var(--accent);
  color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(109, 92, 255, 0.18);
  animation: pulse 1.4s ease-in-out infinite;
}
.step.running .step-title { color: var(--text); }
.step.done .step-dot { border-color: var(--ok); background: rgba(46, 230, 166, 0.14); color: var(--ok); }
.step.done .step-title { color: var(--text); }
.step.error .step-dot { border-color: var(--err); background: rgba(255, 93, 108, 0.14); color: var(--err); }
.step.skipped { opacity: 0.55; }
.step.skipped .step-dot { border-style: dashed; border-color: var(--border); color: var(--text-faint); background: transparent; }
.step.skipped .step-title { color: var(--text-faint); text-decoration: line-through; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(109, 92, 255, 0.18); }
  50% { box-shadow: 0 0 0 7px rgba(109, 92, 255, 0.05); }
}

.spinner {
  width: 13px; height: 13px;
  border: 2px solid rgba(0, 212, 255, 0.25);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Stats ---------------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 20px; font-weight: 700; font-family: var(--mono); }
.stat-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1px; }

/* ---------------- Main ---------------- */
.main { padding: 28px 34px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.status-line { color: var(--text-dim); font-size: 13.5px; margin-top: 5px; }

.global-badge {
  font-size: 12px; font-weight: 600; padding: 7px 14px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.6px;
  border: 1px solid var(--border);
}
.global-badge.idle { color: var(--text-faint); }
.global-badge.running { color: var(--accent-2); border-color: rgba(0, 212, 255, 0.4); background: rgba(0, 212, 255, 0.08); }
.global-badge.done { color: var(--ok); border-color: rgba(46, 230, 166, 0.4); background: rgba(46, 230, 166, 0.1); }
.global-badge.error { color: var(--err); border-color: rgba(255, 93, 108, 0.4); background: rgba(255, 93, 108, 0.1); }
.global-badge.done.interrompido, .global-badge.interrompido { color: var(--warn); border-color: rgba(255, 176, 32, 0.4); background: rgba(255, 176, 32, 0.1); }

/* ---------------- Briefing editor ---------------- */
.briefing {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 22px; overflow: hidden;
}
.briefing.hidden { display: none; }
.briefing-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft);
  font-size: 13px; color: var(--text-dim);
}
#briefingInput {
  width: 100%; min-height: 220px; resize: vertical;
  background: #0c0e16; border: none; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 12.5px;
  line-height: 1.6; padding: 16px;
}

/* ---------------- Results ---------------- */
.results { display: flex; flex-direction: column; gap: 18px; }

.empty-state {
  text-align: center; padding: 80px 20px; color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state p { font-size: 15px; color: var(--text-dim); }
.empty-state small { font-size: 13px; }
.empty-ring {
  width: 60px; height: 60px; border-radius: 50%;
  border: 2px dashed var(--border); margin-bottom: 8px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: slideIn 0.4s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.card-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  user-select: none;
}
.card-head:hover { background: var(--bg-elev-2); }
.card-num {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  background: rgba(109, 92, 255, 0.15); color: var(--accent-2);
  display: grid; place-items: center; font-weight: 700; font-family: var(--mono);
}
.card-head .meta { flex: 1; min-width: 0; }
.card-head .meta h3 { font-size: 15px; font-weight: 600; }
.card-head .meta p { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

.card-badge {
  font-size: 11px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
}
.card-badge.running { color: var(--accent-2); background: rgba(0, 212, 255, 0.1); }
.card-badge.done { color: var(--ok); background: rgba(46, 230, 166, 0.12); }
.card-badge.error { color: var(--err); background: rgba(255, 93, 108, 0.12); }
.card-tokens { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
/* Estimativa de custo: bem pequena e discreta, ao lado dos tokens. */
.cost-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-faint);
  opacity: 0.7;
  margin-left: 4px;
  white-space: nowrap;
}
/* Tabela de custo por ciclo (Agente 1 dois-ciclos). */
.custo-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.custo-table th, .custo-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border-soft); }
.custo-table th { color: var(--text-dim); font-weight: 600; }
.custo-table tfoot td { border-top: 1px solid var(--border); border-bottom: none; }
.custo-nota { font-size: 11px; color: var(--text-faint); margin: 6px 0 0; }
/* Abas Ciclo 1 / Ciclo 2 do relatório executivo. */
.rel-tabs { display: flex; gap: 4px; margin: 8px 0 10px; }
.rel-tab {
  padding: 4px 12px; border-radius: 8px 8px 0 0; border: 1px solid var(--border);
  border-bottom: none; background: var(--bg-elev); color: var(--text-dim);
  font-size: 12.5px; cursor: pointer;
}
.rel-tab.active { background: var(--bg-elev-2); color: var(--text); font-weight: 600; }
.rel-pane.hidden { display: none; }
/* Rodapé do card do Agente 1 (cálculos + custo), após a lista de atividades. */
.fin-footer { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.chevron { color: var(--text-faint); font-size: 12px; transition: transform 0.2s; }
.card.collapsed .chevron { transform: rotate(-90deg); }

.card-body { padding: 4px 24px 24px; }
.card.collapsed .card-body { display: none; }

.card-loading {
  display: flex; align-items: center; gap: 12px;
  padding: 24px; color: var(--text-dim); font-size: 13.5px;
}

/* Markdown render */
.md { font-size: 14px; line-height: 1.7; color: var(--text); word-wrap: break-word; }
.md h1, .md h2, .md h3 { margin: 20px 0 10px; line-height: 1.3; font-weight: 650; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md h2 { border-bottom: 1px solid var(--border-soft); padding-bottom: 6px; }
.md p { margin: 10px 0; color: var(--text-dim); }
.md ul, .md ol { margin: 10px 0 10px 22px; color: var(--text-dim); }
.md li { margin: 5px 0; }
.md strong { color: var(--text); }
.md code {
  font-family: var(--mono); font-size: 12.5px;
  background: #0c0e16; padding: 2px 6px; border-radius: 5px; color: var(--accent-2);
}
.md pre {
  background: #0c0e16; border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 14px; overflow-x: auto; margin: 12px 0;
}
.md pre code { background: none; padding: 0; color: var(--text); }
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.md th { background: var(--bg-elev-2); }
.md a { color: var(--accent-2); }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text-dim); margin: 12px 0; }

.raw-json {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  background: #0c0e16; border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 16px; overflow-x: auto;
  color: var(--text-dim); white-space: pre-wrap; word-break: break-word;
}

.verdict {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; margin-bottom: 16px;
  font-weight: 600; font-size: 13.5px;
}
.verdict.ok { background: rgba(46, 230, 166, 0.12); color: var(--ok); }
.verdict.no { background: rgba(255, 93, 108, 0.12); color: var(--err); }
.verdict.wait { background: rgba(255, 193, 7, 0.14); color: #d9a400; }

/* Bloco "aguardando %TRA": simula o recebimento do %TRA e dispara o Ciclo 2 (teste). */
.tra-prompt {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--bg-elev);
}
.tra-prompt-hint { font-size: 13px; color: var(--text-dim); margin: 0 0 8px; }
.tra-prompt-nums { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; margin-bottom: 10px; }
.tra-prompt-input { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tra-prompt-input label { font-size: 12px; color: var(--text-dim); flex: 1 1 100%; }
.tra-input {
  width: 140px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.tra-prompt-status { font-size: 12.5px; color: var(--text-dim); margin-top: 8px; min-height: 1em; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab {
  font-size: 12.5px; padding: 6px 14px; border-radius: 8px; cursor: pointer;
  color: var(--text-faint); border: 1px solid transparent;
}
.tab.active { color: var(--text); background: var(--bg-elev-2); border-color: var(--border); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

/* ---------------- Sub-atividades (Agente 1) ---------------- */
.activities {
  list-style: none;
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.activity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--text-faint);
  transition: color 0.2s ease;
}
.activity-dot {
  width: 18px; height: 18px;
  flex: 0 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  font-size: 11px;
  color: var(--ok);
  background: var(--bg-elev-2);
}
.activity.running { color: var(--text); }
.activity.running .activity-dot { border-color: var(--accent-2); }
.activity.done { color: var(--text-dim); }
.activity.done .activity-dot {
  border-color: var(--ok);
  color: var(--ok);
}
.spinner-sm { width: 10px; height: 10px; border-width: 1.5px; }

/* ---------------- Sub-atividades: cabeçalho clicável (abre modal) ---------------- */
.activity-head {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  transition: background 0.15s ease;
}
.activity-head:hover { background: var(--bg-elev-2); }
.activity-open {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}
/* O indicador "detalhes ↗" só aparece quando há detalhes e ao passar o mouse. */
.activity.has-detail .activity-head:hover .activity-open { opacity: 1; color: var(--accent-2); }
.activity:not(.has-detail) .activity-head { cursor: default; }
.activity:not(.has-detail) .activity-head:hover { background: transparent; }

/* ---------------- Modal de detalhes de atividade ---------------- */
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  z-index: 1000;
  animation: modalFade 0.15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(760px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modalRise 0.18s ease;
}
@keyframes modalRise { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 15px; font-weight: 600; flex: 1; }
.modal-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: all 0.15s ease;
}
.modal-close:hover { background: var(--bg-elev-2); color: var(--text); border-color: var(--err); }
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.act-section { display: flex; flex-direction: column; gap: 6px; }

.act-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  font-weight: 600;
}
.act-md { font-size: 13px; color: var(--text-dim); }

/* Cartões de cálculo (observabilidade) */
.calc-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.calc-name {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.calc-origin {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-2);
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 20px;
  padding: 1px 8px;
}
.calc-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.calc-row > span {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-top: 2px;
}
.calc-row code {
  font-family: var(--mono);
  color: var(--text);
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
}
.calc-row p { margin: 0; }

/* Alertas por severidade */
.alert-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.sev-dot {
  width: 8px; height: 8px; flex: 0 0 8px;
  border-radius: 50%;
  margin-top: 5px;
}
.sev-dot.critico { background: var(--err); }
.sev-dot.alerta { background: var(--warn); }
.sev-dot.info { background: var(--accent-2); }
.alert-item.critico { color: #ffc3c9; }

/* Resumo agregado do agente financeiro (acima da lista de atividades) */
.fin-summary { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.audit-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.audit-chip.ok { color: var(--ok); border-color: rgba(46, 230, 166, 0.35); }
.audit-chip.no { color: var(--err); border-color: rgba(255, 93, 108, 0.35); }

.calc-details > summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  padding: 4px 0;
}
.calc-details .raw-json { margin-top: 10px; }

/* Análise consolidada do agente financeiro (markdown agregado das atividades) */
.calc-details.consolidated {
  margin-top: 6px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}
.calc-details.consolidated > summary {
  color: var(--text);
  font-weight: 600;
}
.calc-details.consolidated .md { margin-top: 10px; }

/* ---------------- Relatório executivo (Nível 1 — leitura de negócio) ---------------- */
.exec-report {
  margin-top: 6px;
  padding: 14px 16px;
  border: 1px solid rgba(109, 92, 255, 0.35);
  border-radius: var(--radius);
  background: rgba(109, 92, 255, 0.06);
}
.exec-report-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 8px;
}
.exec-report .md { color: var(--text); }
/* O consolidado logo após o relatório executivo recua um nível visualmente. */
.exec-report + .calc-details.consolidated { margin-top: 12px; }


/* ---------------- Fontes consultadas (observabilidade do Agente 2) ---------------- */
.source-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.source-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.source-link {
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  word-break: break-all;
}
.source-link:hover { text-decoration: underline; }
.source-title { font-size: 12px; color: var(--text-dim); }
.source-rel { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }
.source-snippet {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 8px;
}

/* ---------------- Chat do analista ---------------- */
.chat-panel {
  margin-top: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-head h2 { font-size: 15px; font-weight: 600; }
.chat-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.chat-messages {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 420px;
  overflow-y: auto;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
}
.chat-msg.user .chat-bubble {
  background: var(--accent-grad);
  color: #0a0b0f;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble.md > *:first-child { margin-top: 0; }
.chat-bubble.md > *:last-child { margin-bottom: 0; }
.chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-soft);
}
.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input:disabled { opacity: 0.6; }
.chat-send { padding: 10px 20px; white-space: nowrap; }
.chat-send:disabled { opacity: 0.6; cursor: default; }

/* ---------------- Abas (Atual / Histórico) ---------------- */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tabs { display: inline-flex; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-grad); color: #0a0b0f; font-weight: 600; }
.view.hidden { display: none; }

/* ---------------- Lista de histórico ---------------- */
.history {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  color: var(--text-dim);
}
.history-list { list-style: none; }
.history-empty { padding: 24px 18px; color: var(--text-faint); font-size: 13px; }
.history-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s ease;
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--bg-elev-2); }
.history-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.history-title { font-size: 14px; font-weight: 600; color: var(--text); }
.history-date { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.history-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.history-status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.history-status.completed { color: var(--ok); }
.history-status.interrupted { color: var(--warn); }
.history-status.error { color: var(--err); }
.history-status.running { color: var(--accent-2); }
.verdict-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.verdict-pill.ok { color: var(--ok); border-color: rgba(46, 230, 166, 0.35); }
.verdict-pill.no { color: var(--err); border-color: rgba(255, 93, 108, 0.35); }
.history-tokens { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.global-badge.running { } /* mantém estilo existente para 'carregando' */

/* ---------------- Aba Calculadora (auditoria do Agente 1) ---------------- */
.calc { padding: 4px 0 40px; }
.calc-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}
.calc-left { display: flex; flex-direction: column; gap: 16px; }
.calc-block {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.calc-block-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px; color: var(--text-dim);
}
.calc-briefing-hint {
  padding: 14px 16px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-faint);
}
.calc-briefing-hint strong { color: var(--text-dim); }

.calc-tra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 16px; }
.calc-unit { color: var(--text-dim); font-size: 14px; }
.calc-hint { flex-basis: 100%; color: var(--text-faint); font-size: 11px; margin-top: 2px; }

.calc-constants { padding: 10px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.calc-const { display: flex; flex-direction: column; gap: 4px; }
.calc-const-label { font-size: 12px; color: var(--text-dim); }
.calc-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
}
.calc-input:focus { outline: none; border-color: var(--accent); }
.calc-tra .calc-input { width: 120px; }

.calc-right { display: flex; flex-direction: column; gap: 14px; }
.calc-status {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px; color: var(--text-dim);
}
.calc-steps { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.calc-bloco-head {
  list-style: none;
  margin: 8px 0 2px;
  padding-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-soft);
}
.calc-bloco-head:first-child { margin-top: 0; }
.calc-step {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.calc-step.na { border-left-color: var(--text-faint); opacity: 0.85; }
.calc-step-head { display: flex; align-items: center; gap: 10px; }
.calc-step-num {
  width: 22px; height: 22px; flex: none;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--bg-elev-2);
  font-size: 12px; font-family: var(--mono); color: var(--text-dim);
}
.calc-step-title { font-size: 14px; font-weight: 600; flex: 1; }
.calc-step-badge {
  font-size: 11px; font-weight: 600;
  padding: 1px 9px; border-radius: 20px;
  border: 1px solid var(--border);
}
.calc-step-badge.ok { color: var(--ok); border-color: rgba(46, 230, 166, 0.35); }
.calc-step-badge.na { color: var(--text-faint); }
.calc-step-formula {
  display: block;
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-2);
  background: var(--bg);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  word-break: break-word;
}
.calc-step-obs { margin-top: 8px; font-size: 12px; color: var(--text-faint); font-style: italic; }
.calc-step-motivo { margin-top: 8px; font-size: 12px; color: var(--warn); }
.calc-io {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}
.calc-io-col { display: flex; flex-direction: column; gap: 5px; }
.calc-io-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-faint); margin-bottom: 2px;
}
.kv { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.kv span { font-size: 12px; color: var(--text-dim); word-break: break-word; }
.kv code { font-family: var(--mono); font-size: 12px; color: var(--text); white-space: nowrap; }

@media (max-width: 1100px) {
  .calc-grid { grid-template-columns: 1fr; }
  .calc-io { grid-template-columns: 1fr; }
}

/* ---------------- Sessão (sidebar) ---------------- */
.session-box {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.session-email {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
