/**
 * Responsive & cross-device fixes
 * Mobile (320+), Tablet (768+), Laptop (1024+), Desktop (1280+)
 * iOS safe-area, touch targets, overflow fixes
 */

/* ========== iOS & touch ========== */
@supports (padding: max(0px)) {
    :root {
        --safe-area-inset-top: env(safe-area-inset-top, 0px);
        --safe-area-inset-right: env(safe-area-inset-right, 0px);
        --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
        --safe-area-inset-left: env(safe-area-inset-left, 0px);
    }
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}
@media (pointer: coarse) {
    .btn:not(.btn-sm),
    .upload-btn,
    .hero-cta,
    .dataset-share-btn {
        min-height: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }
    .tab-btn { padding: 10px 14px; }
    .nav-link { padding: 10px 14px; }
}

/* ========== Containers ========== */
.container {
    width: 100%;
    max-width: 100%;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}
@media (min-width: 640px) {
    .container { padding-left: 24px; padding-right: 24px; }
}
@media (min-width: 1024px) {
    .container { max-width: 1200px; margin-left: auto; margin-right: auto; padding-left: 32px; padding-right: 32px; }
}
@media (min-width: 1280px) {
    .container { max-width: 1280px; padding-left: 40px; padding-right: 40px; }
}

/* ========== Tables: horizontal scroll on small screens ========== */
.table-container,
.data-table-section .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
}
@media (min-width: 640px) {
    .table-container,
    .data-table-section .table-container {
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
    }
}
.table-container table,
.comprehensive-table {
    min-width: 500px;
}

/* ========== Category tabs: one-row horizontal scroll on phone, wrap on tablet+ ========== */
.category-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-start;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    margin: 15px -16px 0;
    padding-left: 16px;
    padding-right: 16px;
    scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar {
    display: none;
}
@media (min-width: 640px) {
    .category-tabs {
        flex-wrap: wrap;
        justify-content: center;
        margin: 15px 0 0;
        padding-left: 0;
        padding-right: 0;
    }
}
.tab-btn {
    flex: 0 0 auto;
    padding: 10px 14px;
    font-size: 14px;
    white-space: nowrap;
}
@media (min-width: 768px) {
    .tab-btn { padding: 10px 18px; font-size: 15px; }
}

/* ========== Map layout: stack on mobile/tablet ========== */
.map-layout-container {
    flex-wrap: wrap;
}
@media (max-width: 1023px) {
    .map-layout-container {
        flex-direction: column;
        gap: 16px;
    }
    .map-column {
        flex: 0 0 100%;
        width: 100%;
    }
    .results-column {
        flex: 0 0 100%;
        width: 100%;
    }
    .results-panel {
        position: static;
        max-height: none;
    }
}
@media (max-width: 767px) {
    .map-section {
        padding: 16px;
        margin-left: -16px;
        margin-right: -16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .map-container,
    .map-container1 {
        min-height: 280px;
        height: 50vmin;
        max-height: 400px;
    }
    .state-selector-bar .container {
        padding-left: 16px;
        padding-right: 16px;
    }
    .state-selector-content {
        flex-wrap: wrap;
        gap: 10px;
    }
    .state-select,
    .year-filter-inline select {
        min-width: 120px;
    }
}

/* ========== Dataset cards: full width on small screens ========== */
.datasets-list-health,
.datasets-list-education,
.datasets-list-governance,
.datasets-list-infrastructure,
.datasets-list-others,
.datasets-list-governance {
    display: grid;
    gap: 20px;
}
@media (max-width: 639px) {
    .datasets-list-health .dataset-card-with-image,
    .datasets-list-education .dataset-card-with-image,
    .datasets-list-governance .dataset-card-with-image,
    .datasets-list-infrastructure .dataset-card-with-image,
    .datasets-list-others .dataset-card-with-image {
        flex-direction: column;
    }
    .dataset-card-image,
    .dataset-card-image-title {
        width: 100%;
        min-height: 140px;
    }
    .dataset-card-body {
        padding: 16px 14px;
        padding-right: 16px;
    }
    .dataset-actions {
        flex-wrap: wrap;
        gap: 10px;
    }
    .dataset-share .dataset-share-btn {
        min-width: 44px;
        min-height: 44px;
    }
}
@media (min-width: 640px) {
    .datasets-list-health,
    .datasets-list-education,
    .datasets-list-governance,
    .datasets-list-infrastructure,
    .datasets-list-others {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }
}
@media (min-width: 1024px) {
    .datasets-list-health,
    .datasets-list-education,
    .datasets-list-governance,
    .datasets-list-infrastructure,
    .datasets-list-others {
        grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    }
}

/* ========== Page headers ========== */
.page-header h1 {
    word-wrap: break-word;
    font-size: clamp(1.5rem, 5vw, 2rem);
}
@media (max-width: 767px) {
    .page-header {
        padding-right: 0;
    }
    .page-header p {
        font-size: 14px;
    }
}

/* ========== Search & data search section ========== */
.data-search-section,
.search-box {
    width: 100%;
}
@media (max-width: 767px) {
    .search-box {
        flex-wrap: wrap;
    }
    .search-input-large,
    .search-input {
        min-width: 0;
        width: 100%;
    }
    .btn-primary {
        width: 100%;
        min-height: 44px;
    }
}

/* ========== Admin dashboard ========== */
.admin-category-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 8px;
}
.admin-category-nav a {
    flex: 0 0 auto;
    white-space: nowrap;
}
@media (max-width: 1023px) {
    .upload-sections {
        grid-template-columns: 1fr !important;
    }
    .upload-card {
        min-width: 0;
    }
    .upload-card-header h2 {
        font-size: 16px;
        line-height: 1.3;
    }
}
@media (max-width: 767px) {
    .upload-category-divider,
    .upload-category-subdivider {
        font-size: 0.95rem;
        padding-left: 12px;
        padding-right: 12px;
    }
    .upload-card-body {
        padding: 16px;
    }
    .upload-description {
        font-size: 14px;
    }
    .upload-actions {
        flex-direction: column;
    }
    .upload-btn {
        width: 100%;
        min-height: 44px;
        justify-content: center;
    }
}

/* ========== Tamil Nadu district / state-wise ========== */
@media (max-width: 767px) {
    .state-wise-main {
        padding: 16px 0;
    }
    .summary-stats .stats-grid {
        grid-template-columns: 1fr;
    }
    .summary-card {
        padding: 14px;
    }
    .data-info-panel {
        margin-bottom: 12px;
    }
    /* Match state-wise.css mobile title sizing when both sheets load */
    .data-info-panel .info-header h3 {
        font-size: 18px;
        line-height: 1.35;
        padding-left: 32px;
        padding-right: 32px;
    }
}
@media (max-width: 479px) {
    .map-container,
    .map-container1 {
        height: 260px;
        min-height: 260px;
    }
}

/* Tamil Nadu district map (tamilnadu-districts.css) */
.map-chart-section {
    width: 100%;
    overflow: hidden;
}
@media (max-width: 1023px) {
    .map-container-tn {
        height: 320px;
        min-height: 280px;
    }
    .chart-container-tn {
        height: 280px;
    }
}
@media (max-width: 767px) {
    .map-container-tn {
        height: 300px;
        min-height: 260px;
    }
}
@media (max-width: 479px) {
    .map-container-tn {
        height: 260px;
        min-height: 240px;
    }
}

/* ========== Landing: hero & cards ========== */
@media (max-width: 767px) {
    .landing-hero {
        padding-left: 16px;
        padding-right: 16px;
    }
    .hero-title-main {
        font-size: clamp(32px, 8vw, 56px);
    }
    .hero-title-secondary {
        font-size: clamp(24px, 6vw, 40px);
    }
    .landing-cards-section .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}
@media (max-width: 479px) {
    .hero-title-main {
        font-size: 40px;
    }
    .hero-title-secondary {
        font-size: 22px;
    }
    .hero-cta {
        /* width: 100%; */
        min-height: 48px;
    }
}

/* ========== Header/body safe area (iOS notch) ========== */
.landing-header .container {
    padding-top: max(0, env(safe-area-inset-top));
}

/* ========== Footer safe area (iOS home indicator) ========== */
.landing-page .footer,
.footer {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* ========== Fix overflow on body/html ========== */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ========== Main content min height for short viewports ========== */
.main-content {
    min-height: 50vh;
}
