/* ==================== COMPREHENSIVE MOBILE OVERHAUL ==================== */

/* 1. Reset & Global Mobile Styles */
@media (max-width: 768px) {

    /* Fix horizontal overflow */
    body,
    html {
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }

    /* Container padding adjustment */
    .main-layout-wrapper,
    .header-container {
        padding: 0 0.5rem !important;
        /* Reduce padding for more space */
        width: 100% !important;
        max-width: 100vw !important;
    }
}

/* 2. Header Improvements */
@media (max-width: 768px) {
    .header-top {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 0.5rem !important;
        gap: 0.25rem !important;
    }

    /* ORDERING: Name First, Menu Second, Others Below */

    /* 1. Village Title & Logo */
    .village-title-container {
        order: 1 !important;
        width: auto !important;
        flex: 1 1 auto !important;
        /* Allow growing, but shrink if needed */
        justify-content: flex-start !important;
        margin-top: 0 !important;
        text-align: left !important;
        min-width: 0 !important;
        /* Allow text truncate/wrap properly */
    }

    .village-title {
        font-size: 1rem !important;
        /* Optimized size */
        white-space: normal !important;
        line-height: 1.1 !important;
        text-align: left !important;
        margin-left: 0.25rem !important;
    }

    .gp-logo {
        width: 45px !important;
        height: 45px !important;
        margin-right: 0 !important;
    }

    /* 2. Menu Button & Right Section */
    .header-right {
        order: 2 !important;
        flex: 0 0 auto !important;
        /* Don't grow/shrink unexpectedly */
        gap: 0.5rem !important;
        margin-left: 0.5rem !important;
    }

    /* Adjust Seal/Lang on Mobile to save space */
    .header-right .rajya-mudra-logo {
        width: 35px !important;
        height: 35px !important;
        display: none !important;
        /* Hide seal on small mobile screens to fit Menu next to Name */
    }

    /* Show Seal on slightly larger mobile if space permits */
    @media (min-width: 400px) {
        .header-right .rajya-mudra-logo {
            display: block !important;
        }
    }

    .lang-select {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.75rem !important;
        height: 30px !important;
        display: none !important;
        /* Hide lang on very small screens, menu has it? OR keep it below? */
    }

    /* Actually, keep lang visible but compact, or move to order 3? 
       Can't move children of header-right out easily without JS. 
       Let's keep it but compact. */
    .lang-select {
        display: block !important;
    }


    /* 3. LGD ID & Census - Move to next line */
    .id-center {
        order: 3 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 1rem !important;
        margin-top: 0.5rem !important;
        padding-top: 0.5rem !important;
        border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    .id-value {
        font-size: 0.9rem !important;
        padding: 0.15rem 0.5rem !important;
    }

    .id-label,
    .census-id {
        font-size: 0.6rem !important;
    }

    /* 4. Population Stats - Move to Bottom */
    .header-population {
        order: 4 !important;
        width: 100% !important;
        margin-top: 0.5rem !important;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 0.5rem !important;
    }

    .pop-title {
        font-size: 0.8rem !important;
        text-align: center !important;
        margin-bottom: 0.25rem !important;
    }

    .pop-stats-grid {
        display: flex !important;
        justify-content: space-around !important;
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
    }

    .pop-item {
        flex-direction: column !important;
        align-items: center !important;
    }

    .pop-label {
        font-size: 0.6rem !important;
    }

    .pop-value {
        font-size: 0.7rem !important;
    }

    /* Mobile Menu Button */
    .mobile-menu-btn {
        padding: 0.4rem !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        color: white !important;
        /* Ensure readable against header bg */
        border: 1px solid rgba(255, 255, 255, 0.5) !important;
    }

    .mobile-menu-btn svg {
        width: 24px;
        height: 24px;
    }
}

/* 3. Leadership Section - Vertical Grid (2 Columns) */
@media (max-width: 768px) {
    .leadership-row {
        padding: 1rem 0.5rem !important;
        background: #F5EFE7 !important;
        width: 100% !important;
        height: auto !important;
        display: block !important;
    }

    .leadership-inline {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        /* 2 Columns */
        gap: 0.75rem !important;
        padding: 0 !important;
        width: 100% !important;
        overflow: visible !important;
        justify-items: stretch !important;
        /* Stretch to fill column */
    }

    .leader-item {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0.5rem !important;
        display: flex !important;
        flex-direction: row !important;
        /* Image left, Text right style? OR Top/Bottom? */
        /* Let's try side-by-side for 2-col grid to save vertical space, OR top-bottom for clean look */
        /* Previous 2-col was vertical stack item. Let's keep it. */
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;

        background: white !important;
        border-radius: 8px !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
        height: 100% !important;
    }

    .leader-img {
        width: 65px !important;
        height: 65px !important;
        margin-bottom: 0.4rem !important;
        border-width: 2px !important;
    }

    .leader-info {
        text-align: center !important;
        width: 100% !important;
    }

    .leader-info span {
        font-size: 0.55rem !important;
        color: #666 !important;
        margin-bottom: 0.1rem !important;
        display: block !important;
        line-height: 1.1 !important;
    }

    .leader-info p {
        font-size: 0.7rem !important;
        font-weight: 700 !important;
        color: #333 !important;
        line-height: 1.2 !important;
    }
}

/* 4. Section & Card Standardization */
@media (max-width: 768px) {
    section {
        padding: 1.25rem 1rem !important;
        margin-bottom: 1.5rem !important;
        border-radius: 12px !important;
    }

    .section-title {
        font-size: 1.4rem !important;
        text-align: center !important;
        margin-bottom: 1.25rem !important;
    }

    .section-title::after {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    /* Cards - Make them full width */
    .gp-member-grid,
    .admin-member-grid,
    .member-grid,
    .self-declaration-grid {
        grid-template-columns: 1fr !important;
        /* Single column */
        gap: 1rem !important;
    }

    /* 5-col leadership inside grid? No, that was inline. */

    .member-card,
    .self-declaration-card {
        width: 100% !important;
        margin: 0 !important;
    }
}

/* 5. Buttons & Touch Targets */
@media (max-width: 768px) {

    button,
    .download-btn,
    .scheme-link-external,
    .sidebar-nav a {
        min-height: 44px;
        /* Accessible touch target */
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* 6. Footer Layout */
@media (max-width: 768px) {
    .footer-content {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        padding: 2rem 1rem !important;
        text-align: center !important;
    }

    .footer-section h3 {
        text-align: center !important;
    }

    .footer-section h3::after {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}

/* 7. Gallery & Images */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: 1fr !important;
    }

    img {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* 8. Table Responsiveness */
@media (max-width: 768px) {

    .revenue-table-container,
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        display: block !important;
        width: 100% !important;
    }

    table {
        min-width: 500px !important;
    }
}

/* 9. Sidebar Improvements */
@media (max-width: 768px) {
    .sidebar {
        width: 80% !important;
        max-width: 300px !important;
    }

    .sidebar-nav a {
        padding: 0.8rem 1rem !important;
        margin-bottom: 0.5rem !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        text-align: left !important;
        padding-left: 1.5rem !important;
    }

    .sidebar-overlay {
        z-index: 9999 !important;
    }

    .sidebar {
        z-index: 10000 !important;
    }
}