/* ============================================
   MOBILE OPTIMIZATIONS
   Additional mobile-specific improvements
   ============================================ */

/* ============================================
   1. TOUCH TARGETS - Minimum 44x44px
   ============================================ */

@media (max-width: 768px) {

    /* Ensure all buttons have adequate touch targets */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }

    .btn-sm {
        min-height: 36px;
        padding: 0.5rem 0.75rem;
    }

    /* Navigation links */
    .nav-link,
    .dropdown-item {
        min-height: 44px;
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
    }

    /* Social icons */
    .social-icon {
        min-width: 44px;
        min-height: 44px;
    }

    /* Form controls */
    .form-control,
    .form-select {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        /* Prevent zoom on iOS */
    }

    /* Checkbox and radio larger touch area */
    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
        margin-top: 0.25rem;
    }

    .form-check-label {
        padding-left: 0.5rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ============================================
   2. MODAL IMPROVEMENTS FOR MOBILE
   ============================================ */

@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 8px;
    }

    .modal-header {
        padding: 1rem;
        flex-direction: column;
        align-items: flex-start;
    }

        .modal-header .btn-close {
            position: absolute;
            top: 1rem;
            left: 1rem;
            margin: 0;
        }

    .modal-title {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: 70vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

        .modal-footer .btn {
            width: 100%;
            margin: 0 !important;
        }
}

/* ============================================
   3. IMAGE OPTIMIZATION
   ============================================ */

@media (max-width: 768px) {

    /* Ensure images don't overflow */
    img {
        max-width: 100%;
        height: auto;
    }

    .news-card-img,
    .article-img {
        max-height: 220px;
        object-fit: cover;
        width: 100%;
    }

    .featured-news img {
        max-height: 300px;
        object-fit: cover;
    }

    /* Avatar images */
    .avatar,
    .user-avatar {
        max-width: 50px;
        max-height: 50px;
    }
}

/* ============================================
   4. ARTICLE CONTENT READABILITY
   ============================================ */

@media (max-width: 768px) {
    .article-content {
        font-size: 1.1rem;
        line-height: 1.8;
        padding: 0 0.5rem;
    }

        .article-content p {
            margin-bottom: 1.5rem;
            text-align: justify;
        }

        .article-content h2,
        .article-content h3,
        .article-content h4 {
            margin-top: 2rem;
            margin-bottom: 1rem;
            line-height: 1.4;
        }

        .article-content h2 {
            font-size: 1.5rem;
        }

        .article-content h3 {
            font-size: 1.3rem;
        }

        .article-content ul,
        .article-content ol {
            padding-right: 1.5rem;
            margin-bottom: 1.5rem;
        }

        .article-content li {
            margin-bottom: 0.75rem;
        }

        /* Code blocks */
        .article-content pre {
            overflow-x: auto;
            padding: 1rem;
            border-radius: 8px;
            font-size: 0.9rem;
        }

        /* Tables in article content */
        .article-content table {
            display: block;
            overflow-x: auto;
            white-space: nowrap;
        }
}

/* ============================================
   5. CARD IMPROVEMENTS
   ============================================ */

@media (max-width: 576px) {
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .card-text {
        font-size: 0.95rem;
    }

    /* News cards in grid */
    .news-grid .card {
        margin-bottom: 1.5rem;
    }
}

/* ============================================
   6. FORMS OPTIMIZATION
   ============================================ */

@media (max-width: 768px) {

    .form-group,
    .mb-3 {
        margin-bottom: 1.5rem;
    }

    .form-label {
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    textarea.form-control {
        min-height: 150px;
    }

    /* File upload */
    .form-control[type="file"] {
        padding: 0.5rem;
    }

    /* Form buttons */
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

        .form-actions .btn {
            width: 100%;
        }
}

/* ============================================
   7. PAGINATION MOBILE
   ============================================ */

@media (max-width: 576px) {
    .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .page-link {
        min-width: 40px;
        min-height: 40px;
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }

    /* Hide some page numbers on very small screens */
    .pagination .page-item:not(.active):not(.previous):not(.next):nth-child(n+6):nth-last-child(n+4) {
        display: none;
    }
}

/* ============================================
   8. BREADCRUMB MOBILE
   ============================================ */

@media (max-width: 576px) {
    .breadcrumb {
        padding: 0.5rem;
        font-size: 0.85rem;
        flex-wrap: wrap;
    }

    .breadcrumb-item {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ============================================
   9. SIDEBAR MOBILE
   ============================================ */

@media (max-width: 991px) {
    .sidebar {
        margin-top: 2rem;
    }

    .sidebar-widget {
        margin-bottom: 1.5rem;
    }
}

/* ============================================
   10. COMMENTS SECTION MOBILE
   ============================================ */

@media (max-width: 576px) {
    .comment-item {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .comment-author {
        font-size: 0.95rem;
    }

    .comment-meta {
        font-size: 0.8rem;
        flex-wrap: wrap;
    }

    .comment-content {
        font-size: 0.95rem;
        margin-top: 0.75rem;
    }

    .comment-actions {
        margin-top: 0.75rem;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

        .comment-actions .btn {
            flex: 1;
            min-width: 80px;
        }

    /* Nested replies */
    .comment-reply {
        margin-right: 0.5rem;
        padding-right: 0.5rem;
        border-right: 2px solid var(--border-color);
    }
}

/* ============================================
   11. TAGS & BADGES MOBILE
   ============================================ */

@media (max-width: 576px) {

    .tags-list,
    .badge-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .badge,
    .tag {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }
}

/* ============================================
   12. ALERT MESSAGES MOBILE
   ============================================ */

@media (max-width: 768px) {
    .alert {
        padding: 1rem;
        font-size: 0.95rem;
        border-radius: 8px;
    }

    .alert-dismissible .btn-close {
        padding: 1rem;
    }
}

/* ============================================
   13. HAMBURGER MENU IMPROVEMENTS
   ============================================ */

@media (max-width: 991px) {
    .navbar-toggler {
        padding: 0.5rem 0.75rem;
        border: 2px solid rgba(255, 255, 255, 0.5);
        border-radius: 8px;
        min-width: 44px;
        min-height: 44px;
    }

        .navbar-toggler:focus {
            box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
            outline: none;
        }

    .navbar-toggler-icon {
        width: 1.5rem;
        height: 1.5rem;
    }

    /* Collapsed navbar */
    .navbar-collapse {
        margin-top: 1rem;
        padding: 1rem 0;
    }

    .navbar-nav {
        gap: 0.5rem;
    }
}

/* ============================================
   14. SEARCH OVERLAY MOBILE
   ============================================ */

@media (max-width: 576px) {
    .search-overlay-content {
        width: 95%;
        padding: 1rem;
    }

    .search-form-large {
        flex-direction: column;
        gap: 0.75rem;
    }

        .search-form-large input {
            width: 100%;
            font-size: 1rem;
            padding: 0.875rem 1.5rem;
        }

        .search-form-large button {
            width: 100%;
            padding: 0.875rem;
        }

    .search-close {
        top: -50px;
        font-size: 1.75rem;
    }
}

/* ============================================
   15. FOOTER MOBILE
   ============================================ */

@media (max-width: 767px) {
    .footer-main {
        padding: 2rem 0 1rem;
    }

    .footer-column {
        margin-bottom: 2rem;
    }

    .footer-title {
        font-size: 1rem;
        margin-bottom: 1rem;
    }

    .footer-social {
        justify-content: center;
        margin-bottom: 1.5rem;
    }

    .newsletter-form-footer .input-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .newsletter-form-footer input,
    .newsletter-form-footer button {
        width: 100%;
    }
}

/* ============================================
   16. ADMIN PANEL MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Admin tables - force responsive wrapper */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Admin cards */
    .admin-card {
        margin-bottom: 1rem;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

        .admin-header .btn-group {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .admin-header .btn {
            width: 100%;
        }

    /* Admin filters */
    .admin-filters {
        flex-direction: column;
        gap: 1rem;
    }

        .admin-filters .form-group {
            width: 100% !important;
        }

    /* Stats cards */
    .stats-card {
        margin-bottom: 1rem;
    }
}

/* ============================================
   17. LOADING STATES
   ============================================ */

@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(5px);
        z-index: 9999;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .loading-spinner {
        width: 3rem;
        height: 3rem;
    }
}

/* ============================================
   18. ACCESSIBILITY IMPROVEMENTS
   ============================================ */

@media (max-width: 768px) {

    /* Focus states more visible on mobile */
    *:focus-visible {
        outline: 3px solid var(--accent-primary);
        outline-offset: 2px;
    }

    /* Skip to main content link */
    .skip-to-main {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--accent-primary);
        color: white;
        padding: 0.5rem 1rem;
        text-decoration: none;
        z-index: 10000;
    }

        .skip-to-main:focus {
            top: 0;
        }
}

/* ============================================
   19. PREVENT ZOOM ON INPUT FOCUS (iOS)
   ============================================ */

@media (max-width: 768px) {

    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
        /* Prevents iOS zoom */
    }
}

/* ============================================
   20. HORIZONTAL SCROLL PREVENTION
   ============================================ */

@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .container,
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Prevent wide elements from breaking layout */
    * {
        /* max-width: 100%; */
    }

    img,
    video,
    iframe {
        max-width: 100% !important;
        height: auto !important;
    }

    pre,
    code {
        overflow-x: auto;
        word-wrap: break-word;
    }
}
