/**
 * WooCommerce Modern Orders - Minimalistic Design
 * 
 * Modern, clean redesign for WooCommerce orders table
 * Compatible with Multi-Cart Saver plugin
 */

/* ============================================
 * CSS VARIABLES & FOUNDATIONS
 * ============================================ */
:root {
    --wcmo-primary: #3b82f6;
    --wcmo-primary-light: #dbeafe;
    --wcmo-primary-dark: #1e40af;
    --wcmo-success: #10b981;
    --wcmo-success-light: #d1fae5;
    --wcmo-warning: #f59e0b;
    --wcmo-warning-light: #fef3c7;
    --wcmo-danger: #ef4444;
    --wcmo-danger-light: #fee2e2;
    --wcmo-gray-50: #f8fafc;
    --wcmo-gray-100: #f1f5f9;
    --wcmo-gray-200: #e2e8f0;
    --wcmo-gray-300: #cbd5e1;
    --wcmo-gray-400: #94a3b8;
    --wcmo-gray-500: #64748b;
    --wcmo-gray-600: #475569;
    --wcmo-gray-700: #334155;
    --wcmo-gray-800: #1e293b;
    --wcmo-gray-900: #0f172a;
    --wcmo-white: #ffffff;
    --wcmo-radius: 12px;
    --wcmo-radius-sm: 8px;
    --wcmo-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --wcmo-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --wcmo-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --wcmo-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================
 * SEARCH FUNCTIONALITY
 * ============================================ */
.wcmo-search-container {
    background: var(--wcmo-white);
    border-radius: var(--wcmo-radius);
    box-shadow: var(--wcmo-shadow);
    padding: 24px;
    margin-bottom: 32px;
    border: 1px solid var(--wcmo-gray-200);
}

.wcmo-search-wrapper {
    position: relative;
    max-width: 500px;
    margin: 0 auto;
    /* Ensure no floating or positioning issues */
    clear: both;
    overflow: visible;
}

.wcmo-search-input {
    width: 100%;
    padding: 16px 50px 16px 16px;
    border: 2px solid var(--wcmo-gray-200);
    border-radius: 12px;
    font-size: 16px;
    font-family: var(--wcmo-font-family);
    transition: all 0.2s ease;
    background: var(--wcmo-white);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    /* Prevent zoom on iOS */
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: text;
}

.wcmo-search-input::placeholder {
    color: var(--wcmo-gray-400);
    font-weight: 400;
    padding-left: 0;
}

.wcmo-search-input:focus {
    outline: none;
    border-color: var(--wcmo-primary);
    background: var(--wcmo-white);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

/* Remove the search icon - it's causing overlap issues */
.wcmo-search-wrapper::before {
    display: none;
}

.wcmo-search-clear {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--wcmo-gray-300);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--wcmo-gray-600);
    z-index: 3;
}

.wcmo-search-clear:hover {
    background: var(--wcmo-gray-400);
    color: var(--wcmo-white);
}

.wcmo-search-clear.show {
    display: flex;
}

.wcmo-search-results-info {
    margin-top: 16px;
    color: var(--wcmo-gray-600);
    font-size: 14px;
    transition: opacity 0.2s ease;
}

/* Hidden order cards during search - AGGRESSIVE HIDING */
.wcmo-order-card.wcmo-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    left: -9999px !important;
    z-index: -1 !important;
    transform: scale(0) !important;
}

/* Ensure visible orders are properly shown */
.wcmo-order-card:not(.wcmo-hidden) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    left: auto !important;
    z-index: auto !important;
    transform: scale(1) !important;
}

/* Search loading state */
.wcmo-search-input.loading {
    background-image: none;
}

.wcmo-search-wrapper.loading::after {
    content: "";
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--wcmo-gray-200);
    border-top: 2px solid var(--wcmo-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 4;
}

/* Hide clear button when loading */
.wcmo-search-wrapper.loading .wcmo-search-clear {
    display: none !important;
}

@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* ============================================
 * MODERN ORDERS TABLE CONTAINER
 * ============================================ */
.wcmo-orders-container {
    background: var(--wcmo-white);
    border-radius: var(--wcmo-radius);
    overflow: hidden;
    box-shadow: var(--wcmo-shadow);
    border: 1px solid var(--wcmo-gray-200);
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
    z-index: 10;
}

/* Force show our modern elements */
.wcmo-modern-orders-active .wcmo-search-container,
.wcmo-modern-orders-active .wcmo-orders-container,
.wcmo-modern-orders-active .wcmo-order-card {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Hide default WooCommerce table styles */
.wcmo-modern-orders-active .woocommerce-orders-table,
.wcmo-modern-orders-active .woocommerce-table {
    margin: 0;
    box-shadow: none;
    border: none;
}

/* ============================================
 * MODERN ORDER CARD DESIGN
 * ============================================ */
.wcmo-order-card {
    border-bottom: 1px solid var(--wcmo-gray-100);
    padding: 24px;
    transition: var(--wcmo-transition);
    position: relative;
}

.wcmo-order-card:last-child {
    border-bottom: none;
}

.wcmo-order-card:hover {
    background: var(--wcmo-gray-50);
}

.wcmo-order-card.completed {
    border-left: 4px solid var(--wcmo-success);
}

.wcmo-order-card.processing {
    border-left: 4px solid var(--wcmo-warning);
}

.wcmo-order-card.pending {
    border-left: 4px solid var(--wcmo-primary);
}

.wcmo-order-card.cancelled,
.wcmo-order-card.failed {
    border-left: 4px solid var(--wcmo-danger);
}

/* ============================================
 * ORDER CARD HEADER
 * ============================================ */
.wcmo-order-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 16px;
}

.wcmo-order-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.wcmo-order-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--wcmo-gray-900);
    font-family: var(--wcmo-font-family);
}

.wcmo-order-date {
    color: var(--wcmo-gray-600);
    font-size: 14px;
}

.wcmo-order-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.wcmo-order-status.completed {
    background: var(--wcmo-success-light);
    color: var(--wcmo-success);
}

.wcmo-order-status.processing {
    background: var(--wcmo-warning-light);
    color: var(--wcmo-warning);
}

.wcmo-order-status.pending {
    background: var(--wcmo-primary-light);
    color: var(--wcmo-primary);
}

.wcmo-order-status.cancelled,
.wcmo-order-status.failed {
    background: var(--wcmo-danger-light);
    color: var(--wcmo-danger);
}

/* ============================================
 * ORDER CARD CONTENT
 * ============================================ */
.wcmo-order-content {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 24px;
    align-items: center;
}

.wcmo-order-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wcmo-order-total {
    font-size: 20px;
    font-weight: 700;
    color: var(--wcmo-gray-900);
    font-family: var(--wcmo-font-family);
}

.wcmo-order-items {
    color: var(--wcmo-gray-600);
    font-size: 14px;
}

/* ============================================
 * ORDER ACTIONS
 * ============================================ */
.wcmo-order-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.wcmo-action-btn {
    padding: 8px 16px;
    border: 2px solid var(--wcmo-gray-300);
    border-radius: var(--wcmo-radius-sm);
    background: var(--wcmo-white);
    color: var(--wcmo-gray-700);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--wcmo-transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--wcmo-font-family);
}

.wcmo-action-btn:hover {
    border-color: var(--wcmo-primary);
    color: var(--wcmo-primary);
    transform: translateY(-1px);
    box-shadow: var(--wcmo-shadow);
}

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

.wcmo-action-btn.primary:hover {
    background: var(--wcmo-primary-dark);
    border-color: var(--wcmo-primary-dark);
    color: var(--wcmo-white);
}

/* ============================================
 * MULTI-CART SAVER INTEGRATION
 * ============================================ */
.wcmo-modern-orders-active .wcmcs-order-cart-info {
    background: linear-gradient(135deg, var(--wcmo-primary-light) 0%, #e0f2fe 100%) !important;
    border: 1px solid var(--wcmo-primary) !important;
    border-radius: var(--wcmo-radius-sm) !important;
    margin-top: 16px !important;
    padding: 16px !important;
    box-shadow: var(--wcmo-shadow) !important;
    border-left: 4px solid var(--wcmo-primary) !important;
}

.wcmo-modern-orders-active .wcmcs-cart-name {
    color: var(--wcmo-primary-dark) !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    font-family: var(--wcmo-font-family) !important;
    margin-bottom: 8px !important;
}

.wcmo-modern-orders-active .wcmcs-order-number {
    color: var(--wcmo-gray-700) !important;
    font-weight: 500 !important;
    font-size: 13px !important;
    font-family: var(--wcmo-font-family) !important;
    margin-bottom: 6px !important;
}

.wcmo-modern-orders-active .wcmcs-ordered-by {
    color: var(--wcmo-gray-600) !important;
    font-size: 12px !important;
    font-family: var(--wcmo-font-family) !important;
}

.wcmo-modern-orders-active .wcmcs-order-cart-info .dashicons {
    color: var(--wcmo-primary) !important;
    font-size: 14px !important;
    width: 14px !important;
    height: 14px !important;
}

/* ============================================
 * LOADING STATES
 * ============================================ */
.wcmo-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--wcmo-gray-600);
    font-size: 16px;
}

.wcmo-loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--wcmo-gray-300);
    border-radius: 50%;
    border-top-color: var(--wcmo-primary);
    animation: wcmo-spin 1s ease-in-out infinite;
    margin-right: 12px;
}

@keyframes wcmo-spin {
    to { transform: rotate(360deg); }
}

.wcmo-no-results {
    text-align: center;
    padding: 48px 24px;
    color: var(--wcmo-gray-600);
}

.wcmo-no-results-icon {
    font-size: 48px;
    color: var(--wcmo-gray-300);
    margin-bottom: 16px;
}

.wcmo-no-results-text {
    font-size: 18px;
    margin-bottom: 8px;
}

.wcmo-no-results-subtext {
    font-size: 14px;
    color: var(--wcmo-gray-500);
}

/* ============================================
 * RESPONSIVE DESIGN
 * ============================================ */
@media (max-width: 768px) {
    .wcmo-search-container {
        padding: 16px;
        margin-bottom: 24px;
    }
    
    .wcmo-search-input {
        padding: 14px 16px 14px 44px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .wcmo-order-card {
        padding: 16px;
    }
    
    .wcmo-order-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .wcmo-order-content {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .wcmo-order-actions {
        justify-content: stretch;
    }
    
    .wcmo-action-btn {
        flex: 1;
        justify-content: center;
        min-height: 44px; /* Touch-friendly */
    }
    
    .wcmo-order-number {
        font-size: 16px;
    }
    
    .wcmo-order-total {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .wcmo-order-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .wcmo-action-btn {
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* ============================================
 * THEME COMPATIBILITY
 * ============================================ */

/* Astra theme compatibility */
.wcmo-theme-astra .wcmo-orders-container {
    font-family: inherit;
}

.wcmo-theme-astra .wcmo-action-btn {
    font-family: inherit;
}

/* General WooCommerce compatibility */
.woocommerce-account .woocommerce-MyAccount-content .wcmo-orders-container {
    margin-bottom: 0;
}

/* Ensure proper spacing in account area */
.woocommerce-MyAccount-content .wcmo-search-container:first-child {
    margin-top: 0;
}

/* AGGRESSIVE FORCE HIDE ALL ORIGINAL WOOCOMMERCE & THEME ORDER ELEMENTS */
.wcmo-modern-orders-active .woocommerce-orders-table,
.wcmo-modern-orders-active .woocommerce-orders-table__row,
.wcmo-modern-orders-active .shop_table.shop_table_responsive.my_account_orders,
.wcmo-modern-orders-active .shop_table.my_account_orders,
.wcmo-modern-orders-active table.my_account_orders,
.wcmo-modern-orders-active .woocommerce-table,
.wcmo-modern-orders-active .woocommerce-table--order-details,
.wcmo-modern-orders-active .ast-orders-table,
.wcmo-modern-orders-active .ast-orders-table__row,
.wcmo-modern-orders-active .ast-woo-grid-orders-container,
.wcmo-modern-orders-active .ast-woo-grid-orders-container *,
body.wcmo-modern-orders-active .woocommerce-orders-table,
body.wcmo-modern-orders-active .shop_table.my_account_orders,
body.wcmo-modern-orders-active .ast-woo-grid-orders-container,
body.wcmo-theme-astra .ast-orders-table,
body.wcmo-theme-astra .ast-woo-grid-orders-container {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    left: -9999px !important;
    z-index: -1 !important;
}

/* Also hide any Astra-specific order elements */
.wcmo-modern-orders-active .ast-orders-table__cell,
.wcmo-modern-orders-active .ast-orders-table__cell-order-number,
.wcmo-modern-orders-active .ast-orders-table__cell-order-date,
.wcmo-modern-orders-active .ast-orders-table__cell-order-status,
.wcmo-modern-orders-active .ast-orders-table__cell-order-total,
.wcmo-modern-orders-active .ast-orders-table__cell-order-actions {
    display: none !important;
}

/* Force hide any remaining WooCommerce order elements */
.wcmo-modern-orders-active .woocommerce-orders-table *:not(.wcmo-search-container):not(.wcmo-orders-container):not(.wcmo-order-card):not(.wcmo-order-card *) {
    display: none !important;
}

/* ============================================
 * ACCESSIBILITY
 * ============================================ */
.wcmo-action-btn:focus {
    outline: 2px solid var(--wcmo-primary);
    outline-offset: 2px;
}

.wcmo-search-input:focus {
    outline: none; /* Custom focus styles provided above */
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --wcmo-gray-100: #e5e5e5;
        --wcmo-gray-200: #cccccc;
        --wcmo-gray-300: #999999;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
 * PRINT STYLES
 * ============================================ */
@media print {
    .wcmo-search-container,
    .wcmo-order-actions {
        display: none;
    }
    
    .wcmo-order-card {
        break-inside: avoid;
        border: 1px solid #000;
        margin-bottom: 1rem;
    }
}