/**
 * Responsive Styles
 */

/* Tablet (max-width: 1024px) */
@media (max-width: 1024px) {
    /* Layout adjustments */
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] {
        grid-template-columns: 1fr 1fr;
    }
    
    /* Progress bar */
    .vime-progress-title {
        font-size: 12px;
    }
    
    .vime-progress-icon,
    .vime-progress-number {
        width: 40px;
        height: 40px;
    }
    
    /* Table adjustments */
    .vime-cart-table {
        font-size: 14px;
    }
    
    .vime-product-thumbnail img {
        max-width: 60px;
    }
    
    /* Products grid */
    .vime-products-grid[data-columns="4"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    /* Container - remove padding on mobile */
    .vime-cart-container {
        padding: 0;
    }
    
    /* Layout - Force single column on mobile */
    .vime-cart-container[data-settings*='"layout_type":"two_columns"'],
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] {
        display: block !important;
    }
    
    /* Ensure all direct children are block level */
    .vime-cart-container[data-settings*='"layout_type":"two_columns"'] > *,
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] > * {
        display: block !important;
        width: 100% !important;
        margin-bottom: 20px;
    }
    
    /* Remove any grid-specific styles from children */
    .vime-cart-container[data-settings*='"layout_type":"two_columns"'] .vime-cart-main,
    .vime-cart-container[data-settings*='"layout_type":"two_columns"'] .vime-cart-sidebar,
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] .vime-cart-main,
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] .vime-cart-sidebar,
    .vime-cart-container[data-settings*='"layout_type":"three_columns"'] .vime-cart-upsell {
        grid-column: unset !important;
        grid-row: unset !important;
    }
    
    /* Header */
    .vime-cart-header {
        margin-bottom: 20px;
    }
    
    .vime-cart-title {
        font-size: 24px;
    }
    
    /* Progress bar */
    .vime-progress-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .vime-progress-step {
        min-width: 100px;
    }
    
    /* Cart table - Mobile layout matching screenshot */
    .vime-cart-table-wrapper {
        overflow-x: visible;
    }
    
    .vime-cart-table {
        width: 100%;
    }
    
    .vime-cart-table thead {
        display: none;
    }
    
    .vime-cart-table tbody {
        display: block;
    }
    
    /* Remove striped background on mobile */
    table tbody>tr:nth-child(odd)>td,
    table tbody>tr:nth-child(odd)>th,
    table tbody tr:hover>td, table tbody tr:hover>th {
        background-color: transparent!important;
    }
    
    .vime-cart-table tr {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        margin-bottom: 10px;
        padding: 12px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        background: #fff;
        position: relative;
    }
    
    .vime-cart-table td {
        display: block;
        padding: 0;
        border: none;
    }
    
    .vime-cart-table td::before {
        display: none;
    }
    
    /* Remove button - position at bottom left next to quantity */
    .vime-cart-table .vime-product-remove {
        order: 6;
        margin-right: 10px;
        margin-top: 0;
        position: static;
        flex: 0 0 auto;
        min-height: auto;
        min-width: auto;
    }
    
    .vime-remove-item {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        background: #f5f5f5;
        border: 1px solid #e0e0e0;
        border-radius: 4px;
        color: #e74c3c;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    .vime-remove-item:hover {
        background: #e74c3c;
        color: white;
        border-color: #e74c3c;
    }
    
    .vime-remove-item svg,
    .vime-remove-item i {
        width: 16px;
        height: 16px;
        font-size: 16px;
    }
    
    /* Product thumbnail */
    .vime-cart-table .vime-product-thumbnail {
        order: 1;
        width: 50px;
        min-width: 50px;
        margin-right: 12px;
    }
    
    .vime-product-thumbnail img {
        width: 100%;
        height: auto;
        border-radius: 4px;
    }
    
    /* Product info container */
    .vime-cart-table .vime-product-name {
        order: 2;
        flex: 1 1 calc(100% - 70px);
        display: flex;
        flex-direction: column;
        margin-right: 0;
    }
    
    .vime-product-name a {
        font-size: 14px;
        font-weight: 500;
        color: #333;
        line-height: 1.2;
        margin-bottom: 2px;
        display: block;
    }
    
    .vime-product-sku {
        font-size: 11px;
        color: #999;
        margin-top: 2px;
    }
    
    .vime-product-meta {
        font-size: 11px;
        color: #666;
    }
    
    /* Price columns - hide on mobile */
    .vime-cart-table .vime-product-price {
        display: none !important;
    }
    
    .vime-cart-table .vime-product-subtotal {
        display: none !important;
    }
    
    /* Mobile price - hide (will show in different position) */
    .vime-product-price-mobile {
        display: none !important;
    }
    
    /* Quantity - position in second row */
    .vime-cart-table .vime-product-quantity {
        order: 7;
        margin-top: 10px;
        flex: 0 0 auto;
    }
    
    .vime-quantity-wrapper {
        display: flex;
        align-items: center;
        background: #f5f5f5;
        border-radius: 4px;
        padding: 0;
        border: 1px solid #e0e0e0;
    }
    
    .vime-quantity-input-group {
        min-height: auto;
        min-width: auto;
    }
    
    .vime-quantity-wrapper button {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
        padding: 0;
        font-size: 18px;
        border: none;
        background: transparent;
        color: #666;
        cursor: pointer;
    }
    
    .vime-quantity-wrapper button:hover {
        background: #e0e0e0;
    }
    
    .vime-quantity-wrapper input[type="number"] {
        width: 35px;
        height: 30px;
        text-align: center;
        border: none;
        border-left: 1px solid #e0e0e0;
        border-right: 1px solid #e0e0e0;
        background: white;
        font-size: 14px;
        padding: 0;
        margin: 0;
    }
    
    /* Mobile price cell - position in second row, right aligned */
    .vime-product-price-mobile-cell {
        display: none;
    }
    
    .vime-cart-table .vime-product-price-mobile-cell {
        display: block !important;
        order: 8;
        flex: 1 1 auto;
        align-self: center;
        text-align: right;
        margin-top: 10px;
        margin-left: auto;
    }
    
    .vime-price-mobile-display {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        white-space: nowrap;
    }
    
    /* Force full width break after product name */
    .vime-cart-table tr::before {
        content: '';
        width: 100%;
        order: 4;
    }
    
    /* Shipping Calculator - Keep inline on mobile */
    .vime-shipping-calculator .shipping-calculator-form,
    .vime-shipping-calculator form {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-end !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
    }
    
    /* Force all direct children to participate in flex */
    .vime-shipping-calculator .shipping-calculator-form > *,
    .vime-shipping-calculator form > * {
        flex-shrink: 0 !important;
    }
    
    /* Hide any hidden fields that might interfere */
    .vime-shipping-calculator input[type="hidden"] {
        display: none !important;
    }
    
    .vime-shipping-calculator .shipping-calculator-form p {
        margin: 0 !important;
        width: auto !important;
        display: block !important;
    }
    
    .vime-shipping-calculator .shipping-calculator-form .form-row {
        margin: 0 !important;
        width: auto !important;
        display: block !important;
    }
    
    /* Container do input de CEP */
    .vime-shipping-calculator .shipping-calculator-form p:first-child,
    .vime-shipping-calculator .shipping-calculator-form .form-row:first-child {
        flex: 1 1 auto !important;
        width: auto !important;
    }
    
    /* Container do botão */
    .vime-shipping-calculator .shipping-calculator-form p:last-child,
    .vime-shipping-calculator .shipping-calculator-form .form-row:last-child {
        flex: 0 0 auto !important;
        width: auto !important;
    }
    
    /* Fallback para :has() se suportado */
    @supports selector(:has(*)) {
        .vime-shipping-calculator .shipping-calculator-form p:has(input[name="calc_shipping_postcode"]) {
            flex: 1 1 auto !important;
            max-width: calc(100% - 100px) !important;
            width: auto !important;
        }
        
        .vime-shipping-calculator .shipping-calculator-form p:has(button[name="calc_shipping"]) {
            flex: 0 0 auto !important;
            width: auto !important;
        }
    }
    
    /* Garantir que elementos não quebrem linha */
    .vime-shipping-calculator .shipping-calculator-form br {
        display: none !important;
    }
    
    /* Reset de margins e paddings que possam estar interferindo */
    .vime-shipping-calculator .shipping-calculator-form label {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Input de CEP */
    .vime-shipping-calculator input[name="calc_shipping_postcode"] {
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px 12px !important;
        font-size: 14px !important;
        box-sizing: border-box !important;
    }
    
    /* Botão de calcular */
    .vime-shipping-calculator button[name="calc_shipping"] {
        padding: 8px 12px !important;
        font-size: 13px !important;
        white-space: nowrap !important;
        width: auto !important;
        min-width: 80px !important;
        height: -webkit-fill-available;
        line-height: normal !important;
    }
    
    /* Coupon form */
    .vime-coupon-form {
        flex-direction: column;
    }
    
    .vime-coupon-input,
    .vime-button {
        width: 100%;
    }
    
    /* Cart totals */
    .vime-cart-totals {
        padding: 20px;
    }
    
    /* Action buttons */
    .vime-cart-actions {
        flex-direction: column;
    }
    
    .vime-cart-actions .vime-button {
        width: 100%;
        justify-content: center;
    }
    
    .vime-clear-cart {
        margin-left: 0;
        order: 3;
    }
    
    /* Sticky checkout button */
    .vime-cart-widget[data-sticky-mobile="yes"] .vime-checkout-button {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        margin: 0;
        border-radius: 0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }
    
    /* Products grid */
    .vime-products-grid[data-columns="3"],
    .vime-products-grid[data-columns="4"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Email capture */
    .vime-capture-form {
        flex-direction: column;
    }
    
    /* Shipping cards - ensure single column on mobile */
    .vime-shipping-cards {
        grid-template-columns: 1fr !important;
    }
}

/* Shipping calculator responsive */
@media (max-width: 768px) {
    .vime-shipping-calculator .shipping-calculator-form {
        align-items: stretch !important;
    }
    
    .vime-shipping-calculator .shipping-calculator-form p,
    .vime-shipping-calculator .shipping-calculator-form .form-row {
        width: 100% !important;
        max-width: none !important;
        flex: 1 1 100% !important;
    }
    
    .vime-shipping-calculator button[name="calc_shipping"] {
        width: 100%;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    
    /* Further adjustments for small screens */
    .vime-cart-table tr {
        padding: 10px;
    }
    
    .vime-cart-table .vime-product-thumbnail {
        width: 45px;
        min-width: 45px;
        margin-right: 8px;
    }
    
    /* Adjust product name to take full space minus thumbnail */
    .vime-cart-table .vime-product-name {
        flex: 1 1 calc(100% - 60px);
    }
    
    .vime-product-name a {
        font-size: 13px;
        line-height: 1.3;
    }
    
    .vime-product-sku {
        font-size: 10px;
    }
    
    .vime-price-mobile-display {
        font-size: 14px;
    }
    
    /* Ensure remove button and quantity stay together */
    .vime-cart-table .vime-product-remove {
        margin-right: 8px;
    }
    
    .vime-quantity-wrapper {
        transform: scale(0.9);
    }
    
    .vime-remove-item {
        width: 26px;
        height: 26px;
        min-width: 26px;
        min-height: 26px;
        font-size: 14px;
    }
    
    .vime-remove-item svg,
    .vime-remove-item i {
        width: 14px;
        height: 14px;
        font-size: 14px;
    }
    
    /* Progress bar */
    .vime-progress-step {
        min-width: 80px;
        padding: 5px;
    }
    
    .vime-progress-icon,
    .vime-progress-number {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    .vime-progress-title {
        font-size: 11px;
    }
    
    /* Products grid */
    .vime-products-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Cart table mobile */
    .vime-cart-table td::before {
        width: 100px;
        font-size: 13px;
    }
    
    /* Buttons */
    .vime-button {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* Accordion mobile layout */
@media (max-width: 768px) {
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .vime-cart-section {
        border: 1px solid #e0e0e0;
        border-radius: 4px;
        margin-bottom: 10px;
        overflow: hidden;
    }
    
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .vime-section-header {
        background: #f9f9f9;
        padding: 15px;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .vime-section-content {
        padding: 15px;
        display: none;
    }
    
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .vime-section-content.active {
        display: block;
    }
    
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .vime-section-toggle {
        transition: transform 0.3s;
    }
    
    .vime-cart-container[data-settings*='"layout_type":"accordion_mobile"'] .active .vime-section-toggle {
        transform: rotate(180deg);
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .vime-remove-item,
    .vime-button,
    .vime-quantity-wrapper button {
        min-height: auto;
        min-width: auto;
    }
    
    /* Quantity input */
    .vime-quantity-wrapper input[type="number"] {
        min-height: auto;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Form inputs */
    .vime-coupon-input,
    .vime-capture-form input {
        min-height: 44px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Print styles */
@media print {
    .vime-cart-actions,
    .vime-remove-item,
    .vime-toggle-coupon,
    .vime-toggle-shipping,
    .vime-coupon-section,
    .vime-shipping-section,
    .vime-cross-sells,
    .vime-upsells,
    .vime-email-capture {
        display: none !important;
    }
    
    .vime-cart-table {
        border: 1px solid #000;
    }
    
    .vime-cart-table th,
    .vime-cart-table td {
        border: 1px solid #000;
    }
}