/*
 * Mobile-First Modern Design for StoreBest
 * Built with performance and UX in mind
 * Optimized for smooth animations and touch interactions
 */

/* ==================== CSS Variables ==================== */
:root {
    /* Colors - Modern Palette */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #0f172a;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    
    /* Neutrals */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Typography */
    --font-sans: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-display: 'Space Grotesk', 'Cairo', sans-serif;
    
    /* Transitions */
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Z-index layers */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-toast: 1060;
}

/* ==================== Base Reset ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Remove default button styles */
button {
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

/* Improve image rendering */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==================== Mobile-First Header ==================== */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--gray-200);
    z-index: var(--z-sticky);
    padding: var(--space-3) var(--space-4);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.mobile-header__container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.mobile-header__logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    text-decoration: none;
    font-family: var(--font-display);
}

.mobile-header__logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
}

.mobile-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.mobile-header__icon-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-lg);
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-700);
    transition: all var(--transition-base);
}

.mobile-header__icon-btn:active {
    transform: scale(0.95);
    background: var(--gray-200);
}

.mobile-header__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border: 2px solid white;
}

/* Hamburger Menu Icon */
.mobile-menu-btn {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 44px;
    height: 44px;
    background: var(--gray-100);
    border-radius: var(--radius-lg);
    justify-content: center;
    align-items: center;
    transition: all var(--transition-base);
}

.mobile-menu-btn__line {
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
    transition: all var(--transition-smooth);
}

.mobile-menu-btn.active .mobile-menu-btn__line:nth-child(1) {
    transform: rotate(45deg) translateY(7px);
}

.mobile-menu-btn.active .mobile-menu-btn__line:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn.active .mobile-menu-btn__line:nth-child(3) {
    transform: rotate(-45deg) translateY(-7px);
}

/* ==================== Mobile Sidebar Navigation ==================== */
.mobile-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    background: white;
    z-index: var(--z-modal);
    transform: translateX(100%);
    transition: transform var(--transition-smooth);
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.rtl .mobile-sidebar {
    right: auto;
    left: 0;
    transform: translateX(-100%);
}

.mobile-sidebar.active {
    transform: translateX(0);
}

.rtl .mobile-sidebar.active {
    transform: translateX(0);
}

.mobile-sidebar__header {
    padding: var(--space-6) var(--space-5);
    border-bottom: 1px solid var(--gray-200);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.mobile-sidebar__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.mobile-sidebar__avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.mobile-sidebar__user-info h3 {
    font-size: 1.1rem;
    margin-bottom: var(--space-1);
}

.mobile-sidebar__user-info p {
    font-size: 0.85rem;
    opacity: 0.9;
}

.mobile-sidebar__close {
    position: absolute;
    top: var(--space-4);
    left: var(--space-4);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.mobile-sidebar__nav {
    padding: var(--space-4) 0;
}

.mobile-sidebar__section-title {
    padding: var(--space-4) var(--space-5) var(--space-2);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    font-weight: 700;
}

.mobile-sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    color: var(--gray-700);
    text-decoration: none;
    transition: all var(--transition-base);
    position: relative;
}

.mobile-sidebar__link::before {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
    transform: scaleY(0);
    transition: transform var(--transition-smooth);
}

.rtl .mobile-sidebar__link::before {
    right: auto;
    left: 0;
}

.mobile-sidebar__link:active {
    background: var(--gray-50);
}

.mobile-sidebar__link.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.1), transparent);
    color: var(--primary);
    font-weight: 600;
}

.mobile-sidebar__link.active::before {
    transform: scaleY(1);
}

.mobile-sidebar__link-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.mobile-sidebar__link-text {
    flex: 1;
}

.mobile-sidebar__link-arrow {
    color: var(--gray-400);
    font-size: 0.9rem;
}

/* Mobile Sidebar Overlay */
.mobile-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal) - 1);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-smooth);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.mobile-sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ==================== Main Content Spacing ==================== */
.mobile-main {
    padding-top: 72px; /* Height of mobile header */
    min-height: 100vh;
}

.mobile-container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
    max-width: 100%;
}

/* ==================== Mobile Cards ==================== */
.mobile-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-5);
}

.mobile-card--elevated {
    box-shadow: var(--shadow-lg);
}

.mobile-card__header {
    margin-bottom: var(--space-4);
}

.mobile-card__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: var(--space-1);
}

.mobile-card__subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
}

/* ==================== Mobile Product Grid ==================== */
.mobile-product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
    padding: var(--space-4) 0;
}

.mobile-product-card {
    background: white;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-smooth);
    display: flex;
    flex-direction: column;
}

.mobile-product-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

.mobile-product-card__image {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--gray-100);
}

.mobile-product-card__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.mobile-product-card:active .mobile-product-card__image img {
    transform: scale(1.05);
}

.mobile-product-card__badge {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    background: var(--primary);
    color: white;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mobile-product-card__wishlist {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    box-shadow: var(--shadow-md);
}

.mobile-product-card__wishlist.active {
    color: var(--danger);
}

.mobile-product-card__body {
    padding: var(--space-3);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mobile-product-card__category {
    font-size: 0.7rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-1);
}

.mobile-product-card__title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--space-2);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mobile-product-card__rating {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
    font-size: 0.75rem;
}

.mobile-product-card__stars {
    color: var(--accent);
}

.mobile-product-card__rating-count {
    color: var(--gray-500);
}

.mobile-product-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: var(--space-2);
    border-top: 1px solid var(--gray-100);
}

.mobile-product-card__price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.mobile-product-card__old-price {
    font-size: 0.8rem;
    color: var(--gray-400);
    text-decoration: line-through;
    margin-right: var(--space-2);
}

.mobile-product-card__cart-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.mobile-product-card__cart-btn:active {
    transform: scale(0.9);
    background: var(--primary-dark);
}

/* ==================== Mobile Buttons ==================== */
.mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-xl);
    font-weight: 600;
    font-size: 1rem;
    transition: all var(--transition-base);
    text-decoration: none;
    border: none;
    cursor: pointer;
    min-height: 52px;
}

.mobile-btn--primary {
    background: var(--primary);
    color: white;
}

.mobile-btn--primary:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.mobile-btn--secondary {
    background: var(--gray-100);
    color: var(--gray-900);
}

.mobile-btn--secondary:active {
    background: var(--gray-200);
}

.mobile-btn--outline {
    background: transparent;
    border: 2px solid var(--gray-300);
    color: var(--gray-700);
}

.mobile-btn--outline:active {
    background: var(--gray-50);
}

.mobile-btn--full {
    width: 100%;
}

.mobile-btn--lg {
    padding: var(--space-5) var(--space-8);
    font-size: 1.1rem;
    min-height: 56px;
}

.mobile-btn--icon-only {
    width: 52px;
    height: 52px;
    padding: 0;
}

/* ==================== Mobile Hero Section ==================== */
.mobile-hero {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-2xl);
    padding: var(--space-8) var(--space-5);
    margin: var(--space-5) 0;
    color: white;
    position: relative;
    overflow: hidden;
}

.mobile-hero::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1), transparent);
    border-radius: 50%;
    transform: translate(50%, -50%);
}

.mobile-hero__eyebrow {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.9;
    margin-bottom: var(--space-2);
}

.mobile-hero__title {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: var(--space-3);
}

.mobile-hero__description {
    font-size: 0.95rem;
    opacity: 0.9;
    line-height: 1.6;
    margin-bottom: var(--space-5);
}

.mobile-hero__actions {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* ==================== Mobile Bottom Navigation ==================== */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: var(--space-2) var(--space-4) calc(var(--space-2) + env(safe-area-inset-bottom));
    z-index: var(--z-fixed);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.mobile-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2);
    border-radius: var(--radius-lg);
    color: var(--gray-600);
    text-decoration: none;
    transition: all var(--transition-base);
    position: relative;
}

.mobile-bottom-nav__item:active {
    background: var(--gray-100);
    transform: scale(0.95);
}

.mobile-bottom-nav__item.active {
    color: var(--primary);
}

.mobile-bottom-nav__icon {
    font-size: 1.3rem;
    position: relative;
}

.mobile-bottom-nav__badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    background: var(--danger);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.mobile-bottom-nav__label {
    font-size: 0.7rem;
    font-weight: 600;
}

/* Add padding to main content to account for bottom nav */
.mobile-main--with-bottom-nav {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ==================== Mobile Search Bar ==================== */
.mobile-search {
    position: relative;
    margin: var(--space-4) 0;
}

.mobile-search__input {
    width: 100%;
    padding: var(--space-4) var(--space-5) var(--space-4) var(--space-12);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-xl);
    font-size: 1rem;
    background: white;
    transition: all var(--transition-base);
}

.mobile-search__input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.mobile-search__icon {
    position: absolute;
    left: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 1.2rem;
}

.mobile-search__clear {
    position: absolute;
    right: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--gray-200);
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.mobile-search__input:not(:placeholder-shown) ~ .mobile-search__clear {
    opacity: 1;
    visibility: visible;
}

/* ==================== Mobile Category Pills ==================== */
.mobile-category-pills {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding: var(--space-2) 0;
    margin: var(--space-4) 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.mobile-category-pills::-webkit-scrollbar {
    display: none;
}

.mobile-category-pill {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-full);
    background: white;
    border: 2px solid var(--gray-200);
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all var(--transition-base);
    white-space: nowrap;
}

.mobile-category-pill:active {
    transform: scale(0.95);
}

.mobile-category-pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ==================== Mobile Animations ==================== */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==================== RTL Support ==================== */
.rtl {
    direction: rtl;
}

.rtl .mobile-search__icon {
    left: auto;
    right: var(--space-4);
}

.rtl .mobile-search__clear {
    right: auto;
    left: var(--space-3);
}

.rtl .mobile-search__input {
    padding: var(--space-4) var(--space-12) var(--space-4) var(--space-5);
}

/* ==================== Performance Optimizations ==================== */
.mobile-product-card,
.mobile-btn,
.mobile-sidebar__link {
    will-change: transform;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== Responsive - Tablet ==================== */
@media (min-width: 768px) {
    .mobile-product-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-5);
    }
    
    .mobile-container {
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
    
    .mobile-hero {
        padding: var(--space-10) var(--space-8);
    }
    
    .mobile-hero__title {
        font-size: 2.25rem;
    }
}

/* ==================== Responsive - Desktop ==================== */
@media (min-width: 1024px) {
    .mobile-product-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--space-6);
    }
    
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-sidebar,
    .mobile-sidebar-overlay,
    .mobile-search {
        display: none !important;
    }
    
    .mobile-main {
        padding-top: 0;
    }
    
    .mobile-main--with-bottom-nav {
        padding-bottom: 0;
    }
    
    .site-header {
        display: block !important;
    }
    
    .page-content {
        padding-bottom: 4rem;
    }
}

/* Hide mobile elements on desktop, show desktop header */
@media (max-width: 1023px) {
    .site-header {
        display: none !important;
    }
}

/* ==================== Safe Area Insets for iPhone ==================== */
@supports (padding: max(0px)) {
    .mobile-header {
        padding-left: max(var(--space-4), env(safe-area-inset-left));
        padding-right: max(var(--space-4), env(safe-area-inset-right));
        padding-top: max(var(--space-3), env(safe-area-inset-top));
    }
    
    .mobile-bottom-nav {
        padding-left: max(var(--space-4), env(safe-area-inset-left));
        padding-right: max(var(--space-4), env(safe-area-inset-right));
    }
}

