/**
 * JP Delivery Pallet Shipping - Frontend Styles
 */

/* Shipping label container */
.jp-delivery-shipping-label {
    width: 100%;
    padding: 0;
    margin: 0;
}

/* Title and delivery time */
.jp-delivery-shipping-label .jp-delivery-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: normal;
}

.jp-delivery-shipping-label .jp-delivery-time {
    font-weight: normal;
    font-size: 13px;
    color: #666;
}

/* Destination info */
.jp-delivery-shipping-label .jp-delivery-destination {
    margin-bottom: 8px;
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Change address button */
.jp-delivery-shipping-label .jp-delivery-change-address {
    background: #2c3e50;
    color: #fff;
    border: none;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.jp-delivery-shipping-label .jp-delivery-change-address:hover {
    background: #34495e;
}

/* Address form */
.jp-delivery-shipping-label .jp-delivery-address-form {
    margin-top: 15px;
    padding: 15px;
    background: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.jp-delivery-shipping-label .jp-delivery-form-row {
    margin-bottom: 15px;
}

.jp-delivery-shipping-label .jp-delivery-form-row:last-of-type {
    margin-bottom: 20px;
}

.jp-delivery-shipping-label .jp-delivery-form-row label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
    color: #333;
}

.jp-delivery-shipping-label .jp-delivery-form-row input[type="text"],
.jp-delivery-shipping-label .jp-delivery-form-row select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.jp-delivery-shipping-label .jp-delivery-form-row input[type="text"]:focus,
.jp-delivery-shipping-label .jp-delivery-form-row select:focus {
    outline: none;
    border-color: #2c3e50;
    box-shadow: 0 0 0 1px #2c3e50;
}

/* Update button */
.jp-delivery-shipping-label .jp-delivery-update-address {
    background: #2c3e50;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.jp-delivery-shipping-label .jp-delivery-update-address:hover {
    background: #34495e;
}

.jp-delivery-shipping-label .jp-delivery-update-address:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

/* Loading indicator */
.jp-delivery-shipping-label .jp-delivery-loading {
    display: inline-block;
    margin-left: 10px;
    color: #666;
    font-size: 13px;
    font-style: italic;
}

/* Error message */
.jp-delivery-error-message {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 10px 15px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 13px;
}

/* Success message */
.jp-delivery-success-message {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
    padding: 10px 15px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 13px;
}

/* Responsive design */
@media (max-width: 768px) {
    .jp-delivery-shipping-label .jp-delivery-destination {
        flex-direction: column;
        align-items: flex-start;
    }

    .jp-delivery-shipping-label .jp-delivery-change-address {
        margin-top: 5px;
    }

    .jp-delivery-shipping-label .jp-delivery-form-row input[type="text"],
    .jp-delivery-shipping-label .jp-delivery-form-row select {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Animation for form toggle */
@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

.jp-delivery-address-form.show {
    animation: slideDown 0.3s ease-out;
}

/* Price Table on Product Pages */
.jp-delivery-price-table-wrapper {
    margin: 20px 0;
    padding: 20px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.jp-delivery-price-table-wrapper h3 {
    margin: 0 0 15px 0;
    font-size: 20px;
    color: #2c3e50;
    border-bottom: 2px solid #2c3e50;
    padding-bottom: 10px;
}

.jp-delivery-calculator {
    margin-bottom: 20px;
}

.jp-delivery-calculator p {
    margin: 0 0 10px 0;
}

.jp-delivery-calc-form {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.jp-delivery-calc-form input[type="text"] {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.jp-delivery-calc-form input[type="text"]:focus {
    outline: none;
    border-color: #2c3e50;
    box-shadow: 0 0 0 1px #2c3e50;
}

.jp-delivery-calc-form .button {
    padding: 10px 20px;
    background: #2c3e50;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

.jp-delivery-calc-form .button:hover {
    background: #34495e;
}

.jp-delivery-calc-form .button:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

#jp-delivery-price-result .error {
    color: #e74c3c;
    padding: 10px;
    background: #ffe8e8;
    border: 1px solid #e74c3c;
    border-radius: 4px;
    margin-top: 10px;
}

.jp-delivery-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.jp-delivery-table-section h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #2c3e50;
}

.jp-delivery-price-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.jp-delivery-price-table thead {
    background: #2c3e50;
    color: #fff;
}

.jp-delivery-price-table thead th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
}

.jp-delivery-price-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
}

.jp-delivery-price-table tbody tr:last-child {
    border-bottom: none;
}

.jp-delivery-price-table tbody tr:hover {
    background: #f5f5f5;
}

.jp-delivery-price-table tbody td {
    padding: 10px 12px;
    font-size: 14px;
}

.jp-delivery-price-table tbody tr.per-pallet-rate {
    background: #e8f4f8;
    font-weight: 600;
}

.jp-delivery-price-table tbody tr.per-pallet-rate:hover {
    background: #d6ecf3;
}

/* Basic product info (fallback) */
.jp-delivery-product-info {
    margin: 15px 0;
    padding: 15px;
    background: #f7f7f7;
    border-left: 3px solid #2c3e50;
    border-radius: 4px;
}

.jp-delivery-product-info .label {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 16px;
    color: #2c3e50;
}

.jp-delivery-product-info .value {
    color: #666;
    font-size: 14px;
}

/* Responsive design for price tables */
@media (max-width: 768px) {
    .jp-delivery-calc-form {
        flex-direction: column;
    }

    .jp-delivery-calc-form .button {
        width: 100%;
    }

    .jp-delivery-tables {
        grid-template-columns: 1fr;
    }

    .jp-delivery-price-table {
        font-size: 13px;
    }

    .jp-delivery-price-table thead th,
    .jp-delivery-price-table tbody td {
        padding: 8px;
    }
}

/* ============================================
   Moffett Option & Origin Options Styles
   ============================================ */

/* Ensure shipping method list items can contain block elements */
#shipping_method li,
.woocommerce-shipping-methods li {
    display: block !important;
    margin-bottom: 12px !important;
}

.woocommerce-shipping-methods li input[type="radio"] {
    float: left;
    margin-top: 4px;
    margin-right: 8px;
}

/* Ensure the label does not wrap under the radio */
.woocommerce-shipping-methods li label {
    display: block;
    overflow: hidden;     /* forces label text to start after radio */
    line-height: 1.4;
    padding-left: 2px;
}

/* Only apply indentation to the Moffett option inside Truckload */
.jp-delivery-moffett-option {
    clear: both;                   /* ensures starts below the label */
    margin: 8px 0 0 26px !important; /* indent under the label */
    padding: 10px 12px !important;
    background: #f8f8f8 !important;
    border: 1px solid #ddd !important;
    border-left: 3px solid #2c3e50 !important;
    border-radius: 4px !important;
    max-width: 420px !important;
}

/* Hidden state for Moffett checkbox (toggled by JS on option change) */
.jp-delivery-moffett-option.jp-delivery-moffett-hidden {
    display: none !important;
}

.jp-delivery-moffett-option label {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

.jp-delivery-moffett-option input[type="checkbox"] {
    margin-top: 2px !important;
    flex-shrink: 0 !important;
}

.jp-delivery-moffett-option .description {
    margin: 4px 0 0 28px !important;
    font-size: 12px !important;
    color: #666 !important;
}

/* ===========================
   MOBILE FIXES (max-width 600px)
   =========================== */
@media (max-width: 600px) {

    /* Make each shipping method vertical + left aligned */
    .woocommerce-shipping-methods li {
        display: block !important;
        margin-bottom: 18px !important;
        text-align: left !important;
    }

    .woocommerce-shipping-methods li label {
        display: block !important;
        padding-left: 0 !important;
        text-align: left !important;
        margin-left: 28px !important; /* align with radio */
        max-width: 100% !important;
    }

    .woocommerce-shipping-methods li input[type="radio"] {
        float: left !important;
        margin-top: 4px;
        margin-right: 8px;
    }

    /* --- Moffett box on mobile --- */
    .jp-delivery-moffett-option {
        margin: 10px 0 0 28px !important;
        padding: 10px !important;
        width: calc(100% - 28px) !important;  /* fits screen */
        border-left-width: 3px !important;
    }

    .jp-delivery-moffett-option label {
        flex-wrap: wrap !important;
        align-items: flex-start !important;
    }

    .jp-delivery-moffett-option label span {
        flex: 1 1 100% !important; /* price text moves under checkbox */
    }

    .jp-delivery-moffett-option input[type="checkbox"] {
        margin-top: 3px !important;
    }

    .jp-delivery-moffett-option .description {
        margin: 6px 0 0 22px !important;
        font-size: 12px !important;
    }
}

/* Full-width origin row in cart table */
tr.jp-delivery-origin-row > td {
    padding: 0 15px 15px 15px !important;
    border: none !important;
    background: transparent !important;
}

/* Origin options container */
.jp-delivery-origin-options {
    display: block !important;
    clear: both !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 15px !important;
    background: #f9f9f9 !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
}

.jp-delivery-origin-options h4 {
    margin: 0 0 12px 0 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #333 !important;
}

.jp-delivery-origin-group {
    margin-bottom: 12px !important;
    padding: 12px !important;
    background: #fff !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
}

.jp-delivery-origin-group:last-child {
    margin-bottom: 0 !important;
}

.jp-delivery-origin-group .origin-header {
    font-weight: 600 !important;
    font-size: 14px !important;
    margin-bottom: 10px !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid #eee !important;
    color: #333 !important;
}

.jp-delivery-origin-group .origin-header span {
    font-weight: normal !important;
    font-size: 13px !important;
    color: #666 !important;
    margin-left: 4px !important;
}

/* Radio button options styling */
.jp-delivery-origin-group .origin-options {
    margin-left: 0 !important;
}

.jp-delivery-origin-group .origin-options label {
    display: flex !important;
    align-items: flex-start !important;
    gap: 8px !important;
    margin-bottom: 8px !important;
    padding: 10px !important;
    background: #f8f8f8 !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    transition: background-color 0.2s ease !important;
}

.jp-delivery-origin-group .origin-options label:hover {
    background: #f0f0f0 !important;
}

.jp-delivery-origin-group .origin-options label:last-of-type {
    margin-bottom: 0 !important;
}

.jp-delivery-origin-group .origin-options input[type="radio"] {
    margin: 3px 0 0 0 !important;
    flex-shrink: 0 !important;
}

.jp-delivery-origin-group .origin-options label span {
    flex: 1 !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
}

.jp-delivery-origin-group .origin-options label span strong {
    color: #2c3e50 !important;
}

/* Single option display (when no choice available) */
.jp-delivery-origin-group .origin-single-option {
    color: #555 !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    padding: 8px 0 !important;
}

.jp-delivery-origin-group .origin-single-option strong {
    color: #2c3e50 !important;
}

.jp-delivery-origin-group .origin-single-option .only-option {
    font-style: italic !important;
    font-size: 12px !important;
    color: #888 !important;
    margin-left: 4px !important;
}

/* Moffett option within origin group */
.jp-delivery-origin-moffett {
    margin: 10px 0 0 0 !important;
    padding: 10px !important;
    background: #fff !important;
    border: 1px dashed #ccc !important;
    border-left: 3px solid #2c3e50 !important;
    border-radius: 4px !important;
}

.jp-delivery-origin-moffett label {
    display: flex !important;
    align-items: flex-start !important;
    gap: 8px !important;
    cursor: pointer !important;
    font-size: 13px !important;
}

.jp-delivery-origin-moffett input[type="checkbox"] {
    margin: 2px 0 0 0 !important;
    flex-shrink: 0 !important;
}

.jp-delivery-origin-moffett p {
    margin: 6px 0 0 0 !important;
    font-size: 11px !important;
    color: #888 !important;
    line-height: 1.3 !important;
}

/* Responsive styles for shipping options */
@media (max-width: 768px) {
    .jp-delivery-origin-options {
        margin: 10px 0 !important;
        padding: 10px !important;
    }

    .jp-delivery-origin-options h4 {
        font-size: 13px !important;
        margin-bottom: 8px !important;
    }

    .jp-delivery-origin-group {
        padding: 10px !important;
        margin-bottom: 10px !important;
    }

    .jp-delivery-origin-group .origin-header {
        font-size: 13px !important;
        margin-bottom: 6px !important;
        line-height: 1.4 !important;
    }

    .jp-delivery-origin-group .origin-header span {
        display: inline !important;
        font-size: 12px !important;
    }

    .jp-delivery-origin-group .origin-single-option {
        font-size: 12px !important;
        margin-left: 5px !important;
    }

    .jp-delivery-origin-group .origin-options {
        margin-left: 5px !important;
    }

    .jp-delivery-origin-group .origin-options label {
        font-size: 12px !important;
        padding: 4px 0 !important;
    }
}

@media (max-width: 600px) {
    .jp-delivery-moffett-option,
    .jp-delivery-origin-options {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 8px !important;
    }

    .jp-delivery-moffett-option label {
        flex-wrap: wrap !important;
    }

    .jp-delivery-moffett-option label span {
        flex: 1 1 calc(100% - 30px) !important;
    }

    .jp-delivery-origin-group {
        padding: 10px !important;
        margin-bottom: 8px !important;
    }

    .jp-delivery-origin-group .origin-header {
        font-size: 13px !important;
        font-weight: 600 !important;
        margin-bottom: 8px !important;
        padding-bottom: 6px !important;
        border-bottom: 1px solid #eee !important;
    }

    .jp-delivery-origin-group .origin-header span {
        font-size: 12px !important;
        color: #666 !important;
    }

    .jp-delivery-origin-group .origin-single-option {
        font-size: 12px !important;
        margin-left: 0 !important;
        padding: 4px 0 !important;
    }

    .jp-delivery-origin-group .origin-options {
        margin-left: 0 !important;
        margin-top: 6px !important;
    }

    .jp-delivery-origin-group .origin-options label {
        display: flex !important;
        align-items: flex-start !important;
        gap: 8px !important;
        padding: 8px !important;
        margin-bottom: 6px !important;
        background: #f8f8f8 !important;
        border-radius: 4px !important;
        font-size: 12px !important;
        line-height: 1.4 !important;
    }

    .jp-delivery-origin-group .origin-options label:last-of-type {
        margin-bottom: 0 !important;
    }

    .jp-delivery-origin-group .origin-options input[type="radio"] {
        margin: 2px 0 0 0 !important;
        flex-shrink: 0 !important;
    }

    .jp-delivery-origin-group .origin-options label span {
        flex: 1 !important;
    }

    .jp-delivery-origin-group .origin-options label span strong {
        display: block !important;
        color: #2c3e50 !important;
        margin-top: 2px !important;
    }

    .jp-delivery-origin-moffett {
        margin: 8px 0 0 0 !important;
        padding: 10px !important;
        background: #fff !important;
        border: 1px dashed #ccc !important;
        border-left: 3px solid #2c3e50 !important;
        border-radius: 4px !important;
    }

    .jp-delivery-origin-moffett label {
        display: flex !important;
        align-items: flex-start !important;
        gap: 8px !important;
        font-size: 12px !important;
    }

    .jp-delivery-origin-moffett input[type="checkbox"] {
        margin: 2px 0 0 0 !important;
        flex-shrink: 0 !important;
    }

    .jp-delivery-origin-moffett p {
        font-size: 11px !important;
        margin: 6px 0 0 0 !important;
        color: #888 !important;
        line-height: 1.3 !important;
    }
}

/* Mobile: Right-align shipping labels in cart totals */
@media (max-width: 768px) {
    .cart_totals .woocommerce-shipping-totals td,
    .cart_totals .woocommerce-shipping-methods,
    .cart_totals .woocommerce-shipping-methods li,
    .cart_totals .woocommerce-shipping-methods li label {
        text-align: right !important;
    }

    .jp-delivery-shipping-label {
        text-align: right !important;
    }

    .jp-delivery-shipping-label .jp-delivery-title,
    .jp-delivery-shipping-label .jp-delivery-destination {
        justify-content: flex-end !important;
        text-align: right !important;
    }

    .jp-delivery-time {
        display: block !important;
        text-align: right !important;
    }

    /* Bold the shipping price on mobile */
    .cart_totals .woocommerce-shipping-methods .woocommerce-Price-amount,
    .woocommerce-shipping-totals .woocommerce-Price-amount {
        font-weight: 700 !important;
    }

    /* Freight Shipping Moffett option - full width on mobile */
    .shipping__table .jp-delivery-moffett-option,
    .woocommerce-shipping-methods .jp-delivery-moffett-option {
        width: 100% !important;
        max-width: none !important;
        display: block !important;
        margin: 10px 0 0 0 !important;
        text-align: right !important;
        box-sizing: border-box !important;
    }

    .shipping__table .jp-delivery-moffett-option label,
    .woocommerce-shipping-methods .jp-delivery-moffett-option label {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
        text-align: right !important;
    }

    .shipping__table .jp-delivery-moffett-option .moffett-description,
    .woocommerce-shipping-methods .jp-delivery-moffett-option .moffett-description {
        text-align: right !important;
        margin-left: 0 !important;
    }
}

/* Custom quote notice for large orders */
.origin-exceeds-capacity {
    margin: 8px 0;
}

.jp-delivery-custom-quote-notice {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    padding: 12px 15px;
    margin: 0;
    font-size: 13px;
    color: #856404;
    border-radius: 4px;
}

.jp-delivery-custom-quote-notice a {
    color: #0056b3;
    text-decoration: underline;
    font-weight: 600;
}

.jp-delivery-custom-quote-notice a:hover {
    color: #003d7a;
}

/* Enquiry required container */
.jp-delivery-enquiry-required {
    margin: 10px 0;
    width: 100%;
}

.jp-delivery-enquiry-required .jp-delivery-custom-quote-notice {
    margin: 0;
}

.jp-delivery-enquiry-required .jp-delivery-custom-quote-notice p {
    margin: 0 0 8px 0;
}

.jp-delivery-enquiry-required .jp-delivery-custom-quote-notice p:last-child {
    margin-bottom: 0;
}

.jp-delivery-enquiry-required .jp-delivery-custom-quote-notice ul {
    margin: 8px 0;
    padding-left: 20px;
}

.jp-delivery-enquiry-required .jp-delivery-custom-quote-notice li {
    margin: 4px 0;
}

/* Exceeded origin styling */
.jp-delivery-origin-group.exceeded-origin {
    border-left: 3px solid #ffc107;
    padding-left: 10px;
    margin-bottom: 15px;
}

.jp-delivery-origin-group.exceeded-origin .origin-header {
    color: #856404;
}

/* Exceeded origins notice after Freight shipping */
.jp-delivery-exceeded-origins-notice {
    margin: 10px 0;
    width: 100%;
}

.jp-delivery-exceeded-origins-notice .jp-delivery-custom-quote-notice ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.jp-delivery-exceeded-origins-notice .jp-delivery-custom-quote-notice li {
    margin: 4px 0;
}
