:root {
    /* Subtle Gradient Design System - tokens */
    --canvas: #ffffff;
    --surface-soft: #f7f7f7;
    --surface-card: #ffffff;
    --surface-strong: #eef0f3;
    --surface-dark: #0a0b0d;
    --surface-dark-elevated: #16181c;
    --ink: #0a0b0d;
    --body: #5b616e;
    --muted: #7c828a;
    --muted-soft: #a8acb3;
    --hairline: #dee1e6;
    --hairline-soft: #eef0f3;
    --primary: #2f5fe8;
    --primary-active: #1e46be;
    --primary-disabled: #afc1ec;
    --primary-soft: #e8edfc;
    --on-primary: #ffffff;
    --on-dark: #ffffff;
    --on-dark-soft: #a8acb3;
    --link: #2f5fe8;
    --income: #05b169;
    --income-soft: #e3f7ee;
    --expense: #cf202f;
    --expense-soft: #fceaec;
    --warning: #a66c00;
    --warning-soft: #fbedd3;
    --accent-yellow: #f4b000;
    --focus-ring: #2f5fe8;
    --shadow-card: 0 4px 12px rgba(10, 11, 13, 0.04);
    --shadow-overlay: 0 16px 40px rgba(10, 11, 13, 0.22);
    --radius-pill: 100px;
    --radius-full: 9999px;
    --radius-xl: 24px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-xs: 4px;
    --space-xxs: 4px;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-base: 16px;
    --space-md: 20px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;
    --space-section: 96px;
    --bottom-nav-height: 64px;
}

* { -webkit-tap-highlight-color: transparent; }

html, body { overflow-x: hidden; }

body {
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--surface-soft);
    color: var(--ink);
    width: 100%;
}

/* ---------- Typography ---------- */
.display-lg { font-size: 32px; font-weight: 400; letter-spacing: -0.4px; line-height: 1.13; color: var(--ink); }
.display-md { font-size: 24px; font-weight: 400; letter-spacing: -0.3px; line-height: 1.2; color: var(--ink); }
.title-md { font-size: 18px; font-weight: 600; line-height: 1.33; color: var(--ink); }
.title-sm { font-size: 16px; font-weight: 600; line-height: 1.25; color: var(--ink); }
.body-md { font-size: 16px; font-weight: 400; line-height: 1.5; color: var(--body); }
.body-sm { font-size: 14px; font-weight: 400; line-height: 1.5; color: var(--muted); }
.caption { font-size: 13px; font-weight: 400; line-height: 1.5; color: var(--muted); }
.caption-strong { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1.5; color: var(--muted); }
.button { font-size: 16px; font-weight: 600; line-height: 1.15; font-family: inherit; }
.label { font-size: 13px; font-weight: 600; color: var(--body); margin-bottom: 4px; display: block; }
.link-text { color: var(--link); text-decoration: underline; }
.nav-link { font-size: 14px; font-weight: 500; line-height: 1.4; }

.amount { font-family: 'JetBrains Mono', ui-monospace, monospace; white-space: nowrap; }
.amount-lg { font-size: 24px; font-weight: 500; }
.amount-md { font-size: 16px; font-weight: 500; }
.amount-sm { font-size: 13px; font-weight: 500; }
.amount-income { color: var(--income); }
.amount-expense { color: var(--expense); }
.amount-neutral { color: var(--ink); }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-base); margin-bottom: var(--space-lg); }
.page-header h2 { display: flex; align-items: center; gap: var(--space-xs); }
.page-subtitle { color: var(--body); margin-top: 4px; max-width: 48rem; }

/* ---------- Button ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    height: 44px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn:disabled { cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-active); }
.btn-primary:disabled { background: var(--primary-disabled); }
.btn-secondary { background: var(--surface-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--hairline); }
.btn-danger { background: var(--expense-soft); color: var(--expense); }
.btn-danger:hover { background: #f8d4d8; }
.btn-success { background: var(--income); color: var(--on-primary); }
.btn-success:hover { filter: brightness(0.93); }
.btn-ghost { background: transparent; color: var(--link); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { height: 36px; padding: 0 var(--space-base); font-size: 13px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: var(--radius-full); }

/* ---------- Text field ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-xs); }
.field-input {
    height: 44px;
    padding: 0 var(--space-base);
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
    background: var(--surface-card);
    color: var(--ink);
    width: 100%;
    font-size: 14px;
    font-family: inherit;
}
.field-input::placeholder { color: var(--muted-soft); }
.field-input:focus { outline: none; border-color: var(--focus-ring); box-shadow: 0 0 0 1px var(--focus-ring); }
.field-input[aria-invalid="true"] { border-color: var(--expense); }
.field-hint { color: var(--muted); }
.field-error { color: var(--expense); }
input[type="color"].field-input { padding: 4px; cursor: pointer; }

/* ---------- Badge ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xxs);
    padding: 3px var(--space-sm);
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}
.badge-neutral { background: var(--surface-strong); color: var(--body); }
.badge-success { background: var(--income-soft); color: var(--income); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--expense-soft); color: var(--expense); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; }

/* ---------- Cards / sections ---------- */
.card {
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}
.stat-card {
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}
.stat-card:hover { box-shadow: var(--shadow-card); }
.stat-card-label { color: var(--muted); }
.empty-state {
    background: var(--surface-soft);
    border: 1px solid var(--hairline-soft);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    text-align: center;
    color: var(--body);
}

/* ---------- Table ---------- */
.ds-table { width: 100%; font-size: 14px; border-collapse: collapse; }
.ds-table thead { text-align: left; color: var(--muted); }
.ds-table thead th { padding: var(--space-xs) var(--space-sm); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.ds-table tbody tr { border-top: 1px solid var(--hairline-soft); }
.ds-table tbody td { padding: var(--space-sm); color: var(--ink); vertical-align: top; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Filter pill group ---------- */
.pill-group { display: inline-flex; border-radius: var(--radius-pill); background: var(--surface-strong); padding: 3px; gap: 2px; }
.pill-btn { border-radius: var(--radius-pill); padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--body); background: transparent; border: none; cursor: pointer; white-space: nowrap; }
.pill-btn.active { background: var(--canvas); color: var(--ink); box-shadow: var(--shadow-card); }
.filter-btn { border-radius: var(--radius-pill); padding: 6px 14px; font-size: 13px; font-weight: 600; background: var(--surface-strong); color: var(--body); border: none; cursor: pointer; white-space: nowrap; }
.filter-btn.active { background: var(--primary); color: var(--on-primary); }

/* ---------- Transaction row ---------- */
.date-group + .date-group { margin-top: var(--space-xl); }
.date-heading { color: var(--muted); margin-bottom: var(--space-sm); }
.date-group-rows { background: var(--surface-card); border: 1px solid var(--hairline); border-radius: var(--radius-lg); overflow: hidden; }

.tx-row {
    display: flex;
    align-items: center;
    gap: var(--space-base);
    padding: var(--space-base) var(--space-md);
    border-bottom: 1px solid var(--hairline-soft);
    cursor: pointer;
}
.date-group-rows .tx-row:last-child { border-bottom: none; }
.tx-row:hover { background: var(--surface-soft); }
.tx-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--radius-full);
    background: var(--surface-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tx-title { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.tx-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.tx-badges { display: flex; gap: var(--space-xxs); margin-top: 2px; }
.tx-amount { text-align: right; min-width: 96px; }

/* ---------- Modal ---------- */
.modal-panel {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-overlay);
    padding: var(--space-xl);
}
.sheet-panel {
    background: var(--surface-card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-overlay);
    padding: var(--space-lg);
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
}

/* ====================================================================
   Navigation
   ==================================================================== */
.top-nav {
    background: var(--canvas);
    border-bottom: 1px solid var(--hairline);
}
.top-nav-link {
    font-size: 14px;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    color: var(--body);
    white-space: nowrap;
}
.top-nav-link:hover { background: var(--surface-soft); color: var(--ink); }
.top-nav-link.active { background: var(--primary-soft); color: var(--primary); }

.lang-dropdown { position: relative; }
.lang-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    height: 36px;
    padding: 0 var(--space-sm);
    border-radius: var(--radius-pill);
    background: var(--surface-strong);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
}
.lang-trigger:hover { background: var(--hairline); }
.lang-trigger:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.lang-chevron { font-size: 10px; color: var(--muted); }
.lang-flag { width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px var(--hairline-soft); flex-shrink: 0; }
.lang-menu {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-xs));
    z-index: 45;
    min-width: 200px;
    padding: var(--space-xxs);
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-overlay);
}
.lang-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
}
.lang-menu-item:hover { background: var(--surface-soft); }
.lang-menu-item.active { background: var(--primary-soft); color: var(--primary); }
.lang-menu-item .check { font-weight: 700; visibility: hidden; }
.lang-menu-item.active .check { visibility: visible; }

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--surface-strong);
}
.avatar-initials { background: var(--primary-soft); color: var(--primary); font-weight: 600; line-height: 1; }
.nav-avatar { display: inline-flex; border-radius: var(--radius-full); }
.nav-avatar:hover .avatar { box-shadow: 0 0 0 2px var(--hairline); }
.nav-avatar.active .avatar { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 4px var(--primary); }
.nav-avatar:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.profile-avatar-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-lg); }

/* Bottom tab bar - mobile only */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--canvas);
    border-top: 1px solid var(--hairline);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: var(--bottom-nav-height);
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    min-width: 0;
    padding: 6px 2px;
}
.bottom-nav-item .bn-icon { font-size: 20px; line-height: 1; }
.bottom-nav-item .bn-label { font-size: 11px; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:active { opacity: 0.7; }

@media (max-width: 767px) {
    .bottom-nav { display: block; }
    body.has-bottom-nav { padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)); }
    .top-nav .top-nav-links, .top-nav .top-nav-lang { display: none; }
    .top-nav .title-md { flex: 1; min-width: 0; }
}

/* More sheet + Language sheet */
.nav-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 11, 13, 0.5);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.nav-sheet-list { display: flex; flex-direction: column; gap: 2px; }
.nav-sheet-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-xs);
    border-radius: var(--radius-md);
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
}
.nav-sheet-link:hover, .nav-sheet-link:active { background: var(--surface-soft); }
.nav-sheet-link .bn-icon { font-size: 18px; width: 24px; text-align: center; }
.nav-sheet-link.active { color: var(--primary); }

.lang-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-sm) var(--space-base);
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
    background: var(--canvas);
    font-size: 15px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
}
.lang-option + .lang-option { margin-top: var(--space-xs); }
.lang-option.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.lang-option .check { color: var(--primary); font-weight: 700; visibility: hidden; }
.lang-option.active .check { visibility: visible; }

/* Mobile layout helpers */
@media (max-width: 767px) {
    .display-lg { font-size: 24px; }
    .display-md { font-size: 20px; }
}

/* Global loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(10, 11, 13, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease;
}
.loading-overlay.visible {
    opacity: 1;
    pointer-events: all;
}
.loading-card {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-overlay);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    min-width: 220px;
    text-align: center;
}
.loading-spinner {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 3px solid var(--hairline);
    border-top-color: var(--primary);
    animation: loading-spin 0.8s linear infinite;
}
@keyframes loading-spin {
    to { transform: rotate(360deg); }
}
.loading-message {
    color: var(--ink);
}

/* ---------- Categorisation ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    height: 32px;
    padding: 0 var(--space-sm);
    border-radius: var(--radius-pill);
    border: 1px solid var(--hairline);
    background: var(--canvas);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.chip:hover { background: var(--surface-soft); }
.chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip kbd { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px; color: var(--muted); }
.chip-dot { width: 8px; height: 8px; border-radius: var(--radius-full); flex-shrink: 0; }
.reason-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-xs);
    border-radius: var(--radius-pill);
    background: var(--surface-strong);
    color: var(--body);
    font-size: 12px;
    font-weight: 500;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reason-manual { background: var(--primary-soft); color: var(--primary); }
.reason-guess { background: var(--warning-soft); color: var(--warning); }
.inbox-card { transition: box-shadow 150ms ease, border-color 150ms ease; }
.inbox-card.current { border-color: var(--primary); box-shadow: var(--shadow-card); }
.inbox-card details > summary { cursor: pointer; list-style: none; }
.inbox-card details > summary::-webkit-details-marker { display: none; }
.who-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-base);
    border-radius: var(--radius-md);
    background: var(--warning-soft);
}
.description-cell { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.description-cell.expanded { white-space: normal; overflow: visible; word-break: break-word; }
.category-tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-xxs);
    padding: var(--space-base);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    background: var(--surface-card);
}
.category-tile:hover { box-shadow: var(--shadow-card); }
.bulk-bar {
    position: sticky;
    bottom: calc(var(--space-base) + env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-base);
    border-radius: var(--radius-lg);
    background: var(--surface-dark);
    color: var(--on-dark);
    box-shadow: var(--shadow-overlay);
}
.bulk-bar .field-input { height: 36px; width: auto; }
@media (max-width: 767px) {
    .bulk-bar { bottom: calc(var(--bottom-nav-height) + var(--space-xs) + env(safe-area-inset-bottom)); }
}
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 90;
    display: flex;
    align-items: center;
    gap: var(--space-base);
    max-width: calc(100vw - 2 * var(--space-base));
    width: max-content;
    padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--surface-dark);
    color: var(--on-dark);
    box-shadow: var(--shadow-overlay);
    font-size: 14px;
}
.toast .btn { background: var(--surface-dark-elevated); color: var(--on-dark); }
@media (max-width: 767px) {
    .toast { bottom: calc(var(--bottom-nav-height) + var(--space-sm) + env(safe-area-inset-bottom)); }
}

/* ---------- Category icons ---------- */
.material-symbols-rounded {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    font-size: inherit;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.category-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--cat) 14%, var(--canvas));
    color: var(--cat);
    overflow: hidden;
}
.category-initial { font-weight: 600; line-height: 1; }
.icon-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 22px;
    cursor: pointer;
}
.icon-option:hover { background: var(--surface-strong); }
.icon-option.active { border-color: var(--cat, var(--primary)); background: color-mix(in srgb, var(--cat, var(--primary)) 14%, var(--canvas)); color: var(--cat, var(--primary)); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: var(--space-xs); }
.color-option {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    border: 2px solid var(--canvas);
    box-shadow: 0 0 0 1px var(--hairline);
    cursor: pointer;
}
.color-option.active { box-shadow: 0 0 0 2px var(--ink); }
.look-toggle { display: inline-flex; padding: 2px; border-radius: var(--radius-pill); background: var(--surface-strong); }
.look-toggle button { height: 32px; padding: 0 var(--space-sm); border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; color: var(--body); }
.look-toggle button.active { background: var(--canvas); color: var(--ink); box-shadow: var(--shadow-card); }
