@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    --tm-primary:     #343892;
    --tm-primary-d:   #2a2e7a;
    --tm-primary-l:   #eef0fb;
    --tm-secondary:   #f6c657;
    --tm-secondary-d: #e0a800;
    --tm-secondary-l: #fff8e6;
    --tm-white:       #ffffff;
    --tm-gray-50:     #f8f9fa;
    --tm-gray-100:    #f1f3f5;
    --tm-gray-200:    #e9ecef;
    --tm-gray-400:    #adb5bd;
    --tm-gray-600:    #6c757d;
    --tm-gray-800:    #343a40;
    --tm-danger:      #e24b4a;
    --tm-shadow-sm:   0 2px 8px rgba(52,56,146,0.08);
    --tm-shadow-md:   0 4px 16px rgba(52,56,146,0.12);
    --tm-radius:      12px;
    --tm-radius-sm:   8px;
    --tm-radius-pill: 50px;
    --tm-transition:  all 0.22s ease;
    --tm-font:        'DG 3asomy','Cairo','Tajawal',sans-serif;
}

/* ============================================================
   WRAPPER
============================================================ */
.tm-filter-wrapper {
    direction: rtl;
    font-family: var(--tm-font);
    margin-bottom: 24px;
    position: relative;
}

/* ============================================================
   DESKTOP FILTER BAR
============================================================ */
.tm-filter-bar {
    background: var(--tm-white);
    border: 1px solid var(--tm-gray-200);
    border-radius: var(--tm-radius);
    box-shadow: var(--tm-shadow-sm);
    overflow: hidden;
}

/* --- صف التصنيفات --- */
.tm-cat-row {
    position: relative;
    border-bottom: 1px solid var(--tm-gray-200);
    padding: 0 40px;
}

.tm-cat-chips {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
}
.tm-cat-chips::-webkit-scrollbar { display: none; }

/* Base chip */
.tm-cat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: var(--tm-radius-pill);
    border: 1.5px solid var(--tm-gray-200);
    background: var(--tm-white);
    color: var(--tm-gray-800);
    font-family: var(--tm-font);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--tm-transition);
    flex-shrink: 0;
    text-decoration: none;
    user-select: none;
}
.tm-cat-chip:hover {
    border-color: var(--tm-primary);
    color: var(--tm-primary);
    background: var(--tm-primary-l);
    transform: translateY(-1px);
}
/* Active chip — same style for "الكل" AND any category */
.tm-cat-chip.active {
    background: var(--tm-primary);
    border-color: var(--tm-primary);
    color: var(--tm-white) !important;
    box-shadow: 0 3px 10px rgba(52,56,146,0.28);
    transform: translateY(-1px);
}
.tm-cat-chip.active:hover {
    background: var(--tm-primary-d);
    border-color: var(--tm-primary-d);
    color: var(--tm-white);
}
.chip-icon { font-size: 16px; }

/* أسهم scroll — أسهم فقط، لا نقاط */
.cat-scroll-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1.5px solid var(--tm-gray-200);
    background: var(--tm-white);
    color: var(--tm-primary);
    cursor: pointer;
    display: none; /* JS يُظهرها */
    align-items: center;
    justify-content: center;
    box-shadow: var(--tm-shadow-sm);
    transition: var(--tm-transition);
    z-index: 3;
    font-size: 12px;
}
.cat-scroll-arrow:hover {
    background: var(--tm-primary);
    color: var(--tm-white);
    border-color: var(--tm-primary);
    box-shadow: var(--tm-shadow-md);
}
.cat-arrow-right { right: 4px; }
.cat-arrow-left  { left: 4px; }

/* fade gradient عند حافة الأسهم */
.tm-cat-row::before,
.tm-cat-row::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    width: 36px;
    z-index: 2;
    pointer-events: none;
}
.tm-cat-row::before {
    right: 40px;
    background: linear-gradient(to left, var(--tm-white), transparent);
}
.tm-cat-row::after {
    left: 40px;
    background: linear-gradient(to right, var(--tm-white), transparent);
}

/* --- صف الكونترولز --- */
.tm-controls-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--tm-gray-200);
}

.tm-control {
    flex: 1;
    padding: 12px 20px;
    border-left: 1px solid var(--tm-gray-200);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.tm-control:last-child { border-left: none; }

.ctrl-label {
    font-size: 11px;
    color: var(--tm-gray-600);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}
.ctrl-label i { color: var(--tm-primary); font-size: 11px; }

/* السعر */
.price-fields { display: flex; align-items: center; gap: 8px; }
.price-input {
    width: 80px;
    padding: 6px 10px;
    border: 1.5px solid var(--tm-gray-200);
    border-radius: var(--tm-radius-sm);
    font-family: var(--tm-font);
    font-size: 13px;
    font-weight: 600;
    color: var(--tm-primary);
    background: var(--tm-gray-50);
    text-align: center;
    transition: var(--tm-transition);
    -moz-appearance: textfield;
}
.price-input::-webkit-outer-spin-button,
.price-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.price-input:focus { outline: none; border-color: var(--tm-primary); background: var(--tm-white); }
.price-dash { color: var(--tm-gray-400); font-weight: 600; }

/* السليكت */
.tm-select {
    padding: 7px 10px;
    border: 1.5px solid var(--tm-gray-200);
    border-radius: var(--tm-radius-sm);
    font-family: var(--tm-font);
    font-size: 13px;
    font-weight: 600;
    color: var(--tm-gray-800);
    background: var(--tm-gray-50);
    cursor: pointer;
    transition: var(--tm-transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23343892' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 10px center;
    padding-left: 30px;
    width: 100%;
}
.tm-select:focus { outline: none; border-color: var(--tm-primary); }

/* التوجل */
.tm-toggle-wrap { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.tm-toggle-input { display: none; }
.tm-toggle-track {
    width: 44px; height: 24px;
    background: var(--tm-gray-200);
    border-radius: var(--tm-radius-pill);
    position: relative;
    transition: var(--tm-transition);
    flex-shrink: 0;
}
.tm-toggle-thumb {
    position: absolute;
    width: 18px; height: 18px;
    background: var(--tm-white);
    border-radius: 50%;
    top: 3px; right: 3px;
    transition: var(--tm-transition);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.tm-toggle-input:checked + .tm-toggle-track { background: var(--tm-primary); }
.tm-toggle-input:checked + .tm-toggle-track .tm-toggle-thumb { right: calc(100% - 21px); }
.toggle-label { font-size: 13px; font-weight: 600; color: var(--tm-gray-800); }

/* أزرار */
.actions-control {
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
}
.tm-apply-btn {
    background: var(--tm-primary);
    color: var(--tm-white);
    border: none;
    padding: 9px 20px;
    border-radius: var(--tm-radius-pill);
    font-family: var(--tm-font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: var(--tm-transition);
    white-space: nowrap;
    text-decoration: none;
}
.tm-apply-btn:hover { background: var(--tm-primary-d); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(52,56,146,0.3); }

.tm-clear-btn {
    background: transparent;
    color: var(--tm-danger);
    border: 1.5px solid var(--tm-danger);
    padding: 7px 14px;
    border-radius: var(--tm-radius-pill);
    font-family: var(--tm-font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: var(--tm-transition);
    white-space: nowrap;
    text-decoration: none;
}
.tm-clear-btn:hover { background: var(--tm-danger); color: var(--tm-white); }

/* ============================================================
   شريط الفلاتر النشطة
============================================================ */
.tm-active-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--tm-secondary-l);
    border-top: 1px solid #fde68a;
    flex-wrap: wrap;
}
.ab-label { font-size: 12px; font-weight: 700; color: var(--tm-primary); white-space: nowrap; }
.tm-active-tags { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }

.active-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--tm-secondary);
    color: #5a3e00;
    border-radius: var(--tm-radius-pill);
    padding: 4px 10px 4px 6px;
    font-size: 12px;
    font-weight: 600;
}
.active-tag-icon { font-size: 14px; line-height: 1; }
.active-tag-name { line-height: 1; }
.active-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px; height: 16px;
    background: rgba(90,62,0,0.2);
    border-radius: 50%;
    margin-right: 2px;
    text-decoration: none;
    color: #5a3e00;
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    transition: var(--tm-transition);
    flex-shrink: 0;
}
.active-tag-remove:hover { background: var(--tm-danger); color: var(--tm-white); }

.ab-clear-all {
    margin-right: auto;
    background: none;
    border: none;
    color: var(--tm-danger);
    font-family: var(--tm-font);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--tm-radius-sm);
    transition: var(--tm-transition);
}
.ab-clear-all:hover { background: rgba(226,75,74,0.08); }

/* ============================================================
   MOBILE FILTER
============================================================ */
.tm-mobile-filter { display: none; }

.mob-cat-scroll {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--tm-white);
    border-bottom: 1px solid var(--tm-gray-200);
}
.mob-cat-scroll::-webkit-scrollbar { display: none; }

.mob-cat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: var(--tm-radius-pill);
    border: 1.5px solid var(--tm-gray-200);
    background: var(--tm-white);
    color: var(--tm-gray-800);
    font-family: var(--tm-font);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    transition: var(--tm-transition);
    text-decoration: none;
    /* button reset */
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    line-height: 1.4;
}
.mob-cat.active {
    background: var(--tm-primary);
    border-color: var(--tm-primary);
    color: var(--tm-white);
    box-shadow: 0 2px 8px rgba(52,56,146,0.25);
}
.mob-cat:hover:not(.active) { border-color: var(--tm-primary); color: var(--tm-primary); background: var(--tm-primary-l); }
/* تأثير loading عند الضغط */
.mob-cat:active { transform: scale(0.95); opacity: 0.85; }

.mob-filter-bar {
    display: flex;
    align-items: stretch;
    background: var(--tm-white);
    border-bottom: 2px solid var(--tm-gray-200);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.mob-fb-btn {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    font-family: var(--tm-font);
    font-size: 12px;
    font-weight: 700;
    color: var(--tm-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--tm-transition);
    text-decoration: none;
    position: relative;
}
.mob-fb-btn:hover { background: var(--tm-primary-l); }
.mob-fb-btn i { font-size: 14px; }
.mob-fb-divider { width: 1px; background: var(--tm-gray-200); margin: 8px 0; }
.mob-badge {
    background: var(--tm-danger);
    color: var(--tm-white);
    border-radius: 50%;
    width: 16px; height: 16px;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.sale-btn { color: var(--tm-primary); }
.sale-btn.active {
    color: var(--tm-secondary-d);
    background: var(--tm-secondary-l);
    font-weight: 800;
}
.sale-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0; left: 12px; right: 12px;
    height: 2px;
    background: var(--tm-secondary-d);
    border-radius: 2px 2px 0 0;
}

/* ============================================================
   OVERLAY
============================================================ */
.tm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9998;
    backdrop-filter: blur(2px);
}
.tm-overlay.visible { display: block; }

/* ============================================================
   MOBILE DRAWER
============================================================ */
.tm-drawer {
    position: fixed;
    bottom: 0; right: 0; left: 0;
    background: var(--tm-white);
    border-radius: 20px 20px 0 0;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -8px 40px rgba(52,56,146,0.18);
}
.tm-drawer.open { transform: translateY(0); }

.drawer-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tm-gray-200);
    gap: 12px;
    flex-shrink: 0;
}
.drawer-close {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--tm-gray-100);
    color: var(--tm-gray-600);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--tm-transition);
    font-size: 14px;
}
.drawer-close:hover { background: var(--tm-gray-200); }
.drawer-title { flex: 1; text-align: center; font-size: 16px; font-weight: 700; color: var(--tm-primary); }

.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; -webkit-overflow-scrolling: touch; }
.drawer-section { margin-bottom: 22px; }
.ds-title { font-size: 13px; font-weight: 700; color: var(--tm-primary); margin-bottom: 12px; display: flex; align-items: center; gap: 7px; }

.drawer-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.d-chip {
    padding: 7px 14px;
    border-radius: var(--tm-radius-pill);
    border: 1.5px solid var(--tm-gray-200);
    background: var(--tm-white);
    font-family: var(--tm-font);
    font-size: 12px;
    font-weight: 600;
    color: var(--tm-gray-800);
    cursor: pointer;
    transition: var(--tm-transition);
    text-decoration: none;
    display: inline-block;
}
.d-chip:hover { border-color: var(--tm-primary); color: var(--tm-primary); }
.d-chip.active { background: var(--tm-primary); border-color: var(--tm-primary); color: var(--tm-white); }

.drawer-price-row { display: flex; align-items: center; gap: 10px; }
.drawer-price-row input {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid var(--tm-gray-200);
    border-radius: var(--tm-radius-sm);
    font-family: var(--tm-font);
    font-size: 14px;
    font-weight: 600;
    color: var(--tm-primary);
    text-align: center;
    -moz-appearance: textfield;
}
.drawer-price-row input::-webkit-outer-spin-button,
.drawer-price-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.drawer-price-row input:focus { outline: none; border-color: var(--tm-primary); }
.drawer-price-row span { color: var(--tm-gray-400); font-weight: 700; }

.drawer-footer {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--tm-gray-200);
    flex-shrink: 0;
    background: var(--tm-white);
}
.drawer-clear-btn {
    flex: 1;
    padding: 12px;
    border: 1.5px solid var(--tm-gray-200);
    border-radius: var(--tm-radius-sm);
    background: var(--tm-white);
    font-family: var(--tm-font);
    font-size: 14px;
    font-weight: 700;
    color: var(--tm-gray-600);
    cursor: pointer;
    transition: var(--tm-transition);
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}
.drawer-clear-btn:hover { border-color: var(--tm-danger); color: var(--tm-danger); }

.drawer-apply-btn {
    flex: 2;
    padding: 12px;
    background: var(--tm-primary);
    border: none;
    border-radius: var(--tm-radius-sm);
    font-family: var(--tm-font);
    font-size: 14px;
    font-weight: 700;
    color: var(--tm-white);
    cursor: pointer;
    transition: var(--tm-transition);
}
.drawer-apply-btn:hover { background: var(--tm-primary-d); }
.drawer-apply-btn:active { transform: scale(0.98); }

/* ============================================================
   RESPONSIVE — TABLET
============================================================ */
@media (max-width: 1024px) {
    .tm-cat-row { padding: 0 34px; }
    .tm-control { padding: 10px 14px; }
    .price-input { width: 70px; }
    .tm-apply-btn { padding: 8px 14px; font-size: 12px; }
}

/* ============================================================
   RESPONSIVE — MOBILE
============================================================ */
@media (max-width: 768px) {
    .tm-filter-bar   { display: none; }
    .tm-mobile-filter { display: block; }
}

@media (max-width: 420px) {
    .mob-cat { padding: 6px 12px; font-size: 11px; }
    .mob-fb-btn { font-size: 11px; padding: 10px 6px; }
    .drawer-footer { gap: 8px; padding: 12px 14px; }
    .drawer-apply-btn, .drawer-clear-btn { font-size: 13px; padding: 11px; }
}

/* ============================================================
   LOADING OVERLAY — يظهر عند التنقل بعد اختيار تصنيف
============================================================ */
#tm-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.75);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    animation: tmFadeIn 0.15s ease;
}
@keyframes tmFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.tm-loading-spinner {
    width: 42px;
    height: 42px;
    border: 3.5px solid var(--tm-primary-l);
    border-top-color: var(--tm-primary);
    border-radius: 50%;
    animation: tmSpin 0.7s linear infinite;
}
@keyframes tmSpin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   DRAWER — badge عدد التصنيفات في عنوان القسم
============================================================ */
.ds-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--tm-primary);
    color: var(--tm-white);
    border-radius: var(--tm-radius-pill);
    font-size: 11px;
    font-weight: 700;
    margin-right: 4px;
}

/* ============================================================
   MOBILE BADGE — عدد رقمي بدل "!"
============================================================ */
.mob-badge {
    background: var(--tm-danger);
    color: var(--tm-white);
    border-radius: var(--tm-radius-pill);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
