:root {
    --red: #E31E24;
    --red-dark: #B8141A;
    --teal: #0F5E5C;
    --teal-light: #E3F0EF;
    --ink: #1A1A1A;
    --muted: #6B6B6B;
    --bg: #F6F4F1;
    --card: #FFFFFF;
    --line: #E7E3DE;
    --wa: #25D366;
    --radius: 16px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-padding-top: 80px; }

body {
    margin: 0;
    font-family: "Cairo", system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    padding-bottom: calc(160px + var(--safe-b));
    -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 16px; /* يمنع التكبير التلقائي في iPhone */ }

/* ===== الرأس ===== */
.top {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--card);
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    transition: padding .2s;
}

.logo {
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 12px;
    transition: width .2s, height .2s;
}

.brand-text { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 800; line-height: 1.2; transition: font-size .2s; }
.brand p { margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p.on-cat { color: var(--red); font-weight: 800; font-size: 14px; }

/* الرأس المصغّر عند النزول */
.top.compact .brand { padding: 5px 14px; }
.top.compact .logo { width: 34px; height: 34px; border-radius: 9px; }
.top.compact h1 { font-size: 15px; }

.to-cats {
    flex: 0 0 auto;
    border: none;
    background: var(--red);
    color: #fff;
    border-radius: 10px;
    padding: 7px 12px;
    font-size: 14px;
    font-weight: 800;
}
.to-cats[hidden] { display: none; }

/* ===== شبكة الأقسام (صغيرة وتصعد مع التمرير) ===== */
.cats {
    max-width: 900px;
    margin: 0 auto;
    padding: 10px 12px 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

@media (min-width: 560px) { .cats { grid-template-columns: repeat(6, 1fr); } }

.cat-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 5px 3px 6px;
    color: var(--ink);
    min-width: 0;
    transition: transform .12s, border-color .12s;
}
.cat-tile:active { transform: scale(.95); border-color: var(--red); }

.cat-tile img {
    width: 100%;
    height: 36px;
    object-fit: contain;
}

.cat-tile span {
    font-size: 11.5px;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    min-height: 2.6em;
    display: flex;
    align-items: center;
}

/* الشبكة داخل نافذة الأقسام */
.cats-sheet { padding: 12px 0 4px; gap: 8px; grid-template-columns: repeat(3, 1fr); }
.cats-sheet .cat-tile img { height: 48px; }
.cats-sheet .cat-tile span { font-size: 13px; }

/* ===== دعوة تثبيت التطبيق ===== */
.install {
    max-width: 876px;
    margin: 10px 12px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card);
    border: 1.5px solid var(--red);
    border-radius: 14px;
    padding: 8px 10px;
}
@media (min-width: 900px) { .install { margin: 10px auto 0; } }
.install[hidden] { display: none; }
.install img { width: 40px; height: 40px; border-radius: 10px; flex: 0 0 40px; }
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.install-text strong { font-size: 14px; font-weight: 800; }
.install-text span { font-size: 12px; color: var(--muted); }
.install-btn {
    border: none;
    background: var(--red);
    color: #fff;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: 14px;
}
.install-btn[hidden] { display: none; }
.install-close {
    border: none;
    background: none;
    color: var(--muted);
    font-size: 15px;
    width: 28px;
    height: 28px;
    padding: 0;
}

/* ===== الأقسام ===== */
.menu { max-width: 900px; margin: 0 auto; padding: 8px 12px; }

.section { margin-top: 18px; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--red);
    color: #fff;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
}
.section-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.section-head span { font-weight: 800; letter-spacing: 2px; opacity: .85; font-size: 13px; direction: ltr; }

.items { display: grid; gap: 10px; }

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

/* ===== بطاقة الصنف ===== */
.item {
    display: flex;
    gap: 12px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 10px;
    border: 1px solid var(--line);
    text-align: right;
    width: 100%;
    color: inherit;
    font: inherit;
    align-items: stretch;
}
.item:active { transform: scale(.99); }

.item-img {
    width: 104px;
    height: 88px;
    flex: 0 0 104px;
    object-fit: contain;
    background: #fff;
    border-radius: 12px;
}

.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-name { font-size: 16px; font-weight: 800; margin: 0 0 2px; }
.item-desc {
    font-size: 12.5px;
    color: var(--red-dark);
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-foot {
    margin-top: auto;
    padding-top: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.price-pill {
    background: var(--teal);
    color: #fff;
    border-radius: 999px;
    padding: 3px 12px;
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
}
.price-pill small { font-weight: 600; opacity: .85; font-size: 11px; }

.add-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: none;
    background: var(--red);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    position: relative;
}
.add-btn .badge {
    position: absolute;
    top: -6px;
    left: -6px;
    background: var(--teal);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    padding: 0 4px;
    border: 2px solid #fff;
}

.add-btn .badge[hidden] { display: none; }

.foot-note { text-align: center; color: var(--muted); font-size: 14px; margin: 24px 16px; }

/* ===== شريط السلة ===== */
.cart-bar {
    position: fixed;
    bottom: calc(60px + var(--safe-b)); /* فوق الفوتر الثابت */
    left: 12px;
    right: 12px;
    max-width: 560px;
    margin: 0 auto;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    border: none;
    border-radius: 16px;
    background: var(--red);
    color: #fff;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 8px 24px rgba(227,30,36,.35);
}
.cart-bar[hidden] { display: none; }
.cart-count {
    background: #fff;
    color: var(--red);
    min-width: 28px;
    height: 28px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 14px;
    padding: 0 6px;
}
.cart-bar-text { flex: 1; text-align: right; }
.cart-bar.bump { animation: bump .35s; }
@keyframes bump { 50% { transform: scale(1.04); } }

/* ===== النوافذ السفلية ===== */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
}
.sheet-backdrop[hidden], .sheet[hidden] { display: none; }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    max-width: 560px;
    margin: 0 auto;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--card);
    border-radius: 22px 22px 0 0;
    padding: 18px 16px calc(18px + var(--safe-b));
    animation: up .22s ease-out;
}
.sheet-tall { min-height: 60vh; }
@keyframes up { from { transform: translateY(100%); } }

@media (min-width: 640px) {
    .sheet { bottom: 50%; transform: translateY(50%); border-radius: 22px; animation: none; }
}

.sheet h2 { margin: 4px 0; font-size: 20px; font-weight: 800; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 10px; line-height: 1.6; }

.sheet-close {
    position: sticky;
    top: 0;
    float: left;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    font-size: 16px;
    z-index: 2;
}

.sheet-img {
    display: block;
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    margin: 0 auto 8px;
}

.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 10px 0 14px; }

.opt {
    border: 2px solid var(--line);
    background: var(--card);
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    color: var(--ink);
}
.opt b { display: block; color: var(--teal); font-size: 15px; }
.opt.selected { border-color: var(--red); background: #FFF1F1; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.field input, .field textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    background: #FCFBFA;
    resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--teal); background: #fff; }
.field input.invalid, .field textarea.invalid { border-color: var(--red); }

.sheet-actions { display: flex; gap: 12px; align-items: center; position: sticky; bottom: 0; background: var(--card); padding-top: 6px; }

.qty {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}
.qty button {
    width: 44px;
    height: 48px;
    border: none;
    background: var(--bg);
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
}
.qty span { min-width: 38px; text-align: center; font-weight: 800; font-size: 18px; }

.btn-primary {
    flex: 1;
    height: 50px;
    border: none;
    border-radius: 12px;
    background: var(--red);
    color: #fff;
    font-size: 16px;
    font-weight: 800;
}

/* ===== السلة ===== */
.cart-list { list-style: none; padding: 0; margin: 12px 0; }

.cart-item {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.cart-item img { width: 56px; height: 48px; object-fit: contain; border-radius: 8px; flex: 0 0 56px; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-weight: 800; font-size: 15px; margin: 0; }
.cart-item-meta { font-size: 12.5px; color: var(--muted); margin: 0; }
.cart-item-price { font-weight: 800; color: var(--teal); font-size: 14px; margin: 2px 0 0; }

.cart-item .qty button { width: 34px; height: 36px; font-size: 18px; }
.cart-item .qty span { min-width: 26px; font-size: 15px; }

.cart-empty { text-align: center; color: var(--muted); padding: 30px 0; }

.cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    font-weight: 800;
    padding: 6px 0;
}
.cart-total strong { color: var(--red); font-size: 20px; }

.delivery-note {
    background: #FFF6E0;
    color: #7A5200;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 700;
    margin: 6px 0 16px;
    text-align: center;
}

.form-error { color: var(--red); font-weight: 700; font-size: 14px; margin: 0 0 10px; }

.btn-whatsapp {
    width: 100%;
    height: 54px;
    border: none;
    border-radius: 14px;
    background: var(--wa);
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-whatsapp:disabled { opacity: .5; }

.btn-link {
    display: block;
    margin: 12px auto 0;
    background: none;
    border: none;
    color: var(--muted);
    text-decoration: underline;
    font-size: 14px;
}

/* ===== تنبيه ===== */
.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translate(-50%, -150%);
    background: var(--ink);
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
    z-index: 60;
    transition: transform .25s;
    pointer-events: none;
    white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); }

/* التنبيه مخفي تماماً عندما لا توجد رسالة (كان يظهر كنقطة سوداء أعلى الشاشة) */
.toast { opacity: 0; visibility: hidden; transform: translate(-50%, -120px); transition: transform .25s, opacity .2s, visibility .25s; }
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }


/* ===== رسالة المنيو التجريبي ===== */
.demo-sheet { text-align: center; padding-top: 22px; }
.demo-logo { width: 84px; height: auto; margin: 0 auto 6px; display: block; }
.demo-sheet h2 { font-size: 22px; margin: 4px 0 8px; }
.demo-text { color: var(--muted); font-size: 15.5px; line-height: 1.9; margin: 0 0 12px; }
.demo-text b { color: #3F4596; font-size: 16px; }
.demo-phone {
    display: inline-block;
    font-size: 26px;
    font-weight: 800;
    color: #E8343B;
    text-decoration: none;
    letter-spacing: 1px;
    margin-bottom: 14px;
}
.demo-actions { display: flex; gap: 10px; }
.demo-actions .btn-whatsapp { flex: 1; text-decoration: none; }
.demo-call {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    height: 54px;
    border-radius: 14px;
    background: #3F4596;
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    text-decoration: none;
}
