/* Tablet */
@media (max-width: 1024px) {
    .header__title {
        font-size: 2rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Filtered Stats - Tablet */
    .filtered-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .filtered-stat-card__value {
        font-size: 1.35rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    .header {
        padding: 1.5rem 0;
    }

    .header__title {
        font-size: 1.5rem;
    }

    .header__subtitle {
        font-size: 0.95rem;
    }

    .section-title {
        font-size: 1.3rem;
    }

    /* Filtered Stats - Mobile */
    .filtered-stats {
        padding: 1rem 0;
    }

    .filtered-stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .filtered-stat-card {
        padding: 0.875rem;
    }

    .filtered-stat-card__icon {
        font-size: 1.75rem;
    }

    .filtered-stat-card__label {
        font-size: 0.7rem;
    }

    .filtered-stat-card__value {
        font-size: 1.25rem;
    }

    /* Camp Buttons - Mobile */
    .camp-filters-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .camp-btn {
        padding: 0.875rem;
        font-size: 0.9rem;
    }

    /* Floating Action Buttons - Mobile */
    .floating-actions {
        bottom: 1rem;
        left: 1rem;
        gap: 0.75rem;
    }

    .floating-btn {
        padding: 0.875rem 1.25rem;
        font-size: 0.95rem;
    }

    .floating-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Search Modal - Mobile */
    .search-modal-content {
        width: 95%;
        margin: 2% auto;
    }

    .search-input-field {
        font-size: 1rem;
        padding: 0.875rem;
    }

    /* Filter Modal - Mobile */
    .filter-modal-content {
        width: 95%;
        margin: 2% auto;
        max-width: none;
    }

    .filter-modal-header {
        padding: 1rem;
    }

    .filter-modal-header h2 {
        font-size: 1.25rem;
    }

    .filter-modal-body {
        padding: 1rem;
        gap: 1rem;
    }

    .filter-modal-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-modal-actions .btn {
        width: 100%;
    }

    /* Camp Filters - Mobile */
    .camp-filters {
        flex-direction: column;
        gap: 0.5rem;
    }

    .camp-filter {
        width: 100%;
        padding: 0.75rem 1rem;
    }

    /* Section Header - Mobile */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .section-header .btn {
        width: 100%;
    }

    /* Charts - Mobile */
    .charts {
        padding: 1.5rem 0;
    }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-card {
        padding: 1rem;
    }

    .chart-card h3 {
        font-size: 1rem;
    }

    .chart-card canvas {
        max-height: 250px;
    }

    /* Data Table - Mobile */
    .data-table {
        padding: 1.5rem 0;
    }

    .table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .table-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }

    .table-actions select,
    .table-actions button {
        width: 100%;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }

    .table {
        font-size: 0.8rem;
        min-width: 700px; /* Ensure horizontal scroll */
    }

    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }

    .table .avatar {
        width: 30px;
        height: 30px;
    }

    .table .governor-info {
        gap: 0.5rem;
    }

    .table .governor-name {
        font-size: 0.85rem;
    }

    .table .camp-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }

    .table .delta-inline {
        font-size: 0.75rem;
        display: block;
        margin-top: 2px;
    }

    /* Pagination - Mobile */
    .pagination {
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .pagination__btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-width: 44px; /* Touch target */
        min-height: 44px;
    }

    .pagination__info {
        width: 100%;
        text-align: center;
        margin-top: 0.5rem;
        font-size: 0.85rem;
    }

    /* Governor Modal - Mobile */
    .modal-content {
        width: 95%;
        padding: 1rem;
        margin: 5% auto;
        max-height: 85vh;
        overflow-y: auto;
    }

    .modal-content h2 {
        font-size: 1.3rem;
    }

    .modal-content img {
        width: 100px !important;
        height: 100px !important;
    }

    .modal-content .stat-card {
        padding: 1rem;
    }

    .modal-content .stat-card__value {
        font-size: 1.3rem;
    }

    .modal-content .stat-card__label {
        font-size: 0.8rem;
    }

    .modal-close {
        font-size: 32px;
    }

    /* Touch Targets */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
    }

    .filter-input,
    .filter-select {
        min-height: 44px;
        padding: 0.75rem;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .header__title {
        font-size: 1.25rem;
    }

    .header__subtitle {
        font-size: 0.85rem;
    }

    /* Filtered Stats - Small Mobile */
    .filtered-stat-card {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .filtered-stat-card__icon {
        font-size: 1.5rem;
    }

    .filtered-stat-card__label {
        font-size: 0.65rem;
    }

    .filtered-stat-card__value {
        font-size: 1.1rem;
    }

    /* Camp Buttons - Small Mobile */
    .camp-btn {
        padding: 0.75rem;
        font-size: 0.85rem;
    }

    /* Floating Buttons - Small Mobile */
    .floating-actions {
        bottom: 0.75rem;
        left: 0.75rem;
        gap: 0.5rem;
    }

    .floating-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    .floating-btn span {
        display: none; /* Show only icon on very small screens */
    }

    .floating-btn {
        padding: 0.875rem;
        border-radius: 50%;
    }

    .search-input-field {
        font-size: 0.95rem;
    }

    /* Section titles */
    .section-title {
        font-size: 1.15rem;
    }

    /* Charts */
    .chart-card h3 {
        font-size: 0.9rem;
    }

    .chart-card canvas {
        max-height: 220px;
    }

    /* Table */
    .table {
        font-size: 0.75rem;
        min-width: 650px;
    }

    .table th,
    .table td {
        padding: 0.6rem 0.4rem;
    }

    .table .avatar {
        width: 28px;
        height: 28px;
    }

    .table .governor-name {
        font-size: 0.8rem;
    }

    .table .camp-badge {
        font-size: 0.65rem;
        padding: 0.15rem 0.5rem;
    }

    /* Pagination */
    .pagination__btn {
        padding: 0.5rem 0.65rem;
        font-size: 0.75rem;
        min-width: 40px;
        min-height: 40px;
    }

    /* Hide page numbers on very small screens, keep prev/next */
    .pagination__btn:not(:first-child):not(:last-child):not(.pagination__info) {
        display: none;
    }

    .pagination__btn.active {
        display: inline-block; /* Show current page */
    }

    /* Modal */
    .modal-content {
        padding: 0.875rem;
        margin: 2% auto;
    }

    .modal-content h2 {
        font-size: 1.15rem;
    }

    .modal-content img {
        width: 80px !important;
        height: 80px !important;
    }

    .modal-content .stat-card__value {
        font-size: 1.1rem;
    }

    .filter-modal-header h2 {
        font-size: 1.1rem;
    }
}

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none;
    }
}

/* Performance optimizations for all mobile devices */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .table tbody tr:hover {
        background: var(--bg-primary);
    }

    /* Better tap highlighting */
    * {
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.1);
    }

    /* Optimize scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent pull-to-refresh while scrolling table */
    .table-container {
        overscroll-behavior: contain;
    }

    /* Larger touch targets for interactive elements */
    a, button, input, select, textarea, [onclick] {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Better click behavior on clickable governor names */
    .governor-name.clickable {
        cursor: pointer;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Landscape mode optimizations for mobile */
@media (max-width: 896px) and (orientation: landscape) {
    .header {
        padding: 1rem 0;
    }

    .header__title {
        font-size: 1.3rem;
    }

    .header__subtitle {
        font-size: 0.9rem;
    }

    .modal-content,
    .filter-modal-content {
        margin: 2% auto;
        max-height: 90vh;
    }

    .floating-actions {
        bottom: 0.75rem;
        left: 0.75rem;
    }

    .floating-btn {
        padding: 0.7rem 1rem;
        font-size: 0.85rem;
    }
}

/* Compare Modal Responsive */
@media (max-width: 768px) {
    .compare-modal-content {
        width: 95%;
        margin: 2% auto;
    }

    .compare-selected-container {
        padding: 0.875rem;
    }

    .compare-chip {
        font-size: 0.8rem;
        padding: 0.4rem 0.65rem;
    }

    /* Hide table, show cards on mobile */
    .compare-results-table {
        display: none;
    }

    .compare-results-cards {
        display: block;
    }

    /* Category breakdown mobile */
    .category-breakdown-section {
        margin-top: 1.5rem;
        padding-top: 1.5rem;
    }

    .category-breakdown-title {
        font-size: 1.2rem;
    }

    .category-cards-title {
        font-size: 1.1rem;
    }

    /* Threshold config mobile */
    .threshold-grid {
        grid-template-columns: 1fr;
    }

    .threshold-grid .threshold-input-group:last-child {
        grid-column: span 1;
    }

    .compare-metric-card {
        padding: 0.875rem;
    }

    .compare-metric-card__header {
        font-size: 1rem;
    }

    .compare-metric-card__item {
        padding: 0.65rem;
    }

    .compare-metric-card__item-value {
        font-size: 1rem;
    }

    .compare-header-actions {
        flex-direction: row;
        gap: 0.5rem;
    }

    #compare-back-btn {
        padding: 0.65rem 1rem;
        font-size: 0.875rem;
    }
}

@media (max-width: 480px) {
    .compare-selected-list {
        gap: 0.4rem;
    }

    .compare-chip {
        font-size: 0.75rem;
        padding: 0.35rem 0.55rem;
    }

    .compare-metric-card__header {
        font-size: 0.95rem;
    }

    .compare-metric-card__item {
        padding: 0.6rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .compare-metric-card__item-value {
        font-size: 0.95rem;
        align-self: flex-end;
    }

    /* Category breakdown small mobile */
    .category-breakdown-section {
        margin-top: 1rem;
        padding-top: 1rem;
    }

    .category-breakdown-title {
        font-size: 1.1rem;
    }

    .category-cards-title {
        font-size: 1rem;
    }

    /* Threshold config mobile */
    .threshold-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .threshold-toggle-btn {
        padding: 0.45rem 0.85rem;
        font-size: 0.8rem;
    }

    .threshold-config {
        padding: 0.875rem;
    }

    .threshold-input-group label {
        font-size: 0.75rem;
    }

    .threshold-input-group input {
        padding: 0.65rem;
        font-size: 0.9rem;
    }

    .threshold-note {
        font-size: 0.75rem;
        padding: 0.65rem;
    }
}
