/* ============================================
   PAKISTAN RAILWAY GIS DASHBOARD
   ============================================ */

:root {
    /* Color Palette */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --success-color: #10b981;
    --danger-color: #dc2626;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Layout */
    --header-height: 70px;
    --sidebar-width: 280px;
    
    /* Colors */
    --railway-color: #dc2626;
    --road-color: #2563eb;
    --building-color: #059669;
    --city-marker-color: #f59e0b;


    --color-residential: #10b981;
    --color-hospital: #ef4444;
    --color-government: #4d4957;
    --color-mosque: #1e3a8a;
    --color-education: #f59e0b;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   HEADER
   ============================================ */

.dashboard-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

/* New: Constrain the content to a reasonable max-width and center it */
.header-wrapper {
    max-width: 1600px;          /* or 1440px / 1800px — choose what feels good */
    margin: 0 auto;             /* centers it horizontally */
    height: 100%;
    padding: 0 1.5rem;          /* breathing space on sides — this is what keeps logos away from edge */
    box-sizing: border-box;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;   /* distributes left / center / right */
    height: 100%;
    gap: 1.5rem;                      /* minimum space between sections */
}

/* Left logo — push to start, but wrapper padding already handles edge distance */
.logo-left {
    flex-shrink: 0;
    min-width: 100px;                 /* prevents collapsing too much */
}

/* Right logos */
.logo-right {
    display: flex;
    align-items: center;
    gap: 1rem;                        /* space between the two right logos */
    flex-shrink: 0;
    min-width: 180px;                 /* keeps them together */
}

.company-logo {
    height: 42px;                     /* fixed height → consistent size */
    width: 150px;
    object-fit: contain;
    display: block;
    margin-right: 10px;
}
.company-logo1 {
    height: 62px;                     /* fixed height → consistent size */
    width: auto;
    object-fit: contain;
    display: block;
    margin-right: 10px;
}
.second-logo {
    height: 38px;                     /* optional: slightly smaller for hierarchy */
}

/* Title stays centered in remaining space */
.title-section {
    flex: 1;                          /* takes available space */
    text-align: center;
    margin-left: 130px;
    min-width: 0;                     /* prevents overflow issues */
}

/* On smaller screens — reduce padding if needed */
@media (max-width: 1200px) {
    .header-wrapper {
        padding: 0 1rem;
    }
    .company-logo {
        height: 36px;
    }
    .company-logo1 {
        height: 36px;
    }
}

/* Very small screens — you can stack or hide if needed, but for now keep simple */
@media (max-width: 768px) {
    .header-content {
        justify-content: center;
        gap: 0.8rem;
    }
    .logo-left, .logo-right {
        flex: 0 0 auto;
    }
    .title-section {
        font-size: 0.95rem;           /* smaller title if needed */
    }
}
/* Sidebar reset button */
.reset-section {
    margin-bottom: 1.5rem;
    padding: 0.5rem 0;
}

.reset-btn-sidebar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.reset-btn-sidebar:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.reset-btn-sidebar svg {
    flex-shrink: 0;
}
/* Make sure toggles for base map look active when selected */
.layer-toggles input[type="radio"]:checked + .toggle-switch {
    background: var(--primary-color);  /* same as checkboxes */
}

.layer-toggles input[type="radio"]:checked + .toggle-switch::after {
    transform: translateX(16px);
}
.base-map-toggle {
    padding: 0.8rem 0.6rem;
    background: rgba(37, 99, 235, 0.05);  /* light tint to make it stand out a bit */
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.base-map-toggle .toggle-label {
    font-weight: 500;
    color: var(--text-primary);
}

.base-map-toggle input[type="checkbox"]:checked ~ .toggle-label svg {
    stroke: #10b981;  /* green when satellite is on - optional visual cue */
}
/* Optional: Highlight the whole row when active */
.layer-toggle-item:has(input[type="radio"]:checked) {
    background: rgba(37, 99, 235, 0.08);  /* light blue tint */
    border-radius: 6px;
}

/* .title-section {
    flex: 1;
    text-align: center;
} */

.dashboard-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.dashboard-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-nav {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ============================================
   MAIN LAYOUT
   ============================================ */

.dashboard-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    padding-top: var(--header-height);
    min-height: 100vh;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* City Selector */
.city-selector {
    width: 100%;
}

.city-dropdown {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.15s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
}

.city-dropdown:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.city-dropdown option {
    padding: 10px;
}

/* City Info Card */
.city-info-section {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
}

.city-info-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.city-name-display {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary-color);
}

.city-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-light);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.zoom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.zoom-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.zoom-btn:active {
    transform: translateY(0);
}

/* Layer Controls - Radio Buttons */
.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.layer-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.layer-option:hover {
    background: var(--bg-tertiary);
}

.layer-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
}

.layer-label {
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Layer Toggles - Checkboxes with Switch */
.layer-toggles {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
/* Raster Legend Blocks */
/* Raster Legend */
#rasterLegend {
    display: none;
}

#rasterLegend.active {
    display: block !important;
}

/* Horizontal Legend Blocks */
.legend-block {
    border: 1px solid rgba(0,0,0,0.3);
}

.block-3 {
    background: rgb(0, 0, 139, 0.6); /* Dark Blue - High */
}

.block-2 {
    background: rgb(65, 105, 225, 0.5); /* Royal Blue - Medium */
}

.block-1 {
    background: rgb(135, 206, 250, 0.5); /* Light Blue - Low */
}
.layer-toggle-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.legend-color {
    width: 20px;
    height: 20px;
    display: inline-block;
    margin-right: 8px;
    border-radius: 3px;
    vertical-align: middle;
}
.layer-toggle-item:hover {
    background: var(--bg-tertiary);
}

.layer-toggle-item input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    width: 36px;
    height: 20px;
    background: var(--border-color);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.layer-toggle-item input[type="checkbox"]:checked + .toggle-switch {
    background: var(--primary-color);
}

.layer-toggle-item input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(16px);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.toggle-label svg {
    color: var(--text-secondary);
}

/* Stats Section */
.stats-section {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-light);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   MAP SECTION
   ============================================ */

.map-full-width {
    position: fixed;
    top: var(--header-height);
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
}

.dashboard-map {
    width: 100%;
    height: 100%;
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 15px;
    left: 15px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;          /* smaller corners */
    padding: 6px 10px;           /* reduced padding */
    box-shadow: var(--shadow-sm);/* lighter shadow */
    z-index: 1000;
    width: fit-content;          /* shrink to content */
    max-width: 420px;            /* prevent stretching */
}

.map-legend h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-line {
    width: 24px;
    height: 4px;
    border-radius: 2px;
}

.legend-line.railway {
    background: var(--railway-color);
}

.legend-line.road {
    background: var(--road-color);
}

.legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-marker.city {
    background: var(--city-marker-color);
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* City Marker Info Popup */
.city-marker-info {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--city-marker-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    animation: fadeInDown 0.3s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   LOADING OVERLAY
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ============================================
   LEAFLET CUSTOMIZATIONS
   ============================================ */

.leaflet-container {
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-content {
    margin: 12px;
    line-height: 1.6;
}

.popup-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.popup-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.popup-info strong {
    color: var(--text-primary);
}

/* Custom City Marker */
.city-marker-icon {
    background: var(--city-marker-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 992px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        top: 0;
        display: none;
    }
    
    .sidebar.open {
        display: block;
    }
    
    .map-full-width {
        position: relative;
        top: 0;
        left: 0;
        height: 60vh;
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: auto;
    }
    
    .header-content {
        flex-wrap: wrap;
        padding: 12px;
        gap: 10px;
    }
    
    .logo-container {
        order: 1;
    }
    
    .title-section {
        order: 2;
        flex-basis: 100%;
        text-align: center;
    }
    
    .header-nav {
        order: 3;
    }
    
    .company-logo {
        height: 32px;
    }
    .company-logo1 {
        height: 32px;
    }
    .dashboard-title {
        font-size: 1.1rem;
    }
    
    .map-legend {
        bottom: 10px;
        left: 10px;
        padding: 8px 12px;
    }
    
    .city-info-section {
        margin-top: 1rem;
    }
}

/* ============================================
   DARK MODE & TOGGLE BUTTON STYLES
   ============================================ */

/* Toggle Button Styling */
.theme-toggle-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 1rem; /* Spacing from other buttons */
}

.theme-toggle-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

/* Default Icons (Sun visible, Moon hidden) */
.icon-moon { display: none; }

/* Define Dark Theme Variables */
body.dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #6b7280;
    --border-color: #404040;
    --border-light: #333333;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

    background-color: var(--bg-primary);
}

/* Switch Icons when Dark */
body.dark-mode .icon-sun { display: none; }
body.dark-mode .icon-moon { display: block; }

/* Header & Sidebar Dark Mode */
body.dark-mode .dashboard-header,
body.dark-mode .sidebar {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

/* Typography Colors */
body.dark-mode .dashboard-title,
body.dark-mode .section-title,
body.dark-mode .detail-label,
body.dark-mode .stat-label,
body.dark-mode .toggle-label,
body.dark-mode .theme-toggle-btn {
    color: var(--text-primary);
}

body.dark-mode .dashboard-subtitle,
body.dark-mode .detail-value,
body.dark-mode .stat-value {
    color: var(--text-secondary);
}

/* LOGO MAGIC: Turn Black logos White automatically */
body.dark-mode .company-logo1 {
    filter: brightness(0) invert(1); 
}

/* Form Elements */
body.dark-mode .city-dropdown {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

body.dark-mode .city-dropdown:focus {
    background-color: var(--bg-secondary);
    border-color: var(--primary-color);
}

/* Toggles/Switches */
body.dark-mode .layer-toggle-item:hover {
    background: var(--bg-tertiary);
}
body.dark-mode .toggle-switch {
    background: #555;
}

/* Stats & Cards */
body.dark-mode .stats-section { background: var(--bg-tertiary); }
body.dark-mode .detail-row { border-bottom: 1px solid var(--border-light); }
body.dark-mode .city-info-section {
    background: linear-gradient(135deg, #2d2d2d 0%, #1e1e1e 100%);
    border: 1px solid var(--border-color);
}

/* Buttons Dark Mode Style */
body.dark-mode .reset-btn-sidebar {
    background: #333;
    border: 1px solid #555;
    color: var(--text-primary);
}
body.dark-mode .reset-btn-sidebar:hover { background: #444; }

body.dark-mode .theme-toggle-btn {
    background: #2d2d2d;
    border-color: #404040;
}
body.dark-mode .theme-toggle-btn:hover {
    border-color: var(--primary-color);
}

/* Leaflet Map UI */
body.dark-mode .leaflet-popup-content-wrapper {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
body.dark-mode .leaflet-popup-tip { background: var(--bg-secondary); }
body.dark-mode .leaflet-container { background: #121212; }

/* Map Legend */
body.dark-mode .map-legend {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Loading Overlay */
body.dark-mode .loading-overlay { background: var(--bg-primary); }