/* =========================================
   Base / Reset
   ========================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:        #3b82f6;
    --blue-dark:   #1d4ed8;
    --blue-dim:    rgba(59,130,246,.18);
    --green:       #22c55e;
    --green-dim:   rgba(34,197,94,.15);
    --red:         #f87171;
    --red-dim:     rgba(248,113,113,.15);
    --yellow:      #fbbf24;

    --bg:          #0f172a;
    --bg2:         #162032;
    --card:        #1e293b;
    --card2:       #273549;
    --text:        #f1f5f9;
    --text-muted:  #94a3b8;
    --text-dim:    #64748b;
    --border:      #334155;
    --border-dim:  #1e293b;
    --input-bg:    #0f172a;

    --radius:    12px;
    --radius-sm:  8px;
    --shadow:    0 1px 4px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overscroll-behavior: none;
}

/* =========================================
   Utility
   ========================================= */
.text-green { color: var(--green)      !important; }
.text-red   { color: var(--red)        !important; }
.text-muted { color: var(--text-muted); }
.optional   { color: var(--text-dim); font-size: .8rem; font-weight: 400; }

/* =========================================
   Alerts
   ========================================= */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .9rem;
}
.alert-error   { background: var(--red-dim);   color: #fca5a5; border: 1px solid rgba(248,113,113,.3); }
.alert-success { background: var(--green-dim); color: #86efac; border: 1px solid rgba(34,197,94,.3); }

/* =========================================
   Buttons
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .625rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); opacity: .8; }
.btn-primary   { background: var(--blue);           color: #fff; }
.btn-secondary { background: var(--card2);          color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: rgba(248,113,113,.2);  color: var(--red);  border: 1px solid rgba(248,113,113,.3); }
.btn-full      { width: 100%; }
.btn-large     { padding: 1rem; font-size: 1.05rem; border-radius: var(--radius); }
.btn-sm        { padding: .35rem .75rem; font-size: .8rem; }

/* =========================================
   Forms
   ========================================= */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: .35rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--text);
    background: var(--input-bg);
    transition: border-color .15s;
    appearance: none;
    -webkit-appearance: none;
}
.form-group input::placeholder { color: var(--text-dim); }
.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}

/* Checkboxes — restore native appearance */
.form-group input[type="checkbox"],
.form-group input[type="radio"] {
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    background: none;
    appearance: auto;
    -webkit-appearance: auto;
    accent-color: var(--blue);
    cursor: pointer;
    flex-shrink: 0;
}
.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .9rem center;
    padding-right: 2.5rem;
}
/* Fix select option bg on dark */
.form-group select option { background: var(--card); color: var(--text); }

.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }
.form-inline { display: flex; gap: .5rem; align-items: flex-end; }
.form-inline input { flex: 1; }
.form-check label {
    display: flex; align-items: center; gap: .5rem;
    font-size: .95rem; text-transform: none; letter-spacing: 0; color: var(--text);
    cursor: pointer;
}
.form-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }
.form-error { color: var(--red); font-size: .85rem; margin-top: .5rem; min-height: 1.2rem; }

/* =========================================
   Cards
   ========================================= */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: .875rem;
    border: 1px solid var(--border);
}
.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

/* =========================================
   Badges
   ========================================= */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    background: var(--blue-dim);
    color: var(--blue);
}
.badge-secondary { background: rgba(255,255,255,.07); color: var(--text-muted); }
.badge-green     { background: var(--green-dim);      color: var(--green); }
.badge-red       { background: var(--red-dim);        color: var(--red); }

/* =========================================
   LOGIN PAGE
   ========================================= */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 1.5rem;
    background: linear-gradient(145deg, #0d1b2e 0%, #0f172a 60%, #162032 100%);
}
.login-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}
.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}
.login-logo svg { width: 56px; height: 56px; }
.login-container h1 { text-align: center; font-size: 1.5rem; font-weight: 700; margin-bottom: .25rem; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }

/* =========================================
   APP SHELL
   ========================================= */
.app-page { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.app-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    background: #1a3a6b;
    color: #fff;
    padding: .875rem 1rem;
    padding-top: calc(.875rem + env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.5);
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.header-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: .01em;
}
.header-left, .header-right { display: flex; align-items: center; }
.header-month { font-size: .85rem; opacity: .75; }

/* Hamburger */
.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-tap-highlight-color: transparent;
}
.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

/* Balance button */
.balance-btn {
    background: rgba(255,255,255,.1);
    border: 1.5px solid rgba(255,255,255,.2);
    border-radius: var(--radius-sm);
    color: #fff;
    padding: .4rem .85rem;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
    white-space: nowrap;
}
.balance-btn:active { background: rgba(255,255,255,.25); }
.balance-reveal {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
    margin-right: 15px;
    min-width: 0;
    white-space: nowrap;
}

/* Side Menu */
.menu-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 200;
}
.menu-overlay.open { display: block; }

.side-menu {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    background: var(--card);
    border-right: 1px solid var(--border);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}
.side-menu.open { transform: translateX(0); }

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem;
    padding-top: calc(1.25rem + env(safe-area-inset-top));
    background: #1a3a6b;
    color: #fff;
    font-weight: 600;
}
.menu-close { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 0 .25rem; }
.menu-list { list-style: none; padding: .5rem 0; overflow-y: auto; }
.menu-list li a {
    display: block;
    padding: .9rem 1.25rem;
    color: var(--text);
    text-decoration: none;
    font-size: .95rem;
    transition: background .15s;
}
.menu-list li a:hover,
.menu-list li a.active { background: var(--blue-dim); color: var(--blue); font-weight: 600; }
.menu-divider { height: 1px; background: var(--border); margin: .5rem 0; }

.app-main {
    flex: 1;
    padding: 1rem;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

/* =========================================
   QUICK ENTRY
   ========================================= */
.entry-card { padding: 1.5rem; }

.amount-wrapper {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-bg);
    transition: border-color .15s;
}
.amount-wrapper:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
.currency-symbol {
    padding: 0 .25rem 0 1rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dim);
    pointer-events: none;
    flex-shrink: 0;
    line-height: 1;
}
.amount-wrapper input {
    border: none !important;
    box-shadow: none !important;
    background: transparent;
    padding-left: .25rem;
    padding-right: 1rem;
    flex: 1;
    font-size: 1.6rem;
    font-weight: 700;
    height: 64px;
    border-radius: 0;
    letter-spacing: .02em;
    outline: none !important;
}

/* =========================================
   SUCCESS OVERLAY
   ========================================= */
.success-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.75);
    z-index: 300;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}
.success-overlay.show { display: flex; }
.success-circle { width: 100px; height: 100px; }
.success-circle svg { width: 100%; height: 100%; }
.success-text { color: #fff; font-size: 1.2rem; font-weight: 600; }

.success-ring {
    stroke-dasharray: 226;
    stroke-dashoffset: 226;
}
.success-check {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
}
.success-overlay.show .success-ring {
    animation: drawRing .4s ease forwards;
}
.success-overlay.show .success-check {
    animation: drawCheck .3s ease .35s forwards;
}
@keyframes drawRing  { to { stroke-dashoffset: 0; } }
@keyframes drawCheck { to { stroke-dashoffset: 0; } }

/* =========================================
   BUDGET SUMMARY
   ========================================= */
.summary-totals .totals-row { display: flex; gap: .5rem; }
.total-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    text-align: center;
}
.total-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.total-value { font-size: 1.1rem; font-weight: 700; }

.budget-list { display: flex; flex-direction: column; gap: .625rem; }
.budget-row { padding: 1rem 1.25rem; }
.budget-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .5rem;
}
.budget-category { font-weight: 600; font-size: .95rem; }
.budget-status   { font-weight: 700; font-size: .95rem; }

.budget-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: .5rem;
}
.budget-progress-fill {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width .3s ease;
}
.budget-progress-fill.over { background: var(--red); }

.budget-row-footer {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
    color: var(--text-muted);
}

/* =========================================
   REGISTER
   ========================================= */
.filter-card { padding: .875rem 1rem; }
.filter-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filter-form select { flex: 1; min-width: 100px; padding: .5rem .75rem; font-size: .85rem; }

/* Account filter dropdown */
.acct-filter-wrap { position: relative; }
.acct-filter-btn {
    display: flex;
    align-items: center;
    gap: .4rem;
    background: var(--card2);
    border: 1.5px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: .5rem .85rem;
    font-size: .85rem;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.acct-filter-btn .arrow { font-size: .7rem; transition: transform .2s; }
.acct-filter-btn.open .arrow { transform: rotate(180deg); }

.acct-filter-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 120;
    overflow: hidden;
}
.acct-filter-menu.open { display: block; }
.acct-filter-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .65rem 1rem;
    cursor: pointer;
    font-size: .9rem;
    color: var(--text);
    transition: background .1s;
}
.acct-filter-item:hover { background: var(--card2); }
.acct-filter-item input[type="checkbox"] {
    width: 15px; height: 15px;
    accent-color: var(--blue);
    cursor: pointer;
    flex-shrink: 0;
}
.acct-filter-apply {
    padding: .65rem 1rem;
    border-top: 1px solid var(--border);
}

.register-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1rem;
    font-size: .9rem;
}
.register-total { font-weight: 700; font-size: 1rem; }

/* Wider layout for register page */
.register-page .app-main { max-width: 840px; }

/* Register table */
.register-table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: .875rem;
}
.register-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
    white-space: nowrap;
}
.register-table thead th {
    padding: .55rem .75rem;
    text-align: left;
    background: var(--bg2);
    color: var(--text-dim);
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
}
.register-table tbody td {
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--border-dim);
    vertical-align: middle;
    color: var(--text);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.register-table tbody tr:last-child td { border-bottom: none; }
.register-table thead th.sortable { cursor: pointer; user-select: none; }
.register-table thead th.sortable:hover { background: var(--card2); }
.sort-arrow { display: inline-block; font-size: .65em; margin-left: .25em; opacity: .75; min-width: .8em; }
.register-table tbody tr.row-even td { background: var(--card); }
.register-table tbody tr.row-odd  td { background: var(--bg2); }
.register-table tbody tr:hover td    { background: var(--card2) !important; }
.register-table tbody tr.row-hidden td {
    opacity: .5;
    font-style: italic;
    background: rgba(248,113,113,.05) !important;
}
.register-table .col-amount {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.register-table .col-actions {
    white-space: nowrap;
}
.register-table .col-actions .btn { margin-right: .25rem; }
.txn-type-expense { color: var(--red); }
.txn-type-deposit { color: var(--green); }
.txn-type-refund  { color: var(--yellow); }
.txn-amount { font-weight: 700; font-size: 1rem; color: var(--red); }

/* Pagination bar */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
    padding: .6rem .75rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: .8rem;
    color: var(--text-dim);
    margin-bottom: .875rem;
}
.pg-info { white-space: nowrap; }
.pg-controls { display: flex; align-items: center; gap: .4rem; }
.pg-label { white-space: nowrap; padding: 0 .25rem; }
.pg-perpage label { display: flex; align-items: center; gap: .35rem; white-space: nowrap; }
.pg-select { padding: .25rem .4rem; font-size: .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--input-bg); color: var(--text); }
.txn-credit { color: var(--green) !important; }

/* Restore banner inside edit modal */
.restore-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    background: rgba(251,191,36,.12);
    border: 1px solid rgba(251,191,36,.3);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    font-size: .875rem;
    color: var(--yellow);
}

/* =========================================
   EMPTY STATE
   ========================================= */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* =========================================
   ADMIN
   ========================================= */
.admin-page { background: var(--bg); min-height: 100vh; min-height: 100dvh; }

.admin-header {
    display: flex;
    align-items: center;
    background: #0d1b2e;
    border-bottom: 1px solid var(--border);
    color: #fff;
    padding: .875rem 1.25rem;
    gap: .75rem;
}
.admin-back, .admin-logout {
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: .85rem;
    white-space: nowrap;
    transition: color .15s;
}
.admin-back:hover, .admin-logout:hover { color: #fff; }
.admin-header-title { flex: 1; text-align: center; font-weight: 700; font-size: 1rem; }

.admin-main { max-width: 900px; margin: 0 auto; padding: 1.25rem 1rem; }
.admin-page-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 1.25rem; }
.admin-form-card { margin-bottom: 1.25rem; }
.admin-form-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-muted); }

.admin-stats { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    flex: 1;
    min-width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
}
.stat-num   { font-size: 1.8rem; font-weight: 700; color: var(--blue); }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

.admin-nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.admin-nav-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1rem;
    text-align: center;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    transition: box-shadow .15s, transform .15s, background .15s;
}
.admin-nav-card:hover {
    background: var(--card2);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.nav-card-num  { font-size: 1.7rem; font-weight: 700; color: var(--blue); line-height: 1; }
.nav-card-icon { font-size: 1.5rem; }
.nav-card-label{ font-size: .9rem;  font-weight: 700; color: var(--text); }
.nav-card-sub  { font-size: .72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }

/* Import page */
.sample-list { display: flex; flex-direction: column; gap: .625rem; }
.sample-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    background: var(--bg2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.sample-info  { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.sample-label { font-weight: 600; font-size: .9rem; }
.sample-headers {
    font-size: .75rem;
    color: var(--text-muted);
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    margin-bottom: 1.25rem;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.admin-table th {
    padding: .75rem 1rem;
    text-align: left;
    background: var(--bg2);
    color: var(--text-dim);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.admin-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border-dim);
    vertical-align: middle;
    color: var(--text);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: var(--card2); }
.admin-table .row-inactive td { opacity: .4; }
.action-cell { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.empty-cell  { text-align: center; color: var(--text-muted); padding: 2rem !important; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 400;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay[style*="flex"] { display: flex !important; }
.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}
.modal-box h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* =========================================
   FAB & Speed Dial
   ========================================= */
.fab-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .75rem;
}
.fab-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .25s, background .15s;
    -webkit-tap-highlight-color: transparent;
}
.fab-btn.open { transform: rotate(45deg); background: var(--red); }

.fab-speed-dial {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity .2s, transform .2s;
}
.fab-speed-dial.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}
.fab-option {
    display: flex;
    align-items: center;
    gap: .65rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.fab-option-label {
    background: var(--card);
    color: var(--text);
    padding: .3rem .85rem;
    border-radius: 20px;
    font-size: .875rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}
.fab-option-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
}
.fab-expense { background: rgba(248,113,113,.2); color: var(--red); }
.fab-deposit { background: var(--green-dim);    color: var(--green); }
.fab-refund  { background: rgba(251,191,36,.2); color: var(--yellow); }

/* =========================================
   Compact inline form (labels beside fields)
   ========================================= */
.form-compact .form-group {
    display: grid;
    grid-template-columns: 6.75rem 1fr;
    align-items: center;
    gap: 0 .75rem;
    margin-bottom: .75rem;
}
.form-compact .form-group label {
    margin-bottom: 0;
    text-align: right;
    white-space: nowrap;
    font-size: .925rem;     /* larger, readable label */
    letter-spacing: .02em;
}
.form-compact .form-group input:not([type="checkbox"]):not([type="radio"]),
.form-compact .form-group select {
    padding: .65rem .8rem;
    font-size: 1rem;        /* 16px — prevents iOS auto-zoom on focus */
    height: auto;
    min-height: 48px;       /* comfortable touch target */
}
.form-compact .amount-wrapper { height: auto; }
.form-compact .amount-wrapper input {
    min-height: 54px;
    font-size: 1.5rem;      /* big, easy-to-read amount */
    font-weight: 600;
}
.form-compact .currency-symbol {
    font-size: 1.2rem;
    padding-left: .85rem;
}
.form-compact .btn-full {
    margin-top: 1rem;
    min-height: 52px;
    font-size: 1.1rem;
}

/* Entry card title */
.entry-card .card-title {
    font-size: 1.25rem;
    margin-bottom: 1.1rem;
}

/* Quick-add modal */
#quickAddModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 400;
    align-items: center;
    justify-content: center;
}
#quickAddModal.open { display: flex; }
.quick-add-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.55);
}
.quick-add-box {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.5rem;
    width: min(340px, 92vw);
    box-shadow: var(--shadow-md);
    z-index: 1;
}
.quick-add-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.1rem;
}
.quick-add-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}
.quick-add-body { margin-bottom: 1.25rem; }
.quick-add-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .4rem;
}
.quick-add-input {
    width: 100%;
    padding: .65rem .9rem;
    font-size: .95rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text);
    box-sizing: border-box;
}
.quick-add-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
.quick-add-error { color: var(--red); font-size: .8rem; margin-top: .4rem; min-height: 1em; }
.quick-add-footer { display: flex; justify-content: flex-end; gap: .6rem; }

/* =========================================
   Transaction Modals (bottom sheet style)
   ========================================= */
.txn-modal-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 150;
}
.txn-modal-backdrop.open { display: block; }

.txn-modal {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 160;
    transform: translateY(100%);
    transition: transform .3s ease;
    max-height: 92vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.txn-modal.open { transform: translateY(0); }

.txn-modal-box {
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
}
.txn-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    font-size: 1.05rem;
    font-weight: 700;
}
.modal-x {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 .25rem;
    line-height: 1;
}
.required-star { color: var(--red); }

/* Transaction type colors */
.txn-amount         { color: var(--red); }
.txn-credit         { color: var(--green) !important; }
.badge-refund       { background: rgba(251,191,36,.15); color: var(--yellow); }

/* =========================================
   Recurring toast notification
   ========================================= */
#recurringToast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--green);
    color: var(--text);
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
    font-size: .9rem;
    white-space: nowrap;
    z-index: 500;
    transition: transform .35s cubic-bezier(.34,1.56,.64,1);
    pointer-events: none;
}
#recurringToast.show {
    transform: translateX(-50%) translateY(0);
}

/* =========================================
   Responsive tweaks
   ========================================= */
@media (min-width: 600px) {
    .app-main  { padding: 1.25rem; }
    .entry-card { padding: 2rem; }
}

/* =========================================
   Mobile card view — register & summary
   ========================================= */
@media (max-width: 640px) {

    /* ── Break table layout so grid/block overrides actually work ── */
    /* Browsers ignore display:grid on <tr> unless the table itself is block */
    .register-table-wrap { overflow-x: visible; }
    .register-table,
    .register-table tbody { display: block; white-space: normal; }
    .register-table thead { display: none; }

    /* Clear per-cell alternating backgrounds so the TR card shows through */
    .register-table tbody tr.row-even td,
    .register-table tbody tr.row-odd  td,
    .register-table tbody tr:hover    td,
    .register-table tbody             td { background: transparent !important; }

    .register-table tbody tr {
        display: grid !important;
        grid-template-areas:
            "date   amount"
            "payee  payee"
            "cat    type"
            "acct   acct"
            "acts   acts";
        grid-template-columns: 1fr auto;
        column-gap: .5rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin: 0 0 .45rem;
        padding: .55rem .7rem;
        background: var(--card) !important;
    }

    /* Hidden rows keep their tint on the card itself */
    .register-table tbody tr.row-hidden {
        background: rgba(248,113,113,.06) !important;
        opacity: .65;
    }

    /* All cells: reset table defaults */
    .register-table tbody td {
        display: block;
        padding: 0 !important;
        border: none !important;
        overflow: visible !important;
        white-space: normal !important;
        text-overflow: clip !important;
        font-size: .85rem;
        line-height: 1.3;
    }

    /* Cell placement */
    .register-table td[data-col="date"] {
        grid-area: date;
        font-size: .74rem;
        color: var(--text-muted);
        align-self: center;
    }
    .register-table td[data-col="amount"] {
        grid-area: amount;
        font-size: .95rem;
        font-weight: 700;
        text-align: right;
        align-self: center;
    }
    .register-table td[data-col="payee"] {
        grid-area: payee;
        font-size: .88rem;
        font-weight: 600;
        padding: .2rem 0 .05rem !important;
    }
    .register-table td[data-col="category"] {
        grid-area: cat;
        font-size: .74rem;
        color: var(--text-muted);
        align-self: center;
    }
    .register-table td[data-col="type"] {
        grid-area: type;
        font-size: .72rem;
        text-align: right;
        align-self: center;
    }
    .register-table td[data-col="account"] {
        grid-area: acct;
        font-size: .72rem;
        color: var(--text-dim);
        padding-bottom: .15rem !important;
    }
    /* User column hidden on mobile — low value */
    .register-table td[data-col="user"] { display: none !important; }

    .register-table td.col-actions {
        grid-area: acts;
        text-align: right;
        padding-top: .25rem !important;
        white-space: nowrap !important;
    }

    /* Opening-balance row: simple flex, no grid */
    .register-table tr.row-begin-balance {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: .4rem .7rem !important;
        background: rgba(59,130,246,.07) !important;
    }
    .register-table tr.row-begin-balance td          { display: none !important; }
    .register-table tr.row-begin-balance td:nth-child(2) {
        display: block !important;
        font-size: .75rem;
        color: var(--text-muted);
        font-style: italic;
    }
    .register-table tr.row-begin-balance td:nth-child(3) {
        display: block !important;
        font-size: .88rem;
        font-weight: 700;
        text-align: right;
    }

    /* Pagination bar: wrap on small screens */
    .pagination-bar {
        flex-wrap: wrap;
        gap: .4rem;
        font-size: .8rem;
    }

    /* ── Summary: card layout ── */
    #summaryTable,
    #summaryTable tbody { display: block; }
    #summaryTable thead { display: none; }

    #summaryTable tbody tr {
        display: grid !important;
        grid-template-areas: "name name name" "bud  spt  rem";
        grid-template-columns: 1fr 1fr 1fr;
        row-gap: .25rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin: 0 0 .4rem;
        padding: .5rem .65rem;
        background: var(--card) !important;
    }

    #summaryTable td {
        display: block;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: .85rem;
        line-height: 1.3;
    }

    /* Category name spans all 3 columns as card title */
    #summaryTable td:first-child {
        grid-area: name;
        font-weight: 600;
        font-size: .88rem;
        color: var(--text);
    }

    /* Three amount columns */
    #summaryTable td:nth-child(2) { grid-area: bud;  text-align: center; }
    #summaryTable td:nth-child(3) { grid-area: spt;  text-align: center; }
    #summaryTable td:nth-child(4) { grid-area: rem;  text-align: center; }

    /* Tiny label above each amount via data-label */
    #summaryTable td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: .62rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--text-muted);
        margin-bottom: .1rem;
    }
}
