/* Core Variables */
:root {
    --primary-color: #137a3b;
    --primary-dark: #155a38;
    --accent-color: #a94f19;
    --accent-soft: #f7eadf;
    --secondary-color: #e6eee1;
    --text-main: #1d2a21;
    --text-muted: #55645a;
    --border-color: #b8c8b5;
    --input-border-color: #718673;
    --bg-color: #f4f0e6;
    --card-bg: #fffdf7;
    --input-bg: #fffefa;
    --raised-bg: #f7faf3;
    --danger: #a61b2b;
    --warning: #7a4b12;
    --radius: 8px;
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    max-width: 100%;
    overflow-x: clip;
}

html {
    scroll-padding-top: 78px;
    scroll-padding-bottom: 124px;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.skip-link {
    position: fixed;
    inset-block-start: 8px;
    inset-inline-start: 12px;
    z-index: 1000;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--text-main);
    color: white;
    text-decoration: none;
    transform: translateY(-150%);
    transition: transform 140ms ease;
}

.skip-link:focus {
    transform: translateY(0);
}

:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 3px;
}

button,
a,
input,
select,
textarea,
[tabindex="0"] {
    scroll-margin-block-start: 82px;
    scroll-margin-block-end: 110px;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at top left, rgba(208, 222, 198, 0.48), transparent 34rem),
        linear-gradient(180deg, #f8f5ed 0%, var(--bg-color) 52%, #efe9db 100%);
    color: var(--text-main);
    padding-bottom: 120px; /* Space for sticky footer */
    line-height: 1.5;
    min-height: 100vh;
}

/* Typography & Direction adjustments */
html[dir="rtl"] body {
    font-family: Tahoma, Arial, sans-serif; /* Fallback for better Arabic rendering */
}

/* Header */
header {
    background-color: var(--card-bg);
    padding: 15px 20px;
    display: block;
    box-shadow: 0 2px 12px rgba(29, 42, 33, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    min-width: 0;
    line-height: 1.25;
}

.lang-switch {
    display: flex;
    gap: 5px;
    flex: 0 0 auto;
}

.lang-switch button {
    background: var(--secondary-color);
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 40px;
    color: var(--text-main);
    transition: background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.lang-switch button.active {
    background: var(--text-main);
    color: white;
}

/* Main Layout */
main {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Sections */
.hero {
    text-align: center;
    margin-bottom: 20px;
}
.highlight-note {
    font-size: 0.9rem;
    color: var(--primary-dark);
    font-weight: bold;
    margin-top: 5px;
}

main:focus {
    outline: none;
}

#customer-details,
#shop-section,
#order-review-section,
.form-group {
    scroll-margin-top: 82px;
    scroll-margin-bottom: 110px;
}

/* Order workflow */
.order-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.order-steps a {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 0.84rem;
    font-weight: 650;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(29, 42, 33, 0.05);
}

.step-number,
.section-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--primary-dark);
    color: white;
    font-weight: 750;
}

.step-number {
    width: 25px;
    height: 25px;
    font-size: 0.76rem;
}

.section-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 9px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.section-heading h2 {
    margin: 0;
    padding: 0;
    border: 0;
}

.section-step {
    width: 30px;
    height: 30px;
    font-size: 0.88rem;
}

.shop-section {
    margin-bottom: 22px;
}

.shop-heading {
    align-items: flex-start;
    padding: 16px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: 0 4px 14px rgba(29, 42, 33, 0.06);
}

.shop-heading p,
.review-help {
    color: var(--text-muted);
    font-size: 0.84rem;
    margin-top: 3px;
}

.vat-notice {
    margin: -6px 0 18px;
    padding: 10px 12px;
    border: 1px solid #dfc7ae;
    border-inline-start: 4px solid var(--accent-color);
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--warning);
    font-size: 0.84rem;
}

/* Most Popular Items */
.popular-section {
    margin-bottom: 22px;
    padding: 18px;
    border: 1px solid rgba(21, 90, 56, 0.24);
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(255, 253, 247, 0.99), rgba(230, 238, 225, 0.97));
    box-shadow: 0 7px 22px rgba(29, 42, 33, 0.08);
}

.popular-section-header {
    margin-bottom: 18px;
}

.popular-badge {
    display: inline-block;
    color: var(--accent-color);
    background: var(--accent-soft);
    border: 1px solid rgba(169, 79, 25, 0.24);
    border-radius: 999px;
    padding: 4px 10px;
    margin-bottom: 8px;
    font-size: 0.75rem;
    font-weight: 750;
    letter-spacing: 0.02em;
}

.popular-title {
    border: none;
    padding: 0;
    margin-bottom: 4px;
    font-size: 1.25rem;
}

.popular-subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.popular-category + .popular-category {
    margin-top: 20px;
}

.popular-category-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 9px;
}

.popular-category-header h4 {
    font-size: 0.98rem;
}

.popular-category-header span {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.popular-product-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(280px, 88%);
    gap: 13px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline mandatory;
    scroll-padding-inline: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(21, 90, 56, 0.32) transparent;
    padding: 2px 2px 10px;
}

.popular-product-row::-webkit-scrollbar {
    height: 6px;
}

.popular-product-row::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(21, 90, 56, 0.32);
}

.popular-product-row:focus-visible {
    outline: 3px solid rgba(21, 90, 56, 0.22);
    outline-offset: 3px;
    border-radius: var(--radius);
}

.popular-product-row .product-item {
    scroll-snap-align: start;
}

.card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 5px 18px rgba(29, 42, 33, 0.075);
    margin-bottom: 20px;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.profile-save-note {
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
    margin: 0 0 7px;
}

.required-note {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-bottom: 16px;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 5px;
    font-weight: 500;
}

input[type="text"],
input[type="tel"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--input-border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    background-color: var(--input-bg);
    transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

input[type="text"]:focus,
input[type="tel"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-dark);
    background-color: var(--raised-bg);
    box-shadow: 0 0 0 3px rgba(21, 90, 56, 0.16);
    outline: none;
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(166, 27, 43, 0.12);
}

.field-error {
    color: var(--danger);
    font-size: 0.8rem;
    line-height: 1.4;
    margin-top: 5px;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

select {
    min-height: 46px;
    cursor: pointer;
}

select:required:invalid {
    color: var(--text-muted);
}

select option {
    color: var(--text-main);
}

.form-subsection-title {
    font-size: 0.98rem;
    color: var(--primary-dark);
    margin: 5px 0 14px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}

.field-help {
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
    margin: -1px 0 9px;
}

.location-button {
    width: 100%;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid rgba(21, 90, 56, 0.72);
    border-radius: var(--radius);
    background: #eef6ec;
    color: var(--primary-dark);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.location-button:focus-visible,
.location-actions a:focus-visible,
.location-remove:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(21, 90, 56, 0.2);
}

.location-button:disabled {
    cursor: wait;
    opacity: 0.78;
}

.location-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
}

.location-spinner {
    display: none;
    width: 1.05rem;
    height: 1.05rem;
    flex: 0 0 auto;
    border: 2px solid rgba(21, 90, 56, 0.25);
    border-top-color: var(--primary-dark);
    border-radius: 50%;
    animation: location-spin 700ms linear infinite;
}

.location-button.is-loading .location-icon {
    display: none;
}

.location-button.is-loading .location-spinner {
    display: block;
}

@keyframes location-spin {
    to {
        transform: rotate(360deg);
    }
}

.location-status {
    font-size: 0.82rem;
    line-height: 1.45;
    margin-top: 8px;
}

.location-status:empty {
    display: none;
}

.location-status.is-success {
    color: var(--primary-dark);
}

.location-status.is-warning {
    color: var(--warning);
}

.location-status.is-error {
    color: var(--danger);
}

.location-status.is-info {
    color: var(--text-muted);
}

.location-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 9px;
}

.location-actions[hidden] {
    display: none;
}

.location-actions a,
.location-remove {
    border: none;
    background: none;
    color: var(--primary-dark);
    padding: 2px 0;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 650;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
}

.location-remove {
    color: var(--text-muted);
}

/* Controls (Search & Filters) */
.controls {
    margin-bottom: 20px;
}

.controls h3 {
    font-size: 1rem;
    margin-bottom: 10px;
}

#search-bar {
    margin-bottom: 15px;
}

.categories {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.cat-btn {
    background: var(--secondary-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.95rem;
    min-height: 44px;
    color: var(--text-main);
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.cat-btn.active {
    background: var(--text-main);
    color: white;
    border-color: var(--text-main);
}

/* Product Grid */
.product-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.empty-products {
    grid-column: 1 / -1;
    padding: 24px 16px;
    border: 1px dashed var(--input-border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text-muted);
    text-align: center;
}

@media (min-width: 600px) {
    .product-grid {
        grid-template-columns: 1fr 1fr;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }

    .popular-product-row {
        grid-auto-columns: calc((100% - 13px) / 2);
    }
}

.product-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 3px 14px rgba(29, 42, 33, 0.065);
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
    min-width: 0;
}

.product-item.is-selected {
    border-color: rgba(21, 90, 56, 0.58);
    box-shadow: 0 5px 18px rgba(21, 90, 56, 0.13);
}

.product-main {
    display: grid;
    grid-template-columns: clamp(92px, 27vw, 108px) minmax(0, 1fr);
    gap: 13px;
    align-items: center;
    margin-bottom: 12px;
}

.product-image-shell {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #eff3ec;
    isolation: isolate;
}

.product-image-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(105deg, #e7eee5 20%, #f7faf5 42%, #e7eee5 64%);
    background-size: 220% 100%;
    animation: product-image-loading 1.3s ease-in-out infinite;
    transition: opacity 180ms ease;
}

.product-image-shell.is-loaded::before,
.product-image-shell.has-error::before {
    opacity: 0;
    animation: none;
    pointer-events: none;
}

.product-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0;
    transform: scale(1.015);
    transition: opacity 220ms ease, transform 300ms ease;
}

.product-image-shell.is-loaded .product-image {
    opacity: 1;
    transform: scale(1);
}

.product-content {
    min-width: 0;
}

@keyframes product-image-loading {
    from {
        background-position: 100% 0;
    }
    to {
        background-position: -100% 0;
    }
}

.product-name {
    font-size: 1.02rem;
    line-height: 1.3;
    margin-bottom: 3px;
}

.product-origin {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.product-price {
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.95rem;
    margin-top: 8px;
}

/* Official UAE Dirham symbol: always placed to the left of the amount. */
.currency-amount {
    display: inline-flex;
    align-items: center;
    gap: 0.26em;
    direction: ltr;
    unicode-bidi: isolate;
    white-space: nowrap;
}

.dirham-symbol {
    display: block;
    width: 1.03em;
    height: 0.9em;
    flex: 0 0 auto;
}

/* Quantity Controls */
.qty-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    background: var(--secondary-color);
    border-radius: var(--radius);
    padding: 5px;
}

.qty-btn {
    background: var(--raised-bg);
    border: 1px solid var(--border-color);
    width: 44px;
    height: 44px;
    border-radius: 7px;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.qty-btn:active {
    background: var(--border-color);
    transform: scale(0.94);
}

.qty-display {
    font-weight: bold;
    font-size: 0.95rem;
    text-align: center;
    flex-grow: 1;
}

.item-total {
    text-align: end;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    min-height: 20px; /* reserve space */
}

/* Review Section */
#order-preview {
    background: var(--secondary-color);
    border: none;
    border-radius: 4px;
    width: 100%;
    min-height: 320px;
    padding: 10px;
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 15px;
    outline: none;
    color: var(--text-main);
    font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    tab-size: 4;
    white-space: pre;
    overflow-x: auto;
    text-align: left;
}

.review-help {
    margin: -2px 0 12px;
}

.price-breakdown {
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--raised-bg);
}

.price-breakdown h3 {
    margin-bottom: 9px;
    font-size: 1rem;
}

.price-breakdown dl > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding-block: 5px;
}

.price-breakdown dt {
    color: var(--text-muted);
}

.price-breakdown dd {
    margin: 0;
    flex: 0 0 auto;
}

.price-breakdown .price-breakdown-total {
    margin-top: 5px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-weight: bold;
}

.price-breakdown .price-breakdown-total dt,
.price-breakdown .price-breakdown-total dd {
    color: var(--primary-dark);
}

.error-msg {
    color: var(--danger);
    background: #fbe4e7;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.error-msg:focus {
    outline: 3px solid rgba(166, 27, 43, 0.2);
    outline-offset: 2px;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-status {
    min-height: 1.4em;
    margin-top: 9px;
    color: var(--primary-dark);
    font-size: 0.84rem;
    text-align: center;
}

.action-status.is-error {
    color: var(--danger);
}

.btn-primary,
.btn-secondary,
.btn-review {
    border: none;
    padding: 14px;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: bold;
    min-height: 48px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: filter 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-secondary {
    background-color: var(--text-main);
    color: white;
}

/* Sticky Bottom Bar */
.sticky-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 18px rgba(29, 42, 33, 0.1);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 99;
    gap: 12px;
}

.summary-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.summary-total {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary-dark);
}

.summary-vat-note {
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.2;
}

.btn-review {
    background: var(--text-main);
    color: white;
    padding: 10px 20px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) {
    .lang-switch button:hover,
    .cat-btn:hover,
    .qty-btn:hover {
        border-color: var(--primary-dark);
    }

    .product-item:hover {
        border-color: var(--input-border-color);
        box-shadow: 0 7px 20px rgba(29, 42, 33, 0.11);
        transform: translateY(-1px);
    }

    .product-item:hover .product-image-shell.is-loaded .product-image {
        transform: scale(1.035);
    }

    .location-button:hover:not(:disabled) {
        background: #e3efdf;
        border-color: var(--primary-dark);
        transform: translateY(-1px);
    }

    .location-actions a:hover,
    .location-remove:hover {
        color: var(--text-main);
    }

    .btn-primary:hover,
    .btn-secondary:hover,
    .btn-review:hover {
        filter: brightness(0.95);
        box-shadow: 0 4px 12px rgba(29, 42, 33, 0.18);
        transform: translateY(-1px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }

    .product-image-shell::before {
        animation: none;
    }
}

@media (max-width: 480px) {
    header {
        padding: 12px;
    }

    header h1 {
        font-size: 1.02rem;
    }

    .lang-switch button {
        padding-inline: 8px;
        font-size: 0.82rem;
    }

    main {
        padding: 16px;
    }

    .popular-section {
        padding: 14px;
    }

    .hero p {
        overflow-wrap: anywhere;
    }

    .sticky-bar {
        padding: 11px 14px;
    }

    .btn-review {
        padding-inline: 14px;
    }
}

@media (max-width: 360px) {
    main {
        padding-inline: 12px;
    }

    .product-item {
        padding: 12px;
    }

    .product-main {
        grid-template-columns: 88px minmax(0, 1fr);
        gap: 11px;
    }
}
