/* ForSale Widget System - Mobile-first CSS */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition: 200ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

/* Lock body scroll when modal open */
body.fs-modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* ─── Layout ─────────────────────────────────── */
.fs-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-left)) 16px max(16px, env(safe-area-inset-right));
}

.fs-header {
    text-align: center;
    padding: 24px 0 16px;
}
.fs-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ─── Search Bar ─────────────────────────────── */
.fs-search {
    position: relative;
    margin-bottom: 20px;
}
.fs-search input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 16px; /* 16px prevents iOS zoom */
    background: #fff;
    transition: border-color var(--transition);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    min-height: 48px;
}
.fs-search input:focus {
    border-color: var(--primary);
}
.fs-search .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--gray-400);
    pointer-events: none;
}

/* ─── Filter pills ───────────────────────────── */
.fs-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scroll-snap-type: x mandatory;
}
.fs-filters::-webkit-scrollbar { display: none; }
.fs-pill {
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid var(--gray-300);
    background: #fff;
    font-size: .875rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--gray-600);
    scroll-snap-align: start;
    min-height: 36px;
}
.fs-pill:hover, .fs-pill.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ─── Item Grid ──────────────────────────────── */
.fs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ─── Item Card ──────────────────────────────── */
.fs-card {
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(37, 99, 235, .15);
    position: relative;
}
.fs-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.fs-card:active {
    transform: scale(0.98);
    transition: transform 100ms ease;
}
.fs-card-img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: var(--gray-100);
    display: block;
}
.fs-card-body {
    padding: 16px;
}
.fs-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 4px;
    line-height: 1.3;
}
.fs-card-desc {
    font-size: .875rem;
    color: var(--gray-500);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.fs-card-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
}
.fs-card-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 50px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.fs-card-status.sold { background: #fef2f2; color: var(--danger); }
.fs-card-status.active { background: #f0fdf4; color: var(--success); }

/* ─── Detail Modal / Lightbox ────────────────── */
.fs-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 300ms ease;
    overscroll-behavior: contain;
}
.fs-modal-overlay.open {
    opacity: 1;
    visibility: visible;
}
.fs-modal {
    background: #fff;
    border-radius: var(--radius);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 300ms ease;
    overscroll-behavior: contain;
    position: relative;
}
.fs-modal-overlay.open .fs-modal {
    transform: translateY(0);
}
.fs-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0,0,0,.6);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.fs-modal-close:active { background: rgba(0,0,0,.8); }
.fs-modal-gallery {
    position: relative;
    background: var(--gray-100);
    touch-action: pan-y pinch-zoom;
}
.fs-modal-gallery img {
    width: 100%;
    max-height: 500px;
    object-fit: contain;
    display: block;
    background: var(--gray-100);
}
.fs-gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,.5);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.fs-gallery-nav:active { background: rgba(0,0,0,.75); }
.fs-gallery-nav.prev { left: 8px; }
.fs-gallery-nav.next { right: 8px; }
.fs-gallery-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 12px;
}
.fs-gallery-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-300);
    border: none;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 200ms ease;
}
.fs-gallery-dot.active {
    background: var(--primary);
}
.fs-modal-body {
    padding: 20px;
}
.fs-modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.3;
    padding-right: 50px; /* leave room for close btn */
}
.fs-modal-price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 16px;
}
.fs-modal-desc {
    color: var(--gray-600);
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ─── Empty / Loading States ─────────────────── */
.fs-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}
.fs-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
}
.fs-loading {
    display: flex;
    justify-content: center;
    padding: 40px;
}
.fs-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── No-image placeholder ───────────────────── */
.fs-no-img {
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-300);
}
.fs-no-img svg { width: 48px; height: 48px; }

/* ═══════════════════════════════════════════════ */
/* ═══ Mobile Breakpoints (Progressive) ═════════ */
/* ═══════════════════════════════════════════════ */

/* Tablet (up to 900px) - 2 columns */
@media (max-width: 900px) {
    .fs-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
}

/* Phone landscape / small tablet (640px) - single column */
@media (max-width: 640px) {
    .fs-container { padding: 12px; }
    .fs-header { padding: 16px 0 12px; }
    .fs-header h1 { font-size: 1.5rem; }
    .fs-search { margin-bottom: 14px; }
    .fs-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Modal becomes bottom sheet on mobile */
    .fs-modal-overlay {
        padding: 0;
        align-items: flex-end;
    }
    .fs-modal {
        max-height: 95vh;
        max-height: 95dvh; /* dynamic viewport height */
        border-radius: var(--radius) var(--radius) 0 0;
        max-width: 100%;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .fs-modal::before {
        content: '';
        position: sticky;
        top: 0;
        display: block;
        width: 40px;
        height: 4px;
        background: var(--gray-300);
        border-radius: 2px;
        margin: 8px auto 0;
        z-index: 3;
    }
    .fs-modal-overlay.open .fs-modal {
        transform: translateY(0);
        animation: slideUp 300ms ease;
    }
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .fs-modal-close {
        top: 20px;
        right: 12px;
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
    }
    .fs-modal-body {
        padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    }
    .fs-modal-title {
        font-size: 1.25rem;
        padding-right: 44px;
    }
    .fs-modal-price { font-size: 1.25rem; }
    .fs-modal-gallery img { max-height: 50vh; }
    .fs-gallery-nav {
        width: 40px;
        height: 40px;
    }
}

/* Small phones (up to 380px) */
@media (max-width: 380px) {
    .fs-header h1 { font-size: 1.25rem; }
    .fs-card-body { padding: 14px; }
    .fs-card-price { font-size: 1.1rem; }
    .fs-search input { padding: 12px 12px 12px 40px; }
    .fs-modal-title { font-size: 1.1rem; }
    .fs-modal-price { font-size: 1.1rem; }
}

/* Landscape phone - smaller modal */
@media (max-height: 500px) and (orientation: landscape) {
    .fs-modal { max-height: 100vh; border-radius: 0; }
    .fs-modal-gallery img { max-height: 70vh; }
    .fs-modal-body { padding: 12px 16px; }
}

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

/* ─── Utility ────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}
