:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-light: #6366f1;
    --brand-soft: rgba(99, 102, 241, 0.12);

    --income: #059669;
    --income-soft: rgba(5, 150, 105, 0.12);
    --expense: #e11d48;
    --expense-soft: rgba(225, 29, 72, 0.12);
    --savings: #d97706;
    --savings-soft: rgba(217, 119, 6, 0.12);
    --info: #0ea5e9;

    --good: #059669;
    --warn: #d97706;
    --bad: #e11d48;

    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-hover: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #5b657a;
    --text-faint: #94a3b8;
    --border: #e7e9f1;
    --border-strong: #d7dbe7;

    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .05);
    --shadow-lg: 0 10px 30px -8px rgba(15, 23, 42, .18);
    --shadow-brand: 0 6px 18px rgba(79, 70, 229, .28);

    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --transition: all .22s cubic-bezier(.4, 0, .2, 1);
    --sidebar-w: 250px;
}

[data-theme="dark"] {
    --brand: #818cf8;
    --brand-dark: #6366f1;
    --brand-light: #a5b4fc;
    --brand-soft: rgba(129, 140, 248, 0.16);

    --income: #34d399;
    --income-soft: rgba(52, 211, 153, 0.16);
    --expense: #fb7185;
    --expense-soft: rgba(251, 113, 133, 0.16);
    --savings: #fbbf24;
    --savings-soft: rgba(251, 191, 36, 0.16);
    --info: #38bdf8;

    --good: #34d399;
    --warn: #fbbf24;
    --bad: #fb7185;

    --bg: #0b1120;
    --surface: #131b2e;
    --surface-2: #0f1726;
    --surface-hover: #1b2640;
    --text: #f1f5f9;
    --text-secondary: #9aa6bd;
    --text-faint: #64748b;
    --border: #243049;
    --border-strong: #2f3d5a;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 40px -10px rgba(0, 0, 0, .6);
    --shadow-brand: 0 6px 18px rgba(99, 102, 241, .4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html { scroll-behavior: smooth; overflow-x: hidden; max-width: 100%; }

body {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-font-smoothing: antialiased;
    transition: background .3s ease, color .3s ease;
}

/* Bouton d'action flottant (visible en mobile uniquement) */
.fab {
    display: none;
    position: fixed; right: 16px; bottom: 78px; z-index: 60;
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
    color: #fff; font-size: 1.4rem; box-shadow: var(--shadow-brand);
    align-items: center; justify-content: center;
}

/* Gestion des membres (admin) */
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.admin-row:last-child { border-bottom: none; }
.admin-who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 180px; }
.admin-name { font-weight: 600; max-width: 220px; }
.invite-box { display: flex; gap: 8px; }
.invite-box .form-control { width: 180px; }

::selection { background: var(--brand-soft); }

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

/* ---------- Anti-débordement global ---------- */
img, canvas, svg, video { max-width: 100%; }
.tx-main, .admin-who, .kpi-meta, .detail-val, .card, .card-title { min-width: 0; }
.tx-label, .tx-sub, .card-title, .member-name { overflow-wrap: anywhere; }

/* ---------- Layout ---------- */
.app-container { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    inset: 0 auto 0 0;
    height: 100vh;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.sidebar-header { padding: 22px 20px; border-bottom: 1px solid var(--border); }

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.18rem;
    letter-spacing: -0.02em;
    color: var(--text);
}

.logo .mark {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
    color: #fff;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    box-shadow: var(--shadow-brand);
    flex-shrink: 0;
}
.logo small { display: block; font-size: .68rem; font-weight: 500; color: var(--text-faint); letter-spacing: .04em; }

.nav-menu { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; }

.nav-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-faint);
    padding: 14px 16px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: .92rem;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    position: relative;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
    background: var(--brand); border-radius: 0 3px 3px 0;
}
.nav-item i { width: 22px; text-align: center; font-size: 1.02rem; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); }

.theme-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface-2);
    cursor: pointer; color: var(--text-secondary); font-family: inherit;
    font-size: .85rem; font-weight: 500; transition: var(--transition);
}
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text); }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 0 32px 48px;
    max-width: calc(100vw - var(--sidebar-w));
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 18px 0 16px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.page-title h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 2px; }
.page-title p { color: var(--text-secondary); font-size: .9rem; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.month-nav {
    display: flex; align-items: center; gap: 4px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 3px;
}
.month-nav button {
    width: 32px; height: 32px; border: none; background: none; cursor: pointer;
    color: var(--text-secondary); border-radius: var(--radius-xs); transition: var(--transition);
}
.month-nav button:hover { background: var(--surface-hover); color: var(--text); }
.month-nav .month-label {
    min-width: 130px; text-align: center; font-weight: 600; font-size: .9rem;
    text-transform: capitalize;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: .88rem; cursor: pointer;
    transition: var(--transition); border: none; font-family: inherit; white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, var(--brand-light), var(--brand-dark)); color: #fff; box-shadow: var(--shadow-brand); }
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-sm { padding: 7px 13px; font-size: .82rem; }
.icon-btn {
    width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
    color: var(--text-secondary); cursor: pointer; transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border-radius: var(--radius); padding: 22px;
    box-shadow: var(--shadow); border: 1px solid var(--border); transition: var(--transition);
}
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.card-title { font-weight: 600; font-size: 1.02rem; letter-spacing: -0.01em; }
.card-subtitle { font-size: .8rem; color: var(--text-secondary); font-weight: 400; }

.grid { display: grid; gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi-card {
    background: var(--surface); border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow); border: 1px solid var(--border); position: relative; overflow: hidden;
    transition: var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.kpi-label { font-size: .82rem; color: var(--text-secondary); font-weight: 500; }
.kpi-icon {
    width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
}
.kpi-icon.balance { background: var(--brand-soft); color: var(--brand); }
.kpi-icon.income { background: var(--income-soft); color: var(--income); }
.kpi-icon.expense { background: var(--expense-soft); color: var(--expense); }
.kpi-icon.savings { background: var(--savings-soft); color: var(--savings); }
.kpi-value { font-size: 1.62rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.kpi-meta { font-size: .8rem; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.trend-up { color: var(--income); }
.trend-down { color: var(--expense); }
.kpi-meta .muted { color: var(--text-secondary); }

/* health pills */
.pill {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
    font-size: .74rem; font-weight: 600;
}
.pill.good { background: var(--income-soft); color: var(--good); }
.pill.warn { background: var(--savings-soft); color: var(--warn); }
.pill.bad { background: var(--expense-soft); color: var(--bad); }

/* indicator cards row */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.health-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow);
}
.health-card .h-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.health-card .h-name { font-size: .85rem; color: var(--text-secondary); font-weight: 500; display: flex; gap: 7px; align-items: center; }
.health-card .h-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.health-card .h-hint { font-size: .76rem; color: var(--text-secondary); margin-top: 4px; }
.gauge { height: 7px; border-radius: 4px; background: var(--surface-hover); overflow: hidden; margin-top: 12px; }
.gauge > span { display: block; height: 100%; border-radius: 4px; transition: width .6s cubic-bezier(.4,0,.2,1); }

/* ---------- Charts ---------- */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }
.chart-container { position: relative; height: 300px; }
.chart-container.tall { height: 360px; }

/* ---------- Tables ---------- */
.table-container { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
th {
    background: var(--surface-2); padding: 12px 14px; text-align: left;
    font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: .88rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s ease; }
tbody tr:hover td { background: var(--surface-hover); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px; font-size: .76rem; font-weight: 600; }
.badge-income { background: var(--income-soft); color: var(--income); }
.badge-expense { background: var(--expense-soft); color: var(--expense); }
.amount-income { color: var(--income); font-weight: 600; white-space: nowrap; }
.amount-expense { color: var(--expense); font-weight: 600; white-space: nowrap; }

.chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 7px;
    font-size: .78rem; font-weight: 500; background: var(--surface-hover); color: var(--text-secondary);
}

.avatar {
    width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .76rem; color: #fff; flex-shrink: 0;
}
.who-cell { display: inline-flex; align-items: center; gap: 8px; }
.paid-by-note { font-size: .72rem; color: var(--text-secondary); display: block; margin-top: 2px; }

/* ---------- Transaction list (cliquable, sans scroll horizontal) ---------- */
.tx-list { display: flex; flex-direction: column; }
.tx-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 11px 10px; border: none; background: none; cursor: pointer;
    border-bottom: 1px solid var(--border); text-align: left; font-family: inherit;
    border-radius: 10px; transition: background .15s ease; color: var(--text);
}
.tx-item:last-child { border-bottom: none; }
.tx-item:hover { background: var(--surface-hover); }
.tx-icon {
    width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    color: #fff; flex-shrink: 0; font-size: .95rem;
}
.tx-main { flex: 1; min-width: 0; }
.tx-label { font-weight: 600; font-size: .92rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: .76rem; color: var(--text-secondary); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 700; font-size: .95rem; white-space: nowrap; margin-left: auto; padding-left: 8px; }

/* ---------- Detail rows (modal) ---------- */
.detail-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: .95rem; flex-wrap: wrap; }
.detail-row:last-child { border-bottom: none; }
.detail-row > span:first-child { color: var(--text-secondary); flex-shrink: 0; }
.detail-val { font-weight: 500; text-align: right; margin-left: auto; overflow-wrap: anywhere; }

/* ---------- Filters ---------- */
.filters-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-wrap i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: .85rem; }
.form-control {
    padding: 9px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .88rem; background: var(--surface); color: var(--text); transition: var(--transition);
}
.search-wrap .form-control { width: 100%; padding-left: 36px; }
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---------- Forms / Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(8, 12, 24, .55); backdrop-filter: blur(4px);
    z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity .25s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal {
    background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px;
    max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
    transform: translateY(16px) scale(.98); transition: transform .25s ease;
}
.modal.wide { max-width: 720px; }
.modal-overlay.active .modal { transform: translateY(0) scale(1); }
.modal-header { padding: 22px 24px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; }
.modal-close {
    background: none; border: none; font-size: 1.05rem; color: var(--text-secondary); cursor: pointer;
    width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-body { padding: 22px 24px; }
.modal-footer { padding: 0 24px 24px; display: flex; justify-content: flex-end; gap: 10px; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: 7px; color: var(--text); }
.form-input, .form-select, textarea.form-input {
    width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .92rem; background: var(--surface); color: var(--text); transition: var(--transition);
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: .75rem; color: var(--text-secondary); margin-top: 5px; }

.seg { display: flex; gap: 10px; }
.seg-card {
    flex: 1; padding: 13px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    text-align: center; cursor: pointer; transition: var(--transition); font-weight: 600; font-size: .9rem;
    display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-secondary);
}
.seg-card i { font-size: 1.3rem; }
.seg-card:hover { border-color: var(--border-strong); }
.seg-card.income.selected { border-color: var(--income); background: var(--income-soft); color: var(--income); }
.seg-card.expense.selected { border-color: var(--expense); background: var(--expense-soft); color: var(--expense); }

.amount-field { position: relative; }
.amount-field .cur { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-weight: 600; }

/* ---------- Members ---------- */
.members-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.member-card {
    background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
    border: 1px solid var(--border); transition: var(--transition); cursor: pointer; text-align: left;
}
.member-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.member-card .m-head { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; }
.avatar-lg { width: 52px; height: 52px; border-radius: 15px; font-size: 1.2rem; }
.member-name { font-weight: 700; font-size: 1.05rem; }
.member-role { color: var(--text-secondary); font-size: .8rem; display: inline-flex; align-items: center; gap: 5px; }
.m-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.m-stat .v { font-weight: 700; font-size: 1.02rem; }
.m-stat .l { font-size: .72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }

.progress-bar { height: 7px; background: var(--surface-hover); border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; border-radius: 4px; transition: width .6s ease; }

/* ---------- Budgets ---------- */
.budget-row {
    display: grid; grid-template-columns: 200px 1fr 150px; gap: 16px; align-items: center;
    padding: 14px 0; border-bottom: 1px solid var(--border);
}
.budget-row:last-child { border-bottom: none; }
.budget-name { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .9rem; }
.budget-cat-icon { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: .82rem; color: #fff; flex-shrink: 0; }
.budget-track { height: 9px; background: var(--surface-hover); border-radius: 5px; overflow: hidden; }
.budget-track > span { display: block; height: 100%; border-radius: 5px; transition: width .6s ease; }
.budget-figures { display: flex; justify-content: space-between; font-size: .78rem; margin-bottom: 6px; color: var(--text-secondary); }
.budget-input { width: 130px; text-align: right; }

/* ---------- Settings ---------- */
.settings-card { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.settings-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.settings-title i { color: var(--brand); }
.settings-desc { color: var(--text-secondary); font-size: .88rem; margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast-container { position: fixed; top: 22px; right: 22px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--surface); border-radius: var(--radius-sm); padding: 13px 18px; box-shadow: var(--shadow-lg);
    border: 1px solid var(--border); border-left: 4px solid var(--brand);
    display: flex; align-items: center; gap: 11px; min-width: 280px; font-size: .9rem; font-weight: 500;
    animation: slideIn .3s ease, fadeOut .3s ease 2.7s forwards;
}
.toast.success { border-left-color: var(--good); }
.toast.success i { color: var(--good); }
.toast.error { border-left-color: var(--bad); }
.toast.error i { color: var(--bad); }
@keyframes slideIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(110%); } }

/* ---------- Sections ---------- */
.section { display: none; animation: fadeIn .35s ease; }
.section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-secondary); }
.empty-state i { font-size: 2.6rem; margin-bottom: 12px; opacity: .4; display: block; }

.pagination { display: flex; justify-content: center; gap: 7px; margin-top: 18px; flex-wrap: wrap; }
.page-btn {
    min-width: 38px; padding: 8px 12px; border: 1px solid var(--border); background: var(--surface);
    border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: .85rem; color: var(--text-secondary); transition: var(--transition);
}
.page-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

.section-heading { font-size: 1.02rem; font-weight: 700; margin: 26px 0 14px; letter-spacing: -.01em; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
    :root { --sidebar-w: 0px; }
    .sidebar {
        width: 100%; height: auto; position: fixed; inset: auto 0 0 0; top: auto;
        flex-direction: row; border-right: none; border-top: 1px solid var(--border);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; align-items: center;
        background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
    }
    .sidebar-header, .sidebar-footer, .nav-label { display: none; }
    .nav-menu { flex-direction: row; padding: 0; width: 100%; justify-content: space-around; gap: 0; }
    .nav-item { flex-direction: column; padding: 6px 4px; font-size: .6rem; gap: 4px; text-align: center; min-height: 50px; border-radius: 12px; }
    .nav-item.active { background: none; color: var(--brand); }
    .nav-item.active::before { display: none; }
    .nav-item i { font-size: 1.25rem; }
    .main-content { margin-left: 0; max-width: 100%; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); overflow-x: hidden; }
    /* 16px sur les champs : évite le zoom automatique de Safari au focus */
    .form-input, .form-select, .form-control, .amount-field input { font-size: 16px; }
    .card { padding: 18px 16px; }
    .form-row { grid-template-columns: 1fr; }
    .budget-row { grid-template-columns: 1fr; gap: 8px; }
    .budget-input { width: 100%; }
    .charts-grid { grid-template-columns: 1fr; }
    .kpi-grid, .health-grid, .members-grid { grid-template-columns: 1fr; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    .filters-bar .form-control, .search-wrap { width: 100%; min-width: 0; }
    .topbar { padding-top: 14px; gap: 10px; }
    .topbar-actions { width: 100%; }
    .month-nav { flex: 1; justify-content: center; }
    .month-nav .month-label { flex: 1; min-width: 0; }
    .kpi-value { font-size: 1.45rem; }
    .page-title h1 { font-size: 1.3rem; }
    .modal-footer .btn, .topbar-actions .btn-primary { flex: 1; justify-content: center; }

    /* cibles tactiles >= 44px + espacement */
    .nav-item { min-height: 52px; justify-content: center; }
    .month-nav button { width: 42px; height: 42px; }
    .icon-btn { width: 44px; height: 44px; }
    .tx-item { padding: 14px 10px; }

    /* le bouton + flottant remplace le bouton d'ajout de la barre du haut */
    .fab { display: flex; bottom: calc(74px + env(safe-area-inset-bottom)); }
    .topbar-actions .btn-primary { display: none; }

    /* modales en feuille du bas (bottom sheet) */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal { max-width: 100%; border-radius: 20px 20px 0 0; max-height: 92dvh; }
    .modal-body { padding-bottom: 20px; }
    .modal-footer { position: sticky; bottom: 0; background: var(--surface); padding: 14px 24px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
    .admin-row { gap: 10px; }
    .admin-who { min-width: 140px; }
    .admin-name, .invite-box .form-control { max-width: none; width: 100%; }
    .invite-box { width: 100%; }
    .budget-figures { font-size: .8rem; }
    .detail-val { font-size: 1rem; }
}

/* ---------- Auth gate (mode cloud) ---------- */
.auth-gate {
    position: fixed; inset: 0; z-index: 3000;
    display: flex; align-items: center; justify-content: center; padding: 20px;
    background: var(--bg);
    background-image: radial-gradient(circle at 20% 20%, var(--brand-soft), transparent 40%),
                      radial-gradient(circle at 80% 80%, var(--income-soft), transparent 40%);
    animation: fadeIn .3s ease;
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 34px 30px; width: 100%; max-width: 420px; text-align: center;
}
.auth-mark {
    width: 58px; height: 58px; margin: 0 auto 18px; border-radius: 16px;
    background: linear-gradient(135deg, var(--brand-light), var(--brand-dark)); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem; box-shadow: var(--shadow-brand);
}
.auth-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-secondary); font-size: .9rem; margin-bottom: 22px; }
.auth-body { text-align: left; }
.auth-body .form-label { margin-top: 0; }
.auth-message { margin-top: 14px; min-height: 22px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
