:root {
    --primary-color: #800020;
    --secondary-color: #ffffff;
    --text-color: #333;
    --light-bg: #f4f6f9;
    --success: #28a745;
    --danger: #dc3545;
    --info: #007bff;
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--light-bg);
    color: var(--text-color);
    min-height: 100vh;
}

/* --- SPA VIEW LOGIC --- */
.view { display: none; }
.view.active { display: block; }

/* --- TOAST NOTIFICATION --- */
#toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    width: 100%;
    padding: 0 20px;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 25px;
    border-radius: 50px;
    margin-bottom: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
    pointer-events: auto;
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    max-width: 300px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

/* --- AUTH VIEWS --- */
.auth-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 2000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.auth-view.active { display: flex; }

.auth-container {
    width: 85%;
    max-width: 400px;
    text-align: center;
}

.auth-logo { margin-bottom: 30px; }
.auth-logo h1 {
    margin-top: 15px;
    color: var(--primary-color);
    font-size: 1.8rem;
}

/* --- PIN DOTS --- */
.pin-dots {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}
.dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: transparent;
    transition: background 0.2s;
}
.dot.active { background: var(--primary-color); }

/* --- KEYPAD --- */
.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 10px;
}
.key {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    margin: 0 auto;
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.key:active {
    background: #e9ecef;
    transform: scale(0.95);
    box-shadow: none;
}
.key-submit {
    background: var(--primary-color);
    color: white;
    border: none;
}
.key-submit:active { background: #5a0017; }

.auth-footer-links {
    margin-top: 30px;
    font-size: 0.9rem;
}

/* --- MAIN APP SHELL --- */
body.logged-in header,
body.logged-in .mobile-nav,
body.logged-in .container {
    display: block;
}
body:not(.logged-in) header,
body:not(.logged-in) .mobile-nav,
body:not(.logged-in) .container {
    display: none;
}

/* --- HEADER & SIDE MENU --- */
header {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    position: fixed;
    top: 0;
    width: 100%;
    display: flex;
    align-items: center;
    z-index: 1000;
    height: 60px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
header h1 {
    font-size: 1.1rem;
    text-align: center;
    width: 100%;
    position: absolute;
    left: 0;
    right: 0;
    pointer-events: none;
}
.hamburger {
    width: 24px;
    height: 20px;
    position: relative;
    z-index: 110;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.hamburger span {
    display: block;
    height: 3px;
    width: 100%;
    background: white;
    border-radius: 2px;
}

/* Side Menu */
.side-nav {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background: white;
    z-index: 10000 !important;
    overflow-x: hidden;
    transition: 0.3s;
    padding-top: 60px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

.side-nav.active {
    width: 280px;
}

.side-nav a {
    padding: 15px 20px;
    text-decoration: none;
    color: #333;
    display: block;
    border-bottom: 1px solid #eee;
    font-size: 16px;
}

.side-nav a i {
    width: 25px;
    margin-right: 10px;
}

.side-nav .close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    z-index: 9999;
    cursor: pointer;
}

.overlay.active {
    display: block;
}

/* ===== FIXED BOTTOM NAVIGATION ===== */
.mobile-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 65px !important;
    background: #ffffff !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: center !important;
    border-top: 1px solid #e0e0e0 !important;
    z-index: 100 !important;
    padding: 0 5px !important;
    box-sizing: border-box !important;
}

.mobile-nav a {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    color: #888 !important;
    font-size: 0.7rem !important;
    flex: 1 1 0 !important;
    height: 100% !important;
    min-width: 40px !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

.mobile-nav a i {
    font-size: 1.3rem !important;
    margin-bottom: 2px !important;
    display: block !important;
}

.mobile-nav a span {
    display: block !important;
    line-height: 1.2 !important;
}

.mobile-nav a.active {
    color: var(--primary-color) !important;
    font-weight: 600 !important;
}

/* Center (+) button */
.mobile-nav .center-btn {
    background: var(--primary-color) !important;
    color: white !important;
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    transform: translateY(-18px) !important;
    box-shadow: 0 4px 10px rgba(128,0,32,0.3) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 auto !important;
}

.mobile-nav .center-btn i {
    font-size: 1.8rem !important;
    margin: 0 !important;
}

.mobile-nav .center-btn span {
    display: none !important;
}

/* Hide footer when NOT logged in */
body:not(.logged-in) .mobile-nav {
    display: none !important;
}

/* --- DESKTOP STYLES (≥768px) --- */
@media (min-width: 768px) {
    .container {
        max-width: 600px;
        margin-left: auto;
        margin-right: auto;
        padding: 15px;
        padding-bottom: 80px;
        padding-top: 70px;
    }

    /* Center the footer on desktop */
    .mobile-nav {
        max-width: 600px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        border-radius: 30px 30px 0 0 !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
        height: 55px !important;
    }

    .mobile-nav a i {
        font-size: 1.2rem !important;
    }

    .mobile-nav a span {
        font-size: 0.65rem !important;
    }

    .mobile-nav .center-btn {
        width: 55px !important;
        height: 55px !important;
        transform: translateY(-15px) !important;
    }

    .mobile-nav .center-btn i {
        font-size: 1.6rem !important;
    }
}

/* --- MOBILE STYLES (<768px) --- */
@media (max-width: 767px) {
    .container {
        padding: 15px;
        padding-bottom: 80px;
        padding-top: 70px;
    }

    .mobile-nav {
        max-width: 100% !important;
        left: 0 !important;
        transform: none !important;
        border-radius: 0 !important;
    }

    .mobile-nav a i {
        font-size: 1.3rem !important;
    }

    .mobile-nav a span {
        font-size: 0.7rem !important;
    }

    .mobile-nav .center-btn {
        width: 60px !important;
        height: 60px !important;
        transform: translateY(-18px) !important;
    }

    .mobile-nav .center-btn i {
        font-size: 1.8rem !important;
    }
}

/* --- MAIN CONTENT AREA --- */
.container {
    padding: 15px;
    padding-bottom: 80px;
    padding-top: 70px;
}

/* --- CARDS & COMPONENTS --- */
.card {
    background: white;
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.card-header {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    display: block;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-warning { background: #ffc107; color: #333; }
.btn-secondary { background: #6c757d; color: white; }
.btn-sm {
    padding: 8px 12px;
    font-size: 0.8rem;
    border-radius: 20px;
    width: auto;
    display: inline-block;
}

.form-control {
    width: 100%;
    padding: 15px;
    border: 2px solid #eee;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 1.1rem;
    text-align: center;
}
.form-control:focus {
    border-color: var(--primary-color);
    outline: none;
}

.balance-box {
    background: linear-gradient(135deg, var(--primary-color), #4d0014);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    margin-bottom: 20px;
}
.balance-amount { font-size: 2.5rem; font-weight: bold; }

.wallet-card {
    background: var(--primary-color);
    color: white;
    padding: 25px;
    border-radius: 15px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.transaction-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}
.ti-icon {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    color: white;
}
.ti-icon.plus { background: var(--success); }
.ti-amount.plus { color: var(--success); }

.earn-info-box {
    background: #e7f3ff;
    color: #004085;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
    text-align: center;
}

/* --- SETTINGS PAGE --- */
.settings-group {
    margin-bottom: 25px;
}
.settings-group h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.2rem;
}
.settings-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
}
.settings-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}
.settings-item select,
.settings-item input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
}
.settings-item .note {
    font-size: 0.85rem;
    color: #777;
    margin-top: 8px;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: white;
    width: 90%;
    max-width: 400px;
    border-radius: 10px;
    overflow: hidden;
}
.modal-header {
    padding: 15px;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
}
.modal-close {
    font-size: 24px;
    cursor: pointer;
}
.modal-body {
    padding: 20px;
    text-align: center;
}
.progress-container {
    height: 5px;
    background: #eee;
}
.progress-bar {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 1s linear;
}
.modal-footer {
    padding: 15px;
}

/* --- BADGES --- */
.badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
}
.badge.active, .badge.paid { background: #d4edda; color: #155724; }
.badge.blocked, .badge.rejected { background: #f8d7da; color: #721c24; }
.badge.pending { background: #fff3cd; color: #856404; }
.badge.draft { background: #ffc107; color: #856404; }
.badge.paused, .badge.completed { background: #f8d7da; color: #721c24; }

/* --- PUBLIC ADS --- */
.public-ad-card {
    cursor: pointer;
    transition: transform 0.2s;
}
.public-ad-card:hover {
    transform: scale(1.02);
}
.public-ad-card img {
    margin-top: 10px;
    border-radius: 8px;
    max-width: 100%;
}

/* --- ADMIN TABLES --- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th,
.admin-table td {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

.admin-table th {
    background-color: #f5f5f5;
    font-weight: bold;
}

@media (max-width: 768px) {
    .admin-table th,
    .admin-table td {
        padding: 8px;
        font-size: 12px;
    }
}

/* --- DASHBOARD CARDS --- */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.dashboard-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.dashboard-card h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
}

.dashboard-card .value {
    font-size: 1.5rem;
    font-weight: bold;
}

.dashboard-card.earnings .value { color: #28a745; }
.dashboard-card.deposits .value { color: #007bff; }
.dashboard-card.withdrawals .value { color: #dc3545; }
.dashboard-card.fees .value { color: #ffc107; }
.dashboard-card.profit .value { color: #800020; }

/* --- REPORT CARDS --- */
.report-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.report-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.report-card h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
}

.report-card .value {
    font-size: 1.5rem;
    font-weight: bold;
}

.report-card.earnings .value { color: #28a745; }
.report-card.deposits .value { color: #007bff; }
.report-card.withdrawals .value { color: #dc3545; }
.report-card.fees .value { color: #ffc107; }
.report-card.profit .value { color: #800020; }

/* --- PERIOD BUTTONS --- */
.period-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 8px 16px;
    background: #f0f0f0;
    border: none;
    border-radius: 20px;
    cursor: pointer;
}

.period-btn.active {
    background: #800020;
    color: white;
}

/* --- DATE RANGE --- */
.date-range {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.date-range input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* Dashboard Cards */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.dashboard-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.dashboard-card h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 5px;
}

.dashboard-card .value {
    font-size: 1.5rem;
    font-weight: bold;
}

.dashboard-card.earnings .value { color: #28a745; }
.dashboard-card.deposits .value { color: #007bff; }
.dashboard-card.withdrawals .value { color: #dc3545; }
.dashboard-card.fees .value { color: #ffc107; }
.dashboard-card.profit .value { color: #800020; }

/* Dashboard Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.stat-item {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

/* Transaction item */
.transaction-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.ti-icon {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

.ti-details {
    flex: 1;
}

.ti-details h4 {
    font-size: 0.9rem;
    margin: 0;
}

.ti-details p {
    font-size: 0.7rem;
    color: #999;
    margin: 0;
}

.ti-amount {
    font-weight: bold;
}

.ti-amount.positive {
    color: #28a745;
}

.ti-amount.negative {
    color: #dc3545;
}