/* Base Styles */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #06b6d4;
    --accent-color: #8b5cf6;
    --text-light: #f9fafb;
    --text-dark: #111827;
    --bg-light: #f9fafb;
    --bg-dark: #111827;
    --card-light: #ffffff;
    --card-dark: #1f2937;
    --input-light: #f3f4f6;
    --input-dark: #374151;
    --border-light: #e5e7eb;
    --border-dark: #4b5563;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --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.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --transition: all 0.3s ease;
}

/* Global Styles */
body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    transition: var(--transition);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

button, input, select {
    font-family: inherit;
    outline: none;
}

button {
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fadeIn {
    animation: fadeIn 0.5s ease forwards;
}

/* Light/Dark Mode */
html.light {
    color-scheme: light;
    background-color: var(--bg-light);
    color: var(--text-dark);
}

html.dark {
    color-scheme: dark;
    background-color: var(--bg-dark);
    color: var(--text-light);
}

html.dark .bg-white {
    background-color: var(--card-dark);
    color: var(--text-light);
}

html.dark .text-gray-900 {
    color: var(--text-light);
}

html.dark .text-gray-600 {
    color: #d1d1d1;
}

html.dark .text-gray-500 {
    color: #9ca3af;
}

html.dark .bg-gray-50 {
    background-color: var(--input-dark);
}

html.dark .border {
    border-color: var(--border-dark);
}

html.dark .input-field, html.dark .category-select {
    background-color: var(--input-dark);
    border-color: var(--border-dark);
    color: var(--text-light);
}

html.dark .category-select option {
    background-color: var(--card-dark);
    color: var(--text-light);
}

/* Components */
.card {
    background-color: var(--card-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
    border: 1px solid var(--border-light);
}

html.dark .card {
    background-color: var(--card-dark);
    border-color: var(--border-dark);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: var(--transition);
    border: none;
}

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

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

.input-field {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background-color: var(--input-light);
    transition: var(--transition);
    font-size: 1rem;
}

.input-field:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

html.dark .input-field {
    background-color: var(--input-dark);
    border-color: var(--border-dark);
}

/* Modal & Drawer */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    max-height: 100vh;
    will-change: transform;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 1050;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    background-color: var(--card-light);
    border-left: 1px solid var(--border-light);
    visibility: hidden;
    opacity: 0;
    box-sizing: border-box;
}

html.dark .drawer {
    background-color: var(--card-dark);
    border-left: 1px solid var(--border-dark);
}

.drawer.open {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
}

/* Overlay for drawer */
.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 1040;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.drawer-overlay.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* Actions */
.action-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    border: none;
    flex-shrink: 0;
    min-width: 40px;
}

.action-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background-color: var(--primary-hover);
}

/* Tooltip styles */
#editCategory {
    position: relative;
    flex: 0 0 auto;
}

#editCategory:hover::after {
    content: "Add Custom Category";
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background-color: var(--card-dark);
    color: var(--text-light);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.avatar {
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

html.dark .table-container {
    border-color: var(--border-dark);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    padding: 1rem;
    font-weight: 500;
    text-align: left;
    color: var(--text-dark);
    background-color: var(--input-light);
    border-bottom: 1px solid var(--border-light);
}

html.dark th {
    color: var(--text-light);
    background-color: var(--input-dark);
    border-bottom: 1px solid var(--border-dark);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
}

html.dark td {
    border-bottom: 1px solid var(--border-dark);
}

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

/* Charts */
canvas {
    border: none !important;
}

/* Fix for Tailwind Dark Mode */
.dark .dark\:bg-gray-800 {
    background-color: var(--card-dark) !important;
}

.dark .dark\:bg-gray-900 {
    background-color: var(--bg-dark) !important;
}

.dark .dark\:text-white {
    color: var(--text-light) !important;
}

.dark .dark\:text-gray-300 {
    color: #d1d1d1 !important;
}

.dark .dark\:text-gray-400 {
    color: #9ca3af !important;
}

/* Fix rounded corners for inputs and buttons */
.rounded-lg {
    border-radius: var(--radius-lg) !important;
}

.rounded-full {
    border-radius: 9999px !important;
}

/* Override Tailwind styles for better accessibility */
.text-indigo-500 {
    color: var(--primary-color) !important;
}

.bg-indigo-500 {
    background-color: var(--primary-color) !important;
}

.hover\:bg-indigo-600:hover {
    background-color: var(--primary-hover) !important;
}

/* Fix specific layout issues */
@media (max-width: 768px) {
    .drawer {
        width: 90vw;
        max-height: 85vh;
    }
    
    .card {
        padding: 1.25rem;
    }
    
    /* Fix for input groups with buttons */
    .input-group {
        display: flex;
        align-items: center;
    }
    
    .input-group .action-button {
        flex: 0 0 auto;
    }
    
    /* Prevent currency select from overflowing */
    .currency-select {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Ensure proper spacing for name input group */
    #nameInputContainer .flex {
        flex-wrap: nowrap;
    }
    
    /* Fix for buttons inside name input container */
    #nameInputContainer .action-button {
        flex: 0 0 auto;
    }
    
    .btn {
        width: auto;
        min-width: 120px;
        max-width: 100%;
    }
}

/* Z-index management for appropriate layering */
#menuBtn {
    z-index: 1100;
}

/* Ensure body is set to handle fixed position overlays properly */
html, body {
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

/* Fix for responsive button containers */
.button-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ensure all buttons maintain shape */
button {
    flex-shrink: 0;
}

/* Fix for category buttons */
#editCategory, #deleteCategory {
    position: relative;
    flex: 0 0 auto;
}

#editCategory:hover::after {
    content: "Add Custom Category";
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background-color: var(--card-dark);
    color: var(--text-light);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

/* Additional fixes for mobile layout */

/* Adjust button sizing for smallest screens */
@media (max-width: 360px) {
    .action-button {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Ensure form inputs have proper padding */
    .input-field {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* Fix for alignment in form groups */
.input-group {
    display: flex;
    align-items: center;
    width: 100%;
}

/* Ensure buttons maintain their shape */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    max-width: 100%;
}

/* Fix for button with icons */
.btn i {
    flex-shrink: 0;
}

/* Fix button container for proper centering */
.button-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

/* Fix for form buttons that should be full width */
.form-button-full {
    width: 100%;
}

/* Adjust menu button position for better visibility */
#menuBtn {
    transform: scale(1);
    transition: transform 0.2s ease;
}

#menuBtn:hover,
#menuBtn:active {
    transform: scale(1.1);
}
