/**
 * IMMOR Discount Engine — Frontend Styles
 *
 * CI V8.1/V8.2 "Green Web — Anakotmai Edition" Compliant
 * Forest Dark: #2D5016 | Forest Mid: #527A1F | Olive: #6B8E23
 * Ocean Blue: #0080C0 | Sky Blue: #0099DD | Teal Bridge: #2A9D8F
 *
 * Note: ใช้ !important เพื่อกัน WoodMart/WooCommerce override
 */

/* ===== 3-Layer Price Display ===== */
.immor-price-stack {
    display: inline-flex !important;
    align-items: baseline !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    font-family: 'Anakotmai', sans-serif !important;
}

.immor-price-reference {
    text-decoration: line-through !important;
    color: #999 !important;
    font-size: 0.9em !important;
    font-weight: 400 !important;
    opacity: 0.85 !important;
}

.immor-price-reference bdi {
    color: inherit !important;
}

.immor-price-regular {
    color: #005C99 !important; /* Ocean Blue Deep — WCAG compliant */
    font-weight: 700 !important;
    font-size: 1.1em !important;
    text-decoration: none !important;
    background: none !important;
}

.immor-price-regular bdi {
    color: inherit !important;
}

.immor-savings-inline {
    display: inline-block !important;
    padding: 2px 8px !important;
    background: #E63946 !important;
    color: #FFFFFF !important;
    font-size: 0.75em !important;
    font-weight: 700 !important;
    border-radius: 3px !important;
    margin-left: 4px !important;
}

/* ===== Discount Badges ===== */
.immor-discount-badge {
    position: absolute !important;
    z-index: 10 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-weight: 700 !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    text-align: center !important;
    pointer-events: none !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
}

/* Position variants */
.immor-discount-badge--top-left {
    top: 8px !important;
    left: 8px !important;
}

.immor-discount-badge--top-right {
    top: 8px !important;
    right: 8px !important;
}

.immor-discount-badge--bottom-left {
    bottom: 8px !important;
    left: 8px !important;
}

.immor-discount-badge--bottom-right {
    bottom: 8px !important;
    right: 8px !important;
}

/* Shape: Rectangle */
.immor-discount-badge--rectangle {
    padding: 6px 12px !important;
    border-radius: 4px !important;
    min-width: 50px !important;
}

/* Shape: Ribbon */
.immor-discount-badge--ribbon {
    padding: 8px 16px 12px !important;
    min-width: 80px !important;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 85%, 0 100%) !important;
}

.immor-discount-badge--ribbon .immor-badge-ribbon-content {
    display: block !important;
    padding-bottom: 4px !important;
}

/* Bundle savings badge — เฉพาะแบบ rectangle (มุมซ้ายบน) */
.immor-bundle-savings-badge {
    background: #E63946 !important;
    color: #FFFFFF !important;
}

/* Ensure parent has position relative */
.product .immor-discount-badge,
.products .product .immor-discount-badge,
.woocommerce ul.products li.product .immor-discount-badge,
.product-image-wrap .immor-discount-badge,
.wd-product-grid-item .immor-discount-badge {
    position: absolute !important;
}

/* WoodMart specific — ensure badge container relative */
.wd-product .product-image-wrap,
.product-grid-item .product-image-wrap {
    position: relative !important;
}

/* ===== Cart Savings Message ===== */
.immor-total-savings th {
    text-align: center !important;
    padding: 12px !important;
    background: linear-gradient(135deg, #6B8E23 0%, #0080C0 100%) !important;
    color: #FFFFFF !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-weight: 700 !important;
    border-radius: 4px !important;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .immor-discount-badge {
        font-size: 10px !important;
    }

    .immor-discount-badge--rectangle {
        padding: 4px 8px !important;
    }

    .immor-discount-badge--ribbon {
        padding: 6px 12px 10px !important;
        min-width: 70px !important;
    }

    .immor-price-stack {
        gap: 6px !important;
    }

    .immor-price-regular {
        font-size: 1em !important;
    }
}

/* ============================================================
 * COUPON FORM
 * ============================================================ */

.immor-coupon-section {
    margin: 0 0 24px !important;
    padding: 0 !important;
}

.immor-coupon-form-wrapper {
    background: linear-gradient(135deg, rgba(107, 142, 35, 0.05) 0%, rgba(0, 128, 192, 0.05) 100%) !important;
    border: 1px dashed #6B8E23 !important;
    border-radius: 12px !important;
    padding: 16px 20px !important;
    transition: all 0.3s ease !important;
}

.immor-coupon-form-wrapper:hover {
    border-color: #527A1F !important;
    background: linear-gradient(135deg, rgba(107, 142, 35, 0.08) 0%, rgba(0, 128, 192, 0.08) 100%) !important;
}

.immor-coupon-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
    font-family: 'Anakotmai', sans-serif !important;
}

.immor-coupon-icon {
    font-size: 20px !important;
    line-height: 1 !important;
}

.immor-coupon-title {
    font-weight: 700 !important;
    color: #2D5016 !important; /* CI Forest Dark */
    font-size: 15px !important;
}

.immor-coupon-form {
    margin: 0 !important;
}

.immor-coupon-input-group {
    display: flex !important;
    gap: 8px !important;
    align-items: stretch !important;
}

.immor-coupon-input {
    flex: 1 !important;
    padding: 10px 14px !important;
    border: 1px solid #ddd !important;
    border-radius: 6px !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 14px !important;
    background: #FFFFFF !important;
    color: #333 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    transition: border-color 0.2s !important;
    min-height: 42px !important;
}

.immor-coupon-input::placeholder {
    text-transform: none !important;
    letter-spacing: normal !important;
    color: #999 !important;
}

.immor-coupon-input:focus {
    border-color: #6B8E23 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(107, 142, 35, 0.15) !important;
}

.immor-coupon-submit {
    padding: 10px 20px !important;
    background: linear-gradient(135deg, #6B8E23 0%, #0080C0 100%) !important;
    color: #FFFFFF !important;
    border: none !important;
    border-radius: 6px !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-weight: 700 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    white-space: nowrap !important;
    min-height: 42px !important;
    line-height: 1 !important;
}

.immor-coupon-submit:hover {
    background: linear-gradient(135deg, #527A1F 0%, #005C99 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(107, 142, 35, 0.2) !important;
}

.immor-coupon-submit:active {
    transform: translateY(0) !important;
}

.immor-coupon-submit:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

/* Message area */
.immor-coupon-message {
    margin-top: 10px !important;
    padding: 10px 14px !important;
    border-radius: 6px !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
}

.immor-coupon-message.success {
    background: rgba(46, 125, 50, 0.1) !important;
    color: #2E7D32 !important;
    border: 1px solid rgba(46, 125, 50, 0.2) !important;
}

.immor-coupon-message.error {
    background: rgba(220, 53, 69, 0.1) !important;
    color: #C82333 !important;
    border: 1px solid rgba(220, 53, 69, 0.2) !important;
}

.immor-coupon-message code {
    background: rgba(255, 255, 255, 0.5) !important;
    padding: 2px 6px !important;
    border-radius: 3px !important;
    font-weight: 700 !important;
}

/* Applied coupons list */
.immor-coupon-applied-list {
    margin-top: 12px !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
}

.immor-coupon-applied {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 6px 12px !important;
    background: #FFFFFF !important;
    border: 1px solid #2E7D32 !important;
    border-radius: 20px !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 13px !important;
}

.immor-coupon-applied-icon {
    color: #2E7D32 !important;
    font-weight: 700 !important;
}

.immor-coupon-applied-code {
    font-family: 'Courier New', monospace !important;
    font-weight: 700 !important;
    color: #2D5016 !important;
    background: transparent !important;
    padding: 0 !important;
}

.immor-coupon-remove {
    background: none !important;
    border: none !important;
    color: #999 !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 12px !important;
    cursor: pointer !important;
    padding: 2px 6px !important;
    text-decoration: underline !important;
    transition: color 0.2s !important;
}

.immor-coupon-remove:hover {
    color: #C82333 !important;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .immor-coupon-form-wrapper {
        padding: 14px 16px !important;
    }

    .immor-coupon-input-group {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .immor-coupon-submit {
        width: 100% !important;
    }

    .immor-coupon-input,
    .immor-coupon-submit {
        font-size: 16px !important; /* prevent iOS zoom */
    }
}

/* ============================================================
 * COUPON LINK BUTTON — disabled state + hint
 * ============================================================ */

/* ปุ่ม "ใช้โค้ด" เมื่อเป็น <a> link */
a.immor-coupon-submit {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    color: #FFFFFF !important;
}

a.immor-coupon-submit:hover {
    color: #FFFFFF !important;
    text-decoration: none !important;
}

/* Disabled state — ตอนยังไม่พิมพ์โค้ด */
a.immor-coupon-submit--disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    background: #999 !important;
    pointer-events: auto !important; /* ให้คลิกได้เพื่อ focus input */
}

a.immor-coupon-submit--disabled:hover {
    background: #999 !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Hint text */
.immor-coupon-hint {
    margin: 8px 0 0 !important;
    padding: 0 !important;
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 12px !important;
    color: #666 !important;
    line-height: 1.4 !important;
}

/* ============================================================
 * QUICK APPLY BUTTONS — ปุ่มใช้โค้ดสำเร็จรูป
 * ============================================================ */

.immor-coupon-quick {
    margin-top: 14px !important;
    padding-top: 14px !important;
    border-top: 1px dashed rgba(107, 142, 35, 0.3) !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    align-items: center !important;
}

.immor-coupon-quick-label {
    font-family: 'Anakotmai', sans-serif !important;
    font-size: 13px !important;
    color: #527A1F !important;
    font-weight: 700 !important;
    margin-right: 4px !important;
}

a.immor-coupon-quick-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 8px 14px !important;
    background: #FFFFFF !important;
    border: 1.5px solid #6B8E23 !important;
    border-radius: 20px !important;
    text-decoration: none !important;
    transition: all 0.2s ease !important;
    font-family: 'Anakotmai', sans-serif !important;
    color: #2D5016 !important;
}

a.immor-coupon-quick-btn:hover {
    background: linear-gradient(135deg, #6B8E23 0%, #0080C0 100%) !important;
    border-color: transparent !important;
    color: #FFFFFF !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(107, 142, 35, 0.2) !important;
    text-decoration: none !important;
}

.immor-coupon-quick-btn code {
    font-family: 'Courier New', monospace !important;
    font-weight: 700 !important;
    font-size: 13px !important;
    color: inherit !important;
    background: transparent !important;
    padding: 0 !important;
}

.immor-coupon-quick-btn small {
    font-size: 11px !important;
    opacity: 0.8 !important;
    color: inherit !important;
}

/* Mobile: stack vertically */
@media (max-width: 600px) {
    .immor-coupon-quick {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .immor-coupon-quick-label {
        margin-bottom: 4px !important;
    }

    a.immor-coupon-quick-btn {
        justify-content: center !important;
    }
}

/* ============================================================
 * SAVINGS AMOUNT — สีเหลืองตัดกับ gradient
 * ============================================================ */

.immor-total-savings .immor-savings-amount,
.immor-total-savings .immor-savings-amount .amount,
.immor-total-savings .immor-savings-amount .woocommerce-Price-amount,
.immor-total-savings .immor-savings-amount bdi,
.immor-total-savings .immor-savings-amount span {
    color: #FFEB3B !important; /* เหลืองสด — ตัดกับ gradient เขียว/น้ำเงิน */
    font-weight: 800 !important;
    font-size: 1.1em !important;
}

.immor-total-savings .immor-savings-amount .woocommerce-Price-currencySymbol {
    color: #FFEB3B !important;
    font-weight: 700 !important;
}

/* ============================================================
 * THRESHOLD PROGRESS — ใกล้ถึงโปร / ได้รับโปรแล้ว
 * ============================================================ */

.immor-threshold-wrapper {
    margin: 20px 0;
}

.immor-threshold-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    font-family: 'Anakotmai', 'Prompt', sans-serif;
}

/* PENDING — ยังไม่ถึง threshold (สีฟ้า/เขียวอ่อน — กระตุ้นให้ซื้อเพิ่ม) */
.immor-threshold-pending {
    background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    border: 2px solid #FFB300;
}

.immor-threshold-pending .immor-threshold-title {
    color: #E65100;
}

.immor-threshold-pending .immor-threshold-remaining {
    color: #B71C1C;
    font-size: 1.15em;
}

.immor-threshold-pending .immor-threshold-reward {
    color: #2E7D32;
    font-size: 1.1em;
}

/* REACHED — ผ่าน threshold แล้ว (สีเขียว — celebrate!) */
.immor-threshold-reached {
    background: linear-gradient(135deg, #C8E6C9 0%, #A5D6A7 100%);
    border: 2px solid #2E7D32;
}

.immor-threshold-reached .immor-threshold-title {
    color: #1B5E20;
    font-weight: 700;
}

.immor-threshold-reached .immor-threshold-detail {
    color: #2E7D32;
}

/* Icon */
.immor-threshold-icon {
    font-size: 2em;
    flex-shrink: 0;
}

/* Content */
.immor-threshold-content {
    flex: 1;
    min-width: 0;
}

.immor-threshold-title {
    font-size: 1.05em;
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.4;
}

.immor-threshold-detail {
    font-size: 0.95em;
    line-height: 1.4;
}

.immor-threshold-meta {
    margin-top: 6px;
    font-size: 0.85em;
    color: #666;
}

/* Progress bar */
.immor-threshold-progress-wrap {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0 4px 0;
}

.immor-threshold-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #66BB6A 0%, #2E7D32 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

/* Mobile responsive */
@media (max-width: 600px) {
    .immor-threshold-card {
        padding: 14px 16px;
        gap: 12px;
    }

    .immor-threshold-icon {
        font-size: 1.6em;
    }

    .immor-threshold-title {
        font-size: 0.95em;
    }

    .immor-threshold-meta {
        font-size: 0.8em;
    }
}

/* Hide on checkout review (ใช้แค่ใน cart page) */
.woocommerce-checkout .immor-threshold-wrapper {
    margin: 12px 0;
}

/* ============================================================
 * MINI CART THRESHOLD (Sidebar Widget)
 * — Compact version สำหรับพื้นที่จำกัด
 * ============================================================ */

.immor-mini-threshold {
    margin: 12px 0;
    padding: 12px 14px;
    border-radius: 10px;
    font-family: 'Anakotmai', 'Prompt', sans-serif;
    font-size: 0.92em;
    line-height: 1.4;
}

/* PENDING — ยังไม่ถึง threshold */
.immor-mini-pending {
    background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    border: 1.5px solid #FFB300;
}

.immor-mini-pending .immor-mini-text-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.immor-mini-pending .immor-mini-text {
    color: #E65100;
    flex: 1;
}

.immor-mini-pending .immor-mini-remaining {
    color: #B71C1C;
    font-weight: 700;
}

.immor-mini-pending .immor-mini-reward {
    color: #2E7D32;
    font-weight: 700;
}

/* REACHED — ผ่าน threshold แล้ว */
.immor-mini-reached {
    background: linear-gradient(135deg, #C8E6C9 0%, #A5D6A7 100%);
    border: 1.5px solid #2E7D32;
    color: #1B5E20;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.immor-mini-reached .immor-mini-text {
    flex: 1;
    color: #1B5E20;
}

.immor-mini-reached strong {
    color: #1B5E20;
}

/* Icon */
.immor-mini-icon {
    font-size: 1.3em;
    flex-shrink: 0;
    line-height: 1;
}

/* Mini progress bar */
.immor-mini-progress-wrap {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.immor-mini-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #66BB6A 0%, #2E7D32 100%);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* WoodMart-specific: ในหน้า off-canvas cart */
.widget_shopping_cart .immor-mini-threshold,
.wd-side-hidden-content .immor-mini-threshold,
.woocommerce.widget_shopping_cart_content .immor-mini-threshold {
    margin: 14px 16px;
}

/* ============================================================
 * FREE GIFT — Cart row styling
 * ============================================================ */

.immor-free-gift-row {
    background: linear-gradient(90deg, #FFF8E1 0%, #FFFFFF 100%) !important;
    border-left: 4px solid #FFB300 !important;
}

.immor-free-gift-row td {
    padding-top: 12px !important;
    padding-bottom: 12px !important;
}

.immor-gift-label {
    display: inline-block;
    padding: 2px 10px;
    background: linear-gradient(135deg, #FF6B6B 0%, #FFA500 100%);
    color: #FFFFFF !important;
    font-weight: 700;
    font-size: 0.85em;
    border-radius: 12px;
    margin-right: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.immor-gift-qty-lock {
    display: inline-block;
    padding: 4px 12px;
    background: #F5F5F5;
    border: 1px solid #DDD;
    border-radius: 4px;
    color: #666;
    font-weight: 600;
    cursor: not-allowed;
}

/* Override theme price ของ free gift = ฟรี */
.immor-free-gift-row .product-price .amount,
.immor-free-gift-row .product-subtotal .amount {
    color: #2E7D32 !important;
    font-weight: 700 !important;
}

.immor-free-gift-row .product-price::after,
.immor-free-gift-row .product-subtotal::after {
    /* Add free indicator (optional) */
}

/* Mobile responsive */
@media (max-width: 600px) {
    .immor-gift-label {
        font-size: 0.75em;
        padding: 2px 8px;
    }
}

/* ============================================================
 * CART TABLE COLUMN WIDTHS — ป้องกันราคาทับกัน
 * ============================================================ */

/* Cart page table */
.woocommerce-cart-form table.shop_table {
    table-layout: auto !important;
}

.woocommerce-cart-form table.shop_table th.product-price,
.woocommerce-cart-form table.shop_table td.product-price,
.woocommerce-cart-form table.shop_table th.product-subtotal,
.woocommerce-cart-form table.shop_table td.product-subtotal {
    min-width: 100px !important;
    white-space: nowrap !important;
    text-align: right !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

/* ราคา/ยอดรวม ห้าม wrap */
.woocommerce-cart-form .product-price .amount,
.woocommerce-cart-form .product-price .woocommerce-Price-amount,
.woocommerce-cart-form .product-subtotal .amount,
.woocommerce-cart-form .product-subtotal .woocommerce-Price-amount {
    white-space: nowrap !important;
    display: inline-block !important;
}

.woocommerce-cart-form .product-price bdi,
.woocommerce-cart-form .product-subtotal bdi {
    white-space: nowrap !important;
}

/* Quantity column — ไม่ให้กว้างเกิน */
.woocommerce-cart-form table.shop_table th.product-quantity,
.woocommerce-cart-form table.shop_table td.product-quantity {
    width: auto !important;
    text-align: center !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
}

/* Product name column — ใช้พื้นที่ที่เหลือ */
.woocommerce-cart-form table.shop_table th.product-name,
.woocommerce-cart-form table.shop_table td.product-name {
    width: auto !important;
}

/* Mobile responsive — ลด min-width */
@media (max-width: 768px) {
    .woocommerce-cart-form table.shop_table th.product-price,
    .woocommerce-cart-form table.shop_table td.product-price,
    .woocommerce-cart-form table.shop_table th.product-subtotal,
    .woocommerce-cart-form table.shop_table td.product-subtotal {
        min-width: 80px !important;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .woocommerce-cart-form table.shop_table th.product-price,
    .woocommerce-cart-form table.shop_table td.product-price {
        display: none !important; /* ซ่อน "ราคา" บนจอเล็ก เพราะมี subtotal แล้ว */
    }
}

/* ============================================================
 * FREE GIFT — Lock quantity controls
 * ============================================================ */

/* Cart page: ซ่อน input qty + ปุ่ม + - */
.immor-free-gift-row .quantity .qty,
.immor-free-gift-row .quantity .plus,
.immor-free-gift-row .quantity .minus,
.immor-free-gift-row .quantity input[type="number"],
.immor-free-gift-row .quantity button {
    display: none !important;
}

/* แสดง "×1" แทน */
.immor-free-gift-row .quantity {
    display: inline-block !important;
    text-align: center !important;
}

/* Checkout review: locked indicator */
.immor-free-gift-row .product-quantity strong {
    color: #2E7D32;
    font-weight: 700;
}

/* WoodMart-specific qty button hide */
.immor-free-gift-row .wd-quantity,
.immor-free-gift-row .wd-qty-control,
.immor-free-gift-row .wd-buttons {
    display: none !important;
}
