/**
 * Eastpresso Mix & Match Builder — Frontend Styles
 *
 * All rules are scoped under .emmb-builder-wrap to avoid
 * collisions with theme CSS. RTL-first. Mobile-safe.
 * Quantity control buttons are custom-styled and never
 * depend on theme .button class behaviour.
 *
 * @package EastpressoMixMatch
 */

/* ============================================================
   1. WRAPPER & LAYOUT FOUNDATION
   ============================================================ */

.emmb-builder-wrap {
    direction: rtl;
    font-family: inherit;
    color: inherit;
    max-width: 100%;
    margin: 24px 0;
    padding: 0;
    box-sizing: border-box;
}

.emmb-builder-wrap *,
.emmb-builder-wrap *::before,
.emmb-builder-wrap *::after {
    box-sizing: border-box;
}

/* ============================================================
   2. HEADER
   ============================================================ */

.emmb-header {
    margin-bottom: 20px;
}

.emmb-title {
    font-size: 1.35em;
    font-weight: 700;
    margin: 0 0 6px 0;
    color: inherit;
    line-height: 1.3;
}

.emmb-subtitle {
    font-size: 0.95em;
    color: #555;
    margin: 0 0 10px 0;
    line-height: 1.5;
}

.emmb-price-display {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 1.1em;
    font-weight: 600;
    flex-wrap: wrap;
}

.emmb-price-label {
    color: #666;
    font-weight: 400;
    font-size: 0.9em;
}

.emmb-price-value .woocommerce-Price-amount,
.emmb-price-value {
    color: #1a1a1a;
    font-weight: 700;
}

/* ============================================================
   3. PROGRESS BAR
   ============================================================ */

.emmb-progress {
    margin-bottom: 18px;
}

.emmb-progress-text-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    color: #444;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.emmb-progress-count {
    font-weight: 700;
    font-size: 1.05em;
    color: #1a1a1a;
    min-width: 20px;
    text-align: center;
}

.emmb-progress-separator {
    color: #999;
}

.emmb-progress-capacity {
    font-weight: 600;
}

.emmb-progress-bar {
    width: 100%;
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.emmb-progress-fill {
    height: 100%;
    width: 0%;
    background: #2d6a4f;
    border-radius: 4px;
    transition: width 0.25s ease, background-color 0.2s ease;
}

.emmb-progress-fill.emmb-progress-complete {
    background: #1b4332;
}

.emmb-progress-fill.emmb-progress-over {
    background: #c1121f;
}

/* ============================================================
   4. MESSAGE AREA
   ============================================================ */

.emmb-message {
    min-height: 0;
    padding: 0;
    margin-bottom: 0;
    font-size: 0.9em;
    line-height: 1.5;
    border-radius: 6px;
    transition: all 0.2s ease;
    text-align: right;
}

.emmb-message:not(:empty) {
    padding: 10px 14px;
    margin-bottom: 14px;
}

.emmb-message.emmb-msg-error {
    background: #fff5f5;
    color: #c1121f;
    border: 1px solid #f0b8bb;
}

.emmb-message.emmb-msg-success {
    background: #f0faf4;
    color: #1b4332;
    border: 1px solid #b7dfc9;
}

.emmb-message.emmb-msg-info {
    background: #f5f7ff;
    color: #2d4a8a;
    border: 1px solid #c3cef5;
}

/* ============================================================
   5. ITEM GRID — DESKTOP
   ============================================================ */

.emmb-items {
    margin-bottom: 18px;
}

/* Grid layout */
.emmb-items.emmb-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

/* List layout */
.emmb-items.emmb-items-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ============================================================
   6. ITEM CARD — GRID MODE
   ============================================================ */

.emmb-item {
    background: #fff;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    position: relative;
    text-align: center;
}

.emmb-item:hover:not(.emmb-item-disabled) {
    border-color: #2d6a4f;
    box-shadow: 0 2px 12px rgba(45, 106, 79, 0.12);
}

/* Item with qty selected */
.emmb-item.emmb-item-selected {
    border-color: #2d6a4f;
    background: #f8fef9;
}

/* Disabled / out-of-stock item */
.emmb-item.emmb-item-disabled {
    opacity: 0.55;
    pointer-events: none;
    background: #f9f9f9;
}

/* ── Image ── */
.emmb-item-image {
    width: 80px;
    height: 80px;
    overflow: hidden;
    border-radius: 6px;
    flex-shrink: 0;
}

.emmb-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── Info ── */
.emmb-item-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.emmb-item-name {
    font-size: 0.85em;
    font-weight: 600;
    line-height: 1.35;
    color: #1a1a1a;
    word-break: break-word;
    hyphens: auto;
}

.emmb-item-stock {
    font-size: 0.75em;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
}

.emmb-in-stock {
    color: #1b4332;
    background: #d8f3e8;
}

.emmb-out-of-stock {
    color: #7f1d1d;
    background: #fee2e2;
}

.emmb-backorder {
    color: #78350f;
    background: #fef3c7;
}

.emmb-item-price {
    font-size: 0.8em;
    color: #555;
    font-weight: 500;
}

/* ============================================================
   7. ITEM CARD — LIST MODE
   ============================================================ */

.emmb-items-list .emmb-item {
    flex-direction: row;
    align-items: center;
    text-align: right;
    padding: 10px 14px;
    gap: 14px;
}

.emmb-items-list .emmb-item-image {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
}

.emmb-items-list .emmb-item-info {
    flex: 1;
    align-items: flex-start;
}

.emmb-items-list .emmb-item-controls {
    flex-shrink: 0;
    margin-right: auto;
    margin-left: 0;
}

/* ============================================================
   8. QUANTITY CONTROLS
   ============================================================
   These are intentionally custom-styled and use type="button"
   so they are NEVER affected by theme .button CSS or
   WooCommerce button styles. They do not inherit theme colours.
   ============================================================ */

.emmb-item-controls {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;  /* CRITICAL: never wrap on mobile */
    gap: 4px;
    width: 100%;
    justify-content: center;
}

.emmb-items-list .emmb-item-controls {
    width: auto;
    justify-content: flex-end;
}

.emmb-qty-btn {
    /* Reset — override any theme styles */
    all: unset;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;

    /* Custom appearance */
    width: 32px;
    height: 32px;
    min-width: 32px;  /* CRITICAL: prevent shrinking on mobile */
    border-radius: 50%;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    background: #f0f0f0;
    color: #333;
    border: 1.5px solid #ccc;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; /* Removes 300ms delay on touch */
    flex-shrink: 0;             /* CRITICAL: prevent shrinking */
}

/* Larger touch targets on mobile (achieved via padding, not size change) */
@media (max-width: 600px) {
    .emmb-qty-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 20px;
    }
}

.emmb-qty-btn:hover:not(:disabled) {
    background: #2d6a4f;
    border-color: #2d6a4f;
    color: #fff;
}

.emmb-qty-btn:active:not(:disabled) {
    transform: scale(0.93);
}

.emmb-qty-btn:focus-visible {
    outline: 2px solid #2d6a4f;
    outline-offset: 2px;
}

.emmb-qty-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: #f5f5f5;
    border-color: #ddd;
    color: #999;
}

.emmb-qty-display {
    display: inline-block;
    min-width: 28px;
    text-align: center;
    font-size: 1em;
    font-weight: 700;
    color: #1a1a1a;
    flex-shrink: 0;
    line-height: 32px;
}

/* Highlight qty display when > 0 */
.emmb-item.emmb-item-selected .emmb-qty-display {
    color: #1b4332;
}

/* ============================================================
   9. HELP TEXT
   ============================================================ */

.emmb-help-text {
    font-size: 0.85em;
    color: #777;
    margin-top: 12px;
    line-height: 1.5;
    text-align: right;
}

/* ============================================================
   10. ADD TO CART BUTTON — DISABLED STATE
   ============================================================
   We manage the disabled state on the existing WooCommerce
   add-to-cart button. These rules give clear visual feedback.
   ============================================================ */

.single_add_to_cart_button.emmb-btn-disabled,
.single_add_to_cart_button[aria-disabled="true"] {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* ============================================================
   11. ADMIN-ONLY NOTICE (shown only to logged-in admins)
   ============================================================ */

.emmb-admin-notice {
    background: #fff8e1;
    border: 1px solid #ffe082;
    color: #7a5c00;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.88em;
    margin: 12px 0;
    text-align: right;
    direction: rtl;
}

/* ============================================================
   12. RESPONSIVE — TABLET (≤ 768px)
   ============================================================ */

@media (max-width: 768px) {
    .emmb-items.emmb-items-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .emmb-item-image {
        width: 70px;
        height: 70px;
    }

    .emmb-title {
        font-size: 1.2em;
    }
}

/* ============================================================
   13. RESPONSIVE — MOBILE (≤ 480px)
   ============================================================ */

@media (max-width: 480px) {
    .emmb-items.emmb-items-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    /* Switch grid items to horizontal layout on small screens */
    .emmb-items-grid .emmb-item {
        flex-direction: row;
        text-align: right;
        padding: 10px 12px;
        gap: 10px;
    }

    .emmb-items-grid .emmb-item-image {
        width: 54px;
        height: 54px;
        flex-shrink: 0;
    }

    .emmb-items-grid .emmb-item-info {
        flex: 1;
        align-items: flex-start;
    }

    .emmb-items-grid .emmb-item-controls {
        flex-shrink: 0;
        width: auto;
        margin-right: auto;
        margin-left: 0;
    }

    .emmb-title {
        font-size: 1.1em;
    }

    .emmb-subtitle {
        font-size: 0.9em;
    }
}

/* ============================================================
   14. ORDER META DISPLAY (admin order screen)
   ============================================================ */

.emmb-order-meta {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
    font-size: 0.88em;
    direction: rtl;
    text-align: right;
}

.emmb-order-meta p {
    margin: 0 0 4px 0;
}

.emmb-order-items-list {
    margin: 4px 0 8px 0;
    padding: 0 18px 0 0;
    list-style: disc;
}

.emmb-order-items-list li {
    margin-bottom: 2px;
    color: #333;
}

.emmb-price-mode-label {
    color: #666;
    margin: 4px 0 0 0;
}
