/* Layout Settings Dynamic Styles */

/* ============================
   Settings Navigation Sticky
   ============================ */

#settings-nav {
    position: sticky;
    top: 1rem; /* 16px from top */
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

/* Desktop: show submenu only when active (preserve current behavior) */
@media (min-width: 641px) {
    .category-submenu {
        display: none;
    }

    .category-item.active + .category-submenu {
        display: block;
    }
}
/* Global submenu controls: allow JS to open/close submenus on any screen size */
.category-submenu {
    display: none;
}

.category-item.active + .category-submenu,
.category-item.submenu-open + .category-submenu {
    display: block !important;
}

/* Rotate arrow when submenu open */
.category-item.submenu-open svg {
    transform: rotate(90deg);
}

/* Smooth scrollbar for settings nav */
#settings-nav::-webkit-scrollbar {
    width: 5px;
}

#settings-nav::-webkit-scrollbar-track {
    background: transparent;
}

#settings-nav::-webkit-scrollbar-thumb {
    background: var(--border-soft);
    border-radius: 2.5px;
}

#settings-nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Ensure settings nav stays above content */
.settings-section {
    position: relative;
    z-index: 1;
}

/* Smooth scroll behavior */
#settings-nav {
    scroll-behavior: smooth;
}

/* Responsive adjustments */
@media (max-height: 768px) {
    #settings-nav {
        max-height: calc(100vh - 3rem);
    }
}

@media (max-height: 600px) {
    #settings-nav {
        max-height: calc(100vh - 4rem);
    }
}

/* ============================
   Header Height Settings
   ============================ */

/* Compact Header - 48px */
body.header-height-compact header {
    min-height: 48px !important;
}

body.header-height-compact header > div {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
}

/* Normal Header - 64px (DEFAULT) */
/* Uses default padding */

/* Large Header - 80px */
body.header-height-large header {
    min-height: 80px !important;
}

body.header-height-large header > div {
    padding-top: 1.25rem !important;
    padding-bottom: 1.25rem !important;
}

body.header-height-large header h1,
body.header-height-large header .text-xl {
    font-size: 1.5rem !important;
}

/* ============================
   Animation Speed Settings
   ============================ */

/* Slow Animations - 500ms */
body.animation-slow .transition-all,
body.animation-slow #sidebar,
body.animation-slow button,
body.animation-slow a,
body.animation-slow .hover\:bg-gray-50 {
    transition-duration: 500ms !important;
}

/* Normal Animations - 300ms (DEFAULT) */
/* No additional CSS needed - this is the default */

/* Fast Animations - 150ms */
body.animation-fast .transition-all,
body.animation-fast #sidebar,
body.animation-fast button,
body.animation-fast a,
body.animation-fast .hover\:bg-gray-50 {
    transition-duration: 150ms !important;
}

/* No Animations */
body.animation-none .transition-all,
body.animation-none #sidebar,
body.animation-none button,
body.animation-none a,
body.animation-none .hover\:bg-gray-50 {
    transition: none !important;
    animation: none !important;
}

/* ============================
   Card Style Settings
   ============================ */

/* Flat Cards - No shadow, subtle background */
body.card-style-flat main .bg-white,
body.card-style-flat main .bg-card {
    box-shadow: none !important;
}

/* Elevated Cards - Default with shadow */
/* No additional CSS needed - this is the default */

/* Bordered Cards - With visible borders */
body.card-style-bordered main .bg-white,
body.card-style-bordered main .bg-card {
    border: 1px solid var(--border-soft) !important;
}

body.card-style-bordered main .bg-white:not(#sidebar),
body.card-style-bordered main .bg-card:not(#sidebar) {
    box-shadow: none !important;
}

/* ============================
   Sidebar Width Settings
   ============================ */

/* Narrow Sidebar - 200px */
body.sidebar-width-narrow #sidebar:not(.sidebar-mini) {
    width: 200px !important;
}

body.sidebar-width-narrow #main-content {
    margin-right: 200px !important;
}

body.sidebar-width-narrow #main-content[data-position="left"] {
    margin-right: 0 !important;
    margin-left: 200px !important;
}

body.sidebar-width-narrow .sidebar-toggle-btn.right {
    right: 210px !important;
}

body.sidebar-width-narrow .sidebar-toggle-btn.left {
    left: 210px !important;
}

/* Normal Sidebar - 256px (DEFAULT) */
/* No additional CSS needed - this is the default */

/* Wide Sidebar - 320px */
body.sidebar-width-wide #sidebar:not(.sidebar-mini) {
    width: 320px !important;
}

body.sidebar-width-wide #main-content {
    margin-right: 320px !important;
}

body.sidebar-width-wide #main-content[data-position="left"] {
    margin-right: 0 !important;
    margin-left: 320px !important;
}

body.sidebar-width-wide .sidebar-toggle-btn.right {
    right: 330px !important;
}

body.sidebar-width-wide .sidebar-toggle-btn.left {
    left: 330px !important;
}

/* ============================
   Content Spacing Settings
   ============================ */

/* Compact Spacing - 12px */
body.spacing-compact main {
    padding: 0.75rem !important; /* 12px instead of 24px */
}

body.spacing-compact .space-y-6 > * + * {
    margin-top: 0.75rem !important; /* 12px instead of 24px */
}

body.spacing-compact .space-y-4 > * + * {
    margin-top: 0.5rem !important; /* 8px instead of 16px */
}

body.spacing-compact .mb-6 {
    margin-bottom: 0.75rem !important;
}

body.spacing-compact .mb-4 {
    margin-bottom: 0.5rem !important;
}

body.spacing-compact .mt-6 {
    margin-top: 0.75rem !important;
}

body.spacing-compact .mt-4 {
    margin-top: 0.5rem !important;
}

body.spacing-compact .p-6 {
    padding: 0.75rem !important;
}

body.spacing-compact .p-4 {
    padding: 0.5rem !important;
}

body.spacing-compact .gap-6 {
    gap: 0.75rem !important;
}

body.spacing-compact .gap-4 {
    gap: 0.5rem !important;
}

/* Normal Spacing - 24px (DEFAULT) */
/* No additional CSS needed - this is the default */

/* Spacious Spacing - 32px */
body.spacing-spacious main {
    padding: 2.5rem !important; /* 40px instead of 24px */
}

body.spacing-spacious .space-y-6 > * + * {
    margin-top: 2.5rem !important; /* 40px instead of 24px */
}

body.spacing-spacious .space-y-4 > * + * {
    margin-top: 2rem !important; /* 32px instead of 16px */
}

body.spacing-spacious .mb-6 {
    margin-bottom: 2.5rem !important;
}

body.spacing-spacious .mb-4 {
    margin-bottom: 2rem !important;
}

body.spacing-spacious .mt-6 {
    margin-top: 2.5rem !important;
}

body.spacing-spacious .mt-4 {
    margin-top: 2rem !important;
}

body.spacing-spacious .p-6 {
    padding: 2.5rem !important;
}

body.spacing-spacious .p-4 {
    padding: 2rem !important;
}

body.spacing-spacious .gap-6 {
    gap: 2.5rem !important;
}

body.spacing-spacious .gap-4 {
    gap: 2rem !important;
}

/* ============================
   Compact Mode - Reduces everything by 30%
   ============================ */

body.compact-mode-enabled {
    font-size: 0.875rem !important; /* 14px instead of 16px */
}

/* Reduce main content padding significantly */
body.compact-mode-enabled main {
    padding: 1rem !important; /* 16px instead of 24px */
}

/* Reduce all padding classes */
body.compact-mode-enabled .p-6 {
    padding: 1rem !important; /* 16px instead of 24px */
}

body.compact-mode-enabled .p-4 {
    padding: 0.75rem !important; /* 12px instead of 16px */
}

body.compact-mode-enabled .p-3 {
    padding: 0.5rem !important; /* 8px instead of 12px */
}

body.compact-mode-enabled .py-4 {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
}

body.compact-mode-enabled .px-4 {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
}

body.compact-mode-enabled .py-3 {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
}

body.compact-mode-enabled .px-3 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

/* Reduce all margin classes */
body.compact-mode-enabled .mb-6 {
    margin-bottom: 1rem !important; /* 16px instead of 24px */
}

body.compact-mode-enabled .mb-4 {
    margin-bottom: 0.75rem !important; /* 12px instead of 16px */
}

body.compact-mode-enabled .mt-6 {
    margin-top: 1rem !important;
}

body.compact-mode-enabled .mt-4 {
    margin-top: 0.75rem !important;
}

body.compact-mode-enabled .space-y-6 > * + * {
    margin-top: 1rem !important;
}

body.compact-mode-enabled .space-y-4 > * + * {
    margin-top: 0.75rem !important;
}

body.compact-mode-enabled .gap-6 {
    gap: 1rem !important;
}

body.compact-mode-enabled .gap-4 {
    gap: 0.75rem !important;
}

/* Reduce font sizes */
body.compact-mode-enabled h1 {
    font-size: 1.75rem !important; /* Smaller */
}

body.compact-mode-enabled h2 {
    font-size: 1.25rem !important; /* Smaller */
}

body.compact-mode-enabled h3 {
    font-size: 1.1rem !important; /* Smaller */
}

body.compact-mode-enabled .text-3xl {
    font-size: 1.75rem !important;
}

body.compact-mode-enabled .text-2xl {
    font-size: 1.25rem !important;
}

body.compact-mode-enabled .text-xl {
    font-size: 1.1rem !important;
}

/* Reduce sidebar items - but maintain readability */
body.compact-mode-enabled #sidebar a {
    padding-top: 0.6rem !important;
    padding-bottom: 0.6rem !important;
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
}

body.compact-mode-enabled #sidebar {
    font-size: 0.9rem !important;
}

/* Keep header normal unless combined with compact header height */
body.compact-mode-enabled:not(.header-height-compact) header > div {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
}

/* Reduce table padding */
body.compact-mode-enabled td,
body.compact-mode-enabled th {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
}

/* Reduce button padding */
body.compact-mode-enabled button,
body.compact-mode-enabled .btn {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
}

/* Reduce card padding */
body.compact-mode-enabled main .bg-white,
body.compact-mode-enabled main .bg-card {
    padding: 1rem !important;
}

/* Reduce form elements */
body.compact-mode-enabled input:not([type="checkbox"]),
body.compact-mode-enabled select,
body.compact-mode-enabled textarea {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    font-size: 0.875rem !important;
}

/* ============================
   Border Radius Settings
   ============================ */

/* Sharp - No border radius */
body.border-radius-sharp .rounded,
body.border-radius-sharp .rounded-lg,
body.border-radius-sharp .rounded-xl,
body.border-radius-sharp .rounded-md,
body.border-radius-sharp .rounded-sm,
body.border-radius-sharp #sidebar,
body.border-radius-sharp .bg-white,
body.border-radius-sharp .bg-card,
body.border-radius-sharp button,
body.border-radius-sharp input,
body.border-radius-sharp select,
body.border-radius-sharp textarea {
    border-radius: 0 !important;
}

/* Soft - Light border radius (8px) - DEFAULT */
body.border-radius-soft .rounded,
body.border-radius-soft .rounded-lg {
    border-radius: 0.5rem !important;
}
body.border-radius-soft .rounded-sm {
    border-radius: 0.25rem !important;
}
body.border-radius-soft .rounded-md {
    border-radius: 0.375rem !important;
}
body.border-radius-soft .rounded-xl {
    border-radius: 0.75rem !important;
}

/* Rounded - Medium border radius (16px) */
body.border-radius-rounded .rounded,
body.border-radius-rounded .rounded-lg,
body.border-radius-rounded #sidebar,
body.border-radius-rounded .bg-white,
body.border-radius-rounded .bg-card,
body.border-radius-rounded button,
body.border-radius-rounded input,
body.border-radius-rounded select,
body.border-radius-rounded textarea {
    border-radius: 1rem !important; /* 16px */
}
body.border-radius-rounded .rounded-sm {
    border-radius: 0.5rem !important;
}
body.border-radius-rounded .rounded-md {
    border-radius: 0.75rem !important;
}
body.border-radius-rounded .rounded-xl {
    border-radius: 1.5rem !important;
}

/* Full - Large border radius (24px) */
body.border-radius-full .rounded,
body.border-radius-full .rounded-lg,
body.border-radius-full #sidebar,
body.border-radius-full .bg-white,
body.border-radius-full .bg-card,
body.border-radius-full button,
body.border-radius-full input,
body.border-radius-full select,
body.border-radius-full textarea {
    border-radius: 1.5rem !important; /* 24px */
}
body.border-radius-full .rounded-sm {
    border-radius: 0.75rem !important;
}
body.border-radius-full .rounded-md {
    border-radius: 1rem !important;
}
body.border-radius-full .rounded-xl {
    border-radius: 2rem !important;
}

/* ============================
   Shadow Level Settings
   ============================ */

/* None - No shadow */
body.shadow-level-none .shadow,
body.shadow-level-none .shadow-sm,
body.shadow-level-none .shadow-md,
body.shadow-level-none .shadow-lg,
body.shadow-level-none .shadow-xl,
body.shadow-level-none #sidebar,
body.shadow-level-none .bg-white,
body.shadow-level-none .bg-card,
body.shadow-level-none header {
    box-shadow: none !important;
}

/* Light - Light shadow - DEFAULT */
body.shadow-level-light .shadow-sm {
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05) !important;
}
body.shadow-level-light .shadow,
body.shadow-level-light .shadow-lg {
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1) !important;
}
body.shadow-level-light .shadow-md {
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1) !important;
}

/* Medium - Medium shadow */
body.shadow-level-medium .shadow-sm {
    box-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.1) !important;
}
body.shadow-level-medium .shadow,
body.shadow-level-medium .shadow-lg,
body.shadow-level-medium #sidebar,
body.shadow-level-medium .bg-white,
body.shadow-level-medium .bg-card,
body.shadow-level-medium header {
    box-shadow: 0 4px 8px 0 rgb(0 0 0 / 0.15), 0 2px 4px -2px rgb(0 0 0 / 0.15) !important;
}
body.shadow-level-medium .shadow-md {
    box-shadow: 0 8px 12px -2px rgb(0 0 0 / 0.15), 0 4px 8px -3px rgb(0 0 0 / 0.15) !important;
}

/* Strong - Strong shadow */
body.shadow-level-strong .shadow-sm {
    box-shadow: 0 4px 8px 0 rgb(0 0 0 / 0.15) !important;
}
body.shadow-level-strong .shadow,
body.shadow-level-strong .shadow-lg,
body.shadow-level-strong #sidebar,
body.shadow-level-strong .bg-white,
body.shadow-level-strong .bg-card,
body.shadow-level-strong header {
    box-shadow: 0 8px 16px 0 rgb(0 0 0 / 0.25), 0 4px 8px -3px rgb(0 0 0 / 0.2) !important;
}
body.shadow-level-strong .shadow-md {
    box-shadow: 0 12px 20px -3px rgb(0 0 0 / 0.25), 0 8px 16px -4px rgb(0 0 0 / 0.2) !important;
}

/* ============================
   Sidebar Style Settings
   ============================ */

/* Mini Sidebar - Icons only */
.sidebar-mini {
    width: 80px !important;
}

.sidebar-mini .sidebar-text {
    display: none;
}

.sidebar-mini:hover {
    width: 256px !important;
}

.sidebar-mini:hover .sidebar-text {
    display: inline-block;
    animation: fadeIn 0.2s ease-in;
}

/* Main content margin adjustment for mini sidebar */
.content-with-mini-sidebar {
    margin-right: 80px !important;
}

.content-with-mini-sidebar-left {
    margin-left: 80px !important;
}

/* Collapsible Sidebar */
.sidebar-collapsible {
    transition: transform 0.3s ease-in-out;
}

.sidebar-collapsible.collapsed {
    transform: translateX(100%);
}

.sidebar-collapsible.collapsed[data-position="left"] {
    transform: translateX(-100%);
}

/* Toggle button for collapsible sidebar */
.sidebar-toggle-btn {
    position: fixed;
    top: 50%;
    z-index: 50;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-muted);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-toggle-btn.right {
    right: 270px;
}

.sidebar-toggle-btn.left {
    left: 270px;
}

.sidebar-toggle-btn.collapsed.right {
    right: 10px;
}

.sidebar-toggle-btn.collapsed.left {
    left: 10px;
}

/* Toggle button in header */
.sidebar-toggle-btn-header {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn-header:hover {
    background: var(--bg-muted);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Adjust main content when sidebar is collapsed */
.content-with-collapsible-sidebar {
    transition: margin 0.3s ease-in-out;
}

.content-with-collapsible-sidebar.sidebar-collapsed {
    margin-right: 0 !important;
}

.content-with-collapsible-sidebar.sidebar-collapsed[data-position="left"] {
    margin-left: 0 !important;
}

/* ============================================
   MOBILE RESPONSIVE STYLES (640px وأقل فقط)
   تنسيقات خاصة بالشاشات الصغيرة فقط
   ============================================ */
@media (max-width: 640px) {
    /* إخفاء السايدبار افتراضياً وجعله bottom sheet */
    /* موبايل: اجعل الشريط يغطي الشاشة بالكامل عند العرض */
    #sidebar {
        position: fixed !important;
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: 0 !important; /* غيّرنا إلى أعلى الشاشة */
        height: 100vh !important; /* يملأ الشاشة بالكامل */
        max-height: 100vh !important;
        transform: translateY(100%) !important;
        border-radius: 0 !important; /* بدون زوايا مستديرة عند ملء الشاشة */
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3) !important;
        z-index: 999 !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        overflow: auto !important;
    }

    /* إظهار السايدبار عند الضغط على زر القائمة */

    /* إلغاء مسافات الأسطر السفليّة للنصوص على الشاشات الصغيرة */
    p {
        margin-bottom: 0 !important;
    }
    /* Sidebar category submenu: hidden by default on mobile; toggled via JS */
    .category-submenu {
        display: none !important;
    }

    .category-item.submenu-open + .category-submenu {
        display: block !important;
    }
    #sidebar.show {
        transform: translateY(0) !important;
    }

    /* اجعل شريط الهيدر للموبايل ثابتاً عند التمرير، فقط على الشاشات الصغيرة */
    header#mobile-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 60 !important;
    }

    /* إزالة الهوامش من المحتوى الرئيسي */
    #main-content,
    .content-with-mini-sidebar,
    .content-with-mini-sidebar-left,
    .content-with-collapsible-sidebar,
    body.sidebar-width-narrow #main-content,
    body.sidebar-width-wide #main-content {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Overlay للسايدبار */
    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        backdrop-filter: blur(4px);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    #sidebar-overlay.show {
        display: block;
        opacity: 1;
    }

    /* تحسين الهيدر للشاشات الصغيرة */
    header {
        position: sticky !important;
        top: 0 !important;
        z-index: 50 !important;
    }

    /* إزالة البادينج من الهيدر على الموبايل فقط */
    header#mobile-header,
    header#mobile-header.bg-card,
    header#mobile-header.bg-white {
        padding: 0 !important;
    }

    /* Mobile Header Buttons - equal padding & icon sizes */
    #mobile-header .sidebar-toggle-btn-header,
    #mobile-header .filters-toggle-btn-header,
    #mobile-header a[href*="/login"],
    #mobile-header a[href*="from=add-ad"],
    #mobile-header a[href*="profile"],
    #mobile-header a[href*="notifications"] {
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important; /* remove internal padding so icons center exactly */
        box-sizing: border-box !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease !important;
    }

    /* unify svg/icon sizes inside mobile header buttons */
    #mobile-header svg,
    #mobile-header a > span {
        width: 18px !important;
        height: 18px !important;
        font-size: 18px !important;
        line-height: 1 !important;
        display: block !important;
    }

    /* Modern Login Button - transparent, icon-centered */
    .mobile-btn-login {
        background: transparent !important;
        border: none !important;
        color: var(--text-main) !important;
        padding: 0 !important;
    }

    .mobile-btn-login:hover {
        opacity: 0.9 !important;
        transform: translateY(-1px) !important;
    }

    .mobile-btn-login:active {
        transform: translateY(0) scale(0.98) !important;
    }

    /* Modern Add Ad Button - transparent with primary-colored icon */
    .mobile-btn-add-ad {
        background: transparent !important;
        border: none !important;
        color: var(--primary) !important;
        padding: 0 !important;
    }

    .mobile-btn-add-ad:hover {
        opacity: 0.95 !important;
        transform: translateY(-1px) !important;
    }

    .mobile-btn-add-ad:active {
        transform: translateY(0) scale(0.98) !important;
    }

    /* إخفاء زر السايدبار العائم في الموبايل */
    .sidebar-toggle-btn:not(.sidebar-toggle-btn-header) {
        display: none !important;
    }

    /* تحسين حقل البحث */
    header form {
        max-width: 100% !important;
        position: relative !important;
    }

    header form input[type="text"] {
        font-size: 13px !important;
        padding: 0.4rem 2rem 0.4rem 0.5rem !important;
        width: 100% !important;
        border-radius: 8px !important;
    }

    header form button[type="submit"] {
        position: absolute !important;
        width: 28px !important;
        height: 28px !important;
        left: auto !important;
        right: 87.5% !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    header form button[type="submit"] svg {
        width: 15px !important;
        height: 15px !important;
    }

    /* تحسين فلتر المدينة */
    #header-city-filter {
        font-size: 12px !important;
        padding: 0.4rem 0.5rem !important;
        height: auto !important;
        border-radius: 8px !important;
    }

    /* تحسين أزرار الأكشن في الهيدر */
    header .flex.items-center.gap-4 {
        gap: 0.5rem !important;
    }

    header a,
    header button:not([type="submit"]) {
        font-size: 13px !important;
        padding: 0.5rem 0.75rem !important;
    }

    /* أيقونة الإشعارات والبروفايل */
    header a.w-10 {
        width: 36px !important;
        height: 36px !important;
    }

    header a svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* تحسين المحتوى الرئيسي */
    main {
        padding: 1rem;
    }

    main > div {
        padding: 0 !important;
    }

    /* تحسين البطاقات */
    .bg-card,
    .bg-white {
        border-radius: 16px !important;
        padding: 0.75rem !important;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08) !important;
    }

    /* تحسين العناوين */
    h1 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 1rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.875rem !important;
    }

    h3 {
        font-size: 1.125rem !important;
        line-height: 1.3 !important;
    }

    /* تحسين الأزرار */
    button:not([type="submit"]):not(.sidebar-toggle-btn-header),
    a.inline-flex,
    .btn {
        padding: 0.75rem 1.25rem !important;
        font-size: 14px !important;
        border-radius: 12px !important;
        font-weight: 500 !important;
    }

    /* أزرار الإرسال - اجعلها مدمجة على الموبايل (بدون padding) */
    button[type="submit"] {
        padding: 0 !important;
        font-size: 15px !important;
        border-radius: 12px !important;
        font-weight: 600 !important;
    }

    /* تحسين الإدخالات */
    input:not([type="submit"]):not([type="button"]):not([type="checkbox"]):not([type="radio"]),
    textarea,
    select {
        padding: 0.75rem 1rem !important;
        font-size: 14px !important;
        border-radius: 12px !important;
        border-width: 1.5px !important;
    }

    textarea {
        /* allow natural height on mobile */
        min-height: auto !important;
    }

    /* تحسين التباعد */
    .space-y-6 > * + * {
        margin-top: 1.25rem !important;
    }

    .space-y-4 > * + * {
        margin-top: 1rem !important;
    }

    .gap-6 {
        gap: 1.25rem !important;
    }

    .gap-4 {
        gap: 1rem !important;
    }

    /* تحسين مظهر السايدبار الداخلي */
    #sidebar .px-3 {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }

    #sidebar nav a {
        padding: 0.875rem 1.25rem !important;
        font-size: 15px !important;
        border-radius: 12px !important;
        min-height: 44px !important;
    }

    /* تحسين اللوجو في السايدبار */
    #sidebar .pt-4 {
        padding-top: 1.25rem !important;
    }

    #sidebar img {
        height: 36px !important;
    }

    #sidebar .text-xl {
        font-size: 1.125rem !important;
    }

    /* شريط السحب للسايدبار */
    #sidebar::before {
        content: '';
        position: absolute;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: 48px;
        height: 5px;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 10px;
        z-index: 1000;
    }

    /* تحسين الجداول */
    table {
        font-size: 13px !important;
    }

    table th,
    table td {
        padding: 0.75rem 0.5rem !important;
    }

    /* جعل الجداول scrollable */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* تحسين النصوص الصغيرة */
    .text-sm {
        font-size: 13px !important;
    }

    .text-xs {
        font-size: 11px !important;
    }

    /* تحسين الفوتر في السايدبار */
    #sidebar footer {
        padding: 1rem 1.25rem !important;
    }

    #sidebar footer p {
        font-size: 12px !important;
    }

    /* إزالة تأثيرات الحوم للتاتش */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    button:active,
    a:active {
        transform: scale(0.98);
    }

    /* تحسين Flash Messages للموبايل */
    #toast-container {
        top: 1rem !important;
        left: 1rem !important;
        right: 1rem !important;
        width: auto !important;
    }

    .toast-message {
        padding: 1rem !important;
        font-size: 14px !important;
        border-radius: 12px !important;
    }

    /* تحسين المسافات في الوضع المضغوط */
    body.compact-mode-enabled main {
        padding: 0.75rem !important;
    }

    body.compact-mode-enabled .bg-card,
    body.compact-mode-enabled .bg-white {
        padding: 1rem !important;
    }

    /* تعطيل تأثيرات عرض السايدبار المختلفة في الموبايل */
    body.sidebar-width-narrow #sidebar,
    body.sidebar-width-wide #sidebar,
    .sidebar-mini {
        width: 100% !important;
    }

    .sidebar-mini .sidebar-text {
        display: inline-block !important;
    }

    /* تحسين loader */
    #app-loader h1 {
        font-size: 2.5rem !important;
        margin-bottom: 2rem !important;
    }
}

/* ============================================
   زر الفلاتر - خارج media query
   ============================================ */

/* زر الفلاتر في الهيدر - نفس تنسيق زر السايدبار */
.filters-toggle-btn-header {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: none; /* مخفي افتراضياً */
    align-items: center;
    justify-content: center;
}

.filters-toggle-btn-header:hover {
    background: var(--bg-muted);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* إظهار الزر فقط في الشاشات الصغيرة */
@media (max-width: 767px) {
    .filters-toggle-btn-header {
        display: flex;
    }
}

/* إخفاء صريح في الشاشات الكبيرة والمتوسطة */
@media (min-width: 768px) {
    .filters-toggle-btn-header {
        display: none !important;
    }
}

/* ============================================
   تنسيقات خاصة بأزرار الفلاتر (الموبايل فقط)
   ============================================ */
@media (max-width: 640px) {

    /* Overlay للفلاتر */
    #filters-bar::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 39;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    #filters-bar.filters-open::before {
        opacity: 1;
        pointer-events: auto;
    }

    /* محتوى الفلاتر - overlay من الأعلى */
    .filters-content {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        padding: 1.5rem 1rem 1rem 1rem;
        border-radius: 0 0 20px 20px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
        transform: translateY(-100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 999;
        max-height: 90vh;
        overflow-y: auto;
    }

    .filters-content.filters-collapsed {
        transform: translateY(-100%) !important;
        pointer-events: none;
    }

    .filters-content:not(.filters-collapsed) {
        transform: translateY(60px) !important;
        pointer-events: auto;
    }

    /* تحسين شريط الفلاتر نفسه */
    #filters-bar {
        position: relative;
    }

    /* تحسين أزرار الترتيب */
    #filters-bar a {
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.5rem !important;
        font-size: 13px !important;
        font-weight: 500 !important;
        border-radius: 10px !important;
        transition: all 0.2s ease !important;
        white-space: nowrap !important;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }

    /* أزرار الترتيب - الحالة العادية */
    #filters-bar a:not([class*="bg-yellow-500"]):not([class*="bg-blue-500"]):not([class*="bg-red-500"]):not([class*="bg-green-500"]) {
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
    }

    /* أزرار الترتيب - الحالة النشطة */
    #filters-bar a[class*="bg-yellow-500"],
    #filters-bar a[class*="bg-blue-500"],
    #filters-bar a[class*="bg-red-500"],
    #filters-bar a[class*="bg-green-500"] {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
        transform: translateY(-1px);
    }

    /* تحسين الأيقونات داخل الأزرار */
    #filters-bar a svg {
        width: 16px !important;
        height: 16px !important;
        flex-shrink: 0;
    }

    /* تحسين نص "الترتيب:" */
    #filters-bar .flex.items-center.gap-2 {
        margin-bottom: 0.25rem !important;
        width: 100%;
    }

    #filters-bar .flex.items-center.gap-2 span {
        font-size: 14px !important;
        font-weight: 600 !important;
    }

    /* Grid للأزرار */
    #filters-bar .flex.flex-wrap.gap-2.flex-1 {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* جعل الأزرار تملأ العرض */
    #filters-bar .flex.flex-wrap.gap-2.flex-1 a {
        width: 100% !important;
    }

    /* تحسين تأثير اللمس */
    #filters-bar a:active {
        transform: scale(0.97) !important;
    }

    #mobile-filters-toggle:active {
        transform: scale(0.98) !important;
    }

    /* إخفاء الزر في الشاشات المتوسطة والكبيرة */
    @media (min-width: 768px) {
        #mobile-filters-toggle {
            display: none !important;
        }
        
        .filters-content {
            position: static !important;
            transform: none !important;
            max-height: none !important;
            padding: 0 !important;
            box-shadow: none !important;
            border-radius: 0 !important;
        }
        
        #filters-bar::before {
            display: none !important;
        }
    }

    /* شريط السحب في overlay */
    .filters-content > div:first-child {
        position: relative;
    }

    /* تحسين زر الإغلاق */
    .filters-content button[onclick*="toggleMobileFilters"] {
        transition: all 0.2s ease;
        position: absolute !important;
        top: 1.25rem !important;
        left: -1rem !important;
        z-index: 1000 !important;
    }

    .filters-content button[onclick*="toggleMobileFilters"]:hover {
        background: var(--bg-muted);
        border-radius: 50%;
    }
}

/* ============================================
   Styles للشاشات الكبيرة والمتوسطة (≥768px)
   إرجاع أزرار Login و Add Ad للعرض الطبيعي
   ============================================ */
@media (min-width: 768px) {
    /* عرض أزرار الدخول والإضافة بشكل عادي */
    header a[href*="/login"]:not([href*="from"]) {
        padding: 0.5rem 1rem !important;
        width: auto !important;
        height: auto !important;
        border: 1px solid var(--border-soft) !important;
        background: transparent !important;
        font-size: 0.875rem !important;
        gap: 0.5rem !important;
    }

    header a[href*="/login"]:not([href*="from"]) span:first-child {
        display: inline !important;
    }

    header a[href*="/login"]:not([href*="from"]) span:nth-child(2) {
        font-size: 1.125rem !important;
    }

    header a[href*="from=add-ad"] {
        padding: 0.5rem 1.25rem !important;
        width: auto !important;
        height: auto !important;
        border-radius: 0.5rem !important;
        font-size: 0.875rem !important;
        background: var(--primary) !important;
        color: white !important;
        border: none !important;
    }

    header a[href*="from=add-ad"]::before {
        display: none !important;
        content: none !important;
    }
}

