/* ==========================================================
   Componentes reutilizáveis
   ========================================================== */

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .right { margin-left: auto; }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.link { display: block; color: inherit; transition: border-color .15s, transform .15s; }
.card.link:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.card .icon-badge {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; margin-bottom: 12px;
}
.card .icon-badge svg { width: 20px; height: 20px; }

/* ---------- KPI ---------- */
.kpi .label { font-size: .8rem; color: var(--text-2); font-weight: 500; }
.kpi .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: .78rem; color: var(--text-3); margin-top: 2px; }
@media (max-width: 520px) { .kpi .value { font-size: 1.2rem; } .card.kpi { padding: 14px; } }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { padding: 8px; }

/* ---------- Badges / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: .72rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- Alertas ---------- */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: .9rem;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.alert.ok { background: var(--ok-soft); border-color: transparent; }
.alert.ok svg { color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: transparent; }
.alert.warn svg { color: var(--warn); }
.alert.err { background: var(--err-soft); border-color: transparent; }
.alert.err svg { color: var(--err); }
.alert.info { background: var(--info-soft); border-color: transparent; }
.alert.info svg { color: var(--info); }
.alert p:last-child { margin-bottom: 0; }
.alert strong { display: block; margin-bottom: 2px; }

/* ---------- Formulários ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.field label, .field .label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 5px; }
.field .help { font-size: .78rem; color: var(--text-3); margin-top: 4px; }
input[type="text"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .92rem;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.field.invalid input, .field.invalid select { border-color: var(--err); }
.field .error { color: var(--err); font-size: .78rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Opções em formato de cartão (assistente) */
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.choice {
  position: relative; display: block;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; cursor: pointer; background: var(--surface);
  transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--border-strong); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .t { font-weight: 600; font-size: .92rem; display: block; }
.choice .d { font-size: .78rem; color: var(--text-3); display: block; margin-top: 2px; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Stepper do assistente ---------- */
.stepper { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.stepper .s {
  flex: 1; min-width: 70px; height: 5px; border-radius: 99px; background: var(--border);
}
.stepper .s.done { background: var(--primary); }
.stepper .s.current { background: var(--primary); opacity: .55; }
.wizard-q h2 { font-size: 1.25rem; }
.wizard-q .why { color: var(--text-2); font-size: .9rem; margin-bottom: 16px; }
.wizard-nav { display: flex; gap: 10px; margin-top: 22px; }
.wizard-nav .right { margin-left: auto; }

/* ---------- Passo a passo (resultado) ---------- */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps > li {
  position: relative; padding: 0 0 22px 48px;
  counter-increment: step;
}
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.steps > li::after {
  content: ""; position: absolute; left: 15px; top: 36px; bottom: 4px;
  width: 2px; background: var(--border);
}
.steps > li:last-child::after { display: none; }
.steps h3 { margin-top: 5px; }
.step-body { color: var(--text-2); font-size: .92rem; }
.step-body p { margin-bottom: .5em; }
.field-explain {
  margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
.field-explain .fe-row { display: grid; grid-template-columns: 200px 1fr; border-top: 1px solid var(--border); }
.field-explain .fe-row:first-child { border-top: 0; }
.field-explain .fe-k { padding: 9px 12px; background: var(--surface-2); font-weight: 600; font-size: .82rem; color: var(--text); }
.field-explain .fe-v { padding: 9px 12px; font-size: .86rem; }
.field-explain .fe-v code, code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; color: var(--text); }
@media (max-width: 640px) { .field-explain .fe-row { grid-template-columns: 1fr; } .field-explain .fe-k { padding-bottom: 4px; } }

.src { font-size: .76rem; color: var(--text-3); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.src a { color: var(--text-3); text-decoration: underline; text-decoration-color: var(--border-strong); }

/* ---------- Tabela ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 200px; }
tbody tr:hover td { background: var(--surface-2); }
tr.muted td { color: var(--text-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 10px 14px; color: var(--text-2); font-weight: 600; font-size: .9rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Lista de destaques ---------- */
.highlights { list-style: none; margin: 0; padding: 0; }
.highlights li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.highlights li:first-child { border-top: 0; padding-top: 0; }
.highlights .dot { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.highlights .dot svg { width: 17px; height: 17px; }
.highlights .dot.warn { background: var(--warn-soft); color: var(--warn); }
.highlights .dot.info { background: var(--info-soft); color: var(--info); }
.highlights .dot.err { background: var(--err-soft); color: var(--err); }
.highlights .dot.ok { background: var(--ok-soft); color: var(--ok); }
.highlights .t { font-weight: 600; font-size: .92rem; }
.highlights .d { font-size: .86rem; color: var(--text-2); }

/* ---------- Gráfico ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { font-size: 11px; fill: var(--text-3); }
.chart .val { font-size: 11px; fill: var(--text-2); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--text-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Outros ---------- */
.muted { color: var(--text-3); }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty svg { width: 36px; height: 36px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9rem; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 500; }
.money-flow { display: flex; flex-direction: column; gap: 6px; font-variant-numeric: tabular-nums; }
.money-flow .line { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.money-flow .line.minus { color: var(--err); }
.money-flow .line.total { border-top: 1px solid var(--border); padding-top: 8px; font-weight: 700; font-size: 1rem; }
details.acc { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
details.acc + details.acc { margin-top: 8px; }
details.acc summary { padding: 12px 14px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.acc summary::-webkit-details-marker { display: none; }
details.acc summary::after { content: "+"; margin-left: auto; color: var(--text-3); font-weight: 400; font-size: 1.2rem; }
details.acc[open] summary::after { content: "–"; }
details.acc .acc-body { padding: 0 14px 14px; color: var(--text-2); font-size: .92rem; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px;
  font-size: .88rem; font-weight: 500; z-index: 100; box-shadow: var(--shadow-lg);
}
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); max-width: 560px; width: 100%; padding: 22px; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
