/**
 * Mobile-Specific Enhancements
 * Extra polish for mobile devices
 * EVERYTHING CENTERED ON MOBILE
 */

/* CENTER ALL CONTENT ON MOBILE */
@media (max-width: 991px) {
    /* Center all headings */
    h1, h2, h3, h4, h5, h6,
    .h1, .h2, .h3, .h4, .h5, .h6 {
        text-align: center !important;
    }
    
    /* Center all paragraphs and text */
    p, span, div, a {
        text-align: center !important;
    }
    
    /* Center all cards */
    .card {
        text-align: center;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    /* Center all buttons */
    .btn,
    .btn-group,
    .btn-toolbar {
        margin-left: auto !important;
        margin-right: auto !important;
        justify-content: center !important;
        display: flex !important;
    }
    
    /* Center all images */
    img {
        display: block;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    /* Center flex containers */
    .d-flex,
    .flex-between,
    .flex-center {
        justify-content: center !important;
        text-align: center !important;
    }
    
    /* Center grid items */
    .row {
        justify-content: center;
    }
    
    /* Center lists */
    ul, ol {
        text-align: center;
        list-style-position: inside;
    }
    
    /* Center navbar items */
    .navbar-nav {
        align-items: center;
        width: 100%;
    }
    
    .navbar-nav .nav-item {
        width: 100%;
        text-align: center;
    }
    
    /* Center breadcrumb */
    .breadcrumb {
        justify-content: center !important;
    }
}

/* Touch-friendly styles */
.is-mobile .btn,
.is-mobile .nav-link,
.is-mobile .page-link {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Touch active states */
.touch-active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* Navbar toggler: always on top and touch-friendly on all devices where it shows */
@media (max-width: 991.98px) {
    .site-nav.navbar {
        z-index: 1020 !important;
    }
    .site-nav .navbar-toggler,
    .site-nav .nav-toggler {
        position: relative !important;
        z-index: 1050 !important;
        min-width: 48px !important;
        min-height: 48px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Better mobile/tablet menu - same overlay for all devices where toggler shows (navbar-expand-lg = 992px) */
@media (max-width: 991.98px) {
    .site-nav .navbar-collapse {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        margin: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
        z-index: 1040 !important;
        padding: 30px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        transform: translateX(100%);
        -webkit-transform: translateX(100%);
        transition: transform 0.25s ease-out;
        border-radius: 0 !important;
    }
    
    /* Safari: open menu above all content, own stacking context so links work */
    .site-nav .navbar-collapse.show {
        z-index: 9998 !important;
        transform: translateX(0) translateZ(0);
        -webkit-transform: translateX(0) translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .site-nav .navbar-collapse .nav-collapse-header,
    .site-nav .navbar-collapse .navbar-nav {
        position: relative !important;
        z-index: 2 !important;
    }
    
    .site-nav .navbar-collapse .nav-link {
        position: relative !important;
        z-index: 2 !important;
    }
    
    .navbar-nav {
        gap: 10px;
    }
    
    .navbar-nav .nav-link {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 12px;
        padding: 16px 20px;
        font-size: 16px;
        backdrop-filter: blur(10px);
    }
    
    .navbar-nav .nav-link.active {
        background: rgba(255, 255, 255, 0.25);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }
}

/* Mobile body scroll lock (inline script uses nav-menu-open). No position:fixed so Safari link taps work */
body.menu-open,
body.nav-menu-open {
    overflow: hidden;
}

/* Mobile optimized cards - ALL CENTERED */
@media (max-width: 767px) {
    .news-card {
        border-radius: 12px;
        text-align: center;
    }
    
    .news-card .card-body {
        padding: 20px;
        text-align: center !important;
    }
    
    .news-card .card-title {
        font-size: 16px;
        line-height: 1.5;
        text-align: center !important;
    }
    
    .news-card .card-title a {
        text-align: center !important;
    }
    
    .news-card .card-text {
        font-size: 14px;
        line-height: 1.7;
        text-align: center !important;
    }
    
    .news-meta {
        justify-content: center !important;
        text-align: center !important;
    }
    
    /* Center category badge */
    .category-badge,
    .breaking-badge {
        position: relative;
        top: auto;
        right: auto;
        margin: 10px auto;
        display: inline-block;
    }
}

/* Mobile article enhancements - ALL CENTERED */
@media (max-width: 767px) {
    .article-card {
        border-radius: 12px;
        text-align: center;
    }
    
    .article-card .card-body {
        text-align: center !important;
        padding: 25px 20px !important;
    }
    
    .article-title,
    .article-summary,
    .article-content,
    .article-content p,
    .article-content h2,
    .article-content h3 {
        text-align: center !important;
    }
    
    .article-header {
        text-align: center !important;
    }
    
    .article-header .badge {
        display: inline-block;
        margin: 5px;
    }
    
    .article-meta {
        text-align: center !important;
    }
    
    .article-meta .row {
        justify-content: center;
    }
    
    .article-meta .col-md-6 {
        text-align: center !important;
        margin-bottom: 10px;
    }
    
    .article-cover-image {
        text-align: center;
    }
    
    .article-cover-image img {
        border-radius: 12px;
        margin: 0 auto;
        display: block;
    }
    
    .article-gallery {
        text-align: center;
    }
    
    .article-gallery img {
        border-radius: 8px;
        margin: 0 auto;
    }
    
    .article-share {
        text-align: center !important;
    }
}

/* Mobile-friendly tables */
@media (max-width: 767px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
    }
    
    .table {
        font-size: 13px;
    }
    
    .table thead {
        font-size: 11px;
    }
}

/* Improved mobile forms */
@media (max-width: 767px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 14px 18px;
    }
    
    .form-label {
        font-size: 14px;
    }
}

/* Mobile gallery improvements */
@media (max-width: 575px) {
    .article-gallery .col-md-4 {
        width: 100%;
        margin-bottom: 20px;
    }
    
    .article-gallery img {
        width: 100%;
        height: auto;
    }
}

/* Mobile share buttons: same circles in a row */
@media (max-width: 575px) {
    .share-buttons {
        display: flex;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        gap: 12px;
    }
    
    .share-buttons .btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        border-radius: 50%;
    }
}

/* Mobile footer improvements */
@media (max-width: 767px) {
    .site-footer .col-md-4 {
        margin-bottom: 30px;
        text-align: center;
    }
    
    .site-footer ul {
        padding-right: 0;
    }
}

/* Safe area for iPhone notch */
@supports (padding: max(0px)) {
    .top-bar,
    .navbar,
    .site-footer {
        padding-right: max(15px, env(safe-area-inset-right));
        padding-left: max(15px, env(safe-area-inset-left));
    }
}

/* Prevent horizontal scroll */
body {
    overflow-x: hidden;
}

.container,
.row {
    max-width: 100%;
}

/* Better mobile pagination */
@media (max-width: 575px) {
    .pagination {
        font-size: 14px;
    }
    
    .page-link {
        padding: 8px 12px;
        margin: 0 2px;
    }
    
    /* Show only prev, current, next on mobile */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child) {
        display: none;
    }
}

/* Mobile breadcrumb */
@media (max-width: 575px) {
    .breadcrumb {
        font-size: 12px;
        padding: 10px 15px;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 6px;
    }
}

/* Mobile sticky elements */
@media (max-width: 767px) {
    .sticky-top {
        position: sticky;
        top: 0;
        z-index: 1020;
    }
}

/* Optimize animations for mobile */
@media (max-width: 767px) {
    .news-card,
    .widget,
    .article-card {
        animation-duration: 0.3s;
    }
    
    /* Disable parallax on mobile */
    .featured-image {
        transform: none !important;
    }
}

/* Better mobile accessibility */
@media (max-width: 767px) {
    /* Larger clickable areas */
    .news-card .stretched-link::before {
        position: absolute;
        top: -10px;
        right: -10px;
        bottom: -10px;
        left: -10px;
    }
}

/* Mobile admin enhancements */
@media (max-width: 767px) {
    /* Admin navbar */
    .navbar-brand {
        font-size: 16px;
    }
    
    /* Admin stats */
    .stat-card .text-muted {
        font-size: 11px;
    }
    
    /* Admin quick actions */
    .btn-toolbar .btn {
        font-size: 14px;
        padding: 10px 16px;
    }
    
    /* Admin page title */
    .border-bottom h1 {
        font-size: 22px;
    }
}

/* Improve touch scrolling */
.sidebar,
.table-responsive,
.overflow-auto {
    -webkit-overflow-scrolling: touch;
}

/* Better font rendering on mobile */
@media (max-width: 767px) {
    body {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* PWA-like mobile experience */
@media (display-mode: standalone) {
    .top-bar {
        padding-top: env(safe-area-inset-top);
    }
}
