/**
 * Responsive layer — mobile-first, fluid layout
 * Breakpoints: 320 | 480 | 768 | 1024 | 1440+
 */

/* ==================== Global overflow & full-width ==================== */
html,
body {
    width: 100%;
    max-width: 100%;
}

main,
section,
article,
header,
footer,
nav,
form {
    max-width: 100%;
}

/* ==================== Utility: responsive media & tables ==================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--space-md, 1rem);
}

.table-responsive > table {
    min-width: min(100%, 40rem);
}

.form-grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
    gap: var(--space-md, 0.75rem);
    width: 100%;
}

.form-grid-responsive > [style*="grid-column"] {
    grid-column: 1 / -1 !important;
}

/* Auth / dashboard forms */
.page-content form:not(.search-form) {
    width: 100%;
    max-width: min(100%, 28rem);
}

.page-content input,
.page-content select,
.page-content textarea {
    width: 100%;
}

/* ==================== Modals & lightbox ==================== */
.property-lightbox,
[class*="lightbox"],
.modal-overlay {
    padding: clamp(0.5rem, 2vw, 1.5rem);
    box-sizing: border-box;
}

.property-lightbox img,
#propertyLightboxImg {
    max-width: min(96vw, 68.75rem);
    max-height: min(86vh, 86dvh);
    width: auto;
    height: auto;
    object-fit: contain;
}

.property-lightbox-prev,
.property-lightbox-next {
    width: clamp(2.25rem, 8vw, 3rem) !important;
    height: clamp(2.25rem, 8vw, 3rem) !important;
    font-size: clamp(1.25rem, 4vw, 2rem) !important;
}

.property-gallery {
    width: 100%;
}

.property-gallery-thumb img {
    width: 100%;
    height: clamp(6rem, 22vw, 8.75rem);
    object-fit: cover;
}

/* Blog / detail article */
.blog-post-body,
.card {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#searchResults {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr));
    gap: clamp(1rem, 2.5vw, 1.875rem);
}

#pagination {
    width: 100%;
    flex-wrap: wrap;
}

/* ==================== Navbar mobile (≤768px) ==================== */
@media screen and (max-width: 768px) {
    .navbar .container {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "brand actions"
            "menu menu";
        align-items: center;
    }

    .navbar-brand {
        grid-area: brand;
    }

    .navbar-right {
        grid-area: actions;
        width: auto;
        margin-top: 0;
        flex-wrap: nowrap;
        gap: var(--space-xs, 0.5rem);
    }

    .navbar-right .btn-primary,
    .navbar-right .btn-secondary,
    .navbar-right .btn-danger {
        flex: 0 1 auto;
        min-width: 0;
        padding: 0.5rem 0.65rem;
        font-size: var(--text-xs, 0.75rem);
    }

    .hamburger-menu {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .navbar-menu {
        grid-area: menu;
        display: none;
        position: static;
        width: 100%;
        margin-left: 0;
        flex-direction: column;
        gap: 0;
        background: rgba(10, 10, 10, 0.98);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md, 0.5rem);
        margin-top: var(--space-sm, 0.5rem);
        overflow: hidden;
    }

    body.light-theme .navbar-menu {
        background: rgba(255, 255, 255, 0.98);
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-menu .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color);
        width: 100%;
    }

    .navbar-menu .nav-link:last-child {
        border-bottom: none;
    }
}

/* ==================== 320px — small phones ==================== */
@media screen and (max-width: 320px) {
    .container {
        padding-inline: 0.75rem;
    }

    .navbar-right .btn-secondary,
    .navbar-right .btn-primary,
    .navbar-right .btn-danger {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }

    .hero-content {
        padding: 0.5rem;
    }

    .search-tabs {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .listing-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-view {
        width: 100%;
    }
}

/* ==================== 480px — phones ==================== */
@media screen and (max-width: 480px) {
    .hero {
        min-height: clamp(18rem, 75vh, 28rem);
        min-height: clamp(18rem, 75dvh, 28rem);
    }

    .search-form {
        padding: 1rem;
    }

    .search-inputs {
        grid-template-columns: 1fr;
    }

    .listings-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: var(--space-lg, 1.5rem);
    }

    .listing-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* ==================== 768px — tablets ==================== */
@media screen and (max-width: 768px) {
    .featured-section,
    .statistics-section {
        padding-block: var(--space-lg, 2rem);
    }

    .search-inputs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .listings-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .footer-content {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .footer {
        margin-top: var(--space-xl, 3rem);
        padding-block: var(--space-xl, 3rem) var(--space-md, 1rem);
    }
}

/* ==================== 1024px — laptops ==================== */
@media screen and (max-width: 1024px) {
    .search-inputs {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
    }

    .listings-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    }
}

@media screen and (min-width: 769px) {
    .navbar-menu {
        display: flex !important;
        position: static;
        flex-direction: row;
        border: none;
        margin-top: 0;
        background: transparent;
    }

    .hamburger-menu {
        display: none !important;
    }
}

/* ==================== 1440px+ — large / 2K ==================== */
@media screen and (min-width: 1440px) {
    :root {
        --container-max: min(90rem, 100vw - 4rem);
    }

    .listings-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    }
}

/* ==================== 1920px+ — 4K / ultra-wide ==================== */
@media screen and (min-width: 1920px) {
    :root {
        --container-max: min(100rem, 92vw);
        --text-hero: clamp(2.5rem, 2rem + 2vw, 4.5rem);
    }

    .listings-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
    }
}

/* ==================== Touch & motion ==================== */
@media (hover: none) and (pointer: coarse) {
    .btn-primary:active,
    .btn-secondary:active,
    .listing-card:active {
        transform: scale(0.98);
    }

    .listing-card:hover {
        transform: none;
    }
}

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

/* ==================== Landscape phones ==================== */
@media (orientation: landscape) and (max-height: 31.25rem) {
    .hero {
        min-height: 100vh;
        min-height: 100dvh;
    }

    .navbar .container {
        min-height: auto;
    }
}

/* ==================== High DPI ==================== */
@media (min-resolution: 2dppx) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ==================== Print ==================== */
@media print {
    .navbar,
    .hero,
    .search-form,
    .footer,
    .hamburger-menu,
    .theme-toggle {
        display: none !important;
    }

    .page-content {
        padding-top: 0;
    }

    .listing-card {
        page-break-inside: avoid;
    }
}
