/* ===================================
   MOBILE RESPONSIVE CSS
   eServis Organik Market
   =================================== */

/* Base Mobile Optimizations */
@media (max-width: 1024px) {
    .container,
    .container-sm,
    .container-md,
    .container-lg {
        padding: 0 20px;
    }
}

/* Standard mobile padding (px-4 = 16px) */
@media (max-width: 768px) {
    .container,
    .container-sm,
    .container-md,
    .container-lg {
        padding: 0 16px !important;
    }
}

/* Tablet & Mobile */
@media (max-width: 768px) {
    /* Remove all rounded corners on mobile for non-product pages */
    body:not(.home-page) div[style*="border-radius"],
    body:not(.home-page) .container > div,
    body:not(.home-page) main > div > div,
    body:not(.home-page) main > div,
    .cart-item,
    .checkout-section,
    .address-card,
    .order-summary,
    .cart-summary {
        border-radius: 0 !important;
    }

    /* Make content full width on mobile with standard padding */
    body:not(.home-page) .container,
    body:not(.home-page) .container-sm,
    body:not(.home-page) .container-md,
    body:not(.home-page) .container-lg {
        padding: 0 16px !important;
        max-width: 100% !important;
    }

    body:not(.home-page) main {
        padding: 0 !important;
    }

    /* Page titles on mobile - full width with background */
    body:not(.home-page) h1 {
        padding: 12px 16px !important;
        background: #f8f9fa !important;
        margin: 0 0 0 0 !important;
        font-size: 20px !important;
    }

    /* Remove box shadows on mobile */
    body:not(.home-page) div[style*="box-shadow"] {
        box-shadow: none !important;
    }

    /* All content boxes should have no gaps */
    body:not(.home-page) div[style*="gap:"],
    body:not(.home-page) div[style*="gap: "] {
        gap: 0 !important;
    }

    /* All margins between sections removed */
    body:not(.home-page) div[style*="margin-bottom"] {
        margin-bottom: 0 !important;
    }

    /* Header Mobile - 2 Row Layout */
    .header-content {
        display: grid !important;
        grid-template-columns: 1fr auto auto !important;
        grid-template-rows: auto auto !important;
        gap: 12px !important;
    }

    /* Row 1: Logo + Profile + Cart */
    .logo {
        display: flex !important;
        align-items: center !important;
        grid-column: 1 / 2 !important;
        grid-row: 1 / 2 !important;
    }

    .logo img {
        height: 32px !important;
        width: auto !important;
    }

    .header-actions {
        grid-column: 2 / 4 !important;
        grid-row: 1 / 2 !important;
        justify-content: flex-end !important;
        gap: 10px !important;
        flex-wrap: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* Row 2: Categories + Search */
    .categories-dropdown {
        grid-column: 1 / 2 !important;
        grid-row: 2 / 3 !important;
        flex-shrink: 0 !important;
    }

    .search-bar {
        grid-column: 2 / 4 !important;
        grid-row: 2 / 3 !important;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
    }

    .search-bar input {
        font-size: 14px !important;
        padding: 10px 48px 10px 14px !important;
        width: 100% !important;
    }

    /* Navigation Mobile */
    nav {
        position: static !important;
        width: 100% !important;
        order: 4;
    }

    nav ul {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    nav ul::-webkit-scrollbar {
        display: none;
    }

    nav a {
        white-space: nowrap;
        font-size: 14px;
        padding: 8px 12px;
    }

    /* Header Actions - Profile + Cart */
    .header-actions {
        order: 3 !important;
        gap: 10px !important;
        flex-wrap: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* Profile - Show only initials */
    .header-actions .btn:not(.cart-link):not(.auth-btn) {
        padding: 8px 10px !important;
        font-size: 14px !important;
        white-space: nowrap !important;
        max-width: 80px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* Cart - Icon Only */
    .header-actions .cart-link {
        padding: 8px 12px !important;
        font-size: 20px !important;
        min-width: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
    }

    .cart-text {
        display: none !important;
    }

    .cart-icon {
        display: inline-block !important;
        font-size: 20px !important;
    }

    .cart-count {
        position: absolute !important;
        top: -4px !important;
        right: -4px !important;
        background: #f56400 !important;
        color: white !important;
        border-radius: 50% !important;
        width: 20px !important;
        height: 20px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 11px !important;
        font-weight: 600 !important;
    }

    /* Auth Buttons - Icon Only on Mobile */
    .header-actions .auth-btn {
        padding: 10px !important;
        min-width: 44px !important;
        height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .header-actions .auth-btn .auth-text {
        display: none !important;
    }

    .header-actions .auth-btn .auth-icon {
        display: block !important;
        width: 22px !important;
        height: 22px !important;
    }

    .header-actions .auth-btn.btn-primary .auth-icon {
        stroke: #fff !important;
    }

    .header-actions .auth-btn.btn-outline .auth-icon {
        stroke: #111 !important;
    }

    .header-actions a {
        font-size: 14px !important;
    }

    /* Categories Button */
    .categories-btn {
        padding: 8px 10px !important;
        font-size: 13px !important;
    }

    /* Categories Menu Mobile */
    .categories-menu {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        border-radius: 0 !important;
        overflow-y: auto !important;
        padding-top: 60px !important;
    }

    /* Close Button for Categories */
    .categories-menu::before {
        content: "✕" !important;
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        width: 50px !important;
        height: 50px !important;
        background: #f56400 !important;
        color: white !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 24px !important;
        cursor: pointer !important;
        z-index: 10001 !important;
        border-bottom-left-radius: 8px !important;
    }

    .categories-main {
        min-width: 100% !important;
        border-right: none !important;
        padding-bottom: 40px !important;
    }

    .categories-sub {
        display: none !important;
    }

    .category-item {
        padding: 14px 16px !important;
        font-size: 15px !important;
        display: block !important;
        width: 100% !important;
        text-align: left !important;
        border-bottom: 1px solid #e3e3e3 !important;
    }

    /* Subcategories Dropdown */
    .category-item.has-children::after {
        content: "▼" !important;
        float: right !important;
        font-size: 12px !important;
        transition: transform 0.3s !important;
    }

    .category-item.has-children.expanded::after {
        transform: rotate(180deg) !important;
    }

    .subcategories-mobile {
        display: none !important;
        background: #f9f9f9 !important;
        padding: 8px 0 !important;
    }

    .subcategories-mobile.show {
        display: block !important;
    }

    .subcategory-link-mobile {
        display: block !important;
        padding: 10px 16px 10px 32px !important;
        color: #666 !important;
        text-decoration: none !important;
        font-size: 14px !important;
        border-bottom: 1px solid #ececec !important;
    }

    .subcategory-link-mobile:hover {
        background: #f0f0f0 !important;
        color: #f56400 !important;
    }

    /* Product Grid */
    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }

    .product-card {
        border-radius: 12px;
    }

    .product-image {
        height: 180px !important;
    }

    .product-title {
        font-size: 13px !important;
    }

    .product-price {
        font-size: 16px !important;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }

    .footer-section {
        text-align: center;
    }

    .footer-section h3 {
        font-size: 16px;
    }

    .footer-section p,
    .footer-section a {
        font-size: 14px;
    }

    /* Toast Notifications */
    #toastContainer {
        top: 10px !important;
        right: 10px !important;
        left: 10px !important;
        max-width: calc(100% - 20px) !important;
    }

    /* Cart */
    .cart-items {
        grid-template-columns: 1fr !important;
    }

    .cart-item {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .cart-item-image {
        width: 100% !important;
        height: 200px !important;
    }

    /* Checkout */
    .checkout-grid {
        grid-template-columns: 1fr !important;
    }

    .checkout-section {
        padding: 16px !important;
    }

    /* Forms */
    input, select, textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }

    .form-grid {
        grid-template-columns: 1fr !important;
    }

    /* Buttons */
    .btn-primary,
    .btn-outline,
    .btn {
        width: 100%;
        padding: 14px !important;
        font-size: 15px !important;
    }

    /* Modal / Popup */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 24px !important;
    }

    /* Tables */
    table {
        font-size: 13px;
    }

    th, td {
        padding: 10px 8px !important;
    }

    /* Dashboard */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .stat-card {
        padding: 16px !important;
    }

    .stat-value {
        font-size: 24px !important;
    }

    .stat-label {
        font-size: 12px !important;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    /* Container - px-4 (16px) padding */
    .container,
    .container-sm,
    .container-md,
    .container-lg {
        padding: 0 16px !important;
    }

    /* Header */
    .logo img {
        height: 28px !important;
    }

    .header-actions .btn {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    .categories-btn {
        padding: 6px 8px !important;
        font-size: 12px !important;
    }

    /* Navigation */
    nav a {
        font-size: 13px !important;
        padding: 6px 10px !important;
    }

    /* Product Grid - Keep 2 columns on mobile */
    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .product-image {
        height: 240px !important;
    }

    .product-title {
        font-size: 14px !important;
    }

    .product-price {
        font-size: 18px !important;
    }

    /* Main Content */
    main {
        padding: 12px 0 !important;
    }

    /* Section Titles */
    h1 {
        font-size: 24px !important;
    }

    h2 {
        font-size: 20px !important;
    }

    h3 {
        font-size: 18px !important;
    }

    /* Footer */
    footer {
        padding: 24px 0 16px !important;
    }

    .footer-section h3 {
        font-size: 15px !important;
    }

    .footer-section p,
    .footer-section a {
        font-size: 13px !important;
    }

    .footer-bottom {
        font-size: 11px !important;
        padding-top: 16px !important;
    }

    /* Dashboard Stats */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .stat-card {
        padding: 14px !important;
    }

    /* Forms */
    input, select, textarea, button {
        padding: 12px !important;
        font-size: 16px !important;
    }

    .form-group label {
        font-size: 14px !important;
    }

    /* Product Detail */
    .product-detail-grid {
        grid-template-columns: 1fr !important;
    }

    .product-detail-image {
        height: 300px !important;
    }

    /* Cart Badge */
    .cart-badge {
        right: -4px !important;
        top: -4px !important;
        font-size: 10px !important;
        min-width: 16px !important;
        height: 16px !important;
    }

    /* Alert/Success Messages */
    .alert, .alert-error, .alert-success {
        padding: 12px !important;
        font-size: 13px !important;
    }
}

/* Extra Small Mobile */
@media (max-width: 360px) {
    /* Container - minimum 12px padding for very small screens */
    .container,
    .container-sm,
    .container-md,
    .container-lg {
        padding: 0 12px !important;
    }

    .logo img {
        height: 24px !important;
    }

    /* Keep 2 columns even on very small screens */
    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .product-title {
        font-size: 12px !important;
    }

    .product-price {
        font-size: 14px !important;
    }

    .product-image {
        height: 160px !important;
    }

    h1 {
        font-size: 22px !important;
    }

    h2 {
        font-size: 18px !important;
    }
}

/* Landscape Mode (Mobile) */
@media (max-width: 768px) and (orientation: landscape) {
    .categories-menu {
        height: 100vh !important;
        overflow-y: auto !important;
    }

    nav ul {
        flex-direction: row !important;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    button, a, input[type="button"], input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Better tap highlighting */
    button, a {
        -webkit-tap-highlight-color: rgba(245, 100, 0, 0.1);
    }

    /* Remove hover effects on touch */
    .product-card:hover {
        transform: none;
    }

    .btn:hover {
        transform: none;
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari fixes */
    input, select, textarea {
        font-size: 16px !important;
    }

    .search-bar input {
        font-size: 16px !important;
    }
}

/* Print Media */
@media print {
    header, footer, nav, .header-actions, .categories-dropdown {
        display: none !important;
    }

    .container {
        max-width: 100% !important;
    }

    .product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

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

@media (max-width: 768px) {
    /* Sticky Top Bar */
    #stickyTopBar {
        top: 50px !important;
    }

    #stickyTopBar > div {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    #stickyTopBar button {
        width: 100% !important;
        padding: 12px !important;
    }

    #stickyQuantity {
        width: 100% !important;
    }

    /* Product Detail Grid */
    .product-detail-content {
        grid-template-columns: 1fr !important;
    }

    /* Product Images */
    .product-images-grid {
        grid-template-columns: 1fr !important;
    }

    .main-image {
        height: 350px !important;
    }

    .thumbnail-images {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
    }

    .thumbnail-image {
        height: 70px !important;
    }

    /* Product Info */
    .product-info-section {
        padding: 16px !important;
    }

    .product-title-detail {
        font-size: 20px !important;
    }

    .product-price-large {
        font-size: 28px !important;
    }

    /* Reviews */
    .reviews-section {
        padding: 16px !important;
    }

    .review-card {
        padding: 14px !important;
    }

    /* Related Products */
    .related-products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    #stickyTopBar {
        top: 45px !important;
    }

    .main-image {
        height: 280px !important;
    }

    .thumbnail-images {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .product-title-detail {
        font-size: 18px !important;
    }

    .product-price-large {
        font-size: 24px !important;
    }

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

/* ===================================
   CART PAGE MOBILE
   =================================== */

@media (max-width: 768px) {
    .cart-container {
        padding: 16px !important;
    }

    .cart-grid {
        grid-template-columns: 1fr !important;
    }

    .cart-items-section {
        padding: 16px !important;
    }

    .cart-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }

    .cart-item-image {
        width: 100% !important;
        height: 200px !important;
    }

    .cart-item-details {
        width: 100% !important;
    }

    .cart-item-actions {
        width: 100% !important;
        flex-direction: row !important;
        justify-content: space-between !important;
    }

    .quantity-selector {
        flex-direction: row !important;
    }

    .cart-summary {
        position: sticky !important;
        bottom: 0 !important;
        padding: 16px !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
    }
}

@media (max-width: 480px) {
    .cart-item-title {
        font-size: 14px !important;
    }

    .cart-item-price {
        font-size: 16px !important;
    }

    .quantity-selector button {
        width: 36px !important;
        height: 36px !important;
    }
}

/* ===================================
   CHECKOUT PAGE MOBILE
   =================================== */

@media (max-width: 768px) {
    .checkout-container {
        padding: 16px !important;
    }

    .checkout-grid {
        grid-template-columns: 1fr !important;
    }

    .checkout-section {
        padding: 16px !important;
        margin-bottom: 16px !important;
    }

    .address-grid {
        grid-template-columns: 1fr !important;
    }

    .address-card {
        padding: 14px !important;
    }

    .order-summary {
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
        padding: 16px !important;
    }

    .order-item {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .order-item-image {
        width: 100% !important;
        height: 150px !important;
    }
}

/* ===================================
   SELLER DASHBOARD MOBILE
   =================================== */

@media (max-width: 768px) {
    .dashboard-header {
        padding: 16px !important;
    }

    .dashboard-stats {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .stat-card {
        padding: 16px !important;
    }

    .stat-value {
        font-size: 24px !important;
    }

    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    .dashboard-card {
        padding: 16px !important;
    }

    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .dashboard-table {
        min-width: 600px !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -280px !important;
        width: 280px !important;
        height: 100vh !important;
        background: white !important;
        z-index: 9999 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1) !important;
    }

    .sidebar.active {
        left: 0 !important;
    }

    .mobile-sidebar-toggle {
        display: block !important;
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 56px !important;
        height: 56px !important;
        border-radius: 50% !important;
        background: #f56400 !important;
        color: white !important;
        border: none !important;
        box-shadow: 0 4px 12px rgba(245,100,0,0.4) !important;
        font-size: 24px !important;
        cursor: pointer !important;
        z-index: 999 !important;
    }
}

@media (max-width: 480px) {
    .dashboard-stats {
        gap: 10px !important;
    }

    .stat-card {
        padding: 12px !important;
    }

    .stat-value {
        font-size: 20px !important;
    }

    .stat-label {
        font-size: 11px !important;
    }
}

/* ===================================
   SEARCH PAGE MOBILE
   =================================== */

@media (max-width: 768px) {
    .search-results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .search-filters {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 100% !important;
        height: 100vh !important;
        background: white !important;
        z-index: 9999 !important;
        overflow-y: auto !important;
        transition: left 0.3s ease !important;
        padding: 20px !important;
    }

    .search-filters.active {
        left: 0 !important;
    }

    .filter-toggle-btn {
        display: block !important;
        width: 100% !important;
        padding: 12px !important;
        background: #f56400 !important;
        color: white !important;
        border: none !important;
        border-radius: 8px !important;
        margin-bottom: 16px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
    }
}

@media (max-width: 480px) {
    .search-results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
