/* ==========================================================================
   FinanceGo — design system for the money management app.
   Minimalist & elegant: quiet neutrals, hairline borders,
   monochrome accent, generous whitespace.
   ========================================================================== */

:root {
    --paper: #f6f6f4;
    --paper-raised: #ffffff;
    --ink: #17171a;
    --ink-soft: #45454b;
    --muted: #84848c;
    --line: #eaeae7;
    --line-strong: #dddcd8;
    --accent: #1b1b1e;
    --accent-deep: #000000;
    --accent-wash: #f1f1ef;
    --positive: #147d52;
    --negative: #b0392e;
    --danger: #b0392e;
    --danger-wash: #f7ebe8;
    --danger-ink: #8c2c22;
    --sidebar: #141416;
    --sidebar-ink: #a3a3ac;
    --input-bg: #ffffff;
    --on-ink: #fafafa; /* text color used on top of var(--ink) backgrounds */
    --on-accent: #fafafa; /* text color used on top of var(--accent) backgrounds */
    --hover: rgba(23, 23, 26, 0.05);
    --hover-soft: rgba(23, 23, 26, 0.035);
    --ring: rgba(23, 23, 26, 0.12);
    --shadow-card: 0 1px 2px rgba(20, 20, 25, 0.04), 0 1px 3px rgba(20, 20, 25, 0.03);
    --radius: 14px;
    color-scheme: light;
}

/* Dark mode — same minimal language, neutral night palette.
   The accent inverts to a light tone, so surfaces built on it flip too. */
:root[data-theme='dark'] {
    --paper: #101013;
    --paper-raised: #18181c;
    --ink: #ededf0;
    --ink-soft: #c9c9cf;
    --muted: #82828c;
    --line: #28282d;
    --line-strong: #37373e;
    --accent: #ececef;
    --accent-deep: #ffffff;
    --accent-wash: #232329;
    --positive: #4fb583;
    --negative: #e2857a;
    --danger: #e2857a;
    --danger-wash: #2c201d;
    --danger-ink: #eda59c;
    --sidebar: #0c0c0e;
    --sidebar-ink: #9b9ba4;
    --input-bg: #212127;
    --on-ink: #131316;
    --on-accent: #17171a;
    --hover: rgba(255, 255, 255, 0.07);
    --hover-soft: rgba(255, 255, 255, 0.05);
    --ring: rgba(255, 255, 255, 0.16);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0;
}

a { color: inherit; text-decoration: none; }

::selection { background: var(--ink); color: var(--on-ink); }

/* ---- Numbers ---------------------------------------------------------- */
.money, .num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}
.money--pos { color: var(--positive); }
.money--neg { color: var(--negative); }

/* ---- Shell layout ------------------------------------------------------ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    padding: 26px 0 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
}

.brand {
    padding: 0 26px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 14px;
}

.brand__name {
    font-size: 20px;
    font-weight: 600;
    color: #f5f5f7;
    letter-spacing: -0.01em;
}

.brand__tagline {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: rgba(255, 255, 255, 0.42);
    margin-top: 3px;
}

.nav { padding: 0 12px; display: grid; gap: 2px; }

.nav__item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 14px;
    border-radius: 7px;
    font-size: 14px;
    color: var(--sidebar-ink);
    transition: background 120ms ease, color 120ms ease;
}

.nav__item svg { width: 17px; height: 17px; opacity: 0.7; }

.nav__item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.nav__item.is-active {
    background: var(--accent);
    color: var(--on-accent);
}
.nav__item.is-active svg { opacity: 1; }

.sidebar__foot {
    margin-top: auto;
    padding: 14px 12px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.userchip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
}

.userchip__avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    display: grid; place-items: center;
    font-size: 13px; font-weight: 600;
}

.userchip__name {
    font-size: 13px;
    color: #e9e9ee;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.userchip form button {
    all: unset;
    cursor: pointer;
    display: grid;
    place-items: center;
    width: 28px; height: 28px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.55);
}
.userchip form button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.userchip form button svg { width: 15px; height: 15px; }

/* ---- Main column ------------------------------------------------------- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 30px 40px 0;
}

.topbar h1 { font-size: 26px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.topbar__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.content { padding: 24px 40px 56px; max-width: 1160px; width: 100%; }

/* ---- Cards ------------------------------------------------------------- */
.card {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.card + .card { margin-top: 16px; }

.card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}
.card__head h2 { font-size: 16px; }
.card__head .hint { font-size: 12.5px; color: var(--muted); }

.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px 18px 14px;
}

.stat__label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 600;
    color: var(--muted);
}

.stat__value {
    font-size: 25px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.stat__meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 16px;
    align-items: start;
}
.grid-2 > .card + .card { margin-top: 0; }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .topbar, .content { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 720px) {
    .shell { flex-direction: column; }
    .sidebar { position: static; height: auto; width: 100%; padding: 16px 0; }
    .nav { grid-auto-flow: column; overflow-x: auto; }
    .brand { border-bottom: none; padding-bottom: 8px; }
    .sidebar__foot { display: none; }
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 15px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
    white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }

.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-deep); }

.btn--ghost {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--ink-soft);
}
.btn--ghost:hover { background: var(--hover-soft); }

.btn--quiet {
    background: transparent;
    color: var(--muted);
    padding: 6px 8px;
}
.btn--quiet:hover { color: var(--ink); background: var(--hover-soft); }

.btn--danger { background: transparent; border-color: transparent; color: var(--negative); padding: 6px 8px; }
.btn--danger:hover { background: var(--danger-wash); }

.btn--block { width: 100%; justify-content: center; }

.iconbtn {
    all: unset;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
    width: 30px; height: 30px;
    border-radius: 7px;
    color: var(--muted);
}
.iconbtn:hover { background: var(--hover-soft); color: var(--ink); }
.iconbtn--danger:hover { background: var(--danger-wash); color: var(--negative); }
.iconbtn svg { width: 16px; height: 16px; }

/* ---- Forms ---------------------------------------------------------------- */
.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}

.input,
select.input,
textarea.input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--input-bg);
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--ring);
}

.input--error { border-color: var(--negative); }

.field__error {
    color: var(--negative);
    font-size: 12.5px;
    margin-top: 5px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 22px;
}

/* Segmented type switch (income / expense) */
.segmented {
    display: inline-flex;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    overflow: hidden;
    background: var(--input-bg);
}
.segmented label {
    margin: 0 !important;
    padding: 8px 18px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) {
    background: var(--ink);
    color: var(--on-ink);
}
.segmented label:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }

/* Color swatch picker */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label {
    margin: 0 !important;
    cursor: pointer;
    position: relative;
}
.swatches input { position: absolute; opacity: 0; }
.swatch {
    display: block;
    width: 26px; height: 26px;
    border-radius: 7px;
    border: 2px solid transparent;
}
.swatches input:checked + .swatch { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Icon picker */
.icons-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.icons-picker label { margin: 0 !important; cursor: pointer; position: relative; }
.icons-picker input { position: absolute; opacity: 0; }
.icons-picker .ipick {
    display: grid; place-items: center;
    width: 34px; height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    color: var(--ink-soft);
}
.icons-picker .ipick svg { width: 17px; height: 17px; }
.icons-picker input:checked + .ipick { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* ---- Tables --------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    color: var(--muted);
    padding: 11px 20px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table td {
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tbody tr { transition: background 80ms ease; }
.table tbody tr:hover { background: var(--hover-soft); }

.t-right { text-align: right; }
.t-nowrap { white-space: nowrap; }
.t-muted { color: var(--muted); }
.t-small { font-size: 12.5px; }

/* Category chip */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
}
.chip__dot {
    width: 9px; height: 9px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Account tile */
.account-tile {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}
.account-tile:last-child { border-bottom: none; }

.account-mark {
    width: 38px; height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    color: var(--on-accent);
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
}

.account-tile__name { font-weight: 600; font-size: 14.5px; }
.account-tile__type { font-size: 12.5px; color: var(--muted); }
.account-tile__balance {
    margin-left: auto;
    text-align: right;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

.txn-note { font-weight: 500; }
.txn-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

/* Budget bars */
.budget-row { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: none; }

.bar {
    height: 6px;
    background: var(--line);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 9px;
}
.bar__fill { height: 100%; border-radius: 99px; transition: width 300ms ease; }

.breakdown-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .bar { flex: 1; margin: 0; }
.breakdown-row .amount { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }

.empty {
    padding: 44px 24px;
    text-align: center;
    color: var(--muted);
}
.empty svg { width: 30px; height: 30px; opacity: 0.45; margin-bottom: 10px; }
.empty p { margin: 4px 0 14px; font-size: 14px; }

.flash {
    margin: 0 0 18px;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 13.5px;
    border: 1px solid var(--line-strong);
    background: var(--paper-raised);
    color: var(--ink-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.flash--error { border-color: #ecccc5; background: var(--danger-wash); color: var(--danger-ink); }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.filters .field { margin: 0; }
.filters .field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.filters .input { padding: 7px 10px; font-size: 13px; width: auto; }

.pagination {
    display: flex;
    gap: 4px;
    padding: 14px 20px;
    justify-content: flex-end;
}
.pagination a, .pagination span {
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
}
.pagination a:hover { background: var(--hover-soft); }
.pagination .is-current { background: var(--ink); color: var(--on-ink); }
.pagination .is-disabled { color: var(--line-strong); }

.month-pager {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--paper-raised);
    overflow: hidden;
}
.month-pager a, .month-pager span {
    padding: 7px 13px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink-soft);
}
.month-pager a:hover { background: var(--hover-soft); }
.month-pager span { min-width: 128px; text-align: center; }

.auth-wrap {
    /* Flexes to fill the space between viewport top and the shared
       footer, keeping the footer visible without scrolling. */
    flex: 1 0 auto;
    display: grid;
    place-items: center;
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 36px 34px;
}
.auth-card .brand-mark {
    font-size: 23px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}
.auth-card .auth-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 26px; }
.auth-foot { margin-top: 20px; font-size: 13.5px; color: var(--muted); text-align: center; }
.auth-foot a { color: var(--accent); font-weight: 600; }
.auth-foot a:hover { text-decoration: underline; }

.mono-note { font-size: 12.5px; color: var(--muted); }
.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---- Footer ------------------------------------------------------------- */
.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-footer {
    margin-top: auto;
    border-top: 1px solid var(--line);
    background: var(--paper-raised);
}
.site-footer--guest { margin-top: 0; }

.footer-inner {
    max-width: 1160px;
    width: 100%;
    margin: 0 auto;
    padding: 14px 40px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 20px;
    font-size: 12.5px;
    color: var(--muted);
}

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
}
.footer-brand svg { color: var(--accent); }

/* ---- Brand row (sidebar / auth) ------------------------------------------ */
.brand-row {
    display: flex;
    align-items: center;
    gap: 11px;
}
.brand-row svg { color: var(--accent); flex-shrink: 0; }

/* ---- Theme toggle --------------------------------------------------------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border: none;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    position: relative;
    width: 58px;
    height: 26px;
}

.theme-toggle__sun,
.theme-toggle__moon {
    display: grid;
    place-items: center;
    width: 18px; height: 18px;
    color: rgba(255, 255, 255, 0.85);
}
.theme-toggle__sun svg,
.theme-toggle__moon svg { width: 13px; height: 13px; }

.theme-toggle__knob {
    position: absolute;
    top: 3px; left: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    transition: transform 160ms ease;
}

:root[data-theme='dark'] .theme-toggle__knob { transform: translateX(32px); }

.theme-toggle--floating {
    position: absolute;
    top: 18px; right: 0;
    background: var(--line);
}


.footer-copy a {
    color: var(--accent);
    font-weight: 600;
}
.footer-copy a:hover { text-decoration: underline; }

@media (max-width: 720px) {
    .footer-inner { padding: 12px 16px; }
}

/* ---- Currency switcher --------------------------------------------------- */
.cur-switch {
    display: inline-flex;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    overflow: hidden;
    background: var(--paper-raised);
}
.cur-switch a {
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--muted);
    border-right: 1px solid var(--line);
}
.cur-switch a:last-child { border-right: none; }
.cur-switch a:hover { color: var(--ink); background: var(--hover-soft); }
.cur-switch a.is-active {
    background: var(--ink);
    color: var(--on-ink);
}

/* ==========================================================================
   Responsive hardening — real-device pass
   ========================================================================== */

/* Center the main column on wide screens instead of hugging the sidebar. */
.topbar,
.content {
    width: 100%;
    max-width: 1240px;
    margin-inline: auto;
}

/* Rows (transactions, accounts, categories): let text shrink with
   ellipsis instead of pushing balances off-screen. */
.account-tile {
    min-width: 0;
}
.account-tile > div:nth-child(2) {
    min-width: 0;
    flex: 1 1 auto;
}
.txn-note,
.txn-sub,
.account-tile__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-tile__balance {
    white-space: nowrap;
}

@media (max-width: 480px) {
    .account-tile { gap: 10px; padding-inline: 14px; }
    .table th, .table td { padding-inline: 14px; }
    .card__head { padding-inline: 14px; }
    .budget-row { padding-inline: 14px; }
    .breakdown-row { padding-inline: 14px; }
    .filters { padding-inline: 14px; }
}

/* Currency switchers must scroll inside themselves, never widen the page. */
.cur-switch {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.cur-switch::-webkit-scrollbar { display: none; }
.cur-switch a { white-space: nowrap; }
.card__head > .cur-switch,
.topbar__actions > .cur-switch { max-width: min(100%, 320px); }
.topbar__actions { min-width: 0; }

/* iPhone home-indicator / notch safe areas. */
.footer-inner {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.site-footer--guest .footer-inner {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

@media (max-width: 720px) {
    /* Landscape phones and small tablets get a roomier content column. */
    .content { padding-top: 18px; }

    /* Filters: fields flow naturally and inputs fill their slot. */
    .filters { align-items: stretch; }
    .filters .input { width: 100%; }

    /* Flow chart stays readable when squeezed. */
    .flow-label { font-size: 9px; padding-top: 5px; letter-spacing: 0; }
    .flow-chart { height: 150px; gap: 3px; }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat { padding: 12px; }
    .stat__value { font-size: 18px; }

    /* Hide every other month label on tiny screens; bars + tooltip remain. */
    .flow-col:nth-child(even) .flow-label { visibility: hidden; }

    .month-pager span { min-width: 96px; padding: 7px 8px; }
    .btn { padding: 7px 12px; font-size: 13px; }
    .topbar h1 { font-size: 20px; }
}

@media (max-width: 340px) {
    .stats { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* Large desktops: keep line lengths pleasant and center everything. */
@media (min-width: 1600px) {
    .topbar, .content { max-width: 1320px; }
}

/* ==========================================================================
   Cash flow
   ========================================================================== */

.legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
    width: 10px; height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.flow-chart {
    display: flex;
    align-items: stretch;
    gap: 8px;
    height: 230px;
}

.flow-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.flow-bars {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    border-bottom: 1px solid var(--line-strong);
    padding-bottom: 1px;
}

.flow-bar {
    width: clamp(6px, 30%, 18px);
    min-height: 2px;
    border-radius: 3px 3px 0 0;
    transition: opacity 120ms ease;
}
.flow-col:hover .flow-bar { opacity: 0.82; }

.flow-label {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    padding-top: 7px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.flow-label.is-current {
    color: var(--ink);
    font-weight: 700;
}

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table tfoot td {
    padding: 12px 20px;
    border-top: 1px solid var(--line-strong);
    background: var(--accent-wash);
}

/* ==========================================================================
   Responsive — tablets and phones
   ========================================================================== */

.nav__item { white-space: nowrap; }

@media (max-width: 1024px) {
    .sidebar { width: 200px; }
    .brand { padding: 0 20px 18px; }
}

@media (max-width: 720px) {
    body { font-size: 14px; }

    /* Sidebar becomes a top bar; nav scrolls horizontally */
    .sidebar { padding: 0; }
    .brand {
        display: flex;
        align-items: baseline;
        gap: 10px;
        padding: 14px 16px 10px;
        border-bottom: none;
        margin-bottom: 0;
    }
    .brand__name { font-size: 18px; }
    .nav {
        grid-auto-flow: column;
        justify-content: start;
        padding: 0 8px 10px;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .nav::-webkit-scrollbar { display: none; }
    .sidebar__foot { display: none; }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 18px 16px 0;
    }
    .topbar h1 { font-size: 22px; }
    .content { padding: 16px 16px 48px; }

    .stats { gap: 10px; margin-bottom: 14px; }
    .stat { padding: 13px 14px 11px; }
    .stat__value { font-size: 21px; }

    .flow-chart { height: 170px; gap: 4px; }
    .card__head { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr 1fr; }
    .stat__value { font-size: 19px; }

    /* Prevent iOS zoom-on-focus */
    .input, select.input, textarea.input { font-size: 16px; }

    .filters { padding: 12px 14px; }
    .filters > .field { flex: 1 1 calc(50% - 5px); }
    .filters > .input,
    .filters > button,
    .filters > a { flex: 1 1 auto; }

    .table th, .table td { padding: 10px 12px; }
    .breakdown-row .amount { width: auto; }
    .account-tile__balance { font-size: 15px; }

    .form-actions { flex-wrap: wrap; }
    .form-actions .btn { flex: 1; justify-content: center; }

    .auth-card { padding: 28px 22px; }
    .month-pager span { min-width: 100px; }
}

/* ==========================================================================
   Responsive pass v2 — real-device refinements
   Appended last on purpose: these rules win the cascade over the
   scattered blocks above without touching their desktop behavior.
   ========================================================================== */

/* Guard against sideways scrolling caused by stray wide content. */
body { overflow-x: clip; }

/* ---- Mobile header: sticky top bar, account controls stay reachable ---- */
@media (max-width: 720px) {
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 50;
        height: auto;
        box-shadow: 0 6px 18px rgba(10, 10, 14, 0.18);
    }

    .brand { padding: 12px 16px 8px; }

    .nav {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding: 0 8px 8px;
    }

    /* Comfortable touch targets for horizontal nav chips. */
    .nav__item { padding: 9px 13px; font-size: 13.5px; }

    /* Profile, logout and theme toggle were previously hidden on phones —
       keep them as a compact second bar under the nav. */
    .sidebar__foot {
        display: flex;
        align-items: center;
        gap: 4px;
        margin-top: 0;
        padding: 7px 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
    }
    .sidebar-foot-row { flex: 1 1 auto; min-width: 0; }
    .userchip { padding: 2px 6px; gap: 8px; min-width: 0; }

    /* Topbar actions flow full-width under the page title. */
    .topbar__actions { width: 100%; }
    .topbar__actions > .btn--primary { flex: 1 1 auto; justify-content: center; }

    /* Filter fields grow to fill the row instead of hugging left. */
    .filters > .field { flex: 1 1 150px; }

    /* Prevent iOS zoom-on-focus at every phone width, not just ≤480px. */
    .input, select.input, textarea.input { font-size: 16px; }
}

/* Short landscape phones: collapse the account bar to keep chart height. */
@media (max-width: 720px) and (max-height: 420px) {
    .sidebar__foot { display: none; }
}

/* ---- Small phones --------------------------------------------------------- */
@media (max-width: 480px) {
    /* Long money values must never push a stat card past its slot. */
    .stat { min-width: 0; }
    .stat__value { font-size: clamp(17px, 5.6vw, 21px); overflow-wrap: anywhere; }

    /* Row actions may drop to their own line instead of squeezing the
       balance off-screen on ~320px devices. */
    .account-tile { flex-wrap: wrap; row-gap: 6px; }
    .account-tile > div:last-child { margin-left: auto; }

    /* Pagination centers and wraps instead of clipping at the right edge. */
    .pagination { justify-content: center; flex-wrap: wrap; }
}

/* ---- Touch devices: bigger hit areas --------------------------------------- */
@media (pointer: coarse) {
    .iconbtn { width: 36px; height: 36px; }
    .userchip form button { width: 34px; height: 34px; }
    .pagination a, .pagination span { padding: 9px 14px; }
    .month-pager a, .month-pager span { padding: 10px 14px; }
    .cur-switch a { padding: 9px 13px; }
}

/* ---- Guest / auth pages ------------------------------------------------------ */
/* Keep the floating theme toggle off the screen edge. */
.theme-toggle--floating { right: 16px; }

/* ==========================================================================
   Responsive pass v3 — hamburger drawer navigation (phones)
   ========================================================================== */

.mobilebar { display: none; }
.scrim { display: none; }

.menu-btn {
    all: unset;
    cursor: pointer;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 9px;
    color: var(--sidebar-ink);
}
.menu-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.menu-btn svg { width: 22px; height: 22px; }

@media (max-width: 720px) {
    /* Slim app bar pinned to the top of the screen. */
    .mobilebar {
        display: flex;
        align-items: center;
        gap: 6px;
        position: sticky;
        top: 0;
        z-index: 60;
        background: var(--sidebar);
        padding: 8px 10px;
        padding-top: calc(8px + env(safe-area-inset-top));
        box-shadow: 0 6px 18px rgba(10, 10, 14, 0.18);
    }
    .mobilebar__brand {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        flex: 1 1 auto;
        min-width: 0;
        font-size: 17px;
        font-weight: 600;
        letter-spacing: -0.01em;
        color: #f5f5f7;
    }
    .mobilebar__brand svg { color: var(--accent); flex-shrink: 0; }
    .mobilebar .theme-toggle { flex-shrink: 0; }

    /* Dimmed backdrop behind the open drawer. */
    .scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(8, 8, 10, 0.55);
        z-index: 70;
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }
    body.nav-open .scrim { opacity: 1; pointer-events: auto; }

    /* Sidebar becomes an off-canvas drawer. */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(286px, 84vw);
        height: 100dvh;
        transform: translateX(-104%);
        transition: transform 220ms ease;
        z-index: 80;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    body.nav-open .sidebar { transform: none; }

    /* Drawer nav is a vertical list again — no sideways chips. */
    .nav {
        display: grid;
        grid-auto-flow: row;
        overflow: visible;
        padding: 6px 12px 12px;
    }
    .nav__item { padding: 11px 14px; font-size: 14px; }

    /* Drawer footer: user chip on its own row, theme toggle under it. */
    .sidebar__foot {
        display: block;
        margin-top: auto;
        padding: 12px;
    }
    .sidebar-foot-row { display: block; }
}

/* Theme toggle lives in the topbar actions (right of the primary button)
   on every device — the single toggle for the whole app. */
.theme-toggle--topbar { display: inline-flex; flex-shrink: 0; }

/* ==========================================================================
   Default currency switcher (sidebar)
   ========================================================================== */

/* Sits above the user chip in the sidebar foot. The sidebar is near-black
   in BOTH themes, so its controls can safely use fixed dark values. */
.cur-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 14px 14px;
}

.cur-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.42);
}

.cur-select {
    width: 100%;
    padding: 7px 9px;
    font: inherit;
    font-size: 13px;
    color: #eaeaef;
    background: #232328;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    cursor: pointer;
}

.cur-select:hover { border-color: rgba(255, 255, 255, 0.22); }
.cur-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

@media (max-width: 720px) {
    /* Compact inline control inside the mobile account bar. */
    .sidebar__foot .cur-form {
        flex: 0 0 auto;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding: 0 6px;
    }
    .sidebar__foot .cur-label { display: none; }
    .sidebar__foot .cur-select { width: auto; padding: 5px 7px; font-size: 12.5px; }
}

/* ==========================================================================
   Shared finance — workspace banner & share rows
   ========================================================================== */

/* Shown while browsing a partner's workspace; calm accent so it reads as
   context, not an error. */
.workspace-banner {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px 16px;
    padding: 11px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--line-strong);
    border-left: 3px solid var(--ink);
    border-radius: var(--radius);
    background: var(--paper-raised);
    font-size: 13.5px;
    color: var(--ink-soft);
}

.share-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}
.share-row:last-child { border-bottom: none; }
.share-row > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
}
.share-row form { margin: 0; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
    flex-shrink: 0;
}
.badge--ok { background: var(--accent-wash); color: var(--ink); }
.badge--pending { background: var(--hover-soft); color: var(--muted); }

/* ==========================================================================
   Responsive pass v4 — the page must never pan horizontally
   ========================================================================== */

/* Clip sideways overflow on BOTH html and body: some mobile browsers
   (notably iOS Safari) ignore a body-only rule. `clip` is preferred over
   `hidden` because it does not create a scroll container, so position:
   sticky (mobile app bar) keeps working. */
html, body {
    max-width: 100%;
    overflow-x: clip;
}
@supports not (overflow: clip) {
    html, body { overflow-x: hidden; }
}

/* `1fr` grid tracks carry an automatic minimum, so one long unbreakable
   value (a money amount, an email) can blow the whole page wide. Pin the
   minimum to zero / the track size. */
.stats { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
.stat,
.form-row > .field,
.filters > .field,
.card,
.topbar > div:first-child {
    min-width: 0;
}
.form-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 560px) {
    .form-row { grid-template-columns: minmax(0, 1fr); }
}

/* Auto-width filter selects (721–900px range) must never exceed their card. */
.filters .input { max-width: 100%; }

/* Nowrap balances get a wrap escape hatch across the whole phone/tablet
   range, not just ≤480px. */
@media (max-width: 720px) {
    .account-tile { flex-wrap: wrap; row-gap: 6px; }
}

/* The closed drawer is fully inert: not hit-testable, not focusable, and
   cannot contribute to any gesture or scroll area. */
@media (max-width: 720px) {
    .sidebar {
        visibility: hidden;
        transition: transform 220ms ease, visibility 0s linear 220ms;
    }
    body.nav-open .sidebar {
        visibility: visible;
        transition: transform 220ms ease;
    }
}





