/* ════════════════════════════════════════════════════════
   نظام إدارة المطعم — التصميم
   الهوية: داكن دافئ (فحمي بنّي) + برتقالي توابل + كريمي
   ════════════════════════════════════════════════════════ */

:root {
  /* Palette — warm charcoal kitchen */
  --bg:        #15100C;   /* deepest — app background */
  --surface:   #1F1813;   /* cards, sidebar */
  --surface-2: #2A211A;   /* raised elements, inputs */
  --line:      #3A2E24;   /* borders */
  --ember:     #E8651E;   /* primary accent — spice orange */
  --ember-soft:#F2935A;   /* lighter accent */
  --gold:      #E8B04B;   /* secondary accent — saffron */
  --cream:     #F4ECE2;   /* primary text */
  --muted:     #A8978A;   /* secondary text */
  --faint:     #6E6055;   /* tertiary text */
  --green:     #4CAF6E;   /* success / paid */
  --red:       #E0533D;   /* danger / cancel */
  --blue:      #4F93D1;   /* info / dine-in */

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow: 0 8px 28px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.55);

  --sidebar-w: 240px;
}

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

html, body {
  height: 100%;
  font-family: 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--cream);
  overscroll-behavior: none;
}

body { overflow: hidden; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ───────── App shell ───────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ───────── Sidebar ───────── */
.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  z-index: 50;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 22px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: linear-gradient(135deg, var(--ember), var(--gold));
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 4px 14px rgba(232,101,30,0.35);
}
.brand-name { font-size: 16px; font-weight: 800; letter-spacing: -0.2px; }
.brand-sub  { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 14px; border-radius: var(--r-md);
  color: var(--muted); font-size: 15px; font-weight: 700;
  text-align: right; position: relative;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--cream); }
.nav-item.active { background: linear-gradient(135deg, rgba(232,101,30,0.18), rgba(232,176,75,0.08)); color: var(--ember-soft); }
.nav-item.active::before {
  content: ''; position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; background: var(--ember); border-radius: 3px;
}
.ni-icon { font-size: 19px; width: 22px; text-align: center; }
.ni-label { flex: 1; }
.ni-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--ember); color: #fff; font-size: 11px; font-weight: 800;
  display: none; align-items: center; justify-content: center;
}
.ni-badge.show { display: flex; }

.sidebar-foot { padding-top: 14px; border-top: 1px solid var(--line); }
.conn-pill {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 9px; border-radius: var(--r-sm); background: var(--surface-2);
}
.conn-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }

/* ───────── Topbar (mobile) ───────── */
.topbar {
  display: none;
  align-items: center; gap: 14px;
  padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.hamburger { font-size: 22px; color: var(--cream); width: 40px; height: 40px; border-radius: 10px; }
.hamburger:hover { background: var(--surface-2); }
.topbar-title { flex: 1; font-size: 17px; font-weight: 800; }
.topbar-clock { font-size: 13px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ───────── Content ───────── */
.content { overflow-y: auto; padding: 26px; height: 100vh; height: 100dvh; }

.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.view-title { font-size: 26px; font-weight: 900; letter-spacing: -0.5px; }
.view-title .sub { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 3px; letter-spacing: 0; }

/* ───────── Buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 800;
  transition: transform .1s, filter .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--ember); color: #fff; box-shadow: 0 4px 14px rgba(232,101,30,0.3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-2); color: var(--cream); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--line); }
.btn-danger { background: rgba(224,83,61,0.15); color: var(--red); border: 1px solid rgba(224,83,61,0.3); }
.btn-danger:hover { background: rgba(224,83,61,0.25); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ───────── Cards / generic ───────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; }

.field {
  width: 100%; padding: 13px 15px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--cream);
  font-size: 15px; font-weight: 600; transition: border-color .15s;
}
.field:focus { outline: none; border-color: var(--ember); }
.field::placeholder { color: var(--faint); }
select.field { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23A8978A' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 15px center; }
.field-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 7px; display: block; }
.field-row { margin-bottom: 15px; }

/* ───────── POS view ───────── */
.pos-grid { display: grid; grid-template-columns: 1fr 380px; gap: 22px; align-items: start; }

.pos-menu-side { min-width: 0; }
.cat-tabs { display: flex; gap: 9px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 6px; }
.cat-tab {
  white-space: nowrap; padding: 10px 18px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-weight: 700; font-size: 14px; flex-shrink: 0;
  transition: all .15s;
}
.cat-tab.active { background: var(--ember); color: #fff; border-color: var(--ember); }

.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 13px; }
.prod-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px; text-align: center; transition: transform .1s, border-color .15s;
  position: relative; overflow: hidden;
}
.prod-card:hover { border-color: var(--ember); transform: translateY(-2px); }
.prod-card:active { transform: scale(.97); }
.prod-emoji { font-size: 34px; margin-bottom: 8px; }
.prod-name { font-size: 14px; font-weight: 700; line-height: 1.3; margin-bottom: 5px; }
.prod-price { font-size: 13px; font-weight: 800; color: var(--ember-soft); }
.prod-card.out { opacity: .4; pointer-events: none; }
.prod-out-tag { position: absolute; top: 8px; left: 8px; font-size: 10px; background: var(--red); color: #fff; padding: 2px 7px; border-radius: 6px; font-weight: 700; }

/* Cart panel */
.cart-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  display: flex; flex-direction: column; position: sticky; top: 0;
  max-height: calc(100vh - 52px); overflow: hidden;
}
.cart-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.cart-head h3 { font-size: 17px; font-weight: 800; }
.cart-clear { font-size: 12px; color: var(--red); font-weight: 700; }
.cart-type-row { display: flex; gap: 7px; padding: 14px 20px 0; }
.ctype {
  flex: 1; padding: 9px; border-radius: var(--r-sm); background: var(--surface-2);
  border: 1px solid var(--line); color: var(--muted); font-weight: 700; font-size: 13px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.ctype.active { border-color: var(--ember); color: var(--ember-soft); background: rgba(232,101,30,0.1); }
.ctype .e { font-size: 17px; }

.cart-lines { flex: 1; overflow-y: auto; padding: 14px 20px; min-height: 120px; }
.cart-empty { text-align: center; color: var(--faint); padding: 40px 0; font-weight: 600; }
.cart-empty .e { font-size: 40px; display: block; margin-bottom: 10px; opacity: .5; }
.cline { display: flex; align-items: center; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.cline:last-child { border-bottom: none; }
.cl-emoji { font-size: 24px; width: 30px; text-align: center; }
.cl-mid { flex: 1; min-width: 0; }
.cl-name { font-size: 14px; font-weight: 700; }
.cl-price { font-size: 12px; color: var(--muted); font-weight: 600; }
.cl-step { display: flex; align-items: center; gap: 9px; background: var(--surface-2); border-radius: 9px; padding: 4px; }
.cl-step button { width: 26px; height: 26px; border-radius: 7px; background: var(--surface); font-size: 17px; font-weight: 800; color: var(--ember-soft); display: grid; place-items: center; }
.cl-step button:hover { background: var(--line); }
.cl-qty { font-size: 14px; font-weight: 800; min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; }

.cart-foot { padding: 16px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.cart-total-row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.cart-grand { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0 14px; }
.cart-grand .lbl { font-size: 15px; font-weight: 700; }
.cart-grand .amt { font-size: 24px; font-weight: 900; color: var(--ember-soft); }

/* ───────── Orders view ───────── */
.orders-toolbar { display: flex; gap: 9px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 4px; }
.filter-chip { white-space: nowrap; padding: 9px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 700; font-size: 13px; }
.filter-chip.active { background: var(--cream); color: var(--bg); border-color: var(--cream); }

.orders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 15px; }
.order-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; }
.oc-top { padding: 15px 17px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
.oc-id { font-size: 16px; font-weight: 900; }
.oc-meta { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.oc-status { font-size: 11px; font-weight: 800; padding: 5px 11px; border-radius: 20px; white-space: nowrap; }
.st-new      { background: rgba(232,176,75,0.16); color: var(--gold); }
.st-preparing{ background: rgba(79,147,209,0.16); color: var(--blue); }
.st-ready    { background: rgba(76,175,110,0.16); color: var(--green); }
.st-done     { background: rgba(168,151,138,0.14); color: var(--muted); }
.st-cancelled{ background: rgba(224,83,61,0.16); color: var(--red); }
.oc-body { padding: 13px 17px; flex: 1; }
.oc-line { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--cream); font-weight: 600; }
.oc-line .q { color: var(--ember-soft); font-weight: 800; }
.oc-foot { padding: 13px 17px; border-top: 1px solid var(--line); }
.oc-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 11px; }
.oc-total .amt { font-size: 19px; font-weight: 900; color: var(--ember-soft); }
.oc-actions { display: flex; gap: 7px; }
.oc-actions .btn { flex: 1; }
.oc-typetag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; color: var(--muted); margin-top: 5px; }

/* ───────── Tables view ───────── */
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 15px; }
.table-card { aspect-ratio: 1; border-radius: var(--r-lg); border: 2px solid var(--line); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; transition: all .15s; position: relative; }
.table-card:hover { transform: translateY(-3px); }
.table-card.free { border-color: var(--line); }
.table-card.busy { border-color: var(--ember); background: rgba(232,101,30,0.08); }
.table-card .t-num { font-size: 30px; font-weight: 900; }
.table-card .t-state { font-size: 13px; font-weight: 700; color: var(--muted); }
.table-card.busy .t-state { color: var(--ember-soft); }
.table-card .t-amount { font-size: 13px; font-weight: 800; color: var(--ember-soft); }
.table-card .t-icon { position: absolute; top: 12px; left: 12px; font-size: 16px; }

/* ───────── Menu management ───────── */
.menu-section { margin-bottom: 26px; }
.menu-sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.menu-sec-title { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 9px; }
.menu-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.menu-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; display: flex; align-items: center; gap: 13px; }
.mi-emoji { font-size: 28px; width: 38px; text-align: center; }
.mi-info { flex: 1; min-width: 0; }
.mi-name { font-size: 15px; font-weight: 700; }
.mi-price { font-size: 13px; color: var(--ember-soft); font-weight: 800; margin-top: 2px; }
.mi-actions { display: flex; gap: 6px; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; font-size: 15px; transition: background .15s; }
.icon-btn:hover { background: var(--line); }

/* ───────── Reports ───────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 15px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; top: -30px; left: -30px; width: 90px; height: 90px; border-radius: 50%; background: var(--accent, var(--ember)); opacity: .07; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 900; letter-spacing: -0.5px; }
.stat-sub { font-size: 12px; color: var(--faint); font-weight: 600; margin-top: 5px; }

.report-card { margin-bottom: 18px; }
.bar-row { display: flex; align-items: center; gap: 13px; margin-bottom: 12px; }
.bar-label { width: 100px; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.bar-track { flex: 1; height: 26px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--ember), var(--gold)); border-radius: 8px; transition: width .5s; display: flex; align-items: center; padding: 0 10px; }
.bar-val { font-size: 12px; font-weight: 800; color: #fff; white-space: nowrap; }

/* table list */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: right; padding: 11px 14px; font-size: 12px; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); }
.data-table td { padding: 13px 14px; font-size: 14px; font-weight: 600; border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: none; }

/* ───────── Settings ───────── */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; max-width: 900px; }

/* ───────── Modal ───────── */
.modal-host { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-host.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); }
.modal { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn .2s ease; }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { padding: 20px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 18px; font-weight: 800; }
.modal-close { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; font-size: 18px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }

.emoji-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.emoji-opt { aspect-ratio: 1; border-radius: 8px; background: var(--surface-2); font-size: 20px; display: grid; place-items: center; border: 2px solid transparent; }
.emoji-opt.sel { border-color: var(--ember); background: rgba(232,101,30,0.12); }

/* ───────── Toast ───────── */
.toast-host { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 9px; align-items: center; }
.toast { background: var(--cream); color: var(--bg); padding: 13px 22px; border-radius: var(--r-md); font-weight: 800; font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .25s ease; display: flex; align-items: center; gap: 9px; }
.toast.ok { background: var(--green); color: #fff; }
.toast.err { background: var(--red); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ───────── Empty state ───────── */
.empty-state { text-align: center; padding: 70px 20px; color: var(--faint); }
.empty-state .es-icon { font-size: 56px; margin-bottom: 16px; opacity: .5; }
.empty-state .es-title { font-size: 18px; font-weight: 800; color: var(--muted); margin-bottom: 7px; }
.empty-state .es-text { font-size: 14px; font-weight: 600; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 45; display: none; }
.scrim.show { display: block; }

/* ───────── Responsive ───────── */
@media (max-width: 1080px) {
  .pos-grid { grid-template-columns: 1fr; }
  .cart-panel { position: static; max-height: none; }
}

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; right: 0; width: 280px;
    transform: translateX(100%); transition: transform .25s ease;
  }
  .sidebar.open { transform: none; }
  .content { padding: 18px; height: auto; }
  .view-title { font-size: 22px; }
  .prod-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (max-width: 420px) {
  .content { padding: 14px; }
  .prod-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 24px; }
}
