:root {
  --plum: #181818;
  --plum-dark: #0b0b0b;
  --plum-soft: #f4eedc;
  --teal: #0b6b68;
  --saffron: #c99b22;
  --canvas: #f7f7f6;
  --surface: #ffffff;
  --ink: #211b1d;
  --muted: #655c5f;
  --line: #ded8da;
  --danger: #a32929;
  --z-sticky: 20;
  --z-dock: 30;
  --z-modal: 40;
  --z-toast: 50;
  font-family: "Tajawal", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
img { display: block; max-width: 100%; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -60px; right: 1rem; z-index: var(--z-toast); padding: .65rem 1rem; border-radius: .5rem; background: var(--surface); }
.skip-link:focus { top: 1rem; }

/* Mobile-first menu */
.menu-body { min-height: 100vh; padding-bottom: calc(5.8rem + env(safe-area-inset-bottom)); background: var(--canvas); }
.menu-shell { width: min(100% - 1.25rem, 1120px); margin-inline: auto; }
.menu-tools { position: sticky; top: 0; z-index: var(--z-sticky); margin-inline: -.625rem; padding: .5rem .625rem .4rem; background: rgba(247,247,246,.98); border-bottom: 1px solid rgba(222,216,218,.65); }
.search-box { min-height: 44px; display: flex; align-items: center; gap: .55rem; padding: 0 .8rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.search-icon { color: var(--plum); font-size: 1.15rem; }
.search-box input { width: 100%; min-height: 44px; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-box input::placeholder { color: #6c6265; opacity: 1; }
.category-tabs { display: flex; gap: .45rem; overflow-x: auto; margin-top: .55rem; padding-bottom: .1rem; scrollbar-width: none; }
.category-tabs::-webkit-scrollbar { display: none; }
.tab-button { min-height: 40px; flex: 0 0 auto; padding: .45rem .85rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: .8rem; font-weight: 700; }
.tab-button:hover { border-color: #baaeb2; color: var(--ink); }
.tab-button:active { transform: scale(.97); }
.tab-button[aria-pressed="true"] { border-color: var(--plum); background: var(--plum); color: #fff; }
.cart-tip { margin: .65rem 0 0; color: var(--muted); font-size: .76rem; text-align: center; }
.menu-title-row { padding: .8rem 0 .55rem; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.menu-title-row h1 { margin: 0; font-size: 1.2rem; }
.result-count { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.menu-content { display: flex; flex-direction: column; gap: .55rem; }
.menu-content.is-filtering .dish-card { animation: cards-in .2s cubic-bezier(.22,1,.36,1) both; }
.menu-content.is-filtering .dish-card:nth-child(2n) { animation-delay: 28ms; }
.dish-card { min-width: 0; display: grid; grid-template-columns: 112px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: .75rem; background: var(--surface); }
.dish-photo-wrap { position: relative; min-height: 112px; overflow: hidden; background: #ece9ea; }
.dish-image { width: 100%; height: 100%; object-fit: cover; transition: transform .22s cubic-bezier(.22,1,.36,1); }
.dish-card:hover .dish-image { transform: scale(1.025); }
.popular-tag { position: absolute; top: .5rem; right: .5rem; padding: .2rem .5rem; border-radius: 999px; background: var(--teal); color: #fff; font-size: .65rem; font-weight: 850; }
.dish-body { min-width: 0; padding: .7rem; display: flex; flex-direction: column; }
.dish-body h3 { margin: 0; font-size: .98rem; line-height: 1.35; text-wrap: balance; }
.dish-body p { display: -webkit-box; margin: .22rem 0 .45rem; overflow: hidden; color: var(--muted); font-size: .74rem; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 1; text-wrap: pretty; }
.dish-actions { min-height: 40px; margin-top: auto; display: flex; align-items: end; justify-content: space-between; gap: .5rem; }
.price { color: var(--plum); font-size: .84rem; white-space: nowrap; }
.price-missing { color: var(--muted); font-size: .67rem; line-height: 1.2; }
.add-button { min-height: 40px; flex: 0 0 auto; padding: .45rem .8rem; border: 0; border-radius: .55rem; background: var(--plum-soft); color: var(--plum); cursor: pointer; font-size: .78rem; font-weight: 850; transition: background-color .18s ease, color .18s ease, transform .18s ease; }
.add-button:hover { background: var(--plum); color: #fff; }
.add-button:active { transform: scale(.94); }
.add-button:disabled { max-width: 72px; background: #ece9ea; color: #776e70; cursor: not-allowed; font-size: .62rem; }
.quantity { min-height: 40px; display: inline-flex; align-items: center; overflow: hidden; border-radius: .55rem; background: var(--plum); color: #fff; }
.quantity button { width: 36px; min-height: 40px; border: 0; background: transparent; color: #fff; cursor: pointer; font-weight: 850; }
.quantity button:hover { background: rgba(255,255,255,.12); }
.quantity strong { min-width: 1.25rem; text-align: center; font-size: .78rem; }
.quantity-compact { min-height: 32px; }
.quantity-compact button { min-height: 32px; }
.empty-state { padding: 4rem 1rem; text-align: center; color: var(--muted); }
.empty-state strong, .empty-state span { display: block; }
.compact-footer { width: min(100% - 1.25rem, 1120px); margin: 2rem auto 0; padding: 1rem 0; border-top: 1px solid var(--line); color: var(--muted); font-size: .72rem; text-align: center; }

.cart-dock { position: fixed; right: 50%; bottom: calc(.75rem + env(safe-area-inset-bottom)); z-index: var(--z-dock); width: min(calc(100% - 1.25rem), 430px); min-height: 56px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; padding: .55rem .7rem; border: 0; border-radius: .9rem; background: var(--plum-dark); color: #fff; box-shadow: 0 6px 14px rgba(42,17,24,.24); cursor: pointer; transform: translateX(50%); }
.cart-dock:hover { background: #351720; }
.cart-dock:active { transform: translateX(50%) scale(.985); }
.cart-count { width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: .55rem; background: var(--saffron); color: var(--plum-dark); font-weight: 900; }
.cart-dock strong { text-align: right; }
.cart-dock > span:last-child { color: #f0e6e8; font-size: .85rem; }
.cart-dock.is-bumping { animation: dock-bump .22s cubic-bezier(.22,1,.36,1); }

.cart-dialog { width: min(100%, 540px); max-width: 540px; max-height: 92dvh; inset: auto 0 0; margin: auto auto 0; padding: 0; overflow: visible; border: 0; background: transparent; color: var(--ink); }
.cart-dialog::backdrop { background: rgba(27,13,17,.62); }
.cart-dialog[open] .cart-sheet { animation: sheet-in .22s cubic-bezier(.22,1,.36,1); }
.cart-sheet { max-height: 88dvh; display: flex; flex-direction: column; overflow: hidden; border-radius: 1rem 1rem 0 0; background: var(--surface); }
.cart-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: 1rem 1rem .8rem; border-bottom: 1px solid var(--line); }
.sheet-handle { width: 38px; height: 4px; display: block; margin: -.4rem auto .7rem; border-radius: 999px; background: #d1c9cb; }
.cart-header h2 { margin: 0; font-size: 1.25rem; }
.cart-header p { margin: .15rem 0 0; color: var(--muted); font-size: .74rem; }
.icon-button { width: 36px; height: 36px; flex: 0 0 auto; border: 0; border-radius: .6rem; background: var(--canvas); cursor: pointer; font-size: 1.4rem; line-height: 1; }
.cart-items { min-height: 0; overflow-y: auto; padding: .4rem 1rem; }
.cart-row { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: .7rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.cart-row img { width: 52px; height: 52px; object-fit: cover; border-radius: .55rem; }
.cart-row h3 { margin: 0; font-size: .85rem; }
.cart-row span { color: var(--muted); font-size: .74rem; }
.cart-empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.split-card { margin: .8rem 1rem; padding: .85rem; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .75rem; border-radius: .8rem; background: var(--plum-soft); }
.split-card h3 { margin: 0; font-size: .95rem; }
.split-card p { margin: .1rem 0 0; color: var(--muted); font-size: .72rem; }
.split-stepper { display: inline-flex; align-items: center; overflow: hidden; border-radius: .6rem; background: var(--surface); }
.split-stepper button { width: 34px; height: 34px; border: 0; background: transparent; cursor: pointer; }
.split-stepper strong { min-width: 1.5rem; text-align: center; }
.split-result { grid-column: 1 / -1; padding-top: .7rem; display: flex; align-items: baseline; justify-content: space-between; border-top: 1px solid #dacdd1; }
.split-result span { color: var(--muted); font-size: .75rem; }
.split-result strong { color: var(--plum); font-size: 1.1rem; }
.cart-summary { padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.cart-summary > div { display: grid; text-align: left; }
.cart-summary span { color: var(--muted); font-size: .72rem; }
.cart-summary strong { color: var(--plum); font-size: 1.15rem; }
.clear-button { border: 0; background: transparent; color: var(--danger); cursor: pointer; text-decoration: underline; text-underline-offset: .2rem; }
.clear-button:disabled { color: #9b9395; cursor: not-allowed; }
.toast { position: fixed; right: 50%; bottom: calc(5rem + env(safe-area-inset-bottom)); z-index: var(--z-toast); max-width: calc(100% - 2rem); padding: .55rem .9rem; border-radius: .6rem; background: var(--teal); color: #fff; opacity: 0; pointer-events: none; transform: translate(50%, .6rem); transition: opacity .18s ease, transform .18s cubic-bezier(.22,1,.36,1); font-size: .78rem; font-weight: 800; }
.toast.is-visible { opacity: 1; transform: translate(50%, 0); }

@keyframes cards-in { from { opacity: .55; transform: translateY(6px); } }
@keyframes dock-bump { 50% { transform: translateX(50%) scale(1.035); } }
@keyframes sheet-in { from { opacity: .7; transform: translateY(20px); } }

@media (min-width: 700px) {
  .menu-shell { width: min(100% - 3rem, 1120px); }
  .menu-tools { margin-inline: 0; padding: .5rem 0; }
  .search-box { max-width: 620px; margin-inline: auto; }
  .category-tabs { max-width: 960px; margin: .45rem auto 0; justify-content: center; flex-wrap: wrap; overflow: visible; }
  .tab-button { min-height: 34px; padding: .3rem .7rem; font-size: .76rem; }
  .menu-content { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; }
  .dish-card { display: block; }
  .dish-photo-wrap { aspect-ratio: 1.15; min-height: 0; }
  .dish-body h3 { min-height: 2.55em; font-size: .92rem; }
  .dish-body p { min-height: 2.65em; -webkit-line-clamp: 2; }
  .compact-footer { width: min(100% - 3rem, 1120px); }
  .cart-sheet { border-radius: 1rem 1rem 0 0; }
}

@media (min-width: 1020px) {
  .menu-content { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 350px) {
  .dish-card { grid-template-columns: 96px minmax(0, 1fr); }
  .dish-photo-wrap { min-height: 104px; }
}

/* Admin */
.admin-body { min-height: 100vh; background: var(--canvas); }
.admin-header { background: var(--plum-dark); color: white; padding: 1rem clamp(1rem,5vw,4rem); display: flex; align-items: center; justify-content: space-between; }
.admin-header h1 { font-size: 1.25rem; letter-spacing: 0; margin: 0; }
.admin-main { max-width: 1100px; margin: auto; padding: 2rem 1rem 5rem; }
.admin-toolbar { position: sticky; top: .7rem; z-index: 5; display: grid; grid-template-columns: 1fr auto auto; gap: .7rem; padding: 1rem; border: 1px solid var(--line); border-radius: .8rem; background: white; }
.admin-toolbar input, .admin-toolbar select, .field input, .field select, .field textarea { width: 100%; padding: .75rem; border: 1px solid var(--line); border-radius: .65rem; background: white; color: var(--ink); }
.button { padding: .75rem 1rem; border: 0; border-radius: .65rem; cursor: pointer; font-weight: 800; }
.button-primary { background: var(--plum); color: white; }
.button-secondary { background: #eeebec; color: var(--ink); }
.button-danger { background: #fff0f0; color: var(--danger); }
.admin-status { min-height: 1.5rem; margin: 1rem 0; color: var(--muted); }
.admin-status.success { color: var(--teal); }
.admin-status.error { color: var(--danger); }
.admin-list { display: grid; gap: .7rem; }
.admin-item { display: grid; grid-template-columns: 76px 1fr auto; gap: 1rem; align-items: center; padding: .65rem; border: 1px solid var(--line); border-radius: .8rem; background: white; }
.admin-item img { width: 76px; height: 76px; object-fit: cover; border-radius: .55rem; background: #eeebec; }
.admin-item h3, .admin-item p { margin: 0; }
.admin-item p { color: var(--muted); font-size: .8rem; }
.admin-actions { display: flex; gap: .4rem; }
dialog:not(.cart-dialog) { width: min(620px, calc(100% - 2rem)); padding: 0; border: 0; border-radius: .8rem; box-shadow: 0 12px 32px rgba(0,0,0,.24); }
dialog:not(.cart-dialog)::backdrop { background: rgba(25,12,16,.7); }
.dialog-form { padding: 1.4rem; }
.dialog-form h2 { margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.field { display: grid; gap: .3rem; font-size: .85rem; }
.field-wide { grid-column: 1 / -1; }
.checkbox-field { display: flex; gap: .6rem; align-items: center; }
.checkbox-field input { width: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

@media (max-width: 820px) {
  .admin-toolbar { grid-template-columns: 1fr 1fr; }
  .admin-toolbar input { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .admin-item { grid-template-columns: 58px 1fr; }
  .admin-item img { width: 58px; height: 58px; }
  .admin-actions { grid-column: 1 / -1; justify-content: end; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
