@font-face {
  font-family: 'GESS';
  src: url('/fonts/gess-Medium.woff2') format('woff2');
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F;
}
@font-face {
  font-family: 'GESS';
  src: url('/fonts/gess-Bold.woff2') format('woff2');
  font-weight: 600 800;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F;
}

:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --sunk: #eef0ec;
  --line: #dfe2dc;
  --line-strong: #c9cdc5;
  --text: #19201c;
  --muted: #5f6a64;
  --accent: #0d6b4e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --radius: 6px;
  --nav-h: 62px;
  --top-h: 56px;
  --font: 'GESS', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #121614;
  --surface: #1a1f1c;
  --sunk: #222824;
  --line: #2e3531;
  --line-strong: #3d4540;
  --text: #e9ece9;
  --muted: #9aa49e;
  --accent: #3fb68b;
  --accent-ink: #0b1310;
  --accent-soft: #183229;
  --danger: #f0715f;
  --danger-soft: #3a1c18;
  --warn: #e3a64a;
  --warn-soft: #33270f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.35; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p { margin: 0; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.hidden { display: none !important; }
.danger-text { color: var(--danger); }
.warn-text { color: var(--warn); }
.ok-text { color: var(--accent); }

/* ---------- هيكل التطبيق ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top .brand { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { margin-inline-start: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.top .back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin-inline-start: -8px;
  border: 0; background: none; border-radius: var(--radius); cursor: pointer;
}
.layout { display: block; }
.main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; min-width: 0;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--accent); font-weight: 700; }
.side { display: none; }

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - var(--top-h)); }
  .nav { display: none; }
  .side {
    display: block; position: sticky; top: var(--top-h); align-self: start;
    height: calc(100vh - var(--top-h)); overflow-y: auto;
    padding: 12px 8px; border-inline-end: 1px solid var(--line); background: var(--surface);
  }
  .side a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: var(--radius); color: var(--text); font-size: 14px;
  }
  .side a svg { width: 18px; height: 18px; color: var(--muted); }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .side a.on svg { color: var(--accent); }
  .side .sep { height: 1px; background: var(--line); margin: 8px 12px; }
  .main { padding: 24px 28px 48px; width: 100%; }
}
@media (hover: hover) {
  .side a:hover:not(.on) { background: var(--sunk); }
  .btn:hover { filter: brightness(0.96); }
  .row-link:hover { background: var(--sunk); }
  .top .back:hover { background: var(--sunk); }
}

/* ---------- عناصر ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { flex: 1; min-width: 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.box + .box, .section + .section { margin-top: 16px; }
.box-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.box-head h2 { flex: 1; }
.box-body { padding: 16px; }
.section { margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field > span b { color: var(--danger); font-weight: 700; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); outline: none;
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.num-input { direction: ltr; text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex: 1 1 0; min-width: 72px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; text-align: center;
}
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* أرقام اللوحة */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .stats.six { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; border-bottom: 1px solid var(--line); border-inline-end: 1px solid var(--line); min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; direction: ltr; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v small { font-size: 12px; font-weight: 600; color: var(--muted); }
.stat a { color: inherit; display: block; }

/* قوائم */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.row-link, .row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 16px; color: var(--text);
}
.row-link .t, .row .t { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row-link .s, .row .s { grid-column: 1; font-size: 13px; color: var(--muted); min-width: 0; }
.row-link .e, .row .e { grid-row: 1 / span 2; grid-column: 2; text-align: left; direction: ltr; font-weight: 700; white-space: nowrap; }
.row-link .e small, .row .e small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; direction: rtl; text-align: left; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 600;
  background: var(--sunk); color: var(--muted); white-space: nowrap;
}
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }

/* جداول (كمبيوتر) */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--sunk); }
table.t td.n, table.t th.n { text-align: left; direction: ltr; }
table.t td.wrap { white-space: normal; min-width: 160px; }
table.t tr.link { cursor: pointer; }
@media (hover: hover) { table.t tr.link:hover td { background: var(--sunk); } }
.desk { display: none; }
@media (min-width: 760px) { .desk { display: block; } .mob { display: none; } }

/* أسطر الطلب */
.lines .line {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.lines .line:last-child { border-bottom: 0; }
.lines .line .nm { font-weight: 600; min-width: 0; }
.lines .line .meta { font-size: 13px; color: var(--muted); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.qty button { width: 40px; height: 40px; border: 0; background: var(--sunk); cursor: pointer; font-size: 18px; font-weight: 700; }
.qty input { width: 58px; height: 40px; border: 0; text-align: center; direction: ltr; background: var(--surface); outline: none; }
.qty.sm button { width: 34px; height: 36px; }
.qty.sm input { width: 46px; height: 36px; }

.picker { position: relative; }
.picker .results {
  position: absolute; inset-inline: 0; top: 100%; z-index: 15; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  max-height: 320px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.08);
}
.picker .results button {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: right;
  padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer;
}
.picker .results button:last-child { border-bottom: 0; }
.picker .results button .s { font-size: 12px; color: var(--muted); }
.picker .results button .e { grid-row: 1 / span 2; grid-column: 2; direction: ltr; font-size: 13px; color: var(--muted); align-self: center; }
@media (hover: hover) { .picker .results button:hover { background: var(--sunk); } }

.total-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--sunk); border-top: 1px solid var(--line);
}
.total-bar .v { font-size: 22px; font-weight: 700; direction: ltr; }

.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10;
  padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.alert { padding: 12px 14px; border-radius: var(--radius); font-size: 14px; border: 1px solid; margin-bottom: 14px; }
.alert.err { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert.ok { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert ul { margin: 6px 0 0; padding-inline-start: 18px; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 420px; margin: 0 auto; padding: 12px 16px; border-radius: var(--radius);
  background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
}
.toast.err { background: var(--danger); color: #fff; }

.bars { display: grid; gap: 6px; }
.bars .b { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bars .b .track { height: 10px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.bars .b .fill { height: 100%; background: var(--accent); }
.bars .b .v { direction: ltr; min-width: 80px; text-align: left; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 18px;
  background: var(--surface); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .input { flex: 1 1 200px; }
.pager { display: flex; gap: 8px; justify-content: center; padding: 12px; }

/* ---------- الشاشة العامة ---------- */
.public { min-height: 100vh; display: flex; flex-direction: column; }
.public header {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.public header .brand { font-weight: 700; flex: 1; }
.public main { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 32px 20px 48px; }
.public h1 { font-size: 24px; margin-bottom: 6px; }
.public .lead { color: var(--muted); margin-bottom: 20px; }
.search-big { display: flex; gap: 8px; }
.search-big .input { min-height: 54px; font-size: 18px; direction: ltr; text-align: right; }
.search-big .btn { min-height: 54px; padding: 0 20px; }
.result { margin-top: 20px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.result .code { direction: ltr; text-align: right; color: var(--muted); font-size: 14px; }
.result .name { font-size: 18px; font-weight: 700; margin: 2px 0 12px; }
.result .state { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.result .state .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.result.yes .state { color: var(--accent); } .result.yes .dot { background: var(--accent); }
.result.no .state { color: var(--danger); } .result.no .dot { background: var(--danger); }
.result .low { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.public footer { padding: 16px 20px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .box { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { margin-bottom: 4px; }
.login p { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

.more-list a { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: var(--text); border-bottom: 1px solid var(--line); }
.more-list a:last-child { border-bottom: 0; }
.more-list a svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.more-list a .arrow { margin-inline-start: auto; width: 16px; height: 16px; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.progress { height: 8px; background: var(--sunk); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
