/* Mobile-First Responsive Design */

/* Hide mobile-only elements by default (desktop) */
.mobile-nav-bar,
.mobile-back-btn,
.mobile-filters-overlay {
    display: none !important;
}

/* ============================================
   MOBILE PHONES (< 576px)
   ============================================ */
@media (max-width: 575.98px) {
    /* === HEADER === */
    .dashboard-header {
        padding: 0.5rem 0 1rem 0 !important;
        min-height: auto !important;
    }
    .prism-logo {
        font-size: 1.2rem !important;
    }
    .prism-subtitle,
    .header-nav {
        display: none !important;
    }
    .pm-super {
        width: 45px !important;
        height: 36px !important;
        margin-top: -5px !important;
    }
    .pm-super::before {
        border-left: 22px solid transparent !important;
        border-right: 22px solid transparent !important;
        border-top: 36px solid #20558a !important;
    }
    .pm-super span {
        top: 8px !important;
        font-size: 0.55rem !important;
    }
    .prism-text {
        font-size: 1.2rem !important;
        margin-left: 0 !important;
    }

    /* === BOTTOM NAVIGATION BAR === */
    .mobile-nav-bar {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 60px !important;
        background: #fff !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.15) !important;
        z-index: 1050 !important;
        justify-content: space-around !important;
        align-items: center !important;
        border-top: 1px solid #e2e8f0 !important;
    }
    .mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-decoration: none !important;
        color: #64748b !important;
        font-size: 0.7rem !important;
        font-weight: 600 !important;
        padding: 8px 12px !important;
        flex: 1 !important;
        height: 100% !important;
    }
    .mobile-nav-item i {
        font-size: 1.4rem !important;
        margin-bottom: 3px !important;
    }
    .mobile-nav-item.active,
    .mobile-nav-item:hover {
        color: #764ba2 !important;
        background: rgba(118, 75, 162, 0.1) !important;
    }
    
    html {
        scroll-behavior: smooth;
        scroll-padding-top: 20px;
    }
    
    /* Sticky nav bar adjustments */
    @media (max-width: 575.98px) {
        .mobile-nav-bar {
            background: rgba(255, 255, 255, 0.95) !important;
            backdrop-filter: blur(8px) !important;
        }
    }
    
    /* Body padding for bottom nav */
    body {
        padding-bottom: 70px !important;
    }

    /* === COMPACT DESKTOP FILTERS ON MOBILE === */
    #filters-section {
        margin-bottom: 1rem !important;
    }
    #filters-section .filters-card-container .stat-card {
        padding: 12px !important;
    }
    #filters-section .filter-row {
        flex-direction: column !important;
        gap: 12px !important;
    }
    #filters-section .filter-column {
        width: 100% !important;
        padding: 0 !important;
        border-right: none !important;
    }
    #filters-section .filter-column h6 {
        font-size: 0.8rem !important;
        margin-bottom: 6px !important;
    }
    #filters-section .form-select,
    #filters-section .form-control {
        padding: 8px 12px !important;
        font-size: 0.9rem !important;
    }
    #filters-section .form-check {
        padding: 6px 6px 6px 32px !important;
        margin-bottom: 4px !important;
    }
    #filters-section .filters-badges-row,
    #filters-section #active-filters-display {
        display: none !important;
    }

    /* === MOBILE FILTER OVERLAY (supplementary, not required) === */
    .mobile-filters-overlay {
        display: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        background: #ffffff !important;
        z-index: 2000 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease-out !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    .mobile-filters-overlay.open {
        transform: translateX(0) !important;
    }
    
    /* Mobile overlay header */
    .mobile-filters-header {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        z-index: 10;
    }
    .mobile-filters-title {
        font-size: 1.25rem;
        font-weight: 700;
    }
    .mobile-filters-close-btn {
        background: rgba(255,255,255,0.2);
        color: #fff;
        border: none;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    /* Mobile overlay content */
    .mobile-filters-content {
        padding: 16px 16px 140px 16px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    /* Compact mobile selects with inline labels */
    .mobile-filter-select {
        width: 100%;
        padding: 14px 40px 14px 16px;
        font-size: 0.95rem;
        border: 2px solid #e2e8f0;
        border-radius: 10px;
        background: #fff;
        color: #1e293b;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 14px center;
    }
    .mobile-filter-select:focus {
        border-color: #764ba2;
        outline: none;
        box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.15);
    }
    
    /* Flag chips row */
    .mobile-filter-flags {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 4px;
    }
    .mobile-flag-chip {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 12px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 20px;
        font-size: 0.85rem;
        color: #475569;
        cursor: pointer;
        transition: all 0.2s;
    }
    .mobile-flag-chip:has(input:checked) {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #fff;
        border-color: transparent;
    }
    .mobile-flag-chip input[type="checkbox"] {
        display: none;
    }
    
    /* Mobile apply button */
    .mobile-filters-apply-btn {
        position: fixed;
        bottom: 70px;
        left: 16px;
        right: 16px;
        padding: 16px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #fff;
        border: none;
        border-radius: 12px;
        font-size: 1.1rem;
        font-weight: 700;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
        z-index: 2001;
        display: none;
    }
    .mobile-filters-overlay.open .mobile-filters-apply-btn {
        display: block;
    }

    /* === TREATMENT CARDS === */
    .treatment-cards-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .parallelogram-card {
        transform: skewX(-2deg) !important;
        padding: 10px !important;
        min-height: auto !important;
    }
    .parallelogram-card .card-content {
        transform: skewX(2deg) !important;
    }
    .parallelogram-card .treatment-name {
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        line-height: 1.2 !important;
        margin-bottom: 5px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }
    .parallelogram-card .treatment-count,
    .parallelogram-card-redesigned .treatment-count {
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 4px !important;
    }
    .parallelogram-card .badge,
    .parallelogram-card-redesigned .badge {
        font-size: 0.65rem !important;
        padding: 3px 6px !important;
    }
    .parallelogram-card .save-treatment-btn {
        display: none !important;
    }

    /* === HIDE ABSTRACT PANEL ON MOBILE === */
    .abstract-panel {
        display: none !important;
    }

    /* === GMAIL-STYLE ARTICLES LIST === */
    .articles-nav-panel {
        display: none !important;
    }
    .articles-container {
        flex-direction: column !important;
    }
    .articles-list {
        width: 100% !important;
        max-width: 100% !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        overflow: hidden !important;
    }
    .article-row {
        padding: 14px 12px !important;
        border-bottom: 1px solid #f1f5f9 !important;
        background: #fff !important;
        cursor: pointer !important;
    }
    .article-row:last-child {
        border-bottom: none !important;
    }
    .article-row:active {
        background: #f8fafc !important;
    }
    .article-row.expanded {
        background: linear-gradient(to bottom, #f8fafc, #fff) !important;
    }
    .article-title {
        font-size: 0.95rem !important;
        font-weight: 600 !important;
        line-height: 1.4 !important;
        color: #1e293b !important;
        margin-bottom: 6px !important;
    }
    .article-meta-row {
        font-size: 0.75rem !important;
        color: #64748b !important;
    }
    .article-meta-row .badge {
        font-size: 0.6rem !important;
        padding: 3px 6px !important;
        border-radius: 4px !important;
    }
    
    /* Inline abstract expansion on mobile */
    .article-row .mobile-abstract {
        display: none;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #e2e8f0;
        font-size: 0.85rem;
        line-height: 1.6;
        color: #475569;
    }
    .article-row.expanded .mobile-abstract {
        display: block !important;
    }
    
    /* Hide search bar complexity on mobile */
    .articles-section #articles-highly-effective-btn {
        display: none !important;
    }
    .articles-section .input-group {
        flex: 1 !important;
    }

    /* === GENERAL === */
    .stat-card,
    .prism-card {
        padding: 12px !important;
        clip-path: none !important;
        border-radius: 12px !important;
    }
    .stat-number {
        font-size: 1.4rem !important;
    }
    .chart-container {
        height: auto !important;
        min-height: 550px !important;
        padding: 12px !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .chart-container .row {
        flex-direction: column !important;
        margin: 0 !important;
    }
    
    .chart-container .col-md-7 {
        height: 250px !important;
        width: 100% !important;
        margin-bottom: 1rem !important;
    }
    
    .chart-container .col-md-5 {
        width: 100% !important;
        padding: 0 !important;
    }
    
    #trending-legend {
        margin-top: 0 !important;
        padding: 5px !important;
    }
    
    #trending-legend h6 {
        font-size: 0.85rem !important;
        margin-bottom: 8px !important;
    }
    
    .legend-item {
        font-size: 0.75rem !important;
        padding: 4px 0 !important;
    }
    h4, h5 {
        font-size: 1rem !important;
    }
    .prism-divider {
        display: none !important;
    }
    
    /* Section titles */
    .mesh-title {
        font-size: 1.1rem !important;
    }
}

/* ============================================
   SMALL TABLETS (576px - 767px)
   ============================================ */
@media (min-width: 576px) and (max-width: 767.98px) {
    .treatment-cards-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .filter-column {
        min-width: 48% !important;
        flex: 0 0 48% !important;
    }
}

/* ============================================
   TABLETS (768px - 991px)
   ============================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
    .treatment-cards-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .filter-column {
        min-width: 30% !important;
        flex: 1 !important;
    }
}

/* ============================================
   DESKTOP (992px+)
   ============================================ */
@media (min-width: 992px) {
    .treatment-cards-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (min-width: 1200px) {
    .treatment-cards-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .article-row:hover {
        background: inherit !important;
    }
    .article-row.active {
        background: linear-gradient(135deg, #e0e7ff 0%, #fce7f3 100%) !important;
    }
    .form-check-input {
        width: 22px !important;
        height: 22px !important;
    }
    .btn {
        min-height: 44px !important;
    }
    
    /* Disable hover effects on touch */
    .parallelogram-card:hover {
        transform: skewX(-2deg) !important;
    }
}
