/**
 * CRC Warriors - Responsive Fixes
 * Comprehensive mobile/tablet optimizations
 * Version: 1.0 - December 2025
 */

/* ============================================
   BASE RESPONSIVE UTILITIES
   ============================================ */

/* Prevent horizontal overflow */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Responsive tables */
.table-responsive-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but keep functionality */
.table-responsive-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-responsive-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Make all tables scrollable on mobile */
@media (max-width: 991.98px) {
    table:not(.no-responsive) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table:not(.no-responsive) thead,
    table:not(.no-responsive) tbody,
    table:not(.no-responsive) tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
}

/* ============================================
   NAVBAR RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .navbar-brand {
        font-size: 1.1rem;
    }
    
    .navbar-nav {
        padding: 1rem 0;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .navbar-nav .dropdown-menu {
        border: none;
        box-shadow: none;
        padding-left: 1rem;
        background: transparent;
    }
    
    /* User dropdown in mobile */
    .navbar .dropdown-menu-end {
        position: static !important;
        transform: none !important;
        width: 100%;
        margin-top: 0.5rem;
    }
    
    .notification-menu {
        width: 100% !important;
        max-width: 100% !important;
        position: static !important;
        transform: none !important;
    }
}

@media (max-width: 575.98px) {
    .navbar-brand span {
        display: none;
    }
    
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
    }
}

/* ============================================
   HERO SECTION RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .hero-section {
        min-height: 80vh;
        padding: 3rem 0;
        background-attachment: scroll; /* Better mobile performance */
    }
    
    .hero-section h1 {
        font-size: 2rem;
    }
    
    .hero-section .lead {
        font-size: 1rem;
    }
    
    .hero-section .btn {
        display: block;
        width: 100%;
        margin-bottom: 0.75rem;
    }
    
    .hero-section .btn + .btn {
        margin-left: 0;
    }
}

@media (max-width: 575.98px) {
    .hero-section {
        min-height: 70vh;
        padding: 2rem 0;
    }
    
    .hero-section h1 {
        font-size: 1.75rem;
    }
}

/* ============================================
   CARDS RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1.25rem;
    }
    
    /* Stack card actions */
    .card-footer .btn-group,
    .card-footer .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .card-footer .btn {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    .card-body {
        padding: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
}

/* ============================================
   FORMS RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents iOS zoom */
    }
    
    /* Stack form groups */
    .row.g-3 > [class*="col-md"],
    .row.g-3 > [class*="col-lg"] {
        margin-bottom: 0.75rem;
    }
    
    /* Full width inputs */
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group .form-control {
        flex: 1 1 100%;
        margin-bottom: 0.5rem;
    }
    
    .input-group .btn {
        flex: 1 1 100%;
    }
}

@media (max-width: 575.98px) {
    .form-label {
        font-size: 0.9rem;
    }
    
    /* Checkbox/radio spacing */
    .form-check {
        padding-left: 1.75rem;
    }
}

/* ============================================
   BUTTONS RESPONSIVE
   ============================================ */

@media (max-width: 575.98px) {
    /* Stack button groups */
    .btn-group:not(.btn-group-sm) {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group:not(.btn-group-sm) .btn {
        border-radius: 0.375rem !important;
        margin-bottom: 0.25rem;
    }
    
    /* Larger touch targets */
    .btn {
        padding: 0.625rem 1rem;
        min-height: 44px;
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        min-height: 38px;
    }
}

/* ============================================
   MODALS RESPONSIVE
   ============================================ */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.75rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ============================================
   SIDEBAR/DASHBOARD RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        height: 100vh;
        width: 280px;
        z-index: 1050;
        transition: left 0.3s ease;
        background: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        display: none;
    }
    
    .sidebar-backdrop.show {
        display: block;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* ============================================
   CLINICAL TRIALS PAGE RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    /* Filters sidebar */
    .trials-filters {
        position: fixed;
        top: 0;
        left: -100%;
        width: 100%;
        max-width: 320px;
        height: 100vh;
        z-index: 1050;
        background: white;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding: 1rem;
    }
    
    .trials-filters.show {
        left: 0;
    }
    
    /* Filter toggle button */
    .filter-toggle-btn {
        display: flex !important;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1030;
        border-radius: 50px;
        padding: 0.75rem 1.25rem;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    }
    
    /* Trial cards */
    .trial-card {
        padding: 1rem;
    }
    
    .trial-card .badge {
        font-size: 0.7rem;
    }
    
    /* Trial table */
    .trials-table {
        font-size: 0.85rem;
    }
    
    .trials-table th,
    .trials-table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
}

@media (max-width: 575.98px) {
    .trials-filters {
        max-width: 100%;
    }
}

/* ============================================
   PROFILE PAGE RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-avatar {
        margin-bottom: 1rem;
    }
    
    .profile-info {
        text-align: center;
    }
    
    .profile-stats {
        justify-content: center;
        flex-wrap: wrap;
        gap: 1rem;
    }
    
    .profile-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 575.98px) {
    .profile-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .profile-tabs .nav-item {
        flex-shrink: 0;
    }
}

/* ============================================
   MEDICATIONS PAGE RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .medication-grid {
        grid-template-columns: 1fr;
    }
    
    .medication-card {
        padding: 1rem;
    }
    
    .medication-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ============================================
   NEWS/BLOG RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    .news-grid {
        grid-template-columns: 1fr;
    }
    
    .article-content {
        padding: 1rem;
    }
    
    .article-sidebar {
        margin-top: 2rem;
    }
}

/* ============================================
   FOOTER RESPONSIVE
   ============================================ */

@media (max-width: 991.98px) {
    footer {
        padding: 2rem 0 1rem;
    }
    
    footer .row > div {
        margin-bottom: 1.5rem;
    }
    
    footer h5 {
        margin-bottom: 0.75rem;
    }
    
    footer ul {
        margin-bottom: 0;
    }
}

@media (max-width: 575.98px) {
    footer {
        text-align: center;
    }
    
    footer .social-links {
        justify-content: center;
    }
    
    .footer-bottom {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ============================================
   UTILITY RESPONSIVE CLASSES
   ============================================ */

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

/* Show only on mobile */
@media (min-width: 768px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* Full width on mobile */
@media (max-width: 575.98px) {
    .w-100-mobile {
        width: 100% !important;
    }
}

/* Text alignment on mobile */
@media (max-width: 575.98px) {
    .text-center-mobile {
        text-align: center !important;
    }
}

/* Spacing adjustments for mobile */
@media (max-width: 575.98px) {
    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
    
    .py-4 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    
    .mb-5 {
        margin-bottom: 2rem !important;
    }
    
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) {
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    .card:hover {
        transform: none;
        box-shadow: inherit;
    }
    
    /* Larger touch targets */
    a, button, .clickable {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .navbar,
    .sidebar,
    footer,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
