/* ========================================================
   My Capetown - Base Stylesheet
   Light theme, mobile-first, card-based listing grid
   ======================================================== */

:root {
    --primary: #1E3A5F;       /* navy - header, nav, headings */
    --primary-dark: #142940;  /* darker navy for hover states */
    --accent: #56CFE1;        /* cyan - active chips, highlights */
    --cta: #FF7F50;           /* orange - primary action buttons */
    --cta-dark: #e6653a;      /* darker orange for hover */
    --bg: #FAFAFA;            /* very light, near-white page background */
    --card-bg: #FFFFFF;       /* white card background */
    --text: #333333;
    --text-muted: #6b6b63;
    --border: #e7e2d6;
    --danger: #b3261e;
    --danger-bg: #fce8e6;
    --success: #2e7d5b;
    --success-bg: #e8f5e9;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding-bottom: 84px; /* space for taller fixed bottom nav */
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Top header --- */
.site-header {
    background: #FFFFFF;
    color: var(--primary);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border);
}
.site-header .brand {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.site-header .brand:hover { text-decoration: none; }

/* --- Page container --- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

/* --- Category chips / filter --- */
.category-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
}
.category-chips::-webkit-scrollbar { display: none; }
.chip {
    flex: 0 0 auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 16px;
    color: var(--text);
    white-space: nowrap;
}
.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--primary-dark);
    font-weight: 600;
}
.chip:hover { text-decoration: none; }

/* --- Listing grid --- */
.listing-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
@media (min-width: 480px) {
    .listing-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
}
@media (min-width: 700px) {
    .listing-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.listing-card {
    background: linear-gradient(180deg, #FFFFFF 0%, #FBFBFD 100%);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: block;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.listing-card:hover {
    text-decoration: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06), 0 8px 20px rgba(0,0,0,0.06);
    transform: translateY(-2px);
}
.listing-card .thumb {
    width: 100%;
    aspect-ratio: 25 / 13.86;
    background: #eef1f0;
    overflow: hidden;
}
.listing-card .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.listing-card .info { padding: 10px; }
.listing-card .name {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 2px;
    line-height: 1.3;
}
.listing-card .snippet {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* --- Premium/Featured listing badge --- */
.premium-card {
    position: relative;
}
.premium-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--cta);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 12px;
    z-index: 2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* --- Listing detail page --- */
.detail-gallery-wrap {
    position: relative;
}
.gallery-counter {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    padding: 3px 11px;
    border-radius: 12px;
    pointer-events: none;
}
.gallery-arrow-right {
    position: absolute;
    right: 12px;
    top: 38%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cta);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    cursor: pointer;
    animation: galleryArrowBlink 1.2s ease-in-out infinite;
}
.gallery-arrow-right i { font-style: normal; line-height: 1; }
@keyframes galleryArrowBlink {
    0%, 100% { opacity: 1; transform: translateY(-50%) translateX(0); }
    50% { opacity: 0.35; transform: translateY(-50%) translateX(6px); }
}
.detail-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}
.detail-gallery img {
    width: 100%;
    height: 40vh;
    object-fit: cover;
    border-radius: 12px;
    flex: 0 0 100%;
    scroll-snap-align: start;
    cursor: pointer;
}

/* --- Full-screen photo lightbox --- */
.photo-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-lightbox img {
    max-width: 92%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 6px;
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    font-size: 26px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    line-height: 1;
    cursor: pointer;
}
.lightbox-nav {
    position: absolute;
    top: 38%;
    transform: translateY(-50%);
    background: var(--cta);
    color: #fff;
    border: none;
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    animation: lightboxArrowBlink 2.4s ease-in-out infinite;
}
@keyframes lightboxArrowBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 12px;
}
.detail-title { font-size: 26px; font-weight: 700; margin: 0 0 8px; }
.detail-category {
    display: inline-block;
    vertical-align: middle;
    background: #e8f5ee;
    color: var(--primary-dark);
    font-size: 15px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    margin-left: 6px;
}
.detail-description {
    font-size: 18px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-line;
    margin-bottom: 8px;
}

.desktop-only-feed { display: none; }
.desktop-sidebar { display: none; }

@media (min-width: 1024px) {
    .detail-title { font-size: 23px; }
    .detail-description { font-size: 17px; }

    /* --- New Facebook-style desktop layout (index.php + listing.php only) --- */
    .sidebar-layout .site-header { display: none; }
    .sidebar-layout .mobile-only-grid { display: none; }
    .sidebar-layout .desktop-only-feed { display: block; }
    .sidebar-layout .category-chips { display: none; }

    .sidebar-layout .desktop-sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 240px;
        padding: 20px 16px;
        background: var(--card-bg);
        border-right: 1px solid var(--border);
        overflow-y: auto;
    }
    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        font-weight: 700;
        font-size: 17px;
        color: var(--primary);
        text-decoration: none;
        padding: 8px 6px;
        margin-bottom: 16px;
    }
    .sidebar-brand:hover { text-decoration: none; }
    .sidebar-link {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px;
        border-radius: 8px;
        color: var(--text);
        font-size: 15px;
        text-decoration: none;
        margin-bottom: 2px;
    }
    .sidebar-link:hover, .sidebar-link.active {
        background: var(--bg);
        color: var(--primary);
        font-weight: 600;
        text-decoration: none;
    }
    .sidebar-icon { font-style: normal; font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
    .sidebar-whatsapp { color: #25D366; }
    .sidebar-link-highlight { color: var(--danger); font-weight: 700; }
    .sidebar-link-highlight:hover { color: var(--danger); }
    .sidebar-post-ad {
        display: block;
        margin-top: 16px;
        padding: 11px;
        text-align: center;
        background: var(--cta);
        color: #fff;
        border-radius: 20px;
        font-size: 15px;
        font-weight: 700;
        text-decoration: none;
    }
    .sidebar-post-ad:hover { background: var(--cta-dark); text-decoration: none; }

    .sidebar-layout .container {
        margin-left: 240px;
        max-width: 1003px;
        padding: 24px;
    }

    /* Desktop feed: same continuous-scroll full-post style as mobile, just no
       snap-scrolling and no forced full-screen-per-post height. */
    .sidebar-layout .feed-viewport {
        height: auto;
        overflow: visible;
        scroll-snap-type: none;
    }
    .sidebar-layout .snap-section {
        min-height: 0;
        scroll-snap-align: none;
        padding-top: 0;
    }
    .sidebar-layout .feed-full-item .detail-gallery img {
        height: 216px;
    }
    .sidebar-layout .detail-layout .detail-gallery img {
        height: 281px;
    }
    .sidebar-layout .detail-layout {
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 20px;
    }
    .sidebar-layout .feed-full-item {
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 16px;
        border-top: none;
    }
    .sidebar-layout .desktop-only-feed,
    .sidebar-layout .feed-container {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
        align-items: start;
    }
    .sidebar-layout #desktopFeedSentinel,
    .sidebar-layout #desktopFeedEndMessage {
        grid-column: 1 / -1;
    }
}

/* --- Infinite scroll feed (mobile only) --- */
.feed-viewport {
    height: calc(100vh - 130px);
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
}
.snap-section {
    scroll-snap-align: start;
    scroll-snap-stop: always;
    min-height: calc(100vh - 130px);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 2px;
    position: relative;
}
.feed-scroll-hint {
    display: flex;
    justify-content: center;
    margin-top: 2px;
}
.feed-arrow {
    font-style: normal;
    font-size: 44px;
    line-height: 1;
    color: var(--cta);
    animation: feedBounce 1.1s ease-in-out infinite;
}
@keyframes feedBounce {
    0%, 100% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(10px); opacity: 0.5; }
}
.feed-arrow-up {
    animation-name: feedBounceUp;
}
@keyframes feedBounceUp {
    0%, 100% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(-10px); opacity: 0.5; }
}
.feed-container {
    display: flex;
    flex-direction: column;
}
.feed-full-item {
    border-top: 6px solid var(--bg);
}
.feed-title-link {
    color: inherit;
    text-decoration: none;
}
.feed-title-link:hover { text-decoration: none; }
.feed-title-link .detail-title { margin-bottom: 4px; }
.whatsapp-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #25D366;
    color: #fff;
    padding: 12px 20px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 17px;
}
.whatsapp-btn:hover { text-decoration: none; opacity: 0.92; }

/* --- Forms (shared across login/setup/post-ad/admin) --- */
.box {
    max-width: 440px;
    margin: 24px auto;
    background: linear-gradient(180deg, #FFFFFF 0%, #FBFBFD 100%);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 14px rgba(0,0,0,0.04);
}
.box h1 { font-size: 23px; margin-top: 0; }
.box label { display: block; margin-top: 14px; font-size: 16px; color: var(--text); }
.box input, .box select, .box textarea {
    width: 100%;
    padding: 10px;
    margin-top: 4px;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
    font-size: 17px;
    font-family: inherit;
}
.box button {
    margin-top: 20px;
    width: 100%;
    padding: 12px;
    background: linear-gradient(180deg, #FF8F65 0%, var(--cta) 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 17px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(255,127,80,0.3);
}
.box button:hover { background: var(--cta-dark); }
.error {
    color: var(--danger);
    background: var(--danger-bg);
    padding: 10px;
    border-radius: 8px;
    margin-top: 14px;
    font-size: 16px;
}
.success {
    color: var(--success);
    background: var(--success-bg);
    padding: 10px;
    border-radius: 8px;
    margin-top: 14px;
    font-size: 16px;
}
.hint { font-size: 15px; color: var(--text-muted); margin-top: 10px; }

/* --- Accumulating photo picker (Post Ad / Edit Listing forms) --- */
.photo-preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.photo-preview-thumb {
    position: relative;
    width: 76px;
}
.photo-preview-thumb img {
    width: 76px;
    height: 76px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}
.photo-remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    z-index: 2;
}
.photo-default-btn {
    display: block;
    width: 100%;
    margin-top: 3px;
    padding: 2px 0;
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 10px;
    cursor: pointer;
}
.photo-default-btn:hover { background: var(--accent); color: #fff; }
.photo-default-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    background: var(--cta);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 6px;
    z-index: 2;
}
.btn-add-photo {
    margin-top: 10px;
    padding: 8px 16px;
    background: var(--card-bg);
    border: 1px dashed var(--primary);
    color: var(--primary);
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

/* --- Fixed mobile bottom nav --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 20;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0 8px;
    font-size: 15px;
    color: var(--text-muted);
    gap: 3px;
    min-height: 56px;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .icon { font-size: 24px; line-height: 1; }
.whatsapp-nav-link span:last-child { color: #25D366; font-weight: 600; }

/* --- Push notification opt-in popup --- */
.push-prompt {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    padding: 20px;
}
.push-prompt-box {
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
    padding: 40px 32px;
    max-width: 520px;
    width: 100%;
    text-align: center;
}
.push-prompt-icon {
    font-size: 56px;
    margin-bottom: 12px;
}
.push-prompt-text {
    font-size: 25px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 28px;
    line-height: 1.4;
}
.push-prompt-actions {
    display: flex;
    gap: 14px;
    justify-content: center;
}
.btn-secondary-small, .btn-primary-small {
    padding: 16px 26px;
    border-radius: 12px;
    font-size: 19px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    flex: 1;
}
.btn-secondary-small { background: var(--bg); color: var(--text-muted); order: 2; }
.btn-primary-small { background: var(--cta); color: #fff; order: 1; }
.push-prompt-status {
    margin: 18px 0 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
}
.push-prompt-status-ok { color: var(--success); }
.push-prompt-status-error { color: var(--danger); }

/* --- Desktop top navigation (hidden on mobile, shown at desktop breakpoint) --- */
.desktop-nav {
    display: none;
    align-items: center;
    gap: 24px;
}
.desktop-nav a {
    color: var(--primary);
    font-size: 17px;
    font-weight: 500;
    opacity: 0.75;
}
.desktop-nav a:hover { opacity: 1; text-decoration: none; }
.desktop-nav a.active { opacity: 1; font-weight: 700; }
.desktop-nav .nav-cta {
    background: var(--cta);
    color: #fff;
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: 600;
    opacity: 1;
}
.desktop-nav .nav-cta:hover { background: var(--cta-dark); opacity: 1; }
.desktop-nav .nav-pill {
    background: rgba(30,58,95,0.08);
    padding: 8px 16px;
    border-radius: 20px;
}

/* --- Desktop layout: wider container, more grid columns, top nav instead of bottom nav --- */
@media (min-width: 1024px) {
    body { padding-bottom: 0; }

    .container { max-width: 1140px; padding: 24px; }

    .site-header { padding: 16px 32px; }
    .site-header .brand { font-size: 25px; }

    .bottom-nav { display: none; }
    .desktop-nav { display: flex; }

    .listing-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; }

    .category-chips { margin-bottom: 24px; }

    .box { max-width: 520px; }

    .owner-subnav { display: none; }
}
