/* Responsive Design */

/* Tablet & Mobile Navigation */
@media (max-width: 768px) {
    .hero h1 {
        font-size: 2.5rem;
    }

    .main-nav {
        padding: 0.5rem 0;
        height: 150px;
        /* Auto height for 1 row */
        background: var(--header-bg) !important;
    }

    .nav-wrapper {
        flex-direction: column;
        /* Stack vertically */
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        align-items: center;
    }

    /* Only apply flex to visible nav-items */
    .nav-items:not(.hidden) {
        width: 100%;
        display: flex !important;
        flex-wrap: nowrap;
        /* No wrapping */
        justify-content: space-around;
        /* Distribute evenly */
        align-items: center;
        gap: 0;
        padding: 0;
        margin: 0;
        border: none;
    }

    /* Center the login button if it's the only item */
    /* Hide login button on mobile */
    #auth-links.nav-items {
        display: none !important;
    }

    .logo {
        font-size: 2rem !important;
        margin-bottom: 0.5rem;
    }

    .nav-items a {
        width: auto;
        padding: 0.5rem;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        position: relative;
        color: rgba(255, 255, 255, 0.9);
        text-decoration: none;
        transition: color 0.3s ease;
        flex: 1;
        /* Equal width */
    }

    .nav-items a.active,
    .nav-items a:hover {
        color: white;
    }

    /* Show text labels on mobile */
    .nav-items a>span:not(.badge) {
        display: block !important;
        font-size: 0.75rem;
        margin-top: 4px;
        font-weight: 500;
        text-align: center;
        line-height: 1.2;
    }

    .nav-items a i {
        font-size: 1.5rem;
        margin-bottom: 0;
        color: white;
    }

    /* Reset button styles for logout/login on mobile */
    .nav-items .btn-main {
        background: transparent !important;
        padding: 0.25rem;
        box-shadow: none !important;
        color: white !important;
        width: 22%;
        /* Match other items */
        border: none !important;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .nav-items .btn-main:hover {
        background: rgba(255, 255, 255, 0.1) !important;
        color: white !important;
        transform: none !important;
    }

    /* Fix notification wrapper alignment */
    .notification-wrapper {
        width: 22%;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .notification-wrapper a {
        width: 100% !important;
        padding: 0.25rem !important;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    /* Prevent overflow in nav items */
    .nav-items a,
    .notification-wrapper {
        max-width: 25%;
        /* Safety cap */
        box-sizing: border-box;
    }

    .notification-dropdown {
        position: fixed !important;
        top: 70px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 95vw !important;
        max-width: 380px !important;
        max-height: 80vh !important;
        right: auto !important;
        z-index: 99999 !important;
        background: #ffffff !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        backdrop-filter: blur(100px) !important;
        -webkit-backdrop-filter: blur(100px) !important;
        border-radius: 12px !important;
        display: flex;
        flex-direction: column;
    }

    .notification-list {
        max-height: none !important;
        overflow-y: auto !important;
        flex-grow: 1;
    }

    /* Ensure text doesn't overflow */
    .nav-items a>span:not(.badge) {
        display: block !important;
        font-size: 0.75rem;
        /* Slightly smaller to fit */
        margin-top: 4px;
        font-weight: 500;
        text-align: center;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
    }

    .details-info {
        grid-template-columns: 1fr;
    }

    .filters-wrapper {
        flex-direction: column;
        align-items: stretch;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    .chat-container {
        grid-template-columns: 1fr;
        height: calc(100vh - 140px);
    }

    .chat-sidebar {
        display: none;
        /* Toggle via JS ideally, or stack */
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .chat-sidebar.active {
        display: flex;
    }

    .chat-window {
        display: flex;
    }

    .chat-window.hidden-mobile {
        display: none;
    }

    /* Profile Mobile Fixes */
    .profile-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.5rem;
        padding: 1.5rem;
    }

    .profile-info {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .profile-text {
        width: 100%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .profile-text h2 {
        text-align: center !important;
        word-break: break-word;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    .profile-text p {
        justify-content: center;
        word-break: break-all;
        /* Ensure long emails don't overflow */
    }

    .profile-stats {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .stat-card {
        flex: 1;
        min-width: 80px;
        padding: 0.75rem;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

/* Mobile Details Fix */
@media (max-width: 768px) {
    .details-box {
        padding: 1.5rem;
        margin-top: 1rem;
        overflow-x: hidden;
        /* Prevent overflow */
        width: 100%;
    }

    .wrapper {
        padding: 0 24px;
        overflow-x: hidden;
        width: 100%;
    }

    .details-gallery {
        grid-template-columns: 1fr;
    }

    .details-info {
        gap: 2rem;
    }

    .details-header h2 {
        font-size: 1.8rem;
        word-break: break-word;
    }

    .btn-back {
        display: inline-flex !important;
        margin-bottom: 1rem;
        position: relative;
        z-index: 50;
        cursor: pointer;
        padding: 0.5rem 1rem;
        /* Ensure touch target size */
    }
}

/* Mobile Chat */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 140px);
        border: none;
        border-radius: 0;
    }

    .chat-sidebar {
        width: 100%;
        display: flex;
    }

    .chat-window {
        display: none;
        width: 100%;
    }

    .chat-container.mobile-chat-active .chat-sidebar {
        display: none;
    }

    .chat-container.mobile-chat-active .chat-window {
        display: flex;
        padding-right: 0;
    }

    .btn-back-chat {
        display: block;
    }
}

/* Mobile Reviews & Grid */
@media (max-width: 600px) {
    .reviews-summary-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .rating-distribution {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 1100px) {
    .listings-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 800px) {
    .listings-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .wrapper {
        padding: 0 24px;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Adjust main nav for mobile */
    .main-nav {
        backdrop-filter: blur(20px);
        background: rgba(15, 23, 42, 0.8);
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .nav-wrapper {
        justify-content: center;
        /* Center logo on mobile */
    }

    /* Hide default auth links if not handled by desktop-only */
    #auth-links,
    #user-links {
        display: none;
    }
}

@media (max-width: 480px) {
    .listings-grid {
        grid-template-columns: 1fr !important;
        /* Force 1 column */
        gap: 1.5rem;
        padding-left: 16px;
        padding-right: 16px;
    }

    .card-image {
        height: 220px;
        /* Larger image for single column */
    }

    .item-card h3 {
        font-size: 1rem;
    }

    .price {
        font-size: 1.2rem;
    }

    .wrapper {
        padding-bottom: 90px;
        /* Space for bottom nav */
    }

    .item-card {
        border: none;
        background: transparent;
        /* Cleaner look */
    }

    .card-image {
        border-radius: 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .card-content {
        padding: 0.75rem 0.25rem;
    }

    .btn-details {
        background: rgba(255, 255, 255, 0.1);
        border: none;
    }

    .filters-wrapper {
        display: flex !important;
        padding: 1rem;
        background: transparent;
        border: none;
        backdrop-filter: none;
        margin-bottom: 1rem;
    }

    .filter-select {
        display: none;
        /* Hide dropdown, use scroll instead */
    }
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.7rem;
    gap: 4px;
    width: 60px;
    transition: all 0.2s ease;
}

.nav-item i {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

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

.nav-item.active i {
    transform: translateY(-2px);
}

/* Center Floating Button (Sell) */
.nav-item-center {
    position: relative;
    top: -25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

.center-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px var(--primary-glow);
    border: 4px solid #0f172a;
    /* Match bg to create cutout effect */
    color: white;
    font-size: 1.8rem;
    transition: transform 0.2s;
}

.center-btn:active {
    transform: scale(0.95);
}

.nav-item-center span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.icon-wrapper {
    position: relative;
}

.badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: var(--danger-color);
    border-radius: 50%;
    border: 1px solid #0f172a;
}