.profile-btn {
    background: none;
    border: none;
    padding: 0.75rem; /* Increased from 0.5rem to make it bigger */
    border-radius: 12px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem; /* Added to make the icon bigger */
}
body.dark-mode .profile-btn {
    color: #cbd5e1;
}

.profile-btn:hover {
    background: #f8fafc;
    color: #1e293b;
    transform: translateY(-1px);
}

body.dark-mode .profile-btn:hover {
    background: #1e293b;
    color: #f1f5f9;
}

/* ================================== */
/* PROFILE MODAL STYLES             */
/* ================================== */
.profile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

body.dark-mode .profile-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.profile-card {
    background: #ffffff;
    border-radius: 24px;
    padding: 0; /* CHANGED */
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease;
    display: flex; /* ADDED */
    flex-direction: column; /* ADDED */
}

body.dark-mode .profile-card {
    background: #1e293b;
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: sticky; /* ADDED */
    top: 0; /* ADDED */
    background: #ffffff; /* ADDED */
    z-index: 10; /* ADDED */
    padding: 1.5rem; /* ADDED */
    border-bottom: 1px solid #e2e8f0; /* ADDED */
}

body.dark-mode .profile-header {
    background: #1e293b; /* ADDED */
    border-bottom: 1px solid #334155; /* ADDED */
}

.profile-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
}

body.dark-mode .profile-header h2 {
    color: #f1f5f9;
}

/* Re-use the .close-btn from styles.css */
.profile-header .close-btn {
    top: 0.75rem; /* ADJUSTED */
    right: 0.75rem; /* ADJUSTED */
}


.profile-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem; /* ADDED */
}

/* User Info Section */
.profile-user-info {
    display: flex;
    align-items: flex-start; /* CHANGED */
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

body.dark-mode .profile-user-info {
    border-bottom: 1px solid #334155;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #eef2ff;
    color: #6366f1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

body.dark-mode .profile-avatar {
    background: #312e81;
    color: #c7d2fe;
}

.profile-details {
    flex-grow: 1; /* ADDED */
    min-width: 0; /* ADDED */
}

/* --- NEW NAME EDIT STYLES --- */
.profile-name-wrapper {
    position: relative;
    min-height: 28px; /* Approx height of h3 */
    margin-bottom: 0.25rem; /* Space before contact info */
}

#profile-name-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 2px solid #6366f1;
    border-radius: 8px;
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
    background: #f8fafc;
    font-family: inherit;
    box-sizing: border-box; /* Ensure padding doesn't break layout */
}

body.dark-mode #profile-name-input {
    background: #334155;
    color: #f1f5f9;
    border-color: #8b5cf6;
}

#profile-name-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#profile-name-input.hidden {
    display: none;
}

#profile-name.hidden {
    display: none;
}

/* Edit buttons container */
.profile-edit-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.profile-edit-btn,
.profile-save-btn,
.profile-cancel-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #94a3b8;
    width: 36px;
    height: 36px;
    display: flex; /* To center icon */
    align-items: center; /* To center icon */
    justify-content: center; /* To center icon */
}

.profile-edit-btn:hover {
    background: #f1f5f9;
    color: #6366f1;
}

.profile-save-btn {
    color: #10b981;
}
.profile-save-btn:hover {
    background: rgba(16, 185, 129, 0.1);
}

.profile-cancel-btn {
    color: #ef4444;
}
.profile-cancel-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

body.dark-mode .profile-edit-btn:hover {
    background: #334155;
    color: #8b5cf6;
}
body.dark-mode .profile-save-btn {
    color: #34d399;
}
body.dark-mode .profile-save-btn:hover {
    background: rgba(52, 211, 153, 0.1);
}
body.dark-mode .profile-cancel-btn {
    color: #f87171;
}
body.dark-mode .profile-cancel-btn:hover {
    background: rgba(248, 113, 113, 0.1);
}

.profile-edit-actions .hidden {
    display: none;
}
/* --- END NAME EDIT STYLES --- */


.profile-details h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
    word-break: break-all;
}

body.dark-mode .profile-details h3 {
    color: #f1f5f9;
}

.profile-details p {
    font-size: 0.875rem;
    color: #64748b;
    word-break: break-all;
}

body.dark-mode .profile-details p {
    color: #cbd5e1;
}

/* Stats Section */
.profile-stats-container h4,
.profile-chart-container h4 {
    font-size: 1rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 1rem;
}

body.dark-mode .profile-stats-container h4,
body.dark-mode .profile-chart-container h4 {
    color: #cbd5e1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

body.dark-mode .stat-box {
    background: #334155;
    border: 1px solid #475569;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #6366f1;
    line-height: 1.2;
}

body.dark-mode .stat-value {
    color: #a5b4fc;
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
}

body.dark-mode .stat-label {
    color: #cbd5e1;
}

/* Chart Container */
#category-chart-wrapper {
    position: relative;
    margin: 0 auto;
    max-height: 300px;
    max-width: 300px;
}

/* Actions */
.profile-actions {
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
}

body.dark-mode .profile-actions {
    border-top: 1px solid #334155;
}

.logout-btn-modal {
    width: 100%;
    padding: 0.875rem 1rem;
    border: none;
    border-radius: 12px;
    background: #fef2f2;
    color: #ef4444;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.logout-btn-modal:hover {
    background: #fee2e2;
    transform: translateY(-1px);
}

body.dark-mode .logout-btn-modal {
    background: #450a0a;
    color: #fca5a5;
}

body.dark-mode .logout-btn-modal:hover {
    background: #571010;
}


/* Responsive */
@media (min-width: 640px) {
    .profile-header {
        padding: 2rem;
    }
    .profile-content {
        padding: 2rem;
    }
    .profile-header h2 {
        font-size: 1.5rem;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}