/* =====================================================================
   Painel web (Fase 6): Início, Extrato, Categorias, Contas e carteiras,
   impressão. Sobre theme.css + financas.css; celular primeiro (390px).
   ===================================================================== */
:root {
    --money-in: var(--ok);
    --chart-prev: #78857f;   /* mês anterior: neutro, tracejado (não é série "rival") */
}
[data-bs-theme="dark"] { --chart-prev: #8d9b95; }

/* Barra inferior: até 5 destinos, colunas iguais (o theme.css fixa 4). */
.mobile-nav-inner { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }

/* ---------- Início ---------- */
.dash-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.month-nav { display: inline-flex; align-items: center; gap: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .2rem; }
.month-nav .icon-btn { width: 40px; height: 40px; border-radius: 50%; }
.month-nav .icon-btn.disabled { opacity: .35; pointer-events: none; }
.month-label { font: 600 .95rem/1 var(--font-display); min-width: 7.5rem; text-align: center; letter-spacing: -.01em; }
.month-label small { font: 500 .75rem var(--font-mono); color: var(--text-muted); }
.month-nav.compact { flex: none; }
.month-nav.compact .month-label { min-width: 6.5rem; font-size: .875rem; }

.money-hero {
    display: grid; gap: 1rem; padding: 1.15rem; border-radius: var(--r-xl);
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(var(--brand-rgb), .16), transparent 55%),
        var(--surface);
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.money-main { display: grid; gap: .25rem; }
.money-main .lbl, .money-cell .lbl { font-size: .78rem; color: var(--text-muted); font-weight: 500; }
.money-main .big { font: 650 clamp(2rem, 9vw, 2.75rem)/1.05 var(--font-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.money-main .cmp { font-size: .82rem; color: var(--text-muted); display: inline-flex; gap: .3rem; align-items: center; }
.money-main .cmp.up i { color: var(--bad); }
.money-main .cmp.down i { color: var(--ok); }
.money-split { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.money-cell {
    display: grid; gap: .15rem; padding: .7rem .75rem; border-radius: var(--r-md); min-width: 0;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text); text-decoration: none;
    transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.money-cell:hover { border-color: var(--border-strong); color: var(--text); }
.money-cell:active { transform: scale(.98); }
.money-cell strong { font: 600 1rem/1.2 var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.money-cell small { font-size: .7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) {
    .money-cell { padding: .6rem .55rem; }
    .money-cell strong { font-size: .875rem; }
    .money-cell .lbl i { display: none; }
}
@media (min-width: 768px) {
    .money-hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); align-items: center; padding: 1.5rem; }
    .money-cell strong { font-size: 1.15rem; }
}
@media (max-width: 991.98px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }

/* Gráfico de linha (SVG desenhado no servidor). */
.line-chart { position: relative; }
.line-chart svg { max-height: 240px; touch-action: pan-y; }
.line-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-chart .line.cur { stroke: var(--brand); }
.line-chart .line.prev { stroke: var(--chart-prev); stroke-dasharray: 5 4; }
.line-chart .area { fill: rgba(var(--brand-rgb), .10); }
.line-chart .end { fill: var(--brand); stroke: var(--surface); stroke-width: 2; }
.line-chart .hit { fill: transparent; cursor: crosshair; }
.line-chart .crosshair { stroke: var(--border-strong); stroke-width: 1; opacity: 0; }
.line-chart .crosshair.on { opacity: 1; }
.chart-legend i.prev { background: repeating-linear-gradient(90deg, var(--chart-prev) 0 4px, transparent 4px 6px); opacity: 1; height: 3px; vertical-align: 2px; }
.chart-legend i { height: 3px; width: 16px; vertical-align: 2px; }
.chart-tip {
    position: absolute; top: -.25rem; z-index: 2; pointer-events: none; white-space: nowrap;
    padding: .3rem .55rem; border-radius: var(--r-sm); font: 500 .75rem var(--font-mono);
    background: var(--text); color: var(--bg); box-shadow: var(--shadow-md);
}

/* Gasto por categoria: barras horizontais, uma cor (magnitude), rótulo em texto. */
.cat-bars { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .15rem; }
.cat-bars a {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem; align-items: center;
    padding: .5rem .4rem; margin: 0 -.4rem; border-radius: var(--r-sm); color: var(--text); text-decoration: none; min-height: 44px;
}
.cat-bars a:hover { background: var(--surface-hover); color: var(--text); }
.cat-name { font-size: .875rem; font-weight: 500; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-name .emo { margin-right: .4rem; }
.cat-val { font: 600 .875rem var(--font-mono); }
.cat-track { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--bg-subtle); overflow: hidden; }
.cat-fill { display: block; height: 100%; border-radius: 99px 4px 4px 99px; background: var(--brand); transform-origin: left; animation: growX .5s var(--ease-out) both; }
.cat-meta { grid-column: 1 / -1; font-size: .72rem; color: var(--text-muted); }
@keyframes growX { from { transform: scaleX(0); } }

/* Últimos lançamentos (lista compacta, também no celular). */
.tx-mini { list-style: none; margin: .5rem 0 0; padding: 0; }
.tx-mini a {
    display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: .6rem; align-items: center;
    padding: .55rem 0; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; min-height: 52px;
}
.tx-mini li:first-child a { border-top: 0; }
.tx-mini a:hover b { color: var(--brand-text); }
.emo { display: inline-grid; place-items: center; font-size: 1.05rem; line-height: 1; }
.tx-mini .emo { width: 32px; height: 32px; border-radius: 10px; background: var(--bg-subtle); }
.who { display: grid; min-width: 0; }
.who b { font-weight: 600; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--text-muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { font: 600 .875rem var(--font-mono); white-space: nowrap; color: var(--text); }
.amt.in, .col-amt.in { color: var(--money-in); }
.quick-actions { display: grid; gap: .5rem; }
.quick-actions .btn { justify-content: center; }
.quick-actions .ico { width: 16px; height: 16px; }

/* Estado vazio: o que vai aparecer. */
.empty-next-grid { display: grid; gap: .75rem; }
@media (min-width: 768px) { .empty-next-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.empty-next-card { display: grid; gap: .3rem; padding: 1rem; border: 1px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface); }
.empty-next-card strong { font-size: .9rem; }
.empty-next-card span { font-size: .8rem; color: var(--text-muted); }
.ghost-kpis, .ghost-bars, .ghost-list { display: grid; gap: 6px; margin-bottom: .5rem; }
.ghost-kpis { grid-template-columns: repeat(3, 1fr); }
.ghost-kpis span { height: 34px; border-radius: 8px; background: var(--bg-subtle); }
.ghost-bars span { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--brand) 22%, var(--bg-subtle)); }
.ghost-list span { height: 12px; border-radius: 6px; background: var(--bg-subtle); }
.ghost-list span:nth-child(2) { width: 80%; } .ghost-list span:nth-child(3) { width: 60%; }

/* ---------- Extrato ---------- */
.filters { display: grid; gap: .5rem; margin-bottom: .75rem; }
.filters-main { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters-main .field-icon { min-width: min(100%, 220px); }
.filters-main .form-control { min-height: 44px; }
.filters-more { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); }
.filters-more summary { list-style: none; cursor: pointer; padding: .6rem .85rem; font-size: .85rem; font-weight: 500; color: var(--text-muted); min-height: 44px; display: flex; align-items: center; gap: .4rem; }
.filters-more summary::-webkit-details-marker { display: none; }
.filters-more[open] summary { border-bottom: 1px solid var(--border); }
.filters-more > :not(summary) { padding: 0 .85rem; }
.filters-more > div:last-child { padding-bottom: .85rem; }
.filters-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; padding-top: .75rem !important; }
@media (min-width: 992px) { .filters-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.sum-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; margin-bottom: .75rem; }
.sum-strip > div { background: var(--surface); padding: .6rem .75rem; display: grid; gap: .1rem; min-width: 0; }
.sum-strip span { font-size: .72rem; color: var(--text-muted); }
.sum-strip b { font: 600 .95rem var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tx-table .col-check { width: 44px; padding-right: 0; }
.check-hit { display: grid; place-items: center; width: 40px; height: 40px; margin: -10px -6px; cursor: pointer; }
.check-hit .form-check-input { margin: 0; width: 1.15em; height: 1.15em; }
.tx-table .col-date { white-space: nowrap; color: var(--text-muted); font-size: .8125rem; width: 70px; }
.tx-table .col-desc { min-width: 0; }
.tx-table .desc-wrap { display: flex; gap: .6rem; align-items: center; min-width: 0; }
.tx-table .col-desc .emo { width: 32px; height: 32px; border-radius: 10px; background: var(--bg-subtle); flex: none; }
.tx-table .col-amt { font-weight: 600; white-space: nowrap; }
.tx-table tr.is-off .who b, .tx-table tr.is-off .col-amt { text-decoration: line-through; color: var(--text-muted); }
.tx-table tr.is-picked > * { background: var(--brand-soft) !important; }
.tx-table .badge-soft { font-size: .65rem; padding: 0 .35rem; }

@media (max-width: 767.98px) {
    /* No celular o extrato é uma lista de cartões, não tabela. */
    .tx-table thead { display: none; }
    .tx-table, .tx-table tbody { display: block; width: 100%; }
    .tx-table tbody tr {
        display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; grid-template-areas: "chk desc amt" "chk desc date";
        align-items: center; column-gap: .5rem; padding: .55rem .75rem; border-top: 1px solid var(--border);
    }
    .tx-table tbody tr:first-child { border-top: 0; }
    .tx-table tbody td { border: 0 !important; padding: 0 !important; background: transparent; }
    .tx-table .col-check { grid-area: chk; width: auto; }
    .tx-table .col-desc { grid-area: desc; }
    .tx-table .col-amt { grid-area: amt; text-align: right; font-size: .9rem; }
    .tx-table .col-date { grid-area: date; text-align: right; width: auto; font-size: .72rem; }
    .check-hit { margin: 0; width: 36px; height: 44px; }
    .sum-strip b { font-size: .82rem; }
}

.bulkbar {
    position: sticky; bottom: calc(.75rem + env(safe-area-inset-bottom)); z-index: 20; margin-top: .75rem;
    display: none; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .75rem;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
}
.bulkbar.show { display: flex; animation: fadeUp var(--normal) var(--ease-out) both; }
.bulk-count { font-size: .85rem; margin-right: auto; }
.bulk-cat { display: flex; gap: .4rem; flex: 1 1 260px; }
.bulk-cat .form-select { min-height: 36px; }
@media (max-width: 767.98px) {
    .bulkbar { bottom: calc(var(--tabbar-h) + .5rem + env(safe-area-inset-bottom)); }
    .bulk-count { width: 100%; }
}
.pager { display: flex; justify-content: center; align-items: center; gap: .75rem; margin: 1rem 0; }

/* Formulário de lançamento. */
.kind-switch { display: inline-grid; grid-template-columns: 1fr 1fr; width: 100%; max-width: 360px; }
.kind-switch label {
    display: flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px; padding: .4rem .8rem;
    border-radius: 7px; font-size: .875rem; font-weight: 500; color: var(--text-muted); cursor: pointer;
}
.kind-switch .btn-check:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); font-weight: 600; }
.kind-switch .btn-check:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 1px; }
.money-input .form-control { font: 600 1.35rem var(--font-mono); }
@media (max-width: 767.98px) {
    .sticky-actions { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 5; }
    .sticky-actions .btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }
    .sticky-actions { flex-wrap: nowrap !important; padding: .6rem .75rem; }
    .sticky-actions .btn-ghost { display: none; } /* a trilha "Extrato" do topo já volta */
}

/* ---------- Categorias ---------- */
.cat-list, .acc-list, .rule-list { list-style: none; margin: 0; padding: 0; }
.cat-list li, .acc-list li, .rule-list li { display: flex; align-items: center; gap: .65rem; padding: .6rem 1rem; border-top: 1px solid var(--border); min-height: 56px; }
.cat-list li:first-child, .acc-list li:first-child, .rule-list li:first-child { border-top: 0; }
.cat-list li .who, .acc-list li .who, .rule-list li .who { flex: 1; }
.cat-list li.off, .acc-list li.off { opacity: .6; }
.cat-list li.editing, .acc-list li.editing { display: block; background: var(--surface-2); }
.cat-dot {
    width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; font-size: 1.1rem;
    background: color-mix(in srgb, var(--cat) 16%, var(--surface)); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--cat) 45%, transparent);
}
.cat-form { display: grid; gap: .75rem; }
.cat-form-row { display: flex; gap: .5rem; align-items: flex-end; }
.cat-icon-field { width: 64px; flex: none; }
.cat-icon-field .form-control { font-size: 1.2rem; padding-inline: .25rem; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: .3rem; }
.emoji-pick .chip-btn { min-height: 36px; min-width: 40px; padding: .2rem .45rem; font-size: 1rem; border-color: var(--border); }

/* ---------- Contas e carteiras ---------- */
.wallet-card.off { opacity: .7; }
.wallet-card .card-header { display: flex; align-items: center; gap: .75rem; }
.acc-ico { width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); }
.acc-list .amt { text-decoration: none; }
.acc-list .amt:hover { color: var(--brand-text); }

/* ---------- Minha conta ---------- */
.choice-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.choice-cards label {
    display: flex; align-items: center; gap: .45rem; min-height: 52px; padding: .55rem .75rem; cursor: pointer; font-size: .875rem;
    border: 1.5px solid var(--border); border-radius: var(--r-md); background: var(--surface);
}
.choice-cards .btn-check:checked + label { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.choice-cards .btn-check:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.erase-box summary { list-style: none; }
.erase-box summary::-webkit-details-marker { display: none; }
.erase-box[open] summary { display: none; }

/* ---------- Impressão / PDF ---------- */
body.print-page { background: var(--bg); }
.print-toolbar { display: flex; justify-content: space-between; gap: .5rem; max-width: 900px; margin: 1rem auto; padding: 0 1rem; }
.print-sheet { max-width: 900px; margin: 0 auto 2rem; background: #fff; color: #111; padding: 2rem; border-radius: var(--r-lg); box-shadow: var(--shadow-md); }
.print-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: .75rem; }
.print-brand { font: 700 .8rem var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: #0E7A55; }
.print-head h1 { font-size: 1.4rem; margin: .2rem 0; color: #111; }
.print-head p { margin: 0; color: #444; font-size: .85rem; }
.print-date { white-space: nowrap; font-size: .75rem !important; }
.print-sums { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin: 1rem 0; }
.print-sums div { border: 1px solid #ccc; border-radius: 8px; padding: .5rem .65rem; }
.print-sums dt { font-size: .7rem; color: #555; font-weight: 500; }
.print-sums dd { margin: 0; font: 600 1rem var(--font-mono); }
.print-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.print-table th { text-align: left; border-bottom: 1px solid #111; padding: .35rem .3rem; font-weight: 600; }
.print-table td { border-bottom: 1px solid #ddd; padding: .3rem; vertical-align: top; }
.print-table .r { text-align: right; white-space: nowrap; font-family: var(--font-mono); }
.print-table tr.off td { color: #888; text-decoration: line-through; }
.print-foot { margin-top: 1rem; font-size: .7rem; color: #666; }
[data-bs-theme="dark"] .print-sheet { box-shadow: none; }
@media (max-width: 640px) {
    .print-sheet { padding: 1rem; border-radius: 0; }
    .print-sums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .print-head { flex-direction: column; }
    .print-table th:nth-child(4), .print-table td:nth-child(4), .print-table th:nth-child(5), .print-table td:nth-child(5) { display: none; }
}
@media print {
    @page { size: A4; margin: 14mm 12mm; }
    body.print-page { background: #fff !important; }
    .print-sheet { box-shadow: none; padding: 0; max-width: none; margin: 0; border-radius: 0; }
    .print-table th:nth-child(n), .print-table td:nth-child(n) { display: table-cell; }
    .print-table thead { display: table-header-group; }
    .print-table tr { break-inside: avoid; }
    .no-print { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    .cat-fill, .bulkbar.show { animation: none; }
}

/* As linhas inteiras clicáveis não levam o sublinhado de "link dentro de lista"
   do theme.css (li a:not(.btn)…), que tem mais peso que um seletor simples. */
.cat-bars li > a:not(.btn), .tx-mini li > a:not(.btn), .acc-list li > a.amt:not(.btn) { text-decoration: none; }

/* Celular: o SVG encolhe pela metade; o texto dele cresce na mesma medida. */
@media (max-width: 575.98px) {
    .line-chart svg { max-height: none; }
    .line-chart text { font-size: 21px; }
    .line-chart .line { stroke-width: 3.5; }
    .money-split { grid-template-columns: minmax(0, 1fr); gap: .4rem; }
    .money-cell { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: .6rem .75rem; }
    .money-cell .lbl i { display: inline; }
    .money-cell strong { grid-column: 2; grid-row: 1 / span 2; font-size: 1rem; }
    .money-cell small { grid-column: 1; }
}
@media (max-width: 767.98px) { .tx-table tbody tr.is-picked { background: var(--brand-soft); } }
