/* Pfolio — brand theme: emerald + gold, ink text on mist. Space Grotesk
 * display, Inter body. See dev_docs/pfolio-brand-guidelines.html. */

:root {
    --nw-bg: #e7f3ed;          /* mist — faint emerald tint (moc default) */
    --nw-surface: #ffffff;     /* paper */
    --nw-surface-2: #f1f5f3;   /* inputs, subtle insets, progress track */
    --nw-border: #e2e8e5;      /* line */
    --nw-text: #0a1424;        /* ink */
    --nw-ink-soft: #33425c;
    --nw-muted: #6c7b93;       /* slate */
    --nw-slate-l: #94a3b5;     /* lighter slate — secondary captions */
    --nw-line-2: #eef2f0;      /* faint hairline inside cards */
    --nw-row-alt: #fbfcfc;     /* lot sub-row background */
    --nw-row-hover: #fafcfb;   /* asset / tx row hover */
    --nw-accent: #0fae84;      /* emerald */
    --nw-accent-ink: #0a8a68;  /* emerald deep — text on white */
    --nw-accent-soft: #e3f6ef; /* emerald wash — icon chips */
    --nw-accent-glow: rgba(15, 174, 132, .45); /* shadows/glows */
    --nw-accent-ring: rgba(15, 174, 132, .22); /* focus rings */
    --nw-accent-tint: rgba(15, 174, 132, .06); /* subtle hover fills */
    --nw-gold: #f2b53c;        /* accent: highlighted asset */
    --nw-green: #0fae84;
    --nw-red: #e0584e;
    --nw-red-soft: #fcedec;
    --nw-amber: #f2b53c;

    --nw-radius: 18px;
    --nw-radius-sm: 12px;
    --nw-shadow: 0 1px 2px rgba(10, 20, 36, .04), 0 14px 34px -18px rgba(10, 20, 36, .20);
    --nw-shadow-sm: 0 1px 2px rgba(10, 20, 36, .04), 0 8px 20px -14px rgba(10, 20, 36, .16);

    --nw-font-display: 'Space Grotesk', system-ui, sans-serif;

    /* Bootstrap variable hooks so its components inherit our look */
    --bs-body-font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
    --bs-body-color: var(--nw-text);
    --bs-border-color: var(--nw-border);
    --bs-primary: var(--nw-accent);
    --bs-link-color: var(--nw-accent-ink);
    --bs-link-hover-color: var(--nw-accent);
}

/* Colour themes — the five elements (Ngũ hành). 'moc' (wood/green) is the :root
   default; the others override the accent trio, which everything else derives from. */
html[data-theme="kim"]  { --nw-accent: #c79a3b; --nw-accent-ink: #a07d26; --nw-accent-soft: #f5edd9; --nw-accent-glow: rgba(199, 154, 59, .45); --nw-accent-ring: rgba(199, 154, 59, .22); --nw-accent-tint: rgba(199, 154, 59, .07); --nw-bg: #f4eee1; } /* metal · gold */
html[data-theme="thuy"] { --nw-accent: #2f80ed; --nw-accent-ink: #1c63c0; --nw-accent-soft: #e6eefc; --nw-accent-glow: rgba(47, 128, 237, .45); --nw-accent-ring: rgba(47, 128, 237, .22); --nw-accent-tint: rgba(47, 128, 237, .06); --nw-bg: #e6eef9; } /* water · blue */
html[data-theme="hoa"]  { --nw-accent: #e0564c; --nw-accent-ink: #bf3a31; --nw-accent-soft: #fdeae8; --nw-accent-glow: rgba(224, 86, 76, .45); --nw-accent-ring: rgba(224, 86, 76, .22); --nw-accent-tint: rgba(224, 86, 76, .06); --nw-bg: #f9ebe8; } /* fire · red */
html[data-theme="tho"]  { --nw-accent: #b27636; --nw-accent-ink: #8e5c26; --nw-accent-soft: #f4ebdf; --nw-accent-glow: rgba(178, 118, 54, .45); --nw-accent-ring: rgba(178, 118, 54, .22); --nw-accent-tint: rgba(178, 118, 54, .07); --nw-bg: #f3eadd; } /* earth · brown */

/* Dark mode — overrides the neutral tokens only; the accent trio still comes from
   the chosen Ngũ hành theme above (these blocks share specificity, and dark is
   ordered last, so its --nw-bg/surface win when both are set). Toggled via
   data-bs-theme, so Bootstrap's own components (modals, selects, dropdowns) go
   dark too. */
html[data-bs-theme="dark"] {
    --nw-bg: #0b111a;
    --nw-surface: #141c27;
    --nw-surface-2: #1d2733;
    --nw-border: #29343f;
    --nw-text: #e7edf4;
    --nw-ink-soft: #b4c1d0;
    --nw-muted: #8593a6;
    --nw-slate-l: #647084;
    --nw-line-2: #1a222d;
    --nw-row-alt: #171f2a;
    --nw-row-hover: rgba(255, 255, 255, .05);
    --nw-accent-soft: rgba(255, 255, 255, .06);
    --nw-red-soft: rgba(224, 88, 78, .16);
    --nw-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 34px -18px rgba(0, 0, 0, .65);
    --nw-shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 20px -14px rgba(0, 0, 0, .55);
}

* { -webkit-font-smoothing: antialiased; }

body {
    background: var(--nw-bg);
    color: var(--nw-text);
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
    font-weight: 500;
    min-height: 100vh;
    letter-spacing: -.005em;
}

h1, h2, h3, h4, h5, h6, .stat-value {
    font-family: var(--nw-font-display);
    font-weight: 700; letter-spacing: -.025em;
}

.text-muted-2 { color: var(--nw-muted) !important; }
.text-pos { color: var(--nw-green) !important; }
.text-neg { color: var(--nw-red) !important; }

a { text-decoration: none; }
.link-light { color: var(--nw-text) !important; font-weight: 600; }
.link-light:hover { color: var(--nw-accent-ink) !important; }
.link-secondary { color: var(--nw-muted) !important; }
.link-secondary.active { color: var(--nw-accent-ink) !important; }

/* ---- Cards ----------------------------------------------------------- */
.card {
    background: var(--nw-surface);
    border: 0;
    border-radius: var(--nw-radius);
    box-shadow: var(--nw-shadow);
}

/* ---- Buttons --------------------------------------------------------- */
.btn {
    --bs-btn-font-weight: 700;
    border-radius: var(--nw-radius-sm);
    font-weight: 700;
    letter-spacing: -.01em;
    padding: .55rem 1.15rem;
    transition: transform .06s ease, filter .15s ease, background-color .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { border-radius: 10px; padding: .4rem .7rem; }
/* Header language/currency selects: match the icon buttons' height (the custom
   .btn-sm padding above makes buttons taller than a default form-select-sm). */
.navbar .form-select-sm { padding-top: .4rem; padding-bottom: .4rem; }

.btn-brand,
.btn-brand:hover,
.btn-brand:focus,
.btn-brand:active,
.btn-brand:focus-visible {
    background-color: var(--nw-accent);
    border-color: var(--nw-accent);
    color: #fff;
}
.btn-brand:not(:disabled):hover { filter: brightness(1.05); box-shadow: 0 8px 22px var(--nw-accent-glow); }
.btn-brand:focus-visible { box-shadow: 0 0 0 .2rem var(--nw-accent-ring); }
.btn-brand:disabled, .btn-brand.disabled { opacity: .45; filter: none; cursor: not-allowed; }

/* Repurpose Bootstrap's outline-light as our neutral secondary button (white + hairline). */
.btn-outline-light,
.btn-outline-light:focus {
    background: var(--nw-surface);
    border-color: var(--nw-border);
    color: var(--nw-text);
}
.btn-outline-light:hover,
.btn-outline-light.active {
    background: var(--nw-surface-2);
    border-color: #dfe0e5;
    color: var(--nw-text);
}
.btn-outline-light.active { color: var(--nw-accent-ink); }

.btn-outline-danger {
    border-color: #f3c2c6;
    color: var(--nw-red);
}
.btn-outline-danger:hover { background: var(--nw-red); border-color: var(--nw-red); color: #fff; }

.btn-success { background: var(--nw-green); border-color: var(--nw-green); }

/* lang VI/EN segmented control */
.btn-group .btn-outline-secondary {
    background: var(--nw-surface);
    border-color: var(--nw-border);
    color: var(--nw-muted);
    font-weight: 700;
}
.btn-group .btn-outline-secondary.active,
.btn-group .btn-outline-secondary:hover { background: var(--nw-surface-2); color: var(--nw-text); }

/* ---- Forms ----------------------------------------------------------- */
.form-control, .form-select {
    background: var(--nw-surface-2);
    border: 1px solid transparent;
    border-radius: var(--nw-radius-sm);
    color: var(--nw-text);
    font-weight: 600;
    padding: .65rem .9rem;
}
.form-control::placeholder { color: #aab0b7; font-weight: 500; }
.form-control:focus, .form-select:focus {
    background: var(--nw-surface);
    color: var(--nw-text);
    border-color: var(--nw-accent);
    box-shadow: 0 0 0 .2rem var(--nw-accent-ring);
}
.form-label { font-weight: 700; font-size: .85rem; margin-bottom: .4rem; }
.form-text { font-weight: 500; }
.form-check-input:checked { background-color: var(--nw-accent); border-color: var(--nw-accent); }
.form-check-input:focus { box-shadow: 0 0 0 .2rem var(--nw-accent-ring); border-color: var(--nw-accent); }

/* ---- Navbar ---------------------------------------------------------- */
.navbar {
    background: var(--nw-surface);
    border-bottom: 1px solid var(--nw-border);
    /* The sticky header owns the top safe-area inset, so its background fills the
     * status-bar strip and its content sits below the clock/battery. */
    padding-top: calc(.65rem + env(safe-area-inset-top));
    padding-bottom: .65rem;
}
.brand { display: inline-flex; align-items: center; color: var(--nw-text); }

/* Integrated logotype: the donut-p mark IS the letter "p" in "pfolio". */
.logotype {
    font-family: var(--nw-font-display);
    font-weight: 700; font-size: 1.8rem; letter-spacing: -.04em; line-height: 1;
    color: var(--nw-text); white-space: nowrap;
}
.logotype .dp {
    display: inline-block; height: .78em; width: .63em;
    vertical-align: -.252em; margin-right: .035em;
}
.logotype .dp svg { display: block; width: 100%; height: 100%; overflow: visible; }
.logotype .dom { color: var(--nw-muted); font-weight: 500; letter-spacing: -.02em; }
.navbar .nav-link {
    color: var(--nw-muted);
    font-weight: 700;
    border-radius: 10px;
    padding: .45rem .85rem;
    margin: 0 .1rem;
}
.navbar .nav-link:hover { color: var(--nw-text); }
.navbar .nav-link.active { color: var(--nw-text); background: var(--nw-surface-2); }

/* ---- Stat cards ------------------------------------------------------ */
.stat-card .stat-label {
    color: var(--nw-muted);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.stat-card .stat-value { font-size: 1.95rem; line-height: 1.15; margin-top: .15rem; }
.stat-card .stat-value.stat-value-lg { font-size: 2.5rem; }
/* Thin rule between the stacked assets / debts figures. */
.stat-divider { height: 1px; background: var(--nw-border); margin: 16px 0; }

/* Total assets / debts under the net-worth chart — smaller than the net worth. */
.nw-breakdown {
    display: flex; gap: 20px;
    margin-top: 16px; padding-top: 14px;
    border-top: 1px solid var(--nw-border);
}
.nw-breakdown .nwb-item { flex: 1 1 0; min-width: 0; }
.nw-breakdown .nwb-value {
    font-family: var(--nw-font-display); font-weight: 700;
    font-size: 1.2rem; line-height: 1.15; letter-spacing: -.02em; margin-top: .1rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Allocation donut + its legend — stacked (donut on top, legend below) so it
   fits the narrow one-third column. */
.donut-layout { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.donut-chart { flex: none; line-height: 0; }
.donut-legend { width: 100%; display: flex; flex-direction: column; gap: 11px; }
.lg-row { display: flex; align-items: center; gap: 9px; font-size: .9rem; }
.lg-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.lg-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg-val { color: var(--nw-ink-soft); white-space: nowrap; font-weight: 600; }

/* Allocation as horizontal bars (one per category). */
.alloc-bars { display: flex; flex-direction: column; gap: 14px; }
.alloc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.alloc-name { font-weight: 600; font-size: .9rem; color: var(--nw-text);
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-val { color: var(--nw-muted); font-size: .82rem; font-weight: 600; white-space: nowrap; flex: none; }
/* When masked, right-align the dots so they sit next to " · %" — otherwise the
   value keeps its full ("… triệu") width and leaves a gap before the percent. */
.alloc-val .mask-num { text-align: right; }
.alloc-bar { height: 8px; border-radius: 5px; background: var(--nw-surface-2); overflow: hidden; }
.alloc-bar span { display: block; height: 100%; border-radius: 5px; transition: width .45s ease; }

/* change pills (1 day / 1 month) */
.chg { display: inline-flex; align-items: center; gap: .25rem; font-weight: 700; font-size: .78rem;
       padding: .12rem .5rem; border-radius: 999px; }
.chg-pos { background: var(--nw-accent-soft); color: var(--nw-accent-ink); }
.chg-neg { background: rgba(240, 97, 109, .12); color: var(--nw-red); }
.chg-flat { background: var(--nw-surface-2); color: var(--nw-muted); }
/* 1-day / 1-month change figures stacked (block), each on its own line. */
.nw-chg-row { display: flex; align-items: center; gap: 6px; }
.nw-chg-row + .nw-chg-row { margin-top: 4px; }

/* ---- Tables ---------------------------------------------------------- */
.table { --bs-table-bg: transparent; color: var(--nw-text); }
.table > thead th { color: var(--nw-muted); font-weight: 700; text-transform: uppercase;
                    font-size: .72rem; letter-spacing: .04em; border-bottom-color: var(--nw-border); }
.table > :not(caption) > * > * { border-bottom-color: var(--nw-border); padding: .85rem .75rem; }
/* Only the very last body closes without a divider — the table now has one
   <tbody> per section header / row-run / name-group, not a single body. */
.table > tbody:last-child > tr:last-child > * { border-bottom: 0; }

/* ---- Delete confirm + row icons -------------------------------------- */
.del-armed {
    background: var(--nw-red) !important; border-color: var(--nw-red) !important;
    color: #fff !important; font-weight: 700; white-space: nowrap;
}
.row-icon {
    width: 34px; height: 34px; border-radius: 9px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--nw-surface-2); color: var(--nw-accent-ink); font-size: 1rem;
    overflow: hidden;
}
/* Bank-account logo (VietQR) in place of the category icon. */
.row-icon.row-logo { background: #fff; border: 1px solid var(--nw-border); }
.row-icon.row-logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }

/* Offline Lucide icons, recoloured via CSS mask to inherit currentColor. */
.lic {
    display: inline-block; width: 1.2em; height: 1.2em; background: currentColor;
    -webkit-mask-position: center; mask-position: center;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-size: contain; mask-size: contain;
}
.lic-cash        { -webkit-mask-image: url(/img/icons/wallet.svg);       mask-image: url(/img/icons/wallet.svg); }
.lic-stock       { -webkit-mask-image: url(/img/icons/trending-up.svg);  mask-image: url(/img/icons/trending-up.svg); }
.lic-crypto      { -webkit-mask-image: url(/img/icons/bitcoin.svg);      mask-image: url(/img/icons/bitcoin.svg); }
.lic-real_estate { -webkit-mask-image: url(/img/icons/house.svg);        mask-image: url(/img/icons/house.svg); }
.lic-vehicle     { -webkit-mask-image: url(/img/icons/car.svg);          mask-image: url(/img/icons/car.svg); }
.lic-metal       { -webkit-mask-image: url(/img/icons/gem.svg);          mask-image: url(/img/icons/gem.svg); }
.lic-business    { -webkit-mask-image: url(/img/icons/briefcase.svg);    mask-image: url(/img/icons/briefcase.svg); }
.lic-other       { -webkit-mask-image: url(/img/icons/shapes.svg);       mask-image: url(/img/icons/shapes.svg); }
.lic-loan        { -webkit-mask-image: url(/img/icons/hand-coins.svg);   mask-image: url(/img/icons/hand-coins.svg); }
.lic-credit      { -webkit-mask-image: url(/img/icons/credit-card.svg);  mask-image: url(/img/icons/credit-card.svg); }

/* ===== Holdings (assets) — grid layout, category groups, nested lots ===== */
.num { font-family: var(--nw-font-display); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
/* On the assets page numbers use our regular body type (Inter), like before —
   only the category name keeps the display font. */
.holdings .num { font-family: 'Inter', system-ui, sans-serif; font-variant-numeric: normal; letter-spacing: -.005em; }

/* Toolbar: filter chips + search + sort */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
    border: 1px solid var(--nw-border); background: var(--nw-surface); color: var(--nw-ink-soft);
    font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 999px; cursor: pointer;
    transition: .15s; line-height: 1;
}
.chip:hover { border-color: var(--nw-accent); }
.chip.on { background: var(--nw-text); color: #fff; border-color: var(--nw-text); }

/* Category filter — Binance-style text tabs (no pill): grey → active is bold ink
   with an accent underline. A plain pencil on the right to configure them. */
.filter-row { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; }
.filter-bar {
    display: flex; gap: 18px; flex: 1 1 auto; min-width: 0;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-tab {
    flex: none; border: 0; background: none; cursor: pointer; white-space: nowrap;
    font-size: .82rem; font-weight: 600; color: var(--nw-muted); line-height: 1.2;
    padding: 4px 0 8px; position: relative; transition: color .15s;
}
.filter-tab:hover { color: var(--nw-ink-soft); }
.filter-tab.on { color: var(--nw-text); font-weight: 700; }
.filter-tab.on::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: 2px; height: 2.5px;
    border-radius: 2px; background: var(--nw-accent);
}
.filter-edit {
    flex: none; border: 0; background: none; color: var(--nw-muted); padding: 4px 2px;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
}
.filter-edit:hover { color: var(--nw-accent-ink); }

/* Filter-edit modal rows (reorder + show/hide). */
.fe-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--nw-border); }
.fe-row:last-child { border-bottom: 0; }
.fe-moves { display: inline-flex; gap: 4px; flex: none; }
.fe-move {
    width: 30px; height: 30px; border-radius: 8px; color: var(--nw-ink-soft);
    border: 1px solid var(--nw-border); background: var(--nw-surface);
    display: inline-flex; align-items: center; justify-content: center;
}
.fe-move:active { transform: scale(.94); }
.fe-label { font-weight: 600; }
.search {
    margin-left: auto; display: flex; align-items: center; gap: 8px; border: 1px solid var(--nw-border);
    background: var(--nw-surface); border-radius: 10px; padding: 8px 12px; min-width: 210px;
}
.search i { color: var(--nw-muted); flex: none; }
.search input { border: 0; outline: 0; font: inherit; font-size: 14px; width: 100%; background: transparent; color: var(--nw-text); }
/* Search takes the full width on phones. */
@media (max-width: 820px) {
    .toolbar .search { flex: 1 1 100%; margin-left: 0; }
}

/* Sort control lives in the "Value" column header (DataTable-style). */
.colhead .sort-th {
    display: flex; align-items: center; justify-content: flex-end; gap: 5px;
    cursor: pointer; user-select: none;
}
.colhead .sort-th:hover { color: var(--nw-text); }
.colhead .sort-th .bi { font-size: .95em; }

/* Small usage hint above the table. */
.holdings-hint {
    display: flex; align-items: center; gap: 7px; color: var(--nw-muted);
    font-size: .8rem; margin: 0 2px 8px;
}
.holdings-hint .bi { color: var(--nw-accent); flex: none; }

/* Tap affordance: whole item row is clickable → detail modal. */
.arow[data-id] { cursor: pointer; }
.row-chev { color: var(--nw-slate-l); font-size: .9rem; }

/* Asset detail modal: label / value rows. */
.dt-row {
    display: flex; justify-content: space-between; gap: 16px;
    padding: 11px 0; border-bottom: 1px solid var(--nw-line-2);
}
.dt-row:last-child { border-bottom: 0; }
.dt-k { color: var(--nw-muted); font-size: .85rem; flex: none; }
.dt-v { font-weight: 600; text-align: right; word-break: break-word; min-width: 0; }
/* Stacked (block) value — e.g. the two weight figures on their own lines. */
.dt-multi { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
#detail-sub:empty { display: none; }

/* Keep top-aligned modals clear of the status bar / home indicator in the app
 * (Bootstrap's .5rem mobile margin sits under the notch otherwise). */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin-top: calc(.5rem + env(safe-area-inset-top));
        margin-bottom: calc(.5rem + env(safe-area-inset-bottom));
    }
}

/* Transactions: slightly smaller figures + tappable rows (detail on tap). */
#tx-content .stat-value { font-size: 1.45rem; }
/* Month income / expense / net in one card. Mobile: three divided rows (label
   left, figure right). Desktop: three inline columns on a single row. */
.tx-sum-head { margin-bottom: 9px; }
.tx-month-badge {
    display: inline-flex; align-items: center; gap: 6px; line-height: 1;
    font-family: var(--nw-font-display); font-size: .9rem; font-weight: 700;
    letter-spacing: -.01em; color: var(--nw-text);
}
.tx-month-badge .bi { font-size: .95em; color: var(--nw-muted); }
.tx-summary { display: flex; flex-direction: column; }
.tx-sum-item {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 9px 0;
}
.tx-sum-item:first-child { padding-top: 0; }
.tx-sum-item:last-child { padding-bottom: 0; }
.tx-sum-item + .tx-sum-item { border-top: 1px solid var(--nw-border); }
.tx-sum-item > .text-muted-2 { flex: none; }
/* Match the transaction-list figures below (0.9rem) rather than a big stat number. */
.tx-summary .tx-sum-val {
    font-family: 'Inter', system-ui, sans-serif; font-weight: 700;
    font-size: .9rem; line-height: 1.2; letter-spacing: -.005em; text-align: right;
}
.tx-summary .sum-detail { font-size: .68rem; }

@media (min-width: 768px) {
    .tx-summary { flex-direction: row; }
    .tx-sum-item { display: block; flex: 1 1 0; min-width: 0; padding: 0 18px; }
    .tx-sum-item:first-child { padding-left: 0; }
    .tx-sum-item:last-child { padding-right: 0; }
    .tx-sum-item + .tx-sum-item { border-top: 0; border-left: 1px solid var(--nw-border); }
    .tx-summary .tx-sum-val { text-align: left; }
}
#tx-content .table td { font-size: .9rem; }
/* Line the masked values in the recurring / history tables up with the
   "This month" summary card (which uses p-3 = 1rem). The table cells default to
   .75rem, so pad the value column to 1rem — every masked value below shares the
   same right edge as income/expense. */
#tx-content .table td:last-child { padding-right: 1rem; }
.tx-row { cursor: pointer; }
.tx-row:hover td { background: var(--nw-row-hover); }
/* "Show all" toggle under the collapsed recurring list — a full-width, link-like
   footer button. */
.recur-showall {
    display: block; width: 100%; border: 0; background: transparent;
    padding: 11px; color: var(--nw-accent-ink); font-weight: 600; font-size: .85rem;
    cursor: pointer; border-top: 1px solid var(--nw-border);
}
.recur-showall:hover { background: var(--nw-surface-2); }
/* Fixed-cost badge in the recurring card header (monthly-normalised total). */
.recur-badge { font-size: .82rem; font-weight: 600; color: var(--nw-muted); white-space: nowrap; }
/* Right-align the masked dots so they line up with the value column below,
   instead of sitting at the left of the (wider) "$409/mo" box. */
.recur-badge .mask-num { color: var(--nw-ink-soft); text-align: right; }
.recur-badge:empty { display: none; }
/* Windows renders the generic left:0/right:0 mask dots with sub-pixel jitter
   that shifts with the value's width — a wide value (e.g. a large salary)
   pushes its dots past the column, misaligning rows. Anchor the dots to the
   right edge in every right-aligned masked context here so all rows line up.
   (Same fix as the dashboard's #top-items / .alloc-val.) */
body.vals-masked #tx-content .text-end .mask-num::after,
body.vals-masked .recur-badge .mask-num::after {
    left: auto; right: 0; text-align: right;
}
@media (max-width: 767.98px) {
    body.vals-masked .tx-sum-val .mask-num::after { left: auto; right: 0; text-align: right; }
}
/* Phones stack recurring + history (recurring collapsed to 3 rows above). On
   desktop they sit side by side 50/50, and the recurring list shows in full. */
.tx-cols { display: flex; flex-direction: column; gap: 1.5rem; }
@media (min-width: 992px) {
    .tx-cols { flex-direction: row; align-items: flex-start; }
    .tx-cols > .card { flex: 1 1 0; min-width: 0; margin-bottom: 0; }
    #recurring-list .recur-more { display: table-row !important; }
    #recurring-list .recur-toggle { display: none !important; }
}
/* Compact monthly figure + a small, dim exact amount below it. */
.sum-detail {
    display: block; margin-top: 1px;
    font-family: var(--bs-body-font-family); font-size: .72rem; font-weight: 500;
    letter-spacing: 0; color: var(--nw-muted);
}
body.vals-masked .sum-detail { display: none; }

.holdings { background: var(--nw-surface); border: 1px solid var(--nw-border); border-radius: 16px; box-shadow: var(--nw-shadow); overflow: hidden; }
.colhead, .arow, .cat {
    display: grid;
    grid-template-columns: minmax(200px, 1.6fr) 150px 175px 140px 70px;
    align-items: center;
}
.colhead {
    padding: 13px 22px; border-bottom: 1px solid var(--nw-border);
    font-size: .72rem; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--nw-muted);
}
.colhead .r { text-align: right; }
/* Align the "Name" header with the asset names below it (34px icon + 12px gap). */
.colhead > span:first-child { padding-left: 46px; }

.group { border-bottom: 1px solid var(--nw-border); }
.group:last-child { border-bottom: 0; }
.group.collapsed .arow { display: none; }

.cat { padding: 14px 22px; background: var(--nw-line-2); cursor: pointer; user-select: none; }
/* gap 12px + a 34px caret slot (= asset icon width + gap) so the category name
   lines up exactly with the asset names below it. */
.cat .nmwrap { display: flex; align-items: center; gap: 12px; min-width: 0; }
.caret {
    flex: none; width: 34px; height: 34px; color: var(--nw-muted); font-size: 1.05rem;
    display: inline-flex; align-items: center; justify-content: center;
}
.caret .cr-closed { display: none; }
.group.collapsed .caret .cr-open { display: none; }
.group.collapsed .caret .cr-closed { display: inline-block; }
.cat .cname { font-family: var(--nw-font-display); font-weight: 700; font-size: .98rem; letter-spacing: -.01em; }
.cat .count {
    font-size: .72rem; font-weight: 700; color: var(--nw-muted); background: var(--nw-surface);
    border: 1px solid var(--nw-border); border-radius: 999px; padding: 1px 8px;
}
.cat .csub { font-weight: 700; font-size: .98rem; text-align: right; }
.cat .cw { text-align: right; font-weight: 600; font-size: .8rem; color: var(--nw-ink-soft); }
.cat .cwbar { height: 5px; border-radius: 3px; background: var(--nw-border); overflow: hidden; margin-top: 5px; }
.cat .cwbar span { display: block; height: 100%; border-radius: 3px; }

.arow { padding: 13px 22px; border-top: 1px solid var(--nw-line-2); transition: background .12s; }
.arow:hover { background: var(--nw-row-hover); }
.arow .name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.aic {
    width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    flex: none; overflow: hidden; background: var(--nw-accent-soft); color: var(--nw-accent-ink);
}
/* Logo images fill the circle; line-glyphs stay smaller so the ring doesn't clip their corners. */
.aic .lic { width: 58%; height: 58%; }
.aic.row-logo, .aic.asset-chip { background: #fff; border: 1px solid var(--nw-border); }
.aic.row-logo img, .aic.asset-chip img { width: 100%; height: 100%; object-fit: contain; padding: 0; }
/* Monogram fallback: ticker initials on a category-tinted chip. */
.aic.mono { font-family: var(--nw-font-display); font-weight: 700; font-size: .6rem;
    letter-spacing: -.02em; line-height: 1; }
.nm { min-width: 0; }
.nm .t { font-size: .95rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; align-items: center; gap: 5px; }
.nm .s { font-size: .82rem; color: var(--nw-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.price { text-align: right; }
.price .p { font-weight: 500; font-size: .9rem; color: var(--nw-ink-soft); }
.price .q { font-size: .74rem; color: var(--nw-slate-l); }
.val { text-align: right; }
.val .v { font-weight: 600; font-size: .95rem; }
.val .c { font-size: .8rem; font-weight: 500; color: var(--nw-muted); }
/* Tap-to-edit quantity (crypto/stock native line): accent colour + a clearly
   visible dashed underline so it reads as editable. (.val .c sets the muted
   colour, so match its specificity to override.) */
.val .qty-edit {
    display: inline-block;   /* hug the number so the underline sits flush right */
    cursor: pointer; color: var(--nw-accent-ink);
    /* border-bottom (not text-decoration) so the dashed line spans the full number
       width without the last dash being clipped. */
    border-bottom: 1px dashed var(--nw-accent-ink); padding-bottom: 1px;
    text-decoration: none;
}
.val .qty-edit.editing { border-bottom: 0; padding-bottom: 0; }
.qty-input {
    width: 90px; max-width: 100%; text-align: right; font: inherit;
    padding: 1px 5px; border: 1px solid var(--nw-accent); border-radius: 6px;
    background: var(--nw-surface); color: var(--nw-text); outline: none;
}

/* "Fetching price…" state: a just-added instrument whose price the crawler
   hasn't filled in yet. Shown instead of a misleading quantity-as-value. */
.price .p.pending { display: inline-flex; align-items: center; gap: 6px;
    color: var(--nw-slate-l); font-weight: 500; white-space: nowrap; }
.price .p.pending .pdot { width: 7px; height: 7px; border-radius: 50%;
    background: var(--nw-accent-ink); animation: pdot 1s ease-in-out infinite; }
@keyframes pdot { 0%, 100% { opacity: .3; transform: scale(.75); } 50% { opacity: 1; transform: scale(1); } }
.val .v.pending { color: var(--nw-slate-l); font-weight: 500; }
/* Brief tint when a background refresh moves a value (the count-up runs in JS). */
.val .v.bump, .cat .csub.bump { animation: valbump .8s ease; }
@keyframes valbump { 0% { color: var(--nw-accent-ink); } 100% { color: inherit; } }
@media (prefers-reduced-motion: reduce) {
    .price .p.pending .pdot { animation: none; }
    .val .v.bump, .cat .csub.bump { animation: none; }
}

/* Hide-balance toggle (eye button, in the navbar) + masked state. Dots out the
   amounts that reveal holdings (values, subtotals, quantities) across every page;
   market price and %-weight stay visible for context. Persists in localStorage. */
#mask-btn .eye-off { display: none; }
body.vals-masked #mask-btn .eye-on { display: none; }
body.vals-masked #mask-btn .eye-off { display: inline-block; }

body.vals-masked .mask-num { color: transparent !important; position: relative; }
body.vals-masked .mask-num::after {
    /* Span the cell and inherit its text-align so the dots sit where the number
       did — right in tables, left/centre in stat cards. */
    content: "••••"; position: absolute; left: 0; right: 0; top: 50%;
    transform: translateY(-50%); text-align: inherit; white-space: nowrap;
    color: var(--nw-ink-soft); letter-spacing: .1em; font-weight: 600; pointer-events: none;
    -webkit-user-select: none; user-select: none;
}
/* Chart tooltip sits on a dark background — keep its masked dots readable. */
/* Reserve the chart + change-figures height: both are filled after an async
   history load, so without this they're 0-high when content appears and then jump
   when they land (a visible jerk under the net-worth figure). */
#nw-chart { min-height: 150px; }
#nw-change { min-height: 2.4rem; }

/* Expand toggle next to the (compact) net-worth figure — tap to show the full amount. */
.nw-expand {
    flex: none; border: 0; background: transparent; padding: 3px; line-height: 1;
    color: var(--nw-muted); cursor: pointer; border-radius: 7px;
    display: inline-flex; align-items: center; font-size: .8rem;
}
.nw-expand:hover { color: var(--nw-accent-ink); background: rgba(148, 163, 184, .14); }
.nw-expand.open { color: var(--nw-accent-ink); }
.nw-expand .bi { transition: transform .15s ease; }
.nw-expand.open .bi { transform: rotate(180deg); }
/* Nothing to expand while values are hidden. */
body.vals-masked .nw-expand { display: none; }
/* Hide the "·" separator before the %-weight when the value is dotted out. */
body.vals-masked .alloc-sep { display: none; }
/* Assets rows: while masked, show a single dotted value per row — drop the native
   quantity line (and its editable underline), which would just be a second "…". */
body.vals-masked .val .c { display: none; }
/* Nested lots while masked: keep only the first letter of the wallet label (so the
   lots stay distinguishable), dot out the rest of the name, and drop the quantity
   sub-line — the value cell already shows the dotted amount. */
body.vals-masked .arow.lot .lot-rest { display: none; }
body.vals-masked .arow.lot .lot-name::after {
    content: "•••"; margin-left: 6px; color: var(--nw-muted);
    letter-spacing: .15em; font-weight: 600;
    -webkit-user-select: none; user-select: none;
}
/* Any sub-line that is a native quantity (lot amount, gold "2 lượng", foreign
   cash "$100") leaks value → hide it while masked. */
body.vals-masked .nm .s-qty { display: none; }
/* The "· qty unit" tag beside a code is a quantity → hide it while masked. Higher
   specificity than the phone show-rule so it wins when both apply. */
body.vals-masked .arow.priced .qtag { display: none; }
.vals-masked #nw-chart .t .mask-num::after { color: #fff; }
/* Biggest-holdings list: hide the secondary native-amount line when masked, so a
   single-unit row doesn't show a redundant second row of dots under the value. */
body.vals-masked #top-items .text-end > div.mask-num { display: none; }
/* The generic mask ::after spans the (variable-width) transparent value with
   text-align:right; on Windows that right-aligns with sub-pixel jitter, so the
   dots wobble left/right between rows. In this right-aligned list, anchor the
   dots to the right edge (fixed width) so every row lines up exactly. */
body.vals-masked #top-items .top-val .mask-num::after { left: auto; right: 0; text-align: right; }
/* Allocation rows: the %-weight stays visible after the dotted value, but its
   width varies (67.1% vs 2.8%), which shoved the dots out of line. Give the % a
   fixed right-aligned slot and anchor the dots to the right, so both columns line
   up across rows. */
body.vals-masked .alloc-val .mask-num::after { left: auto; right: 0; text-align: right; }
body.vals-masked .alloc-pct { display: inline-block; min-width: 3.6em; text-align: right; }
/* Compact %-weight line inside the value cell — only used on phones, where the
   standalone weight column is hidden. Desktop keeps the dedicated column. */
.wpct { display: none; font-size: .72rem; font-weight: 600; color: var(--nw-muted); margin-top: 2px; }
/* Phone-only pieces of a priced row: the "· qty unit" tag next to the code and
   the per-unit price shown as the sub. Hidden on desktop (which keeps the Price
   column + quantity line); toggled on under the phone media query below. */
.qtag { display: none; color: var(--nw-muted); font-weight: 500; font-size: .9em; }
/* Tap-to-edit quantity shown in the name column — the "· qty" tag beside a code
   and a lot's amount under its label — gets the accent colour + dashed underline
   (only the number), matching the desktop value line. */
.nm .qty-edit {
    cursor: pointer; color: var(--nw-accent-ink);
    border-bottom: 1px dashed var(--nw-accent-ink); padding-bottom: 1px;
}
.nm .qty-edit.editing { border-bottom: 0; padding-bottom: 0; }
/* A lot's amount line and a priced row's title ("CODE · qty") are short, so let
   them show the editable-quantity dashed underline instead of clipping it under
   `.s`/`.t`'s overflow:hidden (only there — long non-priced names still ellipsis). */
.arow.lot .nm .s { overflow: visible; }
.arow.priced .nm .t { overflow: visible; }
.s-price { display: none; }
.weight { text-align: right; padding-left: 10px; }
.weight .pct { font-weight: 500; font-size: .85rem; color: var(--nw-ink-soft); }
.weight .wbar { height: 5px; border-radius: 3px; background: var(--nw-border); overflow: hidden; margin-top: 5px; }
.weight .wbar span { display: block; height: 100%; border-radius: 3px; }
.acts { display: flex; gap: 6px; justify-content: flex-end; }
.act {
    width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--nw-border); background: var(--nw-surface);
    display: flex; align-items: center; justify-content: center; color: var(--nw-muted); cursor: pointer; padding: 0;
}
.act:hover { color: var(--nw-text); border-color: var(--nw-ink-soft); }
.act.del:hover { color: var(--nw-red); border-color: var(--nw-red); background: var(--nw-red-soft); }
.act .bi { font-size: 14px; line-height: 1; }
.act.del-armed { background: var(--nw-red); border-color: var(--nw-red); color: #fff; width: auto; padding: 0 10px;
    font-size: 12px; font-weight: 700; white-space: nowrap; gap: 5px; }

/* Nested lot rows (same-name holdings under a parent). */
/* Lots line up under the parent's name; a tree connector (│ ├─ └─) drawn in the
   icon column shows they belong to the parent. */
.arow.lot .name { padding-left: 46px; position: relative; }
.arow.lot { background: var(--nw-row-alt); }
.arow.lot .nm .t { font-weight: 500; color: var(--nw-ink-soft); font-size: .9rem; }
.arow.lot .name::before,
.arow.lot .name::after { content: ""; position: absolute; left: 16px; background: var(--nw-border); }
.arow.lot .name::before { top: 0; bottom: 0; width: 1.5px; }               /* vertical rail */
.arow.lot .name::after  { top: 50%; width: 15px; height: 1.5px; }          /* branch to the row */
.arow.lot.lot-last .name::before { bottom: 50%; }                          /* corner └ on the last lot */
/* Stub from the (open) parent's icon down to the first lot, closing the tree. */
.arow.parent .name { cursor: pointer; position: relative; }
.arow.parent:not(.closed) .name::after {
    content: ""; position: absolute; left: 16px; top: calc(50% + 17px); bottom: -1px;
    width: 1.5px; background: var(--nw-border);
}
.lotcaret { color: var(--nw-slate-l); font-size: 12px; transition: transform .2s; margin-left: 2px; }
.arow.parent.closed .lotcaret { transform: rotate(-90deg); }
.arow.parent.closed ~ .arow.lot { display: none; }

/* A fund nested under its management-company parent: unlike a plain lot it keeps
   its own logo + a readable code, with a small indent for the nested feel. */
.arow.lot.fund-child .name { padding-left: 22px; }
.arow.lot.fund-child .name::before,
.arow.lot.fund-child .name::after { display: none; }
.arow.lot.fund-child .nm .t { font-weight: 600; color: var(--nw-text); font-size: .95rem; }

/* Market widget: a country-local quote (SJC gold, bank USD) as a compact second
   line in the row's right column, aligned with the left sub-label. */
.mkt-local { font-size: .72rem; color: var(--nw-ink-soft); white-space: nowrap; margin-top: 1px; }
.mkt-local .mkt-local-name { font-weight: 600; }

/* Debt group accent */
.group.debt .val .v { color: var(--nw-red); }

/* Footer note */
.holdings-foot { margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 8px;
    color: var(--nw-muted); font-size: 12.5px; }
.holdings-foot .bi { color: var(--nw-accent); }

@media (max-width: 820px) {
    /* Name shrinks (minmax 0 → can ellipsis); value + actions stay fixed so the
       value column lines up between rows and section subtotals, and nothing is
       clipped by the card's overflow:hidden. A trimmer value column + gap give
       the name more room on phones so it ellipsis on ONE line instead of
       wrapping or being clipped mid-word. */
    /* Two columns only — drop the trailing chevron/action cell to save width. */
    .colhead, .arow, .cat { grid-template-columns: minmax(0, 1fr) 100px; column-gap: 8px; }
    .colhead .c-price, .price, .cat .cw, .weight, .colhead .c-w { display: none; }
    .arow .acts, .colhead > span:last-child, .cat > span:last-child { display: none; }
    /* The weight column is hidden here, so surface the %-weight as a line under
       the value instead (order: value → % → quantity). Non-sensitive → stays
       visible while masked. */
    .val .wpct { display: block; }
    /* Priced rows (crypto/stock/by-weight metal): compact phone layout — the
       "· qty unit" tag rides next to the code, the per-unit price becomes the
       sub, and the value cell drops its quantity line (now in the tag). */
    .arow.priced .qtag { display: inline; }
    .arow.priced .nm .s-info { display: none; }
    .arow.priced .nm .s-price { display: inline; }
    .arow.priced .val .c { display: none; }
    /* Full-width holdings on phones: drop the card chrome and bleed to the screen
       edges so the list uses the whole width. */
    .holdings {
        border-radius: 0; border-left: 0; border-right: 0; box-shadow: none;
        margin-left: calc(var(--bs-gutter-x, 1.5rem) * -.5);
        margin-right: calc(var(--bs-gutter-x, 1.5rem) * -.5);
    }
    .arow.lot .name { padding-left: 46px; }
    /* Section header title: keep it on one line; the count badge stays adjacent. */
    .cat .cname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
    .cat .count { flex: none; }
    /* Compact primary action so it doesn't dwarf the page title. */
    #add-btn { padding: .5rem .85rem; font-size: .9rem; }
}
@media (max-width: 520px) {
    .colhead, .arow, .cat { padding-left: 14px; padding-right: 14px; }
    .val .v { font-size: .9rem; }
    .cat .cname { font-size: .92rem; }
}

/* ---- Badges ---------------------------------------------------------- */
.badge { font-weight: 700; border-radius: 8px; padding: .35em .6em; }
.badge.text-bg-secondary { background: var(--nw-surface-2) !important; color: var(--nw-muted) !important; }
.badge.text-bg-danger { background: rgba(240, 97, 109, .12) !important; color: var(--nw-red) !important; }

/* ---- Progress -------------------------------------------------------- */
.progress { background: var(--nw-surface-2) !important; border-radius: 999px; }
.progress-bar { border-radius: 999px; }

/* ---- Alerts ---------------------------------------------------------- */
.alert { border: 0; border-radius: var(--nw-radius-sm); font-weight: 600; }
.alert-danger { background: rgba(240, 97, 109, .1); color: #c0414d; }
.alert-success { background: rgba(47, 176, 152, .12); color: #157d6c; }
.alert-brand { background: var(--nw-accent-soft); color: var(--nw-accent-ink); }
.alert-warning { background: rgba(255, 178, 62, .15); color: #9a6b16; }

/* Dark: brighten alert text/fills so they stay legible on the dark surface. */
html[data-bs-theme="dark"] .alert-danger  { background: rgba(240, 97, 109, .16); color: #f3a6ab; }
html[data-bs-theme="dark"] .alert-success { background: rgba(47, 176, 152, .16); color: #7ed9c6; }
html[data-bs-theme="dark"] .alert-warning { background: rgba(255, 178, 62, .18); color: #f0c579; }
html[data-bs-theme="dark"] .alert-brand   { color: var(--nw-accent); }

/* ---- Modal ----------------------------------------------------------- */
.modal-content { border: 0 !important; border-radius: var(--nw-radius); box-shadow: var(--nw-shadow); }
.modal-header, .modal-footer { border-color: var(--nw-border) !important; }

/* ---- Auth screens ---------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
    background:
        radial-gradient(900px 500px at 85% -10%, var(--nw-accent-tint), transparent 60%),
        var(--nw-bg); }
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--nw-surface);
    border: 0;
    border-radius: var(--nw-radius);
    padding: 2rem;
    box-shadow: var(--nw-shadow);
}

.recovery-key {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1rem; letter-spacing: .03em; word-break: break-all;
    background: var(--nw-surface-2);
    border: 1px dashed #d9dade;
    border-radius: var(--nw-radius-sm);
    padding: 1rem; color: var(--nw-text);
}

/* ---- Asset type picker tiles ----------------------------------------- */
.asset-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; }
@media (max-width: 680px) { .asset-tiles { grid-template-columns: repeat(2, 1fr); } }
.asset-tile {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    text-align: center;
    padding: 1.1rem .9rem;
    min-height: 84px;
    background: var(--nw-surface);
    border: 1px solid var(--nw-border);
    border-radius: var(--nw-radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease, transform .08s ease, box-shadow .12s ease;
}
.asset-tile:hover {
    border-color: var(--nw-accent);
    background: var(--nw-accent-tint);
    transform: translateY(-1px);
    box-shadow: var(--nw-shadow-sm);
}
/* Category glyph becomes a faint watermark filling the tile; no chip background. */
.asset-tile .ti-icon {
    position: absolute; inset: 0; z-index: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--nw-accent-ink); opacity: .08;
    pointer-events: none;
}
.asset-tile .ti-icon .lic { width: 60%; height: 60%; }
.asset-tile:hover .ti-icon { opacity: .14; }
/* Label sits centred on top of the watermark. */
.asset-tile .ti-label { position: relative; z-index: 1; font-weight: 700; line-height: 1.2; }

/* ---- Crypto coin tiles ----------------------------------------------- */
/* Cap the height so long result lists scroll inside the modal, not the page. */
.coin-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem;
    max-height: 56vh; overflow-y: auto; padding: 2px; }
@media (max-width: 680px) { .coin-tiles { grid-template-columns: repeat(2, 1fr); } }
.coin-tile {
    display: flex; flex-direction: column;
    min-width: 0;             /* let long names ellipsis instead of stretching the grid */
    min-height: 92px;
    text-align: left;
    padding: .85rem .9rem;
    background: var(--nw-surface);
    border: 1px solid var(--nw-border);
    border-radius: var(--nw-radius-sm);
    cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease, transform .08s ease, box-shadow .12s ease;
}
.coin-tile:hover { border-color: var(--nw-accent); background: var(--nw-accent-tint); transform: translateY(-1px); box-shadow: var(--nw-shadow-sm); }
.coin-tile .aic { margin-bottom: .5rem; }
.coin-tile .c-sym, .coin-tile .c-name, .coin-tile .c-meta {
    max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coin-tile .c-sym { font-weight: 800; letter-spacing: -.01em; }
.coin-tile .c-name { color: var(--nw-muted); font-size: .82rem; font-weight: 600; }
.coin-tile .c-price { margin-top: auto; padding-top: .5rem; font-weight: 700; font-size: .9rem; }
.coin-tile .c-meta { color: var(--nw-muted); font-size: .72rem; margin-top: .35rem; }
.coin-loading {
    display: flex; align-items: center; justify-content: center; gap: .55rem;
    padding: 2.5rem 1rem; color: var(--nw-muted); font-weight: 600;
}
.coin-loading .spinner-border { color: var(--nw-accent); }

/* ---- Bank tiles ------------------------------------------------------ */
.bank-tiles {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem;
    max-height: 46vh; overflow-y: auto; padding-right: .2rem;
}
@media (max-width: 680px) { .bank-tiles { grid-template-columns: repeat(2, 1fr); } }
.bank-tile {
    display: flex; align-items: center; gap: .65rem;
    padding: .6rem .7rem;
    background: var(--nw-surface);
    border: 1px solid var(--nw-border);
    border-radius: var(--nw-radius-sm);
    cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease, transform .08s ease, box-shadow .12s ease;
}
.bank-tile:hover { border-color: var(--nw-accent); background: var(--nw-accent-tint); transform: translateY(-1px); box-shadow: var(--nw-shadow-sm); }
.bank-tile img {
    width: 40px; height: 28px; object-fit: contain; flex: 0 0 40px;
    border-radius: 5px; background: #fff;
}
.bank-tile .b-name { font-weight: 700; font-size: .84rem; line-height: 1.15;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bank-loading {
    display: flex; align-items: center; justify-content: center; gap: .55rem;
    padding: 2.5rem 1rem; color: var(--nw-muted); font-weight: 600; grid-column: 1 / -1;
}
.bank-loading .spinner-border { color: var(--nw-accent); }

/* ---- Misc ------------------------------------------------------------ */
.busy { opacity: .6; pointer-events: none; }
.empty-state { text-align: center; color: var(--nw-muted); padding: 3rem 1rem; font-weight: 600; }
hr { border-color: var(--nw-border) !important; opacity: 1; }

/* ---- Read-only demo mode -------------------------------------------- */
/* Full-width bar shown below the navbar while previewing sample data. */
.demo-banner {
    background: var(--nw-accent);
    color: #fff;
}
.demo-banner .demo-banner-msg { font-weight: 600; }
.demo-banner .btn-light { font-weight: 600; }

/* Hide every create/edit/delete affordance while in demo mode so the
   preview is strictly read-only (writes are also blocked in JS). */
body.demo-mode #add-btn,
body.demo-mode #add-tx,
body.demo-mode .edit,
body.demo-mode .del,
body.demo-mode #demo-cta,
body.demo-mode .verify-banner,
body.demo-mode .sec-grip {
    display: none !important;
}

/* ===== Mobile / Capacitor webview smoothness ==============================
 * Progressive enhancements: they also polish the web/PWA and degrade
 * gracefully where unsupported (older engines simply ignore them). */

/* Paint the app background (never white) during any load or navigation so a
 * full-page reload flashes the theme colour instead of a jarring white frame. */
html { background: var(--nw-bg); }

/* View transitions disabled: with Turbo, the new snapshot is captured while the
 * page is still the empty shell (content is rendered by JS afterwards), so the
 * cross-fade blinked to the shell before data appeared. Instant swap feels better. */
@view-transition { navigation: none; }

/* No rubber-band overscroll — feels like an app, not a scrolling web page. */
html, body { overscroll-behavior: none; }

/* Respect the notch in landscape (layout already sets viewport-fit=cover). The
 * TOP inset is owned by the sticky navbar, the BOTTOM inset by the tab bar, so
 * only the horizontal insets go on the body here. */
@supports (padding: max(0px, env(safe-area-inset-left))) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ===== Mobile bottom tab bar ============================================
 * Primary navigation on phones — fixed at the bottom like native apps, above
 * the home indicator. The top navbar keeps brand + currency/language/lock. */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1030;
    display: flex;
    background: var(--nw-surface);
    border-top: 1px solid var(--nw-border);
    border-radius: 18px 18px 0 0; /* softly rounded top corners */
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 16px -10px rgba(10, 20, 36, .3);
}
.tabbar .tab {
    flex: 1 1 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    padding: 13px 0 6px;
    color: var(--nw-muted);
    font-size: .66rem; font-weight: 600; letter-spacing: -.01em;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    /* .tab-cam is a <button> — strip the native control chrome (grey box). */
    background: none; border: 0; appearance: none; -webkit-appearance: none;
    font-family: inherit; cursor: pointer;
}
.tabbar .tab i { font-size: 1.3rem; line-height: 1; }
.tabbar .tab.active { color: var(--nw-accent-ink); }

/* Keep page content clear of the fixed tab bar. */
@media (max-width: 991.98px) {
    body:has(.tabbar) { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}

/* ===== Native Face ID app-lock overlay (see public/js/app/applock.js) ======
 * Only rendered inside the packaged app; the .app-locked class covers the
 * screen (also protects the app-switcher snapshot) until biometry passes. */
#app-lock {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    /* Frosted: blur whatever's behind (the login form) so Face ID works on a clean,
       professional backdrop instead of the busy login screen. */
    background: rgba(240, 243, 241, .72);
    -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html.app-locked #app-lock { display: flex; }
/* Dark: swap the frosted backdrop to a dark tint so the (now-light) title/labels
   inside stay readable — they use --nw-text/--nw-muted which are light in dark. */
html[data-bs-theme="dark"] #app-lock { background: rgba(11, 17, 26, .72); }
/* While Face ID runs / the app loads, drop the title for a clean screen. */
#app-lock.al-working .al-title { display: none; }
#app-lock .al-inner { text-align: center; }
#app-lock .al-logo {
    width: 96px; height: 96px; margin: 0 auto 20px;
    background: center / contain no-repeat url('/favicon.svg');
}
#app-lock .al-title {
    font-family: var(--nw-font-display);
    font-weight: 700; font-size: 1.15rem; color: var(--nw-text);
    margin-bottom: 20px;
}
/* "Use passphrase" fallback: quiet text link, no Bootstrap underline. */
#app-lock #al-pass {
    color: var(--nw-muted); text-decoration: none;
    font-weight: 600; font-size: .9rem;
}
#app-lock #al-pass:hover, #app-lock #al-pass:focus { color: var(--nw-text); text-decoration: none; }
/* "Unlocking…" state shown while the key is derived (replaces the buttons). */
#app-lock .al-busy { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--nw-muted); font-weight: 600; }
#app-lock .al-busy[hidden] { display: none; }
#app-lock .al-busy .spinner-border { color: var(--nw-accent); }

/* ===== Instant tap feedback + clear tab-switch effect (app) ==============
 * The press/active states fire on touch (0ms); the content animation + Turbo
 * progress bar cover the brief fetch so navigation feels immediate. */
.tabbar .tab, .btn, .chip, .sortbtn { -webkit-tap-highlight-color: transparent; }

/* Tactile press — scales down the instant a finger lands. */
.tabbar .tab { transition: color .15s ease, transform .08s ease; }
.tabbar .tab:active { transform: scale(.88); }
.btn { transition: transform .08s ease, filter .15s ease, background-color .15s, border-color .15s, color .15s; }
.btn:active { transform: scale(.96); }

/* Clearer active tab: accent colour + a sliding top indicator. */
.tabbar .tab { position: relative; }
.tabbar .tab::before {
    content: ''; position: absolute; top: 0; left: 50%;
    width: 26px; height: 3px; border-radius: 0 0 4px 4px; background: var(--nw-accent);
    transform: translateX(-50%) scaleX(0); transition: transform .18s ease;
}
.tabbar .tab.active::before { transform: translateX(-50%) scaleX(1); }
/* Lively active tab: a small bounce each time it becomes active. */
.tabbar .tab.active i { transform: translateY(-1px); animation: tab-bounce .4s ease; }
@keyframes tab-bounce { 0%, 100% { transform: translateY(-1px) scale(1); } 45% { transform: translateY(-4px) scale(1.18); } }

/* Centre camera action — a raised accent button, not a nav tab. */
.tabbar .tab-cam { padding: 0; overflow: visible; }
.tabbar .tab-cam::before { content: none; }
.tab-cam-btn {
    display: flex; align-items: center; justify-content: center;
    width: 50px; height: 50px; margin-top: -16px; border-radius: 50%;
    background: var(--nw-accent); color: #fff; font-size: 1.3rem;
    border: 3px solid var(--nw-surface);
    box-shadow: 0 8px 18px -5px var(--nw-accent-glow);
    transition: transform .12s ease;
}
.tabbar .tab-cam:active { transform: none; }
.tabbar .tab-cam:active .tab-cam-btn { transform: scale(.9); }

/* "Add to cart" fly-in chip (receipt → Transactions tab). */
.fly-receipt {
    position: fixed; z-index: 20058; width: 52px; height: 52px; border-radius: 14px;
    background: var(--nw-accent); color: #fff; font-size: 1.5rem; pointer-events: none;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 10px 26px var(--nw-accent-glow);
    transition: transform .6s cubic-bezier(.4, -0.2, .3, 1), opacity .6s ease;
}

/* No page-content fade on navigation: content is often shown from cache first,
   so fading the fresh render in from opacity 0 made it blink. Show it instantly. */

/* Skeleton placeholder — shown in the content area while data loads, so a tab
   switch reveals an empty frame + light placeholder, then the real content.
   Deliberately STATIC (no shimmer): Turbo shows the preloaded skeleton snapshot
   and then re-renders the fresh one, so an animation would visibly restart
   ("reload"); identical static blocks make that second render invisible. */
.sk-page { display: grid; gap: 16px; }
@media (min-width: 768px) { .sk-page { grid-template-columns: 1fr 1fr; align-items: start; } }
.sk-card { background: var(--nw-surface); border: 1px solid var(--nw-border); border-radius: 16px; padding: 20px; }
.sk { background: rgba(148, 163, 184, .14); border-radius: 8px; }

/* Turbo's top loading bar in brand colour. */
/* Turbo's top loading bar — hidden: navigations are fast and it just flashes. */
.turbo-progress-bar { display: none !important; }

/* Receipt-scan busy / error overlay (sits above modals). */
.scan-overlay {
    position: fixed; inset: 0; z-index: 20050;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 20, 36, .5); padding: 24px;
}
.scan-box {
    background: var(--nw-surface); color: var(--nw-text);
    border-radius: 16px; padding: 26px 30px; text-align: center;
    box-shadow: var(--nw-shadow); max-width: 320px; font-weight: 500;
}
.scan-box .spinner-border { color: var(--nw-accent); }
.scan-overlay.scan-error .spinner-border { display: none; }
.scan-overlay.scan-error .scan-box { color: var(--nw-red); }

/* Native camera preview (@capacitor-community/camera-preview) renders BEHIND the
   webview; while it's live, make the app transparent so it shows through and keep
   only the HTML camera controls on top. */
html.cam-live, html.cam-live body { background: transparent !important; }
html.cam-live #app-navbar,
html.cam-live #app-tabbar,
html.cam-live #receipt-queue,
html.cam-live .container,
html.cam-live .demo-banner { visibility: hidden !important; }

.cam-view { position: fixed; inset: 0; z-index: 20060; } /* transparent — preview shows through */
.cam-frame {
    position: absolute; left: 8%; right: 8%; top: 16%; bottom: 26%;
    border: 2px solid rgba(255, 255, 255, .9); border-radius: 16px;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
.cam-hint {
    position: absolute; left: 0; right: 0; top: calc(16% - 42px); text-align: center;
    color: #fff; font-weight: 500; font-size: .95rem; padding: 0 24px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.cam-close {
    position: absolute; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 16px;
    width: 40px; height: 40px; border-radius: 50%; border: 0;
    background: rgba(0, 0, 0, .45); color: #fff; display: flex; align-items: center; justify-content: center;
}
.cam-bar {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 18px 24px calc(env(safe-area-inset-bottom, 0px) + 22px);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: linear-gradient(to top, rgba(0, 0, 0, .55), transparent);
}
.cam-gallery, .cam-slot { flex: 1 1 0; }
.cam-gallery {
    display: inline-flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: 0; color: #fff; font-size: .72rem;
}
.cam-gallery i { font-size: 1.5rem; }
.cam-shutter {
    flex: none; width: 72px; height: 72px; border-radius: 50%;
    background: #fff; border: 4px solid rgba(255, 255, 255, .45); box-shadow: 0 0 0 2px rgba(0, 0, 0, .15);
}
.cam-shutter:active { transform: scale(.94); }

/* Transient scan toast (bottom) + a pulse on the Transactions tab when a scanned
   draft lands, plus the in-page drafts banner and the draft cards in the modal. */
.scan-toast {
    position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 74px); z-index: 20055;
    max-width: calc(100vw - 32px); padding: 9px 16px; border-radius: 999px;
    background: #0A1424; color: #fff; font-size: .84rem; font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22); opacity: 0; pointer-events: none;
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
    transition: opacity .2s ease, transform .2s ease;
}
.scan-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.scan-toast .spinner-border { width: .9rem; height: .9rem; border-width: .13em; }
.scan-toast-err { background: var(--nw-red); }

@keyframes tab-pulse { 0%, 100% { transform: scale(1); } 35% { transform: scale(1.28); } }
.tabbar .tab.tab-pulse i { animation: tab-pulse .5s ease 2; color: var(--nw-accent-ink); }

.drafts-banner {
    display: flex; align-items: center; gap: 10px; width: 100%;
    background: var(--nw-accent-soft); border: 1px solid var(--nw-accent);
    color: var(--nw-accent-ink); border-radius: 12px; padding: 11px 14px;
    font-weight: 600; font-size: .92rem;
}
.drafts-banner .bi-receipt-cutoff { font-size: 1.1rem; }

.draft-card {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--nw-border);
}
.draft-card:last-child { border-bottom: 0; }
.draft-info { flex: 1 1 auto; min-width: 0; }
.draft-name { font-weight: 600; }
.draft-sub { font-size: .9rem; margin-top: 1px; }
.draft-acts { flex: none; display: flex; gap: 6px; }
.draft-card.draft-busy { opacity: .5; pointer-events: none; }
.draft-card.draft-pending .draft-name { color: var(--nw-muted); font-weight: 500; }
.draft-spin { flex: none; width: 1.1rem; height: 1.1rem; border-width: .14em; color: var(--nw-accent); }

/* Tag input (add/edit form) — chips + a borderless entry inside a form-control. */
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; height: auto; min-height: 44px; cursor: text; }
.tag-input .tag-entry {
    flex: 1 1 90px; min-width: 90px; border: 0; outline: none; background: none;
    padding: 2px; font: inherit; color: inherit;
}
.tag-chip {
    display: inline-flex; align-items: center; gap: 2px;
    background: var(--nw-accent-soft); color: var(--nw-accent-ink);
    border-radius: 999px; padding: 3px 4px 3px 11px; font-size: .82rem; font-weight: 600;
}
.tag-chip .tag-x { border: 0; background: none; color: inherit; font-size: 1.05rem; line-height: 1; padding: 0 4px; cursor: pointer; opacity: .6; }
.tag-chip .tag-x:hover { opacity: 1; }

/* Tag display chips (rows / detail / draft cards). */
.tag-list { display: inline-flex; flex-wrap: wrap; gap: 5px; vertical-align: middle; }
.tag {
    display: inline-block; background: var(--nw-accent-soft); color: var(--nw-accent-ink);
    border-radius: 6px; padding: 1px 8px; font-size: .74rem; font-weight: 600;
}

/* Colour-theme picker (Ngũ hành) in Settings. */
/* Five swatches, always on one row: each option shares the width equally. */
.theme-picker { display: flex; flex-wrap: nowrap; gap: 8px; }
.theme-opt {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    flex: 1 1 0; min-width: 0; padding: 0; border: 0; background: none; cursor: pointer;
    font-size: .74rem; font-weight: 600; color: var(--nw-muted);
}
.theme-opt .sw {
    width: 40px; height: 40px; max-width: 100%; border-radius: 50%;
    box-shadow: 0 0 0 1px var(--nw-border) inset; transition: box-shadow .12s ease;
}
.theme-opt.active { color: var(--nw-text); }
.theme-opt.active .sw { box-shadow: 0 0 0 3px var(--nw-surface), 0 0 0 5px var(--nw-accent); }
.sw-kim  { background: #c79a3b; }
.sw-moc  { background: #0fae84; }
.sw-thuy { background: #2f80ed; }
.sw-hoa  { background: #e0564c; }
.sw-tho  { background: #b27636; }

/* Appearance (light / dark / auto) segmented picker in Settings. */
.mode-picker { display: flex; gap: 8px; }
.mode-opt {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 12px 8px; border: 1px solid var(--nw-border); border-radius: var(--nw-radius-sm);
    background: var(--nw-surface); color: var(--nw-muted); cursor: pointer;
    font-size: .78rem; font-weight: 600;
    transition: color .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.mode-opt i { font-size: 1.2rem; }
.mode-opt.active {
    color: var(--nw-accent-ink); border-color: var(--nw-accent);
    box-shadow: 0 0 0 1px var(--nw-accent) inset;
}

/* Collapsible card header (e.g. change-passphrase in Settings). */
.collapse-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    width: 100%; padding: 0; border: 0; background: none; text-align: left;
    color: inherit; cursor: pointer;
}
.collapse-title .fw-bold { font-size: 1rem; margin-bottom: 1px; }
.collapse-caret { flex: none; color: var(--nw-muted); transition: transform .18s ease; }
.collapse-head[aria-expanded="true"] .collapse-caret { transform: rotate(180deg); }

/* Brief branded overlay shown while the page reloads after a locale/currency
 * change — acknowledges the tap instantly instead of a frozen/blank moment. */
#view-reload {
    position: fixed; inset: 0; z-index: 20000;
    display: flex; align-items: center; justify-content: center;
    background: var(--nw-bg);
}
#view-reload[hidden] { display: none; }
#view-reload .spinner-border { color: var(--nw-accent); }

/* ===== Pull-to-refresh indicator (app only, see pulltorefresh.js) ========= */
#ptr {
    position: fixed; top: 8px; left: 50%; z-index: 1900;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    background: var(--nw-surface); color: var(--nw-accent);
    border: 1px solid var(--nw-border); border-radius: 50%;
    box-shadow: var(--nw-shadow-sm);
    opacity: 0; transform: translate(-50%, 0);
    pointer-events: none;
}
#ptr .spinner-border { width: 1.05rem; height: 1.05rem; border-width: .14em; }
#ptr.ptr-ready { color: var(--nw-accent-ink); }
