/**
 * TLD Subscription Module v5.3 - FINAL DESIGN
 * - Prices in top-right corner
 * - Compact boxes, reduced height
 * - Off-black button and radio
 * - Pills for footer sections
 * - Fully responsive
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
.tld-subscription-module {
    --tld-card-color: #1a4a5e;
    --tld-banner-color: rgba(26, 74, 94, 0.12);
    --tld-border-radius: 12px;
    --tld-font-family: 'Special Elite', cursive;
    --tld-off-black: #2a2a2a;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================
   PURCHASE OPTIONS ROW
   ============================================ */
.tld-purchase-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

/* ============================================
   OPTION BOXES - COMPACT
   ============================================ */
.tld-option {
    border: 2px solid var(--tld-card-color);
    border-radius: var(--tld-border-radius);
    padding: 10px;
    background: var(--tld-banner-color);
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    min-height: 82px;
    position: relative;
    user-select: none;
}

.tld-option:hover {
    border-color: #ccc;
}

.tld-option-active {
    border-color: #d9d9d9;
    background: #fff;
}

/* TOP ROW: Header + Price in corner */
.tld-option-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

/* ============================================
   OPTION HEADER - BIGGER RADIO
   ============================================ */
.tld-option-header {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 5px;
    margin: -5px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.tld-option-header:hover {
    background: rgba(255, 255, 255, 0.3);
}

.tld-purchase-radio {
    display: none;
}

/* Extend clickable area for radio selection */
.tld-purchase-radio + .tld-radio-custom::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    cursor: pointer;
}

.tld-radio-custom {
    width: 22px;
    height: 22px;
    border: 2px solid var(--tld-off-black);
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.tld-purchase-radio:checked + .tld-radio-custom {
    border-color: var(--tld-off-black);
}

.tld-purchase-radio:checked + .tld-radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: var(--tld-off-black);
    border-radius: 50%;
}

.tld-option-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

/* ============================================
   PRICE IN TOP-RIGHT CORNER
   ============================================ */
.tld-option-price-corner {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.tld-option-save-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: var(--tld-card-color);
    padding: 4px 12px;
    border-radius: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    line-height: 1;
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

/* Left side content wrapper */
.tld-option-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tld-option-price-corner .tld-price-main {
    font-family: var(--tld-font-family);
    font-size: 24px;
    font-weight: 700;
    color: #333;
    line-height: 1.1;
}

.tld-option-price-corner .tld-price-rrp {
    font-size: 12px;
    color: #999;
    text-decoration: line-through;
    margin-top: 2px;
}

/* ============================================
   BENEFITS ROW (icon + text line)
   Both lines on same row, positioned under title
   ============================================ */
.tld-option-benefits-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 32px;
    flex-wrap: wrap;
}

.tld-option-benefits {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 400;
    color: #666;
}

.tld-benefit-icon {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

.tld-benefit-sep {
    color: #bbb;
    font-size: 8px;
}

.tld-learn-more {
    color: var(--tld-card-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
}

/* ============================================
   FREQUENCY SELECTOR
   ============================================ */
.tld-frequency {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.tld-frequency .tld-learn-more {
    margin-left: auto;
}

.tld-frequency-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.tld-frequency-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.tld-frequency-btn {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 16px;
    background: #f5f5f5;
    font-size: 11px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tld-frequency-btn:hover {
    border-color: var(--tld-card-color);
    color: var(--tld-card-color);
}

.tld-frequency-btn.active {
    background: var(--tld-card-color);
    border-color: var(--tld-card-color);
    color: #fff;
}

/* ============================================
   QUANTITY SECTION
   ============================================ */
.tld-quantity-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
}

.tld-option-onetime .tld-quantity-section {
    justify-content: flex-end;
    margin-left: auto;
    width: 100%;
}

.tld-qty-label {
    font-size: 12px;
    color: #666;
}

.tld-qty-control {
    display: flex;
    align-items: stretch;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}

.tld-qty-input {
    width: 40px;
    text-align: center;
    border: none;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 0;
    -moz-appearance: textfield;
}

.tld-qty-input::-webkit-outer-spin-button,
.tld-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tld-qty-buttons {
    display: flex;
    flex-direction: column;
    border-left: 1px solid #ddd;
}

.tld-qty-btn {
    width: 24px;
    height: 16px;
    border: none;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.tld-qty-btn:hover {
    background: #e0e0e0;
}

.tld-qty-btn:first-child {
    border-bottom: 1px solid #ddd;
}

/* ============================================
   UPSELLS - COMPACT, SYMMETRICAL
   ============================================ */
.tld-upsells {
    border: 1px solid #e0e0e0;
    border-radius: var(--tld-border-radius);
    padding: 8px;
    margin-bottom: 8px;
    background: #f7f7f7;
}

.tld-upsells-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 2px;
    gap: 6px;
}

.tld-upsells-title {
    font-size: 11px;
    font-weight: 700;
    color: #333;
    letter-spacing: 0.5px;
}

.tld-upsells-subtitle {
    font-size: 11px;
    font-weight: 400;
    color: #777;
    letter-spacing: 0.2px;
    font-family: 'Josefin Sans', sans-serif;
}

.tld-upsells-subtitle::before {
    content: '|';
    margin-right: 6px;
    color: #999;
}

.tld-upsells-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    align-items: stretch;
}

/* SYMMETRICAL UPSELL BOXES */
.tld-upsell-item {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 50px;
    position: relative;
    height: 100%;
}

.tld-upsell-item:hover {
    border-color: #ccc;
}

.tld-upsell-item.selected {
    border-color: var(--tld-card-color);
    background: var(--tld-banner-color);
}

.tld-upsell-save-tag {
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: var(--tld-card-color);
    padding: 2px 6px;
    border-radius: 10px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 1;
    position: absolute;
    top: -8px;
    right: 10px;
    z-index: 2;
}

.tld-upsell-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    justify-content: center;
}

/* TICK BOX */
.tld-upsell-tick {
    position: relative;
    flex-shrink: 0;
}

.tld-upsell-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.tld-tick-box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 2px solid #ccc;
    border-radius: 50%;
    background: #fff;
    transition: all 0.2s ease;
}

.tld-tick-box::after {
    content: '';
    display: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
}

.tld-upsell-checkbox:checked + .tld-tick-box {
    background: var(--tld-card-color);
    border-color: var(--tld-card-color);
}

.tld-upsell-checkbox:checked + .tld-tick-box::after {
    display: block;
}

.tld-upsell-thumb {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tld-upsell-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.tld-upsell-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* CAPS PRODUCT NAME */
.tld-upsell-name {
    font-size: 10px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tld-upsell-price {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.tld-upsell-price-current {
    font-size: 12px;
    font-weight: 700;
    color: var(--tld-card-color);
}

.tld-upsell-price-original {
    font-size: 10px;
    color: #999;
    text-decoration: line-through;
}

/* ============================================
   ADD TO BASKET - OFF BLACK
   ============================================ */
.tld-cart-row {
    margin-bottom: 12px;
}

.tld-add-to-basket {
    width: 100%;
    padding: 14px 20px;
    background: var(--tld-off-black);
    color: #fff;
    border: none;
    border-radius: var(--tld-border-radius);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.tld-add-to-basket:hover {
    background: #3a3a3a;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.tld-add-to-basket:active {
    background: #1f1f1f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(0);
}
.tld-add-to-basket:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.tld-add-to-basket.success {
    background: #28a745;
}

/* ============================================
   FOOTER ROW - TWO PILLS SIDE BY SIDE
   ============================================ */
.tld-footer-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.tld-footer-pill {
    background: #f7f7f7;
    border-radius: var(--tld-border-radius);
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* DELIVERY PILL (LEFT) */
.tld-delivery-pill {
    justify-content: center;
}

.tld-delivery-icon {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
}

.tld-delivery-content {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.tld-delivery-label {
    font-size: 12px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tld-delivery-dates {
    font-family: var(--tld-font-family);
    font-size: 17px;
    font-weight: 700;
    color: #333;
}

.tld-delivery-meta {
    font-size: 10px;
    color: #888;
}

.tld-delivery-meta a {
    color: var(--tld-card-color);
    text-decoration: underline;
}

/* PAYMENT PILL (RIGHT) */
.tld-payment-pill {
    justify-content: center;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Payment icons on top */
.tld-payment-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    order: 1;
}

.tld-payment-icons img {
    height: 28px;
    width: auto;
}

/* Klarna text below icons */
.tld-klarna-copy {
    display: block;
    width: 100%;
    text-align: center;
    order: 2;
    font-size: 11px;
}

/* Hide the broken Klarna badge, show only working one */
klarna-placement[data-key="credit-promotion-badge"] {
    display: none !important;
}

/* ============================================
   POPUPS
   ============================================ */
.tld-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.tld-popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.tld-popup-content {
    position: relative;
    background: #fff;
    padding: 40px;
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tld-popup-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #333;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.tld-popup-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #000;
    transform: rotate(90deg);
}

.tld-popup-content h3 {
    margin: 0 0 20px;
    font-size: 24px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
}

.tld-popup-content h4 {
    margin: 20px 0 12px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.tld-popup-content p {
    margin: 0 0 16px;
    font-size: 15px;
    color: #555;
    line-height: 1.7;
}

.tld-popup-content ul {
    margin: 0 0 16px;
    padding-left: 24px;
}

.tld-popup-content li {
    margin-bottom: 8px;
    font-size: 15px;
    color: #555;
    line-height: 1.6;
}

.tld-popup-content strong {
    color: #333;
    font-weight: 600;
}

.tld-popup-content a {
    color: var(--tld-card-color);
    text-decoration: underline;
}

.tld-popup-content a:hover {
    text-decoration: none;
}

/* ============================================
   RESPONSIVE - TABLET
   ============================================ */
@media (max-width: 900px) and (min-width: 601px) {
    .tld-option {
        padding: 12px;
    }

    .tld-option-title {
        font-size: 14px;
    }

    .tld-option-price-corner .tld-price-main {
        font-size: 22px;
    }

    .tld-option-benefits-wrapper {
        padding-left: 30px;
    }

    .tld-option-benefits {
        font-size: 10px;
    }

    .tld-frequency-btn {
        font-size: 10px;
        padding: 6px 12px;
    }

    .tld-upsell-name {
        font-size: 9px;
    }

    .tld-delivery-dates {
        font-size: 16px;
    }

    .tld-add-to-basket {
        padding: 15px 18px;
        font-size: 13px;
    }
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */
@media (max-width: 600px) {
    .tld-subscription-module {
        font-size: 14px;
    }

    .tld-purchase-row {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 12px;
    }

    .tld-option {
        min-height: auto;
        padding: 16px 14px;
    }

    .tld-option-top {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .tld-option-left {
        width: 100%;
    }

    .tld-option-header {
        padding: 6px;
        margin: -6px;
    }

    .tld-option-title {
        font-size: 15px;
    }

    .tld-option-price-corner {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding-left: 32px;
    }

    .tld-option-save-tag {
        top: -12px;
        font-size: 9px;
        padding: 4px 11px;
    }

    .tld-option-price-corner .tld-price-main {
        font-size: 22px;
    }

    .tld-option-price-corner .tld-price-rrp {
        font-size: 12px;
    }

    .tld-option-benefits-wrapper {
        padding-left: 32px;
        gap: 6px;
        flex-direction: column;
        align-items: flex-start;
    }

    .tld-option-benefits {
        font-size: 10px;
        gap: 5px;
    }

    .tld-benefit-icon {
        width: 11px;
        height: 11px;
    }

    /* Frequency section mobile */
    .tld-frequency {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-top: 10px;
    }

    .tld-frequency-label {
        font-size: 11px;
        width: 100%;
    }

    .tld-frequency-buttons {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
        gap: 6px;
    }

    .tld-frequency-btn {
        flex: 1;
        text-align: center;
        min-width: 0;
        padding: 6px 8px;
        font-size: 10px;
    }

    .tld-frequency .tld-learn-more {
        width: 100%;
        text-align: center;
        margin: 4px 0 0 0;
    }

    /* Quantity section mobile */
    .tld-quantity-section {
        margin-top: 10px;
        gap: 8px;
    }

    .tld-qty-label {
        font-size: 11px;
    }

    .tld-qty-control {
        flex: 0 0 auto;
    }

    /* Upsells mobile */
    .tld-upsells {
        padding: 10px;
        margin-bottom: 12px;
    }

    .tld-upsells-header {
        margin-bottom: 8px;
        gap: 4px;
    }

    .tld-upsells-title {
        font-size: 10px;
    }

    .tld-upsells-subtitle {
        font-size: 10px;
    }

    .tld-upsells-items {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .tld-upsell-item {
        grid-template-columns: 50px 1fr auto;
        min-height: 60px;
        padding: 8px;
        gap: 10px;
    }

    .tld-upsell-thumb {
        width: 50px;
        height: 50px;
    }

    .tld-upsell-name {
        font-size: 9px;
        line-height: 1.3;
    }

    .tld-upsell-price-current {
        font-size: 11px;
    }

    .tld-upsell-price-original {
        font-size: 9px;
    }

    .tld-tick-box {
        width: 16px;
        height: 16px;
    }

    .tld-tick-box::after {
        width: 6px;
        height: 6px;
    }

    /* Add to basket button mobile */
    .tld-cart-row {
        margin-bottom: 12px;
    }

    .tld-add-to-basket {
        font-size: 13px;
        padding: 16px 20px;
        letter-spacing: 0.8px;
    }

    /* Footer pills mobile */
    .tld-footer-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .tld-footer-pill {
        justify-content: center;
        padding: 12px 10px;
    }

    .tld-delivery-pill {
        justify-content: center;
        text-align: center;
        gap: 10px;
    }

    .tld-delivery-content {
        align-items: center;
    }

    .tld-delivery-icon {
        width: 40px;
        height: 40px;
    }

    .tld-delivery-label {
        font-size: 10px;
    }

    .tld-delivery-dates {
        font-size: 15px;
    }

    .tld-delivery-meta {
        font-size: 9px;
    }

    .tld-payment-pill {
        padding: 10px;
        gap: 8px;
    }

    .tld-payment-icons {
        gap: 8px;
    }

    .tld-payment-icons img {
        height: 26px;
    }

    .tld-klarna-copy {
        font-size: 10px;
    }

    /* Popups mobile */
    .tld-popup {
        padding: 16px;
    }

    .tld-popup-content {
        padding: 24px 20px;
        max-width: 100%;
        max-height: 90vh;
    }

    .tld-popup-content h3 {
        font-size: 18px;
        margin-bottom: 14px;
    }

    .tld-popup-content h4 {
        font-size: 15px;
        margin: 16px 0 10px;
    }

    .tld-popup-content p {
        font-size: 13px;
        margin-bottom: 12px;
    }

    .tld-popup-content li {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .tld-popup-close {
        top: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
        font-size: 18px;
    }
}

@media (max-width: 400px) {
    .tld-subscription-module {
        font-size: 13px;
    }

    .tld-option {
        padding: 12px 10px;
    }

    .tld-option-title {
        font-size: 12px;
    }

    .tld-option-price-corner .tld-price-main {
        font-size: 18px;
    }

    .tld-option-price-corner .tld-price-rrp {
        font-size: 10px;
    }

    .tld-option-benefits {
        font-size: 9px;
    }

    .tld-frequency-btn {
        font-size: 9px;
        padding: 5px 6px;
    }

    .tld-upsells {
        padding: 8px;
    }

    .tld-upsell-item {
        grid-template-columns: 44px 1fr auto;
        padding: 6px;
    }

    .tld-upsell-thumb {
        width: 44px;
        height: 44px;
    }

    .tld-upsell-name {
        font-size: 8px;
    }

    .tld-upsell-price-current {
        font-size: 10px;
    }

    .tld-add-to-basket {
        font-size: 12px;
        padding: 14px 18px;
        letter-spacing: 0.5px;
    }

    .tld-delivery-icon {
        width: 36px;
        height: 36px;
    }

    .tld-delivery-dates {
        font-size: 14px;
    }

    .tld-payment-icons img {
        height: 24px;
    }
}
