:root {
    --brand-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --accent-color: #ff416c;
    --bg-body: #f3f5f7;
    --bg-card: rgba(255, 255, 255, 0.92);
    --text-dark: #2d3436;
    --text-gray: #636e72;
    --shadow-card: 0 10px 30px rgba(102, 126, 234, 0.12);
    --shadow-hover: 0 20px 40px rgba(102, 126, 234, 0.25);
    --radius: 16px;
    --radius-lg: 24px;
    --nav-height: 70px;
    --purple-primary: #667eea;
}

/* Reset & Stability Fixes */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    overflow-x: hidden; /* Critical: Prevents horizontal scroll */
    max-width: 100vw;
    height: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Almarai', 'Cairo', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-dark);
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 10px);
}

[lang="fr"] body { font-family: 'Plus Jakarta Sans', sans-serif; }
[dir="ltr"] body { text-align: left; }
[dir="rtl"] body { text-align: right; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(102, 126, 234, 0.2); border-radius: 10px; }

/* ==================== SIDEBAR ==================== */
.sidebar {
    position: fixed; top: 20px; bottom: 20px; width: 280px;
    background: var(--bg-card); backdrop-filter: blur(20px);
    border-radius: var(--radius-lg); padding: 25px 12px;
    z-index: 1001;
    box-shadow: var(--shadow-card);
    display: flex; flex-direction: column;
    border: 1px solid rgba(255,255,255,0.6);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    overflow-y: auto; overflow-x: hidden;
}

[dir="rtl"] .sidebar { right: 20px; left: auto; }
[dir="ltr"] .sidebar { left: 20px; right: auto; }

.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 0 10px 15px; border-bottom: 1px solid rgba(0,0,0,0.05); margin-bottom: 10px; }
.logo-placeholder { width: 40px; height: 40px; background: var(--brand-gradient); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; flex-shrink: 0; overflow: hidden; }
.logo-text-container { display: flex; flex-direction: column; }
.logo-text { font-size: 18px; font-weight: 900; background: var(--brand-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-sub { font-size: 9px; color: var(--text-gray); margin-top: 2px; }

.nav-menu { list-style: none; flex: 1; }
.nav-link { display: flex; align-items: center; padding: 10px 14px; margin-bottom: 2px; border-radius: 12px; color: var(--text-gray); text-decoration: none; font-weight: 600; font-size: 13px; transition: all 0.2s ease; }
[dir="rtl"] .nav-link i { margin-left: 10px; }
[dir="ltr"] .nav-link i { margin-right: 10px; }
.nav-link:hover { color: var(--text-dark); background: rgba(102, 126, 234, 0.06); }
.nav-link.active { background: var(--brand-gradient); color: white; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3); }

.nav-section-title { font-size: 10px; color: var(--text-gray); font-weight: 800; text-transform: uppercase; letter-spacing: 1.2px; padding: 12px 14px 6px; margin-top: 8px; border-top: 1px solid rgba(0,0,0,0.04); }

.sidebar-footer { margin-top: auto; padding-top: 15px; border-top: 1px solid rgba(0,0,0,0.04); }
.social-icons { display: flex; justify-content: center; gap: 12px; margin-bottom: 15px; }
.social-icon { width: 32px; height: 32px; border-radius: 8px; background: rgba(102, 126, 234, 0.1); color: var(--purple-primary); display: flex; align-items: center; justify-content: center; text-decoration: none; transition: all 0.2s; }
.social-icon:hover { background: var(--brand-gradient); color: white; transform: translateY(-2px); }

/* ==================== MAIN CONTENT ==================== */
.main-content { padding: 40px; min-height: 100vh; transition: margin 0.35s ease; }
[dir="rtl"] .main-content { margin-right: 320px; margin-left: 0; }
[dir="ltr"] .main-content { margin-left: 320px; margin-right: 0; }

.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 15px; }

.header-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.greeting h2 { font-size: 22px; font-weight: 800; color: var(--text-dark); margin-bottom: 2px; white-space: nowrap; }

.header-actions { display: flex; gap: 10px; align-items: center; }

.cta-btn { background: var(--brand-gradient); color: white; border: none; padding: 10px 20px; border-radius: 12px; font-weight: 700; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); transition: all 0.2s; text-decoration: none; white-space: nowrap; }
.cta-btn:hover { transform: translateY(-2px); }

.action-btn { width: 44px; height: 44px; border-radius: 12px; border: none; background: var(--bg-card); box-shadow: var(--shadow-card); color: var(--text-gray); cursor: pointer; font-size: 20px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.notification-wrapper { position: relative; }
.notification-badge { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; background: var(--accent-color); border-radius: 50%; border: 2px solid white; }

.lang-switch { display: flex; background: var(--bg-card); border-radius: 12px; box-shadow: var(--shadow-card); overflow: hidden; }
.lang-btn { padding: 10px 16px; border: none; background: transparent; font-family: inherit; font-size: 12px; font-weight: 700; color: var(--text-gray); cursor: pointer; }
.lang-btn.active { background: var(--brand-gradient); color: white; }

/* ==================== HERO SECTION ==================== */
.hero-section { 
    position: relative; 
    background: var(--brand-gradient); 
    border-radius: var(--radius-lg); 
    padding: 30px; 
    margin-bottom: 28px; 
    overflow: hidden; 
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: var(--shadow-card);
}

.hero-ad-space { 
    align-self: flex-start;
    background: rgba(255,255,255,0.2); 
    backdrop-filter: blur(4px);
    border-radius: 8px; 
    padding: 8px 16px; 
    color: white; 
    font-size: 11px; 
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px dashed rgba(255,255,255,0.4);
}

.hero-content { position: relative; z-index: 2; }
.hero-title { font-size: 26px; font-weight: 900; color: white; margin-bottom: 8px; line-height: 1.3; }
.hero-subtitle { font-size: 14px; color: rgba(255,255,255,0.9); margin-bottom: 20px; }
.hero-btn { background: white; color: var(--purple-primary); border: none; padding: 12px 24px; border-radius: 10px; font-weight: 800; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: all 0.2s; }
.hero-shape { position: absolute; bottom: -30px; right: -30px; width: 150px; height: 150px; background: rgba(255,255,255,0.1); border-radius: 50%; z-index: 1; pointer-events: none; }
[dir="rtl"] .hero-shape { right: auto; left: -30px; }

/* ==================== CATEGORIES ==================== */
.categories-section { margin-bottom: 28px; }
.categories-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.categories-title { font-size: 16px; font-weight: 800; color: var(--text-dark); }

.categories-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 4px 14px 4px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.categories-scroll::-webkit-scrollbar { display: none; }

.category-card {
    flex-shrink: 0;
    width: 110px; 
    background: var(--bg-card);
    border-radius: 15px;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.25s ease;
    scroll-snap-align: start;
    text-decoration: none;
    opacity: 1; /* Default state */
}
/* Fade animation class */
.fade-in { animation: fadeIn 0.3s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.category-card:hover { transform: translateY(-4px); box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2); }
.category-card.active { background: var(--brand-gradient); border-color: transparent; }
.category-card.active .category-icon { color: white; background: rgba(255,255,255,0.2); }
.category-card.active .category-name { color: white; }

.category-icon {
    width: 42px; height: 42px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    color: var(--purple-primary);
    transition: all 0.25s ease;
}
.category-name { font-size: 11px; font-weight: 700; color: var(--text-dark); text-align: center; line-height: 1.3; }

/* ==================== ADS GRID & CARDS ==================== */
.ads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 20px; }

.card { background: var(--bg-card); backdrop-filter: blur(10px); border-radius: var(--radius-lg); overflow: hidden; border: 1px solid rgba(255,255,255,0.5); box-shadow: var(--shadow-card); transition: all 0.3s ease; position: relative; }
.card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); }

.card-visual { height: 160px; position: relative; background: #eee; overflow: hidden; }
.visual-auto { background: linear-gradient(135deg, #ff6b6b 0%, #ffa502 100%); }
.visual-realestate { background: linear-gradient(135deg, #576574 0%, #222f3e 100%); }
.visual-jobs { background: linear-gradient(135deg, #48dbfb 0%, #0abde3 100%); }
.visual-services { background: linear-gradient(135deg, #ff9ff3 0%, #f368e0 100%); }
.visual-commercial { background: linear-gradient(135deg, #fdcb6e 0%, #f39c12 100%); }

.card-badge { position: absolute; top: 10px; background: rgba(0,0,0,0.7); color: white; padding: 4px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; backdrop-filter: blur(4px); z-index: 2; }
[dir="rtl"] .card-badge { right: 10px; }
[dir="ltr"] .card-badge { left: 10px; }

.card-content { padding: 16px; }
.card-title { font-size: 15px; font-weight: 800; margin-bottom: 8px; height: 44px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.4; }
.card-price { font-size: 18px; font-weight: 800; background: var(--brand-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 12px; }

/* Enhanced Info Row */
.card-info-row { display: flex; gap: 14px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid rgba(0,0,0,0.04); }
.card-info-item { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-gray); }
.card-info-item i { font-size: 14px; color: var(--purple-primary); }

.card-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; }
.btn-connect { flex: 1; background: linear-gradient(135deg, #25D366 0%, #128C7E 100%); color: white; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; gap: 4px; box-shadow: 0 3px 10px rgba(37, 211, 102, 0.25); transition: all 0.2s; }

/* ==================== PARTNERS ==================== */
.partners-section { margin-top: 40px; padding-top: 20px; border-top: 1px solid rgba(0,0,0,0.05); overflow: hidden; }
.partners-title { font-size: 14px; color: var(--text-gray); font-weight: 700; text-align: center; margin-bottom: 20px; text-transform: uppercase; letter-spacing: 1px; }
.partners-slider { display: flex; gap: 40px; animation: scroll 20s linear infinite; }
.partner-logo { height: 30px; opacity: 0.6; filter: grayscale(100%); flex-shrink: 0; display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text-gray); font-size: 18px; white-space: nowrap; }

@keyframes scroll { 0% { transform: translateX(0); } 100% { transform: translateX(-50%); } }
[dir="rtl"] .partners-slider { animation-name: scroll-rtl; }
@keyframes scroll-rtl { 0% { transform: translateX(-50%); } 100% { transform: translateX(0); } }

/* ==================== BOTTOM NAV ==================== */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255, 255, 255, 0.98); backdrop-filter: blur(20px); box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06); z-index: 1000; border-top: 1px solid rgba(0, 0, 0, 0.04); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav-container { display: flex; justify-content: space-around; align-items: center; max-width: 600px; margin: 0 auto; height: var(--nav-height); position: relative; }
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; text-decoration: none; color: var(--text-gray); width: 20%; height: 100%; }
.bottom-nav-item.active { color: #667eea; }
.bottom-nav-icon { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 2px; }
.bottom-nav-label { font-size: 9px; font-weight: 700; letter-spacing: 0.2px; }
.bottom-nav-spacer { width: 20%; height: 100%; }
.bottom-nav-add-btn { width: 52px; height: 52px; background: var(--brand-gradient); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); position: absolute; top: -18px; left: 50%; transform: translateX(-50%); border: none; z-index: 10; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1200px) {
    .sidebar { top: 0; bottom: 0; width: 280px; border-radius: 0; box-shadow: 0 0 40px rgba(0,0,0,0.2); }
    [dir="rtl"] .sidebar { transform: translateX(100%); right: 0; }
    [dir="ltr"] .sidebar { transform: translateX(-100%); left: 0; }
    .sidebar.active { transform: translateX(0); }
    .main-content { margin-right: 0 !important; margin-left: 0 !important; padding: 20px; }
}
@media (max-width: 600px) {
    .ads-grid { grid-template-columns: 1fr; gap: 15px; }
    .hero-section { padding: 20px; }
    .hero-title { font-size: 22px; }
    .header { gap: 10px; }
    .greeting h2 { font-size: 18px; }
    .cta-btn span { display: none; }
    .cta-btn { padding: 0; width: 44px; height: 44px; justify-content: center; border-radius: 12px; }
}

/* ==================== MODALS & FORMS ==================== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 2000; display: none; justify-content: center; align-items: center; padding: 20px; }
.modal-content { background: var(--bg-card); width: 100%; max-width: 500px; max-height: 85vh; overflow-y: auto; border-radius: var(--radius-lg); padding: 30px; box-shadow: 0 20px 50px rgba(0,0,0,0.2); animation: popIn 0.3s; position: relative; }
@keyframes popIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.modal-header { margin-bottom: 20px; display: flex; align-items: center; gap: 12px; }
.modal-header h3 { font-size: 20px; font-weight: 800; color: var(--text-dark); }
.modal-icon { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; color: white; background: var(--brand-gradient); box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3); }

.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 12px; color: var(--text-gray); }
.form-input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.05); background: var(--bg-body); color: var(--text-dark); font-family: inherit; font-size: 14px; }
.form-input:focus { border-color: #667eea; outline: none; }
.btn-submit { width: 100%; padding: 14px; background: var(--brand-gradient); color: white; border: none; border-radius: 12px; font-weight: 700; font-size: 15px; cursor: pointer; margin-top: 10px; }
.btn-close { position: absolute; top: 15px; background: var(--bg-body); border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 22px; cursor: pointer; color: var(--text-gray); display: flex; align-items: center; justify-content: center; }
[dir="rtl"] .btn-close { left: 15px; }
[dir="ltr"] .btn-close { right: 15px; }

.login-tabs { display: flex; margin-bottom: 20px; background: var(--bg-body); border-radius: 10px; padding: 3px; }
.login-tab { flex: 1; padding: 10px; border: none; background: none; font-family: inherit; font-size: 12px; font-weight: 700; color: var(--text-gray); cursor: pointer; border-radius: 8px; }
.login-tab.active { background: var(--brand-gradient); color: white; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 400px) { .form-row { grid-template-columns: 1fr; } }

.account-content { display: none; text-align: center; padding: 60px 20px; }
.account-content.active { display: block; }
.account-avatar { width: 90px; height: 90px; background: var(--brand-gradient); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 36px; margin: 0 auto 16px; box-shadow: 0 8px 20px rgba(102, 126, 234, 0.25); }