:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    padding: 2rem;
}

.container {
    max-width: 1600px;
    width: 95%;
    margin: 0 auto;
}

header {
    margin-bottom: 1.5rem;
    /* Reduced margin */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 0 1rem;
    /* Add side padding */
}

.branding {
    text-align: left;
}

header h1 {
    font-size: 1.8rem;
    /* Smaller font */
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.header-user-controls {
    display: none;
    /* Hidden by default */
    gap: 1rem;
    align-items: center;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem;
    text-decoration: underline;
    transition: color 0.2s;
}

.text-btn:hover {
    color: var(--primary-color);
}

/* Compact Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    /* Reduced from default */
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.controls-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    /* Align inputs and buttons at bottom */
    width: 100%;
}

.input-group-row>.input-group {
    flex: 1;
    /* Ensure distinct date inputs split space */
    min-width: 0;
}

.expand-input {
    flex: 1;
    min-width: 0;
}

.compact-calc-btn {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    height: 38px;
    /* Match input height roughly */
    display: flex;
    align-items: center;
}

/* Reduce label margins */
.input-group label {
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

/* Reduce input padding/height if needed */
.input-group input,
.input-group select {
    padding: 0.4rem;
    font-size: 0.9rem;
}

.control-label {
    font-size: 0.8rem;
    font-weight: bold;
    text-decoration: underline;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    display: block;
}

/* Collapsible Headers */
.collapsible-header {
    cursor: pointer;
    user-select: none;
}

.header-title-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-icon {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.collapsible-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.item-list {
    transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
    max-height: 2000px;
    /* Large enough for content */
    opacity: 1;
    overflow: hidden;
    transform-origin: top;
}

.item-list.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
    overflow: hidden;
}

.input-group {
    display: flex;
    flex-direction: column;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: var(--primary-hover);
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.item-list {
    list-style: none;
    max-height: 350px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.item-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.item-list li:last-child {
    border-bottom: none;
}

.results {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.results h2 {
    margin-bottom: 1rem;
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll for mobile */
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th,
td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    background-color: #f1f5f9;
}

tr:hover {
    background-color: #f8fafc;
}

/* Transaction Rows - Global (Desktop) Toggle Logic */
tr.tx-row {
    display: none;
}

tr.tx-row.visible {
    display: table-row;
}

.amount-in {
    color: var(--success-color);
    font-weight: 500;
}

.amount-out {
    color: var(--danger-color);
    font-weight: 500;
}

.balance-positive {
    color: var(--text-main);
    font-weight: 600;
}

.balance-negative {
    color: var(--danger-color);
    font-weight: 600;
}

.forecast-row {
    background-color: #f0f8ff;
}

.forecast-row td[contenteditable="true"] {
    background-color: #fff8dc;
    border: 1px dashed #aaa;
    cursor: text;
}

/* Modern action buttons - equal size with hover effects */
.confirm-btn,
.delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.confirm-btn {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.confirm-btn:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
}

.delete-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    margin-left: 6px;
}

.delete-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.3);
}

.confirm-btn:active,
.delete-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.saved-badge {
    margin-right: 10px;
}

/* Compact table buttons */
.tx-edit-btn,
.save-balance-btn,
.edit-balance-btn,
.recalc-balance-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    border-radius: 6px;
    line-height: 1.2;
}

.day-summary td {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Card header with edit button */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h2 {
    margin-bottom: 0;
}

.edit-list-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.edit-list-btn:hover {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
}

/* Modal overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 500px;
    width: 100%;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
}

.modal-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--danger-color);
    background: none;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

/* Modal item list */
.modal-item-list {
    list-style: none;
    margin-bottom: 1.5rem;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.modal-item-list:empty {
    display: none;
}

.modal-item-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-item-list li:last-child {
    border-bottom: none;
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.item-name {
    font-weight: 500;
}

.item-details {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

.item-edit-btn,
.item-delete-btn {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
    padding: 0;
}

.item-edit-btn {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.item-edit-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.item-delete-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.item-delete-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

/* Form styles */
.item-form {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.item-form h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 140px;
}

.form-group select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: white;
    cursor: pointer;
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #059669, #047857);
}

.btn-secondary {
    background: linear-gradient(135deg, #64748b, #475569);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #475569, #334155);
}

/* Results header */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.min-balance-wrapper {
    background-color: var(--card-bg);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-color);
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
    font-weight: 500;
}

.min-balance-value {
    font-weight: 700;
    color: var(--text-color);
}

.min-balance-value.negative {
    color: var(--danger-color);
}

.add-transaction-btn {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.add-transaction-btn:hover {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
}

/* Transaction form */
.transaction-form {
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.transaction-form .form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.transaction-form .form-group {
    flex: 1;
    min-width: 140px;
}

.transaction-form .form-group.type-group {
    min-width: 280px;
    flex: 1.5;
}

#tx-account-group,
#tx-transfer-target-group {
    min-width: 180px;
}

.transaction-form .form-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Transaction type toggle */
.tx-type-toggle {
    display: flex;
    gap: 0.5rem;
}

.tx-type-option {
    flex: 1;
}

.tx-type-option input {
    display: none;
}

.tx-type-label {
    display: block;
    padding: 0.5rem 0.75rem;
    text-align: center;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    border: 2px solid var(--border-color);
    transition: all 0.2s;
}

.tx-type-label.out {
    color: var(--danger-color);
}

.tx-type-label.in {
    color: var(--success-color);
}

.tx-type-option input:checked+.tx-type-label.out {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

.tx-type-option input:checked+.tx-type-label.in {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.tx-type-label.transfer {
    color: #8b5cf6;
    border-color: #8b5cf6;
}

.tx-type-option input:checked+.tx-type-label.transfer {
    background: #8b5cf6;
    color: white;
    border-color: #8b5cf6;
}

/* Quick Action Buttons */
.quick-actions {
    flex: 1;
    min-width: 200px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    /* Reduced gap */
    align-self: stretch;
}

.quick-btn {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.5rem 0.25rem;
    /* Reduced padding */
    border-radius: 6px;
    font-size: 0.8rem;
    /* Smaller font */
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
}

.quick-btn:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Layout Refactor (Desktop Base) */
.app-layout {
    display: grid;
    grid-template-columns: 30% 1fr;
    gap: 2rem;
    align-items: start;
    position: relative;
    /* Distinct gutter for toggle */
    transition: all 0.3s ease;
}

.account-control-panel {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.account-control-panel label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.account-select-wrapper {
    display: flex;
    gap: 0.5rem;
}

.account-select-wrapper select {
    flex: 1;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.account-select-wrapper button {
    padding: 0.5rem;
    width: 2.5rem;
}

.sidebar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: sticky;
    top: 1rem;
    /* Removed internal padding */
}

.content {
    grid-column: 2;
    grid-row: 1;
}

.sidebar .controls,
.sidebar .dashboard {
    margin-bottom: 0;
}

.sidebar .dashboard {
    grid-template-columns: 1fr;
}

/* Sidebar Toggle */
.sidebar-toggle {
    display: flex;
    position: absolute;
    left: -50px;
    top: -30px;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 32px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    z-index: 20;
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    color: var(--primary-color);
    background: #e2e8f0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Collapsed State */
.app-layout.collapsed {
    grid-template-columns: 0 1fr;
    gap: 0;
}

.app-layout.collapsed .sidebar {
    display: none;
}

.app-layout.collapsed .sidebar-toggle {
    border-radius: 4px;
    background: var(--card-bg);
    /* Keep same size/pos */
}

/* Balance Mismatch Styles */
.mismatch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mismatch-icon {
    margin-left: 8px;
    cursor: help;
    font-size: 1.1em;
    color: darkorange;
}

.balance-cell.mismatch {
    position: relative;
    color: darkorange;
    font-weight: bold;
}

.mismatch-icon[title] {
    border-bottom: 1px dotted #888;
}

/* Daily Grouping Styles */
.day-header td {
    border-top: 2px solid #d0d0d0;
    padding-top: 12px;
}

.hide-date {
    color: transparent;
    user-select: none;
}

tbody tr:not(.day-header) td {
    border-top: none;
}

/* Auth Specific Styles */
.modal-content.auth-content {
    max-width: 400px;
    padding: 2.5rem !important;
    text-align: center;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: block;
}

.auth-content h2 {
    margin-bottom: 2rem;
    color: var(--text-main);
    font-size: 1.8rem;
    font-weight: 700;
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    text-align: left;
}

#auth-form label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 0.2rem;
}

#auth-form input {
    width: 100%;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    background-color: #f8fafc;
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.2s ease;
}

#auth-form input:focus {
    border-color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.auth-toggle {
    margin-top: 1.5rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.auth-toggle a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-toggle a:hover {
    text-decoration: underline;
}

.full-width.btn-primary {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    margin-top: 1rem;
}

.full-width:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.form-error {
    color: var(--danger-color);
    font-size: 0.9rem;
    min-height: 1.25rem;
    text-align: center;
}

/* --------------------------------------------------------- */
/* MOBILE OVERRIDES (Max Width 768px)                        */
/* --------------------------------------------------------- */

/* Mobile Menu Button - Default Hidden */
.mobile-menu-btn {
    display: none;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary-color);
    padding: 0.5rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    box-shadow: none;
}

/* Sidebar Overlay - Default Hidden */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 768px) {

    /* Layout Reset */
    body {
        padding: 1rem;
    }

    .container {
        width: 100%;
    }

    .sidebar-toggle {
        display: none !important;
        /* Force hide on mobile */
    }

    .app-layout {
        display: block;
        /* Stack on mobile */
        padding-left: 0;
        /* Reset gutter on mobile */
    }

    /* Header Adjustments */
    header {
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .header-user-controls {
        position: static;
        margin-top: 1rem;
        transform: none;
        width: 100%;
        justify-content: center;
    }

    .mobile-menu-btn {
        display: block;
    }

    header {
        padding-left: 3rem;
        padding-right: 3rem;
    }

    /* Main Layout - Block instead of Grid */
    .app-layout {
        display: block;
        position: relative;
        overflow: hidden;
    }

    /* Sidebar - Drawer Mode */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100%;
        width: 85%;
        max-width: 320px;
        background: var(--bg-color);
        z-index: 1000;
        transform: translateX(-110%);
        padding: 1rem;
        box-shadow: var(--shadow-md);
        border-right: 1px solid var(--border-color);
        overflow-y: auto;
        transition: transform 0.3s ease-in-out;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar.active+.sidebar-overlay {
        display: block;
    }

    .controls-main {
        grid-template-columns: 1fr;
    }

    .results {
        padding: 1rem;
    }

    /* Card View for Mobile Tables */
    .table-wrapper {
        margin-right: 0;
        padding-right: 0;
        overflow-x: visible;
    }

    /* Break Table Layout */
    table,
    tbody,
    th,
    td {
        display: block;
    }

    tr {
        display: block;
    }

    /* Fallback */

    /* Hide Header Row Completely */
    thead {
        display: none;
    }

    /* Transaction Rows - Card Layout */
    /* HIDDEN BY DEFAULT for Expand/Collapse to work */
    tr.tx-row {
        display: none;
        grid-template-columns: 1fr auto auto;
        grid-template-rows: auto auto auto;
        gap: 0.25rem;
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--border-color);
        background: white;
        margin-bottom: 0.5rem;
        border-radius: 8px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    }

    /* Visible State (Toggled by JS) */
    tr.tx-row.visible {
        display: grid;
    }

    /* Card Content Mapping */
    /* Date */
    tr.tx-row td:nth-child(1) {
        grid-column: 1 / -1;
        grid-row: 1;
        font-size: 0.75rem;
        color: var(--text-muted);
        padding: 0;
        border: none;
    }

    /* Description */
    tr.tx-row td:nth-child(2) {
        grid-column: 1 / 2;
        grid-row: 2;
        font-weight: 500;
        font-size: 0.95rem;
        padding: 0;
        border: none;
        white-space: normal;
        line-height: 1.3;
        padding-right: 0.5rem;
    }

    /* In Amount */
    tr.tx-row td:nth-child(3):not(:empty) {
        grid-column: 2 / 3;
        grid-row: 2;
        text-align: right;
        padding: 0;
        border: none;
        font-weight: 600;
        color: var(--success-color);
        align-self: center;
    }

    tr.tx-row td:nth-child(3):empty {
        display: none;
    }

    /* Out Amount */
    tr.tx-row td:nth-child(4):not(:empty) {
        grid-column: 2 / 3;
        grid-row: 2;
        text-align: right;
        padding: 0;
        border: none;
        font-weight: 600;
        color: var(--danger-color);
        align-self: center;
    }

    tr.tx-row td:nth-child(4):empty {
        display: none;
    }

    /* Balance */
    tr.tx-row td:nth-child(5) {
        grid-column: 1 / -1;
        grid-row: 3;
        text-align: right;
        padding: 0;
        border: none;
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-top: 0.25rem;
    }

    tr.tx-row td:nth-child(5)::before {
        content: "Bal: ";
    }

    /* Actions */
    tr.tx-row td:nth-child(6) {
        grid-column: 3 / 4;
        grid-row: 2;
        padding: 0;
        border: none;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        margin-left: 0.5rem;
    }

    tr.tx-row td:nth-child(6) button {
        width: 32px;
        height: 32px;
        padding: 0;
    }

    /* Day Summary Rows */
    tr.day-summary {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0.5rem;
        background: #f1f5f9;
        border-bottom: 2px solid var(--border-color);
        margin-top: 0.5rem;
        border-radius: 4px;
    }

    tr.day-summary td {
        padding: 0;
        border: none;
        width: auto;
    }

    /* Date Cell */
    tr.day-summary td:nth-child(1) {
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.9rem;
    }

    /* Balance Cell */
    tr.day-summary td:nth-child(2) {
        font-weight: 700;
        margin-left: auto;
        margin-right: 0.5rem;
        font-size: 0.9rem;
    }

    /* Action Cell (Buttons) */
    tr.day-summary td:nth-child(3) {
        display: flex;
        gap: 0.5rem;
    }

    /* Fix Button Sizing in Summary */
    tr.day-summary button {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        line-height: 1;
        height: auto;
    }

    /* General Button Padding for Mobile (excluding summary buttons if cleaner) */
    button:not(.confirm-btn):not(.delete-btn):not(.mobile-menu-btn):not(.edit-balance-btn):not(.recalc-balance-btn) {
        padding: 0.75rem 1rem;
    }
}

/* User Info Group */
.user-info {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Upcoming Bills Notification */
#upcoming-bills-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#upcoming-bills-btn:hover {
    transform: scale(1.1);
}

.upcoming-safe {
    background-color: var(--success-color);
    /* Green */
}

.upcoming-warn {
    background-color: var(--danger-color);
    /* Red */
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}


/* Results Header Refactor */
.results-header {
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-stats {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.date-range-display {
    font-size: 0.95rem;
    /* Slightly smaller to fit stack */
    font-weight: 500;
    color: var(--text-color);
    margin: 0;
    /* text-align: left included by default block flow */
}

/* Ensure min-balance-wrapper has no conflicting margins */
.min-balance-wrapper {
    margin: 0;
    /* Clear any previous margins */
    /* Keep other styles (border etc) */
}

.header-actions-right {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-left: auto;
}

.header-actions-right button {
    width: 100%;
    min-width: 160px;
    margin: 0 !important;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
}

/* Compact List Styles (Bills/Income) */
.compact-item {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.compact-item:last-child {
    border-bottom: none;
}

.item-info-compact {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-color);
    flex-wrap: wrap;
    /* Safety wrap for small screens */
}

.item-name-compact {
    font-weight: 600;
    color: var(--text-main);
}

.item-amount-compact {
    font-family: inherit;
    font-weight: 500;
}

.item-meta-compact {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.item-day-compact {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

.separator {
    color: var(--border-color);
    font-size: 0.8rem;
}

/* Empty Message */
.empty-msg {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}


/* Maintenance Buttons */
.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}


/* Refined Header Layout */
.header-left {
    flex: 1;
}

.header-stats-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    max-width: 600px;
}

.date-range-display {
    font-size: 1.5rem;
    color: var(--text-muted);
    font-weight: bold;
    margin-left: 2px;
    text-align: center;
}

.header-balances {
    display: flex;
    gap: 1rem;
    align-items: center;
}