/* --- Modern Design System Variables --- */
:root {
    /* Indigo Color Palette */
    --primary-color: #4f46e5;
    --primary-hover-color: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.1);
    
    /* Slate Color Palette for UI (High Contrast Light Mode) */
    --bg-main: #e2e8f0; /* Slate 200 */
    --bg-card: #ffffff; /* White */
    --bg-hover: #f1f5f9; /* Slate 100 */
    --text-primary: #020617; /* Slate 950 */
    --text-secondary: #334155; /* Slate 700 */
    --text-muted: #64748b; /* Slate 500 */
    --border-color: #cbd5e1; /* Slate 300 */
    
    /* Semantic Colors */
    --success-color: #059669; /* Emerald 600 */
    --success-bg: #d1fae5; /* Emerald 100 */
    --danger-color: #dc2626; /* Red 600 */
    --danger-bg: #fee2e2; /* Red 100 */
    --warning-color: #d97706; /* Amber 600 */
    --warning-bg: #fef3c7; /* Amber 100 */
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Shadows & Effects */
    --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);
    --border-radius-sm: 6px;
    --border-radius-md: 10px;
    --border-radius-lg: 16px;
    
    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-blur: 12px;
}

/* --- Base Resets --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    padding: 2rem 1rem;
}

/* --- Layout Containers --- */
.container {
    max-width: 98%;
    margin: 0 auto;
    background: var(--bg-card);
    padding: 1.5rem 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

/* Specific styling for login to center it beautifully */
#login-container {
    max-width: 400px;
    margin: 10vh auto;
    text-align: center;
}

/* --- Typography --- */
h1, h2, h3, h4 {
    color: var(--text-primary);
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: -0.025em;
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

/* Header with buttons next to title */
h1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}
h1 span {
    display: flex;
    gap: 0.5rem;
}

/* --- Forms & Inputs --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
input, select {
    padding: 0.75rem 1rem;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background-color: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.95rem;
    transition: all 0.2s ease;
    outline: none;
}
input:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* --- Buttons --- */
button {
    padding: 0.6rem 1.2rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
}
button:hover {
    background-color: var(--primary-hover-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
button:active {
    transform: translateY(0);
}

/* Specific Button Colors */
.btn-group { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1rem; }
button[onclick="register()"] { background-color: var(--text-secondary); }
button[onclick="register()"]:hover { background-color: var(--text-primary); }
button[onclick="logout()"] { background-color: var(--danger-color); }
button[onclick="logout()"]:hover { background-color: #dc2626; }
button[onclick="openAuditView()"] { background-color: var(--text-secondary); }
button[onclick="openAuditView()"]:hover { background-color: var(--text-primary); }

/* Small buttons */
button[style*="font-size: 12px"] {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem !important;
    border-radius: var(--border-radius-sm);
}

/* Transparent small icon buttons */
button.icon-btn {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    box-shadow: none;
}
button.icon-btn:hover { background: var(--bg-hover); color: var(--primary-color); transform: none; box-shadow: none;}

/* --- Tables --- */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    margin-bottom: 2rem;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8rem;
}
th, td {
    padding: 0.2rem 0.4rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
th:first-child, td:first-child { 
    text-align: left; 
    white-space: normal;
    min-width: 120px;
}
th {
    background-color: var(--bg-hover);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Clickable Headers (like Months) */
.clickable-header {
    cursor: pointer;
    color: var(--primary-color);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    transition: all 0.2s ease;
}
.clickable-header:hover {
    color: var(--primary-hover-color);
    background-color: var(--primary-light) !important;
    text-decoration-style: solid;
}

tbody tr {
    transition: background-color 0.15s ease;
}
tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

/* Remove last border for cleanliness */
tbody tr:last-child td { border-bottom: none; }

/* Table Columns Highlighting - Redesigned to be subtle */
#budget-table td:nth-child(1) { font-weight: 600; color: var(--text-primary); } /* Category */
#budget-table td:nth-child(2) { background-color: rgba(56, 189, 248, 0.05); } /* Accum Budget */
#budget-table td:nth-child(3) { background-color: rgba(16, 185, 129, 0.05); } /* Budget */

/* Monthly Columns Backgrounds (Jan-Dec) - Alternating slightly */
#budget-table td:nth-child(n+5):nth-child(-n+16):nth-child(odd) { background-color: rgba(241, 245, 249, 0.5); }

/* Total Row Styling */
tfoot {
    background-color: var(--bg-hover);
    font-weight: 700;
}
tfoot td {
    border-top: 2px solid var(--border-color);
    color: var(--text-primary);
}
tfoot tr:last-child td {
    border-bottom: none;
    border-top: 2px solid var(--text-secondary);
}

/* Month Table specific */
#month-table th { cursor: pointer; }
#month-table th:hover { color: var(--primary-color); }
#month-table select {
    padding: 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    background-color: transparent;
    width: 100%;
}
#month-table select:hover { border-color: var(--border-color); background-color: var(--bg-card); }
#month-table select:focus { border-color: var(--primary-color); }
#month-table input[type="checkbox"] { width: 1.2rem; height: 1.2rem; accent-color: var(--primary-color); cursor: pointer; }

/* In-table Inputs */
table input[type="number"], table input[type="text"] {
    padding: 0.3rem 0.5rem;
    border: 1px solid transparent;
    background: transparent;
    text-align: inherit;
    width: 100%;
    font-size: inherit;
}
table input[type="number"]:hover, table input[type="text"]:hover {
    border-color: var(--border-color);
    background: var(--bg-card);
}
table input[type="number"]:focus, table input[type="text"]:focus {
    border-color: var(--primary-color);
    background: var(--bg-card);
}

/* --- Modals (Glassmorphism) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 2.5rem;
    width: 90%;
    max-width: 450px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    position: relative;
    margin: auto;
    /* Animation */
    animation: modalFadeIn 0.3s ease-out;
}
@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    color: var(--text-muted);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}
.close:hover { color: var(--danger-color); }

.modal-content h2 { margin-bottom: 1.5rem; }
.modal-content input, .modal-content select { margin-bottom: 1rem; }
.modal-content button { width: 100%; margin-top: 0.5rem; }

/* --- Context Menus --- */
#context-menu, #transaction-context-menu {
    display: none;
    position: absolute;
    background-color: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    z-index: 1100;
    min-width: 160px;
    border-radius: var(--border-radius-md);
    overflow: hidden;
}
#context-menu ul, #transaction-context-menu ul { list-style: none; margin: 0; padding: 0.25rem 0; }
#context-menu li, #transaction-context-menu li {
    padding: 0.6rem 1rem;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background-color 0.15s;
}
#context-menu li:hover, #transaction-context-menu li:hover {
    background-color: var(--primary-light);
    color: var(--primary-color);
}
/* Style delete options red */
#context-menu li:last-child, #transaction-context-menu li:last-child { color: var(--danger-color); }
#context-menu li:last-child:hover, #transaction-context-menu li:last-child:hover { background-color: var(--danger-bg); color: var(--danger-color); }

/* --- Sub-Budget Section Headers in Table --- */
/* The app.js generates a tr with background-color: #e9ecef for sub-budgets */
tbody tr[style*="background-color: #e9ecef"],
tbody tr[style*="background-color: rgb(233, 236, 239)"] {
    background-color: var(--bg-hover) !important;
}
tbody tr[style*="background-color: #e9ecef"] td,
tbody tr[style*="background-color: rgb(233, 236, 239)"] td {
    font-weight: 700;
    color: var(--primary-color);
    border-top: 1px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

/* --- Utilities --- */
.list-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container { padding: 1rem; border-radius: var(--border-radius-md); }
    h1 { font-size: 1.5rem; flex-direction: column; align-items: flex-start; gap: 1rem; }
    h1 span { width: 100%; justify-content: space-between; }
    .table-responsive { border-left: none; border-right: none; border-radius: 0; margin-left: -1rem; margin-right: -1rem; width: calc(100% + 2rem); }
}

/* --- Month Navigation Tabs --- */
.month-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.month-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    box-shadow: none;
}
.month-tab:hover {
    color: var(--primary-color);
    background: var(--bg-hover);
    transform: none;
}
.month-tab.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
    background: var(--primary-light);
}

/* --- Month Navigation Tabs --- */
.month-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.month-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    box-shadow: none;
}
.month-tab:hover {
    color: var(--primary-color);
    background: var(--bg-hover);
    transform: none;
}
.month-tab.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
    background: var(--primary-light);
}

/* --- Dashboard --- */
.dashboard-summary {
    display: flex;
    gap: 20px;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}
.dashboard-summary > div {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    flex: 1;
    min-width: 200px;
    text-align: center;
}
.dashboard-summary > div h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
}
.dashboard-summary > div p {
    font-size: 1.5rem;
    font-weight: 700;
}
.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.chart-container {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
.chart-wrapper {
    position: relative;
    height: 350px;
    width: 100%;
}
.chart-container h4 {
    text-align: center;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}
@media (max-width: 900px) {
    .dashboard-charts {
        grid-template-columns: 1fr;
    }
}
