/* ============================================================
   Mobile — up to 639px
   ============================================================ */
@media (max-width: 639px) {
    /* Topbar & Navbar */
    .topbar { display: none; }
    .navbar-inner { height: 52px; }
    .navbar-brand { font-size: 12px; }
    .navbar-nav { display: none; }
    .navbar-actions { gap: 6px; }
    .navbar-actions .btn { font-size: 12px; padding: 6px 12px; }
    .navbar-actions .nav-dropdown { display: none; }
    .navbar-toggle { display: flex; }
    .mobile-menu { display: block; }
    .show-mobile-tablet { display: block; }
    .show-mobile-tablet-inline { display: inline; }
    .hide-mobile-tablet { display: none !important; }

    /* Hero & Search */
    .hero { padding: 20px 16px 24px; }
    .search-box { max-width: 100%; position: relative; z-index: 50; }
    .search-bar { border-radius: 16px; overflow: visible; }
    .search-bar-row { flex-wrap: wrap; height: auto; padding: 8px; gap: 6px; }
    .search-bar-divider { display: none; }
    .search-bar-main { flex: 0 0 100%; padding: 0; order: 1; }
    .search-bar-main input { font-size: 14px; padding: 10px 12px; background: var(--bg-light); border-radius: 10px; }
    .search-bar-filter-toggle { flex: 1 1 0; min-width: 0; padding: 10px 12px; justify-content: center; background: var(--bg-light); border-radius: 10px; font-size: 13px; order: 2; }
    .search-bar-filter-toggle > .bi:first-child { display: none; }
    .search-bar-filter-label { max-width: none; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
    .search-bar-reset { order: 2; position: absolute; right: 16px; top: 18px; z-index: 2; }
    .search-bar-btn { flex: 0 0 100%; border-radius: 10px; height: 44px; margin: 0; order: 3; }
    .filter-dropdown { position: absolute; top: calc(100% + 8px); left: 0; right: auto; bottom: auto; width: 100%; max-width: none; max-height: 60vh; border-radius: 16px; z-index: 300; overflow-y: auto; }
    .search-suggestions { position: absolute; left: 0; right: 0; top: calc(100% + 10px); border-radius: 12px; max-height: 240px; z-index: 250; }

    /* Home */
    .home-layout { grid-template-columns: 1fr; gap: 16px; }
    .home-sidebar { display: none; }
    .mobile-categories { display: block; }
    .mobile-categories-scroll { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .home-content-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .section-title { font-size: 18px; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .section { padding: 32px 0; }

    /* Grids */
    .category-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .category-card { padding: 16px 8px; }
    .category-card-icon { width: 40px; height: 40px; font-size: 18px; }
    .category-card-name { font-size: 12px; }
    .subcat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .subcat-card-img { height: 90px; }
    .subcat-card-body { padding: 8px; }
    .subcat-card-name { font-size: 13px; }
    .cat-page-header { flex-direction: column; align-items: flex-start; }
    .ads-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px 0; }
    .ad-card-img img { height: 130px; }
    .ad-card-body { padding: 8px; }
    .ad-card-title { font-size: 13px; }
    .ad-card-price { font-size: 15px; }
    .ad-card-location { font-size: 11px; }
    .ad-card-badge { font-size: 10px; padding: 2px 6px; }
    .ad-card-seller-name { max-width: 80px; }
    .ad-card-fav { width: 28px; height: 28px; font-size: 14px; }
    .ad-card-desc { font-size: 11px; -webkit-line-clamp: 3; margin-bottom: 4px; }
    .ad-card-engage { gap: 8px; padding: 6px 0; margin-bottom: 6px; }
    .ad-card-like-btn, .ad-card-like-static { font-size: 12px; }
    .fav-header-left h1 { font-size: 18px; }
    .fav-empty { padding: 40px 16px; }
    .fav-empty i { font-size: 48px; }

    /* CTA */
    .cta-box { flex-direction: column; text-align: center; padding: 28px 20px; }
    .cta-content h2 { font-size: 20px; }
    .btn-lg { padding: 12px 24px; font-size: 15px; }

    /* Empty / end */
    .empty-state { padding: 32px 16px; }
    .empty-state i { font-size: 40px; }
    .end-of-ads { padding: 24px 16px; }

    /* Ad Detail */
    .ad-detail { grid-template-columns: 1fr; gap: 16px; padding: 16px 0 32px; }
    .ad-detail-sidebar { position: static; }
    .ad-gallery-main img { max-height: 280px; }
    .ad-gallery-thumbs img { width: 56px; height: 42px; }
    .ad-section { padding: 20px 16px; }
    .ad-details-grid { grid-template-columns: 1fr; }
    .ad-price-card, .ad-seller-card, .ad-safety-card { padding: 20px 16px; }
    .ad-price-main { font-size: 24px; }
    .ad-title { font-size: 16px; }
    .ad-detail .ad-actions { position: fixed; bottom: 60px; left: 0; right: 0; flex-direction: row; background: white; padding: 8px 12px; border-top: 1px solid var(--border); z-index: 90; box-shadow: 0 -2px 12px rgba(0,0,0,0.06); gap: 6px; }
    .ad-detail .ad-action-btn { flex: 1; padding: 10px 6px; font-size: 12px; min-width: 0; }
    .ad-detail .ad-action-btn span { display: none; }
    .ad-detail .ad-action-btn i { margin: 0; font-size: 16px; }
    .ad-seller-stats { flex-direction: column; gap: 8px; }

    /* Seller Profile */
    .seller-hero { padding: 20px 0 24px; }
    .seller-hero-content { gap: 16px; }
    .seller-hero-avatar img, .seller-hero-avatar-placeholder { width: 64px; height: 64px; font-size: 24px; }
    .seller-hero-badge { width: 22px; height: 22px; font-size: 16px; }
    .seller-hero-info h1 { font-size: 18px; }
    .seller-hero-meta { gap: 8px; font-size: 12px; }
    .seller-hero-bio { display: none; }
    .seller-layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 0 32px; }
    .seller-sidebar { position: static; }
    .seller-sidebar .ad-actions { flex-direction: row; gap: 8px; }
    .seller-sidebar .ad-action-btn { flex: 1; padding: 10px 8px; font-size: 13px; min-width: 0; }
    .seller-sidebar .ad-action-btn span { display: none; }
    .seller-sidebar .ad-action-btn i { margin: 0; font-size: 18px; }
    .seller-stats-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .seller-stat-card { padding: 12px; gap: 8px; }
    .seller-stat-icon { width: 34px; height: 34px; font-size: 15px; }
    .seller-stat-card strong { font-size: 16px; }

    /* Admin */
    .admin-sidebar { display: none; }
    .admin-content { margin-left: 0; padding: 16px; }
    .admin-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
    .admin-stat-card { padding: 12px; gap: 8px; }
    .admin-stat-icon { width: 36px; height: 36px; font-size: 15px; }
    .admin-stat-info h3 { font-size: 18px; }
    .admin-stat-info p { font-size: 11px; }
    .admin-settings-header h1 { font-size: 20px; }
    .admin-tabs { gap: 0; padding: 0; }
    .admin-tab { padding: 10px; font-size: 13px; gap: 4px; flex: 1; justify-content: center; }
    .admin-tab-label { display: none; }
    .admin-tab .tab-count { display: none; }
    .admin-card { margin-bottom: 16px; border-radius: 6px; }
    .admin-card-header { padding: 10px 12px; }
    .admin-card-header h2 { font-size: 14px; gap: 6px; }
    .admin-card-body { padding: 10px; }
    .admin-table th, .admin-table td { padding: 8px; font-size: 12px; }
    .admin-table th { font-size: 10px; letter-spacing: 0.3px; }
    .admin-inline-form { flex-direction: column; }
    .admin-inline-form .form-group { min-width: 100%; }
    .admin-inline-form .btn { width: 100%; justify-content: center; }
    .settings-form-grid { grid-template-columns: 1fr; gap: 12px; }
    .admin-tab-panel .btn-primary[type="submit"] { width: 100%; justify-content: center; }

    /* Forms */
    .form-row-2 { grid-template-columns: 1fr; }
    .ts-wrapper { max-width: 100%; }
    .ts-control { font-size: 13px !important; }

    /* Auth */
    .auth-card { padding: 28px 20px; border-radius: 12px; }
    .auth-card-title { font-size: 20px; }
    .auth-card-icon { width: 56px; height: 56px; font-size: 24px; }
    .form-row { flex-direction: column; gap: 0; }
    .auth-options { flex-direction: column; align-items: flex-start; gap: 8px; }

    /* Static pages */
    .page-hero { padding: 24px 0 20px; }
    .page-hero-title { font-size: 20px; margin-bottom: 4px; }
    .page-hero-sub { display: none; }
    .page-hero .breadcrumb { margin-bottom: 8px; font-size: 12px; }
    .page-content { padding: 32px 0; }
    .page-content h2 { font-size: 17px; margin: 28px 0 10px; }
    .info-grid { grid-template-columns: 1fr; gap: 16px; }
    .steps-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
    .contact-grid { grid-template-columns: 1fr; gap: 24px; }
    .stats-row { gap: 12px; padding: 24px 16px; }
    .stat-item { padding: 8px 12px; }
    .stat-item + .stat-item { border-left: none; border-top: 1px solid var(--border); padding-top: 16px; }
    .stat-number { font-size: 28px; }
    .values-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .contact-info-item { padding: 12px; }

    /* Footer */
    .footer { margin-top: 24px; padding: 32px 0 0; }
    .footer-mobile { display: block; text-align: center; padding-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
    .footer-bottom { flex-direction: column; gap: 8px; text-align: center; padding: 12px 0; }
    .footer-copy { font-size: 12px; }

    /* Utils */
    .hide-mobile { display: none !important; }

    main { padding-bottom: 70px; }
}

/* ============================================================
   Tablet — 640px to 899px
   ============================================================ */
@media (min-width: 640px) and (max-width: 899px) {
    .container { padding: 0 24px; }

    /* Navbar: compact nav links + mobile menu for tablet */
    .navbar-inner { height: 56px; }
    .navbar-brand { font-size: 10px; }
    .navbar-nav { display: none; }
    .navbar-actions .nav-dropdown { display: none; }
    .navbar-toggle { display: flex; }
    .mobile-menu { display: block; }
    .show-mobile-tablet { display: block; }
    .show-mobile-tablet-inline { display: inline; }
    .hide-mobile-tablet { display: none !important; }
    .nav-link { font-size: 13px; padding: 6px 10px; }

    /* Hero */
    .hero { padding: 24px 16px 28px; }
    .search-box { max-width: 100%; position: relative; z-index: 50; }
    .filter-dropdown { position: absolute; top: calc(100% + 8px); left: 0; width: 100%; max-width: none; max-height: 60vh; border-radius: 16px; z-index: 300; overflow-y: auto; }

    /* Home: hide sidebar, full-width content */
    .home-layout { grid-template-columns: 1fr; gap: 20px; }
    .home-sidebar { display: none; }
    .mobile-categories { display: block; }
    .ads-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .ad-card-img img { height: 160px; }
    .category-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
    .subcat-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }

    /* Sections */
    .section { padding: 36px 0; }
    .section-title { font-size: 20px; }
    .cta-box { padding: 32px; gap: 20px; }
    .cta-content h2 { font-size: 22px; }

    /* Ad Detail: single column on tablet */
    .ad-detail { grid-template-columns: 1fr; gap: 20px; padding: 20px 0 40px; }
    .ad-detail-sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .ad-gallery-main img { max-height: 400px; }
    .ad-details-grid { grid-template-columns: 1fr 1fr; }
    .ad-safety-card { grid-column: 1 / -1; }

    /* Seller Profile */
    .seller-hero { padding: 28px 0 32px; }
    .seller-hero-avatar img, .seller-hero-avatar-placeholder { width: 76px; height: 76px; font-size: 28px; }
    .seller-hero-info h1 { font-size: 22px; }
    .seller-layout { grid-template-columns: 1fr; gap: 20px; padding: 20px 0 40px; }
    .seller-sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .seller-stats-row { grid-template-columns: repeat(4, 1fr); gap: 10px; }

    /* Admin */
    .admin-sidebar { width: 200px; }
    .admin-sidebar nav a { padding: 10px 16px; font-size: 13px; }
    .admin-content { margin-left: 200px; padding: 20px; }
    .admin-stats { grid-template-columns: repeat(3, 1fr); }
    .admin-tab-label { display: inline; }
    .admin-tab .tab-count { display: inline-flex; }
    .settings-form-grid { grid-template-columns: repeat(2, 1fr); }

    /* Static pages */
    .page-hero { padding: 40px 0 32px; }
    .page-hero-title { font-size: 26px; }
    .info-grid { grid-template-columns: repeat(2, 1fr); }
    .contact-grid { grid-template-columns: repeat(2, 1fr); }
    .steps-grid { grid-template-columns: repeat(2, 1fr); }

    /* Auth */
    .auth-card { max-width: 440px; }

    /* Footer */
    .footer { margin-top: 32px; padding: 40px 0 0; }
    .footer-mobile { display: block; text-align: center; padding-bottom: 24px; border-bottom: 1px solid rgba(255,255,255,0.08); }
    .footer-bottom { flex-direction: column; gap: 8px; text-align: center; padding: 16px 0; }

    main { padding-bottom: 70px; }
}

/* ============================================================
   Small desktop — 900px+
   ============================================================ */
@media (min-width: 900px) {
    .container { padding: 0 24px; }
    .ad-detail { grid-template-columns: 1fr 380px; }
    .ad-detail-sidebar { position: sticky; top: 76px; display: flex; }
    .seller-layout { grid-template-columns: 1fr 360px; }
    .seller-sidebar { position: sticky; top: 76px; display: flex; }
    .seller-stats-row { grid-template-columns: repeat(4, 1fr); }
}

/* ============================================================
   Desktop — 768px+
   ============================================================ */
@media (min-width: 768px) {
    .footer-grid { grid-template-columns: 1.5fr 1fr 1fr 1fr; }
    .ad-details-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   Large desktop — 1024px+
   ============================================================ */
@media (min-width: 1024px) {
    .hero-title { font-size: 44px; }
    .hero { padding: 96px 16px 80px; }
    .ads-grid { grid-template-columns: repeat(4, 1fr); }
    .category-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ============================================================
   XL — 1280px+
   ============================================================ */
@media (min-width: 1280px) {
    .container { max-width: 1280px; }
}

/* ============================================================
   XXL — 1440px+  (grands écrans)
   ============================================================ */
@media (min-width: 1440px) {
    .container { max-width: 1400px; }
    .home-layout { grid-template-columns: 280px 1fr; gap: 32px; }
    .ads-grid { grid-template-columns: repeat(4, 1fr); gap: 24px; }
    .ad-card-img img { height: 220px; }
    .ad-card-body { padding: 14px; }
    .ad-card-title { font-size: 15px; }
    .ad-card-price { font-size: 18px; }
    .ad-card-desc { font-size: 13px; }
    .section-title { font-size: 24px; }
    .hero-title { font-size: 48px; }
    .hero-subtitle { font-size: 18px; }
    .ad-detail { grid-template-columns: 1fr 420px; gap: 32px; }
    .seller-layout { grid-template-columns: 1fr 400px; gap: 32px; }
    .seller-hero-info h1 { font-size: 28px; }
    .seller-stat-card strong { font-size: 22px; }
    .steps-grid { grid-template-columns: repeat(4, 1fr); gap: 36px; }
    .step-card-icon { width: 80px; height: 80px; font-size: 34px; }
    .step-card h3 { font-size: 18px; }
    .step-card p { font-size: 15px; }
    .cta-content h2 { font-size: 28px; }
    .page-hero-title { font-size: 32px; }
    .page-hero-sub { font-size: 17px; }
    .info-grid { grid-template-columns: repeat(3, 1fr); gap: 28px; }
    .category-grid { grid-template-columns: repeat(6, 1fr); gap: 20px; }
}

/* ============================================================
   3XL — 1920px+  (moniteurs Full HD et plus)
   ============================================================ */
@media (min-width: 1920px) {
    .container { max-width: 1680px; }
    .home-layout { grid-template-columns: 300px 1fr; gap: 40px; }
    .ads-grid { grid-template-columns: repeat(5, 1fr); gap: 28px; }
    .ad-card-img img { height: 240px; }
    .ad-card-body { padding: 16px; }
    .ad-card-title { font-size: 16px; }
    .ad-card-price { font-size: 20px; }
    .ad-card-desc { font-size: 14px; }
    .ad-card-seller-name { max-width: 160px; }
    .section { padding: 60px 0; }
    .section-title { font-size: 26px; }
    .hero-title { font-size: 56px; }
    .hero-subtitle { font-size: 20px; }
    .hero { padding: 120px 16px 100px; }
    .ad-detail { grid-template-columns: 1fr 460px; gap: 40px; }
    .ad-gallery-main img { max-height: 560px; }
    .seller-layout { grid-template-columns: 1fr 440px; gap: 40px; }
    .seller-hero-info h1 { font-size: 32px; }
    .seller-stat-card strong { font-size: 24px; }
    .steps-grid { gap: 44px; }
    .step-card-icon { width: 88px; height: 88px; font-size: 38px; }
    .step-card h3 { font-size: 20px; }
    .step-card p { font-size: 16px; }
    .page-hero-title { font-size: 36px; }
    .cta-box { padding: 48px 56px; }
    .cta-content h2 { font-size: 32px; }
    .cta-content p { font-size: 17px; }
    .category-grid { grid-template-columns: repeat(8, 1fr); }
}

/* ============================================================
   4XL — 2560px+  (moniteurs QHD / 4K)
   ============================================================ */
@media (min-width: 2560px) {
    .container { max-width: 2100px; }
    .ads-grid { grid-template-columns: repeat(6, 1fr); gap: 32px; }
    .ad-card-img img { height: 280px; }
    .ad-card-title { font-size: 18px; }
    .ad-card-price { font-size: 22px; }
    .hero-title { font-size: 64px; }
    .hero { padding: 140px 16px 120px; }
    .section { padding: 72px 0; }
    .section-title { font-size: 30px; }
}

/* ============================================================
   Messaging — Responsive
   ============================================================ */
@media (max-width: 767px) {
    .msg-inbox { margin: 12px auto; }
    .msg-inbox-title { font-size: 18px; }
    .msg-item { padding: 10px 8px; gap: 10px; }
    .msg-item-avatar img, .msg-avatar-placeholder { width: 40px; height: 40px; font-size: 15px; }
    .msg-item-name { font-size: 14px; }
    .msg-item-thumb img { width: 44px; height: 44px; }

    .msg-conversation { height: calc(100vh - 115px); height: calc(100dvh - 115px); }
    .msg-conv-header { padding: 8px 10px; gap: 8px; }
    .msg-conv-ad { display: none; }
    .msg-conv-avatar img, .msg-conv-avatar .msg-avatar-placeholder { width: 34px; height: 34px; }
    .msg-conv-user-info strong { font-size: 14px; }
    .msg-conv-body { padding: 12px 8px; }
    .msg-bubble { max-width: 85%; padding: 8px 12px; font-size: 14px; }
    .msg-conv-footer { padding: 8px 10px; }
    .msg-input-wrap textarea { padding: 8px 14px; font-size: 14px; }
    .msg-send-btn { width: 38px; height: 38px; font-size: 16px; }
    .msg-attach-btn { width: 34px; height: 34px; font-size: 18px; }
    .msg-bubble-image img { max-width: 200px; max-height: 200px; }
    .msg-bubble-audio audio { width: 180px; height: 32px; }
    .msg-recording { padding: 10px; gap: 8px; }
    .msg-preview img { height: 60px; }
}

/* ============================================================
   Bottom Navigation — all screens up to 899px
   ============================================================ */
@media (max-width: 899px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
    }
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 11px;
        font-weight: 500;
        color: var(--text-muted);
        padding: 8px 4px 6px;
        flex: 1;
        text-decoration: none;
        transition: color 0.15s;
        min-width: 0;
        position: relative;
    }
    .bottom-nav-item i { font-size: 22px; line-height: 1; }
    .bottom-nav-item span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        display: block;
        text-align: center;
        line-height: 1.2;
    }
    .bottom-nav-item.active,
    .bottom-nav-item:hover { color: var(--primary); }
    .bottom-nav-sell { color: var(--text-muted); }
    .bottom-nav-sell-icon {
        width: 48px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 2px solid var(--success);
        color: var(--success);
        font-size: 24px;
        margin-top: -22px;
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
}
