/**
 * Frontend Order System Styles
 * 
 * Responsive styles for the frontend ordering interface
 * Mobile-first design with 767px breakpoint
 */

/* ==========================================================================
   Hide Default WooCommerce Elements
   ========================================================================== */

/* Hide default WooCommerce add to cart form when our system is present */
.frontend-order-system-container ~ .cart,
.frontend-order-system-container ~ form.cart,
.frontend-order-system-container ~ .single_add_to_cart_button,
.frontend-order-app ~ .cart,
.frontend-order-app ~ form.cart,
.frontend-order-app ~ .single_add_to_cart_button {
    display: none !important;
}

/* Hide WooCommerce quantity selector when our system is active */
body.single-product .frontend-order-system-container ~ .quantity,
body.single-product .frontend-order-app ~ .quantity {
    display: none !important;
}

/* Hide default WooCommerce variation dropdowns */
body.single-product .frontend-order-system-container ~ .variations,
body.single-product .frontend-order-app ~ .variations,
body.single-product .frontend-order-system-container ~ .variations_form .variations,
body.single-product .frontend-order-app ~ .variations_form .variations {
    display: none !important;
}

/* Hide WooCommerce stock status when our system is showing */
body.single-product .frontend-order-system-container ~ .stock,
body.single-product .frontend-order-app ~ .stock {
    display: none !important;
}

/* Hide WooCommerce price range when our system is present */
body.single-product .frontend-order-system-container ~ .price,
body.single-product .frontend-order-app ~ .price,
.product .summary .price,
.woocommerce-Price-amount,
.woocommerce div.product p.price,
.woocommerce div.product span.price {
    display: none !important;
}

/* More specific targeting for common WooCommerce elements */
.product .summary .cart {
    display: none !important;
}

.product .summary form.cart {
    display: none !important;
}

.product .summary .single_add_to_cart_button {
    display: none !important;
}

.product .summary .quantity {
    display: none !important;
}

.product .summary .variations {
    display: none !important;
}

.product .summary .stock {
    display: none !important;
}

/* ==========================================================================
   Main Container
   ========================================================================== */

#frontend-order-root {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.frontend-order-app {
    max-width: 100%;
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Header Section
   ========================================================================== */

.fos-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 8px 8px 0 0;
    text-align: center;
}

.fos-header h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.fos-header p {
    margin: 0;
    opacity: 0.9;
    font-size: 0.9rem;
}

/* ==========================================================================
   Loading States
   ========================================================================== */

.fos-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #666;
}

.fos-loading .spinner {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==========================================================================
   Error States
   ========================================================================== */

.fos-error {
    background: #ffe6e6;
    border: 1px solid #ff9999;
    color: #cc0000;
    padding: 12px 16px;
    border-radius: 4px;
    margin: 10px 0;
}

.fos-error-icon {
    margin-right: 8px;
}

/* ==========================================================================
   Success States
   ========================================================================== */

.fos-success {
    background: #e6ffe6;
    border: 1px solid #99cc99;
    color: #006600;
    padding: 12px 16px;
    border-radius: 4px;
    margin: 10px 0;
}

.fos-success-icon {
    margin-right: 8px;
}

/* ==========================================================================
   Product Information Section
   ========================================================================== */

.fos-product-info {
    background: #f8f9fa;
    border-bottom: 1px solid #e1e1e1;
    padding: 16px 20px;
}

.fos-product-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin: 0 0 8px;
}

.fos-product-price {
    font-size: 1.2rem;
    font-weight: 700;
    color: #0073aa;
    margin: 0;
}

.fos-product-stock-info {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 8px;
    font-size: 0.9rem;
    color: #666;
}

.fos-stock-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
}

.fos-stock-icon {
    color: #28a745;
}

/* ==========================================================================
   Variation Selection
   ========================================================================== */

.fos-variation-section {
    padding: 20px;
    border-bottom: 1px solid #e1e1e1;
}

.fos-variation-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px;
    color: #333;
}

.fos-variation-list {
    display: grid;
    gap: 8px;
}

.fos-variation-item {
    border: 2px solid #e1e1e1;
    border-radius: 6px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fff;
}

.fos-variation-item:hover {
    border-color: #0073aa;
    background: #f8f9ff;
}

.fos-variation-item.selected {
    border-color: #0073aa;
    background: #e7f3ff;
    color: #0073aa;
    font-weight: 500;
}

.fos-variation-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.fos-variation-name {
    flex: 1;
}

.fos-variation-price {
    color: #0073aa;
    font-weight: 600;
    font-size: 1.1rem;
    margin-left: 12px;
}

/* ==========================================================================
   Stock Cells Grid
   ========================================================================== */

.fos-stock-section {
    padding: 20px;
    border-bottom: 1px solid #e1e1e1;
}

.fos-stock-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 8px;
    color: #333;
}

.fos-stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}

.fos-stock-cell {
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    padding: 16px;
    background: #fff;
    transition: all 0.2s ease;
}

.fos-stock-cell:hover {
    border-color: #0073aa;
    box-shadow: 0 2px 8px rgba(0, 115, 170, 0.1);
}

.fos-stock-cell.has-selection {
    border-color: #0073aa;
    background: #f8f9ff;
}

.fos-stock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.fos-stock-name {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.fos-stock-available {
    background: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.fos-stock-available.low-stock {
    background: #ffc107;
    color: #333;
}

.fos-stock-available.out-of-stock {
    background: #dc3545;
    color: white;
}

.fos-quantity-selector {
    margin-top: 8px;
}

.fos-quantity-label {
    display: block;
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 8px;
}

.fos-quantity-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.fos-quantity-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

.fos-quantity-range {
    width: 100%;
    margin: 8px 0;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
}

.fos-quantity-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #0073aa;
    border-radius: 50%;
    cursor: pointer;
}

.fos-quantity-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #0073aa;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.fos-quantity-display {
    text-align: center;
    font-weight: 600;
    color: #0073aa;
    margin-top: 4px;
}

/* ==========================================================================
   No Stock / Pre-order Section
   ========================================================================== */

.fos-no-stock-section {
    padding: 20px;
    border-bottom: 1px solid #e1e1e1;
    background: #fff8e1;
    border-left: 4px solid #ffc107;
}

.fos-no-stock-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.fos-no-stock-icon {
    color: #ffc107;
}

.fos-no-stock-message {
    color: #666;
    margin-bottom: 16px;
    line-height: 1.5;
}

.fos-preorder-quantity {
    max-width: 200px;
}

/* ==========================================================================
   Order Summary
   ========================================================================== */

.fos-summary-section {
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e1e1;
}

.fos-summary-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 16px;
    color: #333;
}

.fos-summary-content {
    background: white;
    border: 1px solid #e1e1e1;
    border-radius: 6px;
    padding: 16px;
}

.fos-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.fos-summary-row:last-child {
    margin-bottom: 0;
    padding-top: 8px;
    border-top: 1px solid #e1e1e1;
    font-weight: 600;
    color: #0073aa;
}

.fos-summary-label {
    color: #666;
}

.fos-summary-value {
    color: #333;
    font-weight: 500;
}

.fos-selected-locations {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e1e1e1;
}

.fos-selected-locations h4 {
    font-size: 0.9rem;
    margin: 0 0 8px;
    color: #666;
}

.fos-location-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.fos-location-tag {
    background: #e7f3ff;
    color: #0073aa;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    border: 1px solid #0073aa;
}

/* ==========================================================================
   Action Buttons
   ========================================================================== */

.fos-actions {
    padding: 20px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.fos-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px; /* Touch-friendly */
}

.fos-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.fos-btn-primary {
    background: #0073aa;
    color: white;
}

.fos-btn-primary:hover:not(:disabled) {
    background: #005a87;
}

.fos-btn-secondary {
    background: #6c757d;
    color: white;
}

.fos-btn-secondary:hover:not(:disabled) {
    background: #545b62;
}

.fos-btn-success {
    background: #28a745;
    color: white;
}

.fos-btn-success:hover:not(:disabled) {
    background: #218838;
}

.fos-btn-icon {
    width: 16px;
    height: 16px;
}

/* ==========================================================================
   Guest Welcome Section
   ========================================================================== */

.fos-guest-welcome {
    background: #e1f5fe;
    border: 1px solid #0288d1;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 16px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fos-guest-icon {
    color: #0288d1;
    font-size: 1.2rem;
}

.fos-guest-message {
    flex: 1;
    margin: 0;
    color: #01579b;
    font-size: 0.9rem;
}

.fos-guest-login-link {
    color: #0288d1;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8rem;
}

.fos-guest-login-link:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Modal/Popup Styles
   ========================================================================== */

.fos-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.fos-modal {
    background: white;
    border-radius: 8px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.fos-modal-header {
    padding: 20px 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fos-modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}

.fos-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.fos-modal-close:hover {
    background: #f0f0f0;
}

.fos-modal-body {
    padding: 20px;
}

.fos-modal-footer {
    padding: 0 20px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */

.fos-form-group {
    margin-bottom: 16px;
}

.fos-form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #333;
}

.fos-form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.fos-form-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

.fos-form-input.error {
    border-color: #dc3545;
}

.fos-form-error {
    color: #dc3545;
    font-size: 0.8rem;
    margin-top: 4px;
}

.fos-form-help {
    color: #666;
    font-size: 0.8rem;
    margin-top: 4px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Mobile-first approach with 767px breakpoint */

@media (max-width: 767px) {
    #frontend-order-root {
        margin: 10px 0;
    }
    
    .frontend-order-app {
        border-radius: 4px;
    }
    
    .fos-header {
        padding: 16px;
        border-radius: 4px 4px 0 0;
    }
    
    .fos-header h3 {
        font-size: 1.3rem;
    }
    
    .fos-product-info,
    .fos-variation-section,
    .fos-stock-section,
    .fos-no-stock-section,
    .fos-summary-section {
        padding: 16px;
    }
    
    .fos-stock-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .fos-stock-cell {
        padding: 12px;
    }
    
    .fos-actions {
        padding: 16px;
        flex-direction: column;
    }
    
    .fos-btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 1.1rem;
    }
    
    .fos-guest-welcome {
        margin: 12px 16px;
        padding: 10px 12px;
    }
    
    .fos-modal {
        margin: 10px;
        max-height: calc(100vh - 40px);
    }
    
    .fos-modal-header,
    .fos-modal-body,
    .fos-modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .fos-modal-footer {
        flex-direction: column;
    }
    
    /* Adjust product info layout on mobile */
    .fos-product-stock-info {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    /* Make quantity inputs more touch-friendly */
    .fos-quantity-input,
    .fos-form-input {
        padding: 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Stack summary rows on very small screens */
    @media (max-width: 480px) {
        .fos-summary-row {
            flex-direction: column;
            align-items: flex-start;
            gap: 4px;
        }
        
        .fos-location-tags {
            justify-content: center;
        }
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
    .fos-stock-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .fos-actions {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .fos-btn {
        flex: 1;
        max-width: 200px;
    }
}

/* Desktop enhancements */
@media (min-width: 1025px) {
    .fos-stock-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
    
    .fos-actions {
        justify-content: flex-end;
    }
    
    .fos-btn {
        width: auto;
        min-width: 140px;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.fos-hidden {
    display: none !important;
}

.fos-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.fos-text-center {
    text-align: center;
}

.fos-text-muted {
    color: #666;
}

.fos-mb-0 { margin-bottom: 0; }
.fos-mb-1 { margin-bottom: 8px; }
.fos-mb-2 { margin-bottom: 16px; }
.fos-mb-3 { margin-bottom: 24px; }

.fos-mt-0 { margin-top: 0; }
.fos-mt-1 { margin-top: 8px; }
.fos-mt-2 { margin-top: 16px; }
.fos-mt-3 { margin-top: 24px; }

/* ==========================================================================
   Raw Material Order Interface
   ========================================================================== */

.fos-raw-material-section {
    padding: 20px;
    border-bottom: 1px solid #e1e1e1;
}

.fos-raw-material-header {
    background: linear-gradient(135deg, #ff8f00 0%, #e65100 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 8px;
    margin: -20px -20px 20px -20px;
}

.fos-raw-material-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 4px;
    color: white;
}

.fos-raw-material-variations {
    margin-bottom: 24px;
}

.fos-raw-material-list {
    display: grid;
    gap: 12px;
}

.fos-raw-material-item {
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    padding: 16px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fos-raw-material-item:hover {
    border-color: #ff8f00;
    box-shadow: 0 2px 8px rgba(255, 143, 0, 0.1);
}

.fos-raw-material-item.selected {
    border-color: #e65100;
    background: #fff3e0;
}

.fos-raw-material-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fos-raw-material-info {
    flex: 1;
}

.fos-raw-material-name {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.fos-raw-material-name strong {
    font-size: 1rem;
    color: #333;
}

.fos-raw-material-price {
    color: #e65100;
    font-weight: 600;
    font-size: 1.1rem;
    margin-left: 12px;
}

.fos-raw-material-details {
    display: flex;
    gap: 16px;
    font-size: 0.9rem;
    color: #666;
}

.fos-reduction-value {
    background: #ffecb3;
    color: #e65100;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.fos-max-quantity {
    background: #e8f5e8;
    color: #2e7d32;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.fos-raw-material-check {
    color: #e65100;
    font-size: 1.2rem;
    font-weight: bold;
}

.fos-quantity-section {
    margin: 24px 0;
    padding: 20px;
    background: #fff3e0;
    border: 1px solid #ffcc02;
    border-radius: 8px;
}

.fos-quantity-section h4 {
    color: #e65100;
    margin: 0 0 16px;
}

.fos-quantity-slider-container {
    margin-bottom: 12px;
}

.fos-raw-material-range {
    background: #ffcc02;
}

.fos-raw-material-range::-webkit-slider-thumb {
    background: #e65100;
}

.fos-raw-material-range::-moz-range-thumb {
    background: #e65100;
}

.fos-raw-material-input {
    border-color: #ffcc02;
}

.fos-raw-material-input:focus {
    border-color: #e65100;
    box-shadow: 0 0 0 2px rgba(230, 81, 0, 0.1);
}

.fos-raw-material-preview {
    margin: 24px 0;
    padding: 20px;
    background: white;
    border: 2px solid #e65100;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(230, 81, 0, 0.1);
}

.fos-raw-material-preview h4 {
    color: #e65100;
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.fos-calculation-details {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
}

.fos-calculation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 4px;
}

.fos-calc-label {
    color: #666;
    font-weight: 500;
}

.fos-calc-value {
    font-weight: 600;
    color: #333;
}

.fos-raw-needed {
    color: #e65100;
    background: #fff3e0;
    padding: 4px 8px;
    border-radius: 4px;
}

.fos-efficiency {
    color: #2e7d32;
}

.fos-raw-material-actions {
    text-align: center;
}

.fos-raw-material-btn {
    background: linear-gradient(135deg, #ff8f00 0%, #e65100 100%);
    border: none;
    color: white;
    font-size: 1.1rem;
    padding: 14px 28px;
    min-width: 200px;
}

.fos-raw-material-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #f57c00 0%, #d84315 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(230, 81, 0, 0.2);
}

.fos-raw-material-instructions {
    margin-top: 24px;
    padding: 16px;
    background: #fff8e1;
    border: 1px solid #ffcc02;
    border-radius: 6px;
    font-size: 0.9rem;
}

.fos-raw-material-instructions ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.fos-raw-material-instructions li {
    margin-bottom: 4px;
}

/* Mobile optimizations for raw materials */
@media (max-width: 767px) {
    .fos-raw-material-header {
        margin: -16px -16px 20px -16px;
        padding: 12px 16px;
    }
    
    .fos-raw-material-section {
        padding: 16px;
    }
    
    .fos-raw-material-item {
        padding: 12px;
    }
    
    .fos-raw-material-details {
        flex-direction: column;
        gap: 8px;
    }
    
    .fos-calculation-row {
        padding: 6px 10px;
    }
    
    .fos-raw-material-btn {
        width: 100%;
        font-size: 1rem;
        padding: 12px 20px;
    }
}

/* ==========================================================================
   Animation Classes
   ========================================================================== */

.fos-fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fos-slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    #frontend-order-root {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .fos-actions,
    .fos-btn,
    .fos-modal-overlay {
        display: none !important;
    }
}