:root {
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --income: #06d6a0;
    --expense: #ef476f;
    --background: #f8f9fa;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.05);
    --shadow-hover: rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --radius: 12px;
    --radius-sm: 8px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
    --primary: #5e72e4;
    --primary-dark: #4d5fd0;
    --income: #05c091;
    --expense: #e5366a;
    --background: #121826;
    --card-bg: #1a243a;
    --text: #e2e8f0;
    --text-light: #94a3b8;
    --border: #2d3748;
    --shadow: rgba(0, 0, 0, 0.2);
    --shadow-hover: rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: var(--transition);
}

body {
    font-family: var(--font-family);
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    padding: 0;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    background-color: var(--card-bg);
    box-shadow: 0 4px 20px var(--shadow);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: 20px;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.logo i {
    color: var(--primary);
    font-size: 24px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-shrink: 0;
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.theme-toggle {
    background: var(--card-bg);
    border: 1px solid var(--border);
    cursor: pointer;
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px var(--shadow);
    transition: var(--transition);
    flex-shrink: 0;
    margin-left: 10px;
}

.theme-toggle:hover {
    transform: rotate(15deg);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

main {
    padding: 20px 0;
    flex: 1;
}

.dashboard {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

@media (min-width: 768px) {
    .dashboard {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 4px 20px var(--shadow);
    transition: var(--transition);
    border: 1px solid var(--border);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px var(--shadow-hover);
}

.card-title {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.balance .card-value {
    color: var(--primary);
}

.income .card-value {
    color: var(--income);
}

.expenses .card-value {
    color: var(--expense);
}

.chart-container {
    height: 340px;
    margin-bottom: 30px;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 4px 20px var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
    text-align: center;
}

.chart-inner {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 280px;
}

.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: var(--radius);
}

[data-theme="dark"] .chart-loading {
    background-color: rgba(26, 36, 58, 0.8);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.form-section {
    margin-bottom: 30px;
}

.section-title {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--text);
    font-weight: 600;
    letter-spacing: -0.5px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (min-width: 640px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .form-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.form-group {
    margin-bottom: 12px;
    position: relative;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-light);
    font-size: 13px;
    font-weight: 500;
}

input, select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: var(--card-bg);
    color: var(--text);
    font-size: 15px;
    font-family: var(--font-family);
    transition: var(--transition);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.help-text {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

button {
    cursor: pointer;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    font-family: var(--font-family);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
}

.btn-secondary {
    background-color: var(--text-light);
    color: white;
    box-shadow: 0 4px 10px rgba(100, 116, 139, 0.3);
}

.btn-secondary:hover, .btn-secondary:focus {
    background-color: #475569;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(100, 116, 139, 0.4);
}

.btn-danger {
    background-color: var(--expense);
    color: white;
    box-shadow: 0 4px 10px rgba(239, 71, 111, 0.3);
}

.btn-danger:hover, .btn-danger:focus {
    background-color: #dc2656;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(239, 71, 111, 0.4);
}

.btn-edit {
    background-color: #ff9e16;
    color: white;
    box-shadow: 0 4px 10px rgba(255, 158, 22, 0.3);
}

.btn-edit:hover, .btn-edit:focus {
    background-color: #eb8c0b;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(255, 158, 22, 0.4);
}

.transactions {
    margin-top: 30px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    background-color: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px var(--shadow);
    border: 1px solid var(--border);
    align-items: flex-end;
}

.filters .form-group {
    flex: 1;
    min-width: 160px;
    margin-bottom: 0;
}

.filter-button-container {
    display: flex;
    align-items: flex-end;
}

.table-container {
    overflow-x: auto;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 30px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

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

th {
    background-color: var(--card-bg);
    color: var(--text-light);
    font-weight: 600;
    position: sticky;
    top: 0;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: var(--shadow);
}

.action-buttons {
    display: flex;
    gap: 6px;
}

.action-btn {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    padding: 50px 16px;
    color: var(--text-light);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--border);
    opacity: 0.7;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .header-content {
        flex-wrap: nowrap;
    }
    
    .logo h1 {
        font-size: 18px;
    }
    
    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .filters {
        flex-direction: column;
    }
    
    th, td {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .action-buttons {
        flex-direction: column;
    }

    .card-value {
        font-size: 20px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    button {
        padding: 10px 16px;
        font-size: 14px;
        width: 100%;
    }
    
    .filters .form-group {
        min-width: 100%;
    }
    
    .chart-container {
        height: 280px;
        padding: 12px;
    }
    
    .chart-title {
        font-size: 14px;
    }
    
    .section-title {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 16px;
    }
    
    .card {
        padding: 16px;
    }
    
    .card-value {
        font-size: 18px;
    }
    
    .chart-container {
        height: 260px;
    }
    
    .action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

.category-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    background-color: var(--primary);
    color: white;
}

.amount.income {
    color: var(--income);
    font-weight: 600;
}

.amount.expense {
    color: var(--expense);
    font-weight: 600;
}

/* Modern scrollbar for webkit browsers */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

.reset-filters-container {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--card-bg);
    color: var(--text);
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-left: 4px solid var(--income);
}

.toast.error {
    border-left: 4px solid var(--expense);
}

.toast.info {
    border-left: 4px solid var(--primary);
}


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

button:focus, input:focus, select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Validation styles */
input:invalid, select:invalid {
    border-color: var(--text-light);
}

input:valid, select:valid {
    border-color: var(--text-light);
}

.error-message {
    color: var(--expense);
    font-size: 12px;
    margin-top: 4px;
    display: none;
}

input:invalid + .error-message {
    display: block;
}