/* Assistente: conversa à esquerda, cards das análises surgindo à direita */
.chat-page { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); height: 100%; min-height: 0; }
.chat-col { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
.chat-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.chat-bar select { width: auto; max-width: 200px; height: 28px; font-size: 12px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.empty { min-height: 280px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.empty h2 { font-size: 15px; } .empty p { margin: 0 0 10px; color: var(--text-2); }

.msg-user { align-self: flex-end; max-width: 85%; padding: 9px 13px; border-radius: 12px 12px 4px 12px; background: var(--primary-soft); color: var(--text); white-space: pre-wrap; animation: rise .16s ease; }
.msg-ai { display: flex; flex-direction: column; gap: 8px; animation: rise .18s ease; }
.msg-ai .text { white-space: pre-wrap; }
.msg-ai .foot { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-size: 11.5px; color: var(--text-3); }
.pill { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 12px; }
.pill.ready { border-color: var(--primary); color: var(--primary); }
.pill.warn { border-color: var(--warning); color: var(--warning); } .pill.error { border-color: var(--danger); color: var(--danger); }
.spin { width: 12px; height: 12px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .9s linear infinite; }
.understood { font-size: 12.5px; color: var(--text-2); border-left: 3px solid var(--primary); padding: 2px 0 2px 10px; }
.note { font-size: 12.5px; color: var(--warning); border-left: 3px solid var(--warning); padding: 2px 0 2px 10px; }
.btn2 { align-self: flex-start; }
.group-title { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 26px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 12px; text-align: left; cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.fb { border: 0; background: transparent; cursor: pointer; padding: 0 2px; color: var(--text-2); font-size: 12px; }
.fb:hover { color: var(--primary); }

.composer { padding: 10px 14px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.composer .box { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--border-strong); border-radius: 10px; padding: 6px; background: var(--surface); }
.composer .box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer textarea { flex: 1; min-height: 38px; max-height: 132px; border: 0; box-shadow: none; resize: none; padding: 8px 6px; background: transparent; }
.composer textarea:focus { box-shadow: none; }
.send { width: 36px; height: 36px; border-radius: 8px; border: 0; background: var(--primary); color: #fff; display: grid; place-items: center; cursor: pointer; }
.send:hover { background: var(--primary-hover); } .send:disabled { opacity: .45; cursor: default; }
.composer .hint { font-size: 11px; color: var(--text-3); margin-top: 6px; }

.workspace { overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); }
.ws-empty { grid-column: 1 / -1; }

/* Cards de análise */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; animation: rise .22s ease; transition: box-shadow .18s, border-color .18s; }
.card.flash { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.card-head { display: flex; gap: 8px; align-items: flex-start; padding: 12px 14px 4px; }
.card-head h3 { font-size: 14px; font-weight: 650; } .card-head small { display: block; color: var(--text-3); font-size: 11.5px; }
.card-head .tools { margin-left: auto; display: flex; gap: 4px; }
.icon { height: 24px; padding: 0 7px; border-radius: 5px; border: 1px solid var(--border); background: transparent; color: var(--text-2); font-size: 11.5px; cursor: pointer; }
.icon:hover { color: var(--text); border-color: var(--border-strong); background: var(--hover); }
.card-body { padding: 6px 14px 10px; min-height: 0; }
.card-body canvas { width: 100% !important; height: 280px !important; }
.kpi-row { display: flex; flex-wrap: wrap; gap: 8px; }
.kpi-inline { min-width: 160px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
.kpi-inline span { display: block; font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.kpi-inline b { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
/* Destaques do card: total, líder, variação */
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; padding: 6px 14px 4px; }
.insight { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.insight span { display: block; font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insight b { display: block; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insight em { font-style: normal; font-size: 11.5px; color: var(--text-2); font-weight: 600; }
.insight em.up { color: var(--success, #15803d); } .insight em.down { color: var(--danger); }
.card-body.is-kpi .kpi-inline b { font-size: 28px; }
.calc { margin: 0 14px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; padding: 6px 10px; }
.calc summary { cursor: pointer; color: var(--text-2); }
.calc pre { white-space: pre-wrap; font: 12px/1.5 inherit; margin: 8px 0 2px; color: var(--text); }
.tbl { overflow: auto; max-height: 340px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tbl table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th, .tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl th { font-weight: 600; color: var(--text-2); position: sticky; top: 0; background: var(--surface-2); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Painel de BI interativo */
.card.dash { grid-column: 1 / -1; }
.card.dash.loading .dash-grid, .card.dash.loading [data-kpis] { opacity: .55; transition: opacity .15s; }
.dash-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 6px 14px; }
.dash-bar select { width: auto; height: 30px; }
.dash-year { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.dash-year input { width: 180px; accent-color: var(--primary); } .dash-year b { min-width: 34px; color: var(--text); font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 12px; padding: 4px 14px 14px; }
.dash-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 10px 12px; min-width: 0; }
.dash-panel.wide { grid-column: 1 / -1; }
.dash-panel h4 { margin: 0 0 6px; font-size: 13px; }
.dash-chart { height: 280px; position: relative; } .dash-panel.wide .dash-chart { height: 220px; }
.crumb-up { border: 0; background: none; padding: 0; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

@media (max-width: 1000px) {
  .chat-page { grid-template-columns: 1fr; grid-template-rows: 70dvh auto; height: auto; }
  .chat-col { border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace { overflow: visible; }
}
