/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f6fa; color: #2c3e50; line-height: 1.6; }
a { color: #3498db; text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navigation === */
.main-nav { background: #2c3e50; color: #fff; display: flex; align-items: center; padding: 0 1rem; height: 56px; flex-wrap: wrap; }
.nav-brand { font-size: 1.1rem; font-weight: 700; margin-right: auto; }
.nav-toggle { display: none; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }
.nav-links a { color: #bdc3c7; padding: 0 0.75rem; line-height: 56px; display: inline-block; }
.nav-links a:hover, .nav-links a.active { color: #fff; text-decoration: none; }
.nav-report { color: #f39c12 !important; }
.nav-report:hover, .nav-report.active { color: #f1c40f !important; }
.nav-logout { color: #e74c3c !important; }

/* === Container === */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }

/* === Page Header === */
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.5rem; }
.page-header h1 { margin: 0; }
.period-label { color: #7f8c8d; font-size: 0.9rem; margin-bottom: 1.5rem; }

/* === Period Filter === */
.period-filter { display: inline-flex; align-items: center; gap: 0.5rem; }
.period-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.period-form select { width: auto; min-width: 140px; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.period-form input[type="date"] { padding: 0.35rem 0.5rem; font-size: 0.85rem; border: 1px solid #dcdde1; border-radius: 4px; }

/* === Cards === */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card { background: #fff; border-radius: 8px; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 1rem; }
.card h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.card h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.card-value { font-size: 2rem; font-weight: 700; color: #2c3e50; }
.card-label { color: #7f8c8d; font-size: 0.9rem; }
.card-income .card-value { color: #27ae60; }
.card-expense .card-value { color: #c0392b; }
.chart-card { padding: 1.25rem; }
.chart-card canvas { max-height: 350px; }

/* === Section Header === */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.section-header h2 { margin: 0; }

/* === Two Column Layout === */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* === Category Lists === */
.category-list { margin-top: 0.5rem; }
.category-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0; border-bottom: 1px solid #f5f6fa; }
.category-row a { flex: 1; min-width: 0; }
.category-row .count { color: #7f8c8d; font-size: 0.8rem; }
.category-row.indent { padding-left: 1rem; }
.sub-cat-sep { color: #bdc3c7; }

/* === Spending Groups === */
.spending-group { margin-bottom: 1rem; }
.spending-group-header { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 2px solid #ecf0f1; }
.spending-group-header .pct { color: #7f8c8d; font-size: 0.8rem; }

/* === Filter Card === */
.filter-card { margin-bottom: 1rem; padding: 0.75rem 1rem; }
.filter-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-form .form-group { margin: 0; }
.filter-form select, .filter-form input[type="text"] { width: auto; min-width: 140px; padding: 0.4rem 0.6rem; font-size: 0.85rem; }

/* === Summary Bar === */
.summary-bar { display: flex; gap: 1.5rem; align-items: center; padding: 0.5rem 0; margin-bottom: 1rem; font-size: 0.9rem; color: #7f8c8d; }

/* === Pagination === */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1rem 0; }
.page-info { color: #7f8c8d; font-size: 0.9rem; }

/* === Category Cards (CRUD page) === */
.form-card { margin-bottom: 1.5rem; }
.form-card h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.category-card { margin-bottom: 1rem; }
.category-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.category-info { display: flex; align-items: center; gap: 0.75rem; }
.category-info h3 { font-size: 1.1rem; margin: 0; }
.category-actions { display: flex; gap: 0.25rem; align-items: center; }
.sub-categories { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid #ecf0f1; }
.sub-list { list-style: none; margin-bottom: 0.5rem; }
.sub-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid #f5f6fa; }
.sub-name { flex: 1; min-width: 120px; }
.txn-count { font-size: 0.75rem; font-weight: 500; color: #7f8c8d; background: #f0f1f3; padding: 0.15rem 0.5rem; border-radius: 10px; margin-left: 0.35rem; vertical-align: middle; white-space: nowrap; align-self: center; }
.txn-count-zero { color: #e74c3c; background: #fde8e8; }
.sub-actions { display: flex; gap: 0.25rem; align-items: center; }
.add-sub-form { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.add-sub-form input[type="text"] { flex: 1; max-width: 250px; }
.edit-form { margin: 0.5rem 0; padding: 0.5rem; background: #f8f9fa; border-radius: 4px; }

/* === Badges === */
.badge { font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 3px; text-transform: uppercase; font-weight: 600; }
.badge-expense { background: #fdecea; color: #c0392b; }
.badge-income { background: #e8f8f5; color: #27ae60; }
.badge-both { background: #ebf5fb; color: #2980b9; }

/* === Tables === */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid #ecf0f1; }
th { background: #f8f9fa; font-weight: 600; font-size: 0.85rem; color: #7f8c8d; text-transform: uppercase; }
.nowrap { white-space: nowrap; }
.amount.income, .text-income { color: #27ae60; }
.amount.expense, .text-expense { color: #c0392b; }
.uncategorised { color: #bdc3c7; }

/* === Forms === */
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; }
input[type="text"], input[type="password"], select { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid #dcdde1; border-radius: 4px; font-size: 0.95rem; }
input[type="text"]:focus, input[type="password"]:focus, select:focus { outline: none; border-color: #3498db; box-shadow: 0 0 0 2px rgba(52,152,219,0.2); }
.inline-form { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; }
.inline-form input[type="text"], .inline-form select { width: auto; min-width: 180px; }

/* === Buttons === */
.btn { display: inline-block; padding: 0.5rem 1rem; border: 1px solid #dcdde1; border-radius: 4px; background: #fff; cursor: pointer; font-size: 0.9rem; color: #2c3e50; text-decoration: none; }
.btn:hover { background: #f5f6fa; text-decoration: none; }
.btn-primary { background: #3498db; color: #fff; border-color: #3498db; }
.btn-primary:hover { background: #2980b9; }
.btn-danger { background: #e74c3c; color: #fff; border-color: #e74c3c; }
.btn-danger:hover { background: #c0392b; }
.btn-block { width: 100%; text-align: center; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-xs { padding: 0.2rem 0.4rem; font-size: 0.75rem; }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.alert-error { background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb; }
.alert-success { background: #e8f8f5; color: #27ae60; border: 1px solid #a3d9c8; }

/* === Sub-Navigation === */
.sub-nav { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 2px solid #ecf0f1; }
.sub-nav a { padding: 0.5rem 1rem; color: #7f8c8d; text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.sub-nav a:hover { color: #2c3e50; text-decoration: none; }
.sub-nav a.active { color: #2c3e50; border-bottom-color: #3498db; font-weight: 600; }

/* === Merchant Group (Assign Page) === */
.merchant-group { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.75rem; }
.merchant-info { flex: 1; min-width: 200px; }
.merchant-info h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.merchant-meta { color: #7f8c8d; font-size: 0.85rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.assign-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.assign-form select { min-width: 130px; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.assign-form input[type="text"] { padding: 0.35rem 0.5rem; font-size: 0.85rem; }

/* === Report Cards === */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.report-card { display: block; transition: box-shadow 0.2s, transform 0.2s; cursor: pointer; text-decoration: none; color: inherit; }
.report-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.15); transform: translateY(-2px); text-decoration: none; }
.report-card h2 { font-size: 1.1rem; color: #2c3e50; margin-bottom: 0.5rem; }
.report-description { color: #7f8c8d; font-size: 0.9rem; margin-bottom: 0.75rem; line-height: 1.4; }
.report-date { color: #bdc3c7; font-size: 0.8rem; }

/* === Empty State === */
.empty-state { text-align: center; padding: 2rem 1rem; color: #7f8c8d; }

/* === Login === */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 100%; max-width: 380px; }
.login-container h1 { text-align: center; margin-bottom: 1.5rem; color: #2c3e50; }

/* === Responsive === */
@media (max-width: 768px) {
    .main-nav { position: relative; z-index: 100; }
    .nav-toggle { display: block; }
    .nav-links { display: none; width: 100%; }
    .nav-links.open { display: block; position: absolute; top: 56px; left: 0; right: 0; background: #2c3e50; padding: 0 1rem 0.5rem; box-shadow: 0 4px 8px rgba(0,0,0,0.2); }
    .nav-links a { display: block; line-height: 2.5; padding: 0; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .two-col { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .category-header { flex-direction: column; align-items: flex-start; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form input[type="text"], .inline-form select { min-width: 0; width: 100%; }
    .filter-form { flex-direction: column; align-items: stretch; }
    .filter-form select, .filter-form input[type="text"] { width: 100%; min-width: 0; }
    .sub-list li { flex-direction: column; align-items: flex-start; }
    th, td { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
    .summary-bar { flex-wrap: wrap; gap: 0.75rem; }
    .merchant-group { flex-direction: column; align-items: stretch; }
    .assign-form { width: 100%; }
    .assign-form select, .assign-form input[type="text"] { min-width: 0; width: 100%; }
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr; }
    .card-value { font-size: 1.5rem; }
}
