/* ==========================================================================
   Ghar Ko Hisab — design system
   Brand: navy #0e2148 · gold #d69a18 · green #125333
   ========================================================================== */

:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f7f8fb;
    --surface-3: #eef1f6;
    --ink: #0e2148;
    --ink-2: #33415c;
    --muted: #66728c;
    --border: #e2e6ee;
    --border-strong: #cdd4e2;

    --primary: #0e2148;
    --primary-2: #1c3874;
    --primary-soft: #e8edf8;
    --gold: #d69a18;
    --gold-soft: #fcf3de;
    --income: #13794e;
    --income-soft: #e2f4ea;
    --expense: #c23b2c;
    --expense-soft: #fbe8e5;
    --warning: #b26b00;
    --warning-soft: #fdf1da;
    --info: #2b5fd9;
    --info-soft: #e7eefd;

    /* Legacy aliases used by older pages and the password vault */
    --accent: var(--income);
    --accent-deep: var(--primary);
    --danger: var(--expense);
    --paper: var(--surface);
    --paper-strong: var(--surface);
    --border-color: var(--border);

    --shadow-sm: 0 1px 2px rgba(14, 33, 72, 0.06);
    --shadow: 0 1px 2px rgba(14, 33, 72, 0.04), 0 6px 20px rgba(14, 33, 72, 0.06);
    --shadow-lg: 0 24px 60px rgba(14, 33, 72, 0.22);
    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 22px;
    --sidebar-w: 260px;
    --bottom-nav-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--ink); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.5rem; }
small { font-size: 0.82rem; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.icon {
    width: 1.15em;
    height: 1.15em;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

[hidden] { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -3rem;
    z-index: 100;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
}
.skip-link:focus { top: 1rem; }

:focus-visible { outline: 3px solid rgba(43, 95, 217, 0.45); outline-offset: 2px; }

/* ---------- Form controls ---------- */
input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
    font-size: 16px; /* prevents iOS zoom */
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { min-height: 88px; resize: vertical; }
select {
    appearance: none;
    padding-right: 2.2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366728c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1rem;
}
input::placeholder, textarea::placeholder { color: #9aa3b5; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-2);
    box-shadow: 0 0 0 3px rgba(28, 56, 116, 0.14);
}
input[type="checkbox"], input[type="radio"] {
    width: 1.15rem;
    height: 1.15rem;
    min-height: 0;
    padding: 0;
    margin: 0.2rem 0 0;
    accent-color: var(--primary);
}
input[type="file"] { padding: 0.55rem; background: var(--surface-2); border-style: dashed; }
input[type="month"], input[type="date"] { min-width: 0; }

/* ---------- App layout ---------- */
.layout { min-height: 100vh; }

.app-body .content {
    margin-left: var(--sidebar-w);
    min-width: 0;
    padding: 1.6rem 2rem 3rem;
}

.content-shell { width: min(100%, 1280px); margin: 0 auto; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.1rem 0.9rem 1rem;
    background: linear-gradient(185deg, #10275a 0%, #0b1a3c 100%);
    color: #dfe6f5;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0 0.35rem; }

.brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.brand img {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #fff;
    padding: 2px;
    object-fit: contain;
}
.brand strong { display: block; color: #fff; font-size: 1.02rem; letter-spacing: 0.01em; }
.brand small { display: block; color: rgba(223, 230, 245, 0.65); font-size: 0.78rem; }
.sidebar-head .sidebar-close { display: none; color: #fff; }

.sidebar-nav { display: grid; gap: 2px; }
.nav-label {
    margin: 0.9rem 0 0.3rem;
    padding: 0 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(223, 230, 245, 0.45);
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 42px;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    color: rgba(223, 230, 245, 0.82);
    font-weight: 500;
    font-size: 0.94rem;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a .icon { width: 1.2rem; height: 1.2rem; opacity: 0.85; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--gold);
}
.sidebar-nav a.active .icon { color: var(--gold); opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
}
.user-card { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; }
.user-card-text { display: grid; min-width: 0; }
.user-card strong { color: #fff; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-text span { color: rgba(223, 230, 245, 0.6); font-size: 0.78rem; }
.logout-form { margin: 0; }
.sidebar-logout-button {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}
.sidebar-logout-button:hover { background: rgba(255, 255, 255, 0.16); }

.drawer-backdrop { display: none; }

.mobile-topbar { display: none; }

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    width: min(100%, 1280px);
    margin: 0 auto 1.3rem;
}
.page-title h1, .page-header h2 { font-size: clamp(1.4rem, 2.4vw, 1.85rem); font-weight: 750; letter-spacing: -0.01em; }
.eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.header-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; justify-content: flex-end; }

.icon-button {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    flex: 0 0 auto;
}
.icon-button:hover { background: var(--surface-3); }
.icon-button .icon { width: 1.25rem; height: 1.25rem; }
.icon-button.small { width: 34px; height: 34px; border-radius: 9px; }
.icon-button.small .icon { width: 1rem; height: 1rem; }
.badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--expense);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 19px;
    text-align: center;
    border: 2px solid var(--bg);
}

/* ---------- Buttons ---------- */
.primary-button,
.ghost-button,
.danger-button,
.success-button,
.soft-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 42px;
    padding: 0.6rem 1.05rem;
    border-radius: 11px;
    font-weight: 600;
    font-size: 0.93rem;
    line-height: 1.2;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.primary-button:active, .ghost-button:active, .danger-button:active, .success-button:active { transform: translateY(1px); }
.primary-button { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(14, 33, 72, 0.18); }
.primary-button:hover { background: var(--primary-2); }
.ghost-button { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.ghost-button:hover { background: var(--surface-3); }
.soft-button { background: var(--primary-soft); color: var(--primary); }
.soft-button:hover { background: #dbe3f4; }
.success-button { background: var(--income); color: #fff; }
.success-button:hover { background: #0f6641; }
.danger-button { background: var(--expense-soft); color: var(--expense); border-color: rgba(194, 59, 44, 0.2); }
.danger-button:hover { background: #f7d9d4; }
.primary-button.small, .ghost-button.small, .danger-button.small, .success-button.small, .soft-button.small, .small {
    min-height: 34px;
    padding: 0.35rem 0.7rem;
    font-size: 0.84rem;
    border-radius: 9px;
}
.full-width { width: 100%; }
.link-button { color: var(--primary-2); font-weight: 600; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 0.25rem; }
.link-button:hover { text-decoration: underline; }
.desktop-only { display: inline-flex; }

/* ---------- Messages ---------- */
.messages { display: grid; gap: 0.6rem; margin-bottom: 1.1rem; }
.message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary-2);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: opacity 0.4s ease;
}
.message.success { border-left-color: var(--income); }
.message.warning { border-left-color: var(--warning); }
.message.error, .message.danger { border-left-color: var(--expense); }
.message.fade-out { opacity: 0.55; }
.message-close { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: var(--muted); }
.message-close:hover { background: var(--surface-3); }

/* ---------- Surfaces ---------- */
.panel,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.panel + .panel { margin-top: 1.1rem; }
.panel.flush { padding: 0; overflow: hidden; }

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.section-header h3 { font-size: 1.05rem; font-weight: 700; }
.section-header p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.88rem; }
.section-header > :last-child:not(:first-child) { flex: 0 0 auto; }

.muted, .help-text, .inline-note, .form-hint { color: var(--muted); }
.help-text { font-size: 0.82rem; }
.inline-note { font-size: 0.85rem; }

.stack { display: grid; gap: 0.75rem; }
.compact-stack { gap: 0.15rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.1rem; }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.grid-2 > .panel + .panel, .grid-3 > .panel + .panel, .grid-main-side > .panel + .panel,
.grid-2 > * + .panel, .grid-main-side > * > .panel + .panel { margin-top: 0; }
.mb { margin-bottom: 1.1rem; }

/* ---------- Stat cards (legacy + new) ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.1rem;
}
.stats-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-grid.three-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat-card {
    position: relative;
    display: grid;
    gap: 0.3rem;
    align-content: start;
    padding: 1rem 1.1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.stat-card > span:first-child, .stat-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}
.stat-card strong { font-size: clamp(1.2rem, 2vw, 1.5rem); font-weight: 750; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat-card small { color: var(--muted); }
.stat-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--border); }
.stat-card.success::before, .stat-card.income::before { background: var(--income); }
.stat-card.danger::before, .stat-card.expense::before { background: var(--expense); }
.stat-card.warning::before { background: var(--gold); }
.stat-card.info::before { background: var(--info); }
.stat-card.success strong, .stat-card.income strong { color: var(--income); }
.stat-card.danger strong, .stat-card.expense strong { color: var(--expense); }

.stat-icon {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--surface-3);
    color: var(--ink-2);
    margin-bottom: 0.2rem;
}
.income .stat-icon { background: var(--income-soft); color: var(--income); }
.expense .stat-icon { background: var(--expense-soft); color: var(--expense); }
.warning .stat-icon { background: var(--gold-soft); color: #946500; }
.info .stat-icon { background: var(--info-soft); color: var(--info); }

/* ---------- Month hero ---------- */
.hero {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 1.25rem;
    padding: 1.4rem 1.5rem;
    margin-bottom: 1.1rem;
    border-radius: var(--radius-lg);
    color: #fff;
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(214, 154, 24, 0.28) 0%, transparent 45%),
        linear-gradient(135deg, #10275a 0%, #0b1a3c 100%);
    box-shadow: 0 12px 32px rgba(14, 33, 72, 0.22);
    overflow: hidden;
}
.hero h2, .hero h3 { color: #fff; }
.hero-label { display: flex; align-items: center; gap: 0.5rem; color: rgba(255, 255, 255, 0.72); font-size: 0.85rem; font-weight: 600; }
.hero-amount { margin: 0.25rem 0 0.15rem; font-size: clamp(1.9rem, 4.5vw, 2.6rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.hero-amount.negative { color: #ffb4a8; }
.hero-sub { color: rgba(255, 255, 255, 0.72); font-size: 0.9rem; margin: 0; }
.hero-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; align-content: center; }
.hero-stat {
    padding: 0.8rem 0.9rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-width: 0;
}
.hero-stat span { display: flex; align-items: center; gap: 0.35rem; color: rgba(255, 255, 255, 0.7); font-size: 0.8rem; }
.hero-stat strong { display: block; margin-top: 0.15rem; font-size: 1.12rem; font-weight: 700; overflow-wrap: anywhere; }
.hero-stat.in strong { color: #8fe3b6; }
.hero-stat.out strong { color: #ffb4a8; }
.hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }
.hero-actions .ghost-button { background: rgba(255, 255, 255, 0.1); color: #fff; border-color: rgba(255, 255, 255, 0.2); }
.hero-actions .ghost-button:hover { background: rgba(255, 255, 255, 0.18); }
.hero-actions .primary-button { background: var(--gold); color: #1a1405; box-shadow: none; }
.hero-actions .primary-button:hover { background: #e6aa29; }
.hero .progress { background: rgba(255, 255, 255, 0.15); }
.hero-progress { margin-top: 0.9rem; }
.hero-progress-row { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8rem; color: rgba(255, 255, 255, 0.75); margin-bottom: 0.35rem; }

/* ---------- Month nav, chips, filters ---------- */
.month-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.month-nav {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.month-step {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    color: var(--ink-2);
}
.month-step:hover { background: var(--surface-3); }
.month-picker { position: relative; margin: 0; }
.month-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 150px;
    justify-content: center;
    padding: 0 0.6rem;
    font-weight: 700;
    white-space: nowrap;
}
.month-label .icon { color: var(--muted); }
.month-picker input[type="month"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    min-height: 0;
    padding: 0;
    border: 0;
}
.month-picker input[type="month"]::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 34px;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-2);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}
a.chip:hover { border-color: var(--border-strong); background: var(--surface-2); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip strong { font-weight: 700; }
.chip-row { display: flex; gap: 0.45rem; flex-wrap: wrap; }

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 0;
}
.filter-bar select, .filter-bar input { width: auto; min-height: 40px; font-size: 0.9rem; }
.filter-bar select { min-width: 140px; }
.search-input { position: relative; }
.search-input .icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-input input { padding-left: 2.2rem; min-width: 190px; }

.soft-pill, .meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface-3);
    color: var(--ink-2);
}
.notification-pill { display: inline-flex; align-items: center; gap: 0.5rem; }

/* ---------- Tabs (segmented) ---------- */
.tabs {
    display: inline-flex;
    gap: 3px;
    padding: 4px;
    border-radius: 13px;
    background: var(--surface-3);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--muted);
    white-space: nowrap;
}
.tabs a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.tabs .count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: rgba(14, 33, 72, 0.08); font-size: 0.75rem; text-align: center; }

/* ---------- Progress ---------- */
.progress {
    position: relative;
    height: 8px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}
.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary-2);
    transition: width 0.4s ease;
}
.progress.income > span, .progress.ok > span { background: var(--income); }
.progress.near > span, .progress.gold > span { background: var(--gold); }
.progress.over > span, .progress.expense > span { background: var(--expense); }
.progress.thin { height: 6px; }

/* ---------- Lists (transactions, dues) ---------- */
.list { display: grid; }
.list-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem 0.15rem;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}
.list-item:last-child { border-bottom: 0; }
.list-item.link:hover { background: var(--surface-2); }
.list-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: 12px;
    background: var(--surface-3);
    color: var(--ink-2);
}
.list-icon.income, .list-icon.recover { background: var(--income-soft); color: var(--income); }
.list-icon.expense, .list-icon.settle { background: var(--expense-soft); color: var(--expense); }
.list-icon.bill, .list-icon.emi, .list-icon.card { background: var(--info-soft); color: var(--info); }
.list-main { flex: 1; min-width: 0; }
.list-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { display: block; color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-end { display: grid; justify-items: end; gap: 0.2rem; text-align: right; flex: 0 0 auto; }
.list-actions { display: flex; gap: 0.35rem; align-items: center; flex: 0 0 auto; }
.list-actions form { margin: 0; }

.amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount.in, .text-income { color: var(--income); }
.amount.out, .text-expense { color: var(--expense); }
.text-warning { color: var(--warning); }
.num { font-variant-numeric: tabular-nums; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.5rem;
    border-radius: 6px;
    font-size: 0.74rem;
    font-weight: 700;
    background: var(--surface-3);
    color: var(--ink-2);
    white-space: nowrap;
}
.tag.overdue, .tag.over, .tag.rejected { background: var(--expense-soft); color: var(--expense); }
.tag.pending, .tag.near, .tag.soon { background: var(--warning-soft); color: var(--warning); }
.tag.ok, .tag.approved, .tag.settled, .tag.paid { background: var(--income-soft); color: var(--income); }

/* ---------- Avatars & people ---------- */
.avatar {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    background: var(--primary-2);
}
.avatar.lg { width: 52px; height: 52px; font-size: 1.05rem; }
.avatar.sm { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar.tone-0 { background: #1c3874; }
.avatar.tone-1 { background: #13794e; }
.avatar.tone-2 { background: #b4790f; }
.avatar.tone-3 { background: #8a3fb0; }
.avatar.tone-4 { background: #c23b2c; }
.avatar.tone-5 { background: #157a8c; }
.avatar.shared { background: var(--surface-3); color: var(--ink-2); }

.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.9rem; }
.member-card {
    display: grid;
    gap: 0.8rem;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.member-card.inactive { opacity: 0.65; }
.member-head { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.member-head > div { min-width: 0; }
.member-head strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-head small { color: var(--muted); }
.member-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem; }
.member-figures div { padding: 0.5rem 0.55rem; border-radius: 10px; background: var(--surface-2); min-width: 0; }
.member-figures span { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.member-figures strong { display: block; font-size: 0.88rem; overflow-wrap: anywhere; }
.member-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.member-actions form { margin: 0; }

.member-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 0.8rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: 0; }
.member-row .member-head { grid-column: 1; }
.member-row .member-amounts { grid-column: 2; text-align: right; display: grid; gap: 0.1rem; font-size: 0.85rem; }
.member-row .progress { grid-column: 1 / -1; }

/* ---------- Budget rows ---------- */
.budget-row { display: grid; gap: 0.4rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: 0; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.budget-name { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; min-width: 0; }
.budget-name .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.budget-meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); }

/* ---------- Key/value summary ---------- */
.kv { display: grid; gap: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px dashed var(--border); font-size: 0.92rem; }
.kv > div:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv .total { border-top: 1px solid var(--border-strong); border-bottom: 0; margin-top: 0.2rem; padding-top: 0.75rem; font-weight: 700; }
.kv .total span { color: var(--ink); }

.summary-list { display: grid; gap: 0.55rem; }
.summary-list > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.summary-list span { color: var(--muted); }
.summary-stack { display: grid; gap: 1rem; }
.summary-stack h4 { margin: 0 0 0.6rem; }
.compact-summary > div { padding: 0.55rem 0.75rem; }

/* ---------- Loan cards (lend & borrow) ---------- */
.loan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.9rem; }
.loan-card {
    display: grid;
    gap: 0.8rem;
    padding: 1rem 1.05rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
/* Safari won't shrink grid items below their content without this. */
.loan-grid > *, .member-grid > *, .grid-2 > *, .grid-3 > *, .grid-main-side > *, .stats-grid > *, .dashboard-grid > * { min-width: 0; }
.loan-remaining { flex: 0 0 auto; }
.loan-card, .member-card, .chart-panel, .stack { grid-template-columns: minmax(0, 1fr); }
.loan-card.overdue { border-color: rgba(194, 59, 44, 0.35); box-shadow: 0 0 0 3px rgba(194, 59, 44, 0.06); }
.loan-card-top { display: flex; align-items: flex-start; gap: 0.75rem; }
.loan-card-top > div { flex: 1; min-width: 0; }
.loan-card-top strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loan-card-top small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loan-remaining { text-align: right; }
.loan-remaining span { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.loan-remaining strong { font-size: 1.15rem; }
.loan-meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); }
.loan-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.loan-actions form { margin: 0; }
.loan-actions > * { flex: 1 1 auto; }

.person-list { display: grid; gap: 0; }
.person-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
.person-row:last-child { border-bottom: 0; }
.person-row > div:nth-child(2) { flex: 1; min-width: 0; }
.person-row strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row small { color: var(--muted); }

/* ---------- Quick links (legacy dashboard tiles) ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; margin-bottom: 1.1rem; }
.quick-link {
    display: grid;
    gap: 0.25rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.quick-link:hover { border-color: var(--border-strong); }
.quick-link span { color: var(--muted); font-size: 0.85rem; }

.shortcut-row { display: flex; gap: 0.6rem; overflow-x: auto; padding-bottom: 0.25rem; scrollbar-width: thin; }
.shortcut {
    display: grid;
    gap: 0.35rem;
    min-width: 170px;
    padding: 0.8rem 0.9rem;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.shortcut-top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.shortcut-top strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shortcut small { color: var(--muted); }
.shortcut-actions { display: flex; gap: 0.35rem; }
.shortcut-actions form { margin: 0; flex: 1; }
.shortcut-actions button { width: 100%; }

/* legacy preset cards */
.preset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.preset-card { display: grid; gap: 0.75rem; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
.preset-card p { margin: 0; }
.preset-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.amount-chip { display: inline-flex; padding: 0.3rem 0.7rem; border-radius: 999px; background: var(--income-soft); color: var(--income); font-weight: 700; white-space: nowrap; }

/* ---------- Mini cards (legacy) ---------- */
.mini-card,
.notification-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}
.mini-card > div:first-child { display: grid; gap: 0.15rem; min-width: 0; }
.mini-card span, .mini-card small { color: var(--muted); }
.notification-card.read { opacity: 0.65; }

/* ---------- Charts ---------- */
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem; }
.dashboard-grid > .panel + .panel { margin-top: 0; }
.chart-panel { display: grid; gap: 0.75rem; align-content: start; }
.chart-surface { display: grid; gap: 0.75rem; }
.chart-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chart-frame { position: relative; height: 300px; min-height: 0; }
.chart-frame.short { height: 220px; }
.doughnut-frame { height: 300px; }
.chart-frame canvas { width: 100% !important; height: 100% !important; display: block; }
.chart-fallback {
    display: grid;
    gap: 0.3rem;
    padding: 0.9rem;
    border-radius: 12px;
    background: var(--warning-soft);
    color: var(--warning);
}

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; margin: 0 -0.25rem; padding: 0 0.25rem; }
table { width: 100%; border-collapse: collapse; min-width: 680px; font-size: 0.92rem; }
th, td { padding: 0.75rem 0.65rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--surface-2);
    white-space: nowrap;
}
th:first-child { border-top-left-radius: 10px; }
th:last-child { border-top-right-radius: 10px; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }

.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.mobile-meta { display: none; }
.action-row form { margin: 0; }

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    background: var(--surface-3);
    color: var(--ink-2);
    white-space: nowrap;
}
.status-badge.approved, .status-badge.paid, .status-badge.settled { color: var(--income); background: var(--income-soft); }
.status-badge.pending, .status-badge.upcoming, .status-badge.open { color: var(--warning); background: var(--warning-soft); }
.status-badge.partial { color: var(--info); background: var(--info-soft); }
.status-badge.rejected, .status-badge.overdue { color: var(--expense); background: var(--expense-soft); }

/* ---------- Empty states ---------- */
.empty-state, .empty {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
}
.empty .empty-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--surface-3);
    color: var(--muted);
}
.empty .empty-icon .icon { width: 1.5rem; height: 1.5rem; }
.empty strong { color: var(--ink); }
.empty-panel { display: grid; gap: 0.7rem; justify-items: start; }

/* ---------- Forms ---------- */
.form-panel { max-width: 820px; }
.form-card-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.1rem; }
.form-card-head .list-icon { width: 46px; height: 46px; }
.form-card-head h2 { font-size: 1.15rem; }
.form-card-head p { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.88rem; }

.form-grid { display: grid; gap: 0 1rem; }
.form-grid.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-group { display: grid; gap: 0.35rem; align-content: start; margin-bottom: 1rem; min-width: 0; }
.form-group > label, .choice-group legend { font-weight: 600; font-size: 0.9rem; color: var(--ink-2); }
.form-group .required { color: var(--expense); }
.full-span { grid-column: 1 / -1; }
.form-group.has-error input, .form-group.has-error select, .form-group.has-error textarea { border-color: var(--expense); }

.amount-input { position: relative; }
.amount-input > span {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-weight: 700;
    pointer-events: none;
}
.amount-input input { padding-left: 2.6rem; font-size: 1.3rem; font-weight: 700; min-height: 52px; }

.form-group.checkbox-group {
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 0.7rem;
    padding: 0.8rem 0.9rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.form-group.checkbox-group label { font-weight: 600; }
.compact-checkbox { margin-top: 0.25rem; }

.choice-group { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
.choice-group legend { margin-bottom: 0.45rem; padding: 0; }
.choice-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.6rem; }
.choice-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 0.95rem;
    border-radius: 12px;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.choice-card input { margin: 0; }
.choice-card:has(input:checked) { border-color: var(--primary-2); background: var(--primary-soft); }
.choice-card:has(input[value="lent"]:checked) { border-color: var(--income); background: var(--income-soft); color: #0c5535; }
.choice-card:has(input[value="borrowed"]:checked) { border-color: var(--expense); background: var(--expense-soft); color: #8d2519; }

.form-hint, .current-file { font-size: 0.88rem; color: var(--muted); }
.current-file {
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    margin-bottom: 1rem;
}
.current-file a { color: var(--primary-2); font-weight: 600; }

.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 0.4rem; }
.form-actions .spacer { flex: 1; }

.form-errors {
    margin-bottom: 1rem;
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    border: 1px solid rgba(194, 59, 44, 0.25);
    background: var(--expense-soft);
    color: #8d2519;
}
.form-errors ul { margin: 0; padding-left: 1.1rem; }
.field-error { color: var(--expense); font-size: 0.84rem; }
.field-error ul, .errorlist { margin: 0; padding-left: 1rem; color: var(--expense); font-size: 0.84rem; }

.budget-inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.2rem 1rem; }
.budget-inputs .form-group label { display: flex; align-items: center; gap: 0.45rem; }
.budget-inputs .dot { width: 10px; height: 10px; border-radius: 3px; }
.previous-hint { font-size: 0.78rem; color: var(--muted); }

/* ---------- Categories ---------- */
.category-row { margin: 0; }
.category-row input[type="text"] { min-height: 38px; padding: 0.4rem 0.6rem; font-size: 0.95rem; font-weight: 600; border-color: transparent; background: transparent; }
.category-row input[type="text"]:hover { border-color: var(--border); }
.category-row input[type="text"]:focus { border-color: var(--primary-2); background: var(--surface); }
.category-row .list-sub { padding-left: 0.6rem; }
.color-swatch { width: 36px; height: 36px; min-height: 0; padding: 2px; border-radius: 10px; cursor: pointer; flex: 0 0 auto; }

/* ---------- Reports ---------- */
.story-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.story-list li { display: flex; align-items: center; gap: 0.8rem; padding: 0.55rem 0; font-size: 0.97rem; line-height: 1.5; }
.story-list li + li { border-top: 1px dashed var(--border); }
.story-list .list-icon { width: 34px; height: 34px; border-radius: 10px; }
.report-table tfoot td { border-top: 2px solid var(--border-strong); border-bottom: 0; background: var(--surface-2); }
.report-table tr.is-empty td { color: var(--muted); }
.report-table tr.is-empty td strong { font-weight: 500; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 1rem; }
.pagination-info { color: var(--muted); font-size: 0.88rem; }

/* ---------- Auth ---------- */
.guest-body { background: radial-gradient(90% 70% at 50% 0%, #e7ecf8 0%, var(--bg) 60%); }
.guest-body .content { margin: 0; padding: 1.5rem; }
.auth-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.guest-body .content-shell { max-width: 440px; }
.auth-card { display: grid; gap: 1rem; padding: 1.75rem; box-shadow: var(--shadow); }
.auth-card-single { max-width: 440px; margin: 0 auto; }
.auth-form { display: grid; gap: 0.2rem; }
.auth-form h3 { font-size: 1.4rem; margin-bottom: 0.9rem; }
.auth-brand { display: flex; justify-content: center; margin-bottom: 0.25rem; }
.auth-brand img { width: min(100%, 210px); height: auto; }
.password-field { position: relative; }
.password-field input { padding-right: 5rem; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    padding: 0.35rem 0.7rem;
    border-radius: 8px;
    background: var(--surface-3);
    color: var(--ink-2);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ---------- Bottom nav & quick-add sheet ---------- */
.bottom-nav { display: none; }

.sheet {
    width: min(560px, calc(100% - 2rem));
    padding: 1.2rem;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-lg);
}
.sheet::backdrop { background: rgba(9, 19, 43, 0.5); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheet-in 0.18s ease-out; }
@keyframes sheet-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.sheet-head h2 { font-size: 1.1rem; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem; }
.sheet-option {
    display: grid;
    gap: 0.2rem;
    justify-items: start;
    padding: 0.9rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.sheet-option:hover { border-color: var(--border-strong); background: var(--surface); }
.sheet-option strong { font-size: 0.95rem; }
.sheet-option small { color: var(--muted); font-size: 0.78rem; }
.sheet-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; margin-bottom: 0.35rem; background: var(--surface-3); }
.sheet-option.income .sheet-icon, .sheet-option.recover .sheet-icon { background: var(--income-soft); color: var(--income); }
.sheet-option.expense .sheet-icon, .sheet-option.settle .sheet-icon { background: var(--expense-soft); color: var(--expense); }
.sheet-option.bill .sheet-icon { background: var(--info-soft); color: var(--info); }
.sheet-option.plan .sheet-icon { background: var(--gold-soft); color: #946500; }

/* ---------- Misc legacy helpers ---------- */
.house-build-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.house-build-insights { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.house-build-grid { margin-bottom: 1.1rem; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; align-items: end; }
.warning-panel { border-left: 4px solid var(--expense); }
.detail-note-card { padding: 1rem; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); line-height: 1.65; }
.feature-list { padding-left: 1rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats-grid.three-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-main-side { grid-template-columns: minmax(0, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .quick-grid, .preset-grid, .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet & phone: off-canvas drawer + bottom navigation */
@media (max-width: 1023px) {
    .app-body .content {
        margin-left: 0;
        padding: 0 1rem calc(var(--bottom-nav-h) + var(--safe-bottom) + 1.5rem);
    }

    .sidebar {
        width: min(300px, 86vw);
        transform: translateX(-102%);
        transition: transform 0.22s ease;
        box-shadow: var(--shadow-lg);
        z-index: 60;
    }
    .drawer-open .sidebar { transform: none; }
    .drawer-open { overflow: hidden; }
    .sidebar-head .sidebar-close { display: inline-grid; background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.12); }
    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(9, 19, 43, 0.5);
    }
    .drawer-backdrop[hidden] { display: none; }

    .mobile-topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.6rem;
        margin: 0 -1rem 1rem;
        padding: calc(env(safe-area-inset-top, 0px) + 0.6rem) 1rem 0.6rem;
        background: rgba(243, 245, 249, 0.9);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
    }
    .mobile-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 750; min-width: 0; }
    .mobile-brand img { width: 32px; height: 32px; border-radius: 8px; background: #fff; border: 1px solid var(--border); object-fit: contain; }
    .mobile-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    .desktop-only { display: none; }

    .page-header { align-items: flex-start; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
    .header-actions { justify-content: flex-start; width: 100%; }

    .bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 35;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: center;
        height: calc(var(--bottom-nav-h) + var(--safe-bottom));
        padding: 0 0.25rem var(--safe-bottom);
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 20px rgba(14, 33, 72, 0.06);
    }
    .bottom-nav a, .bottom-nav button:not(.fab) {
        display: grid;
        justify-items: center;
        gap: 0.15rem;
        padding: 0.35rem 0;
        color: var(--muted);
        font-size: 0.7rem;
        font-weight: 600;
    }
    .bottom-nav .icon { width: 1.35rem; height: 1.35rem; }
    .bottom-nav a.active { color: var(--primary); }
    .bottom-nav a.active .icon { stroke-width: 2.4; }
    .fab {
        justify-self: center;
        display: grid;
        place-items: center;
        width: 54px;
        height: 54px;
        margin-top: -22px;
        border-radius: 18px;
        background: var(--primary);
        color: #fff;
        box-shadow: 0 8px 20px rgba(14, 33, 72, 0.35), 0 0 0 4px var(--bg);
    }
    .fab .icon { width: 1.6rem; height: 1.6rem; stroke-width: 2.4; }

    .sheet {
        width: 100%;
        max-width: 100%;
        margin: auto 0 0;
        padding: 1rem 1rem calc(1rem + var(--safe-bottom));
        border-radius: 22px 22px 0 0;
    }
    .sheet[open] { animation: sheet-up 0.22s ease-out; }
    @keyframes sheet-up { from { transform: translateY(40%); } to { transform: none; } }
    .sheet-head::before {
        content: "";
        position: absolute;
        top: 8px;
        left: 50%;
        width: 40px;
        height: 4px;
        border-radius: 99px;
        background: var(--border-strong);
        transform: translateX(-50%);
    }
    .sheet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .hero { grid-template-columns: minmax(0, 1fr); }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
    .form-grid.two-up { grid-template-columns: minmax(0, 1fr); }
    .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .stats-grid.three-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .house-build-summary, .house-build-insights { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel { padding: 1rem; }
    .toolbar { align-items: stretch; }
    .filter-bar { width: 100%; }
    .filter-bar > * { flex: 1 1 140px; }
    .filter-bar select, .filter-bar input, .search-input input { width: 100%; min-width: 0; }
    .month-bar { width: 100%; }
    .month-nav { flex: 1; justify-content: space-between; }
    .month-label { min-width: 0; }
    .loan-grid { grid-template-columns: minmax(0, 1fr); }
    .form-actions > .primary-button, .form-actions > .ghost-button, .form-actions > button { flex: 1 1 auto; }
    .form-actions .spacer { display: none; }
    .section-header { flex-wrap: wrap; }
    .chart-frame, .doughnut-frame { height: 240px; }
    .hero { padding: 1.15rem; }
    .hero-stat strong { font-size: 1rem; }
    .member-grid { grid-template-columns: minmax(0, 1fr); }
    .stats-grid.three-up > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Tables collapse into cards on phones */
@media (max-width: 640px) {
    body { font-size: 14.5px; }
    .stats-grid, .quick-grid, .preset-grid, .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
    .stat-card { padding: 0.8rem 0.85rem; }
    .stat-card strong { font-size: 1.12rem; }
    .list-item { gap: 0.65rem; }
    .list-icon { width: 36px; height: 36px; border-radius: 10px; }
    .list-actions .label { display: none; }

    .table-responsive { overflow: visible; margin: 0; padding: 0; }
    table, thead, tbody, tfoot, th, td, tr { display: block; min-width: 0; }
    tfoot { margin-top: 0.6rem; }
    .report-table tfoot td { border-top: 0; border-bottom: 1px dashed var(--border); background: transparent; }
    .report-table tfoot tr { border-color: var(--border-strong); background: var(--surface-2); }
    .report-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.35rem 0.6rem; padding: 0.75rem 0.85rem; }
    .report-table td { display: block; padding: 0; border: 0; text-align: left; }
    .report-table td::before { display: block; max-width: none; margin-bottom: 0.1rem; font-size: 0.68rem; }
    .report-table td:first-child { grid-column: 1 / 3; }
    .report-table td:first-child::before, .report-table td:last-child::before { content: none; }
    .report-table td:last-child { grid-column: 3; grid-row: 1; text-align: right; }
    .report-table td.num { text-align: left; }
    thead { display: none; }
    tbody { display: grid; gap: 0.6rem; }
    tbody tr:hover td { background: transparent; }
    tr { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); padding: 0.25rem 0.85rem; }
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.55rem 0;
        border-bottom: 1px dashed var(--border);
        text-align: right;
        overflow-wrap: anywhere;
    }
    td:last-child { border-bottom: 0; }
    td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        color: var(--muted);
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        text-align: left;
    }
    td:not([data-label])::before { content: none; }
    td.empty-state, td[colspan] { display: block; text-align: center; }
    td .action-row { justify-content: flex-end; }
    td.num { text-align: right; }

    /* Compact transaction cards: title + amount, one meta line, then status/actions */
    .tx-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.25rem 0.75rem;
        padding: 0.8rem 0.9rem;
    }
    .tx-table td { display: block; padding: 0; border: 0; text-align: left; }
    .tx-table td::before { content: none; }
    .tx-table .c-hide-sm { display: none; }
    .tx-table .c-main { grid-column: 1; grid-row: 1; min-width: 0; }
    .tx-table .c-amount { grid-column: 2; grid-row: 1; text-align: right; }
    .tx-table .c-status { grid-column: 2; grid-row: 2; text-align: right; align-self: start; }
    .tx-table .c-actions { grid-column: 1 / -1; }
    .tx-table .c-actions:not(:has(*)) { display: none; }
    .tx-table .c-actions .action-row { justify-content: flex-end; padding-top: 0.55rem; margin-top: 0.3rem; border-top: 1px dashed var(--border); }
    .tx-table .mobile-meta { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.8rem; }
    .tx-table .c-main .inline-note { font-size: 0.78rem; }
    .tx-table td[colspan] { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
    .stats-grid, .stats-grid.three-up { grid-template-columns: minmax(0, 1fr); }
    .hero-stats { grid-template-columns: minmax(0, 1fr); }
    .sheet-grid { grid-template-columns: minmax(0, 1fr); }
}

@media print {
    .sidebar, .bottom-nav, .mobile-topbar, .header-actions, .sheet { display: none !important; }
    .app-body .content { margin: 0; padding: 0; }
}

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

/* Amount privacy: charts carry no data while locked, so show a notice instead. */
.amounts-locked canvas { display: none !important; }
.amounts-locked .chart-frame::after { content: "Amounts are hidden"; display: flex; align-items: center; justify-content: center; min-height: 140px; color: #66728c; }
.pin-dialog { border: 0; border-radius: 12px; padding: 1.25rem; box-shadow: 0 10px 40px #0005; }
.pin-dialog::backdrop { background: #0007; }

/* Family chat */
.chat-panel { display: flex; flex-direction: column; gap: 0.75rem; }
.chat-messages { display: flex; flex-direction: column; gap: 0.5rem; height: 55vh; overflow-y: auto; }
.chat-bubble { align-self: flex-start; max-width: 80%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.chat-bubble.mine { align-self: flex-end; background: var(--surface-3); }
.chat-bubble small { opacity: 0.7; }
.chat-bubble p { margin: 0.15rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-form textarea { flex: 1; min-width: 0; resize: none; }

/* Calculator and the sidebar items that open things */
.sidebar-nav .nav-button { display: flex; align-items: center; gap: 0.7rem; width: 100%; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.nav-count { margin-left: auto; min-width: 1.4rem; padding: 0 0.4rem; border-radius: 999px; background: #c0392b; color: #fff; font-size: 0.75rem; text-align: center; }
.calculator { width: min(92vw, 320px); }
.calc-screen { width: 100%; font-size: 1.6rem; text-align: right; }
.calc-preview { min-height: 1.5rem; text-align: right; opacity: 0.75; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin: 0.5rem 0 0.75rem; }
.calc-keys button { padding: 0.75rem 0; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 1.1rem; cursor: pointer; }
.calc-keys button:active { background: var(--surface-3); }
.calc-keys .calc-equals { grid-column: span 4; background: var(--primary); color: #fff; }
