/* ==========================================================================
   LedgerLine — Design System
   Blue = trust/structure, teal = income/growth, coral = highlights/expense
   accents. Kept neutral and financial rather than tied to any one brand —
   the default site icon is a plain wallet mark; the real identity comes
   from whatever name and icon each user sets during setup.
   ========================================================================== */

:root {
    /* Brand */
    --blue-700: #003084;
    --blue-600: #0C54C0;
    --blue-500: #1D63D8;
    --teal-600: #009CB4;
    --teal-500: #18C0A8;
    --coral-500: #FC6060;
    --coral-400: #FC846C;

    /* Neutrals */
    --ink: #101828;
    --ink-soft: #475467;
    --ink-faint: #98A2B3;
    --line: #E4E7EC;
    --line-soft: #F0F2F5;
    --bg-app: #F7F8FA;
    --bg-surface: #FFFFFF;
    --bg-surface-alt: #F4F6F8;

    /* Semantic */
    --income: #0F9D6B;
    --income-bg: #E7F7F0;
    --expense: #D6425C;
    --expense-bg: #FCEAEE;
    --warn: #B5750B;
    --warn-bg: #FDF3DF;

    /* Type */
    --font-display: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-app);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

html[dir="rtl"] body {
    font-family: 'Arial', 'Segoe UI', sans-serif;
}

html[dir="rtl"] .text-right {
    text-align: left;
}

html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea {
    text-align: right;
}

html[dir="rtl"] .data-table th,
html[dir="rtl"] .data-table td {
    text-align: right;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 8px;
    color: var(--ink);
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

.mono { font-family: var(--font-mono); }

/* ---------------- Layout shell ---------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 248px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--blue-700) 0%, #041D52 100%);
    color: #C9D6EE;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 22px;
}

.sidebar-brand img { width: 36px; height: 36px; }

.sidebar-brand-text { font-family: var(--font-display); font-weight: 800; font-size: 19px; color: #fff; letter-spacing: -0.01em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 14px; }

.sidebar-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #6E88BD;
    font-weight: 700;
    margin: 20px 10px 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #C9D6EE;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }

.sidebar-link.active {
    background: rgba(255,255,255,0.14);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--teal-500);
}

/* Inline SVG icons (includes/icons.php): sized by font-size, coloured by currentColor. */
.ic { width: 1em; height: 1em; display: inline-block; vertical-align: -0.14em; flex-shrink: 0; }
.btn .ic, .badge .ic { margin-inline-end: 2px; }
.task-check .ic { stroke-width: 3; }

.sidebar-link .icon { width: 18px; display: inline-flex; justify-content: center; font-size: 17px; opacity: 0.9; }

.sidebar-footer {
    padding: 16px 18px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.sidebar-user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--teal-500); color: #04322C;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 13px; flex-shrink: 0;
}

.sidebar-user-name { color: #fff; font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.sidebar-user-role { color: #8FA6D6; font-size: 11.5px; }

.sidebar-logout {
    display: block; text-align: center; padding: 8px;
    border-radius: 8px; font-size: 13px; font-weight: 600;
    color: #C9D6EE; border: 1px solid rgba(255,255,255,0.16);
}
.sidebar-logout:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }

/* ---------------- Main content ---------------- */

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 72px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 { font-size: 21px; margin: 0; }
.topbar-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }

.content { padding: 28px 32px 60px; max-width: 1320px; width: 100%; margin: 0 auto; }

/* ---------------- Buttons ---------------- */

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--font-body); font-weight: 700; font-size: 14px;
    padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
    cursor: pointer; transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--blue-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--blue-700); box-shadow: var(--shadow-md); color: #fff; }

.btn-teal { background: var(--teal-500); color: #04322C; }
.btn-teal:hover { background: var(--teal-600); color: #fff; }

.btn-coral { background: var(--coral-500); color: #fff; }
.btn-coral:hover { background: #E14848; color: #fff; }

.btn-outline { background: var(--bg-surface); color: var(--ink); border-color: var(--line); }
.btn-outline:hover { background: var(--bg-surface-alt); border-color: var(--ink-faint); color: var(--ink); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg-surface-alt); color: var(--ink); }

.btn-danger { background: var(--expense-bg); color: var(--expense); }
.btn-danger:hover { background: var(--expense); color: #fff; }

.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 8px; white-space: nowrap; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- Cards / surfaces ---------------- */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.card-pad { padding: 22px 24px; }

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px; border-bottom: 1px solid var(--line);
}
.card-header h3 { font-size: 15.5px; margin: 0; }

/* ---------------- KPI stat cards ---------------- */

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.stat-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.stat-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .stat-grid:not(.cols-2):not(.cols-3) { grid-template-columns: repeat(2, 1fr); } }

/* ---------------- Page layout grids (collapse to one column on small screens) ---------------- */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-main-side { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.breakdown-grid { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: center; }
.breakdown-chart { height: 220px; }
@media (max-width: 900px) { .grid-2, .grid-main-side { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--radius-md);
    padding: 20px 22px; box-shadow: var(--shadow-sm);
}
.stat-icon {
    width: 40px; height: 40px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; margin-bottom: 14px;
}
.stat-icon.income { background: var(--income-bg); color: var(--income); }
.stat-icon.expense { background: var(--expense-bg); color: var(--expense); }
.stat-icon.net { background: #E9EEFC; color: var(--blue-600); }
.stat-icon.coral { background: #FFEDE9; color: var(--coral-500); }

.stat-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); margin-bottom: 6px; }
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }

/* ---------------- Hero banner ---------------- */

.hero-banner {
    background: linear-gradient(120deg, var(--blue-700) 0%, var(--blue-600) 55%, var(--teal-600) 100%);
    border-radius: var(--radius-lg);
    padding: 30px 34px;
    color: #fff;
    margin-bottom: 22px;
    position: relative;
    overflow: hidden;
}
.hero-banner::after {
    content: "";
    position: absolute; right: -60px; top: -60px; width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(252,96,96,0.35), transparent 70%);
}
.hero-banner h2 { color: #fff; font-size: 24px; margin-bottom: 6px; }
.hero-banner p { color: #CFE0F7; margin: 0; font-size: 13.5px; max-width: 480px; }

/* ---------------- Tables ---------------- */

.table-wrap { overflow-x: auto; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.data-table thead th {
    text-align: left; padding: 12px 16px; background: var(--bg-surface-alt);
    color: var(--ink-soft); font-weight: 700; font-size: 11.5px; text-transform: uppercase;
    letter-spacing: 0.04em; border-bottom: 1px solid var(--line); white-space: nowrap;
}

.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; white-space: nowrap; }
.data-table tbody tr:hover { background: var(--bg-surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Ledger date cell: "Recurring" / "Pending charge" badges drop below the date instead of widening the table. */
.data-table td.ledger-date .badge { display: table; margin-top: 4px; white-space: normal; max-width: 150px; line-height: 1.35; border-radius: 6px; padding: 3px 8px; }
.amount-income { color: var(--income); font-weight: 700; font-family: var(--font-mono); }
.amount-expense { color: var(--expense); font-weight: 700; font-family: var(--font-mono); }
/* Signed amounts ("-$5.00") are printed as sign + amount; keep them left-to-right in Hebrew. */
html[dir="rtl"] .amount-income, html[dir="rtl"] .amount-expense, html[dir="rtl"] .cf-amount { direction: ltr; unicode-bidi: isolate; }

.badge {
    display: inline-block; padding: 3px 10px; border-radius: 100px;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-income { background: var(--income-bg); color: var(--income); }
.badge-expense { background: var(--expense-bg); color: var(--expense); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-admin { background: #E9EEFC; color: var(--blue-600); }
.badge-neutral { background: var(--bg-surface-alt); color: var(--ink-soft); }

/* ---------------- Forms ---------------- */

.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.form-group > label.field-label,
.form-group > .field-label { letter-spacing: 0.02em; }
.form-group:has(input:focus, select:focus, textarea:focus) > .field-label { color: var(--blue-600); }

label.field-label {
    display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em;
}
label.field-label .req { color: var(--coral-500); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
    width: 100%; padding: 12px 13px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px;
    font-family: var(--font-body); font-size: 14px; color: var(--ink); background: var(--bg-surface);
    transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(29,99,216,0.12);
    background: #fff;
}
textarea { resize: vertical; min-height: 80px; }

input::placeholder, textarea::placeholder { color: #A7B0BF; }
input:disabled { cursor: not-allowed; opacity: 0.78; }
input[type=checkbox] { width: 17px; height: 17px; min-height: 0; accent-color: var(--blue-600); }
input[type=file] { width: 100%; padding: 9px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg-surface-alt); color: var(--ink-soft); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.admin-create-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.admin-create-card .card-pad { padding-bottom: 26px; }
.admin-users-card .table-wrap { overflow-x: auto; }
.admin-users-card .data-table { min-width: 980px; }
.admin-users-card .data-table th:last-child { min-width: 245px; }
.admin-user-actions { min-width: 245px; }
.admin-action-group { display: flex; align-items: center; justify-content: flex-end; gap: 5px; flex-wrap: wrap; }
.admin-action-group form { display: inline-flex; }
.admin-action-group .btn { padding-inline: 9px; }
.admin-backup-card { margin-top: 24px; }
.backup-actions { display: flex; align-items: stretch; gap: 12px; flex-wrap: wrap; }
.restore-form { display: flex; align-items: stretch; gap: 12px; flex: 1; min-width: min(100%, 420px); }
/* File chooser (file_picker() in helpers.php): the whole dashed box opens the file dialog and accepts drops. */
.file-picker { position: relative; display: flex; align-items: center; gap: 10px; min-width: min(100%, 260px); flex: 1; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg-surface-alt); cursor: pointer; text-transform: none; letter-spacing: normal; font-weight: 400; margin: 0; }
.file-picker:hover, .file-picker.is-dragover { border-color: var(--blue-500); background: #F8FAFD; }
.file-picker.is-dragover { border-style: solid; box-shadow: 0 0 0 3px rgba(29, 99, 216, 0.12); }
.file-picker:focus-within { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(29, 99, 216, 0.12); }
.file-picker-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; border-radius: 7px; background: var(--bg-surface); border: 1px solid var(--line); color: var(--blue-600); font-size: 13px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.file-picker:hover .file-picker-button { border-color: var(--blue-500); background: #fff; }
.file-picker-name { color: var(--ink-faint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-picker.has-file .file-picker-name { color: var(--ink); font-weight: 600; }
/* Hidden but still in the form, so "required" keeps working. */
.file-picker input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; inset-inline-start: 24px; bottom: 0; padding: 0; border: 0; pointer-events: none; }

.field-hint { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }
.field-error { font-size: 12.5px; color: var(--expense); margin-top: 5px; font-weight: 600; }

/* ---------------- Read-only "view" rows (paired with an Edit-drawer) ---------------- */
.view-row {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 11px 0; border-bottom: 1px solid var(--line-soft);
}
.view-row:last-child { border-bottom: none; }
.view-label { color: var(--ink-soft); font-size: 13px; font-weight: 600; flex-shrink: 0; }
.view-value { font-size: 13.5px; font-weight: 700; text-align: right; }
html[dir="rtl"] .view-value { text-align: left; }

.input-amount { position: relative; }
.input-amount span { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); font-weight: 700; }
.input-amount input { padding-left: 28px; font-family: var(--font-mono); font-weight: 700; }

/* ---------------- Auth pages ---------------- */

.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 20% 20%, #0C54C0 0%, #003084 45%, #041D3E 100%);
    padding: 24px;
}
.auth-card {
    background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 400px; padding: 38px 36px;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 26px; }
.auth-logo img { width: 56px; height: 56px; }
.auth-logo .name { font-family: var(--font-display); font-weight: 800; font-size: 21px; }
.auth-logo .tag { color: var(--ink-soft); font-size: 12.5px; }

.alert { padding: 12px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600; margin-bottom: 18px; }
.alert-error { background: var(--expense-bg); color: var(--expense); }
.alert-success { background: var(--income-bg); color: var(--income); }
.alert-info { background: #E9EEFC; color: var(--blue-600); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-with-action { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.alert-action { margin: 0; flex-shrink: 0; }
.alert-action .btn { background: var(--bg-surface); }
.bin-item { display: flex; align-items: flex-start; gap: 10px; white-space: normal; }

/* ---------------- Empty state ---------------- */

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state .icon { font-size: 34px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h4 { color: var(--ink); margin-bottom: 6px; }

/* ---------------- Filters bar ---------------- */

.filters-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--radius-md);
    padding: 14px 16px; margin-bottom: 18px;
}
.filters-bar select, .filters-bar input { width: auto; min-width: 140px; }
.filters-bar .grow { flex: 1; min-width: 180px; }
.filters-bar select, .filters-bar input { min-height: 42px; }

/* ---------------- Pills / tabs ---------------- */

.tab-row { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab-link {
    padding: 10px 4px; margin-inline-end: 22px; font-weight: 700; font-size: 14px;
    color: var(--ink-soft); border-bottom: 2px solid transparent; position: relative; top: 1px;
}
.tab-link.active { color: var(--blue-600); border-bottom-color: var(--blue-600); }
.tab-link:hover { text-decoration: none; color: var(--blue-600); }

/* ---------------- Utility ---------------- */

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-24 { margin-top: 24px; }
.text-soft { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-sm { font-size: 13px; }
.text-right { text-align: right; }
.w-full { width: 100%; }

.avatar-chip {
    width: 26px; height: 26px; border-radius: 50%; background: var(--blue-600); color: #fff;
    display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800;
    flex-shrink: 0;
}

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span {
    padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; font-weight: 700; color: var(--ink-soft);
}
.pagination a:hover { background: var(--bg-surface-alt); text-decoration: none; }
.pagination .current { background: var(--blue-600); color: #fff; border-color: var(--blue-600); }

html[dir="rtl"] .input-amount span { left: auto; right: 13px; }
html[dir="rtl"] .input-amount input { padding-left: 13px; padding-right: 28px; }

/* Suffix variant (e.g. a trailing "%") — the mirror image of the prefix
   pattern above: the symbol trails the number, so it sits on the right
   in LTR and flips to the left in RTL. */
.input-amount.suffix span { left: auto; right: 13px; }
.input-amount.suffix input { padding-left: 13px; padding-right: 28px; }
html[dir="rtl"] .input-amount.suffix span { left: 13px; right: auto; }
html[dir="rtl"] .input-amount.suffix input { padding-left: 28px; padding-right: 13px; }

/* ---------------- Slide-over drawers ---------------- */

.drawer-overlay {
    display: none; position: fixed; inset: 0; background: rgba(16,24,40,0.35); z-index: 200;
}
.drawer-panel {
    display: none; position: fixed; top: 0; height: 100%; width: 440px; max-width: 92vw;
    background: #fff; z-index: 201; overflow-y: auto;
    right: 0; box-shadow: -8px 0 30px rgba(0,0,0,0.15);
}
.drawer-panel.drawer-wide { width: 460px; }
html[dir="rtl"] .drawer-panel {
    right: auto; left: 0; box-shadow: 8px 0 30px rgba(0,0,0,0.15);
}

/* ---------------- Responsive sidebar toggle ---------------- */

.mobile-topbar { display: none; }

/* ---------------- Cash-flow / card-charge event lists ---------------- */
.cashflow-events { display: flex; flex-direction: column; gap: 2px; }
.cashflow-event { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); overflow: hidden; }
.cashflow-event + .cashflow-event { margin-top: 6px; }
.cashflow-event summary {
    display: flex; align-items: center; gap: 14px; padding: 12px 14px;
    cursor: pointer; list-style: none; user-select: none;
}
.cashflow-event summary::-webkit-details-marker { display: none; }
.cashflow-event summary::before {
    content: '\25B8'; color: var(--ink-faint); font-size: 11px; transition: transform 0.15s; flex-shrink: 0;
}
.cashflow-event[open] summary::before { transform: rotate(90deg); }
html[dir="rtl"] .cashflow-event summary::before { content: '\25C2'; }
html[dir="rtl"] .cashflow-event[open] summary::before { transform: rotate(-90deg); }
.cashflow-event .cf-date { width: 84px; flex-shrink: 0; color: var(--ink-soft); }
.cashflow-event .cf-label { flex: 1; font-weight: 600; font-size: 13.5px; }
.cashflow-event .cf-amount { font-weight: 700; font-family: var(--font-mono); font-size: 13.5px; }
.cashflow-event .cf-running { width: 96px; text-align: right; flex-shrink: 0; }
.cashflow-event-detail { padding: 0 14px 14px 14px; border-top: 1px solid var(--line-soft); }
.cashflow-event-detail table.data-table { margin-top: 10px; }
.cashflow-event-detail table.data-table td { padding: 6px 8px; }

/* ---------------- Accounts & Cards: expandable account rows ---------------- */
.account-item { overflow: hidden; }
.account-summary {
    display: flex; align-items: center; gap: 20px; padding: 18px 22px; cursor: pointer;
    transition: background 0.12s;
}
.account-summary:hover { background: var(--bg-surface-alt); }
.account-summary:focus-visible { outline: 2px solid var(--blue-500); outline-offset: -2px; }
.account-item.is-archived .account-main,
.account-item.is-archived .account-balance { opacity: 0.55; }
.account-main { flex: 1; min-width: 0; }
.account-name { font-weight: 700; font-size: 14.5px; margin-bottom: 2px; }
.account-balance { font-weight: 700; font-size: 15px; white-space: nowrap; }
.account-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; flex-wrap: wrap; cursor: default; }
.account-actions form { display: inline-flex; margin: 0; }
.account-toggle { white-space: nowrap; flex-shrink: 0; }
.account-toggle .label-hide,
.account-item.open .account-toggle .label-show { display: none; }
.account-item.open .account-toggle .label-hide { display: inline; }
.account-cards { display: none; border-top: 1px solid var(--line); }
.account-item.open .account-cards { display: block; }
.account-cards-empty { margin: 0; padding: 16px 22px; }
.account-cards .data-table th:first-child,
.account-cards .data-table td:first-child { padding-inline-start: 22px; }

@media (max-width: 900px) {
    .account-summary { flex-wrap: wrap; gap: 10px 16px; padding: 16px 18px; }
    .account-main { flex-basis: 100%; }
    .account-balance { flex: 1; }
    .account-actions { order: 3; flex-basis: 100%; justify-content: flex-start; }
}

/* ---------------- Financial health score gauge ---------------- */
.health-score-card summary::-webkit-details-marker { display: none; }
.health-score-card summary { list-style: none; }
.health-score-card .stat-value.stat-value-sm { font-size: 18px; }
.hs-summary { padding: 22px 24px; display: flex; align-items: center; gap: 20px; }
.hs-gauge {
    position: relative; width: 84px; height: 84px; flex-shrink: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.hs-gauge-value {
    width: 66px; height: 66px; border-radius: 50%; background: var(--bg-surface);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 800; font-family: var(--font-display);
}
.hs-text { flex: 1; min-width: 0; }
.hs-title { font-size: 15.5px; font-weight: 700; }
.hs-toggle { flex-shrink: 0; }
.onboarding-item:hover { background: var(--bg-surface-alt); }

@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: -260px; top: 0; z-index: 100; transition: left 0.2s; box-shadow: var(--shadow-lg);
    }
    .sidebar.open { left: 0; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90; }
    .sidebar-overlay.open { display: block; }
    .mobile-topbar {
        display: flex; align-items: center; gap: 14px; padding: 14px 18px; background: var(--blue-700); color: #fff;
    }
    .mobile-topbar img { width: 28px; height: 28px; }
    .mobile-topbar button { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; display: inline-flex; padding: 4px; }
    /* The brand bar stays pinned; the page title scrolls away with the content
       (two sticky bars at top:0 would stack on top of each other). */
    .mobile-topbar { position: sticky; top: 0; z-index: 50; }
    .topbar { padding: 0 18px; position: static; }
    .content { padding: 20px 18px 50px; }
    .form-row { grid-template-columns: 1fr; row-gap: 0; } /* stacked fields already space themselves via .form-group's margin */
    .card-pad { padding: 18px; }
    .form-actions { flex-direction: column-reverse; align-items: stretch; }
    .form-actions .btn { width: 100%; justify-content: center; }
    .admin-create-options { grid-template-columns: 1fr; }
    .admin-create-card .form-actions { margin-top: 4px; }
    .backup-actions, .restore-form { flex-direction: column; min-width: 0; }
    .file-picker, .restore-form .btn, .backup-actions > .btn { width: 100%; }
}

@media (max-width: 900px) {
    html[dir="rtl"] .sidebar { left: auto; right: -260px; transition: right 0.2s; }
    html[dir="rtl"] .sidebar.open { left: auto; right: 0; }
}

/* ---------------- Tasks & the dashboard's Needs Attention panel ---------------- */
.sidebar-count {
    margin-inline-start: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--coral-500); color: #fff; font-size: 11px; font-weight: 800;
    display: inline-flex; align-items: center; justify-content: center;
}

.task-list { display: flex; flex-direction: column; }
.task-row {
    display: flex; align-items: flex-start; gap: 14px; padding: 14px 24px;
    border-bottom: 1px solid var(--line-soft);
}
.task-row:last-child { border-bottom: none; }
.task-check-form { margin: 0; flex-shrink: 0; }
.task-check {
    width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; padding: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 12px; line-height: 1;
    border: 1.5px solid var(--ink-faint); background: transparent; color: transparent;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.task-check:hover { border-color: var(--income); color: var(--income); }
.task-check.done { background: var(--income); border-color: var(--income); color: #fff; }
.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.task-row.is-done .task-title { color: var(--ink-faint); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 4px; color: var(--ink-faint); font-size: 12.5px; }
.task-notes { overflow-wrap: anywhere; white-space: pre-line; }
.task-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.task-actions form { display: inline-flex; margin: 0; }

.task-done-card > summary { cursor: pointer; list-style: none; border-bottom: none; }
.task-done-card > summary::-webkit-details-marker { display: none; }
.task-done-card[open] > summary { border-bottom: 1px solid var(--line); }
.task-done-card .label-hide, .task-done-card[open] .label-show { display: none; }
.task-done-card[open] .label-hide { display: inline; }

.attention-card { border-inline-start: 3px solid var(--warn); }
.attention-list { display: flex; flex-direction: column; padding: 6px 0; }
.attention-item { display: flex; align-items: flex-start; gap: 14px; padding: 10px 24px; }
.attention-item:hover { background: var(--bg-surface-alt); }
.attention-icon { width: 22px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; height: 22px; color: var(--ink-soft); }
.attention-main { flex: 1; min-width: 0; color: inherit; display: flex; flex-direction: column; gap: 4px; }
.attention-main:hover { text-decoration: none; }
.attention-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.attention-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--ink-faint); font-size: 12.5px; }

@media (max-width: 640px) {
    /* Tapping a task opens it for editing (with Delete inside), so the row buttons go. */
    .task-row { padding: 14px 16px; gap: 12px; }
    .task-actions { display: none; }
    .attention-item { padding: 10px 16px; gap: 12px; }
}

/* ---------------- Installment plans ---------------- */
.installment-box { background: var(--bg-surface-alt); border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px 14px; }
.installment-box label { font-size: 13.5px; font-weight: 600; }
.installment-box .form-row { align-items: end; }
.amount-sub { font-family: var(--font-body); font-size: 11.5px; font-weight: 600; color: var(--ink-faint); margin-top: 2px; white-space: normal; max-width: 150px; }
.link-btn { background: none; border: none; padding: 0; margin-top: 3px; cursor: pointer; font-family: var(--font-body); font-size: 12px; font-weight: 700; color: var(--blue-600); }
.link-btn:hover { text-decoration: underline; }
/* Ledger tables: let names, categories and methods wrap so the row fits; dates, amounts and buttons stay on one line. */
.data-table.ledger-table tbody td { white-space: normal; }
.data-table.ledger-table tbody td.ledger-date,
.data-table.ledger-table tbody td.cell-amount,
.data-table.ledger-table tbody td.cell-actions { white-space: nowrap; }
.data-table.ledger-table tbody td.cell-amount .amount-sub { white-space: normal; }
.data-table.ledger-table tbody td.cell-title { min-width: 120px; }
.installment-preview {
    min-height: 44px; display: flex; align-items: center; padding: 0 2px;
    font-size: 13.5px; font-weight: 700; color: var(--ink);
}
.plan-progress { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.progress-track { display: block; position: relative; height: 6px; border-radius: 6px; overflow: hidden; background: var(--bg-surface-alt); }
.progress-fill { position: absolute; inset-inline-start: 0; top: 0; height: 100%; background: var(--blue-600); border-radius: 6px; }

@media (max-width: 640px) {
    .plan-progress { min-width: 0; flex: 1; align-items: flex-end; }
    .plan-progress .progress-track { width: 100%; max-width: 180px; }
}

/* ---------------- Calendar ---------------- */
.stat-sub { margin-top: 4px; font-size: 12.5px; color: var(--ink-faint); font-weight: 600; }

.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .calendar-layout { grid-template-columns: 1fr; } }

.calendar-nav { justify-content: flex-start; gap: 12px; }
.calendar-nav h3 { min-width: 150px; text-align: center; }
.calendar-nav .btn-outline { padding: 5px 12px; font-size: 16px; line-height: 1; }
.calendar-today-btn { margin-inline-start: auto; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line-soft); border-bottom: 1px solid var(--line); }
.cal-weekday {
    background: var(--bg-surface-alt); padding: 8px 10px; font-size: 11.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); text-align: start;
}
.cal-blank { background: var(--bg-surface-alt); opacity: 0.5; }
.cal-day {
    background: var(--bg-surface); border: none; min-height: 96px; padding: 8px 8px 6px;
    display: flex; flex-direction: column; align-items: stretch; gap: 3px;
    font-family: var(--font-body); text-align: start; cursor: pointer; color: var(--ink);
    box-shadow: inset 0 0 0 2px transparent; transition: background 0.12s, box-shadow 0.12s;
}
.cal-day:hover { background: #F8FAFD; }
.cal-day:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--blue-500); }
.cal-day.is-selected { box-shadow: inset 0 0 0 2px var(--blue-600); background: #F5F8FE; }
.cal-num { font-size: 13px; font-weight: 700; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.cal-day.is-past .cal-num { color: var(--ink-faint); }
.cal-day.is-today .cal-num { background: var(--blue-600); color: #fff; }
.cal-amounts { display: flex; flex-direction: column; gap: 1px; font-size: 11.5px; line-height: 1.3; min-width: 0; }
.cal-amounts span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount-expected { color: var(--ink-faint); font-weight: 700; font-family: var(--font-mono); font-style: italic; }
html[dir="rtl"] .amount-expected { direction: ltr; unicode-bidi: isolate; }
.cal-dots { display: flex; gap: 3px; margin-top: auto; }
.cal-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-income { background: var(--income); }
.dot-expense { background: var(--expense); }
.dot-expected { border: 1.5px solid var(--ink-faint); }
.dot-other { background: var(--blue-500); }
.dot-task { background: var(--warn); }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 12px 20px; font-size: 12px; color: var(--ink-soft); }
.calendar-legend span { display: inline-flex; align-items: center; gap: 6px; }

.cal-detail .card-header h3 { font-size: 14.5px; }
.cal-event { color: inherit; }
.cal-event:hover { text-decoration: none; }
.cal-event-amount { font-family: var(--font-mono); font-weight: 700; font-size: 13px; white-space: nowrap; flex-shrink: 0; }
.cal-empty { margin: 0; padding: 10px 24px; }
.cal-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 24px 18px; border-top: 1px solid var(--line-soft); }

@media (max-width: 640px) {
    .calendar-nav { gap: 8px; }
    .calendar-nav h3 { min-width: 0; flex: 1; }
    .calendar-today-btn { margin-inline-start: 0; }
    .cal-weekday { padding: 6px 0; text-align: center; font-size: 10.5px; }
    /* Phones: just the day number and dots; amounts are in the details panel below. */
    .cal-day { min-height: 52px; padding: 5px 2px; align-items: center; }
    .cal-amounts { display: none; }
    .cal-dots { margin-top: 2px; justify-content: center; flex-wrap: wrap; }
    .cal-dot { width: 6px; height: 6px; }
    .calendar-legend { padding: 10px 16px; gap: 6px 12px; }
    .cal-empty { padding: 10px 16px; }
    .cal-detail-actions { padding: 12px 16px 16px; }
    .cal-detail-actions .btn { flex: 1; justify-content: center; }
}

/* ---------------- Statement import ---------------- */
.import-steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; flex-wrap: wrap; }
.import-steps li { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-faint); }
.import-steps li + li::before { content: ''; width: 24px; height: 1px; background: var(--line); margin-inline-end: 4px; }
.import-steps li span {
    width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; background: var(--bg-surface-alt); border: 1px solid var(--line);
}
.import-steps li.current { color: var(--ink); }
.import-steps li.current span { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.import-steps li.done span { background: var(--income); border-color: var(--income); color: #fff; }

.import-layouts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.import-layout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.import-layout:has(input:checked) { border-color: var(--blue-600); background: #F5F8FE; }
.import-layout input { width: auto; margin-top: 3px; }
.import-layout > span { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
@media (max-width: 900px) { .import-layouts { grid-template-columns: 1fr; } }

.import-sample td, .import-sample th { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.import-toolbar { flex-wrap: wrap; gap: 10px; }
.import-bulk select { width: auto; min-width: 230px; min-height: 36px; padding: 6px 10px; font-size: 13px; }
.import-preview tbody tr.is-duplicate { background: var(--warn-bg); }
.import-preview td.import-check { width: 36px; }
.import-preview td.import-check input { width: 17px; height: 17px; }
.import-preview td.cell-title .badge { margin-inline-start: 6px; }
.import-preview td.cell-title .text-faint { display: block; }
.import-preview select { width: auto; min-width: 170px; min-height: 36px; padding: 6px 10px; font-size: 13px; }
.import-submit { display: flex; gap: 10px; align-items: center; margin-top: 18px; position: sticky; bottom: 0; padding: 12px 0; background: var(--bg-app); }
.data-table.import-preview tbody td { white-space: normal; }

@media (max-width: 640px) {
    .import-bulk { width: 100%; }
    .import-bulk select { flex: 1; min-width: 0; }
    /* The checkbox sits beside the title on phones. */
    .data-table.stack-mobile.import-preview tr { grid-template-columns: auto minmax(0, 1fr) auto; }
    .data-table.stack-mobile.import-preview td.import-check { grid-column: 1; grid-row: 1; }
    .data-table.stack-mobile.import-preview td.cell-title { grid-column: 2; }
    .data-table.stack-mobile.import-preview td.cell-amount { grid-column: 3; }
    .import-preview select { min-width: 0; max-width: 60%; }
    .import-submit .btn-primary { flex: 1; justify-content: center; white-space: nowrap; }
}

/* ---------------- Search ---------------- */
.topbar-search { position: relative; margin-inline-start: auto; margin-inline-end: 14px; width: 260px; }
.topbar-search input { min-height: 38px; padding: 8px 34px 8px 12px; font-size: 13.5px; background: var(--bg-surface-alt); }
html[dir="rtl"] .topbar-search input { padding: 8px 12px 8px 34px; }
.topbar-search kbd {
    position: absolute; inset-inline-end: 9px; top: 50%; transform: translateY(-50%);
    font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint);
    border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; background: var(--bg-surface); pointer-events: none;
}
.topbar-search input:focus + kbd { display: none; }
.mobile-search { margin-inline-start: auto; color: #fff; font-size: 20px; text-decoration: none; padding: 4px 6px; display: inline-flex; }
.mobile-search:hover { text-decoration: none; }
.search-hero { display: flex; gap: 10px; margin-bottom: 8px; }
.search-hero input { font-size: 16px; min-height: 48px; }
.search-tips { margin: 0 0 18px; }
.search-explain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 18px; }
.search-explain .badge { text-transform: none; letter-spacing: 0; font-size: 12px; }
@media (max-width: 900px) { .topbar-search { display: none; } }

/* ---------------- Quick-add (bucket) categories ---------------- */
.quick-add-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.quick-add-chip {
    display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; border-radius: 12px;
    background: var(--bg-surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
html[dir="rtl"] .quick-add-chip { padding: 8px 14px 8px 8px; }
.quick-add-chip .qa-text { display: flex; flex-direction: column; line-height: 1.3; }
.quick-add-chip .qa-name { font-weight: 700; font-size: 13.5px; }
.quick-add-chip .qa-total { font-size: 12px; color: var(--ink-faint); font-weight: 600; }
.qa-plus {
    width: 34px; height: 34px; border-radius: 10px; border: none; cursor: pointer; flex-shrink: 0;
    background: var(--coral-500); color: #fff; font-size: 20px; font-weight: 700; line-height: 1;
}
.qa-plus:hover { background: #E14848; }
.quick-add-toggle.on { color: var(--warn); }
.category-row { flex-wrap: wrap; gap: 6px 12px; }
.category-actions { flex-wrap: wrap; margin-inline-start: auto; }

/* ---------------- Loan calculator ---------------- */
.calc-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 14px; align-items: end; }
.calc-form .form-group { margin-bottom: 0; }
.calc-results { margin-top: 20px; }
.calc-method { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 18px 20px; }
.calc-method h4 { font-size: 14px; margin: 0 0 8px; }
.calc-big { font-family: var(--font-display); font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.calc-big span { font-family: var(--font-body); font-size: 13px; font-weight: 600; color: var(--ink-faint); margin-inline-start: 6px; }
.calc-schedule { margin-top: 12px; }
.calc-schedule summary { cursor: pointer; color: var(--blue-600); font-weight: 600; }
.calc-schedule .table-wrap { margin-top: 8px; }
@media (max-width: 1100px) { .calc-form { grid-template-columns: repeat(2, minmax(0, 1fr)); } .calc-form .calc-submit { grid-column: 1 / -1; } }

/* ---------------- Reports ---------------- */
.report-period .report-period-label { margin-inline-start: auto; font-weight: 700; }
.share-cell { display: inline-flex; align-items: center; gap: 8px; min-width: 120px; }
.share-cell .progress-track { width: 70px; }
.print-only { display: none; }

/* ---------------- Printing (any page; Reports has a Print button) ---------------- */
@media print {
    @page { margin: 14mm; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    html, body { background: #fff; font-size: 12px; }
    .sidebar, .sidebar-overlay, .mobile-topbar, .topbar-actions, .topbar-search, .no-print,
    .filters-bar, .pagination, .drawer-panel, .drawer-overlay, .cell-actions, .alert, .quick-add-strip,
    .import-submit, .calc-form, .calc-method .btn { display: none !important; }
    .print-only { display: block !important; }
    .print-heading { margin-bottom: 14px; padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
    .print-heading strong { display: block; font-family: var(--font-display); font-size: 17px; }
    .print-heading span { color: var(--ink-soft); font-size: 11px; }
    .app-shell, .main { display: block; }
    .content { padding: 0; max-width: none; }
    .topbar { position: static; height: auto; padding: 0 0 10px; border: none; }
    .topbar .topbar-sub { display: none; }
    .card, .stat-card { box-shadow: none; border-color: #cfd4dc; break-inside: avoid; }
    .stat-grid, .stat-grid.cols-2, .stat-grid.cols-3 { grid-template-columns: repeat(4, 1fr) !important; gap: 8px; margin-bottom: 12px; }
    .stat-card { padding: 10px 12px; }
    .stat-icon { display: none; }
    .stat-value { font-size: 16px; }
    /* Side-by-side cards get too narrow on paper (and can run off the page in RTL) — stack them. */
    .grid-2, .grid-main-side { grid-template-columns: 1fr; gap: 12px; }
    .data-table tr { break-inside: avoid; }
    .data-table thead { display: table-header-group; }
    .table-wrap { overflow: visible; }
    a { color: inherit; text-decoration: none; }
}

/* ==========================================================================
   Phones (≤ 640px)
   ========================================================================== */
@media (max-width: 640px) {
    /* ---- Page header: title on top, action buttons in a full-width row below ---- */
    .topbar { height: auto; flex-wrap: wrap; gap: 12px; padding: 14px 16px; }
    .topbar h1 { font-size: 19px; }
    .topbar-title { flex: 1 1 100%; }
    .topbar-actions { flex: 1 1 100%; }
    .topbar-actions:empty { display: none; }
    .topbar-actions > .btn,
    .topbar-actions > .flex .btn { width: 100%; justify-content: center; }
    .topbar-actions > .flex > * { flex: 1; }

    .content { padding: 16px 16px 40px; }
    .card-header { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
    .card-pad { padding: 16px; }
    .mb-24 { margin-bottom: 16px; }

    .hero-banner { padding: 22px 20px; border-radius: var(--radius-md); margin-bottom: 16px; }
    .hero-banner h2 { font-size: 20px; }

    /* ---- KPI tiles: two per row, compact; an odd last tile spans the row ---- */
    .stat-grid, .stat-grid.cols-2, .stat-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
    .stat-grid > .stat-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .stat-card { padding: 14px; }
    .stat-icon { width: 32px; height: 32px; font-size: 15px; margin-bottom: 10px; border-radius: 9px; }
    .stat-label { font-size: 10.5px; }
    .stat-value { font-size: 19px; overflow-wrap: anywhere; }

    /* ---- Health score: gauge on the left, text and "View Breakdown" stacked beside it ---- */
    .hs-summary { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 16px; padding: 18px 16px; }
    .hs-gauge { grid-row: span 2; width: 68px; height: 68px; }
    .hs-gauge-value { width: 54px; height: 54px; font-size: 18px; }
    .hs-title { font-size: 14.5px; }
    .hs-toggle { grid-column: 2; }

    .breakdown-grid { grid-template-columns: 1fr; gap: 16px; }
    .breakdown-chart { height: 200px; }

    /* ---- Forms: 16px text so iOS doesn't zoom in on focus ---- */
    input[type=text], input[type=email], input[type=password], input[type=number],
    input[type=date], input[type=search], select, textarea { font-size: 16px; }

    .filters-bar { padding: 12px; gap: 8px; }
    .filters-bar > * { flex: 1 1 calc(50% - 4px); min-width: 0 !important; }
    .filters-bar .grow, .filters-bar select { flex-basis: 100%; }
    .filters-bar .btn { justify-content: center; }

    .export-form { display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
    .export-form > div, .export-form input, .export-form select { min-width: 0; width: 100%; }
    .export-form > :first-child, .export-form > .btn { grid-column: 1 / -1; justify-content: center; }

    .pagination { flex-wrap: wrap; }

    /* ---- Drawers take the full screen width ---- */
    .drawer-panel, .drawer-panel.drawer-wide { width: 100%; max-width: 100%; }
    .drawer-panel > * { padding-left: 18px !important; padding-right: 18px !important; }

    /* ---- Cash-flow / card-charge rows: two lines (what + amount, then when + running balance) ---- */
    .cashflow-event summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline; }
    .cashflow-event summary::before { grid-row: 1 / span 2; align-self: center; }
    .cashflow-event .cf-label { grid-column: 2; grid-row: 1; }
    .cashflow-event .cf-amount { grid-column: 3; grid-row: 1; text-align: end; white-space: nowrap; }
    .cashflow-event .cf-date { grid-column: 2; grid-row: 2; width: auto; font-size: 12px; }
    .cashflow-event .cf-running { grid-column: 3; grid-row: 2; width: auto; font-size: 12px; text-align: end; }

    /* ---- Tables become stacked cards: title + amount on top, labelled rows, then actions ----
       Opt-in per table with .stack-mobile; each <td> carries data-label (its column name),
       and the row's key cells are marked .cell-title / .cell-amount / .cell-actions. */
    .data-table.stack-mobile thead { display: none; }
    .data-table.stack-mobile, .data-table.stack-mobile tbody { display: block; }
    .data-table.stack-mobile tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 12px;
        padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
    }
    .data-table.stack-mobile tbody tr:last-child { border-bottom: none; }
    .data-table.stack-mobile td {
        grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;
        padding: 0 !important; border: none; font-size: 13px; min-width: 0;
        white-space: normal !important; max-width: none !important; overflow: visible !important;
    }
    .data-table.stack-mobile td[data-label]::before {
        content: attr(data-label); margin-inline-end: auto; padding-inline-end: 12px;
        color: var(--ink-faint); font-size: 12px; font-weight: 600; font-family: var(--font-body);
    }
    .data-table.stack-mobile td.cell-title { grid-column: 1; grid-row: 1; display: block; font-size: 14px; }
    .data-table.stack-mobile td.cell-amount { grid-column: 2; grid-row: 1; display: block; font-size: 14px; text-align: end; white-space: nowrap !important; }
    .data-table.stack-mobile td.cell-actions { margin-top: 6px; margin-inline-start: -10px; justify-content: flex-start; }
    .data-table.stack-mobile td.cell-actions form { display: inline-flex; }
    .data-table.stack-mobile td select { width: auto; min-height: 36px; padding: 6px 10px; }
    .admin-users-card .data-table.stack-mobile { min-width: 0; }
    .admin-user-actions { min-width: 0; }
    .admin-action-group { justify-content: flex-start; }
    .account-cards .data-table.stack-mobile td:first-child { padding-inline-start: 0 !important; }

    /* ---- Quick add, loan calculator, reports ---- */
    .quick-add-chip { flex: 1 1 100%; justify-content: space-between; }
    .calc-form { grid-template-columns: 1fr; }
    .calc-big { font-size: 22px; }
    .report-period .report-period-label { flex-basis: 100%; margin: 0; }

    /* ---- Auth pages ---- */
    .auth-shell { padding: 16px; }
    .auth-card { padding: 28px 20px; }
}

/* ---------------- Password eye (assets/js/ui.js) ---------------- */
.pw-field { position: relative; display: block; }
.pw-field input { padding-inline-end: 44px; }
.pw-toggle { position: absolute; top: 50%; inset-inline-end: 6px; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: none; border-radius: 7px; background: transparent; color: var(--ink-faint); font-size: 17px; cursor: pointer; }
.pw-toggle:hover { color: var(--ink-soft); background: var(--bg-surface-alt); }
.pw-toggle:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 1px; color: var(--ink-soft); }
.pw-toggle[aria-pressed="true"] { color: var(--blue-600); }
input::-ms-reveal, input::-ms-clear { display: none; } /* Edge's own eye would double up */

/* ---------------- Live filters (data-autofilter + data-live) ---------------- */
.autofilter-on:is(.filters-bar, .filters-bar-plain) [type=submit] { display: none; }
.filters-clear { display: contents; }
[data-live] { transition: opacity 0.15s; }
[data-live].is-loading { opacity: 0.55; pointer-events: none; }

/* ---------------- Sign in with Google ---------------- */
.google-signin { display: flex; justify-content: center; min-height: 44px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--ink-faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.google-client-id { font-family: var(--font-mono); font-size: 12.5px; overflow-wrap: anywhere; text-align: end; }
@media (max-width: 600px) {
    .view-row-long { flex-direction: column; align-items: flex-start; gap: 4px; }
    .view-row-long .google-client-id { text-align: start; align-self: stretch; }
}
.google-steps { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.google-steps summary { cursor: pointer; color: var(--blue-600); font-weight: 600; }
.google-steps ol { margin: 10px 0 0; padding-inline-start: 20px; display: grid; gap: 6px; }
.google-steps code { background: var(--bg-surface-alt); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; }

/* ---------------- Scrollbars: thin, rounded, quiet ---------------- */
:root { --scroll-thumb: #C3CAD5; --scroll-thumb-hover: #98A2B3; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--scroll-thumb); border: 3px solid transparent; border-radius: 999px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
@supports (scrollbar-color: auto) {
    * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}
.sidebar { --scroll-thumb: rgba(255, 255, 255, 0.18); --scroll-thumb-hover: rgba(255, 255, 255, 0.32); }

/* ---------------- Error pages (includes/error_page.php) ---------------- */
.error-card { max-width: 440px; text-align: center; }
.error-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; color: var(--ink); text-decoration: none; margin-bottom: 26px; }
.error-brand img { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; }
.error-icon { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 34px; background: #E9EEFC; color: var(--blue-600); }
.error-icon-403, .error-icon-500 { background: var(--expense-bg); color: var(--expense); }
.error-icon-400, .error-icon-503 { background: var(--warn-bg); color: var(--warn); }
.error-code { font-family: var(--font-mono); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px; }
.error-title { font-family: var(--font-display); font-size: 22px; margin: 0 0 10px; }
.error-text { color: var(--ink-soft); font-size: 14.5px; line-height: 1.55; margin: 0 0 24px; }
.error-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.error-actions .btn { flex: 1 1 160px; justify-content: center; gap: 8px; }
.error-detail { margin-top: 22px; text-align: start; font-size: 12.5px; color: var(--ink-soft); }
.error-detail summary { cursor: pointer; font-weight: 600; }
.error-detail pre { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bg-surface-alt); border: 1px solid var(--line); font-family: var(--font-mono); font-size: 11.5px; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }

/* ---------------- Connection banner (assets/js/ui.js) ---------------- */
.net-banner { position: fixed; z-index: 400; inset-inline: 0; bottom: 16px; margin-inline: auto; width: max-content; max-width: calc(100% - 32px); display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); }
.net-banner .ic { font-size: 17px; color: #FDB022; }
.net-banner.is-online .ic { color: #47CD89; }
.net-banner[hidden] { display: none; }
html[dir="rtl"] .btn-back .ic { transform: scaleX(-1); }

/* ---------------- Site dialogs (LL.confirm / LL.prompt in assets/js/ui.js) ---------------- */
.ll-modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 16px; }
.ll-modal[hidden] { display: none; }
.ll-modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, 0.45); opacity: 0; transition: opacity 0.15s; }
.ll-modal-card { position: relative; width: 100%; max-width: 400px; background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 28px 26px 22px; text-align: center; opacity: 0; transform: translateY(8px) scale(0.98); transition: opacity 0.15s, transform 0.15s; }
.ll-modal.is-open .ll-modal-backdrop { opacity: 1; }
.ll-modal.is-open .ll-modal-card { opacity: 1; transform: none; }
.ll-modal-icon { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 26px; background: #E9EEFC; color: var(--blue-600); }
.tone-danger .ll-modal-icon { background: var(--expense-bg); color: var(--expense); }
.tone-warn .ll-modal-icon { background: var(--warn-bg); color: var(--warn); }
.ll-modal-title { font-family: var(--font-display); font-size: 18px; margin: 0 0 8px; }
.ll-modal-text { color: var(--ink-soft); font-size: 14px; line-height: 1.55; margin: 0 0 20px; overflow-wrap: anywhere; white-space: pre-line; }
.ll-modal-field { text-align: start; }
.ll-modal-field:not(:empty) { margin: -6px 0 20px; }
.ll-modal-actions { display: flex; gap: 10px; }
.ll-modal-actions .btn { flex: 1; justify-content: center; }
.ll-modal-actions .btn[hidden] { display: none; }
.btn-solid-danger { background: var(--expense); color: #fff; box-shadow: var(--shadow-sm); }
.btn-solid-danger:hover { background: #B8314A; }
html.ll-modal-lock, html.ll-modal-lock body { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .ll-modal-backdrop, .ll-modal-card { transition: none; } }

/* ---------------- Field errors (instead of browser validation bubbles) ---------------- */
.field-error { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--expense); font-size: 12.5px; font-weight: 600; }
.field-error::before { content: ""; flex-shrink: 0; width: 14px; height: 14px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat; }
input.is-invalid, select.is-invalid, textarea.is-invalid, .file-picker:has(.is-invalid) { border-color: var(--expense) !important; box-shadow: 0 0 0 3px rgba(214, 66, 92, 0.12) !important; }

/* ---------------- Email (Gmail) — Admin card, profile choices ---------------- */
.gmail-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 18px 0 6px; }
.gmail-actions form { margin: 0; }
.google-btn { display: inline-flex; align-items: center; gap: 12px; height: 42px; padding: 0 18px 0 14px; border: 1px solid #DADCE0; border-radius: 6px; background: #fff; color: #1F1F1F; font-family: Roboto, var(--font-body, Inter), Arial, sans-serif; font-size: 14px; font-weight: 500; cursor: pointer; box-shadow: var(--shadow-sm); transition: background 0.15s, box-shadow 0.15s; }
.google-btn:hover { background: #F8FAFF; box-shadow: 0 1px 3px rgba(60, 64, 67, 0.25); }
.google-btn:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.google-btn .google-g { flex-shrink: 0; }
.email-features { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.email-features h4 { font-size: 14px; margin: 0 0 10px; }
.check-list { display: grid; gap: 4px; margin-bottom: 14px; }
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--ink); }
.check-row:hover { background: var(--bg-surface-alt); }
.check-row input[type=checkbox] { flex-shrink: 0; margin-top: 2px; }
.check-row strong { display: block; font-weight: 600; }
.check-row-hint { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 12.5px; line-height: 1.45; }
.email-prefs-card { margin-top: 24px; }
.email-sample-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.email-sample-row form { margin: 0; }
.forgot-link { text-align: end; margin-top: 8px; }
@media (max-width: 640px) {
    .gmail-actions > form, .gmail-actions > .btn { flex: 1 1 100%; }
    .gmail-actions .google-btn, .gmail-actions .btn { width: 100%; justify-content: center; }
    .email-sample-row form { flex: 1 1 100%; }
    .email-sample-row .btn { width: 100%; justify-content: center; }
}
