/* Mobile-only styles - does not affect desktop */

/* Tablets and below (768px) */
@media (max-width: 768px) {
    body {
        padding: 10px;
        overflow-x: hidden;
    }
    
    .feed-container {
        overflow-x: hidden;
    }
    
    .feed-header {
        padding: 25px 15px;
    }
    
    .feed-header h1 {
        font-size: 1.5rem;
    }
    
    .feed-header .flag-icon {
        height: 24px;
        max-width: 36px;
    }
    
    .feed-header p {
        font-size: 0.9rem;
    }
    
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px 8px;
        padding: 12px 10px;
    }
    
    /* Hide Villages stat on mobile */
    .stat-item:nth-child(4) {
        display: none;
    }
    
    /* Reorder stats: Profiles, Ethnicities, Y-DNA, mtDNA */
    .stat-item:nth-child(1) { order: 1; }
    .stat-item:nth-child(5) { order: 2; }
    .stat-item:nth-child(2) { order: 3; }
    .stat-item:nth-child(3) { order: 4; }
    
    .stat-number {
        font-size: 1.3rem;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .tab-navigation {
        gap: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tab-btn {
        padding: 14px 12px;
        min-width: 60px;
    }
    
    .tab-label {
        display: none;
    }
    
    .tab-icon {
        font-size: 1.4rem;
    }
    
    .filter-bar {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
        background: linear-gradient(135deg, var(--bg-white) 0%, var(--bg-light) 100%);
    }
    
    .filter-row {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .search-container {
        max-width: none;
        width: 100%;
        order: 1;
    }
    
    .search-input {
        width: 100%;
        font-size: 0.95rem;
        padding: 12px 45px 12px 18px;
        height: 48px;
        border: 2px solid var(--border-medium);
        border-radius: 24px;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        transition: all 0.3s ease;
    }
    
    .search-input:focus {
        border-color: var(--male-color);
        box-shadow: 0 4px 12px rgba(71, 117, 113, 0.2);
        transform: translateY(-1px);
    }
    
    .filter-dropdowns {
        flex-direction: column;
        width: 100%;
        gap: 10px;
        order: 2;
    }
    
    .custom-dropdown {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        position: relative;
    }

    /* Boost open panel above sibling dropdowns below it */
    .custom-options.active {
        z-index: 200;
    }
    
    .custom-select,
    .filter-select {
        min-width: 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        font-size: 0.95rem;
        padding: 12px 16px;
        height: 48px;
        border: 2px solid var(--border-medium);
        border-radius: 24px;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        transition: all 0.3s ease;
        font-weight: 500;
    }
    
    .custom-select:focus,
    .custom-select:active,
    .filter-select:focus,
    .filter-select:active {
        border-color: var(--male-color);
        box-shadow: 0 4px 12px rgba(71, 117, 113, 0.2);
        transform: translateY(-1px);
        outline: none;
    }
    
    .sort-section {
        width: 100%;
        order: 5;
        display: flex;
        align-items: center;
        gap: 10px;
        flex-direction: row;
        margin-top: 4px;
    }
    
    .sort-label {
        display: none !important;
    }
    
    .sort-select {
        width: 100%;
        font-size: 0.95rem;
        padding: 12px 16px;
        height: 48px;
        border: 2px solid var(--border-medium);
        border-radius: 24px;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        transition: all 0.3s ease;
        font-weight: 500;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23374151' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 16px center;
        padding-right: 40px;
    }
    
    .sort-select:focus,
    .sort-select:active {
        border-color: var(--male-color);
        box-shadow: 0 4px 12px rgba(71, 117, 113, 0.2);
        transform: translateY(-1px);
        outline: none;
    }
    
    /* Dropdown menu improvements for mobile */
    .custom-options {
        max-height: 450px !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 8px !important;
        left: 0 !important;
        right: 0 !important;
        position: absolute !important;
    }
    
    .location-options,
    .clade-options {
        max-height: 450px !important;
        width: calc(100% - 20px) !important;
        max-width: calc(100% - 20px) !important;
        min-width: calc(100% - 20px) !important;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 8px !important;
        left: 10px !important;
        right: 10px !important;
        position: absolute !important;
    }
    
    .location-columns {
        display: grid !important;
        grid-template-columns: 0.8fr 1.25fr !important;
        gap: 5px !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .location-column {
        display: flex !important;
        flex-direction: column !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    
    .location-column-header {
        font-size: 0.75rem !important;
        padding: 6px 8px !important;
        margin-bottom: 6px !important;
        font-weight: 700 !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* Clade columns for mobile */
    .clade-columns {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .clade-column {
        display: flex !important;
        flex-direction: column !important;
        min-width: 0 !important;
    }
    
    .clade-column-header {
        font-size: 0.75rem !important;
        padding: 6px 8px !important;
        margin-bottom: 6px !important;
        font-weight: 700 !important;
        text-align: center !important;
    }
    
    /* Ethnicity options — actual rendered classes from main.js */
    .custom-options {
        flex-direction: column !important;
        gap: 4px !important;
    }

    /* Only switch to flex when the panel is actually open */
    .custom-options.active {
        display: flex !important;
    }
    
    .custom-option:not(.sub-option),
    .custom-option.sub-option.visible {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 12px 14px !important;
        min-height: 52px !important;
        border-radius: 12px !important;
        transition: all 0.2s ease !important;
    }

    /* Indent sub-options to visually sit under their parent */
    .custom-option.sub-option.visible {
        padding-left: 44px !important;
    }

    /* Keep hidden sub-options hidden on mobile */
    .custom-option.sub-option:not(.visible) {
        display: none !important;
    }
    
    .custom-option:hover,
    .custom-option:active {
        background: var(--bg-light) !important;
    }
    
    .option-flag {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        object-fit: cover !important;
        border-radius: 6px !important;
    }
    
    .option-text {
        flex: 1 !important;
        font-size: 1rem !important;
        font-weight: 500 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .dropdown-item,
    .filter-option,
    .location-option {
        padding: 10px 8px !important;
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.85rem !important;
        border-radius: 8px;
        margin-bottom: 4px;
        margin-left: 0 !important;
        margin-right: 0 !important;
        transition: all 0.2s ease;
        white-space: normal !important;
        word-wrap: break-word !important;
        overflow: hidden !important;
    }
    
    /* Reduce spacing for location options specifically */
    .location-options .location-option {
        padding: 5px 8px !important;
        min-height: 38px !important;
        margin-bottom: 2px !important;
    }
    
    .dropdown-item label,
    .filter-option label {
        flex: 1 !important;
        min-width: 0 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        line-height: 1.3 !important;
    }
    
    .dropdown-item:hover,
    .dropdown-item:active,
    .filter-option:hover,
    .filter-option:active {
        background: var(--bg-light) !important;
        transform: translateX(2px);
    }
    
    /* Checkboxes for mobile */
    input[type="checkbox"] {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        cursor: pointer;
        border-radius: 6px;
        flex-shrink: 0 !important;
    }
    
    /* Flag icons in dropdowns */
    .flag-icon-small {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        object-fit: cover;
        border-radius: 4px;
        flex-shrink: 0 !important;
    }
    
    /* Reset button */
    .reset-btn {
        padding: 10px 18px !important;
        font-size: 0.95rem !important;
        min-height: 44px;
        border-radius: 22px !important;
        font-weight: 600 !important;
        width: 100% !important;
        margin-bottom: 8px !important;
    }
    
    /* Column headers in clade dropdown */
    .clade-column-header {
        font-size: 0.8rem !important;
        padding: 8px 12px !important;
        margin-bottom: 6px !important;
        font-weight: 700 !important;
    }
    
    .clade-columns {
        gap: 12px !important;
    }
    
    .map-view {
        height: 400px;
    }
    
    .map-tabs {
        gap: 6px;
        padding: 10px;
        justify-content: center;
    }
    
    .map-tab-btn {
        font-size: 0.8rem;
        padding: 6px 12px;
    }
    
    .stats-container,
    .about-container {
        padding: 20px 10px;
        overflow-x: hidden;
    }
    
    .stats-container h2 {
        font-size: 1.2rem !important;
        white-space: nowrap !important;
    }
    
    .about-container .desktop-title {
        display: none;
    }
    
    .about-container .mobile-title {
        display: inline;
    }
    
    .support-link {
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        padding: 10px 12px !important;
    }
    
    .support-link span {
        white-space: nowrap !important;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
        overflow: hidden;
    }
    
    .chart-card {
        padding: 12px;
        overflow: hidden;
    }
    
    .chart-canvas-wrap {
        max-width: 100%;
        width: 100%;
        overflow: hidden;
    }
    
    .chart-canvas-wrap canvas {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Mobile card improvements */
    .heritage-result {
        padding: 12px 15px;
        margin-bottom: 8px;
        grid-template-columns: 40px 1fr 30px;
        min-height: 140px;
    }
    
    .summary-avatar {
        width: 36px;
        height: 36px;
        align-self: flex-start;
        margin-top: 4px;
    }
    
    .summary-content {
        display: flex;
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
    }
    
    .summary-name {
        font-size: 0.95rem;
        font-weight: 600;
        width: 100%;
        margin-bottom: 2px;
    }
    
    .summary-info {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
        width: 100%;
        font-size: 0.8rem;
    }
    
    /* Village and Ethnicity as full width */
    .summary-item {
        display: flex;
        gap: 6px;
    }
    
    /* Village and Ethnicity take full width */
    .summary-item:nth-child(1),  /* Village */
    .summary-item:nth-child(2) { /* Ethnicity */
        width: 100%;
        flex: 0 0 100%;
    }
    
    /* Y-DNA and mtDNA on same line - use calc to account for gap */
    .summary-item:nth-child(3),  /* Y-DNA */
    .summary-item:nth-child(4) { /* mtDNA */
        width: calc(50% - 2px);
        flex: 0 0 calc(50% - 2px);
    }
    
    /* Hide date on mobile */
    .summary-item:nth-child(5) {
        display: none !important;
    }
    
    .summary-label {
        font-size: 0.75rem;
    }
    
    .summary-value {
        font-size: 0.8rem;
    }
    
    .expand-icon {
        font-size: 1.1rem;
        align-self: flex-start;
        margin-top: 4px;
    }
    
    /* Expanded card on mobile */
    .heritage-result.expanded {
        padding: 15px;
        min-height: auto;
        max-height: none;
    }
    
    /* Reorganize expanded card layout for mobile */
    .result-header {
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    .family-info {
        display: grid;
        grid-template-columns: 60px 1fr;
        grid-template-rows: auto auto auto auto auto;
        gap: 4px;
        align-items: start;
        padding: 0;
        margin: 0;
        width: 100%;
    }
    
    .family-avatar {
        grid-row: 1;
        grid-column: 1;
        width: 50px;
        height: 50px;
        align-self: start;
        justify-self: start;
        margin: 0;
        padding: 0;
    }
    
    .family-names {
        grid-column: 2;
        grid-row: 1;
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding-top: 4px;
        padding-left: 0;
        max-width: 100%;
    }
    
    .family-name-english {
        font-size: 1.1rem;
        font-weight: 600;
        line-height: 1.3;
    }
    
    .family-name-other {
        font-size: 0.75rem;
        opacity: 0.8;
        line-height: 1.2;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .family-name-russian,
    .family-name-native {
        font-size: 0.75rem;
    }
    
    .family-name-russian:not(:empty)::after {
        content: " ";
        margin: 0 2px;
    }
    
    .basic-info {
        grid-column: 1 / 3;
        grid-row: 2;
        display: flex;
        flex-direction: column;
        gap: 3px;
        font-size: 0.9rem;
        padding-left: 0;
        margin-top: 18px;
        margin-bottom: 0;
        margin-left: 0;
        align-items: flex-start;
    }
    
    .info-item {
        display: flex;
        gap: 6px;
        align-self: flex-start;
        width: auto;
        justify-content: flex-start;
        margin-left: 0;
        margin-right: auto;
    }
    
    .info-label {
        font-weight: 600;
    }
    
    .test-id-date {
        grid-column: 1 / 3;
        grid-row: 3;
        display: flex;
        gap: 15px;
        font-size: 0.85rem;
        padding-top: 2px;
        margin-top: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Compact genetic data sections */
    .genetic-data {
        gap: 10px;
        display: flex;
        flex-direction: column;
        margin-top: 10px;
    }
    
    .haplogroup-section {
        padding: 8px 10px;
    }
    
    .haplogroup-title {
        font-size: 0.9rem;
        margin-bottom: 6px;
        font-weight: 600;
    }
    
    .genetic-marker {
        display: grid;
        grid-template-columns: 100px 1fr;
        gap: 8px;
        padding: 3px 0 3px 8px;
        font-size: 0.8rem;
    }
    
    .marker-label {
        font-weight: 500;
        opacity: 0.8;
    }
    
    .marker-value {
        font-weight: 600;
    }
    
    /* Ensure expanded cards show full content */
    .result-details {
        max-height: none !important;
        overflow: visible !important;
    }
}

/* Small phones (480px and below) */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }
    
    .feed-header {
        padding: 20px 10px;
    }
    
    .feed-header h1 {
        font-size: 1.25rem;
    }
    
    .feed-header .flag-icon {
        height: 20px;
        max-width: 30px;
    }
    
    .stats-bar {
        gap: 8px 5px;
        padding: 10px 8px;
    }
    
    .stat-number {
        font-size: 1.1rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .tab-btn {
        padding: 12px 8px;
        min-width: 55px;
    }
    
    .tab-icon {
        font-size: 1.3rem;
    }
    
    .filter-bar {
        padding: 12px;
    }
    
    .map-view {
        height: 300px;
    }
    
    .map-tab-btn {
        font-size: 0.75rem;
        padding: 5px 10px;
    }
    
    .heritage-result {
        padding: 10px 12px;
    }
    
    .summary-avatar {
        width: 32px;
        height: 32px;
    }
    
    .summary-name {
        font-size: 0.9rem;
    }
    
    .summary-info {
        gap: 6px 10px;
    }
    
    .summary-label {
        font-size: 0.7rem;
    }
    
    .summary-value {
        font-size: 0.75rem;
    }
    
    .result-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .heritage-result.expanded {
        padding: 12px;
    }
    
    .chart-card {
        padding: 12px;
    }
    
    .stats-container,
    .about-container {
        padding: 15px 10px;
    }
}
