:root {
  --bg: #f6f6f4; --surface: #fff; --line: #e6e4df; --ink: #1a1a1a; --muted: #6b6b66;
  --accent: #c8342f; --accent-ink: #fff; --good: #1f8a4c; --warn: #b7791f; --bad: #c8342f;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
}
:root[data-theme="dark"] {
  --bg: #141414; --surface: #1d1d1d; --line: #2e2e2e; --ink: #f2f2f0; --muted: #a2a29c;
  --accent: #ef5a54; --accent-ink: #1a1a1a; --good: #4cc27f; --warn: #e0a64a; --bad: #ef5a54;
  --shadow: none; color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 "Segoe UI", Tahoma, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.num { direction: ltr; unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }

/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 800; font-size: 18px; padding: 4px 10px 14px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.on { background: var(--ink); color: var(--bg); }
.side .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); }
.main { padding: 22px 26px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .grow { flex: 1; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 800; margin: 2px 0; }
.stat .sub { color: var(--muted); font-size: 13px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; min-height: 38px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; min-height: 38px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; margin-bottom: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 160px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
.scroll { overflow-x: auto; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--line); display: block; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.pill.s0, .pill.s1 { color: var(--warn); } .pill.s2, .pill.s3 { color: #3e8ef7; } .pill.s4 { color: var(--good); } .pill.s9 { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.bar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 3px; }
.bar i { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.bars.alt .bar i { background: #3e8ef7; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; direction: ltr; }
.hbar { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; min-width: 80px; }
.hbar i { display: block; height: 100%; background: var(--accent); }

/* modal / toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; z-index: 50; }
.sheet { background: var(--surface); border-radius: 16px; padding: 20px; width: 100%; max-width: 560px; border: 1px solid var(--line); }
.sheet.wide { max-width: 860px; }
.sheet .head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet .head h2 { margin: 0; flex: 1; }
.toast { position: fixed; bottom: 22px; inset-inline-start: 22px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; font-weight: 600; }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; display: grid; gap: 12px; }
.err { color: var(--bad); font-size: 14px; }

/* product form */
.imgs { display: flex; gap: 10px; flex-wrap: wrap; }
.imgbox { position: relative; width: 92px; }
.imgbox img { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; display: block; background: var(--line); }
.imgbox .x, .imgbox .first { position: absolute; top: 4px; inset-inline-start: 4px; }
.imgbox .first { top: auto; bottom: 4px; }
.vrow { display: grid; grid-template-columns: 1.2fr 1.2fr .8fr auto; gap: 8px; margin-bottom: 8px; }
.tag { font-size: 11px; background: var(--ink); color: var(--bg); border-radius: 6px; padding: 1px 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
  .brand { padding: 4px 8px; } .side .me { margin: 0; border: 0; padding: 0 8px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; width: 100%; order: 3; }
  .nav a { padding: 8px 10px; }
  .main { padding: 16px 12px 60px; }
  .vrow { grid-template-columns: 1fr 1fr; }
}

/* أدوات اللغة والثيم + فلتر القسم */
.tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.login .tools { margin: 0; }
select.sec { width: auto; min-width: 150px; font-weight: 700; }

/* بحث عام + شارة الطلبات الجديدة */
.gsearch { position: relative; margin-bottom: 16px; max-width: 560px; }
.gsr { position: absolute; inset-inline: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; z-index: 40; max-height: 60vh; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.gsr:empty { display: none; }
.gsr .gh { padding: 6px 12px; font-size: 12px; color: var(--muted); background: var(--bg); }
.gsr a { display: block; padding: 8px 12px; cursor: pointer; text-decoration: none; }
.gsr a:hover { background: var(--bg); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; margin-inline-start: 6px; }
.nav { overflow-y: auto; }
