:root {
    /* Premium Dark Mode Colors */
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    
    --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.3), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
    
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 2rem 0;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    padding: 0 2rem;
    margin-bottom: 3rem;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
    border-radius: 8px;
}

.logo h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

nav ul {
    list-style: none;
    padding: 0 1rem;
}

nav li {
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
}

nav li:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

nav li.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent-primary);
    border-left: 3px solid var(--accent-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.05), transparent 400px), var(--bg-main);
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.header-titles h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

select {
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.625rem 1rem;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em;
    padding-right: 2.5rem;
}

select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Cards & Containers */
.card {
    background-color: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-light);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.budget-icon {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
}

.used-icon {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--color-warning);
}

.remaining-icon {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--color-success);
}

.stat-info h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-info .amount {
    font-size: 1.75rem;
    font-weight: 700;
}

.amount.warning { color: var(--color-warning); }
.amount.success { color: var(--color-success); }
.amount.danger { color: var(--color-danger); }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.main-panel {
    padding: 1.5rem;
}

.side-panel {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.panel-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.side-panel h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

/* Forms */
.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 140px;
}

.form-group.flex-2 {
    flex: 2;
    min-width: 200px;
}

.form-group.btn-group {
    flex: 0;
    min-width: 100px;
}

label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input {
    background-color: rgba(15, 23, 42, 0.5);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition);
}

input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    background-color: rgba(15, 23, 42, 0.8);
}

/* Buttons */
button {
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--border-light);
}

.btn-icon {
    background: none;
    color: var(--text-secondary);
    padding: 0.25rem;
    border-radius: 4px;
}

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

/* Table */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

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

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.category-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.cat-maas { background-color: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.cat-satinalma { background-color: rgba(16, 185, 129, 0.15); color: #34d399; }
.cat-muhtelif { background-color: rgba(245, 158, 11, 0.15); color: #fbbf24; }

/* Chart */
.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1rem;
}

.chart-legend {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.legend-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-value {
    font-weight: 600;
}

/* Utilities */
.empty-row td {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Excel Like Tables */
#expenseTable td:first-child {
    width: 15%;
}
#expenseTable td:nth-child(2),
#expenseTable td:nth-child(3),
#expenseTable td:nth-child(4),
#expenseTable td:nth-child(5),
#expenseTable td:nth-child(6) {
    width: 17%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background-color: rgba(15, 23, 42, 0.4);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.data-table th, .data-table td {
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.data-table th {
    font-weight: 600;
}

.data-table tr:hover td {
    background-color: rgba(255, 255, 255, 0.05);
}

.font-bold {
    font-weight: 700;
    color: var(--text-primary);
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(10px);
}

.login-card {
    background-color: var(--bg-card);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.login-card .logo {
    justify-content: center;
    margin-bottom: 2rem;
    padding: 0;
}

.login-card .logo h2 {
    font-size: 1.5rem;
}

/* ==========================================================================
   Mobile Responsiveness (Media Queries)
   ========================================================================== */

/* Tablet & Smaller Laptops */
@media screen and (max-width: 1024px) {
    .summary-cards {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr; /* Stack panels vertically */
    }
    
    .main-content {
        padding: 1.5rem;
    }
}

/* Mobile & Small Tablets */
@media screen and (max-width: 768px) {
    body {
        overflow-y: auto; /* Allow scrolling on body */
    }
    
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    /* Make sidebar a horizontal top bar */
    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 50;
        background-color: rgba(30, 41, 59, 0.95);
        backdrop-filter: blur(10px);
    }
    
    .logo {
        margin-bottom: 0;
        padding: 0;
    }
    
    nav ul {
        display: flex;
        gap: 0.5rem;
        margin: 0;
        padding: 0;
    }
    
    nav li {
        margin-bottom: 0;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .main-content {
        padding: 1rem;
        height: auto;
        overflow-y: visible;
    }
    
    header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .form-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-group.btn-group {
        align-items: stretch;
    }
    
    .summary-cards {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 1rem;
    }

    /* Force grids to be single column on mobile to prevent overflow */
    .dashboard-grid[style] {
        grid-template-columns: 1fr !important;
    }

    /* Allow card heights to adjust naturally on mobile */
    .card.main-panel[style] {
        height: auto !important;
        min-height: 400px;
    }
    
    /* Charts container needs explicit height when card is auto */
    .chart-container {
        height: 300px !important;
        width: 100% !important;
    }
    
    /* Login Screen Mobile */
    .login-card {
        padding: 1.5rem;
        margin: 1rem;
    }
}

/* Very Small Screens */
@media screen and (max-width: 480px) {
    .sidebar {
        flex-direction: column;
        gap: 1rem;
    }
    
    nav ul {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    select {
        width: 100%;
    }
    
    /* Ensure tables can scroll horizontally without breaking layout */
    .table-container, 
    [style*="overflow-x: auto"] {
        -webkit-overflow-scrolling: touch;
    }
}
