/* ============================================================
   TIMIZA AGRO MACHINERY - CART & CHECKOUT (v3.14)
   ------------------------------------------------------------
   Loaded after agro-home.css. Covers the quantity stepper and
   Add to cart row on product cards, the header cart button and
   badge, the cart drawer, the "added" toast, the /checkout/
   page and the Quantity field on Shop Now.

   Uses the v4 tokens (--tfm-*) from ui-v4.css, so it reads as
   part of the marketplace layer rather than the homepage board.
   ============================================================ */

/* Anything the cart script shows/hides with the hidden attribute.
   Several of these set their own display, which would beat the
   browser's built-in [hidden] rule. */
.tfm-cart-count[hidden],
.tfm-cart-toast[hidden],
.tfm-cart-note[hidden],
.tfm-checkout-sent[hidden],
[data-tfm-cart-when-filled][hidden],
[data-tfm-cart-when-empty][hidden] { display: none !important; }

/* ---------- quantity stepper ---------- */
.tfm-qty {
    display: inline-flex;
    align-items: stretch;
    height: 40px;
    background: var(--tfm-white);
    border: 1px solid var(--tfm-gray-medium);
    border-radius: var(--tfm-radius-md);
    overflow: hidden;
}
.tfm-qty:focus-within { border-color: var(--tfm-green); box-shadow: 0 0 0 3px rgba(11, 107, 121, 0.14); }
.tfm-qty-btn {
    flex: none;
    width: 34px;
    border: 0;
    background: transparent;
    color: var(--tfm-green-dark);
    font-size: 0.72rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 0.12s ease;
}
.tfm-qty-btn:hover { background: var(--tfm-green-light); }
.tfm-qty-btn:focus-visible { outline: 2px solid var(--tfm-green); outline-offset: -2px; }
.tfm-qty-input {
    width: 42px;
    min-width: 0;
    flex: 1 1 auto;
    border: 0;
    border-left: 1px solid var(--tfm-gray);
    border-right: 1px solid var(--tfm-gray);
    padding: 0 2px;
    text-align: center;
    font: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--tfm-navy);
    font-variant-numeric: tabular-nums;
    background: transparent;
    -moz-appearance: textfield;
    appearance: textfield;
}
.tfm-qty-input:focus { outline: none; }
.tfm-qty-input::-webkit-outer-spin-button,
.tfm-qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.tfm-qty--sm { height: 34px; }
.tfm-qty--sm .tfm-qty-btn { width: 30px; }
.tfm-qty--sm .tfm-qty-input { width: 38px; font-size: 0.86rem; }

.tfm-qty--lg { height: 48px; }
.tfm-qty--lg .tfm-qty-btn { width: 46px; font-size: 0.8rem; }
.tfm-qty--lg .tfm-qty-input { width: 64px; font-size: 1.05rem; }
/* Inside a form group the generic input styling must not reach the stepper */
.tfm-form-group .tfm-qty input.tfm-qty-input,
.tfm-form-group .tfm-qty input.tfm-qty-input:focus {
    width: 64px;
    min-height: 0;
    padding: 0 2px;
    border: 0;
    border-left: 1px solid var(--tfm-gray);
    border-right: 1px solid var(--tfm-gray);
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    font-size: 1.05rem;
}

/* ---------- product card: stepper + add ---------- */
.tfm-cart-add {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tfm-cart-add .tfm-qty { flex: 1 1 104px; }
.tfm-cart-add .tfm-cart-add-btn { flex: 1 1 112px; }
.tfm-cart-add-btn.is-added,
.tfm-cart-add-btn.is-added:hover { background: var(--tfm-stock); border-color: var(--tfm-stock); }

.tfm-btn-buy-now {
    background: var(--tfm-white);
    border-color: rgba(11, 107, 121, 0.45);
    color: var(--tfm-green-dark);
}
.tfm-btn-buy-now:hover { background: var(--tfm-green-light); border-color: var(--tfm-green); color: var(--tfm-green-dark); }
.tfm-btn-buy-now .fa-whatsapp { color: #1FA855; }

/* ---------- header cart button + badge ---------- */
.tfm-cart-toggle {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--tfm-gray-medium);
    border-radius: var(--tfm-radius-md);
    background: var(--tfm-white);
    color: var(--tfm-navy);
    font-family: inherit;
    font-weight: 650;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.tfm-cart-toggle:hover { border-color: var(--tfm-green); background: var(--tfm-green-light); }
.tfm-cart-toggle .fa-cart-shopping { color: var(--tfm-green-dark); }

.tfm-cart-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--tfm-radius-full);
    background: var(--tfm-orange);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* Bottom nav: the cart entry is a button, the others are links */
button.tfm-bottom-nav-item {
    background: none;
    border: 0;
    font-family: inherit;
    cursor: pointer;
}
.tfm-bottom-nav-icon { position: relative; display: inline-flex; }
.tfm-bottom-nav-icon .tfm-cart-count {
    position: absolute;
    top: -7px;
    right: -12px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    font-size: 0.62rem;
    border: 2px solid #fff;
    box-sizing: content-box;
}

/* ---------- drawer ---------- */
.tfm-cart-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10002;
    background: rgba(19, 32, 44, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
.tfm-cart-backdrop.is-open { opacity: 1; pointer-events: auto; }

.tfm-cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 10003;
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    background: var(--tfm-white);
    box-shadow: var(--tfm-shadow-xl);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.tfm-cart-drawer.is-open {
    transform: none;
    visibility: visible;
    transition: transform 0.25s ease, visibility 0s;
}
.tfm-cart-drawer:focus { outline: none; }

.tfm-cart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tfm-gray);
}
.tfm-cart-head h2 {
    margin: 0;
    font-size: 1.12rem;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--tfm-navy);
}
.tfm-cart-head h2 .fa-cart-shopping { color: var(--tfm-green); }
.tfm-cart-head-count { font-family: var(--tfm-font-body); font-size: 0.85rem; font-weight: 550; color: var(--tfm-text-muted); }
.tfm-cart-close {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--tfm-radius-sm);
    background: var(--tfm-gray-light);
    color: var(--tfm-navy);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}
.tfm-cart-close:hover { background: var(--tfm-gray); }

.tfm-cart-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 20px;
}

.tfm-cart-foot {
    border-top: 1px solid var(--tfm-gray);
    padding: 14px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    background: var(--tfm-gray-light);
}
.tfm-cart-foot .tfm-btn-lg { margin-top: 12px; }
.tfm-cart-keep {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px;
    border: 0;
    background: none;
    font-family: inherit;
    font-weight: 650;
    font-size: 0.88rem;
    color: var(--tfm-green-dark);
    cursor: pointer;
}
.tfm-cart-keep:hover { text-decoration: underline; }

/* ---------- cart lines (drawer + checkout share these) ---------- */
.tfm-cart-item {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 14px 0;
    border-bottom: 1px solid var(--tfm-gray);
}
.tfm-cart-item:last-child { border-bottom: 0; }
.tfm-cart-item img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--tfm-gray);
    border-radius: var(--tfm-radius-sm);
    padding: 3px;
}
.tfm-cart-item-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tfm-cart-item-cat { font-size: 0.7rem; color: var(--tfm-text-muted); font-weight: 550; }
.tfm-cart-item-name {
    font-size: 0.9rem;
    font-weight: 650;
    line-height: 1.3;
    color: var(--tfm-navy);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tfm-cart-item-unit { font-size: 0.78rem; color: var(--tfm-text-light); }
.tfm-cart-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.tfm-cart-item-total {
    font-family: var(--tfm-font-heading);
    font-weight: 700;
    font-size: 0.98rem;
    color: var(--tfm-navy);
    font-variant-numeric: tabular-nums;
}
.tfm-cart-item-remove {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--tfm-radius-sm);
    background: transparent;
    color: var(--tfm-text-muted);
    cursor: pointer;
}
.tfm-cart-item-remove:hover { background: #FDECEA; color: #C2361B; }

.tfm-cart-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    font-size: 0.9rem;
    color: var(--tfm-text-light);
}
.tfm-cart-line strong { color: var(--tfm-navy); font-variant-numeric: tabular-nums; text-align: right; }
.tfm-cart-line--total {
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--tfm-gray);
    font-size: 1rem;
    color: var(--tfm-navy);
    font-weight: 650;
}
.tfm-cart-line--total strong { font-family: var(--tfm-font-heading); font-size: 1.25rem; }
.tfm-cart-free { color: var(--tfm-stock) !important; }
.tfm-cart-note {
    display: flex;
    gap: 8px;
    margin: 8px 0 0;
    font-size: 0.77rem;
    line-height: 1.45;
    color: var(--tfm-text-light);
}
.tfm-cart-note i { color: var(--tfm-orange); margin-top: 2px; }

.tfm-cart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    padding: 56px 8px;
}
.tfm-cart-empty > i { font-size: 2.2rem; color: var(--tfm-gray-medium); margin-bottom: 6px; }
.tfm-cart-empty strong { font-size: 1.02rem; color: var(--tfm-navy); }
.tfm-cart-empty span { font-size: 0.86rem; color: var(--tfm-text-muted); max-width: 30ch; }
.tfm-cart-empty .tfm-btn { margin-top: 10px; }

/* ---------- "added to cart" toast ---------- */
.tfm-cart-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    width: max-content;
    max-width: calc(100% - 32px);
    padding: 11px 12px 11px 16px;
    border-radius: 12px;
    background: var(--tfm-navy);
    color: #fff;
    font-size: 0.88rem;
    box-shadow: var(--tfm-shadow-lg);
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.tfm-cart-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.tfm-cart-toast > i { color: #6EE7A8; flex: none; }
.tfm-cart-toast > span { min-width: 0; line-height: 1.35; }
.tfm-cart-toast button {
    flex: none;
    border: 0;
    border-radius: 8px;
    padding: 7px 12px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.84rem;
    white-space: nowrap;
    cursor: pointer;
}
.tfm-cart-toast button:hover { background: rgba(255, 255, 255, 0.26); }

/* ---------- checkout page ---------- */
.tfm-checkout-section .tfm-container { max-width: 1120px; }
.tfm-checkout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 22px;
    align-items: start;
}
.tfm-checkout-main { grid-column: 1; grid-row: 1; min-width: 0; }
.tfm-checkout-summary {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 150px;
    border: 1px solid var(--tfm-gray);
}
.tfm-checkout-summary-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tfm-checkout-summary-head .tfm-lipa-eyebrow { margin-bottom: 4px; }
.tfm-checkout-summary-count { font-size: 0.8rem; color: var(--tfm-text-muted); }
.tfm-checkout-items { max-height: 46vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.tfm-checkout-totals { border-top: 1px solid var(--tfm-gray); padding-top: 10px; margin-top: 4px; }
.tfm-checkout-more {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 14px;
    font-size: 0.86rem;
    font-weight: 650;
    color: var(--tfm-green-dark);
}
.tfm-checkout-more:hover { text-decoration: underline; }

.tfm-checkout-empty {
    max-width: 560px;
    margin: 0 auto 18px;
    padding: 40px 24px;
    text-align: center;
}
.tfm-checkout-empty h2 { font-size: 1.35rem; margin: 14px 0 8px; }
.tfm-checkout-empty p { color: var(--tfm-text-light); margin-bottom: 20px; }
.tfm-checkout-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--tfm-green-light);
    color: var(--tfm-green);
    font-size: 1.5rem;
}

.tfm-checkout-sent {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid rgba(20, 124, 74, 0.3);
    border-radius: var(--tfm-radius-md);
    background: var(--tfm-stock-light);
    color: var(--tfm-text);
}
.tfm-checkout-sent > i { color: var(--tfm-stock); font-size: 1.3rem; margin-top: 2px; }
.tfm-checkout-sent strong { display: block; color: var(--tfm-navy); }
.tfm-checkout-sent span { display: block; font-size: 0.86rem; color: var(--tfm-text-light); margin-top: 2px; }
.tfm-checkout-clear {
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid var(--tfm-stock);
    border-radius: var(--tfm-radius-sm);
    background: #fff;
    color: var(--tfm-stock);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.84rem;
    cursor: pointer;
}
.tfm-checkout-clear:hover { background: var(--tfm-stock); color: #fff; }

.tfm-payment-info-item a { color: var(--tfm-green-dark); font-weight: 650; text-decoration: underline; }

/* ---------- Shop Now: quantity ---------- */
.tfm-sn-qty-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tfm-sn-total {
    font-family: var(--tfm-font-heading);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--tfm-navy);
    font-variant-numeric: tabular-nums;
}
.tfm-sn-to-cart {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 12px;
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    font-weight: 650;
    font-size: 0.84rem;
    color: var(--tfm-green-dark);
    text-align: left;
    cursor: pointer;
}
.tfm-sn-to-cart:hover { text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 991px) {
    .tfm-cart-toggle { padding: 0 11px; }
    .tfm-cart-toggle-label { display: none; }
}

@media (max-width: 900px) {
    .tfm-checkout-grid { grid-template-columns: minmax(0, 1fr); }
    .tfm-checkout-summary,
    .tfm-checkout-main { grid-column: 1; grid-row: auto; }
    .tfm-checkout-summary { position: static; }
    .tfm-checkout-items { max-height: none; overflow: visible; }
}

@media (max-width: 767px) {
    /* Clear the bottom nav */
    .tfm-cart-toast { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 420px) {
    .tfm-cart-add .tfm-qty { height: 36px; }
    .tfm-cart-add .tfm-qty-btn { width: 30px; }
    .tfm-cart-item { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 10px; }
    .tfm-cart-item img { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
    .tfm-cart-drawer,
    .tfm-cart-drawer.is-open,
    .tfm-cart-backdrop,
    .tfm-cart-toast { transition: none; }
}
