:root {
    --wj-blue: #4A90E2;     
    --wj-dark-blue: #2C3E50; 
    --wj-green: #2EC971;    
    --wj-light-green: #A5D6A7; 
    --wj-red: #FF686B;      
    --wj-yellow: #FFC107;   
    --wj-white: #F5F5F5;    
    --wj-gray: #4A4A4A;     
}

body, html {
    height: 100%;
    background: #2c3e50;
    overscroll-behavior-y: contain;
}

body {
    color: var(--wj-gray);
    font-size: 1.2rem;
    font-family: 'Segoe UI', Arial, sans-serif;
    padding-bottom: 70px;
}

/* Large Text Mode */
body.large-text {
    font-size: 1.5rem !important; /* Increase base font size */
}

/* High Contrast Mode - Enhanced and Fixed */
body.high-contrast {
    background-color: #000 !important;
    color: #fff !important;
}

body.high-contrast #app-container {
    background-color: #000 !important;
}

body.high-contrast .card {
    background: #333 !important;
    background-image: none !important;
    color: #fff !important;
    border: 1px solid #555 !important;
    box-shadow: 0 4px 8px rgba(255, 255, 255, 0.1) !important;
}

body.high-contrast .card-body {
    background-color: #333 !important;
}

body.high-contrast h1, 
body.high-contrast h2, 
body.high-contrast h3, 
body.high-contrast h4, 
body.high-contrast h5, 
body.high-contrast h6,
body.high-contrast .text-muted {
    color: #fff !important;
}

body.high-contrast .btn {
    background-image: none !important;
    background-color: #555 !important;
    color: #fff !important;
    border: 1px solid #777 !important;
}

body.high-contrast .btn:hover {
    background-color: #777 !important;
}

body.high-contrast .btn-success {
    background-color: #005000 !important;
}

body.high-contrast .btn-primary {
    background-color: #004080 !important;
}

body.high-contrast .btn-secondary {
    background-color: #505050 !important;
}

body.high-contrast .progress {
    background-color: #444 !important;
}

body.high-contrast .progress-bar {
    background-color: #888 !important;
}

body.high-contrast .form-control, 
body.high-contrast .form-select {
    background-color: #222 !important;
    color: #fff !important;
    border: 1px solid #555 !important;
}

body.high-contrast #main-bottom-nav {
    background: #222 !important;
    background-image: none !important;
    border-top: 1px solid #555 !important;
}

body.high-contrast .nav-btn {
    color: #fff !important;
}

body.high-contrast .nav-btn.active {
    color: #00ff00 !important;
}

/* Keep achievement card text readable in high contrast mode */
body.high-contrast .p-3.border.rounded.bg-light {
    background-color: #333 !important;
    background-image: none !important;
    border: 1px solid #555 !important;
}

body.high-contrast .p-3.border.rounded.bg-light .fw-bold,
body.high-contrast .p-3.border.rounded.bg-light .small.text-muted {
    color: #000 !important; /* Keep achievement title and description text black */
}

body.high-contrast #achievements-container .p-3.border.rounded.bg-light,
body.high-contrast #achievements-view-container .p-3.border.rounded.bg-light {
    background-color: #fff !important; /* White background for achievement cards */
    border-color: #777 !important;
    box-shadow: 0 3px 10px rgba(255, 255, 255, 0.15) !important;
}

/* Adjust badge contrast in high contrast mode */
body.high-contrast .badge.bg-success {
    background-color: #00aa00 !important; /* Brighter green */
    color: #000 !important; /* Black text */
    border: 1px solid #fff !important;
}

body.high-contrast .badge.bg-secondary {
    background-color: #aaaaaa !important; /* Lighter gray */
    color: #000 !important; /* Black text */
    border: 1px solid #fff !important;
}

#app-container {
    min-height: 100vh;
    position: relative;
    padding-bottom: 80px !important; /* Slightly more than navbar height */
    background: var(--wj-white);
    display: block;
    visibility: visible;
}

.navbar.fixed-bottom {
    position: sticky !important;
    bottom: 0;
    z-index: 1030;
    background: var(--wj-white) !important;
}

.app-page {
    min-height: 100vh;
    margin-left: 0;
    margin-right: 0;
}

/* Only hide navbar on login page */
#login-view:not([style*="display: none"]) ~ #main-bottom-nav {
    display: none !important;
}

/* Ensure navbar is visible on other pages */
.app-page:not(#login-view)[style*="display: block"] ~ #main-bottom-nav {
    display: flex !important;
}

/* Add smooth transition for navbar */
#main-bottom-nav {
    position: fixed !important;
    bottom: 0 !important; 
    left: 0;
    right: 0;
    z-index: 1040;
    height: 70px; /* Standard height */
    margin: 0 !important; /* Remove any margin */
    padding-bottom: calc(env(safe-area-inset-bottom)) !important; /* Adjust for iOS safe areas */
    background: linear-gradient(180deg, #212529, #343a40) !important;
    box-shadow: 0 -5px 10px rgba(0, 0, 0, 0.1) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.card {
    border-radius: 1.25rem;
    border: none;
    /* Modern glassmorphism effect with green tint */
    background: linear-gradient(135deg, var(--wj-light-green) 60%, #e0f2f1 100%);
    box-shadow: 0 4px 24px 0 rgba(60, 120, 80, 0.10), 0 1.5px 4px 0 rgba(60, 120, 80, 0.08);
    backdrop-filter: blur(2px);
}

.card .card-header,
.card .card-body {
    background: transparent;
    border-radius: 1.25rem;
}

.btn-primary {
    background-color: var(--wj-blue);
    border-color: var(--wj-blue);
}
.btn-primary:focus, .btn-primary:hover {
    background-color: #357ABD;
    border-color: #357ABD;
}

.btn-success {
    background-color: var(--wj-green);
    border-color: var(--wj-green);
}
.btn-success:focus, .btn-success:hover {
    background-color: #27ae60;
    border-color: #27ae60;
}

.btn-warning {
    background-color: var(--wj-yellow);
    border-color: var(--wj-yellow);
    color: #212529;
}
.btn-warning:hover, .btn-warning:focus {
    background-color: #e0a800;
    border-color: #d39e00;
    color: #212529;
}

.btn-secondary {
    background-color: var(--wj-dark-blue);
    border-color: var(--wj-dark-blue);
    color: #fff;
}
.btn-secondary:focus, .btn-secondary:hover {
    background-color: #1a242f;
    border-color: #1a242f;
    color: #fff;
}

.btn-outline-secondary {
    border-color: var(--wj-gray);
    color: var(--wj-gray);
}
.btn-outline-secondary:focus, .btn-outline-secondary:hover {
    background-color: var(--wj-gray);
    color: #fff;
}

.progress-bar.bg-success {
    background-color: var(--wj-green) !important;
}
.progress-bar.bg-primary {
    background-color: var(--wj-blue) !important;
}
.progress-bar.bg-warning {
    background-color: var(--wj-yellow) !important;
    color: #212529;
}

input.form-control {
    font-size: 1.2rem;
    padding: 1rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--wj-blue);
    box-shadow: 0 0 0 0.2rem rgba(13,110,253,.15);
}

h1, h2, h3, h4, h5 {
    font-weight: bold;
}

.text-primary, .wj-blue { color: var(--wj-blue) !important; }
.text-success, .wj-green { color: var(--wj-green) !important; }
.text-warning, .wj-yellow { color: var(--wj-yellow) !important; }
.text-dark, .wj-dark-blue { color: var(--wj-dark-blue) !important; }
.text-accent, .wj-red { color: var(--wj-red) !important; }

.nav-btn {
    color: var(--wj-yellow);
    text-decoration: none;
    transition: all 0.3s ease;
    border: none;
    background: transparent;
    padding: 0.5rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 25%;
    cursor: pointer; /* Add cursor pointer to indicate it's clickable */
    outline: none;   /* Remove outline for cleaner look */
    z-index: 1050;   /* Ensure it's above other elements */
    position: relative; /* Enable z-index */
}

.nav-btn.active {
    color: var(--wj-blue);
    font-weight: bold; /* Make active state more visible */
}

.nav-btn:hover, .nav-btn:focus {
    color: var(--wj-blue);
    outline: none;
    text-decoration: none;
    transform: scale(1.05); /* Slight scale effect for feedback */
}

.badge.bg-success {
    background-color: var(--wj-green) !important;
}
.badge.bg-secondary {
    background-color: var(--wj-dark-blue) !important;
}
.badge.bg-warning {
    background-color: var(--wj-yellow) !important;
    color: #212529;
}

/* Custom accent for icons */
.icon-accent { color: var(--wj-red) !important; }

.container {
    padding-left: 2rem;
    padding-right: 2rem;
    padding-bottom: 1rem; /* Add padding at the bottom */
}

/* Fix the padding on the last card in each view */
.app-page .card:last-of-type {
    margin-bottom: 30px !important; /* Ensure last card has sufficient margin */
}

.app-page .container {
    padding-bottom: 20px;
}

@media (max-width: 600px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Essential map styles - updated for better reliability */
#map, #dashboard-map {
    height: 250px !important; /* Increased from 220px to match HTML */
    width: 100% !important;
    z-index: 10;
    position: relative;
    display: block !important;
    touch-action: manipulation;
    background-color: #e8e8e8;
    border-radius: 1rem 1rem 0 0;
    overflow: hidden;
    visibility: visible !important;
    margin-top: 0;
    margin-bottom: 0;
}

/* Map styles - CRITICAL FIXES */
#dashboard-map {
    width: 100% !important;
    height: 300px !important; /* Increased height for better visibility */
    z-index: 1;
    position: relative !important;
    display: block !important;
    border-radius: 1rem 1rem 0 0 !important;
    overflow: hidden !important;
    background-color: #e8e8e8 !important;
    margin: 0; /* Ensure no extra margin */
}

/* Ensure the map card properly contains the map */
.card.mb-4.shadow:first-of-type {
    margin-bottom: 1rem !important; /* Add spacing below the map card */
    padding: 0 !important; /* Remove padding to align map properly */
    overflow: hidden !important; /* Prevent overflow issues */
}

/* Leaflet container MUST be visible */
.leaflet-container {
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
    visibility: visible !important;
    background: #f0f0f0 !important;
}

/* Ensure all map elements are visible */
.leaflet-pane {
    z-index: 400 !important;
    visibility: visible !important;
}

.leaflet-tile-pane {
    z-index: 1 !important;
    visibility: visible !important;
}

.leaflet-tile {
    visibility: visible !important;
}

/* Ensure map controls work */
.leaflet-top, .leaflet-bottom {
    z-index: 1000 !important;
}

/* Map loading indicator - adjusted z-index */
#map-loading {
    position: absolute !important;
    top: 50%; /* Center vertically */
    left: 50%; /* Center horizontally */
    transform: translate(-50%, -50%) !important;
    z-index: 100 !important;
    background: rgba(255, 255, 255, 0.8) !important;
    padding: 10px 15px !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-container {
    height: 100% !important;
    width: 100% !important;
    touch-action: manipulation;
    background: #f0f0f0 !important;
    visibility: visible !important;
    z-index: 10;
}

/* Make sure map tiles are visible */
.leaflet-tile {
    visibility: visible !important;
}

/* Add grid lines to empty map */
.leaflet-tile-pane:empty::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(to right, #ddd 1px, transparent 1px),
        linear-gradient(to bottom, #ddd 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Ensure the map doesn't get hidden by parent containers */
.card .card-body div#dashboard-map {
    visibility: visible !important;
    overflow: visible !important;
}

/* Fix map container to properly contain the map */
#dashboard-map-container {
    position: relative;
    width: 100%; 
    height: 250px; /* Increased from 220px to match HTML */
    overflow: visible; /* Changed from hidden to visible */
    border-radius: 1rem;
    margin-bottom: 0.5rem;
}

/* Ensure the map respects the container boundaries */
#dashboard-map {
    width: 100% !important;
    height: 100% !important;
    border-radius: 1rem 1rem 0 0;
    z-index: 10;
}

/* Enhanced map loading indicator styling */
#map-loading {
    position: absolute;
    top: 125px; 
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 100; /* Lower than 9999 to not block interactions */
    background-color: rgba(255, 255, 255, 0.7);
    padding: 5px 10px;
    border-radius: 5px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: opacity 0.3s ease;
    visibility: visible !important;
}

/* Fix for mobile devices */
@media (max-width: 576px) {
    #dashboard-map-container, #dashboard-map {
        height: 250px;
    }
    
    .leaflet-control-zoom {
        margin: 5px !important;
    }
    
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    #dashboard-map {
        height: 250px !important; /* Adjust height for smaller screens */
    }
    
    #main-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Add these fixes for the marker position */

/* Fix for map panning and zooming behavior */
.leaflet-map-pane {
    z-index: 2 !important;
    transition: none !important;
    transform-origin: center !important;
}

/* Fix for positioning accuracy */
.leaflet-marker-pane {
    position: absolute !important;
    z-index: 4 !important;
    pointer-events: auto !important;
}

/* Ensure marker stays in correct position */
.leaflet-marker-icon {
    transform-origin: center !important;
    transition: transform 0.1s !important;
}

/* Improve Leaflet controls positioning */
.leaflet-top, 
.leaflet-bottom {
    z-index: 1000;
}

.leaflet-overlay-pane {
    z-index: 3 !important;
}

.leaflet-tooltip-pane {
    z-index: 5 !important;
}

.leaflet-popup-pane {
    z-index: 6 !important;
}

.leaflet-control {
    z-index: 7 !important;
}

/* Ensure splash screen hides properly */
#splash-screen {
    display: flex;
    visibility: visible;
    opacity: 1;
    transition: opacity 0.5s ease;
}

/* Increase bottom margin of the logout button */
#logout-btn {
    margin-bottom: 20px !important;
}

/* Fix for scrolling issues after login/signup */
#dashboard-view {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

html, body {
    height: 100%;
    width: 100%;
    position: relative;
    overflow-x: hidden;
    /* Default to auto scrolling unless specifically needed */
    overflow-y: auto !important;
}

/* Fix body overflow issues */
body.scroll-enabled {
    overflow: auto !important;
    height: auto !important;
    position: static !important;
}

/* Allow app container to scroll */
#app-container {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
