@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #006747;
    --primary-light: #008f5d;
    --secondary: #C9A227;
    --secondary-hover: #b08d20;
    --dark: #1A2B23;
    --bg-color: #f4f7f5;
    --card-bg: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --danger: #e74c3c;
    --success: #27ae60;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    --radius: 16px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header & Typography */
.top-nav {
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary) 0%, var(--dark) 100%);
    padding: 1.5rem 2rem;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-area h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-area span {
    color: var(--secondary);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.menu-toggle {
    display: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: white;
}

/* Layout */
.main-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .2rem;
    border-bottom: 4px solid transparent;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card.income {
    border-bottom-color: var(--success);
}

.stat-card.expense {
    border-bottom-color: var(--danger);
}

.stat-card.profit {
    border-bottom-color: var(--secondary);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
    margin: 0;
}

.stat-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-header {
    display: flex;
    align-items: center;
}

.stat-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    /* Prevent shrinking */
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: start;
}

@media (max-width: 992px) {
    .charts-section {
        grid-template-columns: 1fr;
    }
}

.chart-container,
.table-container,
.partner-chart {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.chart-container,
.partner-chart {
    position: relative;
    height: 450px;
    /* Increased height to accommodate the share list */
    display: flex;
    flex-direction: column;
}

.partner-chart canvas {
    max-height: 220px !important;
    /* Limit chart height */
    margin-bottom: 1rem;
}

.share-list {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .5rem;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem;
    background: #f8fcf9;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    font-weight: 600;
}

td {
    padding: 1rem;
    border-top: 1px solid #eee;
    font-size: 0.95rem;
}

.amount {
    font-weight: 600;
}

.amount.positive {
    color: var(--success);
}

.amount.negative {
    color: var(--danger);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--primary);
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 103, 71, 0.1);
}

.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 100;
    transition: var(--transition);
}

.btn-fab i {
    margin: 0;
    padding: 0;
    line-height: 1;
}

.btn-fab:hover {
    transform: scale(1.1);
}

.btn-fab::after {
    content: 'Add Entry';
    position: absolute;
    right: 70px;
    background: var(--dark);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.btn-fab:hover::after {
    opacity: 1;
}

/* Custom vibe elements */
.makkah-pattern {
    position: absolute;
    top: 0;
    right: 0;
    width: 150px;
    opacity: 0.05;
    pointer-events: none;
}

/* Filter controls */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-item {
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid #eee;
    font-size: 0.9rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

footer a:hover {
    color: var(--secondary);
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
        order: 2;
    }

    .nav-links {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: var(--dark);
        background: linear-gradient(180deg, var(--dark) 0%, var(--primary) 100%);
        flex-direction: column;
        padding: 5rem 1.5rem;
        transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
        display: flex !important;
    }

    .nav-links.show {
        left: 0;
    }

    .nav-links a {
        font-size: 1.1rem;
        width: 100%;
        padding: 1rem;
        border-radius: 12px;
        margin-bottom: 0.5rem;
    }

    .user-profile {
        display: none;
    }

    .logo-area {
        order: 1;
    }

    .charts-section {
        grid-template-columns: 1fr;
        margin-top: 2rem;
    }

    .chart-container,
    .partner-chart {
        height: 380px !important;
        /* Slightly smaller for mobile to fit better */
        padding: 1rem;
    }

    .partner-chart {
        height: auto !important;
        /* Let partner chart grow naturally on mobile */
        min-height: 450px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
    }

    .stat-card {
        padding: 1rem;
        gap: 0.8rem;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
        min-width: 38px;
        font-size: 1rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .top-nav {
        padding: 1rem 1.5rem;
    }

    .section-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
        margin-bottom: 1.2rem;
        flex-wrap: nowrap;
    }

    .section-header h2 {
        width: auto;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .filters {
        width: auto;
        flex: 1;
        display: flex;
        gap: 0.3rem;
        margin-bottom: 0;
        flex-wrap: nowrap;
        justify-content: flex-end;
    }

    .filters>* {
        flex: 1;
        min-width: 0;
    }

    .filters .filter-item,
    .filters .btn {
        width: 100%;
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
        white-space: nowrap;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Global Loader Styling */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.sync-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: #f1f2f6;
    color: var(--secondary);
}

.sync-status-indicator.synced {
    background: #e8f5e9;
    color: #2e7d32;
}