/* ProFin — componentes v0.11.0: multi-seleção, painéis de filtro, aba Análises, cards mobile.
   Cores seguem a paleta slate/brand do Tailwind usada no resto do app. */

:root {
  --pf-surface: #ffffff;
  --pf-surface-2: #f8fafc;
  --pf-border: #e2e8f0;
  --pf-border-strong: #cbd5e1;
  --pf-text: #0f172a;
  --pf-text-2: #475569;
  --pf-muted: #94a3b8;
  --pf-brand: #2563eb;
  --pf-brand-soft: #eff6ff;
  --pf-pos: #059669;
  --pf-neg: #dc2626;
  --pf-hover: #f1f5f9;
}
html.dark {
  --pf-surface: #1e293b;
  --pf-surface-2: #0f172a;
  --pf-border: #334155;
  --pf-border-strong: #475569;
  --pf-text: #f1f5f9;
  --pf-text-2: #cbd5e1;
  --pf-muted: #64748b;
  --pf-brand: #60a5fa;
  --pf-brand-soft: rgba(37, 99, 235, 0.15);
  --pf-pos: #34d399;
  --pf-neg: #f87171;
  --pf-hover: rgba(51, 65, 85, 0.5);
}

/* ── MultiSelect ─────────────────────────────────────────────────────── */
.ms-wrap { position: relative; width: 100%; }
.ms-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 10px; font-size: 0.875rem; text-align: left;
  border: 1px solid var(--pf-border-strong); border-radius: 0.5rem;
  background: var(--pf-surface); color: var(--pf-text);
}
.ms-btn:focus-visible { outline: 2px solid var(--pf-brand); outline-offset: 1px; }
.ms-btn svg { flex-shrink: 0; color: var(--pf-muted); }
.ms-btn-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-btn.ms-active { border-color: var(--pf-brand); background: var(--pf-brand-soft); }
/* Painel no fluxo (não flutuante): dentro de painéis com rolagem ele empurra o conteúdo
   em vez de ser cortado pelo overflow do container */
.ms-panel {
  margin-top: 4px; border: 1px solid var(--pf-border); border-radius: 0.5rem;
  background: var(--pf-surface); box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08); overflow: hidden;
}
.ms-search {
  width: 100%; padding: 7px 10px; font-size: 0.8125rem; border: 0; border-bottom: 1px solid var(--pf-border);
  background: transparent; color: var(--pf-text); outline: none;
}
.ms-actions { display: flex; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--pf-border); }
.ms-actions button { font-size: 0.75rem; font-weight: 600; color: var(--pf-brand); }
.ms-actions button:hover { text-decoration: underline; }
.ms-list { max-height: 220px; overflow-y: auto; padding: 4px 0; }
.ms-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 0.8125rem; color: var(--pf-text-2); cursor: pointer; }
.ms-item:hover { background: var(--pf-hover); }
.ms-item input { width: 15px; height: 15px; accent-color: var(--pf-brand); flex-shrink: 0; }
.ms-group { padding: 6px 10px 2px; font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--pf-muted); }
.ms-empty { padding: 10px; font-size: 0.8125rem; color: var(--pf-muted); text-align: center; }
@media (max-width: 1023px) { .ms-item { padding: 9px 12px; } .ms-btn { padding: 8px 10px; } }

/* ── Painel de filtros (Dashboard / Análises) ────────────────────────── */
.fp-backdrop { position: fixed; inset: 0; z-index: 900; background: rgba(15, 23, 42, 0.35); }
@media (min-width: 1024px) { .fp-backdrop { background: transparent; } }
.fp-panel {
  position: fixed; z-index: 950; display: flex; flex-direction: column;
  top: 5.5rem; right: 2rem; width: 26rem; max-height: calc(100vh - 7rem);
  border-radius: 1rem; box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
}
.fp-panel.hidden { display: none; }
@media (min-width: 1024px) {
  /* Cabeçalho da aba Análises é mais alto (título + linha de controles) */
  #an-filter-panel { top: 8.25rem; max-height: calc(100vh - 9.5rem); }
}
.fp-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--pf-border); flex-shrink: 0; }
.fp-body { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.fp-foot { padding: 12px 16px; border-top: 1px solid var(--pf-border); flex-shrink: 0; }
.fp-label { display: block; font-size: 0.75rem; font-weight: 500; color: var(--pf-text-2); margin-bottom: 4px; }
.fp-input {
  width: 100%; padding: 6px 10px; font-size: 0.875rem; border-radius: 0.5rem;
  border: 1px solid var(--pf-border-strong); background: var(--pf-surface); color: var(--pf-text);
}
@media (max-width: 1023px) {
  /* Folha inferior acima da bottom nav */
  .fp-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 85vh; border-radius: 1rem 1rem 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .fp-body .grid-cols-2 { grid-template-columns: 1fr; }
}

/* ── Aba Análises ────────────────────────────────────────────────────── */
.an-ctl {
  font-size: 0.8125rem; padding: 6px 10px; border-radius: 0.5rem;
  border: 1px solid var(--pf-border-strong); background: var(--pf-surface); color: var(--pf-text);
}
.an-date { width: 9.25rem; }
.an-seg { display: inline-flex; padding: 2px; border-radius: 0.5rem; background: var(--pf-hover); }
.an-seg-btn { font-size: 0.75rem; font-weight: 500; padding: 5px 10px; border-radius: 0.375rem; color: var(--pf-text-2); white-space: nowrap; }
.an-seg-btn.is-on { background: var(--pf-surface); color: var(--pf-brand); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1); }
.an-h3 { font-size: 0.9375rem; font-weight: 600; color: var(--pf-text); }

.an-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.an-kpi { border-radius: 1rem; padding: 16px; min-width: 0; }
.an-kpi-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--pf-muted); }
.an-kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--pf-text); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-kpi-income .an-kpi-value { color: var(--pf-pos); }
.an-kpi-expense .an-kpi-value { color: var(--pf-neg); }
.an-kpi-good .an-kpi-value { color: var(--pf-pos); }
.an-kpi-bad .an-kpi-value { color: var(--pf-neg); }
.an-kpi-delta { margin-top: 6px; font-size: 0.75rem; color: var(--pf-muted); }
.an-kpi-delta span:last-child { margin-left: 2px; }
.an-kpi-sub { margin-top: 4px; font-size: 0.6875rem; color: var(--pf-muted); }
.an-delta { font-weight: 600; font-size: 0.75rem; white-space: nowrap; }
.an-delta-good { color: var(--pf-pos); }
.an-delta-bad { color: var(--pf-neg); }
.an-delta-flat { color: var(--pf-muted); font-weight: 500; }

.an-chart-box { position: relative; height: 280px; }
.an-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.an-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.an-table th { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--pf-muted); padding: 8px 10px; text-align: right; white-space: nowrap; }
.an-table td { padding: 8px 10px; text-align: right; color: var(--pf-text-2); border-top: 1px solid var(--pf-border); font-variant-numeric: tabular-nums; }
.an-table .text-left { text-align: left; }
.an-table tbody th { text-align: left; color: var(--pf-text-2); border-top: 1px solid var(--pf-border); }
.an-pos { color: var(--pf-pos) !important; }
.an-neg { color: var(--pf-neg) !important; }
.an-table-months td, .an-table-matrix td { white-space: nowrap; }
.an-table-matrix th:first-child, .an-table-matrix td:first-child,
.an-table-months th:first-child { position: sticky; left: 0; background: var(--pf-surface); z-index: 1; }
html:not(.dark) .an-table-matrix th:first-child, html:not(.dark) .an-table-matrix td:first-child,
html:not(.dark) .an-table-months th:first-child { background: #fff; }
.an-row-group, .an-row-sub[data-sid], .an-row-link { cursor: pointer; }
.an-row-group:hover td, .an-row-sub[data-sid]:hover td, .an-row-link:hover td { background: var(--pf-hover); }
.an-row-group td:first-child { font-weight: 600; color: var(--pf-text); }
.an-row-sub td:first-child { padding-left: 30px; }
.an-row-total td, .an-row-total th { font-weight: 700; color: var(--pf-text); border-top: 2px solid var(--pf-border-strong); }
.an-row-group:focus-visible, .an-row-sub:focus-visible, .an-row-link:focus-visible { outline: 2px solid var(--pf-brand); outline-offset: -2px; }
.an-chev { display: inline-block; width: 10px; color: var(--pf-muted); transition: transform 0.15s; }
.is-open > td:first-child .an-chev { transform: rotate(90deg); }
.an-dot { display: inline-block; width: 8px; height: 8px; border-radius: 9999px; margin-right: 6px; vertical-align: middle; }
.an-col-bar { width: 28%; min-width: 80px; }
.an-bar { display: block; height: 8px; border-radius: 4px; background: var(--pf-hover); overflow: hidden; }
.an-bar > span { display: block; height: 100%; border-radius: 4px; }
.an-bar-sub { height: 6px; opacity: 0.75; }
.an-row-txs > td { padding: 0 10px 10px 30px; background: var(--pf-surface-2); }
html:not(.dark) .an-row-txs > td { background: #f8fafc; }
.an-txs { padding-top: 6px; }
.an-table-txs td { padding: 6px 8px; font-size: 0.75rem; }
.an-tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; font-size: 0.625rem; font-weight: 600; background: var(--pf-hover); color: var(--pf-text-2); }
.an-icon-btn { padding: 4px; border-radius: 6px; color: var(--pf-muted); }
.an-icon-btn:hover { color: var(--pf-brand); background: var(--pf-hover); }

.an-rank-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; padding: 6px 8px; border-radius: 0.5rem; text-align: left; }
.an-rank-row:not(.is-static):hover { background: var(--pf-hover); }
.an-rank-row.is-static { cursor: default; }
.an-rank-name { font-size: 0.8125rem; color: var(--pf-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-rank-val { font-size: 0.8125rem; font-weight: 600; color: var(--pf-text); font-variant-numeric: tabular-nums; }
.an-rank-bar { grid-column: 1 / -1; height: 6px; }
.an-rank-bar > span { background: var(--pf-brand); }

@media (max-width: 1279px) { .an-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1023px) {
  .an-header .an-controls { width: 100%; }
  .an-date { width: 8.5rem; }
  .an-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .an-kpi { padding: 12px; }
  .an-kpi-value { font-size: 1.15rem; }
  .an-chart-box { height: 220px; }
  .an-col-bar { display: none; }
}

/* ── Transações: cards mobile (renderizados pelo script.js) ───────────── */
@media (max-width: 1023px) {
  .txn-mc { padding: 12px; }
  .txn-mc-selected { border-color: var(--pf-brand) !important; background: var(--pf-brand-soft) !important; }
  .txn-mc-top { display: flex; align-items: flex-start; gap: 10px; }
  .txn-mc-cb { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--pf-brand); }
  .txn-mc-main { flex: 1; min-width: 0; }
  .txn-mc-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
  .txn-mc-amount { font-weight: 600; font-size: 0.9375rem; white-space: nowrap; }
  .txn-mc-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
  .txn-mc-chips span { font-size: 0.625rem; font-weight: 600; padding: 1px 6px; border-radius: 9999px; background: var(--pf-hover); color: var(--pf-text-2); white-space: nowrap; }
  .txn-mc-desc { white-space: normal !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .txn-mc-actions { display: flex; gap: 6px; justify-content: flex-end; }
  .txn-mc-btn {
    display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 8px;
    font-size: 0.75rem; font-weight: 500; background: var(--pf-hover); color: var(--pf-text-2);
  }
  .txn-mc-btn:active { background: var(--pf-brand-soft); color: var(--pf-brand); }
  .txn-mc-btn-del:active { background: rgba(239, 68, 68, 0.12); color: var(--pf-neg); }

  /* Ações em lote: barra fixa acima da bottom nav enquanto há seleção */
  #txn-batch-toolbar:not(.hidden) {
    position: fixed; left: 0.75rem; right: 0.75rem; z-index: 60;
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    margin: 0; box-shadow: 0 10px 25px rgba(15, 23, 42, 0.2);
    justify-content: space-between;
  }
  #txn-toolbar { gap: 8px; }
  #txn-count { width: 100%; font-size: 0.75rem; }
}
