/* جَرْد — هوية بصرية بسيطة: حبر داكن، أخضر زمردي للوارد والربح، كهرماني للتنبيه، أحمر للسالب. */
:root {
  --ink: #0F172A;
  --brand: #0E7C66;
  --brand-soft: #E6F2EE;
  --brand-dark: #0A5C4C;
  --amber: #B45309;
  --amber-soft: #FEF3C7;
  --red: #B91C1C;
  --red-soft: #FEE2E2;
  --bg: #FAF9F7;
  --card: #FFFFFF;
  --line: #E7E5E1;
  --muted: #6B7280;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  --tab-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Cairo', 'Segoe UI', Tahoma, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--brand); }

.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- الهيكل ---------- */
.app { max-width: 760px; margin: 0 auto; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--brand); color: #fff;
  box-shadow: 0 2px 12px rgba(14,124,102,.25);
}
.topbar .logo { width: 34px; height: 34px; flex: none; }
.topbar h1 { font-size: 19px; font-weight: 900; margin: 0; letter-spacing: .5px; }
.topbar .sub { font-size: 12px; opacity: .85; margin: 0; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; text-align: left; opacity: .95; }
.icon-btn { color: #fff; padding: 8px; border-radius: 10px; font-size: 13px; background: rgba(255,255,255,.16); }

.page { padding: 14px 14px 20px; }

/* ---------- بطاقات الملخّص ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 900; margin-top: 2px; }
.stat.good .value { color: var(--brand); }
.stat.warn .value { color: var(--amber); }
.stat.bad  .value { color: var(--red); }

/* ---------- الأزرار الكبيرة ---------- */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 18px 12px; border-radius: var(--radius); font-size: 19px; font-weight: 900; color: #fff;
  box-shadow: var(--shadow);
}
.big-btn.in  { background: var(--brand); }
.big-btn.out { background: var(--ink); }
.big-btn:active { transform: translateY(1px); }

/* ---------- البحث ---------- */
.search { position: relative; margin-bottom: 12px; }
.search input {
  width: 100%; padding: 13px 42px 13px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); outline: none;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search .ico { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- القوائم ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: start; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg); }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 700; font-size: 16px; }
.row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row .qty { font-size: 24px; font-weight: 900; min-width: 56px; text-align: center; }
.row .qty small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.qty.ok  { color: var(--brand); }
.qty.low { color: var(--amber); }
.qty.neg { color: var(--red); }
.qty.zero { color: var(--muted); }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.tag.in  { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }
.tag.out { background: #EEF2FF; color: #3730A3; border-color: transparent; }
.tag.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.tag.bad { background: var(--red-soft); color: var(--red); border-color: transparent; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 700; background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.pos { color: var(--brand); font-weight: 700; }
td.neg { color: var(--red); font-weight: 700; }

/* ---------- شريط التبويب ---------- */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 760px; margin: 0 auto;
}
.tabs button {
  flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 700; color: var(--muted);
}
.tabs button.on { color: var(--brand); }
.tabs svg { width: 22px; height: 22px; }

/* ---------- النوافذ السفلية ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.45); display: flex; align-items: flex-end; justify-content: center; }
/* لازم يفضل قبل أي display تاني: خاصية hidden لوحدها بتتغلب منها،
   فالنافذة كانت بتفضل شفافة فوق الشاشة كلها وتبلع كل ضغطة وكل حرف. */
.sheet-wrap[hidden], .toast[hidden] { display: none !important; }
.sheet {
  background: var(--card); width: 100%; max-width: 760px;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5 } to { transform: none; opacity: 1 } }
.sheet .grab { width: 42px; height: 4px; background: var(--line); border-radius: 4px; margin: 6px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 20px; font-weight: 900; }
.sheet .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field input.big { font-size: 24px; font-weight: 900; text-align: center; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 5px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { width: 100%; padding: 15px; border-radius: 12px; font-weight: 900; font-size: 17px; background: var(--brand); color: #fff; }
.btn.dark { background: var(--ink); color: var(--bg); }
.btn.ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-size: 15px; padding: 12px; }
.btn.danger { background: var(--red); }
.btn[disabled] { opacity: .55; }

.total-line { background: var(--brand-soft); color: var(--brand-dark); border-radius: 12px; padding: 12px 14px; font-weight: 900; display: flex; justify-content: space-between; margin-bottom: 12px; }

/* ---------- الدخول ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .brand { text-align: center; margin-bottom: 26px; }
.login .brand svg { width: 78px; height: 78px; }
.login .brand h1 { font-size: 34px; font-weight: 900; margin: 10px 0 2px; letter-spacing: 2px; }
.login .brand p { color: var(--muted); margin: 0; font-size: 14px; }
.login .card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }
.error { background: var(--red-soft); color: var(--red); padding: 11px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 12px; font-weight: 600; }

/* ---------- التنبيهات ---------- */
.toast {
  position: fixed; bottom: calc(var(--tab-h) + 16px); inset-inline: 16px; z-index: 90;
  max-width: 460px; margin: 0 auto; padding: 13px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 700; text-align: center;
  box-shadow: 0 10px 30px rgba(15,23,42,.3);
}
.toast.ok { background: var(--brand); }
.toast.err { background: var(--red); }

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #F1F5F9; --bg: #0B1220; --card: #131C2E; --line: #24304A; --muted: #94A3B8;
    --brand-soft: #10352C; --brand-dark: #6EE7B7; --amber-soft: #3A2A08; --red-soft: #3A1414;
    --amber: #FBBF24; --red: #F87171;
  }
  .big-btn.out { background: #24304A; }
  .tag.out { background: #1E1B4B; color: #C7D2FE; }
}
