/* --- Basic Setup & Variables --- */
:root {
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #212529;
    --text-muted: #6c757d;
    --primary-color: #4a55c7;
    --primary-hover: #3a43a1;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.075);
    --success-color: #28a745;
    --error-color: #dc3545;
    --notification-bg: #343a40;
    --notification-text: white;
    --header-height: 5rem; /* Define header height for main content padding */
}

/* Dark mode variables */
body.dark-mode {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #e9ecef;
    --text-muted: #adb5bd;
    --primary-color: #8c9eff;
    --primary-hover: #a5b4fc;
    --border-color: #343a40;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --success-color: #2a9d8f;
    --error-color: #e63946;
    --notification-bg: #f8f9fa;
    --notification-text: #212121;
}

body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
    direction: rtl;
    text-align: right;
}

/* --- Fixed & Transparent Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    box-shadow: 0 2px 4px var(--shadow-color);
    box-sizing: border-box;
    height: var(--header-height);
}

body.dark-mode header {
    background-color: rgba(30, 30, 30, 0.95);
}

.store-identity { display: flex; align-items: center; gap: 0.75rem; }
.store-identity .icon { color: var(--primary-color); width: 32px; height: 32px; }
.store-info h1 { margin: 0; font-size: 1.25rem; }
.store-info p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 0.5rem; }

.icon-button {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    color: var(--text-color);
    transition: background-color 0.2s;
}
.icon-button:hover { background-color: var(--border-color); }
.icon-button .icon { width: 20px; height: 20px; }
#cart-count {
    position: absolute;
    top: -5px;
    right: auto;
    left: -5px;
    background-color: #e63946;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid var(--card-bg);
}

/* --- Main Content Area --- */
main {
    padding-top: var(--header-height);
}

/* --- Product Feed & Cards --- */
#product-feed { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; }

.product-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px var(--shadow-color);
}

.product-card .product-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}
.product-card .product-info {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: right;
}
.product-info h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.product-info .description { margin: 0; color: var(--text-muted); font-size: 0.85rem; line-height: 1.4; }
.product-info .price { margin: 0.5rem 0; font-size: 1.3rem; font-weight: 700; color: var(--primary-color); }

.product-controls {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 0.5rem;
}

/* --- Quantity Selector --- */
.quantity-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.quantity-btn {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}
.quantity-btn:hover {
    background-color: var(--primary-color);
    color: white;
}
.quantity-value {
    font-size: 1.1rem;
    font-weight: 500;
    min-width: 35px;
    text-align: center;
    direction: ltr;
}

.add-to-cart-btn {
    width: 100%;
    background-color: var(--text-color);
    color: var(--bg-color);
    border: none;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background-color 0.2s;
}
.add-to-cart-btn:hover { background-color: var(--primary-hover); }
.add-to-cart-btn.added { background-color: var(--success-color); color: white; }

/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    padding: 1rem;
    box-sizing: border-box;
}
.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 0; /* No padding here, children will handle it */
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    display: flex; /* Flex container for direct children */
    flex-direction: column;
    justify-content: flex-start; /* Align content to start */
    align-items: stretch; /* Stretch children to fill width */
    text-align: center; /* Default text alignment */
    overflow: hidden; /* Crucial for rounded corners to apply to full-bleed child */
}
.close-button {
    color: var(--text-muted);
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}
.close-button:hover { opacity: 0.7; }

/* --- Modal Content Specifics --- */
#checkout-form-container {
    width: 100%;
    padding: 2rem; /* Apply padding here instead of modal-content */
    box-sizing: border-box;
    display: block;
    text-align: right;
}
#modal-order-summary { margin: 1rem 0; }
.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px dotted var(--border-color);
    gap: 10px;
}
.summary-item:last-of-type { border-bottom: none; }
.summary-item span:first-child {
    flex-grow: 1;
    text-align: right;
    direction: rtl;
}
.summary-item span:last-child {
    flex-shrink: 0;
    text-align: left;
    direction: ltr;
    white-space: nowrap;
    font-weight: bold;
    color: var(--text-color);
}
#summary-total {
    font-weight: bold;
    font-size: 1.4rem;
    margin-top: 1.5rem;
    text-align: center;
    color: var(--primary-color);
    padding: 0.5rem 0;
    border-top: 2px solid var(--primary-color);
    width: 100%;
    box-sizing: border-box;
}
#checkout-form label { display: block; margin-top: 1rem; margin-bottom: 0.5rem; font-weight: bold; text-align: right; }
#checkout-form input, #checkout-form select {
    width: 100%; padding: 0.75rem; border: 1px solid var(--border-color); border-radius: 8px;
    background-color: var(--bg-color); color: var(--text-color); font-size: 1rem; box-sizing: border-box;
    text-align: right;
    direction: rtl;
}
#checkout-form input[type="tel"] { direction: ltr; text-align: left; }
#checkout-form select option { text-align: right; direction: rtl; }
#checkout-form select:disabled { background-color: var(--border-color); cursor: not-allowed; opacity: 0.6; }
.submit-order-btn { width: 100%; padding: 1rem; margin-top: 1.5rem; background-color: var(--primary-color); color: white; border: none; border-radius: 8px; font-size: 1.1rem; font-weight: bold; cursor: pointer; }
.submit-order-btn:hover { background-color: var(--primary-hover); }

/* --- Order Success Message --- */
.order-success-message {
    background-color: var(--success-color);
    color: white;
    padding: 3rem 2rem; /* Adjusted padding here */
    border-radius: 8px; /* Match modal content border-radius */
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    /* Key change: It should directly fill its parent, so no absolute positioning from outside.
       Its parent (.modal-content) is already a flex container that will manage it. */
    height: 100%; /* Fill the height of modal-content */
    box-sizing: border-box; /* Include padding in dimensions */
}


.order-success-message h2 {
    font-size: 1.8rem;
    margin: 0;
}

.order-success-message p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 0;
}

.order-success-message .success-icon {
    color: white;
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
}

.order-success-message .ok-button {
    /* Position relative to its normal flow, and let flexbox center it */
    background-color: white;
    color: var(--success-color);
    border: none;
    padding: 0.75rem 2.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    margin-top: 1.5rem; /* Margin from content above it */
    transition: background-color 0.2s, color 0.2s;
    /* Center using margin auto for a block element within a flex container */
    display: block;
    margin-left: auto;
    margin-right: auto;
}
.order-success-message .ok-button:hover {
    background-color: #f0f0f0;
}

/* Styles for the cart summary item - FORCED LIGHT THEME */
.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 8px;

    /* --- FIX: Forcing a light background and dark text --- */

    /* CHANGE 1: Use a specific light color instead of the theme variable */
    background-color: #FFFFFF; /* Pure white background */

    /* CHANGE 2: Use a specific dark color for the main text */
    color: #212121; /* A dark grey, less harsh than pure black */

    /* CHANGE 3 (Optional but recommended): Add a subtle border */
    border: 1px solid #EEEEEE; /* A light grey border to separate items */
}

.summary-item-details {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.summary-item-details span:first-child {
    font-weight: bold;
    /* This will inherit the dark #212121 color from .summary-item */
}

/* CHANGE 4: Use a specific medium-grey color for the price */
.summary-item-details span:last-child {
    color: #666666; /* A medium grey for secondary text */
    font-size: 0.9em;
    margin-top: 2px;
}

/* The remove button style can remain the same */
.remove-item-btn {
    background-color: #ff4d4d;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-left: 10px;
    transition: background-color 0.2s;
}

.remove-item-btn:hover {
    background-color: #cc0000;
}

/* Style for the price tiers text on product cards */
.price-tiers {
    font-size: 0.8rem;
    color: var(--tg-theme-hint-color, #999);
    margin: 5px 0;
    text-align: center;
}



/* Utility classes */
.hidden { display: none !important; }


/* --- Notification Popup (Toast) --- */
.notification-popup {
    position: fixed;
    top: calc(var(--header-height) + 20px);
    left: 50%;
    transform: translate(-50%, -20px);
    background-color: var(--notification-bg);
    color: var(--notification-text);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 10000;
    font-weight: 500;
    text-align: center;
    min-width: 250px;
    max-width: 90%;
    backdrop-filter: blur(5px);
}
.notification-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}
.notification-popup.success {
    background-color: var(--success-color);
    color: white;
}
.notification-popup.error {
    background-color: var(--error-color);
    color: white;
}


/* --- Responsiveness --- */
@media (min-width: 768px) {
    #product-feed {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (min-width: 1024px) {
    #product-feed {
        grid-template-columns: repeat(3, 1fr);
    }
}