:root {
  --red: #94100f;
  --red-500: #b01a19;
  --red-700: #6a0a0a;
  --red-100: #f6dcdc;
  --red-50: #fcf1f1;
  --ink: #241819;
  --muted: #7b6b6c;
  --line: #ecdfdf;
  --bg: #fbf7f7;
  --card: #fff;
  --ok: #1d7a46;
  --ok-bg: #e6f4ec;
  --warn: #a15c07;
  --warn-bg: #fdf1dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(80, 10, 10, .06), 0 10px 28px rgba(80, 10, 10, .07);
  --font: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  --ctl: 44px; /* ارتفاع موحّد لكل الأزرار وخانات الإدخال والقوائم */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55;
  color: var(--ink); background: var(--bg);
}
img { max-width: 100%; }
a { color: var(--red); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.print-only { display: none; }
.muted { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- الهيكل ---------- */
.app { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 22px 16px 16px; color: #fff; overflow-y: auto;
  background:
    radial-gradient(circle at 100% 0%, rgba(255, 255, 255, .10), transparent 45%),
    linear-gradient(180deg, var(--red) 0%, var(--red-700) 100%);
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 4px 6px 14px; border-bottom: 1px solid rgba(255, 255, 255, .18); }
.brand-logo { flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 800; font-size: 19px; }
.brand-sub { font-size: 12px; opacity: .8; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  color: rgba(255, 255, 255, .88); font-weight: 600; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .13); color: #fff; }
.nav a.active { background: #fff; color: var(--red); box-shadow: 0 6px 16px rgba(0, 0, 0, .18); }
.nav-sep { height: 1px; background: rgba(255, 255, 255, .15); margin: 8px 6px; }

.side-foot { margin-top: auto; }
.feed-card { background: rgba(255, 255, 255, .10); border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.feed-label { font-size: 12px; opacity: .8; }
.feed-card strong { font-size: 14px; direction: ltr; text-align: right; }
.feed-card small { font-size: 11px; opacity: .7; line-height: 1.4; }

.user-card { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 6px; margin-bottom: 12px; background: rgba(255, 255, 255, .10); border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px; }
.user-card .btn-icon { width: 34px; height: 34px; color: #fff; }
.user-card .btn-icon:hover { background: #fff; color: var(--red); }
.user-avatar { flex: none; width: 38px; height: 38px; margin-inline-start: 4px; border-radius: 50%; background: #fff; color: var(--red); font-weight: 800; display: grid; place-items: center; }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.user-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.user-meta small { opacity: .8; font-size: 12px; }

/* ---------- شاشة الدخول ---------- */
body.logged-out { background: linear-gradient(135deg, var(--red) 0%, var(--red-700) 100%); background-attachment: fixed; }
body.logged-out .sidebar, body.logged-out .mobile-bar { display: none; }
body.logged-out .app { display: block; }
.auth-wrap { min-height: calc(100vh - 56px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); background: #fff; border-radius: 22px; padding: 30px 30px 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); animation: pop .25s; }
.auth-logo { width: 112px; height: 112px; margin: -66px auto 10px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
.auth-title { text-align: center; font-size: 24px; font-weight: 800; color: var(--red-700); margin-bottom: 4px; }
.auth-err { min-height: 20px; color: var(--red); font-weight: 700; font-size: 14px; }
body.logged-out .page { padding-top: 90px; }

.main { min-width: 0; }
.page { padding: 28px 32px 48px; max-width: 1480px; margin: 0 auto; }
.mobile-bar { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-title { font-size: 27px; font-weight: 800; color: var(--red-700); line-height: 1.25; }
.page-sub { color: var(--muted); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.back-link:hover { color: var(--red); }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--ctl); padding: 0 18px;
  border: 1.5px solid transparent; border-radius: 11px; font-weight: 700; cursor: pointer;
  background: none; white-space: nowrap; transition: transform .08s, background .15s, box-shadow .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 6px 16px rgba(148, 16, 15, .28); }
.btn-primary:hover:not(:disabled) { background: var(--red-500); }
/* زر ثانوي واحد (outline و ghost شكلهما واحد) حتى لا يختلف تصميم الأزرار من صفحة لأخرى */
.btn-outline, .btn-ghost { color: var(--red-700); border-color: #e4d2d2; background: #fff; }
.btn-outline:hover:not(:disabled), .btn-ghost:hover:not(:disabled) { color: var(--red); border-color: var(--red-100); background: var(--red-50); }
.btn-white { background: #fff; color: var(--red); }
.btn-white:hover:not(:disabled) { background: var(--red-50); }
.btn-danger { color: var(--red); border-color: var(--red-100); background: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; color: inherit; }
.btn-icon:hover { background: var(--red-50); color: var(--red); }
.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }
.ico { display: inline-flex; flex: none; vertical-align: middle; }
.ico svg { display: block; }

/* ---------- بطاقات ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-title { font-weight: 800; font-size: 17px; color: var(--red-700); }
.card-body { padding: 18px 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); overflow: hidden; }
.tile::before { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: var(--red-100); }
.tile-label { color: var(--muted); font-weight: 600; font-size: 13px; }
.tile-value { font-size: 32px; font-weight: 800; color: var(--red-700); line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); }
.tile.accent { background: linear-gradient(135deg, var(--red), var(--red-700)); border: 0; color: #fff; }
.tile.accent::before { background: rgba(255, 255, 255, .35); }
.tile.accent .tile-label, .tile.accent .tile-sub { color: rgba(255, 255, 255, .8); }
.tile.accent .tile-value { color: #fff; }

/* ---------- نماذج ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-weight: 700; font-size: 13px; color: var(--red-700); }
.input, .select, .textarea {
  width: 100%; padding: 10px 14px; background: #fff; border: 1.5px solid var(--line); border-radius: 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input, .select { height: var(--ctl); padding-top: 0; padding-bottom: 0; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--red); box-shadow: 0 0 0 4px rgba(148, 16, 15, .10); }
.textarea { resize: vertical; min-height: 78px; }
/* القائمة المنسدلة: سهم موحّد بدل سهم المتصفح (كان يغطي النص) */
.select {
  appearance: none; -webkit-appearance: none; cursor: pointer; text-overflow: ellipsis;
  padding-inline-end: 40px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237b6b6c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat left 14px center;
}
.select:disabled { background-color: #f6f0f0; cursor: not-allowed; }
/* خانة التاريخ بنفس شكل باقي الخانات، والتاريخ يُقرأ من اليسار لليمين */
.input[type=date] { direction: ltr; text-align: right; }
.input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .65; }
.input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-grid .span-all { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; }
.check input[type=checkbox], .check input[type=radio] { width: 20px; height: 20px; accent-color: var(--red); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 300px; max-width: 520px; }
.search .ico { position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-inline-start: 42px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; color: var(--muted); font-weight: 700; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--red-100); color: var(--red); }
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }
.seg { display: inline-flex; background: var(--red-50); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 18px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--red); color: #fff; box-shadow: 0 4px 12px rgba(148, 16, 15, .25); }

/* ---------- جداول ---------- */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
.table-wrap.scroll { max-height: 66vh; }
.card > .table-wrap { border: 0; box-shadow: none; border-radius: 0 0 var(--radius) var(--radius); }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--red-50); color: var(--red-700); font-weight: 800; font-size: 13px;
  text-align: start; padding: 11px 14px; border-bottom: 2px solid var(--red-100); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fffafa; }
.table tr.row-click { cursor: pointer; }
.table tr.row-click:hover { background: var(--red-50); }
.table tfoot td { background: var(--red-50); font-weight: 800; color: var(--red-700); border-top: 2px solid var(--red-100); }
.table .num, .table th.num { text-align: center; font-variant-numeric: tabular-nums; }
.table .code { font-family: Consolas, 'Courier New', monospace; font-size: 13px; color: var(--muted); direction: ltr; text-align: right; white-space: nowrap; }
.table .pname { min-width: 170px; }
.table tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--red-100); } to { background: transparent; } }
.sub-row td { background: #fffafa; padding-block: 6px; }

.qty-pill { display: inline-block; min-width: 38px; padding: 2px 10px; border-radius: 999px; font-weight: 800; background: var(--red-50); color: var(--red-700); }
.qty-pill.zero { background: #f3eded; color: var(--muted); }
.qty-pill.neg { background: var(--red); color: #fff; }
.qty-pill.good { background: var(--ok-bg); color: var(--ok); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 11px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge-out { background: var(--red-100); color: var(--red-700); }
.badge-in { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: #eee7e7; color: var(--muted); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
tr.cancelled td { opacity: .55; }
tr.cancelled .strike { text-decoration: line-through; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ico { color: var(--red-100); margin-bottom: 8px; }
.empty h3 { color: var(--red-700); font-size: 18px; margin-bottom: 6px; }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; }
.banner-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f1d6a0; }
.banner-red { background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); }

/* ---------- الموردين ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.supplier-card { display: block; color: inherit; padding: 18px; cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.supplier-card:hover { transform: translateY(-3px); border-color: var(--red-100); box-shadow: 0 14px 34px rgba(80, 10, 10, .13); }
.supplier-card.off { opacity: .65; }
.sc-top { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 14px; background: linear-gradient(135deg, var(--red), var(--red-700)); color: #fff; font-weight: 800; font-size: 20px; display: grid; place-items: center; }
.avatar.lg { width: 72px; height: 72px; border-radius: 20px; font-size: 32px; }
.sc-name { font-weight: 800; font-size: 17px; line-height: 1.3; }
.sc-phone { color: var(--muted); font-size: 13px; direction: ltr; text-align: right; }
.sc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sc-stat { background: var(--red-50); border-radius: 11px; padding: 8px 12px; }
.sc-stat b { display: block; font-size: 22px; color: var(--red-700); line-height: 1.2; }
.sc-stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.sc-foot { margin-top: 12px; font-size: 12px; color: var(--muted); }

.profile-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; padding: 22px; }
.profile-info { flex: 1 1 280px; min-width: 0; }
.profile-info h1 { font-size: 26px; font-weight: 800; color: var(--red-700); }
.kv { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 6px; color: var(--muted); }
.kv span { display: inline-flex; align-items: center; gap: 6px; }

.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tab { padding: 10px 20px; border: 0; background: none; font-weight: 800; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab:hover { color: var(--red); }
.tab.active { color: var(--red); border-bottom-color: var(--red); }

.bar-row { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; gap: 12px; align-items: center; padding: 8px 0; }
.bar-row a { font-weight: 700; color: var(--ink); }
.bar-track { height: 10px; border-radius: 999px; background: var(--red-50); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--red-500), var(--red)); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row small { color: var(--muted); display: block; }

/* ---------- صفحة التحويل ---------- */
.transfer-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.picker { position: relative; }
.picker .input { font-size: 17px; height: 56px; padding: 0 16px; padding-inline-start: 48px; border-color: var(--red-100); }
.picker .ico { position: absolute; inset-inline-start: 15px; top: 50%; transform: translateY(-50%); color: var(--red); }
.results { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; max-height: 330px; overflow-y: auto; }
.result { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.result:hover, .result.active { background: var(--red-50); }
.result.disabled { opacity: .45; cursor: not-allowed; }
.result .r-name { font-weight: 600; }
.result .r-code { font-family: Consolas, monospace; font-size: 12px; color: var(--muted); direction: ltr; text-align: right; }
.note-cell { min-width: 190px; }
.note-input { width: 100%; height: 38px; padding: 0 10px; font-size: 14px; }
@media screen and (max-width: 700px) { table.table td.note-cell { min-width: 0; } table.table td.note-cell .note-input { flex: 1; width: auto; min-width: 0; font-size: 16px; } }
.qty-input { width: 84px; height: 38px; text-align: center; padding: 0 8px; font-weight: 800; }
.summary-box { position: sticky; top: 20px; }
.sum-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.sum-big { font-size: 38px; font-weight: 800; color: var(--red); line-height: 1.1; }
.reason-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- سند / جرد ---------- */
.doc { padding: 28px 32px; }
.doc-head { display: flex; align-items: center; gap: 18px; padding-bottom: 18px; border-bottom: 3px solid var(--red); margin-bottom: 18px; }
.doc-logo { width: 74px; height: 74px; object-fit: contain; }
.doc-title { font-size: 24px; font-weight: 800; color: var(--red-700); }
.doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 24px; margin-bottom: 20px; }
.doc-meta div span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.doc-meta div b { font-size: 15px; }
.sign-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; margin-top: 56px; text-align: center; color: var(--muted); font-weight: 700; }
.sign-row div { border-top: 1.5px solid var(--ink); padding-top: 8px; }
.stamp-cancelled { display: inline-block; border: 3px solid var(--red); color: var(--red); font-weight: 800; padding: 2px 16px; border-radius: 10px; transform: rotate(-4deg); font-size: 18px; }

.stk-input { width: 92px; height: 38px; text-align: center; padding: 0 8px; font-weight: 800; }
.diff-neg { color: var(--red); font-weight: 800; }
.diff-pos { color: var(--warn); font-weight: 800; }
.diff-zero { color: var(--ok); font-weight: 800; }
.stk-bar { position: sticky; bottom: 12px; z-index: 5; display: flex; gap: 22px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-top: 16px; padding: 12px 18px; background: #fff; border: 1.5px solid var(--red-100); border-radius: 14px; box-shadow: 0 12px 34px rgba(80, 10, 10, .18); }
.stk-bar .stat b { font-size: 20px; color: var(--red-700); margin-inline-start: 4px; }

/* ---------- نوافذ ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(36, 24, 25, .55); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { width: min(560px, 100%); max-height: 92vh; display: flex; flex-direction: column; background: #fff; border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); animation: pop .18s; }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; background: linear-gradient(135deg, var(--red), var(--red-700)); color: #fff; }
.modal-head h3 { font-size: 18px; font-weight: 800; }
.modal-head .btn-icon:hover { background: rgba(255, 255, 255, .18); color: #fff; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-start; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--red-50); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }

#toasts { position: fixed; bottom: 22px; left: 22px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 14px 34px rgba(0, 0, 0, .3); animation: pop .2s; border-inline-start: 5px solid var(--ok); }
.toast.error { border-inline-start-color: #ff6b6b; background: var(--red-700); }

.loading { display: grid; place-items: center; padding: 90px 0; color: var(--red); }
.loading .ico svg { animation: spin 1s linear infinite; }

/* ---------- موبايل ---------- */
@media screen and (max-width: 1000px) {
  .transfer-grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .summary-box { position: static; }
}
@media screen and (max-width: 900px) {
  .app { display: block; }
  .sidebar { position: fixed; z-index: 60; inset-block: 0; inset-inline-start: 0; width: 280px; transform: translateX(100%); transition: transform .22s; }
  .sidebar.open { transform: none; box-shadow: -20px 0 60px rgba(0, 0, 0, .4); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--red); color: #fff; position: sticky; top: 0; z-index: 40; }
  .mobile-bar .btn-icon:hover { background: rgba(255, 255, 255, .15); color: #fff; }
  .mobile-logo { width: 38px; height: 38px; border-radius: 50%; }
  .page { padding: 18px 14px 40px; }
  .page-title { font-size: 22px; }
  .doc { padding: 18px; }
}

/* ---------- الطباعة ---------- */
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .mobile-bar, .no-print, .toolbar, .page-actions, .tabs, .stk-bar, .back-link, #toasts, .modal-overlay { display: none !important; }
  .app { display: block; }
  .page { padding: 0; max-width: none; }
  .print-only { display: block !important; }
  .card, .table-wrap, .tile { box-shadow: none !important; border-color: #cbbcbc; }
  .card.doc { border: 0; padding: 0; }
  .table-wrap, .table-wrap.scroll { max-height: none !important; overflow: visible !important; }
  .table th { position: static; background: var(--red) !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; border-color: var(--red); }
  .table tfoot td, .tile, .qty-pill, .badge, .avatar, .sc-stat { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table td { padding: 6px 10px; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }
  .tile.accent { background: var(--red) !important; }
  .stk-input { color: transparent; border: 1px solid #555; border-radius: 3px; background: #fff; }
  body.blank-sheet .stk-sheet td { height: 30px; }
  .sign-row { margin-top: 36px; }
  .p-hide { display: none !important; }
  .panel[hidden] { display: block !important; }
}

.print-head { align-items: center; gap: 16px; padding-bottom: 10px; margin-bottom: 14px; border-bottom: 3px solid var(--red); }
@media print { .print-head { display: flex !important; } }
.print-head img { width: 62px; height: 62px; object-fit: contain; }
.print-head h2 { color: var(--red-700); font-size: 20px; }
.print-head p { color: var(--muted); font-size: 12px; }

/* ---------- الكاميرا والمسح ---------- */
/* ---------- شريط الفلاتر ---------- */
.filters { display: flex; flex-direction: column; gap: 14px; padding: 16px; margin-bottom: 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.filters-row .search { flex: 1 1 280px; max-width: 460px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.filters-foot { color: var(--muted); font-weight: 700; }
.toolbar .select { width: auto; min-width: 170px; }

/* ---------- أزرار الصف (عرض / تعديل / حذف) ---------- */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1.5px solid #e4d2d2; border-radius: 10px; background: #fff; color: var(--red-700); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.icon-btn:hover { background: var(--red-50); color: var(--red); border-color: var(--red-100); }
.icon-btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- زر الانتقال لنظام آخر في القائمة ---------- */
.nav a.nav-ext { margin-top: 2px; border: 1.5px solid rgba(255, 255, 255, .38); }
.nav a.nav-ext .ico:last-child { margin-inline-start: auto; opacity: .8; }
.nav a.nav-ext:hover { background: #fff; color: var(--red); }

.search-row { display: flex; gap: 8px; flex: 1 1 300px; max-width: 520px; }
.search-row .search { flex: 1; max-width: none; min-width: 0; }
.btn-cam { flex: none; padding: 0 16px; }
.picker-row { display: flex; gap: 10px; align-items: stretch; }
.picker-row .picker { flex: 1; min-width: 0; }
.btn-cam-lg { padding: 0 20px; font-size: 16px; }
.picker-row .btn-cam { height: 56px; } /* بنفس ارتفاع خانة البحث الكبيرة */

.cart-foot { display: flex; flex-direction: column; gap: 12px; padding: 14px 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.cart-sums { display: flex; gap: 32px; align-items: flex-end; }
.cart-sums b { font-size: 26px; color: var(--red-700); line-height: 1.2; }
.cart-foot .sum-big { font-size: 34px; }

.transfer-grid > *, .stack > *, .field, .grid-2 > * { min-width: 0; }
.steps { margin: 0; padding-inline-start: 22px; display: grid; gap: 8px; }
#banner:empty { display: none; }
#banner .banner { margin: 14px 14px 0; align-items: center; }
.scrim { position: fixed; inset: 0; z-index: 55; background: rgba(36, 24, 25, .55); }

body.scanning { overflow: hidden; }
.scanner { position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; background: #000; color: #fff; touch-action: manipulation; }
.scan-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: linear-gradient(135deg, var(--red), var(--red-700)); font-size: 17px; }
.scan-top .btn-icon { color: #fff; }
.scan-top .btn-icon:hover { background: rgba(255, 255, 255, .18); color: #fff; }
.scan-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #111; }
.scan-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset-inline: 7%; top: 50%; height: min(34%, 230px); transform: translateY(-50%); border: 2px solid rgba(255, 255, 255, .75); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
.scan-frame::after { content: ''; position: absolute; inset-inline: 5%; top: 12%; height: 3px; border-radius: 3px; background: #ff3b3b; box-shadow: 0 0 14px 3px rgba(255, 59, 59, .8); animation: scanline 1.7s ease-in-out infinite alternate; }
@keyframes scanline { to { top: 86%; } }
.scan-flash { position: absolute; inset: 0; background: rgba(52, 211, 120, .45); opacity: 0; pointer-events: none; }
.scan-flash.on { animation: scanflash .4s ease-out; }
@keyframes scanflash { from { opacity: 1; } to { opacity: 0; } }
.scan-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 28px; text-align: center; line-height: 1.7; background: #1a0f10; }
.scan-msg .ico { color: var(--red-100); }
.scan-status { min-height: 58px; padding: 12px 16px; display: grid; place-items: center; text-align: center; font-weight: 700; background: #1a0f10; color: #e9dede; }
.scan-status.ok { color: #8ff0b3; }
.scan-status.err { color: #ffb3b3; }
.scan-actions { display: flex; justify-content: center; gap: 12px; padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: #1a0f10; }
.scan-round { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 76px; padding: 10px 12px; border: 0; border-radius: 16px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; }
.scan-round.on { background: #fff; color: var(--red); }

@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

@media (pointer: coarse) {
  * { -webkit-tap-highlight-color: rgba(148, 16, 15, .15); }
  .btn-icon { width: 44px; height: 44px; }
  .chip { padding: 9px 16px; }
  .tab { padding: 12px 16px; }
  .nav a { padding: 13px 14px; }
  .result { padding: 13px 14px; }
}

/* ---------- الهاتف (كل الصفحات) ---------- */
@media screen and (max-width: 700px) {
  .page-head { margin-bottom: 16px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
  .tile { padding: 12px 14px; }
  .tile-value { font-size: 26px; }
  .tile.accent { grid-column: 1 / -1; }
  .card-head { padding: 14px 16px; }
  .card-body { padding: 14px 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .profile-head { padding: 16px; gap: 14px; }
  .profile-info h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }

  /* نماذج: 16px يمنع تكبير الصفحة تلقائياً في آيفون */
  :root { --ctl: 46px; }
  .input, .select, .textarea { font-size: 16px; }
  .btn-sm { height: 40px; }

  .toolbar { gap: 10px; }
  .toolbar .search, .toolbar .search-row { flex: 1 1 100%; max-width: none; }
  .toolbar .select { flex: 1 1 140px; width: auto !important; }
  .toolbar > .btn-primary { flex: 1 1 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 4px; }
  .chip { flex: none; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }

  /* صفحة التحويل: بيانات السند أولاً ثم المسح، وشريط الحفظ ثابت أسفل الشاشة */
  .transfer-grid > .side-card { order: -1; }
  .reason-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .reason-chips .chip { flex: none; }
  .results { max-height: 45vh; }
  .qty-input { width: 100px; height: 44px; }
  .stk-input { width: 110px; height: 44px; }
  .note-input { height: 44px; }
  .cart-foot { position: sticky; bottom: 0; z-index: 30; margin-inline: -14px; border-inline: 0; border-radius: 18px 18px 0 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(80, 10, 10, .18); }
  .cart-foot .hint { flex: 1 1 100%; order: -1; }
  .cart-foot .hint:empty { display: none; }
  .cart-sums { gap: 18px; }
  .cart-sums b { font-size: 20px; }
  .cart-foot .sum-big { font-size: 24px; }
  .cart-foot .tile-label { font-size: 11px; }
  .cart-foot .btn-block { flex: 1 1 170px; width: auto; padding: 0 14px; }
  .stk-bar { bottom: 8px; padding: 10px 14px; gap: 10px; }

  .doc { padding: 14px; }
  .doc-head { flex-wrap: wrap; gap: 12px; }
  .doc-title { font-size: 20px; }
  .sign-row { gap: 10px; font-size: 12px; }

  /* النوافذ تظهر كورقة من أسفل الشاشة */
  .modal-overlay { place-items: end center; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; animation: sheet .22s ease-out; }
  .modal-foot { flex-wrap: wrap; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 40%; }
  #toasts { left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
  .auth-card { padding: 28px 20px 22px; }

  /* الجداول تتحول لبطاقات: كل صف بطاقة، وكل خلية "العنوان: القيمة" */
  .table-wrap:not(.keep) { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .table-wrap.scroll:not(.keep) { max-height: none; }
  .card > .table-wrap:not(.keep) { padding: 0 12px 4px; }
  table.table:not(.no-cards), table.table:not(.no-cards) tbody, table.table:not(.no-cards) tfoot,
  table.table:not(.no-cards) tr, table.table:not(.no-cards) td { display: block; }
  table.table:not(.no-cards) thead { display: none; }
  table.table:not(.no-cards) tr { margin-bottom: 12px; padding: 4px 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
  table.table:not(.no-cards) tfoot tr { background: var(--red-50); }
  table.table:not(.no-cards) td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0; border-bottom: 1px dashed var(--line); text-align: end; background: transparent; }
  table.table:not(.no-cards) tr td:last-child, table.table:not(.no-cards) tbody tr:last-child td:last-child { border-bottom: 0; }
  table.table:not(.no-cards) tfoot td { border-top: 0; }
  table.table:not(.no-cards) td::before { content: attr(data-label); flex: none; color: var(--muted); font-weight: 700; font-size: 13px; text-align: start; }
  table.table:not(.no-cards) td[data-label=""]::before { display: none; }
  table.table:not(.no-cards) td[data-label=""] { justify-content: center; }
  table.table:not(.no-cards) td[data-label="#"] { display: none; }
  table.table:not(.no-cards) td.pname { display: block; min-width: 0; padding-top: 10px; font-weight: 700; text-align: start; }
  table.table:not(.no-cards) td.pname::before { display: none; }
  table.table:not(.no-cards) td .empty { padding: 28px 8px; }
}

/* ---------- بطاقة السند المضغوطة على الهاتف ---------- */
@media screen and (max-width: 700px) {
  table.table.transfers-table:not(.no-cards) tbody tr {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 12px; padding: 12px 14px;
    grid-template-areas: "id status" "who type" "reason reason" "date qty" "act act";
  }
  table.table.transfers-table:not(.no-cards) td { display: block; padding: 0; border: 0; text-align: start; }
  table.table.transfers-table:not(.no-cards) td::before { display: none; }
  table.table.transfers-table:not(.no-cards) td:only-child { grid-column: 1 / -1; }
  .transfers-table td[data-label="رقم السند"] { grid-area: id; font-weight: 800; color: var(--red); text-align: start; }
  .transfers-table td[data-label="الحالة"] { grid-area: status; justify-self: end; }
  .transfers-table td[data-label="المورد"] { grid-area: who; font-size: 16px; }
  .transfers-table td[data-label="النوع"] { grid-area: type; justify-self: end; }
  .transfers-table.is-profile td[data-label="النوع"] { grid-area: who; justify-self: start; }
  .transfers-table td[data-label="السبب"] { grid-area: reason; color: var(--muted); padding-top: 2px; }
  .transfers-table td[data-label="التاريخ"] { grid-area: date; font-size: 13px; color: var(--muted); }
  .transfers-table td[data-label="الأجهزة"] { grid-area: qty; justify-self: end; font-weight: 800; text-align: end; }
  table.table.transfers-table:not(.no-cards) td[data-label="الأجهزة"]::before { display: inline; margin-inline-end: 6px; font-size: 12px; }
  .transfers-table td[data-label="الأصناف"], .transfers-table td[data-label="بواسطة"] { display: none !important; }
  table.table.transfers-table:not(.no-cards) td:last-child:not(:only-child) { grid-area: act; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
  .transfers-table .row-actions { justify-content: flex-start; }
}
@media screen and (max-width: 700px) {
  table.table.transfers-table:not(.no-cards) td.code { direction: rtl; text-align: start; font-family: var(--font); font-size: 15px; }
}

#updateBanner:empty { display: none; }
#updateBanner .banner { margin: 14px 14px 0; align-items: center; }

/* خانة الكمية بجانب زر الإرجاع في جدول السند */
.ret-box { display: flex; gap: 8px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.ret-qty { width: 72px; height: 36px; padding: 0 6px; text-align: center; font-weight: 800; }
@media screen and (max-width: 700px) { .ret-box { justify-content: flex-start; } .ret-qty { width: 88px; height: 40px; } }

/* ---------- الملاحظات ---------- */
.note-card { margin-bottom: 18px; padding: 12px 16px; background: var(--red-50); border: 1px solid var(--red-100); border-inline-start: 4px solid var(--red); border-radius: 12px; }
.note-card.compact { margin: 10px 0 0; padding: 8px 14px; }
.note-title { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--red-700); font-size: 13px; font-weight: 800; }
.notes { display: flex; flex-direction: column; gap: 6px; line-height: 1.7; }
.notes-row { display: flex; align-items: baseline; gap: 10px; }
.notes-text { min-width: 0; overflow-wrap: anywhere; }
.notes-qty { flex: none; min-width: 34px; padding: 0 9px; text-align: center; background: #fff; border: 1px solid var(--red-100); border-radius: 999px; color: var(--red-700); font-weight: 800; font-variant-numeric: tabular-nums; }
.notes-sep { width: 100%; margin: 4px 0; border: 0; border-top: 1px dashed #d3b4b4; }
.notes-gap { height: 6px; }
@media print { .note-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---------- مشاكل القطع ---------- */
.prob-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; max-width: 210px; padding: 0 12px; border: 1.5px solid #e4d2d2; border-radius: 10px; background: #fff; color: var(--muted); font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.prob-btn:hover { border-color: var(--red-100); color: var(--red); }
.prob-btn.ok { background: var(--ok-bg); border-color: #bfe3cd; color: var(--ok); }
.prob-btn.bad { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.prob-list { display: flex; flex-wrap: wrap; gap: 5px; }
.prob-chip { display: inline-flex; padding: 2px 10px; border-radius: 999px; background: var(--red-100); color: var(--red-700); font-size: 12px; font-weight: 800; white-space: nowrap; }
.chip.ok.active { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.ok { height: 44px; padding: 0 18px; font-size: 15px; gap: 8px; }
.qty-cell { display: flex; align-items: center; gap: 6px; justify-content: center; }
.split-btn { height: 38px; padding: 0 9px; border: 1.5px dashed #d3b4b4; border-radius: 10px; background: #fff; color: var(--red-700); font-weight: 700; font-size: 12px; cursor: pointer; white-space: nowrap; }
.split-btn:hover { background: var(--red-50); border-style: solid; }
@media print { .prob-chip, .prob-btn { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---------- التقرير التفصيلي ---------- */
.det-card { margin-bottom: 14px; break-inside: avoid; }
.det-head { flex-wrap: wrap; }
.det-id { font-weight: 800; font-size: 17px; }
.det-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.det-notes { padding: 10px 20px 0; }
.det-notes .notes { padding: 8px 14px; background: var(--red-50); border-radius: 10px; border-inline-start: 4px solid var(--red); }
.det-card .table-wrap { border: 0; box-shadow: none; border-radius: 0 0 var(--radius) var(--radius); }
@media print { .det-card { page-break-inside: avoid; } .det-notes .notes { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---------- ورقة طباعة السند (تظهر في الطباعة فقط) ---------- */
.print-sheet { --fs: 12.5px; --pad: 6px; font-size: var(--fs); color: #1b1112; break-inside: avoid; page-break-inside: avoid; position: relative; }
.print-sheet.d2 { --fs: 11.5px; --pad: 4px; }
.print-sheet.d3 { --fs: 10px; --pad: 2.5px; }
.print-sheet.d4 { --fs: 9px; --pad: 1.5px; }
.print-sheet * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ps-head { display: flex; align-items: center; gap: 14px; padding-bottom: 8px; border-bottom: 3px solid var(--red); }
.ps-logo { width: 58px; height: 58px; object-fit: contain; }
.ps-t1 { font-size: 20px; font-weight: 800; color: var(--red-700); line-height: 1.3; }
.ps-t2 { font-size: 11px; color: #6b5a5b; }
.ps-no { margin-inline-start: auto; text-align: center; padding: 3px 16px; border: 2px solid var(--red); border-radius: 12px; }
.ps-no small { display: block; font-size: 10px; color: #6b5a5b; }
.ps-no b { font-size: 22px; line-height: 1.2; color: var(--red); }
.ps-stamp { padding: 2px 14px; border: 3px solid var(--red); border-radius: 10px; color: var(--red); font-size: 18px; font-weight: 800; transform: rotate(-4deg); }
.ps-meta { display: grid; grid-template-columns: repeat(4, 1fr); margin: 10px 0; border: 1.5px solid #d9c3c3; border-radius: 10px; overflow: hidden; }
.ps-meta > div { padding: 5px 10px; background: #fdf6f6; border-inline-start: 1px solid #e6d5d5; border-top: 1px solid #e6d5d5; margin-top: -1px; }
.ps-meta span { display: block; font-size: 9.5px; color: #7b6b6c; }
.ps-meta b { font-size: 12.5px; }
.ps-notes { margin: 0 0 10px; padding: 6px 12px; background: #fcf1f1; border: 1px solid var(--red-100); border-inline-start: 4px solid var(--red); border-radius: 8px; }
.ps-notes-title { margin-bottom: 3px; color: var(--red-700); font-size: 10.5px; font-weight: 800; }
.ps-notes .notes { display: block; column-count: 2; column-gap: 22px; font-size: 11px; line-height: 1.5; }
.ps-notes .notes-row { break-inside: avoid; margin-bottom: 2px; }
.ps-notes .notes-sep { column-span: all; margin: 3px 0; }
.ptable { width: 100%; border-collapse: collapse; border: 1.5px solid #cdb0b0; }
.ptable th { padding: 5px 8px; background: var(--red); color: #fff; font-size: 11px; text-align: start; }
.ptable td { padding: var(--pad) 8px; border-top: 1px solid #e3d2d2; vertical-align: middle; }
.ptable tbody tr:nth-child(even) td { background: #fcf7f7; }
.ptable tr { break-inside: avoid; }
.p-idx { width: 26px; text-align: center; color: #8a7a7b; }
.p-qty { width: 54px; text-align: center; font-size: 1.2em; font-weight: 800; color: var(--red-700); }
.p-name { font-weight: 700; }
.p-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; margin-top: 1px; font-size: .84em; color: #6b5a5b; }
.p-code { font-family: Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
.p-note { padding: 0 8px; background: #fbe3e3; color: var(--red-700); border: 1px solid #efc3c3; border-radius: 6px; }
.p-prob { width: 24%; }
.print-sheet .prob-list { gap: 3px; }
.print-sheet .prob-chip { padding: 0 7px; font-size: .86em; }
.print-sheet .badge { padding: 0 8px; font-size: .86em; }
.ps-total { display: flex; gap: 10px; margin-top: 10px; }
.ps-total > div { flex: 1; padding: 4px 10px; text-align: center; background: #fdf6f6; border: 1.5px solid #d9c3c3; border-radius: 10px; }
.ps-total > div.strong { background: var(--red); border-color: var(--red); color: #fff; }
.ps-total span { display: block; font-size: 10px; opacity: .8; }
.ps-total b { font-size: 18px; line-height: 1.2; }
.ps-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 24px; text-align: center; font-size: 11px; color: #6b5a5b; }
.ps-sign > div { padding-top: 4px; border-top: 1.5px solid #333; }
.ps-signname { margin-top: 1px; color: #1b1112; font-weight: 700; }

/* كثافة الطباعة: كلما زادت الأجهزة نضغط التصميم ليبقى السند في ورقة واحدة */
.print-sheet { line-height: 1.3; }
.print-sheet.d2 .ps-logo { width: 46px; height: 46px; }
.print-sheet.d2 .ps-sign { margin-top: 14px; }
.print-sheet.d2 .p-dev, .print-sheet.d3 .p-dev, .print-sheet.d4 .p-dev { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; }
.print-sheet.d2 .p-sub, .print-sheet.d3 .p-sub, .print-sheet.d4 .p-sub { margin-top: 0; }
.print-sheet.d3 .ps-logo, .print-sheet.d4 .ps-logo { width: 38px; height: 38px; }
.print-sheet.d3 .ps-head, .print-sheet.d4 .ps-head { gap: 10px; padding-bottom: 5px; border-bottom-width: 2px; }
.print-sheet.d3 .ps-t1, .print-sheet.d4 .ps-t1 { font-size: 15px; }
.print-sheet.d3 .ps-t2, .print-sheet.d4 .ps-t2 { font-size: 9px; }
.print-sheet.d3 .ps-no, .print-sheet.d4 .ps-no { padding: 1px 12px; }
.print-sheet.d3 .ps-no b, .print-sheet.d4 .ps-no b { font-size: 16px; }
.print-sheet.d3 .ps-meta, .print-sheet.d4 .ps-meta { margin: 6px 0; }
.print-sheet.d3 .ps-meta > div, .print-sheet.d4 .ps-meta > div { padding: 2px 8px; }
.print-sheet.d3 .ps-meta b, .print-sheet.d4 .ps-meta b { font-size: 10.5px; }
.print-sheet.d3 .ps-meta span, .print-sheet.d4 .ps-meta span { font-size: 8px; }
.print-sheet.d3 .ps-notes, .print-sheet.d4 .ps-notes { margin-bottom: 6px; padding: 3px 10px; }
.print-sheet.d3 .ps-notes .notes, .print-sheet.d4 .ps-notes .notes { font-size: 9.5px; }
.print-sheet.d3 .ps-total, .print-sheet.d4 .ps-total { margin-top: 6px; gap: 6px; }
.print-sheet.d3 .ps-total > div, .print-sheet.d4 .ps-total > div { padding: 1px 8px; }
.print-sheet.d3 .ps-total b, .print-sheet.d4 .ps-total b { font-size: 13px; }
.print-sheet.d3 .ps-total span, .print-sheet.d4 .ps-total span { font-size: 8px; }
.print-sheet.d3 .ps-sign, .print-sheet.d4 .ps-sign { margin-top: 12px; font-size: 9px; }
.print-sheet.d3 .ptable th, .print-sheet.d4 .ptable th { padding: 2px 8px; font-size: 9px; }
.print-sheet.d3 .p-qty, .print-sheet.d4 .p-qty { font-size: 1.1em; }

/* ---------- الجرد مقسّم حسب الماركة ---------- */
.stk-groups { display: flex; flex-direction: column; gap: 18px; }
.stk-chips { margin-bottom: 16px; }
.chip-n { margin-inline-start: 8px; padding: 0 8px; border-radius: 999px; background: rgba(0, 0, 0, .08); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip.active .chip-n { background: rgba(255, 255, 255, .28); }
.stk-group { overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stk-ghead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; width: 100%; padding: 12px 16px; border: 0; background: linear-gradient(135deg, var(--red), var(--red-700)); color: #fff; text-align: start; cursor: pointer; }
.stk-brand { padding: 2px 16px; border-radius: 999px; background: #fff; color: var(--red); font-size: 19px; font-weight: 800; line-height: 1.5; }
.stk-count { font-weight: 700; opacity: .92; }
.stk-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-inline-start: auto; }
.stk-pill { display: inline-flex; gap: 6px; align-items: baseline; padding: 1px 12px; border-radius: 999px; background: rgba(255, 255, 255, .18); font-size: 13px; font-weight: 600; }
.stk-pill b { font-weight: 800; font-variant-numeric: tabular-nums; }
.stk-pill.ok { background: rgba(255, 255, 255, .92); color: var(--ok); }
.stk-pill.neg { background: #fff; color: var(--red); }
.stk-pill.pos { background: #fff3d6; color: var(--warn); }
.stk-chev { display: inline-flex; transform: rotate(90deg); transition: transform .2s; }
.stk-group.collapsed .stk-chev { transform: rotate(180deg); }
.stk-group.collapsed .stk-body { display: none; }
.stk-group .table-wrap { border: 0; border-radius: 0; box-shadow: none; }
.stk-group .table th { position: static; }
.stk-group .table tbody tr:nth-child(even) td { background: #fdf9f9; }

@media screen and (max-width: 700px) {
  .stk-ghead { padding: 10px 12px; }
  .stk-summary { flex: 1 1 100%; order: 3; margin-inline-start: 0; }
  .stk-chev { margin-inline-start: auto; }
  .stk-group .table-wrap { padding: 8px 10px 2px; background: var(--bg); }
  .stk-groups { gap: 14px; }
  .stk-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
}

@media print {
  .stk-groups { display: block; }
  .stk-group { margin-bottom: 14px; box-shadow: none; border-color: #cbbcbc; }
  .stk-ghead { cursor: default; break-after: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stk-ghead .stk-pill { background: rgba(255, 255, 255, .25) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stk-chev, .stk-chips { display: none !important; }
  .stk-group.collapsed .stk-body { display: block !important; }
  .stk-group .table tbody tr:nth-child(even) td { background: #fdf9f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .brand-pages .stk-group + .stk-group { break-before: page; }
}

/* ---------- أزرار تعديل/حذف على بطاقة المورد ---------- */
.supplier-card { cursor: pointer; }
.supplier-card:focus-visible { outline: 3px solid var(--red-100); }
.sc-actions { display: flex; gap: 6px; margin-inline-start: auto; align-self: flex-start; }
.sc-actions .icon-btn { width: 34px; height: 34px; }

/* ورقة الجرد الفاضية للطباعة: بدون أي أعداد أو ملخصات تم إدخالها */
@media print {
  body.blank-sheet .stk-pill.prog, body.blank-sheet .stk-pill.ok, body.blank-sheet .stk-pill.neg, body.blank-sheet .stk-pill.pos { display: none; }
  body.blank-sheet .foot-counted { color: transparent; }
}

/* ---------- طباعة ورقة الجرد: A4 مضغوطة وموفّرة للورق ---------- */
@page stocktake { size: A4 portrait; margin: 7mm; @bottom-left { content: "صفحة " counter(page) " من " counter(pages); font-size: 9px; color: #777; } }
.stk-page { page: stocktake; --stk-row: 21px; }
.stk-page[data-density="medium"] { --stk-row: 26px; }
.stk-page[data-density="comfortable"] { --stk-row: 33px; }
.stk-sheet th.print-col, .stk-sheet td.print-col { display: none !important; }
.stk-totals { display: none; }

@media print {
  .stk-sheet th.print-col, .stk-sheet td.print-col { display: table-cell !important; }
  .stk-sheet th.print-col { width: 26%; }
  .stk-page .page-head { display: none; }
  .stk-page .print-head { gap: 10px; margin-bottom: 5px; padding-bottom: 3px; border-bottom-width: 2px; }
  .stk-page .print-head img { width: 34px; height: 34px; }
  .stk-page .print-head h2 { font-size: 14px; }
  .stk-page .print-head p { font-size: 9px; }
  .stk-totals { display: block !important; margin: 0 0 5px; }
  .stk-tbox { display: inline-block; margin-inline-end: 8px; padding: 0 10px; border: 1px solid #888; border-radius: 4px; font-size: 10px; font-weight: 700; }
  .stk-tbox b { margin-inline-start: 6px; font-size: 12px; }
  .stk-page .stk-groups { display: block; }
  .stk-page .stk-group { margin-bottom: 5px; border-radius: 5px; box-shadow: none; }
  .stk-page .stk-ghead { padding: 2px 8px; gap: 8px; }
  .stk-page .stk-brand { padding: 0 12px; font-size: 11px; line-height: 1.7; }
  .stk-page .stk-count, .stk-page .stk-pill { font-size: 9px; }
  .stk-page .stk-pill { padding: 0 8px; }
  .stk-page .table th { padding: 1px 6px; font-size: 9px; }
  .stk-page .table td { height: var(--stk-row); padding: 0 6px; font-size: 10px; line-height: 1.2; }
  body.blank-sheet .stk-page .stk-sheet td { height: var(--stk-row); }
  .stk-page .stk-sheet td.code { width: 82px; font-size: 9px; }
  .stk-page .stk-sheet tfoot td { height: auto; padding: 0 6px; font-size: 9px; }
  .stk-page .stk-input { width: 52px; height: calc(var(--stk-row) - 7px); min-height: 0; padding: 0; border-color: #777; border-radius: 2px; }
  .stk-page .table tr { break-inside: avoid; }
}

/* ضبط كثافة الطباعة: "توفير الورق" لازم يخش 71 صنف في صفحتين بهامش أمان */
.stk-page { --stk-row: 19px; }
.stk-page[data-density="medium"] { --stk-row: 24px; }
@media print {
  .stk-page .stk-group { margin-bottom: 3px; }
  .stk-page .stk-ghead { padding: 1px 8px; }
  .stk-page .stk-brand { line-height: 1.55; }
  .stk-page .stk-sheet tfoot td { font-size: 8.5px; line-height: 1.1; }
  .stk-page .table th { padding: 0 6px; line-height: 1.4; }
  .stk-page .stk-input { height: calc(var(--stk-row) - 6px); }
}

/* ورقة الجرد المطبوعة: بدون شارات الملخص (الدفتري...) وبدون صف إجمالي الماركة */
@media print {
  body.blank-sheet .stk-page .stk-summary,
  body.blank-sheet .stk-page .stk-sheet tfoot { display: none !important; }
}

/* ---------- تنبيه "حالة القطع غير محددة" ---------- */
.cart-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--warn-bg); border: 1px solid #f1d6a0; border-radius: 12px; color: var(--warn); font-weight: 700; }
.cart-tools > span { display: inline-flex; align-items: center; gap: 8px; }
.prob-btn.unset { border-style: dashed; border-color: var(--red); color: var(--red); background: #fff8f8; }
