/**
 * Unified Responsive Fixes - Same look & behavior on all devices
 * Public site + Admin - Mobile, Tablet, Desktop
 */

/* ========== GLOBAL: No horizontal scroll, fluid layout ========== */
html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

.container,
.container-fluid {
    max-width: 100%;
    overflow-x: hidden;
    margin-left: auto;
    margin-right: auto;
}

.row {
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* ========== RESPONSIVE CENTER: All devices, especially mobile ========== */
.main-content {
    width: 100%;
    max-width: 100%;
}

.main-content .container {
    margin-left: auto;
    margin-right: auto;
}

/* Mobile: center header brand and tagline */
@media (max-width: 767.98px) {
    .site-header .header-inner {
        justify-content: center !important;
        text-align: center;
    }
    .site-header .header-brand {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
    }
    .site-header .header-brand-line {
        margin-left: auto;
        margin-right: auto;
    }
    .site-header .header-logo-link {
        justify-content: center;
    }
    .top-bar .top-bar-inner {
        justify-content: center;
        gap: 0.75rem;
    }
}

/* Tablet: center header on medium screens too */
@media (max-width: 991.98px) {
    .site-header .header-inner {
        align-items: center;
        text-align: center;
    }
    .site-header .header-brand {
        text-align: center;
    }
    .site-footer .row {
        justify-content: center;
        text-align: center;
    }
    .site-footer .footer-brand,
    .site-footer .footer-block {
        margin-left: auto;
        margin-right: auto;
        text-align: center;
    }
    .site-footer .footer-social {
        justify-content: center;
    }
    .site-footer .footer-bottom-inner {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.5rem;
    }
}

/* Mobile: center footer columns and content */
@media (max-width: 575.98px) {
    .site-footer .col-6,
    .site-footer [class*="col-"] {
        max-width: 100%;
        flex: 0 0 100%;
        text-align: center;
    }
    .site-footer .footer-block,
    .site-footer .footer-brand {
        margin-left: auto;
        margin-right: auto;
    }
    .main-content .row {
        justify-content: center;
    }
    .section-header {
        text-align: center;
    }
    .section-header .section-title {
        margin-left: auto;
        margin-right: auto;
    }
}

/* ========== All images fluid ========== */
img,
.news-image,
.featured-image,
.article-cover-image img,
.card-img-top,
.widget img {
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

.article-cover-image img,
.article-gallery img {
    max-width: 100%;
    height: auto;
}

/* Prevent overflow in article body and code */
.article-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
    max-width: 100%;
}

.article-content pre,
.article-content iframe {
    max-width: 100%;
    overflow-x: auto;
}

/* ========== PUBLIC: Mobile & Tablet ========== */
@media (max-width: 991.98px) {
    .top-bar .container,
    .site-header .container,
    .main-content .container,
    .site-footer .container {
        padding-left: 15px;
        padding-right: 15px;
    }

    .breaking-news-bar .container {
        padding-left: 15px;
        padding-right: 15px;
    }

    .featured-news-card .card-img-top,
    .featured-image {
        width: 100%;
        height: auto;
        min-height: 200px;
        object-fit: cover;
    }

    .news-card-horizontal .row {
        flex-direction: column;
    }

    .news-card-horizontal .col-4 {
        max-width: 100%;
        width: 100%;
    }

    .news-card-horizontal .col-8 {
        max-width: 100%;
        width: 100%;
    }

    .news-card-horizontal img {
        width: 100%;
        height: auto;
        max-height: 220px;
        object-fit: cover;
    }
}

@media (max-width: 575.98px) {
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .featured-overlay .card-title {
        font-size: 1.1rem !important;
    }

    .news-card .card-title {
        font-size: 0.95rem !important;
    }

    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }
}

/* ========== ADMIN: Mobile ========== */
@media (max-width: 767.98px) {
    body.admin-page,
    body {
        overflow-x: hidden;
    }

    .navbar .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .content-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        padding: 15px 12px !important;
        overflow-x: hidden;
    }

    main.col-md-9,
    main.col-lg-10 {
        max-width: 100%;
        flex: 0 0 100%;
    }

    /* Admin sidebar: overlay from right (RTL) */
    .sidebar {
        position: fixed !important;
        top: 56px;
        right: 0;
        bottom: 0;
        left: auto;
        width: 280px;
        max-width: 85vw;
        z-index: 1040;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: -4px 0 20px rgba(0,0,0,0.2);
    }

    /* Admin cards full width & compact */
    .card {
        max-width: 100%;
        margin-bottom: 16px;
    }

    .card-header,
    .card-footer {
        padding: 0.6rem 0.9rem !important;
    }

    .card-body {
        padding: 0.9rem !important;
        overflow-x: auto;
    }

    /* Admin tables: horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .table {
        min-width: 500px;
    }

    /* Admin forms: full width inputs */
    .form-control,
    .form-select {
        max-width: 100%;
        font-size: 16px; /* prevents zoom on iOS */
    }


    /* Admin stat cards: keep 2 per row on mobile (see .row-stat-cards override in admin.css) */
    .row.g-3 .col-md-3,
    .row.g-4 .col-md-3,
    .row.g-4 .col-lg-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    .row-stat-cards .col-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Admin buttons stack */
    .btn-toolbar {
        flex-direction: column;
        width: 100%;
    }

    .btn-toolbar .btn {
        width: 100%;
        margin-bottom: 8px;
    }

    .d-flex.justify-content-between {
        flex-direction: column;
        gap: 10px;
    }
}

/* ========== ADMIN: Tablet ========== */
@media (min-width: 768px) and (max-width: 991.98px) {
    .content-wrapper {
        margin-right: 250px !important;
        padding: 20px 15px !important;
        max-width: 100%;
    }

    /* Keep Summernote desktop behavior on tablet */
}

/* ========== Touch targets (mobile & tablet) ========== */
@media (max-width: 991.98px) {
    .nav-link,
    .page-link,
    .dropdown-item {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 12px 16px;
    }

    .sidebar .nav-link {
        min-height: 48px;
        padding: 14px 20px;
    }

    /* Summernote toolbar: compact, split into 2 rows on small screens */
    .note-editor .note-toolbar {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center;
        justify-content: flex-start;
        overflow-x: visible;
        white-space: normal;
        gap: 2px 4px; /* row / column gap */
        padding-inline: 4px;
    }

    .note-editor .note-toolbar .btn-group,
    .note-editor .note-toolbar .note-btn-group {
        display: inline-flex !important;
        flex-wrap: nowrap;
        width: auto !important;
        margin: 0 2px 4px 2px !important; /* allow a second row */
    }

    .note-editor .note-toolbar .btn,
    .note-editor .note-toolbar .note-btn {
        display: inline-flex !important;
        width: auto !important;
        min-width: auto;
        padding: 4px 6px;
        font-size: 12px;
        margin: 0 !important;
        justify-content: center;
        align-items: center;
    }
}

/* ========== Safe area (notch devices) ========== */
@supports (padding: max(0px)) {
    @media (max-width: 767.98px) {
        .navbar {
            padding-right: max(12px, env(safe-area-inset-right));
            padding-left: max(12px, env(safe-area-inset-left));
        }

        .content-wrapper {
            padding-right: max(12px, env(safe-area-inset-right)) !important;
            padding-left: max(12px, env(safe-area-inset-left)) !important;
        }

        .btn-scroll-top {
            left: max(15px, env(safe-area-inset-left)) !important;
            bottom: max(15px, env(safe-area-inset-bottom)) !important;
        }
    }
}

/* ========== Prevent tiny text on mobile ========== */
@media (max-width: 767.98px) {
    body {
        font-size: 15px;
    }

    small,
    .text-muted {
        font-size: 0.875rem;
    }
}

/* ========== ADMIN: Restore RTL form alignment (override center-mobile) ========== */
body.admin-page .content-wrapper {
    text-align: right !important;
}

@media (max-width: 991.98px) {
    body.admin-page .content-wrapper .form-label,
    body.admin-page .content-wrapper .form-control,
    body.admin-page .content-wrapper .form-select,
    body.admin-page .content-wrapper .form-check-label,
    body.admin-page .content-wrapper .table thead th,
    body.admin-page .content-wrapper .table tbody td {
        text-align: right !important;
    }

    body.admin-page .content-wrapper .d-flex.justify-content-between {
        justify-content: flex-start !important;
        flex-direction: row;
    }

    body.admin-page .btn-toolbar {
        flex-direction: row;
        flex-wrap: wrap;
    }

    body.admin-page .btn-toolbar .btn {
        width: auto;
        margin-bottom: 0;
    }
}
