/* --- Marketplace Specific Styles (Modern UI V2) --- */
:root {
    --market-bg: #030712;
    --market-card-bg: rgba(30, 41, 59, 0.4);
    --market-accent: #bc00ff;
    --market-text-gold: #fbbf24;
    --market-teal: #00f2ff;
    --glass-nav: rgba(3, 7, 18, 0.7);
}

body {
    background-color: var(--market-bg);
    color: #f8fafc;
    overflow-x: hidden;
    font-family: 'Outfit', 'Noto Sans Thai', sans-serif;
    margin: 0;
}

/* --- Navigation Bar --- */
.modern-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 30px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
    border-bottom: 1px solid transparent;
    box-sizing: border-box;
    /* Critical for padding */
}

.modern-nav.scrolled {
    background: var(--glass-nav);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Base Responsive Fixes */
@media (max-width: 992px) {

    .modern-nav,
    .modern-nav.scrolled {
        padding: 10px 15px;
    }
}

.nav-brand {
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    font-size: var(--fs-logo);
    /* Standardized */
    letter-spacing: -1px;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    height: 70px;
    /* Increased from 45px */
    width: auto;
    filter: drop-shadow(0 0 15px rgba(0, 242, 255, 0.4));
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nav-brand:hover .nav-logo {
    transform: rotate(-5deg) scale(1.1);
}

.brand-accent {
    color: var(--market-accent);
}

.nav-links {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-shrink: 0;
}

.nav-link-item {
    text-decoration: none;
    color: #cbd5e1;
    font-weight: 500;
    font-size: 0.9rem;
    transition: 0.3s;
    padding: 8px 18px;
    border-radius: 50px;
}

.nav-link-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.nav-link-btn {
    text-decoration: none;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 22px;
    border-radius: 50px;
    font-size: 0.9rem;
    transition: 0.3s;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 255, 255, 0.1);
}

/* --- Global Header Identity & User Actions --- */
.header-user-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 10px;
    padding-left: 15px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    /* Important: Don't let this be squeezed out */
}

.user-status-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.06);
    padding: 4px 12px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    cursor: pointer;
    transition: all 0.3s ease;
}

.user-status-card:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.user-info-text {
    text-align: right;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    line-height: 1.1;
}

.user-role {
    font-size: 0.65rem;
    color: var(--market-teal);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--market-teal), #3b82f6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: white;
    box-shadow: 0 4px 10px rgba(0, 242, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#global-logout-btn {
    background: rgba(239, 68, 68, 0.15) !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
    color: #f87171 !important;
    width: 34px !important;
    height: 34px !important;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#global-logout-btn:hover {
    background: rgba(239, 68, 68, 0.4) !important;
    color: white !important;
    transform: scale(1.1);
}

/* --- Hero Section --- */
.hero-section {
    height: 90vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    margin-top: -80px;
    /* Pull up behind nav */
}

/* Enhanced Gradient Overlay */
.hero-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(3, 7, 18, 0.2) 0%, rgba(3, 7, 18, 0.9) 100%);
    z-index: 1;
}

/* Gradient text accent */
.hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
    width: 100%;
    max-width: 900px;
    padding: 0 20px;
    margin-top: 60px;
}

.hero-title {
    font-size: 3.8rem;
    /* Hero is exceptionally larger, but consistent */
    font-weight: 800;
    letter-spacing: -2px;
    color: white;
    margin-bottom: 15px;
    line-height: 1.1;
    text-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.hero-subtitle {
    font-size: 1.3rem;
    color: #cbd5e1;
    font-weight: 300;
    margin-bottom: 50px;
    letter-spacing: 0.5px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Floating Search Bar (Refined) --- */
.search-container {
    background: rgba(255, 255, 255, 0.7);
    /* Lighter for readability */
    backdrop-filter: blur(20px);
    padding: 8px 15px;
    border-radius: 60px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    display: inline-flex;
    align-items: center;
    width: 100%;
    max-width: 750px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease;
}

.search-container:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

.search-input {
    background: transparent;
    border: none;
    color: #334155;
    /* Darker text for input */
    font-size: 1.1rem;
    font-weight: 500;
    flex-grow: 1;
    padding: 10px 15px;
    outline: none;
}

/* Custom Select Dropdowns (Modern Glass) */
.filter-dropdown {
    padding: 12px 40px 12px 25px;
    /* Extra right padding for arrow */
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    backdrop-filter: blur(10px);
    cursor: pointer;
    transition: all 0.3s ease;

    /* Remove Default Arrow & Add Custom One */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 16px;
}

/* Apply specific color for options to be readable on white/dark bg */
.filter-dropdown option {
    background-color: #1e293b;
    /* Dark Slate */
    color: white;
    padding: 10px;
}

.filter-dropdown:hover {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: var(--market-accent);
    box-shadow: 0 0 15px rgba(188, 0, 255, 0.2);
    transform: translateY(-2px);
}

.filter-dropdown:focus {
    border-color: var(--market-teal);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
}

.search-btn {
    background: linear-gradient(135deg, var(--market-accent), #7000ff);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.search-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(188, 0, 255, 0.4);
}

/* --- Stats Box --- */
.stat-box {
    text-align: center;
    padding: 0 25px;
}

.stat-box+.stat-box {
    border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.stat-val {
    font-size: var(--fs-stat);
    /* Standardized */
    font-weight: 800;
    margin-bottom: 5px;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.stat-label {
    font-size: 0.85rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Collections (Cards) --- */
.cat-card {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.8));
    padding: 30px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.cat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.03), transparent);
    transform: translateX(-100%);
    transition: 0.5s;
}

.cat-card:hover::before {
    transform: translateX(100%);
}

.cat-card:hover {
    transform: translateY(-10px);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.cat-icon-box {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    font-size: 1.8rem;
    transition: transform 0.3s;
}

.cat-card:hover .cat-icon-box {
    transform: scale(1.1) rotate(5deg);
}

/* --- Properties Grid & Cards (CRITICAL FIX) --- */
.collection-grid,
#featured-projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 30px;
    padding: 40px 10%;
    width: 100%;
    box-sizing: border-box;
}

.card,
.project-card {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
}

.card:hover,
.project-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border-color: var(--market-accent);
}

.card-img-container,
.project-img-container {
    width: 100%;
    height: 220px;
    /* Fixed Height */
    position: relative;
    overflow: hidden;
}

.card-img,
.project-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Crop to fit */
    transition: transform 0.5s ease;
}

.card:hover .card-img,
.project-card:hover img {
    transform: scale(1.1);
}

.card-content {
    padding: 20px;
    color: #cbd5e1;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f8fafc;
    margin: 5px 0 10px 0;
    line-height: 1.4;
}

.card-price {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--market-teal);
    margin-bottom: 5px;
}

.ai-badge {
    display: inline-block;
    background: linear-gradient(90deg, #10b981, #059669);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.card-tag {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 12px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 60px;
    color: #64748b;
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: #020617;
}

/* --- AI Chatbot Interface (Modern Glass) --- */
#ai-chat-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
}

#chat-toggle-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--market-accent), #7a20c2);
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(188, 0, 255, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#chat-toggle-btn:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 15px 40px rgba(188, 0, 255, 0.6);
}

.chat-btn-pulse {
    animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(188, 0, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(188, 0, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(188, 0, 255, 0);
    }
}

#chat-window {
    position: absolute;
    bottom: 85px;
    right: 0;
    width: 380px;
    height: 550px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8);
}

.chat-hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.chat-header {
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--market-teal), #0891b2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    color: black;
}

#close-chat {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.2rem;
}

#chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--market-accent) transparent;
}

.message {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: msg-fade-in 0.3s ease;
}

@keyframes msg-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
    border-bottom-left-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background: var(--market-accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    gap: 10px;
    align-items: center;
}

#user-input {
    flex-grow: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 12px 20px;
    border-radius: 50px;
    outline: none;
    font-size: 0.9rem;
}

#send-msg {
    background: var(--market-accent);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
}

#send-msg:hover {
    transform: scale(1.1);
}

/* --- Responsive Optimizations (Mobile Standard) --- */
@media (max-width: 768px) {
    .modern-nav {
        padding: 12px 20px;
        background: rgba(3, 7, 18, 0.6);
        /* Slightly darker on mobile nav for contrast */
        backdrop-filter: blur(10px);
    }

    .nav-brand {
        font-size: 1.2rem;
        gap: 8px;
    }

    .nav-logo {
        height: 55px;
        /* Increased from 35px for better visibility */
    }

    .brand-text {
        display: inline;
    }

    .brand-accent {
        display: none;
    }

    @media (max-width: 500px) {
        .brand-text {
            display: none;
        }
    }

    .nav-links {
        gap: 8px;
        align-items: center;
    }

    .nav-link-item {
        display: none;
        /* Hide 'หน้าหลัก' on small screens to save space */
    }

    /* Logged in state mobile fixes */
    .header-user-actions {
        padding-left: 8px;
        margin-left: 5px;
        gap: 8px;
    }

    .user-status-card {
        padding: 4px 8px;
    }

    .user-info-text {
        display: none;
        /* Hide name/role on mobile tablets */
    }

    .user-avatar {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem !important;
    }

    @media (max-width: 600px) {
        .user-status-card div:first-child {
            display: none;
            /* Hide name/role text on tablets/mobile to keep nav clean */
        }

        .nav-link-btn {
            padding: 8px 12px !important;
            font-size: 0.8rem !important;
        }

        #global-logout-btn {
            width: 34px !important;
            height: 34px !important;
            background: rgba(239, 68, 68, 0.3) !important;
            /* More visible red background */
            border-color: rgba(239, 68, 68, 0.6) !important;
            color: #fff !important;
            /* White icon for better contrast */
            flex-shrink: 0;
        }

        .nav-link-btn span {
            display: none;
            /* Icon only on micro devices */
        }
    }

    .nav-link-btn {
        padding: 8px 15px;
        font-size: 0.8rem;
    }

    .hero-section {
        height: auto;
        min-height: 100vh;
        padding-top: 100px;
        padding-bottom: 50px;
        margin-top: 0;
        /* Reset pull-up to avoid overlaps */
    }

    .hero-title {
        font-size: 2.2rem;
        margin-bottom: 20px;
    }

    .hero-subtitle {
        font-size: 1rem;
        margin-bottom: 40px;
    }

    /* Stack Search & Filters */
    .search-container {
        flex-direction: column;
        padding: 20px;
        border-radius: 25px;
        gap: 15px;
        width: 100%;
        max-width: 100%;
    }

    .search-container i {
        display: none;
        /* Hide icon on mobile to save horizontal space */
    }

    .search-input {
        text-align: center;
        padding: 5px;
        font-size: 1rem;
    }

    .search-btn {
        width: 100%;
        padding: 16px;
    }

    /* Filter Dropdowns Grid on Mobile */
    .hero-content>div[style*="flex-wrap: wrap"] {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px !important;
        margin-top: 20px !important;
    }

    .filter-dropdown {
        width: 100%;
        padding: 12px 30px 12px 15px;
        font-size: 0.85rem;
        background-position: right 10px center;
    }

    /* Full width for the last filter if odd */
    .filter-dropdown:last-child:nth-child(odd) {
        grid-column: span 2;
    }

    /* Stats Mobile Layout */
    .hero-content>div[style*="gap: 40px"] {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 15px !important;
        margin-top: 50px !important;
    }

    .stat-box {
        padding: 10px 5px;
        border-left: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .stat-box:last-child {
        border-bottom: none;
    }

    .stat-val {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.65rem;
    }

    /* Collections & Grid */
    .collection-grid,
    #featured-projects-grid {
        padding: 40px 5%;
        gap: 20px;
    }

    /* Specialized Collections titles */
    section[style*="padding: 80px 10%"] {
        padding: 60px 5% !important;
    }

    div[style*="font-size: 2.2rem"] {
        font-size: 1.6rem !important;
    }

    /* Chatbot adjustments */
    #ai-chat-wrapper {
        bottom: 20px;
        right: 20px;
    }

    #chat-toggle-btn {
        width: 55px;
        height: 55px;
        font-size: 1.4rem;
    }

    #chat-window {
        width: calc(100vw - 40px);
        height: 70vh;
        bottom: 75px;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .hero-title {
        font-size: 1.8rem;
    }

    .hero-content>div[style*="gap: 15px"] {
        grid-template-columns: 1fr;
        /* Stack filters fully on small phones */
    }

    .filter-dropdown:last-child:nth-child(odd) {
        grid-column: span 1;
    }
}