/* Dashboard: cards, money position, chart, lists and the first-run state. Tokens come from tokens.css. */

:root { --seg-late: #dd9b24; }
[data-bs-theme="dark"] { --seg-late: #f0be5a; }
@media (prefers-color-scheme: dark) { :root:not([data-bs-theme]) { --seg-late: #f0be5a; } }

/* ---------- Layout: DOM order is the mobile priority order; grid areas re-arrange it for larger screens ---------- */
.dash-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); grid-template-areas: "next" "recv" "pay" "attn" "perf" "obl" "act"; align-items: stretch; }
.dash-grid > * { min-width: 0; }
.area-next { grid-area: next; }
.area-recv { grid-area: recv; }
.area-pay { grid-area: pay; }
.area-attn { grid-area: attn; }
.area-perf { grid-area: perf; }
.area-obl { grid-area: obl; }
.area-act { grid-area: act; }
.dash-grid > * > .dash-card { height: 100%; }

@media (min-width: 768px) {
    .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; grid-template-areas: "next next" "recv pay" "attn attn" "perf perf" "obl act"; }
}

@media (min-width: 1200px) {
    .dash-grid {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        grid-template-areas:
            "perf perf perf perf perf perf perf perf next next next next"
            "perf perf perf perf perf perf perf perf attn attn attn attn"
            "recv recv recv recv recv recv pay pay pay pay pay pay"
            "obl obl obl obl obl obl act act act act act act";
    }
}

.dash-fresh { display: grid; gap: 1.25rem; max-width: 52rem; }

/* ---------- Card ---------- */
.dash-card {
    position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 1.25rem;
    padding: 1.25rem 1.35rem; box-shadow: var(--shadow-1); animation: rise-in .4s var(--ease) both;
}
.area-recv .dash-card { animation-delay: .04s; }
.area-pay .dash-card { animation-delay: .08s; }
.area-attn .dash-card { animation-delay: .12s; }
.area-perf .dash-card { animation-delay: .02s; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .6rem; }
.card-title { margin: 0; font-size: var(--text-sm); font-weight: 650; color: var(--text-2); letter-spacing: 0; }
.card-sub { margin: .25rem 0 0; color: var(--text-3); font-size: var(--text-sm); }
.card-sub.is-overdue { color: var(--warn); font-weight: 560; }
.card-link { display: inline-flex; align-items: center; gap: .35rem; margin-top: 1rem; font-weight: 600; font-size: var(--text-sm); text-decoration: none; }
.card-link:hover { gap: .55rem; }
.card-link .bi { transition: transform var(--dur) var(--ease); }
.eyebrow { margin: 0 0 .4rem; font-size: .6875rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--link); }

.figure { margin: .1rem 0 0; font-family: var(--font-display); font-weight: 540; font-size: 2.1rem; line-height: 1.1; letter-spacing: -.025em; font-variant-numeric: lining-nums tabular-nums; font-variation-settings: "opsz" 72; overflow-wrap: anywhere; }
.figure.hero { font-size: var(--text-hero); }
.figure-zero { color: var(--text-3); }
.figure.is-pos { color: var(--text); }
.figure.is-neg { color: var(--neg); }

.btn-ghost {
    display: inline-flex; align-items: center; gap: .4rem; margin-top: .75rem; min-height: 2.5rem; padding: .35rem .75rem; margin-left: -.75rem;
    border: 0; background: none; color: var(--link); font-weight: 600; font-size: var(--text-sm); border-radius: var(--radius-sm);
}
.btn-ghost:hover { background: var(--brand-50); }

/* ---------- Next step ---------- */
.next-step {
    color: #fff; border: 0; overflow: hidden;
    background:
        radial-gradient(90% 120% at 100% 0%, rgba(242, 184, 75, .28), transparent 55%),
        radial-gradient(70% 90% at 0% 100%, rgba(76, 184, 196, .25), transparent 60%),
        linear-gradient(145deg, #0e6a78, #0a2a31);
    box-shadow: 0 10px 30px rgba(10, 42, 49, .28);
}
.next-step .eyebrow { color: var(--accent); }
.next-step h2 { margin: 0; color: #fff; font-family: var(--font-display); font-weight: 560; font-size: 1.45rem; line-height: 1.2; letter-spacing: -.015em; }
.next-text { margin: .5rem 0 1.1rem; color: rgba(255, 255, 255, .82); max-width: 30rem; }
.btn-next {
    --bs-btn-color: #2a1c00; --bs-btn-hover-color: #2a1c00; --bs-btn-active-color: #2a1c00;
    background: var(--accent); border-color: var(--accent); font-weight: 650; box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
}
.btn-next:hover { background: #f7c561; border-color: #f7c561; }
.btn-next .bi { transition: transform var(--dur) var(--ease); }
.btn-next:hover .bi { transform: translateX(3px); }
.next-step :focus-visible { outline-color: #fff; }

/* ---------- Money position ---------- */
.direction-chip { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; font-size: 1rem; }
.position-in .direction-chip { background: var(--pos-bg); color: var(--pos); }
.position-out .direction-chip { background: var(--neg-bg); color: var(--neg); }
.stack { display: flex; gap: 3px; height: .65rem; margin: 1.1rem 0 .85rem; border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-3); }
.stack-seg { flex-basis: 0; min-width: 6px; border-radius: 2px; }
.seg-ok { background: var(--chart-income); }
.seg-late { background: var(--seg-late); }
.seg-late2 { background: var(--danger); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; font-size: var(--text-sm); }
.legend li { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.dot { flex: none; width: .6rem; height: .6rem; border-radius: 50%; }
.legend-label { color: var(--text-2); flex: 1; min-width: 0; }
.legend-value { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------- Attention ---------- */
.count-chip { min-width: 1.5rem; height: 1.5rem; padding: 0 .45rem; display: inline-grid; place-items: center; border-radius: var(--radius-pill); background: var(--warn-bg); color: var(--warn); font-size: var(--text-xs); font-weight: 700; }
.attention-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.attention-item { display: flex; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--border); }
.attention-item:first-child { border-top: 0; padding-top: .2rem; }
.sev-mark { flex: none; width: 4px; border-radius: 4px; background: var(--info); align-self: stretch; }
.sev-attention .sev-mark { background: var(--seg-late); }
.sev-urgent .sev-mark { background: var(--danger); }
.attention-body { min-width: 0; }
.attention-title { margin: 0; font-weight: 650; line-height: 1.35; }
.attention-text { margin: .15rem 0 .3rem; color: var(--text-3); font-size: var(--text-sm); }
.attention-body a { font-size: var(--text-sm); font-weight: 600; }
.all-clear { display: flex; align-items: center; gap: .6rem; margin: 0; padding: .5rem 0; color: var(--pos); font-weight: 560; }
.all-clear .bi { font-size: 1.4rem; }

/* ---------- Performance and chart ---------- */
.perf-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.perf-sub { margin: .5rem 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; color: var(--text-2); font-size: var(--text-sm); }
.perf-sub strong { color: var(--text); font-variant-numeric: tabular-nums; }
.sep { color: var(--text-3); }
.key { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .35rem; vertical-align: -.05em; }
.key-income { background: var(--chart-income); }
.key-expense { background: var(--chart-expense); }
.mini-stat { display: grid; gap: .15rem; padding: .7rem .9rem; border-radius: var(--radius-md); background: var(--surface-2); border: 1px solid var(--border); min-width: 12rem; }
.mini-label { font-size: var(--text-xs); color: var(--text-3); font-weight: 560; }
.mini-value { font-family: var(--font-display); font-size: 1.25rem; font-weight: 560; font-variant-numeric: lining-nums tabular-nums; }

.chart-title { margin: 0 0 .75rem; font-size: var(--text-sm); font-weight: 650; color: var(--text-2); }
.chart { --chart-h: 11.5rem; display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); gap: .5rem; }
.chart-y { position: relative; height: var(--chart-h); font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; line-height: 1; }
.chart-y span { position: absolute; right: 0; transform: translateY(-50%); }
.chart-y span:nth-child(1) { top: 0; }
.chart-y span:nth-child(2) { top: 50%; }
.chart-y span:nth-child(3) { top: 100%; }
.chart-area {
    position: relative; height: var(--chart-h);
    background:
        linear-gradient(var(--chart-grid), var(--chart-grid)) 0 0 / 100% 1px no-repeat,
        linear-gradient(var(--chart-grid), var(--chart-grid)) 0 50% / 100% 1px no-repeat,
        linear-gradient(var(--border-strong), var(--border-strong)) 0 100% / 100% 1px no-repeat;
}
.chart-cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: .25rem; }
.chart-col { position: relative; display: flex; align-items: flex-end; justify-content: center; border-radius: .6rem .6rem 0 0; cursor: default; }
.chart-col:hover, .chart-col:focus-visible { background: var(--brand-50); }
.chart-col:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -2px; }
.bars { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 100%; width: min(100%, 3.6rem); }
.bar { flex: 1; max-width: 1.5rem; height: var(--h); border-radius: 6px 6px 2px 2px; transform-origin: bottom; animation: bar-grow .6s var(--ease) both; }
.chart-col:nth-child(2) .bar { animation-delay: .04s; }
.chart-col:nth-child(3) .bar { animation-delay: .08s; }
.chart-col:nth-child(4) .bar { animation-delay: .12s; }
.chart-col:nth-child(5) .bar { animation-delay: .16s; }
.chart-col:nth-child(6) .bar { animation-delay: .2s; }
.bar-income { background: var(--chart-income); }
.bar-expense { background: var(--chart-expense); }
.is-current .bars { opacity: .92; }
@keyframes bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

.chart-xs { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: .25rem; margin-top: .45rem; text-align: center; font-size: var(--text-xs); color: var(--text-3); }
.chart-xs .is-current { color: var(--text); font-weight: 700; }
.chart-main { min-width: 0; }
.chart-tip {
    display: none; position: absolute; z-index: 5; bottom: calc(100% + .4rem); left: 50%; transform: translateX(-50%);
    min-width: 12.5rem; padding: .6rem .75rem; border-radius: var(--radius-md); background: var(--text); color: var(--surface);
    box-shadow: var(--shadow-3); font-size: var(--text-xs); gap: .2rem; flex-direction: column; pointer-events: none;
}
.chart-tip .key { margin-right: .4rem; }
.chart-col:hover .chart-tip, .chart-col:focus-visible .chart-tip { display: flex; }
.chart-col:nth-child(-n+2) .chart-tip { left: 0; transform: none; }
.chart-col:nth-last-child(-n+2) .chart-tip { left: auto; right: 0; transform: none; }
.chart-note { margin: .75rem 0 0; font-size: var(--text-xs); color: var(--text-3); }
.chart-empty { margin: 0; padding: 2rem 1rem; text-align: center; color: var(--text-3); background: var(--surface-2); border-radius: var(--radius-md); border: 1px dashed var(--border-strong); }
.perf-table { margin: .75rem 0 0; }
.perf-table th[scope="row"] { font-weight: 560; text-transform: none; letter-spacing: 0; font-size: var(--text-sm); color: var(--text); background: transparent; white-space: nowrap; }

/* ---------- Lists ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.row-item { display: flex; align-items: center; gap: .85rem; padding: .75rem 0; border-top: 1px solid var(--border); }
.row-item:first-child { border-top: 0; padding-top: .25rem; }
.row-icon { flex: none; width: 2.25rem; height: 2.25rem; border-radius: var(--radius-sm); display: grid; place-items: center; font-size: 1rem; }
.row-icon.is-in { background: var(--pos-bg); color: var(--pos); }
.row-icon.is-out { background: var(--neg-bg); color: var(--neg); }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-title { font-weight: 600; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title:hover { color: var(--link); text-decoration: underline; }
.row-meta { font-size: var(--text-xs); color: var(--text-3); overflow-wrap: anywhere; }
.dir-label { font-weight: 700; }
.dir-label.is-in { color: var(--pos); }
.dir-label.is-out { color: var(--neg); }
.late-tag { display: inline-block; margin-left: .35rem; padding: .05rem .45rem; border-radius: var(--radius-pill); background: var(--danger-bg); color: var(--danger); font-weight: 650; }
.late-tag.is-today { background: var(--warn-bg); color: var(--warn); }
.row-amount { flex: none; font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.row-amount.is-out { color: var(--text-2); }

/* ---------- First run ---------- */
.fresh { padding: 1.75rem; overflow: hidden; }
.fresh::before {
    content: ""; position: absolute; right: -4rem; top: -4rem; width: 16rem; height: 16rem; border-radius: 50%;
    background: radial-gradient(circle, rgba(242, 184, 75, .22), transparent 65%); pointer-events: none;
}
.fresh h2 { margin: 0; font-family: var(--font-display); font-weight: 560; font-size: 1.6rem; letter-spacing: -.02em; }
.fresh-lead { margin: .5rem 0 0; color: var(--text-2); max-width: 34rem; }
.steps { list-style: none; margin: 1.5rem 0 1rem; padding: 0; display: grid; gap: .75rem; position: relative; }
.step { display: flex; align-items: center; gap: .9rem; padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.step-no { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border-strong); font-weight: 700; color: var(--text-2); }
.step.is-done { background: var(--pos-bg); border-color: transparent; }
.step.is-done .step-no { background: var(--pos); border-color: var(--pos); color: #fff; }
.step-body { flex: 1; min-width: 0; display: grid; }
.step-body span { color: var(--text-3); font-size: var(--text-sm); }
.step-state { font-weight: 650; font-size: var(--text-sm); color: var(--pos); }
.fresh-note { margin: 0; font-size: var(--text-sm); color: var(--text-3); max-width: 40rem; }

@media (max-width: 575.98px) {
    .dash-card { padding: 1.1rem; border-radius: 1.1rem; }
    .figure { font-size: 1.85rem; }
    .step { flex-wrap: wrap; }
    .step .btn { margin-left: 2.9rem; }
    .chart { --chart-h: 10rem; grid-template-columns: 3rem minmax(0, 1fr); gap: .35rem; }
    .mini-stat { width: 100%; }
    .fresh { padding: 1.25rem; }
    .row-item { gap: .65rem; }
}

/* ---------- Loading skeleton ---------- */
.sk-card { display: grid; gap: .8rem; align-content: start; min-height: 9rem; }
.area-perf.sk-card { min-height: 22rem; }
.sk { display: block; border-radius: .5rem; background: linear-gradient(100deg, var(--skeleton-a) 30%, var(--skeleton-b) 50%, var(--skeleton-a) 70%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; }
.sk-line { height: .9rem; width: 100%; }
.sk-figure { height: 2.4rem; width: 60%; }
.sk-bar { height: .65rem; border-radius: var(--radius-pill); }
.sk-btn { height: 2.5rem; width: 9rem; }
.sk-chart { height: 11rem; border-radius: var(--radius-md); }
.w-30 { width: 30%; } .w-40 { width: 40%; } .w-50 { width: 50%; } .w-70 { width: 70%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (min-width: 1200px) {
    .chart { --chart-h: 17rem; }
}

@media (max-width: 575.98px) {
    .step-body { flex: 1 1 calc(100% - 3rem); }
}
