/**
 * Mobile Responsiveness Fixes
 * Critical improvements for mobile user experience
 * Target: Phones (320px - 768px) and Tablets (768px - 1024px)
 */

/* ============================================
   GLOBAL MOBILE IMPROVEMENTS
   ============================================ */

/* Prevent horizontal scroll on mobile */
html,
body {
    overflow-x: hidden;
    width: 100%;
}

/* Improve touch targets (minimum 44x44px for iOS) */
button,
a,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
    min-width: 44px;
}

/* Prevent iOS zoom on input focus */
@media screen and (max-width: 768px) {

    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px !important;
        /* Prevents zoom on iOS */
    }
}

/* ============================================
   HEADER & NAVIGATION - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Top bar - hide on very small screens */
    .top-bar {
        font-size: 0.75rem;
        padding: 0.375rem 0;
    }

    .top-bar-link {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .top-bar-link span {
        display: none;
        /* Hide text, keep icons */
    }

    /* Main navigation */
    .main-nav {
        padding: 0.5rem 0;
    }

    .brand-logo-img {
        height: 50px !important;
        max-height: 50px;
    }

    .logo-text {
        display: none;
        /* Hide tagline on mobile */
    }

    /* Navigation menu - hide on mobile (use mobile menu instead) */
    .nav-menu {
        display: none;
    }

    /* Mobile toggle button */
    .mobile-toggle {
        display: flex !important;
        flex-direction: column;
        gap: 4px;
        padding: 8px;
        background: none;
        border: none;
        cursor: pointer;
    }

    .mobile-toggle span {
        width: 24px;
        height: 2px;
        background-color: var(--text-primary);
        transition: all 0.3s;
    }

    /* Nav actions - compact on mobile */
    .nav-actions {
        gap: 0.25rem;
    }

    .nav-actions .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .nav-actions .btn-add-adv {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    .nav-actions .btn-add-adv span {
        display: none;
        /* Show icon only */
    }

    /* User dropdown - adjust for mobile */
    .user-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.875rem;
    }

    .user-name {
        display: none;
        /* Hide name on very small screens */
    }
}

@media (min-width: 480px) and (max-width: 768px) {
    .nav-actions .btn-add-adv span {
        display: inline;
        /* Show text on larger phones */
    }
}

/* ============================================
   FORMS - MOBILE OPTIMIZATION
   ============================================ */

@media (max-width: 768px) {

    /* Form groups */
    .form-group {
        margin-bottom: 1rem;
    }

    /* Labels */
    label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Input fields */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        width: 100%;
        padding: 0.75rem;
        border-radius: var(--radius);
        border: 1px solid var(--border-color);
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    /* Textarea */
    textarea {
        min-height: 120px;
        resize: vertical;
    }

    /* Select dropdowns */
    select {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: left 12px center;
        padding-right: 40px;
    }

    /* Form buttons */
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 1.5rem;
    }

    .form-actions button,
    .form-actions .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
}

/* ============================================
   AD CREATION/EDIT FORM - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Form container */
    .adv-form-container {
        padding: 1rem;
    }

    /* Form sections */
    .form-section {
        margin-bottom: 1.5rem;
        padding: 1rem;
        background: white;
        border-radius: var(--radius);
    }

    .form-section-title {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    /* Image upload area */
    .image-upload-area {
        min-height: 150px;
        padding: 1.5rem 1rem;
        border: 2px dashed var(--border-color);
        border-radius: var(--radius);
        text-align: center;
        cursor: pointer;
        transition: all 0.3s;
    }

    .image-upload-area:active {
        background-color: var(--bg-light);
        border-color: var(--primary-color);
    }

    .image-upload-icon {
        font-size: 2.5rem;
        color: var(--text-secondary);
        margin-bottom: 0.5rem;
    }

    .image-upload-text {
        font-size: 0.9rem;
        color: var(--text-secondary);
    }

    /* Image preview grid */
    .image-preview-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .image-preview-item {
        position: relative;
        aspect-ratio: 1;
        border-radius: var(--radius);
        overflow: hidden;
    }

    .image-preview-item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .image-preview-remove {
        position: absolute;
        top: 0.5rem;
        left: 0.5rem;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: rgba(239, 68, 68, 0.9);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    /* Price inputs */
    .price-input-group {
        display: flex;
        gap: 0.5rem;
        align-items: center;
    }

    .price-input-group input {
        flex: 1;
    }

    .price-input-group select {
        flex: 0 0 100px;
    }
}

/* ============================================
   PRODUCT CARDS - MOBILE OPTIMIZATION
   ============================================ */

@media (max-width: 768px) {

    /* Product grid */
    .products-grid,
    .ads-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Product card - horizontal layout on mobile */
    .product-card,
    .ad-card {
        display: flex;
        flex-direction: row;
        background: white;
        border-radius: var(--radius);
        overflow: hidden;
        box-shadow: var(--shadow-sm);
        transition: all 0.3s;
    }

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

    /* Product image - fixed width on mobile */
    .product-image,
    .ad-image {
        width: 120px;
        min-width: 120px;
        height: 120px;
        position: relative;
        flex-shrink: 0;
    }

    .product-image img,
    .ad-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* Product content */
    .product-content,
    .ad-content {
        flex: 1;
        padding: 0.75rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    /* Product title */
    .product-title,
    .ad-title {
        font-size: 0.95rem;
        font-weight: 600;
        margin-bottom: 0.25rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Product meta */
    .product-meta,
    .ad-meta {
        font-size: 0.75rem;
        color: var(--text-secondary);
        margin-bottom: 0.5rem;
    }

    /* Product price */
    .product-price,
    .ad-price {
        font-size: 1rem;
        font-weight: 700;
        color: var(--primary-color);
    }

    /* Product location */
    .product-location,
    .ad-location {
        font-size: 0.75rem;
        color: var(--text-secondary);
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }

    /* Hide description on mobile cards */
    .product-description,
    .ad-description {
        display: none;
    }

    /* Product badges */
    .product-badge,
    .ad-badge {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.25rem 0.5rem;
        background: var(--primary-color);
        color: white;
        font-size: 0.7rem;
        border-radius: var(--radius-sm);
        font-weight: 600;
    }
}

/* Tablet - 2 columns */
@media (min-width: 480px) and (max-width: 768px) {

    .products-grid,
    .ads-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Vertical layout for tablet */
    .product-card,
    .ad-card {
        flex-direction: column;
    }

    .product-image,
    .ad-image {
        width: 100%;
        height: 180px;
    }

    .product-description,
    .ad-description {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        font-size: 0.85rem;
        margin: 0.5rem 0;
    }
}

/* ============================================
   FILTERS & SEARCH - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Filter sidebar - bottom sheet on mobile */
    .filter-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        max-height: 80vh;
        overflow-y: auto;
    }

    .filter-sidebar.active {
        transform: translateY(0);
    }

    /* Filter header */
    .filter-header {
        position: sticky;
        top: 0;
        background: white;
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        justify-content: space-between;
        align-items: center;
        z-index: 10;
    }

    .filter-header h3 {
        font-size: 1.1rem;
        margin: 0;
    }

    .filter-close {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: var(--bg-light);
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    /* Filter content */
    .filter-content {
        padding: 1rem;
    }

    .filter-group {
        margin-bottom: 1.5rem;
    }

    .filter-group-title {
        font-size: 0.95rem;
        font-weight: 600;
        margin-bottom: 0.75rem;
    }

    /* Filter trigger button */
    .filter-trigger {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--primary-color);
        color: white;
        border: none;
        box-shadow: var(--shadow-lg);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        cursor: pointer;
        z-index: 999;
    }

    .filter-trigger:active {
        transform: scale(0.95);
    }

    /* Search bar */
    .search-bar {
        padding: 0.75rem 1rem;
        background: white;
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        margin-bottom: 1rem;
    }

    .search-input-group {
        display: flex;
        gap: 0.5rem;
    }

    .search-input {
        flex: 1;
        padding: 0.75rem;
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        font-size: 16px;
    }

    .search-btn {
        padding: 0.75rem 1.5rem;
        background: var(--primary-color);
        color: white;
        border: none;
        border-radius: var(--radius);
        font-weight: 600;
    }
}

/* ============================================
   CATEGORY PAGE - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Category header */
    .category-header {
        padding: 1rem;
        background: white;
        margin-bottom: 1rem;
    }

    .category-title {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    .category-count {
        font-size: 0.875rem;
        color: var(--text-secondary);
    }

    /* Subcategories - horizontal scroll */
    .subcategories-scroll {
        display: flex;
        gap: 0.75rem;
        overflow-x: auto;
        padding: 1rem;
        margin: 0 -1rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .subcategories-scroll::-webkit-scrollbar {
        display: none;
    }

    .subcategory-chip {
        flex-shrink: 0;
        padding: 0.5rem 1rem;
        background: white;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-full);
        font-size: 0.875rem;
        white-space: nowrap;
        cursor: pointer;
        transition: all 0.3s;
    }

    .subcategory-chip.active {
        background: var(--primary-color);
        color: white;
        border-color: var(--primary-color);
    }

    /* Sort options */
    .sort-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1rem;
        background: white;
        margin-bottom: 1rem;
    }

    .sort-label {
        font-size: 0.875rem;
        color: var(--text-secondary);
    }

    .sort-select {
        padding: 0.5rem 2rem 0.5rem 0.75rem;
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        font-size: 0.875rem;
        background-position: left 0.5rem center;
    }
}

/* ============================================
   PRODUCT DETAIL PAGE - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Product layout - stack vertically */
    .product-layout {
        display: flex;
        flex-direction: column;
    }

    /* Image gallery */
    .gallery-section {
        margin-bottom: 1rem;
    }

    .main-image {
        width: 100%;
        aspect-ratio: 4/3;
        border-radius: var(--radius);
        overflow: hidden;
        margin-bottom: 0.75rem;
    }

    .main-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* Thumbnail gallery - horizontal scroll */
    .thumbnail-gallery {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .thumbnail {
        flex-shrink: 0;
        width: 60px;
        height: 60px;
        border-radius: var(--radius-sm);
        overflow: hidden;
        border: 2px solid transparent;
        cursor: pointer;
    }

    .thumbnail.active {
        border-color: var(--primary-color);
    }

    .thumbnail img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* Product info */
    .product-info-card {
        padding: 1rem;
        background: white;
        border-radius: var(--radius);
        margin-bottom: 1rem;
    }

    .product-title {
        font-size: 1.25rem;
        line-height: 1.4;
        margin-bottom: 0.75rem;
    }

    .product-price-section {
        margin: 1rem 0;
    }

    .price-main {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--primary-color);
    }

    /* Seller card */
    .seller-card {
        padding: 1rem;
        background: white;
        border-radius: var(--radius);
        margin-bottom: 1rem;
    }

    .seller-info {
        display: flex;
        gap: 0.75rem;
        align-items: center;
        margin-bottom: 1rem;
    }

    .seller-info img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        object-fit: cover;
    }

    /* Contact buttons */
    .seller-contact-info {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .contact-link {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.875rem;
        background: var(--bg-light);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--text-primary);
        transition: all 0.3s;
    }

    .contact-link:active {
        background: var(--primary-light);
    }

    /* Mobile action bar (sticky bottom) */
    .mobile-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 0.75rem 1rem;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        display: flex;
        gap: 0.75rem;
        z-index: 100;
    }

    .mobile-action-bar .btn {
        flex: 1;
        padding: 0.875rem;
        font-size: 1rem;
        border-radius: var(--radius);
    }

    .mobile-action-bar .btn-primary {
        background: var(--primary-color);
        color: white;
        border: none;
    }

    .mobile-action-bar .btn-secondary {
        background: white;
        color: var(--primary-color);
        border: 1px solid var(--primary-color);
    }
}

/* ============================================
   MY ADS PAGE - MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Stats cards */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .stat-card {
        padding: 1rem;
        background: white;
        border-radius: var(--radius);
        text-align: center;
    }

    .stat-value {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--primary-color);
    }

    .stat-label {
        font-size: 0.875rem;
        color: var(--text-secondary);
        margin-top: 0.25rem;
    }

    /* Ad card actions */
    .adv-actions {
        position: absolute;
        top: 0.5rem;
        left: 0.5rem;
    }

    .adv-actions .dropdown-toggle {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.9);
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   UTILITIES - MOBILE
   ============================================ */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Spacing utilities for mobile */
@media (max-width: 768px) {
    .mobile-p-1 {
        padding: 0.5rem !important;
    }

    .mobile-p-2 {
        padding: 1rem !important;
    }

    .mobile-p-3 {
        padding: 1.5rem !important;
    }

    .mobile-m-1 {
        margin: 0.5rem !important;
    }

    .mobile-m-2 {
        margin: 1rem !important;
    }

    .mobile-m-3 {
        margin: 1.5rem !important;
    }

    .mobile-mb-1 {
        margin-bottom: 0.5rem !important;
    }

    .mobile-mb-2 {
        margin-bottom: 1rem !important;
    }

    .mobile-mb-3 {
        margin-bottom: 1.5rem !important;
    }
}

/* Safe area for notched devices (iPhone X+) */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-action-bar {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
}

/* ============================================
   PAGINATION STYLING
   ============================================ */

/* Bootstrap Pagination Styling */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0;
    margin: 0;
    list-style: none;
}

.pagination .page-item {
    list-style: none;
}

.pagination .page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0.5rem 0.75rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    color: #4b5563;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s;
}

.pagination .page-link:hover {
    background: #f3f4f6;
    border-color: #2563eb;
    color: #2563eb;
}

.pagination .page-item.active .page-link {
    background: #2563eb;
    border-color: #2563eb;
    color: white;
    font-weight: 600;
}

.pagination .page-item.disabled .page-link {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.pagination .page-item.disabled .page-link:hover {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #9ca3af;
}

/* Previous/Next buttons */
.pagination .page-item:first-child .page-link,
.pagination .page-item:last-child .page-link {
    font-weight: 600;
}

/* Mobile pagination */
@media (max-width: 768px) {
    .pagination {
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .pagination .page-link {
        min-width: 36px;
        height: 36px;
        padding: 0.375rem 0.5rem;
        font-size: 0.875rem;
    }

    /* Hide some page numbers on mobile */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child):not(:nth-child(2)):not(:nth-last-child(2)) {
        display: none;
    }
}

/* Pagination wrapper */
.pagination-wrapper {
    display: flex;
    justify-content: center;
    margin: 2rem 0;
}

/* Laravel pagination nav */
nav[role="navigation"] {
    display: flex;
    justify-content: center;
}

/* Pagination info text */
.pagination-info {
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}
/* Fix for huge RTL pagination icons */
.pagination .page-link svg,
.pagination .page-link i {
    width: 20px !important;
    height: 20px !important;
    font-size: 1rem !important;
}

/* Add text labels to prev/next on desktop */
@media (min-width: 769px) {
    .pagination .page-item:first-child .page-link::after {
        content: " التالي";
        margin-right: 0.25rem;
    }
    
    .pagination .page-item:last-child .page-link::before {
        content: "السابق ";
        margin-left: 0.25rem;
    }
}

/* Mobile - smaller icons */
@media (max-width: 768px) {
    .pagination .page-link svg,
    .pagination .page-link i {
        width: 16px !important;
        height: 16px !important;
        font-size: 0.875rem !important;
    }
}
