/* =========================================================
   KABANKALANX (KX) - DESIGN SYSTEM & STYLESHEET
   Leaflet OpenStreetMap Styling, Hiligaynon Badging,
   KStar Express Delivery Service & KX Premium Tier UI
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');
@import url('https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css');
@import url('https://unpkg.com/leaflet@1.9.4/dist/leaflet.css');

:root {
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    
    /* Negros Emerald & Deep Oceanic Blue Palette */
    --primary: #059669;
    --primary-hover: #047857;
    --primary-light: #ecfdf5;
    
    --secondary: #0284c7;
    --secondary-hover: #0369a1;
    
    --accent-gold: #f59e0b;
    --accent-gold-dark: #d97706;
    --accent-gcash: #007cff;
    --accent-kstar: #ef4444; /* KStar Red Transporter Accent */
    
    /* Dark Mode Defaults */
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --border-color: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.15);
    --shadow-gold: 0 0 25px rgba(245, 158, 11, 0.35);
    --shadow-kstar: 0 0 20px rgba(239, 68, 68, 0.35);
    
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --border-color: #e2e8f0;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: 80px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

/* NAVBAR HEADER */
.navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
}
[data-theme="light"] .navbar {
    background: rgba(255, 255, 255, 0.88);
}

.nav-container {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--text-primary);
}

.brand-badge {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #ffffff;
    font-size: 0.7rem;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #047857);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.4);
}

.btn-premium {
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
    color: #000000;
    font-weight: 800;
    box-shadow: var(--shadow-gold);
    animation: pulseGold 2.5s infinite;
}

.btn-kstar {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    font-weight: 800;
    box-shadow: var(--shadow-kstar);
}

.btn-kstar:hover {
    background: #b91c1c;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-input);
}

.btn-gcash {
    background: var(--accent-gcash);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 124, 255, 0.3);
}

.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* HERO SECTION */
.hero-section {
    padding: 32px 20px 20px;
    max-width: 1280px;
    margin: 0 auto;
    text-align: center;
}

.hero-title {
    font-size: 2.3rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.hero-title span {
    background: linear-gradient(135deg, #10b981, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 24px;
}

.search-box-wrapper {
    max-width: 720px;
    margin: 0 auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-lg);
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
}

/* OPENSTREETMAP LEAFLET MAP CONTAINER */
.map-section {
    max-width: 1280px;
    margin: 16px auto 24px;
    padding: 0 20px;
}

.map-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.map-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}

#kx-map {
    width: 100%;
    height: 340px;
    z-index: 10;
}

/* Custom Leaflet Popup Card */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border-color);
    padding: 4px;
}
.leaflet-popup-tip {
    background: var(--bg-card) !important;
}

.map-popup-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}

.map-popup-title {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.map-popup-price {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
}

/* BARANGAYS & CATEGORY FILTER PILLS */
.filter-section {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 20px;
}

.section-label {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pills-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
}

.pill-item {
    padding: 8px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pill-item:hover, .pill-item.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3);
}

/* LISTINGS GRID */
.listings-container {
    max-width: 1280px;
    margin: 24px auto;
    padding: 0 20px;
}

.grid-listings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.listing-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.listing-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(5, 150, 105, 0.5);
}

.card-image-wrap {
    position: relative;
    width: 100%;
    height: 200px;
    background: var(--bg-input);
    overflow: hidden;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.featured-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.kstar-delivery-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.barangay-tag {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-full);
}

.card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1.3;
}

.card-price {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 12px;
}

.card-seller {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.seller-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.seller-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.kx-verified-badge {
    color: #0284c7;
    font-size: 0.95rem;
    font-weight: 700;
}

/* COMPARTMENTALIZED PREMIUM TIERS GRID MODAL */
.premium-modal-card {
    max-width: 680px;
    background: var(--bg-card);
    border: 2px solid var(--accent-gold);
    box-shadow: var(--shadow-gold);
}

.tier-comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.tier-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tier-card.featured {
    border-color: var(--accent-gold);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(5, 150, 105, 0.08));
}

.tier-title {
    font-size: 1.1rem;
    font-weight: 800;
}

.tier-price {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
}

.tier-benefits {
    list-style: none;
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.85rem;
}

.tier-benefits li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tier-benefits li i {
    color: var(--primary);
}

/* MODALS */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 800;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
}

/* MOBILE NAV */
.mobile-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
    z-index: 1000;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}

.mobile-nav-item.active {
    color: var(--primary);
}

@media (max-width: 768px) {
    .tier-comparison-grid {
        grid-template-columns: 1fr;
    }
    .hero-title {
        font-size: 1.7rem;
    }
}

/* ===== Quick-post photos, sharing, seller track record ===== */
.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.photo-grid:empty { display: none; }
.photo-slot { position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius-md); overflow: hidden; background: var(--bg-input); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-slot.busy img { opacity: 0.45; }
.photo-x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(0,0,0,0.65); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; }
.photo-spin { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.4rem; }
.photo-spin i { animation: spin 1s linear infinite; display: inline-block; }
.photo-main { position: absolute; left: 4px; bottom: 4px; font-size: 0.6rem; font-weight: 700; background: var(--primary); color: #fff; padding: 1px 6px; border-radius: 999px; }

.share-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 16px; }
.share-btn { font-size: 0.8rem; padding: 7px 12px; }

.rate-chip { font-size: 0.7rem; font-weight: 700; color: var(--accent-gold); white-space: nowrap; }

.thumb-strip { display: flex; gap: 6px; padding: 8px 20px 0; overflow-x: auto; }
.thumb-strip img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; opacity: 0.6; cursor: pointer; border: 2px solid transparent; flex: 0 0 auto; }
.thumb-strip img.on { opacity: 1; border-color: var(--primary); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--bg-input); border-radius: var(--radius-md); padding: 10px 6px; text-align: center; }
.stat-num { font-weight: 800; font-size: 1.1rem; }
.stat-lbl { font-size: 0.65rem; color: var(--text-secondary); margin-top: 2px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: var(--text-secondary); margin: 3px 0; }
.dist-row > span:first-child { width: 22px; }
.dist-row > span:last-child { width: 22px; text-align: right; }
.dist-bar { flex: 1; height: 8px; background: var(--bg-input); border-radius: 999px; overflow: hidden; }
.dist-bar > div { height: 100%; background: var(--accent-gold); border-radius: 999px; }
.review { padding: 8px 0; border-bottom: 1px solid var(--border-color); }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-card { cursor: pointer; }
.mini-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-md); background: var(--bg-input); }
.mini-title { font-size: 0.72rem; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mini-price { font-size: 0.75rem; font-weight: 700; color: var(--primary); }
@media (max-width: 480px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-secondary.active { border-color: var(--primary); color: var(--primary); background: rgba(16, 185, 129, 0.12); }

/* Founding Member badge */
.founding-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #b45309; background: rgba(245, 158, 11, 0.18); border: 1px solid rgba(245, 158, 11, 0.55); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }

/* Install banner */
.install-banner { position: fixed; left: 12px; right: 12px; bottom: 76px; z-index: 900; display: flex; align-items: center; gap: 10px; background: var(--bg-card, #1e293b); color: var(--text-primary, #f1f5f9); border: 1px solid var(--border-color, rgba(148,163,184,.25)); border-radius: 14px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.35); max-width: 460px; margin: 0 auto; }
.install-banner img { width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto; }
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.8rem; line-height: 1.3; }
.install-text span { color: var(--text-secondary, #94a3b8); }
.install-x { background: none; border: 0; color: var(--text-muted, #94a3b8); font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0 4px; }

/* Footer */
.site-footer { text-align: center; font-size: 0.78rem; color: var(--text-muted); padding: 24px 16px 96px; }
.site-footer a { color: var(--text-secondary); text-decoration: none; margin: 0 8px; }
.site-footer a:hover { text-decoration: underline; }

/* ===== Phone navbar: icons only, never wider than the screen ===== */
@media (max-width: 768px) {
    .nav-container { gap: 8px; flex-wrap: wrap; }
    .brand-logo { font-size: 1.1rem; }
    .nav-actions { gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; margin-left: auto; }
    .nav-actions .btn { padding: 9px 11px; font-size: 0.85rem; }
    .nav-actions .btn span:not(.desktop-only) { display: none; }
    .nav-actions #authBtn span { display: inline; }
    .nav-actions #postListingBtn { display: none; }      /* the bottom "Sell" tab does this on phones */
    .nav-actions .desktop-only { display: none; }
    .btn-premium { animation: none; }
}
@media (max-width: 400px) {
    .brand-badge { display: none; }
}
html, body { max-width: 100%; }
