/* Bangla web font (SolaimanLipi). @import must be the first rule in the sheet.
   The CSP allows this origin via style-src/font-src in config/security.php. */
@import url('https://fonts.maateen.me/solaiman-lipi/font.css');

:root {
    /* Calm fintech palette */
    --bg: #f7f8fb;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-solid: #ffffff;
    --surface-2: #f3f6fb;
    --surface-3: #ebf0f8;
    --border: rgba(224, 231, 240, 0.8);
    --border-strong: #dbe3ee;

    --text: #0f172a;
    --text-2: #334155;
    --muted: #687388;

    --navy: #0f172a;
    --navy-2: #1e293b;
    --emerald: #10b981;
    --emerald-2: #059669;
    --emerald-soft: #d6f5e7;
    --teal: #14b8a6;
    --coral: #f43f5e;
    --coral-2: #e11d48;
    --coral-soft: #ffe4e8;
    --gold: #f59e0b;
    --sky: #38bdf8;

    --accent: var(--emerald);
    --accent-soft: var(--emerald-soft);
    --negative: var(--coral);
    --negative-soft: var(--coral-soft);
    --warning: var(--gold);

    --radius: 4px;
    --radius-md: 4px;
    --radius-sm: 4px;
    --radius-pill: 4px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow: 0 12px 32px -12px rgba(15, 23, 42, 0.10), 0 4px 12px -4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 26px 60px -20px rgba(15, 23, 42, 0.18), 0 8px 20px -10px rgba(15, 23, 42, 0.08);
    --glow-emerald: 0 14px 34px -14px rgba(16, 185, 129, 0.5);
    --glow-coral: 0 14px 34px -14px rgba(244, 63, 94, 0.35);

    --font: "Inter", "SolaimanLipi", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;

    --sidebar-w: 264px;
    --page-max: 1120px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* When the UI language is Bangla, render all text with SolaimanLipi so the
   Bengali script is consistent (the font also carries Latin glyphs). */
:root[lang="bn"] {
    --font: "SolaimanLipi", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* Explicit theme override (set by the Settings page / local storage). */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b101b;
    --bg-2: #111827;
    --surface: rgba(23, 30, 48, 0.74);
    --surface-solid: #171e30;
    --surface-2: #1e263d;
    --surface-3: #252e49;
    --border: rgba(51, 65, 85, 0.62);
    --border-strong: #3a4a66;
    --text: #f8fafc;
    --text-2: #cbd5e1;
    --muted: #94a3b8;
    --navy: #f8fafc;
    --navy-2: #e2e8f0;
    --emerald: #34d399;
    --emerald-2: #10b981;
    --emerald-soft: rgba(52, 211, 153, 0.16);
    --coral: #fb7185;
    --coral-2: #f43f5e;
    --coral-soft: rgba(251, 113, 133, 0.14);
    --gold: #fbbf24;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow: 0 16px 40px -14px rgba(0, 0, 0, 0.55), 0 4px 12px -6px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 30px 70px -22px rgba(0, 0, 0, 0.7), 0 10px 26px -12px rgba(0, 0, 0, 0.5);
    --glow-emerald: 0 14px 34px -14px rgba(52, 211, 153, 0.35);
}

/* Explicit light override must beat the OS dark preference. */
:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f7f8fb;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-solid: #ffffff;
    --surface-2: #f3f6fb;
    --surface-3: #ebf0f8;
    --border: rgba(224, 231, 240, 0.8);
    --border-strong: #dbe3ee;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #687388;
    --navy: #0f172a;
    --navy-2: #1e293b;
    --emerald: #10b981;
    --emerald-2: #059669;
    --emerald-soft: #d6f5e7;
    --coral: #f43f5e;
    --coral-2: #e11d48;
    --coral-soft: #ffe4e8;
    --gold: #f59e0b;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b101b;
        --surface: rgba(23, 30, 48, 0.74);
        --surface-solid: #171e30;
        --surface-2: #1e263d;
        --surface-3: #252e49;
        --border: rgba(51, 65, 85, 0.6);
        --border-strong: #3a4a66;

        --text: #f8fafc;
        --text-2: #cbd5e1;
        --muted: #94a3b8;

        --navy: #f8fafc;
        --navy-2: #e2e8f0;
        --emerald: #34d399;
        --emerald-2: #10b981;
        --emerald-soft: rgba(52, 211, 153, 0.16);
        --coral: #fb7185;
        --coral-2: #f43f5e;
        --coral-soft: rgba(251, 113, 133, 0.14);
        --gold: #fbbf24;
        --sky: #38bdf8;

        --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
        --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
        --shadow: 0 16px 40px -14px rgba(0, 0, 0, 0.55), 0 4px 12px -6px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 30px 70px -22px rgba(0, 0, 0, 0.7), 0 10px 26px -12px rgba(0, 0, 0, 0.5);
        --glow-emerald: 0 14px 34px -14px rgba(52, 211, 153, 0.35);
        --glow-coral: 0 14px 34px -14px rgba(251, 113, 133, 0.3);
    }
}

/* =========================================================================
   Reset & base
   ========================================================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* The hidden attribute must always win, even over display:flex rules. */
[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    display: flex;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: inherit;
    text-decoration: none;
}

::selection {
    background: rgba(16, 185, 129, 0.25);
}

code {
    font-family: var(--font-mono);
    font-size: 0.83em;
    background: var(--surface-2);
    color: var(--emerald-2);
    padding: 0.14em 0.42em;
    border-radius: 4px;
    border: 1px solid var(--border);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--muted) 35%, transparent);
    border: 3px solid transparent;
    background-clip: padding-box;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--muted) 55%, transparent);
    background-clip: padding-box;
}

/* =========================================================================
   Ambient background
   ========================================================================= */

.ambient {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.ambient-blob {
    position: absolute;
    border-radius: 4px;
    filter: blur(90px);
    opacity: 0.5;
    animation: drift 18s ease-in-out infinite alternate;
}

.ambient-blob-a {
    width: 540px;
    height: 540px;
    top: -180px;
    right: -140px;
    background: radial-gradient(circle at center, rgba(16, 185, 129, 0.34) 0%, transparent 70%);
}

.ambient-blob-b {
    width: 480px;
    height: 480px;
    bottom: -160px;
    left: -130px;
    background: radial-gradient(circle at center, rgba(56, 189, 248, 0.28) 0%, transparent 70%);
    animation-delay: -9s;
    animation-duration: 22s;
}

.ambient-grid {
    position: absolute;
    inset: 0;
    opacity: 0.4;
    background-image:
        linear-gradient(rgba(100, 116, 139, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(100, 116, 139, 0.06) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(ellipse at center, black 0%, transparent 78%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 0%, transparent 78%);
}

@keyframes drift {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(32px, -22px) scale(1.06); }
}

/* =========================================================================
   Sidebar
   ========================================================================= */

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-w);
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px 16px 20px;
    background: var(--surface);
    backdrop-filter: saturate(160%) blur(20px);
    -webkit-backdrop-filter: saturate(160%) blur(20px);
    border-right: 1px solid var(--border);
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 18px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 4px;
    overflow: hidden;
    background: transparent;
    color: #fff;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-mark svg {
    width: 21px;
    height: 21px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.brand-name {
    font-weight: 700;
    font-size: 1.08rem;
    letter-spacing: -0.02em;
}

.brand-tag {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
    /* Still scrollable, but the track/thumb stay hidden (both engines). */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-nav::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.nav-group-label {
    display: block;
    width: 100%;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-2);
    margin: 14px 0 6px;
    padding: 7px 12px 7px 13px;
    border-left: 3px solid var(--emerald);
    border-bottom: 1px solid var(--border-strong);
    border-radius: 3px;
    background: color-mix(in srgb, var(--emerald) 9%, var(--surface-2));
}

/* The first group sits right under the brand; keep the spacing tight there. */
.sidebar-nav > .nav-group-label:first-child {
    margin-top: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 13px;
    border-radius: 4px;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 550;
    text-decoration: none;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-item.is-active {
    background: var(--emerald-soft);
    color: var(--emerald-2);
    font-weight: 650;
}

.nav-item.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.nav-icon {
    display: inline-flex;
    width: 21px;
    height: 21px;
    flex: none;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
}

.sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    flex: none;
    background: linear-gradient(135deg, var(--emerald), var(--teal));
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

/* The header avatar only exists for phones, where the sidebar's identity pill is
   hidden along with the footer. Hidden by default so it never appears twice on a
   wider screen; the mobile block turns it on. */
.avatar-button {
    display: none;
}

/* Same story for the header log out button: the sidebar's copy is hidden when the
   sidebar collapses to a bottom bar, so phones get this one instead of having to
   go through Settings. */
.mobile-logout {
    display: none;
}

.user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.user-chip {
    font-size: 0.86rem;
    font-weight: 650;
    color: var(--text);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-sub {
    font-size: 0.72rem;
    color: var(--muted);
}

/* =========================================================================
   Main content
   ========================================================================= */

.content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.footer {
    padding: 24px 28px 34px;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: center;
    letter-spacing: 0.04em;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: -0.01em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 11px 18px;
    transition: transform 0.16s var(--ease), background 0.18s ease,
                border-color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.btn:active:not(:disabled) {
    transform: translateY(1px) scale(0.99);
}

.btn:disabled {
    opacity: 0.6;
    cursor: progress;
}

.btn .icon {
    width: 17px;
    height: 17px;
}

.btn-block {
    width: 100%;
    padding-top: 13px;
    padding-bottom: 13px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--emerald-2), var(--emerald));
    color: #fff;
    box-shadow: var(--glow-emerald);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 18px 40px -12px rgba(16, 185, 129, 0.55);
}

.btn-logout {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    justify-content: flex-start;
    padding: 10px 13px;
    border-radius: 4px;
}

.btn-logout:hover {
    background: var(--coral-soft);
    border-color: transparent;
    color: var(--coral);
}

/* =========================================================================
   Login
   ========================================================================= */

.auth {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}

.auth-card {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 420px;
    padding: 40px 36px 34px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-radius: 4px;
    background: var(--surface);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    animation: rise 0.6s var(--ease) both;
}

.auth-decoration {
    position: absolute;
    inset: 0 0 auto 0;
    height: 110px;
    color: var(--emerald);
    opacity: 0.5;
    pointer-events: none;
}

.auth-decoration svg {
    width: 100%;
    height: 100%;
    display: block;
}

.auth-badge {
    display: inline-grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--emerald-2), var(--teal));
    color: #fff;
    box-shadow: var(--glow-emerald);
}

.auth-badge svg {
    width: 26px;
    height: 26px;
}

.auth-title {
    margin: 4px 0 0;
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.auth-subtitle {
    margin: -10px 0 8px;
    color: var(--muted);
    font-size: 0.95rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field-label {
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.field input {
    font: inherit;
    font-size: 0.95rem;
    padding: 13px 16px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.field input::placeholder {
    color: color-mix(in srgb, var(--muted) 60%, transparent);
}

.field input:focus {
    outline: none;
    background: var(--surface-solid);
    border-color: var(--emerald);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--emerald) 18%, transparent);
}

.password-wrap {
    position: relative;
    display: block;
}

.password-wrap input {
    width: 100%;
    padding-right: 48px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.16s ease, background 0.16s ease;
}

.password-toggle:hover {
    color: var(--text);
    background: var(--surface-3);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.password-toggle svg {
    display: inline-flex;
    width: 20px;
    height: 20px;
}

.password-toggle .icon-eye-off {
    display: none;
}

.password-toggle.is-visible .icon-eye {
    display: none;
}

.password-toggle.is-visible .icon-eye-off {
    display: inline-flex;
}

[dir="rtl"] .password-wrap input {
    padding-right: 16px;
    padding-left: 48px;
}

[dir="rtl"] .password-toggle {
    right: auto;
    left: 6px;
}

.form-error {
    margin: 0;
    padding: 12px 16px;
    border-radius: 4px;
    background: var(--negative-soft);
    color: var(--negative);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid color-mix(in srgb, var(--negative) 20%, transparent);
    animation: shake 0.42s ease;
}

.auth-footnote {
    margin-top: 4px;
    padding-top: 18px;
    border-top: 1px dashed var(--border-strong);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.auth-hint-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.auth-hint {
    color: var(--muted);
    font-size: 0.86rem;
}

/* =========================================================================
   Dashboard
   ========================================================================= */

.dashboard {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 40px 28px 40px;
}

.dashboard-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 18px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 4px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--emerald-2);
}

.dashboard-title {
    margin: 0;
    font-size: clamp(1.9rem, 3.2vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.05;
}

.dashboard-subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.head-actions {
    display: flex;
    align-items: center;
}

.period-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 5px;
    border-radius: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.period-indicator {
    position: absolute;
    top: 5px;
    left: 0;
    height: calc(100% - 10px);
    width: 0;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--navy), var(--navy-2));
    box-shadow: var(--shadow-sm);
    transition: transform 0.45s var(--ease), width 0.45s var(--ease);
    z-index: 0;
}

.chip {
    position: relative;
    z-index: 1;
    font: inherit;
    font-weight: 600;
    font-size: 0.84rem;
    letter-spacing: -0.01em;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 9px 17px;
    border-radius: 4px;
    transition: color 0.25s ease;
}

.chip:hover {
    color: var(--text);
}

.chip.is-active {
    color: #fff;
}

/* =========================================================================
   Skeleton loader
   ========================================================================= */

.loading {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.skel {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.skel::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        transparent 0%,
        color-mix(in srgb, var(--surface-3) 60%, transparent) 50%,
        transparent 100%
    );
    animation: shimmer 1.4s infinite;
}

.skel-hero {
    height: 150px;
}

.skel-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
}

.skel-stat {
    height: 110px;
}

.skel-panel {
    height: 240px;
}

/* =========================================================================
   KPI: hero + cards
   ========================================================================= */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(188px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.stat {
    position: relative;
    overflow: hidden;
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow);
    transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease),
                border-color 0.25s ease;
    animation: rise 0.55s var(--ease) both;
}

.stat:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-strong);
}

/* Net-worth hero */
.stat.hero {
    grid-column: 1 / -1;
    background:
        radial-gradient(120% 120% at 100% 0%, rgba(16, 185, 129, 0.12) 0%, transparent 52%),
        radial-gradient(80% 120% at 0% 100%, rgba(56, 189, 248, 0.10) 0%, transparent 50%),
        var(--surface);
    border-color: color-mix(in srgb, var(--emerald) 30%, var(--border));
    padding: 26px 28px;
    gap: 18px;
}

.stat.hero::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: linear-gradient(180deg, var(--emerald), var(--teal));
}

.hero-top {
    display: flex;
    align-items: center;
    gap: 14px;
}

.hero-icon {
    display: inline-grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 4px;
    background: var(--emerald-soft);
    color: var(--emerald-2);
}

.hero-icon .icon {
    width: 22px;
    height: 22px;
}

.hero-heading {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.hero-caption {
    font-size: 0.82rem;
    color: var(--muted);
}

.hero-value {
    font-size: clamp(2.2rem, 4.4vw, 3rem);
    font-weight: 740;
    letter-spacing: -0.045em;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.hero-foot {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.hero-cell {
    display: flex;
    align-items: center;
    gap: 11px;
}

.hero-cell-icon {
    width: 18px;
    height: 18px;
    color: var(--muted);
    flex: none;
}

.hero-cell.is-positive .hero-cell-icon { color: var(--emerald-2); }
.hero-cell.is-negative .hero-cell-icon { color: var(--coral); }

.hero-cell-body {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.hero-cell-label {
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.hero-cell-value {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.hero-cell.is-positive .hero-cell-value { color: var(--emerald-2); }
.hero-cell.is-negative .hero-cell-value { color: var(--coral); }

/* KPI cards */
.stat-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
    flex: none;
}

.icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.stat-icon {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    transition: transform 0.3s var(--ease);
}

.stat:hover .stat-icon {
    transform: scale(1.08) rotate(-4deg);
}

.stat-icon svg {
    width: 19px;
    height: 19px;
}

.stat-label {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 720;
    letter-spacing: -0.04em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

/* Secondary line under a KPI figure, e.g. how many items it covers. */
.stat-sub {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.76rem;
}

.stat.is-accent .stat-icon { background: var(--emerald-soft); color: var(--emerald-2); border-color: transparent; }
.stat.is-accent .stat-value { color: var(--emerald-2); }
.stat.is-positive .stat-icon { background: var(--emerald-soft); color: var(--emerald-2); border-color: transparent; }
.stat.is-positive .stat-value { color: var(--emerald-2); }
.stat.is-negative .stat-icon { background: var(--coral-soft); color: var(--coral); border-color: transparent; }
.stat.is-negative .stat-value { color: var(--coral); }

/* =========================================================================
   Panels / grids
   ========================================================================= */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow);
    padding: 24px;
    animation: rise 0.6s var(--ease) both;
}

.panel:nth-child(2) {
    animation-delay: 0.07s;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 0 0 20px;
    font-size: 0.98rem;
    font-weight: 680;
    letter-spacing: -0.01em;
}

/* A per-panel action button, pushed to the far end of the heading row. The
   heading already is a flex row, so margin-left:auto does the placement and no
   extra wrapper is needed. Sizing comes from .btn-mini. */
.panel-action {
    margin-left: auto;
}



.panel-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: var(--emerald-soft);
    color: var(--emerald-2);
    flex: none;
}

.panel-icon svg {
    width: 16px;
    height: 16px;
}

/* Consistent vertical rhythm for every dashboard block (the standalone
   net-worth panel had none, so it collided with the grid below it). */
#dashboard-content > * {
    animation: rise 0.55s var(--ease) both;
    margin-bottom: 18px;
}

#dashboard-content > *:last-child {
    margin-bottom: 0;
}

/* =========================================================================
   Cash flow bars
   ========================================================================= */

.flow {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.flow-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.flow-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text-2);
    font-size: 0.9rem;
    font-weight: 600;
}

.flow-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    transition: transform 0.25s var(--ease);
}

.flow-row:hover .flow-icon {
    transform: scale(1.08);
}

.flow-icon svg {
    width: 15px;
    height: 15px;
}

.flow-icon.is-positive { background: var(--emerald-soft); color: var(--emerald-2); border-color: transparent; }
.flow-icon.is-negative { background: var(--coral-soft); color: var(--coral); border-color: transparent; }
.flow-icon.is-accent { background: var(--emerald-soft); color: var(--emerald-2); border-color: transparent; }
.flow-icon.is-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

.flow-row {
    display: block;
}

.flow-row.is-clickable {
    cursor: pointer;
    border-radius: 6px;
    padding: 6px 8px;
    margin: 0 -8px;
    transition: background 0.16s ease, transform 0.16s ease;
}

.flow-row.is-clickable:hover {
    background: var(--surface-2);
    transform: translateX(3px);
}

.flow-row.is-clickable:focus-visible,
.legend-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Compact label/value row used by the report summary lists (no progress bar). */
.summary-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
}

.flow-value {
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.flow-value.is-positive { color: var(--emerald-2); }
.flow-value.is-negative { color: var(--coral); }
.flow-value.is-accent { color: var(--emerald-2); }
.flow-value.is-neutral { color: var(--text-2); }

.flow-track {
    height: 11px;
    border-radius: 4px;
    background: var(--surface-2);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

.flow-fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--emerald-2), var(--emerald));
    transition: width 0.95s var(--ease);
}

.flow-fill.is-positive { background: linear-gradient(90deg, var(--emerald-2), var(--emerald)); }
.flow-fill.is-negative { background: linear-gradient(90deg, var(--coral), var(--coral-2)); }
.flow-fill.is-accent { background: linear-gradient(90deg, var(--emerald-2), var(--emerald)); }
.flow-fill.is-neutral { background: linear-gradient(90deg, var(--text-2), var(--muted)); }

/* =========================================================================
   Donut + legend
   ========================================================================= */

.breakdown {
    display: grid;
    grid-template-columns: minmax(176px, 230px) 1fr;
    gap: 24px;
    align-items: center;
}

.donut {
    position: relative;
    width: 100%;
    max-width: 230px;
    margin: 0 auto;
    aspect-ratio: 1;
    filter: drop-shadow(0 14px 26px rgba(15, 23, 42, 0.08));
}

.donut-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

.donut-svg circle {
    transition: stroke-dasharray 1.1s var(--ease), stroke-dashoffset 1.1s var(--ease);
}

.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-align: center;
    pointer-events: none;
}

.donut-value {
    font-size: 1.18rem;
    font-weight: 740;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.donut-label {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 650;
}

.legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 380px;
    overflow-y: auto;
    padding-right: 4px;
}

.legend-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 11px;
    padding: 8px 9px;
    border-radius: 4px;
    font-size: 0.88rem;
    transition: background 0.16s ease, transform 0.16s ease;
    cursor: pointer;
}

.legend-item:hover {
    background: var(--surface-2);
    transform: translateX(3px);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 4px;
    flex: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 8%, transparent);
}

.legend-name {
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 550;
}

.legend-value {
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    color: var(--text);
}

.legend-pct {
    color: var(--muted);
    font-size: 0.8rem;
    min-width: 46px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Progress / budgets
   ========================================================================= */

.progress {
    height: 10px;
    border-radius: 4px;
    background: var(--surface-2);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

.progress-fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--emerald-2), var(--emerald));
    transition: width 0.95s var(--ease);
    position: relative;
}

.progress-fill::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, transparent 55%);
}

.progress-fill.is-50 { background: linear-gradient(90deg, var(--emerald-2), var(--emerald)); }
.progress-fill.is-80 { background: linear-gradient(90deg, var(--warning), var(--coral)); }
.progress-fill.is-100,
.progress-fill.is-exceeded { background: linear-gradient(90deg, var(--coral), var(--coral-2)); }
.progress-fill.is-goal { background: linear-gradient(90deg, var(--emerald-2), var(--emerald)); }

.budget {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.budget:first-child {
    padding-top: 0;
}

.budget:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.budget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.budget-name,
.goal-name {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-weight: 640;
    font-size: 0.94rem;
}

.row-icon {
    width: 16px;
    height: 16px;
    color: var(--emerald-2);
}

.budget-figures,
.goal-figures {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.86rem;
    font-weight: 550;
}

.muted-note {
    color: var(--muted);
    font-size: 0.79rem;
    font-weight: 500;
    max-width: 25ch;       /* Wraps text around 25 characters */
    word-break: break-word;
}

.build-stamp {
    max-width: none;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

/* =========================================================================
   Goals
   ========================================================================= */

.goal-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.goal {
    display: flex;
    align-items: center;
    gap: 17px;
    padding: 14px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease),
                border-color 0.25s ease;
}

.goal:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}

.ring {
    position: relative;
    width: 76px;
    height: 76px;
    flex: none;
}

.ring .donut-svg {
    width: 100%;
    height: 100%;
}

.ring-center {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}

.ring-value {
    font-size: 0.92rem;
    font-weight: 740;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.goal-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.goal-figures {
    font-size: 0.85rem;
}

/* Icon shown before the goal name: envelope (mail) for a ring-fenced goal,
   target for track-only. */
.goal-icons {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: none;
}

.goal-icon {
    width: 15px;
    height: 15px;
    flex: none;
}

.goal-icon.is-envelope { color: var(--emerald-2); }
.goal-icon.is-track { color: var(--muted); }

/* =========================================================================
   Transactions table
   ========================================================================= */

.table-wrap {
    overflow-x: auto;
    margin: 0 -6px;
    padding: 0 6px;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.89rem;
}

.table th {
    text-align: left;
    color: var(--muted);
    font-weight: 650;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0 10px 11px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    transition: background 0.15s ease;
}

.table tbody tr {
    transition: transform 0.18s var(--ease);
}

.table tbody tr:hover td {
    background: var(--surface-2);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.align-right {
    text-align: right;
}

.nowrap {
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.83rem;
    font-variant-numeric: tabular-nums;
}

.amount-positive {
    color: var(--emerald-2);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.amount-negative {
    color: var(--coral);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.row-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 190px;
}

.tx-icon {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    flex: none;
    transition: transform 0.2s var(--ease);
}

.table tbody tr:hover .tx-icon {
    transform: scale(1.08);
}

.tx-icon svg {
    width: 16px;
    height: 16px;
}

.tx-icon.is-positive { background: var(--emerald-soft); color: var(--emerald-2); border-color: transparent; }
.tx-icon.is-negative { background: var(--coral-soft); color: var(--coral); border-color: transparent; }
.tx-icon.is-neutral { background: color-mix(in srgb, var(--sky) 16%, transparent); color: var(--sky); border-color: transparent; }

.row-title {
    display: block;
    font-weight: 600;
    color: var(--text);
}

.row-sub {
    display: block;
    color: var(--muted);
    font-size: 0.79rem;
}

.empty-cell {
    text-align: center;
    color: var(--muted);
    padding: 30px 0;
}

/* =========================================================================
   Bills
   ========================================================================= */

.bill-list {
    display: flex;
    flex-direction: column;
}

.bill {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
    transition: transform 0.18s var(--ease);
}

.bill:first-child {
    padding-top: 0;
}

.bill:hover {
    transform: translateX(4px);
}

.bill:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.bill-icon {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    flex: none;
}

.bill-icon svg {
    width: 17px;
    height: 17px;
}

.bill.is-overdue .bill-icon {
    background: var(--coral-soft);
    color: var(--coral);
    border-color: transparent;
    animation: pulse 2s ease-in-out infinite;
}

.bill-icon.is-paid {
    background: var(--emerald-soft);
    color: var(--emerald-2);
    border-color: transparent;
}

.badge {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
}

.badge.is-paid {
    background: var(--emerald-soft);
    color: var(--emerald-2);
}

.badge.is-recurring {
    background: var(--accent-soft, var(--emerald-soft));
    color: var(--emerald-2);
    opacity: 0.85;
}

/* A debt the user owes someone, the mirror of is-recurring on the lending page. */
.badge.is-owed {
    background: var(--rose-soft, var(--red-soft, #fee2e2));
    color: var(--rose-2, var(--red-2, #b91c1c));
}

.badge.badge-soft {
    background: var(--surface-2);
    color: var(--muted);
}

.badge.badge-accent {
    background: var(--accent-soft, var(--emerald-soft));
    color: var(--emerald-2);
}

.account-row.is-owed .account-icon {
    color: var(--rose-2, var(--red-2, #b91c1c));
}

.field-hint.is-warning {
    color: var(--amber-700, #b45309);
    background: var(--amber-soft, #fef3c7);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 6px;
}

.field-inline {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.field-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--emerald);
    flex: none;
}

.field-inline .field-label {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.86rem;
    font-weight: 500;
    color: var(--text-2);
}

.bill-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.bill-name {
    font-weight: 640;
    font-size: 0.94rem;
}

.bill.is-overdue .bill-name {
    color: var(--coral);
}

.bill-amount {
    font-variant-numeric: tabular-nums;
    font-weight: 720;
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.empty {
    color: var(--muted);
    margin: 10px 0;
    font-size: 0.9rem;
}

/* =========================================================================
   Report pages (accounts / holdings)
   ========================================================================= */

#page-content > * {
    margin-bottom: 18px;
}

#page-content > *:last-child {
    margin-bottom: 0;
}

.account-list {
    display: flex;
    flex-direction: column;
}

.account-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
    transition: transform 0.18s var(--ease);
}

.account-row:first-child {
    padding-top: 0;
}

.account-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.account-row:hover {
    transform: translateX(4px);
}

.account-icon {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: var(--emerald-soft);
    color: var(--emerald-2);
    flex: none;
}

.account-icon svg {
    width: 18px;
    height: 18px;
}

.account-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.account-name {
    font-weight: 650;
    font-size: 0.95rem;
}

.account-balance {
    font-variant-numeric: tabular-nums;
    font-weight: 720;
    font-size: 1.02rem;
    letter-spacing: -0.02em;
}

.account-balance.is-positive { color: var(--emerald-2); }
.account-balance.is-negative { color: var(--coral); }

/* =========================================================================
   Animations
   ========================================================================= */

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shimmer {
    100% {
        transform: translateX(100%);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--coral) 45%, transparent); }
    50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--coral) 0%, transparent); }
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1000px) {
    :root {
        --sidebar-w: 84px;
    }

    .sidebar {
        padding: 20px 12px 18px;
        align-items: center;
    }

    .sidebar-brand {
        padding: 2px 0 16px;
    }

    .brand-text,
    .nav-label,
    .nav-group-label,
    .user-meta,
    .btn-label {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .user-pill {
        justify-content: center;
        padding: 6px;
        border-color: transparent;
        background: transparent;
    }

    .btn-logout {
        justify-content: center;
        padding: 11px;
    }
}

@media (max-width: 680px) {
    :root {
        --sidebar-w: 68px;
    }

    .dashboard {
        padding: 24px 16px 32px;
    }

    .stat.hero {
        padding: 22px 20px;
    }

    .breakdown {
        grid-template-columns: 1fr;
    }

    .period-switch {
        width: 100%;
        justify-content: space-between;
    }

    .chip {
        flex: 1;
        text-align: center;
        padding: 9px 10px;
        font-size: 0.82rem;
    }

    .head-actions {
        width: 100%;
    }

    /* Mobile bottom nav: the sidebar collapses to a horizontal bar. */
    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 2px;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        border-right: none;
        border-top: 1px solid var(--border);
        overflow-x: auto;
    }

    .sidebar-brand,
    .sidebar-nav .nav-group-label {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 2px;
        /* 19 destinations cannot share one phone screen, so the bar scrolls.
           `flex: none` is required as well as the width: the base rule's
           `flex: 1` implies flex-basis 0, which would size this to the viewport
           and ignore max-content, letting the labels be squeezed again. */
        flex: none;
        width: max-content;
        min-width: 100%;
        overflow: visible;
    }

    .nav-item {
        /* Sized to the label, never shrunk: equal shares gave each item ~46px of
           text, which wrapped long labels such as "দেনা/পাওনা" onto two lines.
           min-width still guarantees a usable tap target for short labels. */
        flex: 0 0 auto;
        flex-direction: column;
        gap: 3px;
        padding: 8px 10px;
        font-size: 0.66rem;
        min-width: 54px;
    }

    .nav-label {
        display: block;
        white-space: nowrap;
    }

    /* The sidebar footer's identity row and log out button are both duplicated on
       a phone: the identity moves to the header avatar, and logging out lives in
       Settings. Only quick add still needs to come from here, so the wrapper stops
       being a box - otherwise it keeps its padding and border-top and stretches
       the bottom bar taller. */
    .sidebar-foot {
        display: contents;
    }

    .sidebar-foot .user-pill,
    .sidebar-foot .btn-logout {
        display: none;
    }

    /* Quick add becomes a floating action button. Reusing the existing button
       means its handler and its logged-out/hidden bookkeeping are unchanged. */
    #quick-add-button {
        position: fixed;
        right: 16px;
        /* Clears the bottom bar, which is about 82px tall once its safe-area
           inset is added. */
        bottom: calc(96px + env(safe-area-inset-bottom));
        /* Below modals (100) so it never floats over a dialog. */
        z-index: 60;
        display: grid;
        place-items: center;
        width: 56px;
        height: 56px;
        padding: 0;
        border-radius: 50%;
        box-shadow: 0 6px 20px rgba(15, 23, 42, 0.22);
        /* The label is "+ Quick add", which has no place in a 56px circle. The
           text is collapsed rather than removed so it stays readable to
           assistive technology. */
        font-size: 0;
    }

    #quick-add-button::after {
        content: "+";
        font-size: 30px;
        line-height: 1;
        font-weight: 300;
    }

    /* `display: grid` on the button outranks the user agent's [hidden] rule, so
       without this the action button would float over the login screen. */
    #topbar-actions[hidden] .sidebar-foot {
        display: none;
    }

    .avatar-button {
        display: inline-grid;
        place-items: center;
        padding: 0;
        margin-right: 10px;
        border: 1px solid var(--border);
        border-radius: 4px;
        background: var(--surface);
        cursor: pointer;
    }

    /* Matches .avatar-button so the two header controls read as one pair. It
       sits beside the avatar rather than in the bottom bar because the bar holds
       destinations, and signing out is not one. The explicit box is needed: the
       icon inside is 20px while the avatar is 36px, so without it this button
       would come out visibly smaller than its neighbour. */
    .mobile-logout {
        display: inline-grid;
        place-items: center;
        width: 36px;
        height: 36px;
        padding: 0;
        margin-right: 10px;
        border: 1px solid var(--border);
        border-radius: 4px;
        background: var(--surface);
        color: var(--muted);
        cursor: pointer;
    }

    .mobile-logout:hover {
        background: var(--coral-soft);
        border-color: transparent;
        color: var(--coral);
    }

    .content {
        padding-bottom: 82px;
    }
    /* .account-name {
        width: 24ch;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    } */
}

/* =========================================================================
   Toasts + quick add + settings
   ========================================================================= */

.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 16px);
    z-index: 200;
    padding: 12px 20px;
    border-radius: 4px;
    background: var(--navy-2);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 550;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s var(--ease);
    max-width: 90vw;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.is-danger {
    background: var(--coral-2);
}

.quick-add {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

/* --- settings page tabs ------------------------------------------------ */

/* Pill-style tab bar at the top of the settings page. Each button toggles
   the corresponding .settings-tab node's `hidden` attribute; we never
   re-render the page on tab switch so the form fields do not reset. */
.settings-tabs {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    align-self: flex-start;
    max-width: 100%;
}

.tab-button {
    background: none;
    border: 0;
    padding: 7px 14px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.tab-button:hover {
    color: var(--text);
}

.tab-button.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.tab-content {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Tab bar on phones: stretch the row so each button can take its share
   of the panel, shrink the padding, and drop the wrapper so the bar does
   not float off to one side. The labels stay legible. */
@media (max-width: 600px) {
    .tab-bar {
        align-self: stretch;
        width: 100%;
        padding: 3px;
    }
    .tab-button {
        flex: 1 1 auto;
        padding: 8px 10px;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

.settings-tab {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.settings-tab-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-tab-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* --- preferences list ------------------------------------------------- */

.preferences-body {
    display: flex;
    flex-direction: column;
}

.preferences-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    overflow: hidden;
}

.preferences-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.preferences-row:last-child {
    border-bottom: 0;
}

.preferences-row-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}

.preferences-row-key {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.72rem;
    color: var(--muted);
    word-break: break-all;
}

.preferences-row-label {
    color: var(--text);
    font-weight: 600;
    font-size: 0.92rem;
}

/* iOS-style switch toggle. The visible switch state is driven by the
   `.is-on` class so we can flip the visual instantly on user input and
   roll it back if the server rejects the change. */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 40px;
    height: 22px;
    cursor: pointer;
    flex: 0 0 auto;
}

.toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: 999px;
    transition: background 0.15s ease;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.toggle.is-on .toggle-track {
    background: var(--emerald);
}

.toggle.is-on .toggle-thumb {
    transform: translateX(18px);
}

.toggle input:focus-visible + .toggle-track {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--emerald) 30%, transparent);
}

.settings-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
}

/* =========================================================================
   Insights charts
   ========================================================================= */

.insights {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.insight-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 28px;
}

.insight-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.insight-stat-label {
    font-size: 0.74rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.insight-stat-value {
    font-size: 1.3rem;
    font-weight: 720;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.insight-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 22px;
}

.insight-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.insight-title {
    font-size: 0.8rem;
    font-weight: 650;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chart-svg {
    width: 100%;
    height: 110px;
    display: block;
    overflow: visible;
}

.chart-svg path {
    transition: d 0.5s ease;
}

.chart-labels {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.7rem;
}

.bar-groups {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 110px;
}

.bar-group {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 2px;
    height: 100%;
}

.bar-col {
    display: flex;
    align-items: flex-end;
    width: 42%;
    height: 100%;
}

.bar-fill {
    display: block;
    width: 100%;
    min-height: 2px;
    border-radius: 4px 4px 0 0;
}

.bar-fill.is-positive { background: linear-gradient(180deg, var(--emerald), var(--emerald-2)); }
.bar-fill.is-negative { background: linear-gradient(180deg, var(--coral), var(--coral-2)); }

/* =========================================================================
   Filters + pager
   ========================================================================= */

.filter-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    /* Each control has a bounded max-width below so the row fits a
       normal desktop panel without a horizontal scrollbar. The search
       input absorbs any leftover space via flex: 1. */
}

.filter-bar > * {
    /* Each control keeps its natural width up to its max-width. The
       search input overrides this with flex: 1 below. */
    flex: 0 1 auto;
    min-width: 0;
}

.period-filter-bar {
    margin-top: -6px;
}

.period-filter-bar .filter-control {
    min-width: 130px;
}

/* Mobile-only control that reveals the collapsed transactions filter bar. */
.filter-toggle {
    display: none;
}

.filter-count {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--emerald);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}

/* --- transaction tags ---------------------------------------------------- */

/* Tag picker in the transactions filter bar. Multiple + size is what makes a
   single box able to express "any of these", which a one-value select cannot. */
.filter-control-multi {
    min-width: 150px;
    max-width: 220px;
    padding: 4px;
    /* Native multi-select lists scroll rather than expand, so the box keeps a
       fixed height instead of growing with the number of tags. */
    height: auto;
    overflow-y: auto;
}

/* --- multi-select dropdown ----------------------------------------------- */

/* Replaces the native <select multiple> for the tag filter. The trigger
   matches the rest of the filter bar so the dropdown looks like a single
   chip until it is opened, then expands into a checklist below. */
.multi-select {
    position: relative;
    display: inline-block;
}

.multi-select-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 120px;
    max-width: 200px;
    text-align: left;
    cursor: pointer;
    /* Match the .filter-control typography and padding. */
    padding: 8px 10px;
    line-height: 1.2;
}

.multi-select-trigger-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.multi-select-trigger.is-active .multi-select-trigger-label {
    color: var(--text);
}

.multi-select-caret {
    flex: 0 0 auto;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: 0.7;
    transition: transform 0.15s ease;
}

.multi-select-trigger[aria-expanded="true"] .multi-select-caret {
    transform: rotate(180deg);
}

.multi-select-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 50;
    min-width: 200px;
    max-width: 280px;
    max-height: 280px;
    overflow-y: auto;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.multi-select-search {
    width: 100%;
    margin-bottom: 4px;
    padding: 6px 8px;
    font: inherit;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
}

.multi-select-search:focus {
    outline: none;
    border-color: var(--emerald);
}

.multi-select-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.87rem;
    color: var(--text);
}

.multi-select-option:hover {
    background: var(--surface-2);
}

.multi-select-option input[type="checkbox"] {
    margin: 0;
    width: 14px;
    height: 14px;
    accent-color: var(--emerald);
    cursor: pointer;
}

.multi-select-option-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.multi-select-footer {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.multi-select-clear {
    background: none;
    border: none;
    padding: 4px 8px;
    font: inherit;
    font-size: 0.78rem;
    color: var(--muted);
    cursor: pointer;
    border-radius: 4px;
}

.multi-select-clear:hover {
    color: var(--coral);
    background: var(--surface-2);
}

/* Multi-select when embedded inside a form field */
.field .multi-select {
    display: block;
    width: 100%;
}

.field .multi-select-trigger {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-height: 42px;
    padding: 10px 14px;
    font-size: 0.95rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text);
    box-shadow: none;
}

.field .multi-select-trigger:focus-visible {
    outline: 2px solid var(--accent);
    border-color: var(--accent);
}

.field .multi-select-panel {
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    z-index: 1000;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    background: var(--surface);
}

.multi-select-add-new {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 10px;
    margin-top: 4px;
    border: 1px dashed var(--accent, #10b981);
    border-radius: 4px;
    background: transparent;
    color: var(--accent, #10b981);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.multi-select-add-new:hover {
    background: var(--surface-2);
}

/* Tag pills in the transactions table. */
.tag-badges {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.tag-badges.is-empty {
    color: var(--muted);
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

/* The "+N" overflow pill is a count, not a name, so it is toned down to keep
   the real tags reading first. */
.tag-badge.is-more {
    border-style: dashed;
    color: var(--muted);
}

/* Usage count beside a tag on the management screen. */
.tag-usage {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
}

/* The stacked-table layout turns each cell into a labelled row on narrow
   screens; tag pills need to wrap rather than force the row wider. */
@media (max-width: 720px) {
    .filter-control-multi {
        max-width: none;
        width: 100%;
    }
}

.report-period {
    margin-bottom: 10px;
}

.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.report-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.report-card-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.report-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex-shrink: 0;
    background: color-mix(in srgb, var(--emerald) 14%, transparent);
    color: var(--emerald);
}

.report-card-icon svg {
    width: 18px;
    height: 18px;
}

.report-card-title {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.report-card-actions {
    display: flex;
    gap: 8px;
}

.filter-control {
    font: inherit;
    font-size: 0.85rem;
    padding: 7px 9px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    /* Cap the intrinsic width of every filter control so the row fits
       a normal desktop panel. The search input overrides this with
       flex: 1 so it absorbs any leftover space. */
    max-width: 180px;
    min-width: 0;
}

.filter-control:focus {
    outline: none;
    border-color: var(--emerald);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--emerald) 18%, transparent);
}

input.filter-control[type="search"] {
    flex: 1;
    min-width: 80px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 16px;
}

.pager-info {
    color: var(--muted);
    font-size: 0.82rem;
}

.btn-mini:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================================================================
   Modal + forms + action buttons
   ========================================================================= */

.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 16px;
}

.btn-mini {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    border-radius: 4px;
    padding: 6px 8px;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-mini:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-mini.is-danger:hover {
    background: var(--coral-soft);
    border-color: transparent;
    color: var(--coral);
}

.row-actions {
    display: inline-flex;
    gap: 6px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: color-mix(in srgb, var(--navy) 40%, transparent);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.18s ease both;
}

.modal-card {
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    padding: 22px;
    animation: rise 0.22s var(--ease) both;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.modal-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-close {
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 4px 8px;
    border-radius: 4px;
}

.modal-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-form .field-input,
.modal-form .field-select {
    font: inherit;
    font-size: 0.94rem;
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
}

.modal-form .field-input:focus,
.modal-form .field-select:focus {
    outline: none;
    border-color: var(--emerald);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--emerald) 18%, transparent);
}

.field-error {
    margin: 4px 0 0;
    color: var(--coral);
    font-size: 0.8rem;
    font-weight: 550;
}

.modal-form .field-input.is-readonly {
    opacity: 0.75;
    cursor: default;
}

/* A hex box with a swatch that opens the platform colour picker. */
.color-field {
    display: flex;
    gap: 10px;
}

/* Both halves are sized the same way, and these have to out-specify the blanket
   `.field input` rule. A colour input carries a height of its own and will not
   stretch to meet its neighbour - `align-items: stretch` leaves it exactly as
   it was - so it is handed the font size and line height that make the hex box
   47px tall in the first place. Same ingredients on both sides, so the two
   cannot drift apart when the fields are restyled. */
.color-field .field-input,
.color-field .color-swatch {
    font-size: 0.94rem;
    line-height: 1.55;
}

.color-field .field-input {
    flex: 1 1 auto;
    min-width: 0;
}

.color-field .color-swatch {
    flex: none;
    width: 54px;
    /* The browser gives a colour input a height of its own, so it has to be
       released back to auto before it will measure like any other field; and the
       blanket `.field input` padding would leave the swatch looking like a small
       box inside a large one. */
    height: auto;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.color-field .color-swatch:hover {
    border-color: var(--emerald);
}

.color-field .color-swatch:focus-visible {
    outline: none;
    border-color: var(--emerald);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--emerald) 18%, transparent);
}

/* The engine draws its own inner well; inset it so the colour reads as a chip
   rather than as a control floating inside a control. */
.color-swatch::-webkit-color-swatch-wrapper {
    padding: 3px;
}

.color-swatch::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-swatch::-moz-color-swatch {
    border: none;
    border-radius: 2px;
}

.field-note {
    margin: 0;
    font-size: 0.83rem;
    line-height: 1.5;
    color: var(--muted);
}

.field-hint {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--muted);
}

.field-hint:empty {
    display: none;
}

/* An account's identifier (masked number, wallet ID) shown under its name. */
.account-id {
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    align-self: flex-start;
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* Money inside the account that is earmarked for track-only goals. Sits under
   the identifier so the line-up stays consistent. */
.account-committed {
    display: block;
    font-size: 0.82rem;
    color: var(--emerald-2);
    font-weight: 600;
    margin-top: 2px;
}

/* Money that has already left this account for an envelope goal. The
   balance is lower because of it; this label explains the missing amount. */
.account-deducted {
    display: block;
    font-size: 0.82rem;
    color: var(--coral);
    font-weight: 600;
    margin-top: 2px;
}

/* Goal allocation block. Each line is a complete sentence so the user can
   read it as a note: "৳275.97 - ইমার্জেন্সি ফান্ড | দেওয়া হয়েছে।"
   One goal → one line. Multiple goals → one line per goal. */
.goal-allocation {
    margin-top: 4px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.84rem;
    line-height: 1.45;
}

.goal-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 6px;
    min-width: 0;
}

.goal-line-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.goal-allocation.is-committed .goal-line-amount { color: var(--emerald-2); }
.goal-allocation.is-deducted .goal-line-amount { color: var(--coral); }

.goal-line-name {
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    max-width: 100%;
}

.goal-line-sep {
    color: var(--muted);
    opacity: 0.7;
    font-weight: 500;
    flex: 0 0 auto;
}

.goal-line-postfix {
    color: var(--muted);
    font-style: italic;
}

/* Help text for a checkbox-style field (e.g. the envelope toggle). */
.field-help {
    display: block;
    flex-basis: 100%;
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* In a right-aligned toolbar the chip anchors the row to the left instead. */
.page-toolbar .account-id {
    margin-right: auto;
}

/* =========================================================================
   The "paid from" list on a possession purchase
   =========================================================================
   A price can be larger than one account can fund, or simply be settled part
   from a bank and part on a card, so the payment editor is a list of rows
   rather than a single select. Each row is an account, an amount in that
   account's own currency, and - only when the two currencies differ - a rate.
   The rate column collapses to nothing for the ordinary same-currency case, so
   the common purchase is still one row of two fields.

   The column headings are stated once above the rows instead of repeated in
   every one of them. Repeating "paid from" and "amount" down three rows says
   nothing the first row did not already say, and it was the reason the block
   read as a stack of unrelated fields rather than as a list. */

.payment-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
}

.payment-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.payment-block-tools {
    display: flex;
    gap: 8px;
}

/* One grid for the headings and the rows together, so the columns cannot
   disagree: two nested grids sharing a track list still resolve their `auto`
   column independently, and the empty heading above the buttons would size it
   to nothing and hand the difference to the flexible tracks. A single grid has
   one set of tracks and no such opportunity. The rows themselves generate no
   box - they are just their cells, placed in the parent's flow.

   The rate column is only added while some share actually needs converting, so
   the ordinary same-currency purchase does not spend a third of the width on
   nothing. */
.payment-rows {
    /* Shared by the controls and by the button's own box, so "as tall as the
       control beside it" is one number stated once rather than two that can
       drift apart. */
    --control-h: 47px;

    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr) auto;
    gap: 10px;
}

.payment-rows.has-rate {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto;
}

.payment-line-head,
.payment-row {
    display: contents;
}

/* Every cell is placed rather than auto-placed: a row with no rate drops that
   cell, and without an explicit column the remove button would slide left into
   the gap it leaves. */
.payment-cell-account {
    grid-column: 1;
}

.payment-cell-amount {
    grid-column: 2;
}

.payment-cell-remove {
    grid-column: 3;
}

.payment-rows.has-rate .payment-cell-remove {
    grid-column: 4;
}

/* Two ways a cell comes out of the layout: a row whose account shares the
   asset's currency marks its rate cell `hidden` (which the cells' own display
   would otherwise beat), and the rate heading goes away with the column it
   names. */
.payment-rows .field[hidden],
.payment-line-head .payment-cell-rate {
    display: none;
}

.payment-rows.has-rate .payment-line-head .payment-cell-rate {
    display: block;
}

/* The two controls in a row have to come out the same height or the row reads
   as crooked. A select with its native appearance ignores `line-height`, so
   there is no shared typographic setting that levels them: it stays at the
   browser's own 42px while the input, inheriting the form's 1.55, comes out
   five pixels taller. Pinning one height on both turns the equality into a
   fact rather than a coincidence - stripping the select of its dropdown to get
   `line-height` to apply would cost more than it is worth. The value matches
   the single-control fields elsewhere in the modal. */
.payment-row .field-input,
.payment-row .field-select {
    height: var(--control-h);
}

/* The button is centred in a box the height of the control beside it, rather
   than left wherever the flow drops it: a row carrying a rate hint is taller
   than one without, and the button has to stay against the control in both.
   Scoped to the rows, since the cell class is shared with the headings. */
.payment-row .payment-cell-remove {
    justify-content: center;
    height: var(--control-h);
}

.payment-cell-remove .btn-mini {
    padding: 6px 10px;
    line-height: 1;
    font-size: 1rem;
}

.payment-readout {
    margin: 0;
    font-size: 0.83rem;
    color: var(--text-2);
}

.payment-readout.is-warning {
    color: var(--amber-700, #b45309);
}

.payment-cell-rate .field-hint {
    display: block;
    margin-top: 2px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.btn-danger {
    background: linear-gradient(135deg, var(--coral), var(--coral-2));
    color: #fff;
    box-shadow: var(--glow-coral);
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 18px 40px -12px rgba(244, 63, 94, 0.55);
}

/* --- restore from backup ------------------------------------------------- */

.file-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.file-input:hover:not(:disabled) {
    border-color: var(--coral);
}

.restore-report:not(:empty) {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.restore-stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.restore-stat strong {
    font-weight: 600;
    color: var(--text-2);
}

.restore-stat span {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.restore-details {
    margin-top: 4px;
    font-size: 13px;
}

.restore-details summary {
    cursor: pointer;
    color: var(--text-2);
    padding: 4px 0;
}

.restore-tables {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
}

.restore-tables li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 3px 0;
    border-bottom: 1px solid var(--border);
}

.restore-tables li:last-child {
    border-bottom: 0;
}

.restore-tables code {
    font-size: 12px;
    word-break: break-all;
}

.restore-tables .muted-note {
    flex: none;
    font-variant-numeric: tabular-nums;
}

.restore-warning {
    margin: 4px 0 0;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(244, 63, 94, 0.12);
    color: var(--coral);
    font-size: 12.5px;
    line-height: 1.45;
}

.restore-warning:empty {
    display: none;
}

.confirm-body {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.confirm-body::before {
    content: "";
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: var(--emerald-soft);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23059669' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
    background-size: 20px;
    background-repeat: no-repeat;
    background-position: center;
}

.confirm-message {
    margin: 0;
    color: var(--text-2);
    font-size: 0.94rem;
    line-height: 1.5;
    padding-top: 6px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =========================================================================
   Invoices
   ========================================================================= */

.btn-mini.is-primary {
    background: var(--emerald-soft);
    border-color: transparent;
    color: var(--emerald-2);
}

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    color: var(--text-2);
}

.btn-icon .icon {
    width: 20px;
    height: 20px;
}

.btn-icon:hover {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
}

.btn-icon.is-primary {
    background: var(--emerald-soft);
    border-color: transparent;
    color: var(--emerald-2);
}

.btn-icon.is-primary:hover {
    background: var(--emerald);
    color: #fff;
}

.invoice-actions {
    justify-content: center;
    flex-wrap: wrap;
}

.invoice-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.invoice-item-row {
    display: grid;
    grid-template-columns: 1fr 70px 100px 96px 34px;
    gap: 8px;
    align-items: center;
}

.invoice-item-row .filter-control {
    width: 100%;
    min-width: 0;
}

.invoice-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.invoice-total {
    display: block;
    text-align: right;
    font-size: 1.1rem;
    padding-top: 4px;
}

.modal-card.modal-wide {
    max-width: 720px;
}

.invoice-settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.logo-preview {
    max-width: 160px;
    max-height: 80px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
    background: var(--surface);
}

/* Printable invoice sheet */
.invoice-print {
    background: #fff;
    color: #0f172a;
}

.invoice-sheet {
    background: #fff;
    color: #0f172a;
    padding: 22px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.sheet-head {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.sheet-from {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sheet-from strong {
    font-size: 1.15rem;
}

.sheet-from span,
.sheet-billto span {
    color: #475569;
    font-size: 0.85rem;
}

.sheet-logo {
    max-height: 52px;
    max-width: 180px;
    object-fit: contain;
    margin-bottom: 6px;
}

.sheet-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    text-align: right;
}

.sheet-title {
    margin: 0;
    color: #059669;
    font-size: 1.6rem;
    letter-spacing: 0.04em;
}

.sheet-billto {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 18px;
}

.sheet-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #64748b;
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.sheet-table th {
    background: #f1f5f9;
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #334155;
    padding: 8px 10px;
}

.sheet-table td {
    padding: 9px 10px;
    border-bottom: 1px solid #e2e8f0;
}

.sheet-foot {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.sheet-totals {
    margin-left: auto;
    min-width: 220px;
}

.sheet-total-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 4px 0;
}

.sheet-total-row.is-due {
    border-top: 2px solid #e2e8f0;
    margin-top: 4px;
    padding-top: 8px;
    color: #dc2626;
    font-size: 1.05rem;
}

.sheet-payment {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 320px;
}

.sheet-payment span {
    color: #475569;
    font-size: 0.85rem;
}

.sheet-notes {
    margin: 14px 0 0;
    color: #475569;
    font-size: 0.85rem;
}

.sheet-footer {
    margin: 20px 0 0;
    text-align: center;
    color: #94a3b8;
    font-size: 0.8rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 12px;
}

/* Standalone print window body (opened by printInvoice). */
.print-body {
    margin: 0;
    padding: 24px;
    background: #ffffff;
    color: #0f172a;
}

.print-body .invoice-sheet {
    max-width: 820px;
    margin: 0 auto;
}

@media print {
    @page {
        margin: 12mm;
    }

    .print-body {
        padding: 0;
    }

    /* Legacy in-page print (kept as a safety net if a print is triggered while
     * the invoice modal is open). */
    body:not(.print-body) * {
        visibility: hidden;
    }

    body:not(.print-body) .invoice-print,
    body:not(.print-body) .invoice-print * {
        visibility: visible;
    }

    body:not(.print-body) .invoice-print {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }

    .ambient-blob {
        animation: none;
    }
}

/* =========================================================================
   Mobile refinements
   -------------------------------------------------------------------------
   These live at the end of the sheet on purpose: they override components
   (insights, filters, modal, invoices) that are defined later in the file, so
   an earlier media block would lose the cascade at equal specificity.
   ========================================================================= */

@media (max-width: 680px) {
    /* Data tables scroll horizontally instead of squashing their columns. */
    .table-wrap {
        margin: 0;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 560px;
    }

    /* Collapse grids whose minimum track is wider than a phone. */
    .grid,
    .insight-charts,
    .invoice-settings-grid {
        grid-template-columns: 1fr;
    }

    /* List rows (goals, bills, lending, accounts, currencies): let the action
       buttons drop onto their own line instead of overflowing the page. */
    .goal,
    .bill,
    .account-row {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .goal-info,
    .bill-info,
    .account-info {
        flex: 1 1 auto;
    }

    .goal .row-actions,
    .bill .row-actions,
    .account-row .row-actions {
        flex: 1 1 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 8px;
    }

    .budget-head {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .budget-head .row-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .report-card-actions {
        flex-wrap: wrap;
    }

    /* Toolbars, filters, pager and panels get roomier on small screens. */
    .panel {
        padding: 18px 16px;
    }

    .page-toolbar {
        flex-wrap: wrap;
    }

    .filter-bar {
        /* On phones, fall back to wrapping and let the filter-toggle decide
           when to show the bar at all; a nowrap bar would force horizontal
           scrolling on a 360 px-wide screen. */
        flex-wrap: wrap;
        overflow-x: visible;
    }

    .filter-bar .filter-control {
        flex: 1 1 100%;
    }

    /* Transactions date range: From / To side by side instead of two rows. */
    .filter-bar input[type="date"] {
        flex: 1 1 calc(50% - 5px);
    }

    /* Collapse the transactions filters behind the toggle on phones. */
    .filter-toggle {
        display: inline-flex;
        width: 100%;
        justify-content: center;
        align-items: center;
        gap: 8px;
    }

    .filter-collapse {
        display: none;
    }

    .filter-collapse.is-open {
        display: block;
    }

    input.filter-control[type="search"] {
        min-width: 0;
    }

    .pager {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Invoice line items: description/quantity on one line, price/amount on
       the next, remove button on its own. */
    .invoice-item-row {
        grid-template-columns: 1fr 1fr;
    }

    .invoice-item-row > :last-child {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .sheet-head {
        flex-wrap: wrap;
    }

    .invoice-sheet {
        padding: 16px;
    }

    .modal-card {
        padding: 18px 16px;
    }
}

@media (max-width: 420px) {
    .dashboard {
        padding: 20px 12px 28px;
    }

    .panel {
        padding: 16px 13px;
    }

    .stat,
    .stat.hero {
        padding: 16px 16px;
    }

    .table {
        min-width: 480px;
    }

    /* Stack the create/edit forms' footer buttons full width. */
    .modal-actions {
        flex-wrap: wrap;
    }

    .modal-actions .btn {
        flex: 1 1 100%;
    }
}

/* =========================================================================
   Dashboard: mobile layout
   -------------------------------------------------------------------------
   Phones get a dense, scannable summary: the KPI cards sit two per row
   instead of one, the hero is more compact, and the charts/legend get the
   full width. Desktop is untouched.
   ========================================================================= */

@media (max-width: 680px) {
    .dashboard-head {
        margin-bottom: 18px;
    }

    .dashboard-title {
        font-size: clamp(1.65rem, 7vw, 2.05rem);
    }

    /* Two KPI cards per row (the net-worth hero still spans all columns). */
    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 10px;
    }

    .stat.kpi {
        padding: 13px;
        gap: 8px;
    }

    .stat.kpi .stat-top {
        gap: 9px;
    }

    .stat.kpi .stat-icon {
        width: 32px;
        height: 32px;
    }

    .stat.kpi .stat-icon svg {
        width: 16px;
        height: 16px;
    }

    .stat.kpi .stat-label {
        font-size: 0.66rem;
        letter-spacing: 0.05em;
        line-height: 1.2;
    }

    .stat.kpi .stat-value {
        font-size: 1.12rem;
        line-height: 1.15;
    }

    /* The net-worth hero stays the focal point, just more compact. */
    .stat.hero {
        padding: 18px 16px;
        gap: 14px;
    }

    .hero-value {
        font-size: clamp(1.9rem, 9vw, 2.5rem);
    }

    .hero-foot {
        grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
        gap: 12px;
        padding-top: 14px;
    }

    .hero-cell-label {
        font-size: 0.7rem;
    }

    .hero-cell-value {
        font-size: 0.98rem;
    }

    .insights {
        gap: 16px;
    }

    .insight-summary {
        gap: 20px;
    }

    .insight-stat-value {
        font-size: 1.15rem;
    }

    .insight-charts {
        gap: 18px;
    }

    .breakdown {
        gap: 16px;
    }

    .flow-head {
        flex-wrap: wrap;
        row-gap: 4px;
    }

    .legend-item {
        gap: 8px;
        padding: 8px 4px;
        font-size: 0.84rem;
    }

    .legend-pct {
        min-width: 40px;
    }

    .grid {
        gap: 14px;
    }

    /* Loading skeleton mirrors the denser loaded layout (less shift). */
    .skel-row {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .skel-stat {
        height: 88px;
    }
}

/* =========================================================================
   RTL (Arabic)
   -------------------------------------------------------------------------
   Flex rows already follow the document direction, so most of the layout
   mirrors automatically. These rules only fix the physical properties that
   do not (borders, accent bars, text alignment, hover nudge).
   ========================================================================= */

[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
}

[dir="rtl"] .nav-group-label {
    border-left: none;
    border-right: 3px solid var(--emerald);
    padding: 7px 13px 7px 12px;
}

/* The hero accent bar sits on the leading edge. */
[dir="rtl"] .stat.hero::before {
    inset: 0 0 0 auto;
}

[dir="rtl"] .table th {
    text-align: right;
}

[dir="rtl"] .align-right {
    text-align: left;
}

[dir="rtl"] .bill:hover,
[dir="rtl"] .account-row:hover {
    transform: translateX(-4px);
}

[dir="rtl"] .sheet-totals {
    margin-left: 0;
    margin-right: auto;
}

/* Letter-spacing is designed for Latin caps and hurts Arabic legibility. */
[dir="rtl"] .eyebrow,
[dir="rtl"] .stat-label,
[dir="rtl"] .insight-stat-label,
[dir="rtl"] .insight-title,
[dir="rtl"] .hero-cell-label,
[dir="rtl"] .nav-group-label,
[dir="rtl"] .sheet-label,
[dir="rtl"] .table th {
    letter-spacing: 0;
}

/* Same for Bengali, where extra tracking can break conjunct clusters. */
:root[lang="bn"] .eyebrow,
:root[lang="bn"] .stat-label,
:root[lang="bn"] .insight-stat-label,
:root[lang="bn"] .insight-title,
:root[lang="bn"] .hero-cell-label,
:root[lang="bn"] .nav-group-label,
:root[lang="bn"] .sheet-label,
:root[lang="bn"] .table th {
    letter-spacing: 0;
}

/* =========================================================================
   PWA install banner
   ========================================================================= */

.install-banner {
    position: fixed;
    left: 50%;
    bottom: 24px;
    /* Below modals (100) so it never floats over a dialog. */
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(560px, calc(100vw - 24px));
    padding: 12px 14px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translate(-50%, 20px);
    transition: opacity 0.28s ease, transform 0.28s var(--ease);
}

.install-banner.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.install-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    flex: none;
}

.install-banner-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.install-banner-title {
    font-weight: 700;
    font-size: 0.92rem;
}

.install-banner-text {
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

.install-banner-confirm {
    flex: none;
}

.install-banner-close {
    flex: none;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}

.install-banner-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

@media (max-width: 680px) {
    /* Clear the fixed bottom navigation and the home-bar inset. */
    .install-banner {
        bottom: calc(92px + env(safe-area-inset-bottom));
        flex-wrap: wrap;
        row-gap: 10px;
    }

    .install-banner-confirm {
        flex: 1 1 100%;
    }
}

/* =========================================================================
   Installed (standalone) safe areas
   -------------------------------------------------------------------------
   With viewport-fit=cover the installed app draws under the notch / home
   indicator, so pad the containers that hug the screen edges.
   ========================================================================= */

@media (display-mode: standalone) {
    .auth {
        padding-top: calc(40px + env(safe-area-inset-top));
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }
}

@media (display-mode: standalone) and (min-width: 681px) {
    .dashboard {
        padding-top: calc(40px + env(safe-area-inset-top));
    }

    .sidebar {
        padding-top: calc(22px + env(safe-area-inset-top));
    }
}

@media (display-mode: standalone) and (max-width: 680px) {
    .dashboard {
        padding-top: calc(24px + env(safe-area-inset-top));
    }
}

/* =========================================================================
   Stacked tables: native-style cards on phones
   -------------------------------------------------------------------------
   A `.stack-table` collapses into one card per row: the header is hidden and
   each cell shows its column name as an inline label. `.cell-main` becomes the
   card title, `.cell-sub` a supporting line under it, and `.cell-actions`
   turns the row buttons into full-width touch targets.
   ========================================================================= */

@media (max-width: 680px) {
    .stack-table {
        min-width: 0;
    }

    .stack-table thead {
        display: none;
    }

    .stack-table,
    .stack-table tbody,
    .stack-table tr,
    .stack-table td {
        display: block;
        width: 100%;
    }

    .stack-table tr {
        display: flex;
        flex-direction: column;
        margin: 0 0 10px;
        padding: 4px 12px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface-2);
    }

    .stack-table tr:last-child {
        margin-bottom: 0;
    }

    .stack-table td {
        padding: 9px 0;
        border: none;
        border-top: 1px solid var(--border);
    }

    /* Title / subtitle cells sit at the top of the card without a divider. */
    .stack-table td.cell-main {
        order: -2;
        border-top: none;
        padding-bottom: 2px;
    }

    .stack-table td.cell-sub {
        order: -1;
        border-top: none;
        padding-top: 0;
        padding-bottom: 9px;
        color: var(--text-2);
    }

    .stack-table td.cell-sub::before {
        content: "→ ";
        color: var(--muted);
    }

    [dir="rtl"] .stack-table td.cell-sub::before {
        content: "← ";
    }

    .stack-table td[data-label] {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .stack-table td[data-label]::before {
        content: attr(data-label);
        flex: none;
        color: var(--muted);
        font-size: 0.7rem;
        font-weight: 650;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .stack-table td.cell-actions {
        padding-top: 10px;
    }

    .stack-table td.cell-actions .row-actions {
        display: flex;
        width: 100%;
        gap: 8px;
    }

    .stack-table td.cell-actions .row-actions .btn-mini {
        flex: 1 1 0;
        text-align: center;
        padding-top: 9px;
        padding-bottom: 9px;
    }

    .stack-table .row-main {
        min-width: 0;
    }

    .stack-table .empty-cell {
        border-top: none;
        padding: 18px 0;
        text-align: center;
    }

    [dir="rtl"] .stack-table td[data-label]::before,
    :root[lang="bn"] .stack-table td[data-label]::before {
        letter-spacing: 0;
    }
}

/* =========================================================================
   List cards: accounts, bills, budgets on phones
   -------------------------------------------------------------------------
   Separator-style rows become discrete rounded cards so each item reads as a
   tappable unit (accounts/assets/liabilities/investments, bills, budgets).
   ========================================================================= */

@media (max-width: 680px) {
    .account-list,
    .bill-list,
    .goal-list,
    .budget-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .account-row,
    .account-row:first-child,
    .account-row:last-child,
    .bill,
    .bill:first-child,
    .bill:last-child,
    .budget,
    .budget:first-child,
    .budget:last-child {
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface-2);
    }

    /* Goals are already cards; match their radius/padding to the others. */
    .goal {
        padding: 12px;
        border-radius: 8px;
    }

    /* The whole card is the target, so drop the sideways hover nudge. */
    .account-row:hover,
    .bill:hover {
        transform: none;
    }

    /* Keep the amount on the same line as the name, whatever the name's length.
       The identity column is sized from zero rather than its content (flex-basis
       0), so a long name shrinks and wraps inside its own column instead of
       pushing the amount onto a line of its own. The amount then never has to
       wrap: nowrap stops a break after the currency symbol. */
    .account-row {
        flex-wrap: wrap;
        align-items: flex-start;
        column-gap: 10px;
    }

    .account-row .account-icon {
        margin-top: 2px;
    }

    .account-row .account-info {
        flex: 1 1 0;
        min-width: 0;
    }

    .account-row .account-name {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
        min-width: 0;
    }

    /* A long person or business name breaks inside the column instead of
       stretching the row; CJK and Bangla have no spaces to break on. */
    .account-row .account-name > span:first-child {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .account-row .account-balance {
        flex: 0 0 auto;
        white-space: nowrap;
        text-align: end;
    }

    .account-row .muted-note {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    /* Primary toolbar actions become full-width touch targets. */
    .page-toolbar .btn {
        flex: 1 1 auto;
    }
}

/* =========================================================================
   Settings: mobile form layout
   -------------------------------------------------------------------------
   Stack each setting's label above its control and make controls full width.
   ========================================================================= */

@media (max-width: 680px) {
    .settings-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .settings-row .filter-control,
    .settings-row .btn,
    .settings-col .modal-actions .btn {
        width: 100%;
    }
}

/* =========================================================================
   Goal card: mobile layout
   -------------------------------------------------------------------------
   Below 520px the horizontal donut + info + actions row gets squeezed, so
   stack the donut on top (centred) and let the info text and action buttons
   flow left-to-right from the card's left edge.
   ========================================================================= */

@media (max-width: 520px) {
    .goal {
        align-items: center;
        text-align: left;
        gap: 12px;
    }

    .goal .ring {
        width: 96px;
        height: 96px;
    }

    .goal-info {
        align-items: flex-start;
    }

    .goal-icons {
        justify-content: flex-start;
    }

    .goal .row-actions {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .goal .row-actions .btn {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.78rem;
        padding: 6px 8px;
    }
}

/* --- Transactions page toolbar & PDF button ------------------------------ */
.tx-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.tx-toolbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.tx-pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.tx-pdf-btn svg {
    width: 16px;
    height: 16px;
}

.filter-bar input[type="month"] {
    min-width: 140px;
}
