:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2b241c;
  --muted: #8a7d6b;
  --brand: #8a5a2b;
  --brand-ink: #ffffff;
  --brand-soft: #f3e7d8;
  --accent: #2e6e5b;
  --danger: #b3402e;
  --line: #e8ddcd;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html { direction: rtl; }
html[dir="ltr"], html[dir="ltr"] body { direction: ltr; }
body {
  margin: 0;
  font-family: 'Tajawal', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
a { color: var(--brand); }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--brand-ink);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.app-header .logo { width: 40px; height: 40px; border-radius: 10px; }
.app-header h1 { font-size: 1.15rem; margin: 0; flex: 1; }
.app-header .sub { font-size: 0.78rem; opacity: 0.85; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; overflow-x: auto; gap: 4px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 6px 10px; position: sticky; top: 64px; z-index: 15;
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 9px 14px; border-radius: 999px; white-space: nowrap;
  font-weight: 600; cursor: pointer; min-height: 44px;
}
.tabs button.active { background: var(--brand-soft); color: var(--brand); }

/* ---------- layout ---------- */
.page { max-width: 860px; margin: 0 auto; padding: 16px 14px 90px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 0.86rem; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; min-height: 44px;
  cursor: pointer; font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.success { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: 0.86rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 18px; height: 18px; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 10px; }
label.field span { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=tel], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

/* ---------- menu items ---------- */
.item-row {
  display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); align-items: flex-start;
}
.item-row:last-child { border-bottom: 0; }
.item-row img { width: 58px; height: 58px; border-radius: 10px; flex-shrink: 0; }
.item-row .info { flex: 1; min-width: 0; }
.item-row .name { font-weight: 700; }
.item-row .desc { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.price { color: var(--brand); font-weight: 700; white-space: nowrap; }
.old-price { text-decoration: line-through; color: var(--muted); font-size: 0.8rem; font-weight: 400; margin-right: 6px; }
.tag-chip {
  display: inline-block; background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; margin-top: 4px;
}
.off { opacity: 0.45; }

.cat-block { margin-bottom: 20px; }
.cat-block h3 {
  font-size: 1.05rem; margin: 14px 0 6px; padding-bottom: 6px;
  border-bottom: 2px solid var(--brand-soft); color: var(--brand);
}

/* ---------- QR ---------- */
.qr-wrap { text-align: center; padding: 16px; }
.qr-wrap canvas { max-width: 260px; width: 100%; border-radius: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat {
  background: var(--brand-soft); border-radius: 12px; padding: 14px; text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--brand); }
.stat .lbl { font-size: 0.8rem; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 20px;
  max-width: 480px; width: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 18px; right: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 999px;
  font-size: 0.9rem; opacity: 0; transition: opacity 0.25s; z-index: 99; pointer-events: none;
}
#toast.show { opacity: 1; }

/* ---------- customer menu page ---------- */
.menu-hero { text-align: center; padding: 22px 16px 10px; }
.menu-hero img { width: 84px; height: 84px; border-radius: 20px; }
.menu-hero h1 { margin: 10px 0 2px; font-size: 1.35rem; }
.menu-hero .branch { color: var(--muted); font-size: 0.9rem; }
.cat-nav {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 6px; overflow-x: auto;
  background: var(--bg); padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.cat-nav a {
  flex-shrink: 0; text-decoration: none; color: var(--muted); font-weight: 600;
  background: var(--surface); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; font-size: 0.88rem; min-height: 40px;
  display: inline-flex; align-items: center;
}
.cat-nav a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.search-box { padding: 10px 14px 0; }

.dish-card {
  display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.dish-card img { width: 76px; height: 76px; border-radius: 12px; flex-shrink: 0; }
.dish-card .info { flex: 1; min-width: 0; }
.dish-card .name { font-weight: 700; font-size: 1rem; }
.dish-card .desc { font-size: 0.82rem; color: var(--muted); margin: 3px 0 6px; }
.add-btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 999px;
  padding: 8px 16px; min-height: 40px; font-weight: 700; cursor: pointer; white-space: nowrap;
}

/* cart bar + drawer */
.cart-bar {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  background: var(--brand); color: #fff; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; font-weight: 700;
}
.cart-drawer {
  position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--surface);
  border-radius: 18px 18px 0 0; max-height: 82vh; overflow-y: auto;
  padding: 18px 16px 30px; transform: translateY(105%); transition: transform 0.25s;
  box-shadow: 0 -6px 30px rgba(0,0,0,0.2);
}
.cart-drawer.open { transform: translateY(0); }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 35; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.qty-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-weight: 800; cursor: pointer; font-size: 1.1rem;
}
.wa-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #1faa55; color: #fff; border: 0; border-radius: 12px;
  width: 100%; padding: 14px; min-height: 50px; font-size: 1.05rem; font-weight: 800;
  cursor: pointer; text-decoration: none; margin-top: 12px;
}

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }

@media (max-width: 480px) {
  .item-row { flex-wrap: wrap; }
  .item-row > .row { width: 100%; justify-content: flex-start; }
  .item-row .info { min-width: calc(100% - 70px); }
}

@media (min-width: 720px) {
  .dish-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* ---------- print (price list + QR card) ---------- */
@media print {
  .tabs, .btn, .app-header .actions, .cart-bar, .cat-nav, .search-box, #toast { display: none !important; }
  body { background: #fff; }
  .card, .dish-card { box-shadow: none; break-inside: avoid; }
}

/* ---------- themes ---------- */
body[data-theme="theme-green"] {
  --brand: #2e6e5b; --brand-soft: #ddeee7; --bg: #f4f7f4; --accent: #8a5a2b;
}
body[data-theme="theme-dark"] {
  --bg: #1d1a16; --surface: #2a2520; --ink: #f0e9de; --muted: #a89a86;
  --brand: #d9a05b; --brand-ink: #241c10; --brand-soft: #3a3126; --line: #453c30;
  --accent: #5cb899; --shadow: 0 2px 10px rgba(0,0,0,0.4);
}
body[data-theme="theme-dark"] input[type=text], body[data-theme="theme-dark"] input[type=password],
body[data-theme="theme-dark"] input[type=tel], body[data-theme="theme-dark"] input[type=number],
body[data-theme="theme-dark"] select, body[data-theme="theme-dark"] textarea { background: #1d1a16; color: var(--ink); }
body[data-theme="theme-red"] {
  --brand: #a03a2c; --brand-soft: #f6e2dd; --bg: #faf4f2; --accent: #2e6e5b;
}

/* ---------- language toggle ---------- */
.lang-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang-toggle button { border: 0; background: var(--surface); color: var(--muted); padding: 7px 16px; min-height: 40px; cursor: pointer; font-weight: 700; }
.lang-toggle button.active { background: var(--brand); color: var(--brand-ink); }

/* ---------- options dialog ---------- */
.opt-group { margin-bottom: 12px; }
.opt-group h4 { margin: 0 0 6px; font-size: 0.95rem; color: var(--brand); }
.opt-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; min-height: 44px;
}
.opt-row input { width: auto; }
.opt-row .p { margin-inline-start: auto; color: var(--brand); font-weight: 700; white-space: nowrap; }

/* ---------- closed banner ---------- */
.closed-banner {
  background: #f6e2dd; color: #a03a2c; border: 1px solid #e3b7ae;
  border-radius: 12px; padding: 12px 16px; margin: 12px 14px 0; text-align: center; font-weight: 700;
}
body[data-theme="theme-dark"] .closed-banner { background: #402320; color: #f0b7ac; border-color: #5c332c; }

/* ---------- order type radios ---------- */
.otype-row { display: flex; gap: 8px; flex-wrap: wrap; }
.otype-row label {
  flex: 1; min-width: 90px; text-align: center; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 6px; cursor: pointer; font-weight: 600; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.otype-row label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.otype-row input { width: auto; }

/* ---------- reorder buttons ---------- */
.reorder-btn { min-width: 36px; padding: 6px 8px; }

/* ---------- batch QR grid ---------- */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.qr-grid .cell { text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--surface); }
.qr-grid canvas { width: 100%; border-radius: 8px; }

/* ---------- print sheet for batch QR ---------- */
@media print {
  .sheet-cell { display: inline-block; width: 60mm; text-align: center; margin: 5mm; page-break-inside: avoid; }
  .sheet-cell img { width: 45mm; }
}
