:root {
    /* Brand Colors - strictly from brandGuidelines.md */
    --jm-dark-blue: #2E3A8C;
    --jm-light-blue: #4A5FD9;
    --jm-navy: #1A2254;
    
    /* Neutral Colors */
    --white: #FFFFFF;
    --light-gray: #F5F7FA;
    --dark-gray: #4A4A4A;
    --black: #1A1A1A;
    --border-color: #E0E0E0;

    /* Extended Colors */
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg-page: var(--light-gray);
    --bg-card: var(--white);
    --text-primary: var(--black);
    --text-secondary: var(--dark-gray);
    
    /* Styling variables */
    --radius-card: 12px;
    --radius-btn: 8px;
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);
    --sidebar-width: 250px;
    --transition-speed: 0.2s;
}

/* Dark Mode Support (optional bonus to matching guidelines layout) */
body.dark-mode {
    --bg-page: #121836;
    --bg-card: var(--jm-navy);
    --text-primary: var(--white);
    --text-secondary: #A0ABC0;
    --border-color: #2D3748;
    --shadow-card: 0 4px 12px rgba(0,0,0,0.5);
}

/* Base Styles & Typography */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    font-weight: 400;
}

h1 { font-size: 2rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 700; line-height: 1.2; margin-bottom: 0.5rem; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.2; margin-bottom: 0.5rem; }
p, .body-text { font-size: 1rem; }
.small-text { font-size: 0.875rem; }
.caption-text { font-size: 0.75rem; font-weight: 300; }
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; }

/* UI Elements */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: all var(--transition-speed);
    border: none;
    gap: 0.5rem;
}
.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}
.btn-primary {
    background-color: var(--jm-dark-blue);
    color: var(--white);
}
.btn-primary:hover {
    background-color: var(--jm-light-blue);
}
.btn-secondary {
    background-color: transparent;
    color: var(--jm-dark-blue);
    border: 2px solid var(--jm-dark-blue);
}
.btn-secondary:hover {
    background-color: rgba(74, 95, 217, 0.1);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 50%;
    transition: all 0.2s;
}
.icon-btn:hover {
    color: var(--jm-dark-blue);
    background-color: rgba(46, 58, 140, 0.1);
}
.icon {
    width: 24px;
    height: 24px;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Inputs */
.input-field {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
    background-color: transparent;
    transition: border-color var(--transition-speed);
}
.input-field:focus {
    outline: none;
    border-color: var(--jm-dark-blue);
}
.select-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    width: auto;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--jm-navy); /* Dark background for sidebar */
    color: var(--white);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}
.sidebar .brand {
    padding: 0 1.5rem 2rem;
    text-align: center;
}
.sidebar .logo {
    color: var(--white);
    font-size: 1.5rem;
    letter-spacing: 1px;
}
.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: all var(--transition-speed);
    text-align: left;
    width: 100%;
}
.nav-item:hover {
    background-color: rgba(255,255,255,0.1);
    color: var(--white);
}
.nav-item.active {
    background-color: var(--jm-dark-blue);
    color: var(--white);
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* Top Header */
.top-header {
    background-color: var(--bg-card);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* very subtle shadow */
}
.search-bar {
    display: flex;
    align-items: center;
    width: 300px;
    position: relative;
}
.search-bar .icon {
    position: absolute;
    left: 10px;
    color: var(--text-secondary);
    width: 20px;
    height: 20px;
}
.header-search {
    padding-left: 2.5rem;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border-color);
}
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--jm-light-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}
.user-name {
    font-weight: 600;
}

/* Page Views Container */
.pages-container {
    padding: 2rem;
    flex: 1;
}
.page-view {
    display: none;
}
.page-view.active {
    display: block;
}

/* Dashboard Specifics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    gap: 0.5rem;
}
.metric-title {
    color: var(--text-secondary);
    font-weight: 600;
}
.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}
.metric-change {
    font-size: 0.875rem;
    font-weight: 600;
}
.metric-change.positive { color: var(--success); }
.metric-change.negative { color: var(--danger); }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto;
    gap: 1.5rem;
}
.span-2 {
    grid-column: span 2;
}
.chart-container {
    height: 300px;
    position: relative;
    width: 100%;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th, .data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
}
.align-right { text-align: right !important; }

/* Progress bars */
.progress-bar {
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.progress-fill {
    height: 100%;
    background-color: var(--jm-light-blue);
    transition: width 0.3s;
}
.limit-status {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

/* Categories View Settings (Phase 3) */
.category-group {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
}
.group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: 1.1rem;
}
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 1.5rem 1rem;
}
.category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    cursor: pointer;
}
.cat-icon-wrapper {
    position: relative;
    margin-bottom: 0.5rem;
}
.cat-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background-color: var(--light-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s;
}
.category-item:hover .cat-icon {
    transform: scale(1.05);
}
.cat-edit-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--white);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
}
.cat-name {
    font-size: 0.75rem;
    line-height: 1.2;
    font-weight: 500;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Quick Add Transaction Modal */
.type-radio-btn .type-label {
    display: inline-block;
    padding: 8px 24px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.type-radio-btn:has(input[value="expense"]:checked) .type-label {
    background: var(--danger);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}
.type-radio-btn:has(input[value="income"]:checked) .type-label {
    background: var(--success);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
#txnAmount:focus {
    border-bottom-color: var(--jm-dark-blue) !important;
}

/* Horizontal Scroll Hide Scrollbar */
#txnCategoryVisual::-webkit-scrollbar {
    display: none;
}

.visual-cat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    min-width: 65px;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
}
.visual-cat-item:hover {
    opacity: 0.8;
}
.visual-cat-item.selected {
    opacity: 1;
    transform: scale(1.1);
}
.visual-cat-item.selected .cat-icon {
    border: 2px solid var(--jm-dark-blue);
    background: rgba(46, 58, 140, 0.1);
}
.visual-cat-item .cat-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background-color: var(--light-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.2s;
    border: 2px solid transparent;
}

/* Quick Action Grid in Dashboard */
.quick-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* =========================================
   Responsive Mobile & Tablet Layout
   ========================================= */

@media (max-width: 1024px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .span-2 {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    /* Convert left sidebar into bottom navigation tab bar */
    .sidebar {
        width: 100%;
        height: 65px;
        position: fixed;
        bottom: 0;
        left: 0;
        top: auto;
        flex-direction: row;
        padding: 0;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
    }
    
    .sidebar .brand {
        display: none;
    }
    
    .nav-menu {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        height: 100%;
        padding: 0;
    }
    
    .nav-item {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 5px;
        gap: 2px;
        font-size: 0.65rem;
        border-radius: 0;
        flex: 1;
        height: 100%;
        text-align: center;
    }
    
    .nav-item.active {
        background-color: var(--jm-light-blue);
    }
    
    .main-content {
        margin-left: 0;
        padding-bottom: 80px; /* Space for the bottom nav bar */
    }
    
    .top-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: 1rem;
    }
    
    .search-bar {
        width: 100%;
        order: 3; /* Move search bar to next line on mobile */
        margin-top: 0.5rem;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .user-profile {
        margin-left: auto;
    }
    
    .pages-container {
        padding: 1rem;
    }
    
    /* Fix table overflow on mobile */
    .table-card {
        width: 100%;
        overflow-x: auto;
    }
    .data-table {
        min-width: 600px; /* Force scroll */
    }
    
    /* Center auth cards on mobile */
    .auth-container {
        padding: 1rem;
    }
    .auth-card {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .nav-item {
        font-size: 0; /* Hide text, just show icons on very tiny screens */
    }
    
    .nav-item .icon {
        margin-bottom: 0;
        height: 28px;
    }
}

/* Custom Toggle Switch for Biến động */
.toggle-switch input:checked + .slider {
    background-color: var(--success);
}
.toggle-switch input:focus + .slider {
    box-shadow: 0 0 1px var(--success);
}
.toggle-switch input:checked + .slider span {
    transform: translateX(20px);
}

/* Modal slide up animation */
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

#utilitiesModal .card, #txnModal .card {
    animation: slideUp 0.3s cubic-bezier(0.1, 0.9, 0.2, 1);
}

/* Hide desktop navbar if needed or refine Utilities spacing */
.quick-action-btn:active {
    background-color: rgba(0,0,0,0.05);
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .main-content {
        padding-bottom: 80px;
    }
    #utilitiesModal .card, #txnModal .card {
        height: auto !important;
        max-height: 90vh !important;
        border-radius: 24px 24px 0 0 !important;
    }
}
