/* ===== CSS VARIABLES & RESET ===== */
:root {
    /* Colors - Light Theme (Premium Clean Fintech Aesthetic) */
    --bg-primary: #f7f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #edf2f7;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;

    /* Energetic modern accent */
    --accent-primary: #4f46e5;
    --accent-secondary: #6366f1;
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #9333ea 100%);

    /* Status colors with softer, harmonious backgrounds */
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #e11d48;
    --danger-bg: #fff1f2;
    --warning: #ea580c;
    --warning-bg: #fff7ed;

    /* Modern diffuse shadows */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

/* Personal Workspace Theme Overrides */
[data-workspace="personal"] {
    --accent-primary: #10b981;
    --accent-secondary: #34d399;
    --accent-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

[data-workspace="personal"][data-theme="dark"] {
    --accent-primary: #34d399;
    --accent-secondary: #10b981;
    --accent-gradient: linear-gradient(135deg, #34d399 0%, #10b981 100%);
}

/* Reset */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== APP LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ===== TOP BAR ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    gap: 5px;
}

.menu-toggle span {
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.top-bar-stats {
    display: flex;
    gap: 1rem;
}

.stat-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
}

.balance-chip .stat-value {
    color: var(--accent-primary);
}

.saving-chip .stat-value {
    color: var(--success);
}

.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--bg-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--border-color);
    transform: scale(1.05);
}

.theme-toggle svg {
    width: 22px;
    height: 22px;
    stroke: var(--text-primary);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

/* ===== PWA INSTALL BUTTON ===== */
.pwa-install-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    background: rgba(99, 102, 241, 0.08);
    color: var(--accent-primary);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    height: 36px;
    /* Align with theme toggle if possible */
}

.pwa-install-btn:hover {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.pwa-install-btn svg {
    width: 16px;
    height: 16px;
}

.pwa-install-btn.hidden {
    display: none !important;
}

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 0;
    overflow-y: auto;
    z-index: 900;
    transition: var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
    overflow: hidden;
}

@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 80px;
    }

    .sidebar.collapsed .sidebar-header {
        padding: 0 1.5rem 1.5rem;
        justify-content: center;
    }

    .sidebar.collapsed .sidebar-header span {
        display: none;
    }

    .sidebar.collapsed .nav-item {
        justify-content: center;
        padding: 0.875rem 0;
    }

    .sidebar.collapsed .nav-item span {
        display: none;
    }

    .sidebar.collapsed .sidebar-bottom-actions {
        padding: 1rem 0.5rem !important;
        align-items: center;
    }

    .sidebar.collapsed .sidebar-bottom-actions .btn {
        justify-content: center !important;
        padding: 0.6rem 0 !important;
        width: 44px !important;
        height: 44px !important;
    }

    .sidebar.collapsed .sidebar-bottom-actions .btn span {
        display: none !important;
    }

    .sidebar.collapsed~.main-content {
        margin-left: 80px;
    }
}

.sidebar-header .logo {
    font-size: 2rem;
}

.sidebar-header span {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.nav-menu {
    list-style: none;
    padding: 0 0.75rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-md);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.nav-item.active svg {
    stroke: white;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    min-width: 0;
    /* CRITICAL FIX: allows flex child to shrink below inherent content width */
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 2rem;
    min-height: calc(100vh - var(--topbar-height));
    transition: var(--transition);
    overflow-x: hidden;
    max-width: 100%;
    /* Keep settings form and backup options from clipping/underlapping */
    box-sizing: border-box;
}

.content-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.content-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.section-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    white-space: nowrap;
}

.btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== VIEW TOGGLE ===== */
.view-toggle {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 4px;
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ===== DASHBOARD ===== */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.dash-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.dash-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
}

.card-content {
    display: flex;
    flex-direction: column;
}

.card-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.balance-card .card-value {
    color: var(--accent-primary);
}

.due-card .card-value {
    color: var(--warning);
}

.saving-card .card-value {
    color: var(--success);
}

.today-card .card-value {
    color: var(--text-primary);
}

/* ===== CHARTS ===== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.chart-container.full-width {
    grid-column: 1 / -1;
}

.chart-container h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-input::placeholder {
    color: var(--text-muted);
}

textarea.form-input {
    min-height: 100px;
    resize: vertical;
}

/* ===== RECORDS ===== */
.records-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.records-filters .form-input {
    width: auto;
}

.records-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

/* Table View */
.records-table {
    width: 100%;
    border-collapse: collapse;
}

.records-table th,
.records-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.records-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.records-table tr:last-child td {
    border-bottom: none;
}

.records-table tr:hover td {
    background: var(--bg-tertiary);
}

/* Card View */
.records-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.record-card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.record-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
}

.record-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.record-date {
    font-weight: 600;
    font-size: 1.1rem;
}

.record-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-settled {
    background: var(--success-bg);
    color: var(--success);
}

.status-due {
    background: var(--warning-bg);
    color: var(--warning);
}

.record-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.record-stat {
    text-align: center;
}

.record-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.record-stat-value {
    font-weight: 600;
    font-size: 1rem;
}

.record-stat-value.positive {
    color: var(--success);
}

.record-stat-value.negative {
    color: var(--danger);
}

.record-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.record-actions button {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-edit {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-delete {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ===== CATEGORIES ===== */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.category-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.category-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.category-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.category-type {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--accent-gradient);
    color: white;
}

.category-type.transport {
    background: #3b82f6;
}

.category-type.food {
    background: #f59e0b;
}

.category-type.misc {
    background: #8b5cf6;
}

.category-stats {
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.category-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ===== FUNDS ===== */
.fund-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.fund-stat {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.fund-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.fund-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.funds-list {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.fund-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.fund-item:last-child {
    border-bottom: none;
}

.fund-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.fund-item-type {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.fund-item-details {
    font-weight: 500;
}

.fund-item-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.fund-item-amount {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
}

/* ===== ANALYTICS ===== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    height: 350px;
    /* Force a max height to prevent infinite scaling on mobile */
    width: 100%;
}

.chart-container h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.1rem;
    text-align: center;
}

@media (max-width: 768px) {
    .chart-container {
        height: 300px;
        /* Slightly smaller on mobile to fit the screen nicely */
        padding: 1rem;
    }
}

.analytics-filters {
    margin-left: auto;
}

.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analytics-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.analytics-card.positive {
    border-left: 4px solid var(--success);
}

.analytics-card.negative {
    border-left: 4px solid var(--danger);
}

.analytics-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.analytics-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.analytics-card.positive .analytics-value {
    color: var(--success);
}

.analytics-card.negative .analytics-value {
    color: var(--danger);
}

/* ===== REPORTS ===== */
.report-options {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    max-width: 600px;
    margin: 0 auto;
}

.report-type-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.report-type {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.report-type input {
    display: none;
}

.report-type.active,
.report-type:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.05);
}

.type-icon {
    font-size: 2rem;
}

.report-date-inputs {
    margin-bottom: 2rem;
}

.date-input-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.date-input-group.hidden {
    display: none;
}

.date-input-group label {
    font-weight: 500;
    color: var(--text-secondary);
}

.date-input-group .form-input {
    flex: 1;
    min-width: 150px;
}

.report-includes {
    margin-bottom: 2rem;
}

.report-includes h4 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
}

/* ===== SETTINGS ===== */
.settings-form {
    max-width: 800px;
}

.settings-group {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.settings-group h3 {
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* ===== BACKUP ===== */
.backup-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    max-width: 1200px;
}

.backup-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.backup-card .btn {
    width: 100%;
    margin-top: auto;
    justify-content: center;
}

.backup-card.danger {
    border-color: var(--danger);
}

.backup-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.backup-card h3 {
    margin-bottom: 0.5rem;
}

.backup-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: var(--transition);
    box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-tertiary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 1rem 2rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    opacity: 0;
    transition: var(--transition);
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* ===== ENTRY FORM (Inside Modal) ===== */
.entry-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.entry-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.entry-row.three-col {
    grid-template-columns: 1fr 1fr 1fr;
}

.route-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    font-weight: 500;
}

.route-arrow {
    color: var(--accent-primary);
    font-size: 1.25rem;
}

.saving-display {
    text-align: center;
    padding: 1rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1.25rem;
}

.saving-display.positive {
    background: var(--success-bg);
    color: var(--success);
}

.saving-display.negative {
    background: var(--danger-bg);
    color: var(--danger);
}

.saving-display.neutral {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Entry List in Record Form */
.entries-list {
    margin-top: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.entry-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.entry-item:last-child {
    border-bottom: none;
}

.entry-info {
    flex: 1;
}

.entry-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.entry-amounts {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.entry-saving {
    font-weight: 600;
}

.entry-saving.positive {
    color: var(--success);
}

.entry-saving.negative {
    color: var(--danger);
}

.entry-actions {
    display: flex;
    gap: 0.5rem;
}

.entry-actions button {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

/* Category Tabs in Record Form */
.category-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.category-tab {
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.category-tab:hover {
    border-color: var(--accent-primary);
}

.category-tab.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
    }

    .top-bar-stats {
        display: none;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .dashboard-cards {
        grid-template-columns: 1fr 1fr;
    }

    .report-type-selector {
        grid-template-columns: 1fr;
    }

    .records-cards {
        grid-template-columns: 1fr;
    }

    .entry-row {
        grid-template-columns: 1fr;
    }

    .entry-row.three-col {
        grid-template-columns: 1fr 1fr;
    }

    .date-input-group {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    .dashboard-cards {
        grid-template-columns: 1fr;
    }

    .fund-summary {
        grid-template-columns: 1fr;
    }

    .analytics-summary {
        grid-template-columns: 1fr 1fr;
    }

    .modal {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
    }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== CHECKBOX STYLING FOR BULK SELECT ===== */
.record-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* ===== LOADING SPINNER ===== */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

.text-success {
    color: var(--success) !important;
}

.text-danger {
    color: var(--danger) !important;
}

.text-warning {
    color: var(--warning) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

/* ===== SUGGESTIONS MANAGER ===== */
.suggestions-manager-card {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    color: white;
    grid-column: 1 / -1;
}

.suggestions-manager-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.suggestions-manager-card p {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 1rem;
}

.suggestions-summary {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.suggestion-type-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.suggestion-type-badge:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.suggestion-type-badge strong {
    margin-left: 0.25rem;
}

.input-with-button {
    display: flex;
    gap: 0.5rem;
}

.input-with-button .form-input {
    flex: 1;
}

.suggestions-list {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 1rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.suggestion-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
}

.suggestion-item:last-child {
    margin-bottom: 0;
}

.suggestion-item span {
    font-weight: 500;
}

.suggestion-item .btn-delete {
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
}

/* ===== REPORT OPTIONS ENHANCEMENTS ===== */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.notes-group {
    margin-top: 1rem;
}

.notes-group textarea {
    min-height: 80px;
    resize: vertical;
}

@media (max-width: 480px) {
    .checkbox-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== LOADING SPINNER ===== */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Status badges ===== */
.status-due {
    background: var(--danger);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.status-settled {
    background: var(--success);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ===== ENTRY EDITING ===== */
.entry-item.editing {
    border: 2px solid var(--accent-primary);
    background: rgba(99, 102, 241, 0.08);
    border-radius: var(--radius-md);
}

.entry-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.entry-actions .btn-edit:hover {
    opacity: 0.7;
}

/* ===== DATE RANGE FILTER ===== */
.date-range-filter {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.date-range-inputs {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    flex: 1;
}

.date-range-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 160px;
}

.date-range-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.date-range-field .form-input {
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
}

.date-range-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.date-range-actions .btn {
    white-space: nowrap;
}

/* Date Range Label */
.date-range-label {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    letter-spacing: 0.3px;
}

/* ===== FILTERED REPORT TABLE ===== */
.filtered-report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.filtered-report-table th,
.filtered-report-table td {
    padding: 0.75rem 0.85rem;
    text-align: center;
    border: 1px solid var(--border-color);
    vertical-align: middle;
}

.filtered-report-table thead th {
    background: var(--bg-tertiary);
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

/* Cash In column header */
.filtered-report-table th.col-cash-in {
    background: #e5f2f0;
    color: #2e7d32;
}

/* Cash Out column header */
.filtered-report-table th.col-cash-out {
    background: #fbebee;
    color: #c62828;
}

[data-theme="dark"] .filtered-report-table th.col-cash-in {
    background: rgba(46, 125, 50, 0.15);
}

[data-theme="dark"] .filtered-report-table th.col-cash-out {
    background: rgba(198, 40, 40, 0.15);
}

.filtered-report-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.filtered-report-table tbody tr:last-child td {
    border-bottom: 1px solid var(--border-color);
}

/* Cash In cells */
.filtered-report-table td.cell-cash-in {
    background: #e5f2f0;
    color: #2e7d32;
    font-weight: 600;
}

/* Cash Out cells */
.filtered-report-table td.cell-cash-out {
    background: #fbebee;
    color: #c62828;
    font-weight: 600;
}

[data-theme="dark"] .filtered-report-table td.cell-cash-in {
    background: rgba(46, 125, 50, 0.1);
}

[data-theme="dark"] .filtered-report-table td.cell-cash-out {
    background: rgba(198, 40, 40, 0.1);
}

/* Balance colors */
.text-red {
    color: #c62828 !important;
}

.text-green {
    color: #2e7d32 !important;
}

/* Previous Balance row */
.previous-balance-row td {
    text-align: center;
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
    padding: 0.85rem 0.75rem;
}

/* ===== SUMMARY TABLE ===== */
.summary-table-container {
    margin-top: 1.5rem;
}

.summary-table {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.summary-table td {
    padding: 0.75rem 1.25rem;
    border: 1px solid var(--border-color);
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
}

.summary-table tr.summary-label td:first-child {
    font-weight: 700;
}

.summary-table tr.summary-cashin td:first-child {
    color: #2e7d32;
}

.summary-table tr.summary-cashout td:first-child {
    color: #c62828;
}

.summary-table tr.summary-final {
    background: var(--bg-tertiary);
}

.summary-table tr.summary-final td {
    font-size: 1.05rem;
    font-weight: 700;
    border-top: 2px solid var(--border-color);
}

/* ===== RESPONSIVE: Date Range Filter ===== */
@media (max-width: 600px) {
    .date-range-filter {
        flex-direction: column;
        align-items: stretch;
    }

    .date-range-inputs {
        flex-direction: column;
    }

    .date-range-field {
        min-width: unset;
    }

    .date-range-actions {
        justify-content: stretch;
    }

    .date-range-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .filtered-report-table {
        font-size: 0.8rem;
    }

    .filtered-report-table th,
    .filtered-report-table td {
        padding: 0.5rem 0.4rem;
    }
}

/* ===== SUGGESTION AUTOCOMPLETE DROPDOWN ===== */
.suggestion-input-wrapper {
    position: relative;
    width: 100%;
}

.suggestion-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1050;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.suggestion-dropdown.visible {
    display: block;
}

.suggestion-dropdown-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.15s ease;
    border-bottom: 1px solid var(--border-color);
}

.suggestion-dropdown-item:last-child {
    border-bottom: none;
}

.suggestion-dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.suggestion-dropdown-item.highlighted {
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
}

.suggestion-dropdown-add {
    padding: 0.65rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--success);
    background: var(--success-bg);
    border-top: 1px solid var(--border-color);
    transition: background 0.15s ease, color 0.15s ease;
    font-weight: 500;
}

.suggestion-dropdown-add:hover {
    background: var(--success);
    color: white;
}

.suggestion-dropdown-add.highlighted {
    background: var(--success);
    color: white;
    font-weight: 700;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.suggestion-dropdown-add strong {
    font-weight: 700;
}

.suggestion-dropdown-empty {
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* ===== UTILITIES & PWA MOBILE FIXES ===== */
.hidden {
    display: none !important;
}

@media (max-width: 600px) {
    .hidden-mobile {
        display: none !important;
    }

    .top-bar-stats {
        gap: 0.5rem;
    }

    .pwa-install-btn {
        padding: 0.4rem 0.6rem;
    }

    .pwa-install-btn .pwa-text {
        display: none;
        /* Hide the text "Install" on mobile */
    }
}