/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.2s ease;
    --tab-bar-height: 60px;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100dvh;
}

/* Accessibility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    text-decoration: none;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 100;
    font-weight: 600;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* Container */
.container {
    height: calc(100dvh - var(--tab-bar-height) - env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@supports not (height: 100dvh) {
    .container {
        height: calc(100vh - var(--tab-bar-height) - env(safe-area-inset-bottom, 0px));
    }
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

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

/* Help and Theme Toggle Buttons */
.help-toggle,
.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    padding: 0;
}

.help-toggle:hover,
.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.help-toggle svg,
.theme-toggle svg {
    width: 1.125rem;
    height: 1.125rem;
}

.sun-icon { display: block; }
.moon-icon { display: none; }
body.dark-mode .sun-icon { display: none; }
body.dark-mode .moon-icon { display: block; }

body.light-mode .help-toggle,
body.light-mode .theme-toggle {
    color: #6366f1;
    background: rgba(255, 255, 255, 0.95);
}

/* Overflow Menu */
.overflow-menu {
    position: relative;
}

.overflow-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 150px;
    z-index: 100;
}

.overflow-option {
    display: block;
    width: 100%;
    padding: 0.625rem 1rem;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: var(--transition);
}

.overflow-option:hover {
    background: var(--bg-secondary);
}

.overflow-option:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.overflow-option:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ==================== Screen Container ==================== */
#main-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.screen-container {
    display: flex;
    width: 300%;
    height: 100%;
    will-change: transform;
    transition: transform 0.3s ease;
    touch-action: pan-y;
}

.screen {
    width: calc(100% / 3);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100%;
}

/* ==================== Screen 0: Categories ==================== */
/* ==================== Screen 0: Numpad Entry ==================== */
.screen-entry {
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    gap: 0.5rem;
    overflow: hidden;
}

.entry-category-select {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.entry-category-select select {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

.entry-category-select select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.category-select-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.category-select-row select {
    flex: 1;
}

.btn-add-category {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius-lg);
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--primary-color);
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

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

.btn-add-category-sm {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.25rem;
}

.entry-date-row {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    align-items: center;
}

/* Amount Display */
.entry-amount-display {
    text-align: center;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 2px solid var(--border-color);
    position: relative;
    flex-shrink: 0;
}

.entry-amount-display #amount-display {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.entry-amount-display .currency-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

.entry-amount-display #change-date-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
}

.date-picker-wrapper {
    position: relative;
    display: inline-block;
}

.date-input-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Description Input */
.entry-description {
    flex-shrink: 0;
}

.entry-description input {
    width: 100%;
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.entry-description input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.entry-description input::placeholder {
    color: var(--text-muted);
}

/* Numpad */
.entry-numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 0.375rem;
    flex: 1;
    min-height: 0;
}

.numpad-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: var(--transition);
    min-height: 0;
    touch-action: manipulation;
    font-family: inherit;
    user-select: none;
    -webkit-user-select: none;
}

.numpad-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-light);
}

.numpad-btn:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.numpad-btn-backspace {
    color: var(--text-secondary);
}

.numpad-btn-backspace svg {
    width: 1.5rem;
    height: 1.5rem;
}

.numpad-btn-save {
    grid-column: 1 / -1;
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    font-size: 1.125rem;
    min-height: 0;
}

.numpad-btn-save:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.numpad-btn-save:active {
    transform: scale(0.98);
}

/* ==================== Screen 2: Expense List ==================== */
.screen-list {
    gap: 0;
}

/* Summary Bar */
.list-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.summary-item {
    text-align: center;
}

.summary-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.summary-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.summary-count {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Filter Bar */
.list-filters {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.filter-panel {
    padding-top: 0.5rem;
}

.filter-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--danger-color);
    border-radius: 50%;
    margin-left: 0.25rem;
}

.filter-group select,
.filter-group input {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-width: 120px;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-clear-filters {
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: pointer;
}

.btn-clear-filters:hover {
    color: var(--danger-color);
}

.filter-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Expense List */
.expense-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    text-align: center;
}

.empty-icon {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.empty-state small {
    font-size: 0.8125rem;
}

.expense-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.expense-item:hover {
    background: var(--bg-secondary);
}

/* Month Section Headers */
.month-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    position: sticky;
    top: 0;
    z-index: 1;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.month-header:hover {
    background: var(--bg-secondary);
}

.month-header-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.month-header-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
}

.month-header-summary {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.month-header-chevron {
    color: var(--text-muted);
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.month-header-chevron.expanded {
    transform: rotate(90deg);
}

.expense-date {
    flex-shrink: 0;
    width: 50px;
    text-align: center;
}

.expense-date .day {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.expense-date .month {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.expense-details {
    flex: 1;
    min-width: 0;
}

.expense-description {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.expense-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
}

.expense-meta .category-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 500;
}

.expense-amount {
    flex-shrink: 0;
    text-align: right;
}

.expense-amount .amount {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.expense-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.expense-actions button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.expense-actions .edit-btn:hover {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.expense-actions .delete-btn:hover {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

/* ==================== Dot Nav Indicators ==================== */
.dot-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-bar-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.dot-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-color);
    border: none;
    cursor: pointer;
    padding: 0;
    transition: var(--transition);
    touch-action: manipulation;
}

.dot-indicator:hover {
    background: var(--text-muted);
}

.dot-indicator.active {
    background: var(--primary-color);
    transform: scale(1.3);
}

/* ==================== Buttons ==================== */
.btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

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

.btn-text svg {
    width: 14px;
    height: 14px;
}

/* ==================== Form Styles (Edit Modal) ==================== */
.expense-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

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

.input-group.flex-grow {
    flex: 1;
    min-width: 150px;
}

.input-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input,
.input-group select {
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

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

/* Amount Input Group */
.amount-group {
    position: relative;
    min-width: 120px;
}

.amount-group input {
    padding-right: 2.5rem;
}

.currency-symbol {
    position: absolute;
    right: 1rem;
    bottom: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    pointer-events: none;
}

/* ==================== Modals ==================== */
.help-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1002;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.help-modal.visible {
    display: flex;
}

.help-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    pointer-events: auto;
}

.help-modal-content {
    position: relative;
    z-index: 1;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    pointer-events: auto;
}

.edit-modal-content {
    max-width: 600px;
}


.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.help-modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.help-modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.help-modal-close:hover {
    color: var(--danger-color);
    background: var(--bg-tertiary);
}

.help-modal-body {
    padding: 1.5rem;
}

.help-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.help-section-title:not(:first-child) {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.help-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.help-text p {
    margin: 0 0 0.5rem;
}

.help-text p:last-child {
    margin-bottom: 0;
}

.help-privacy-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.help-section {
    margin-bottom: 1.5rem;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h4 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
}

.shortcut-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

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

.shortcut-item dt {
    font-weight: 500;
}

.shortcut-item dd {
    color: var(--text-secondary);
    margin: 0;
}

kbd {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    font-family: monospace;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* ==================== Manage Categories Modal ==================== */
.manage-categories-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.manage-category-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.manage-category-label {
    flex: 1;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.manage-category-badge {
    font-size: 0.6875rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
}

.manage-category-actions {
    display: flex;
    gap: 0.25rem;
}

.manage-category-actions button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.375rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.manage-category-actions .rename-btn:hover {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.manage-category-actions .delete-category-btn:hover {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

/* ==================== Toast Notifications ==================== */
.toast-container {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top, 0px));
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--primary-color);
    color: white;
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-width: 200px;
    animation: slideInRight 0.3s ease;
    pointer-events: auto;
}

.toast-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.8;
}

.toast-close:hover { opacity: 1; }
.toast-success { background: #10b981; }
.toast-error { background: #ef4444; }
.toast-warning { background: #f59e0b; }
.toast-info { background: #3b82f6; }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

.toast.hiding {
    animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

/* ==================== Screen 3: Budget ==================== */
.screen-budget {
    padding: 1rem;
    gap: 1rem;
}

.budget-how-it-works {
    margin-bottom: 0.25rem;
}

.budget-how-it-works summary {
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.budget-how-it-works-body {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 0.5rem 0;
}

.budget-how-it-works-body p {
    margin: 0 0 0.375rem;
}

.budget-how-it-works-body p:last-child {
    margin-bottom: 0;
}

.budget-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.budget-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.budget-field > label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.budget-input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.budget-input-group input {
    flex: 1;
    padding: 0.625rem 2.25rem 0.625rem 0.75rem;
    font-size: 0.9375rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.budget-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.budget-input-group .currency-symbol {
    position: absolute;
    right: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    pointer-events: none;
}

.budget-collapsible {
    margin-bottom: 0.75rem;
}

.budget-collapsible summary {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem 0;
    user-select: none;
}

.budget-collapsible summary::-webkit-details-marker {
    color: var(--text-muted);
}

.budget-collapsible-sum {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 0.25rem;
}

.budget-expenses-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.budget-empty-state {
    font-size: 0.8125rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
}

.budget-expense-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.budget-expense-item .budget-expense-desc {
    flex: 1;
    color: var(--text-primary);
}

.budget-expense-item .budget-expense-amt {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.budget-expense-item .remove-budget-expense {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 1.125rem;
    line-height: 1;
}

.budget-expense-item .remove-budget-expense:hover {
    color: var(--danger-color);
}

.add-budget-expense-form {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    margin-top: 0.75rem;
}

.add-budget-expense-form input[type="text"] {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.add-budget-expense-form .budget-input-group {
    min-width: 100px;
}

.add-budget-expense-form .budget-input-group input {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    border-width: 1px;
}

.budget-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-top: 2px dashed var(--border-color);
    border-bottom: 2px dashed var(--border-color);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.budget-expected-value {
    font-size: 1.125rem;
    color: var(--secondary-color);
}

.budget-expected-value.negative {
    color: var(--danger-color);
}

.budget-progress-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.budget-dual-bar {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.budget-bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.budget-bar-row:first-child {
    margin-bottom: 0.75rem;
}

.budget-bar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    width: 3rem;
    flex-shrink: 0;
}

.budget-bar-value {
    font-size: 0.6875rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 0;
}

.budget-progress-bar {
    height: 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    overflow: hidden;
    flex: 1;
    position: relative;
}

.budget-month-bar {
    overflow: visible;
}

.budget-month-ticks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.budget-month-tick {
    position: absolute;
    top: -1px;
    width: 1px;
    height: 14px;
    background: var(--text-muted);
    opacity: 0.4;
}

.budget-month-tick-label {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.5625rem;
    color: var(--text-muted);
    white-space: nowrap;
    opacity: 1;
}

.budget-progress-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.4s ease, background-color 0.3s ease;
}

.budget-progress-fill.status-month { background-color: var(--text-muted); }
.budget-progress-fill.status-green { background-color: var(--secondary-color); }
.budget-progress-fill.status-yellow { background-color: var(--warning-color); }
.budget-progress-fill.status-red { background-color: var(--danger-color); }

.budget-progress-status {
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: center;
}

.budget-progress-status.status-green { color: var(--secondary-color); }
.budget-progress-status.status-yellow { color: var(--warning-color); }
.budget-progress-status.status-red { color: var(--danger-color); }

.budget-stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    justify-content: center;
}

.budget-stats-row .positive { color: var(--secondary-color); }
.budget-stats-row .negative { color: var(--danger-color, #e53e3e); }

.budget-no-income-msg {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem 0;
}

.budget-label-hint {
    font-weight: 400;
    text-transform: none;
    color: var(--text-muted);
}

/* Weekly Breakdown */
.budget-weekly-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.budget-week-card {
    padding: 0.625rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.budget-week-card.past {
    opacity: 0.6;
}

.budget-week-card.current {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
}

.budget-week-card.future {
    opacity: 0.45;
}

.budget-week-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.budget-week-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.budget-week-dates {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}

.budget-week-total {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.budget-week-details {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.budget-week-balance {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    text-align: right;
}

.budget-week-balance.negative {
    color: var(--danger-color, #e53e3e);
}

.budget-collapsible-remaining {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.budget-collapsible-remaining.negative {
    color: var(--danger-color, #e53e3e);
}

.budget-disposable-income {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.375rem 0;
}

.budget-disposable-value {
    font-weight: 700;
    color: var(--text-primary);
}

.budget-disposable-value.negative {
    color: var(--danger-color, #e53e3e);
}

.budget-current-week-label {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--text-muted);
}

.budget-end-of-month-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0 0.75rem 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.budget-end-of-month-value {
    color: var(--text-secondary);
}

/* Storage indicator */
.storage-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: help;
    margin: 0.5rem 1rem;
}

.storage-indicator svg { flex-shrink: 0; }
.storage-indicator:hover { background: var(--bg-secondary); }
.storage-indicator.warning { color: #b45309; background: rgba(251, 191, 36, 0.15); }
.storage-indicator.danger { color: #dc2626; background: rgba(248, 113, 113, 0.15); }

/* ==================== Dark Mode ==================== */
body.dark-mode {
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --border-color: #374151;
    background: #111827;
}

@media (prefers-color-scheme: dark) {
    body:not(.dark-mode):not(.light-mode) {
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --text-muted: #9ca3af;
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --bg-tertiary: #374151;
        --border-color: #374151;
        background: #111827;
    }
}

/* ==================== Focus Styles ==================== */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ==================== Reduced Motion ==================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== Responsive ==================== */
@media (max-width: 640px) {
    .toast-container {
        top: calc(10px + env(safe-area-inset-top, 0px));
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
    }

    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select,
    .filter-group input {
        width: 100%;
    }

    .add-budget-expense-form {
        flex-direction: column;
    }

    .add-budget-expense-form .budget-input-group {
        min-width: 100%;
    }
}

/* Desktop: centered single-screen layout */
@media (min-width: 768px) {
    body {
        overflow: hidden;
    }

    .container {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg-primary);
    }

    .entry-numpad {
        min-height: 280px;
    }
}
