/* ============================================================
   PURIMIX — التصميم الكامل
   اللبني هو اللون الأساسي، والكحلي للسايدبار عشان اللوجو الأبيض
   ============================================================ */

:root {
  --sky-50: #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-200: #bae6fd;
  --sky-300: #7dd3fc;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #0369a1;
  --navy-950: #061428;
  --navy-900: #0b1f3a;
  --navy-800: #13325c;
  --ink: #0f1f35;
  --ink-2: #33475f;
  --muted: #6b7f96;
  --line: #e2ebf4;
  --line-2: #eef3f9;
  --bg: #f2f7fc;
  --card: #ffffff;
  --green: #10b981;
  --green-bg: #e8f8f1;
  --amber: #f59e0b;
  --amber-bg: #fff6e5;
  --red: #ef4444;
  --red-bg: #fdeeee;
  --violet: #7c6cf2;
  --violet-bg: #f0eefe;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(11, 31, 58, .04), 0 10px 30px rgba(11, 31, 58, .06);
  --shadow-lg: 0 20px 60px rgba(11, 31, 58, .16);
  --grad: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 45%, #0284c7 100%);
  --side-w: 268px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sky-600); text-decoration: none; }
a:hover { color: var(--sky-700); }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: #c47a04; }
.text-sky { color: var(--sky-600); }
[hidden] { display: none !important; }

/* ---------- الهيكل ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 40;
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 50% at 0% 0%, rgba(56, 189, 248, .22), transparent 60%),
    radial-gradient(90% 40% at 100% 100%, rgba(14, 165, 233, .14), transparent 60%),
    linear-gradient(180deg, var(--navy-900), var(--navy-950));
  color: #cfe0f3;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 22px 18px; color: #fff; }
.brand:hover { color: #fff; }
.brand-mark { width: 42px; height: 42px; object-fit: contain; filter: drop-shadow(0 6px 18px rgba(56, 189, 248, .45)); }
.brand-text b { display: block; font-size: 24px; font-weight: 700; letter-spacing: .01em; line-height: 1; }
.brand-text small { display: block; margin-top: 5px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--sky-300); opacity: .85; }

.nav { flex: 1; overflow-y: auto; padding: 6px 14px 14px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.nav-sep { margin: 18px 10px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: rgba(186, 230, 253, .45); }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0;
  border-radius: 12px; color: #c4d6ea; font-weight: 500; transition: background .15s, color .15s;
}
.nav-link i { width: 18px; text-align: center; font-size: 15px; color: #7fa6cc; transition: color .15s; }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link:hover i { color: var(--sky-300); }
.nav-link.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, .95), rgba(2, 132, 199, .95));
  color: #fff; font-weight: 600; box-shadow: 0 8px 22px rgba(14, 165, 233, .35);
}
.nav-link.active i { color: #fff; }
.nav-badge { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; min-width: 22px; text-align: center; padding: 2px 7px; border-radius: 99px; background: var(--amber); color: #fff; }

.side-user { display: flex; align-items: center; gap: 10px; margin: 10px 14px 16px; padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .06); }
.avatar { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; background: var(--grad); color: #fff; flex: none; }
.who { flex: 1; min-width: 0; }
.who b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--sky-300); font-size: 11px; font-weight: 600; letter-spacing: .08em; }
.logout { color: #8fb0d1; padding: 8px; border-radius: 9px; }
.logout:hover { color: #fff; background: rgba(255, 255, 255, .08); }

.main { flex: 1; min-width: 0; margin-left: var(--side-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px;
  padding: 16px 32px; background: rgba(242, 247, 252, .82); backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px); border-bottom: 1px solid rgba(226, 235, 244, .7);
}
.page-title { flex: 1; min-width: 0; }
.page-title h1 { font-size: 22px; font-weight: 800; color: var(--navy-900); }
.page-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.menu-btn { display: none; border: 0; background: #fff; width: 40px; height: 40px; border-radius: 12px; box-shadow: var(--shadow); color: var(--navy-900); font-size: 16px; cursor: pointer; }
.content { padding: 26px 32px 40px; flex: 1; }
.foot { padding: 18px 32px 26px; color: var(--muted); font-size: 12px; }
.scrim { display: none; }

.quick { position: relative; }
.quick .caret { font-size: 10px; opacity: .8; margin-left: 2px; }
.quick-menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 230px; padding: 8px; border-radius: 16px;
  background: #fff; box-shadow: var(--shadow-lg); border: 1px solid var(--line); z-index: 50;
}
.quick-menu a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink); font-weight: 500; }
.quick-menu a i { width: 18px; color: var(--sky-500); text-align: center; }
.quick-menu a:hover { background: var(--sky-50); }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: transform .12s, box-shadow .15s, background .15s; line-height: 1.2;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(14, 165, 233, .32); }
.btn-primary:hover { color: #fff; box-shadow: 0 10px 26px rgba(14, 165, 233, .45); }
.btn-navy { background: var(--navy-900); color: #fff; }
.btn-navy:hover { background: var(--navy-800); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--sky-300); color: var(--sky-700); }
.btn-soft { background: var(--sky-50); color: var(--sky-700); border-color: var(--sky-100); }
.btn-soft:hover { background: var(--sky-100); color: var(--sky-700); }
.btn-green { background: var(--green); color: #fff; box-shadow: 0 8px 20px rgba(16, 185, 129, .28); }
.btn-green:hover { color: #fff; }
.btn-danger { background: #fff; color: var(--red); border-color: #f6caca; }
.btn-danger:hover { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }
.btn-icon { padding: 8px 10px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- الكروت ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 20px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 15.5px; font-weight: 700; color: var(--navy-900); display: flex; align-items: center; gap: 10px; }
.card-head h2 i, .card-head h3 i { color: var(--sky-500); }
.card-head .sub { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.card-head .spacer { flex: 1; }
.card-body { padding: 20px 22px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 20px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.mt { margin-top: 20px; }
.mb { margin-bottom: 20px; }

/* ---------- الـ Hero بتاع الداشبورد ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 18px; padding: 22px 26px; color: #fff;
  background:
    radial-gradient(70% 120% at 100% 0%, rgba(125, 211, 252, .55), transparent 60%),
    linear-gradient(120deg, var(--navy-900) 0%, var(--navy-800) 45%, var(--sky-600) 100%);
  box-shadow: 0 20px 50px rgba(11, 31, 58, .22);
}
.hero::after {
  content: ''; position: absolute; right: -40px; bottom: -70px; width: 300px; height: 300px;
  background: url(mark-white.png) center / contain no-repeat; opacity: .09; transform: rotate(-8deg);
}
.hero h2 { font-size: 22px; font-weight: 800; }
.hero p { margin: 6px 0 0; color: #cfe7fb; max-width: 560px; }
.hero .btn-row { margin-top: 16px; position: relative; z-index: 1; }
.hero .btn-ghost { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .22); color: #fff; }
.hero .btn-ghost:hover { background: rgba(255, 255, 255, .2); color: #fff; }

/* ---------- KPI ---------- */
.kpi { position: relative; padding: 20px; overflow: hidden; }
.kpi .k-icon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 18px; color: #fff; background: var(--grad); box-shadow: 0 8px 18px rgba(14, 165, 233, .3); }
.kpi .k-icon.navy { background: linear-gradient(135deg, var(--navy-800), var(--navy-900)); box-shadow: 0 8px 18px rgba(11, 31, 58, .25); }
.kpi .k-icon.green { background: linear-gradient(135deg, #34d399, #059669); box-shadow: 0 8px 18px rgba(16, 185, 129, .3); }
.kpi .k-icon.amber { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 8px 18px rgba(245, 158, 11, .3); }
.kpi .k-icon.violet { background: linear-gradient(135deg, #a397ff, #6d5ce8); box-shadow: 0 8px 18px rgba(124, 108, 242, .3); }
.kpi .k-icon.red { background: linear-gradient(135deg, #fb7185, #e11d48); box-shadow: 0 8px 18px rgba(225, 29, 72, .25); }
.kpi .k-label { margin-top: 14px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .k-value { margin-top: 2px; font-size: 23px; font-weight: 800; color: var(--navy-900); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .k-value small { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi .k-foot { margin-top: 6px; font-size: 12px; color: var(--muted); }
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: radial-gradient(circle, var(--sky-50), transparent 70%); }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 12px 16px; background: #f8fbfe; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: #f7fbff; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { padding: 13px 16px; border-top: 2px solid var(--line); font-weight: 700; background: #fafcff; }
.tbl .num, .tbl th.num { text-align: right; }
.tbl a.row-link { color: var(--navy-900); font-weight: 600; }
.tbl a.row-link:hover { color: var(--sky-600); }
.tbl .code { font-weight: 700; color: var(--sky-700); font-variant-numeric: tabular-nums; }
.tbl tr.row-warn td { background: #fff8f8; }
.tbl.compact td, .tbl.compact th { padding: 9px 12px; }
.tbl td .sub { display: block; font-size: 12px; color: var(--muted); }

/* ---------- البادجات ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill i { font-size: 10px; }
.pill-green { background: var(--green-bg); color: #047857; }
.pill-amber { background: var(--amber-bg); color: #b45309; }
.pill-red { background: var(--red-bg); color: #b91c1c; }
.pill-sky { background: var(--sky-50); color: var(--sky-700); border: 1px solid var(--sky-100); }
.pill-violet { background: var(--violet-bg); color: #5b4bd6; }
.pill-gray { background: #eef2f6; color: #5b6b7e; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 7px; background: var(--line-2); color: var(--ink-2); font-size: 11.5px; font-weight: 600; }

/* ---------- الفورمز ---------- */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.f-12 { grid-column: span 12; } .f-8 { grid-column: span 8; } .f-6 { grid-column: span 6; }
.f-4 { grid-column: span 4; } .f-3 { grid-column: span 3; } .f-2 { grid-column: span 2; }
.f-5 { grid-column: span 5; } .f-7 { grid-column: span 7; } .f-9 { grid-column: span 9; }
.field label, label.lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.req { color: var(--red); }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea, .input {
  width: 100%; padding: 10px 12px; border: 1px solid #d7e3ef; border-radius: 11px; background: #fff;
  font: inherit; font-size: 14px; color: var(--ink); transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sky-400); box-shadow: 0 0 0 4px rgba(56, 189, 248, .16); }
input[readonly] { background: #f6f9fc; color: var(--ink-2); }
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7f96' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input-group { display: flex; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon { display: grid; place-items: center; padding: 0 12px; border: 1px solid #d7e3ef; border-left: 0; border-radius: 0 11px 11px 0; background: #f6f9fc; color: var(--muted); font-weight: 600; font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--sky-500); }
.seg { display: inline-flex; padding: 4px; background: #eaf2fa; border-radius: 12px; gap: 4px; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: #fff; color: var(--sky-700); box-shadow: 0 2px 8px rgba(11, 31, 58, .08); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px; flex-wrap: wrap; }

/* جداول الإدخال (بنود الفاتورة / التركيبة) */
.lines td { padding: 8px 8px; }
.lines th { padding: 10px 8px; }
.lines input, .lines select { min-height: 38px; padding: 8px 10px; font-size: 13.5px; }
.lines .del { border: 0; background: transparent; color: #b8c6d6; cursor: pointer; padding: 8px; border-radius: 8px; font-size: 14px; }
.lines .del:hover { color: var(--red); background: var(--red-bg); }
.add-line { margin: 10px 8px 4px; }
/* اختيار أساس الحساب في رأس جدول التركيبة (Per 1 kg / 1 L ...) */
.tbl th select.basis-sel { width: auto; min-height: 32px; padding: 5px 30px 5px 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--sky-700); background-color: var(--sky-50); border-color: var(--sky-200); border-radius: 9px; cursor: pointer; }

/* ---------- خطوات الرصيد الافتتاحي + اختيار المخزن ---------- */
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.step { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); font-weight: 500; }
.step b { flex: none; width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: var(--grad); color: #fff; font-size: 13px; }
.wh-pick { display: flex; gap: 12px; flex-wrap: wrap; }
.wh-pick a { display: flex; align-items: center; gap: 12px; padding: 14px 18px; min-width: min(220px, 100%); border-radius: 16px; background: #fff; border: 2px solid var(--line); color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.wh-pick a i { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--sky-50); color: var(--sky-600); font-size: 16px; }
.wh-pick a b { display: block; font-size: 14px; }
.wh-pick a small { color: var(--muted); font-size: 12px; }
.wh-pick a:hover { border-color: var(--sky-300); color: var(--ink); }
.wh-pick a.on { border-color: var(--sky-500); box-shadow: 0 8px 24px rgba(14, 165, 233, .18); }
.wh-pick a.on i { background: var(--grad); color: #fff; }
.tbl tr.row-filled td { background: #f2fbff; }
.tbl tr.row-filled .op-v { color: var(--sky-700); font-weight: 700; }
.count-box { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.count-box div { padding: 12px; border-radius: 12px; background: var(--line-2); }
.count-box span { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.count-box b { display: block; margin-top: 4px; font-size: 18px; color: var(--navy-900); }
@media screen and (max-width: 720px) { .steps { grid-template-columns: 1fr; } .wh-pick a { min-width: 0; flex: 1 1 100%; } }

/* ---------- الفلاتر ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .field { min-width: min(150px, 100%); }
.filters .grow { flex: 1; min-width: min(200px, 100%); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs a { padding: 9px 16px; border-radius: 11px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.tabs a.on { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.tabs a em { font-style: normal; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--sky-100); color: var(--sky-700); }
.tabs a.on em { background: rgba(255, 255, 255, .18); color: #fff; }

/* ---------- التنبيهات ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: 14px; margin-bottom: 18px; font-weight: 500; border: 1px solid; }
.alert i { margin-top: 2px; }
.alert-success { background: var(--green-bg); color: #065f46; border-color: #bfeedd; }
.alert-error { background: var(--red-bg); color: #991b1b; border-color: #f7cdcd; }
.alert-info { background: var(--sky-50); color: var(--sky-700); border-color: var(--sky-100); }
.alert-warn { background: var(--amber-bg); color: #92400e; border-color: #fbe2b0; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 46px 20px; text-align: center; color: var(--muted); }
.empty i { font-size: 30px; color: var(--sky-300); margin-bottom: 6px; }
.empty b { color: var(--ink-2); font-size: 15px; }

/* ---------- بلوك المعلومات ---------- */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px 22px; }
.dl div span { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.dl div b { display: block; margin-top: 3px; font-weight: 600; color: var(--navy-900); }
.sum-box { display: grid; gap: 10px; }
.sum-box .row { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); }
.sum-box .row b { font-variant-numeric: tabular-nums; color: var(--navy-900); }
.sum-box .row.total { padding-top: 12px; border-top: 1px dashed var(--line); font-size: 17px; }
.sum-box .row.total b { color: var(--sky-700); font-size: 20px; font-weight: 800; }
.sum-box .row { align-items: center; }
.sum-box .row span i { width: 16px; margin-right: 4px; }
.sum-box .row.sub-total { padding: 8px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); font-weight: 700; color: var(--navy-900); }
.pct-in { display: inline-flex; flex-wrap: nowrap; width: auto; margin-left: 6px; vertical-align: middle; }
.pct-in input { width: 64px !important; flex: none; }
.pct-in input { min-height: 32px; padding: 5px 8px; font-size: 13px; font-weight: 700; }
.pct-in .addon { padding: 0 8px; }
.per-pack { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.per-pack div { padding: 10px 12px; border-radius: 12px; background: var(--sky-50); border: 1px solid var(--sky-100); }
.per-pack span { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.per-pack b { display: block; margin-top: 2px; font-size: 17px; color: var(--navy-900); }
.per-pack div + div { background: var(--grad); border-color: transparent; }
.per-pack div + div span, .per-pack div + div b { color: #fff; }

/* شريط التقدم */
.progress { height: 9px; border-radius: 99px; background: #e8f0f8; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .p-wh { background: linear-gradient(90deg, #34d399, #10b981); }
.progress .p-fa { background: linear-gradient(90deg, #fcd34d, #f59e0b); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* مقارنة محلي / مستورد */
.split-bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: #e8f0f8; }
.split-bar .a { background: var(--grad); }
.split-bar .b { background: linear-gradient(90deg, #a397ff, #6d5ce8); }

/* شارت أعمدة بسيط */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .bar i { display: block; width: 100%; max-width: 42px; border-radius: 9px 9px 4px 4px; background: var(--grad); min-height: 3px; }
.bars .bar small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .bar em { font-style: normal; font-size: 10.5px; color: var(--ink-2); font-weight: 600; white-space: nowrap; }

/* ---------- المودال ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 20px; width: min(640px, calc(100vw - 28px)); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog.modal::backdrop { background: rgba(6, 20, 40, .5); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { flex: 1; font-size: 16px; color: var(--navy-900); }
.modal-head button { border: 0; background: var(--line-2); width: 34px; height: 34px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px 22px; max-height: calc(100vh - 200px); overflow-y: auto; }
.modal-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- صفحة الدخول ---------- */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
  background: var(--bg);
}
.auth-art {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 48px;
  color: #fff;
  background:
    radial-gradient(60% 60% at 85% 15%, rgba(56, 189, 248, .55), transparent 65%),
    radial-gradient(50% 50% at 10% 95%, rgba(14, 165, 233, .35), transparent 65%),
    linear-gradient(150deg, var(--navy-900), var(--navy-950));
}
.auth-art .art-logo { width: 150px; }
.auth-art h2 { font-size: 40px; font-weight: 800; line-height: 1.1; max-width: 460px; }
.auth-art h2 span { background: linear-gradient(90deg, #7dd3fc, #38bdf8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-art p { color: #bcd6ee; max-width: 440px; margin-top: 14px; font-size: 15px; }
.auth-art .ring { position: absolute; right: -120px; bottom: -120px; width: 520px; opacity: .08; transform: rotate(-12deg); }
.auth-art .feats { display: flex; gap: 22px; flex-wrap: wrap; color: #9fc3e4; font-size: 13px; font-weight: 600; }
.auth-art .feats i { color: var(--sky-300); margin-right: 6px; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: min(400px, 100%); }
.auth-card h1 { font-size: 28px; font-weight: 800; color: var(--navy-900); }
.auth-card .lead { color: var(--muted); margin: 6px 0 26px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn { width: 100%; padding: 13px; font-size: 15px; }

/* ---------- الطباعة A4 ---------- */
.print-body { background: #e9eff6; }
.print-tools { display: flex; gap: 10px; justify-content: center; padding: 18px; }
.sheet {
  width: 210mm; min-height: 297mm; margin: 0 auto 30px; background: #fff; padding: 16mm 15mm 14mm;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; color: #10223a; font-size: 12.5px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 14px; border-bottom: 3px solid var(--sky-500); }
.sheet-logo { height: 70px; }
.sheet-company { text-align: right; display: flex; flex-direction: column; gap: 2px; color: #4a5d74; font-size: 11.5px; }
.sheet-company b { font-size: 16px; color: var(--navy-900); letter-spacing: .06em; }
.sheet-title { display: flex; justify-content: space-between; align-items: flex-end; margin: 22px 0 16px; gap: 20px; }
.sheet-title h2 { font-size: 26px; font-weight: 800; color: var(--navy-900); letter-spacing: .04em; }
.sheet-title h2 small { display: block; font-size: 12px; color: var(--sky-600); letter-spacing: .14em; font-weight: 700; }
.sheet-meta { display: grid; grid-template-columns: auto auto; gap: 3px 14px; font-size: 12px; text-align: right; }
.sheet-meta span { color: #6b7f96; }
.sheet-meta b { color: var(--navy-900); }
.sheet-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.sheet-box { border: 1px solid #dbe6f1; border-radius: 10px; padding: 10px 12px; }
.sheet-box span { display: block; font-size: 10.5px; font-weight: 700; color: var(--sky-600); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }
.sheet-box b { font-size: 14px; color: var(--navy-900); }
.sheet table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.sheet th { background: var(--navy-900); color: #fff; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; padding: 8px 9px; text-align: left; }
.sheet th.num { text-align: right; }
.sheet td { padding: 8px 9px; border-bottom: 1px solid #e3ebf4; }
.sheet tbody tr:nth-child(even) td { background: #f6faff; }
.sheet tfoot td { font-weight: 800; border-top: 2px solid var(--navy-900); border-bottom: 0; }
.sheet h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--sky-700); margin: 12px 0 8px; }
.sheet .totals { margin-left: auto; width: 300px; }
.sheet .totals div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #e3ebf4; }
.sheet .totals .grand { border: 0; margin-top: 4px; padding: 10px 12px; background: var(--navy-900); color: #fff; border-radius: 8px; font-size: 15px; font-weight: 800; }
.sheet .notes { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: #f6faff; border: 1px solid #dbe6f1; color: #4a5d74; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 46px; }
.signs div { border-top: 1px solid #9fb2c6; padding-top: 6px; text-align: center; color: #6b7f96; font-size: 11px; }
.sheet-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid #e3ebf4; text-align: center; font-size: 10.5px; color: #8a9bb0; }
.check-box { display: inline-block; width: 14px; height: 14px; border: 1.5px solid #8aa0b8; border-radius: 3px; }

@media print {
  body.print-body { background: #fff; }
  .print-tools { display: none; }
  .sheet { margin: 0; box-shadow: none; width: auto; min-height: 297mm; }
}
/* ============================================================
   مكونات جديدة: التنقل بين المنتج والتركيبة + الشريط اللي تحت
   ============================================================ */
.page-switch { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-switch > a { display: inline-flex; align-items: center; gap: 9px; padding: 11px 18px; border-radius: 14px; background: #fff; border: 1px solid var(--line);
  color: var(--ink-2); font-weight: 600; transition: border-color .15s, box-shadow .15s; }
.page-switch > a i { color: var(--sky-500); }
.page-switch > a:hover { border-color: var(--sky-300); color: var(--ink); }
.page-switch > a.on { background: var(--navy-900); border-color: var(--navy-900); color: #fff; box-shadow: 0 8px 20px rgba(11, 31, 58, .18); }
.page-switch > a.on i { color: var(--sky-300); }
.page-switch em { font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.page-switch em.ok { background: var(--green-bg); color: #047857; }
.page-switch em.warn { background: var(--amber-bg); color: #b45309; }
.page-switch .switch-pick { margin-left: auto; min-width: min(220px, 100%); }

.side-close, .top-logo, .bottom-nav, .quick-scrim { display: none; }
body.no-scroll { overflow: hidden; }

/* شريط الفترة في التقارير: كله نفس الارتفاع وعلى خط واحد */
.range-bar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.range-bar label { display: block; margin: 0; width: 170px; max-width: 100%; }
.range-bar label span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.range-bar input { height: 42px; min-height: 42px; }
.range-bar .btn { height: 42px; padding-top: 0; padding-bottom: 0; }
.range-presets { display: inline-flex; height: 42px; padding: 3px; gap: 2px; margin-left: auto; background: #eaf2fa; border-radius: 12px; }
.range-presets a { display: inline-flex; align-items: center; padding: 0 13px; border-radius: 9px; color: var(--ink-2); font-weight: 600; font-size: 13px; white-space: nowrap; }
.range-presets a:hover { color: var(--sky-700); }
.range-presets a.on { background: #fff; color: var(--sky-700); box-shadow: 0 2px 8px rgba(11, 31, 58, .08); }

/* كارت دخل المصنع في أمر التصنيع */
.income-card { border-color: #bfeedd; background: linear-gradient(180deg, #f3fcf8, #fff 60%); }
.income-card .card-head h3 i { color: #059669; }
.income-card .sum-box .row span i { color: #10b981; width: 16px; margin-right: 4px; }
.income-card .sum-box .row.total b { color: #047857; }

/* أمر البيع: زرار مسح السعر */
.price-wrap { flex-wrap: nowrap; }
.price-wrap input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.price-wrap .s-clear { flex: none; width: 36px; border: 1px solid #d7e3ef; border-left: 0; border-radius: 0 11px 11px 0; background: #f6f9fc; color: var(--muted); cursor: pointer; }
.price-wrap .s-clear:hover { color: var(--red); background: var(--red-bg); }
.s-info .s-use { font-weight: 700; }

.sum-box .row.neg b { color: var(--red); }

/* جداول البنود (شراء / بيع): خانات الكمية والوحدة والسعر بعرض يكفي الكتابة */
.tbl.lines input.num { min-width: 96px; }
.tbl.lines select.i-unit, .tbl.lines select.s-unit { min-width: 82px; }
.buy-lines { table-layout: fixed; }
.buy-lines .c-qty { width: 118px; }
.buy-lines .c-unit { width: 96px; }
.buy-lines .c-price { width: 128px; }
.buy-lines .c-total { width: 120px; }
.buy-lines .c-x { width: 44px; }
.buy-lines td:first-child select { min-width: 0; text-overflow: ellipsis; }

/* التقارير */
.rep-card { margin-bottom: 20px; }
.grid > .rep-card { margin-bottom: 0; }
.grid + .rep-card { margin-top: 20px; }
.rep-bar { margin-bottom: 12px; }
.rep-bar:last-child { margin-bottom: 0; }
.rep-bar > div { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.rep-bar > i { display: block; height: 8px; margin-top: 5px; border-radius: 99px; background: #e8f0f8; overflow: hidden; }
.rep-bar > i em { display: block; height: 100%; border-radius: 99px; background: var(--grad); }

/* سجل الحركات: ملخص الصنف */
.move-sum { display: flex; flex-wrap: wrap; gap: 10px; }
.move-sum > div { flex: 1 1 140px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.move-sum span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.move-sum b { display: block; font-size: 20px; font-weight: 800; color: var(--navy-900); font-variant-numeric: tabular-nums; margin-top: 2px; }
.move-sum small { color: var(--muted); font-size: 11.5px; }
.move-sum .in b { color: #059669; }
.move-sum .out b { color: #dc2626; }
.move-sum .close { background: var(--navy-900); border-color: var(--navy-900); }
.move-sum .close span, .move-sum .close small { color: #9fc3e4; }
.move-sum .close b { color: #fff; }

/* أمر التصنيع: الخطوات + كارت العبوة */
.step-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 9px; background: var(--grad); color: #fff; font-size: 13px; font-weight: 800; margin-right: 2px; }
.input-group .unit-sel { width: 84px; flex: none; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; background-color: #f6f9fc; font-weight: 600; }
.pc-table td { padding: 6px 6px 6px 0; border: 0; }
.pc-table .pc-q { width: 150px; }
.pc-table .pc-p { width: 130px; }
.pc-table .td-x { width: 44px; }
.pack-card { border: 1px solid var(--sky-100); background: var(--sky-50); border-radius: 14px; padding: 12px 16px; }
.pk-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; color: var(--ink-2); }
.pk-row b { color: var(--navy-900); font-variant-numeric: tabular-nums; }
.pk-row.pk-total { margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--sky-200); font-weight: 700; color: var(--navy-900); }
.pk-row.pk-total b { color: var(--sky-700); font-size: 18px; font-weight: 800; }
.tbl td.grp { background: #f8fbfe; font-size: 12.5px; }

/* صفحة التركيبة: تكلفة كل عبوة */
.pack-cost { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-top: 10px; background: #fbfdff; }
.pc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pc-head b { font-size: 15px; color: var(--navy-900); }
.pc-total { font-weight: 800; color: var(--sky-700); font-size: 16px; }
.pc-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--ink-2); padding: 3px 0; }
.pc-row small { display: block; }

/* ---------- الموبايل والتابلت ---------- */
@media screen and (max-width: 1200px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: 1fr; }
  .content [style*="sticky"] { position: static !important; }
}

/* تابلت وآيباد (رأسي) وأي شاشة أصغر: السايدبار بيتقفل ويفتح بزرار */
@media screen and (max-width: 1024px) {
  .sidebar { width: min(300px, 86vw); height: 100%; height: 100dvh; transform: translateX(-105%); box-shadow: var(--shadow-lg); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .sidebar.open { transform: none; }
  .side-close { display: grid; place-items: center; position: absolute; top: calc(18px + env(safe-area-inset-top)); right: 14px; width: 36px; height: 36px;
    border: 0; border-radius: 11px; background: rgba(255, 255, 255, .08); color: #cfe0f3; font-size: 16px; cursor: pointer; }
  .main { margin-left: 0; }
  .menu-btn { display: grid; place-items: center; flex: none; }
  .top-logo { display: block; flex: none; }
  .top-logo img { width: 36px; height: 36px; border-radius: 10px; display: block; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(6, 20, 40, .5); z-index: 35; backdrop-filter: blur(2px); }
  .topbar { padding: 12px 20px; padding-top: calc(12px + env(safe-area-inset-top)); gap: 10px; }
  .page-title h1 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 20px 20px 30px; }
  .foot { padding: 14px 20px 22px; }
  .g-3, .g-2 { grid-template-columns: 1fr; }
  .form-grid > .f-2, .form-grid > .f-3, .form-grid > .f-4, .form-grid > .f-5 { grid-column: span 6; }
  .form-grid > .f-7, .form-grid > .f-8, .form-grid > .f-9 { grid-column: span 12; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 30px 24px; min-height: 260px; }
  .auth-art h2 { font-size: 28px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; }
  .wh-pick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .wh-pick a { flex: none; }
}

/* الموبايل (أندرويد وآيفون) — التابلت والآيباد بياخدوا شكل الجداول العادي */
@media screen and (max-width: 700px) {
  /* حجم الخط 16 عشان الآيفون ميعملش زووم لما تدوس على خانة */
  input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  .top-logo { display: none; }
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  /* الـ blur بيخلي القايمة الثابتة تتحسب جوه الهيدر، فبنلغيه على الموبايل */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(242, 247, 252, .97); }
  .menu-btn { width: 42px; height: 42px; }
  .page-title h1 { font-size: 18px; }
  .page-title p { display: none; }
  .quick .btn { width: 44px; height: 44px; padding: 0; border-radius: 13px; }
  .quick .btn span, .quick .caret { display: none; }
  .content { padding: 14px 12px 24px; }
  .foot { padding: 6px 16px calc(84px + env(safe-area-inset-bottom)); text-align: center; }

  /* الشريط اللي تحت */
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .94); backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(11, 31, 58, .06); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px; border: 0; background: none; border-radius: 12px;
    color: var(--muted); font: inherit; font-size: 10.5px; font-weight: 600; cursor: pointer; }
  .bottom-nav i { font-size: 18px; }
  .bottom-nav .on { color: var(--sky-600); background: var(--sky-50); }

  /* قايمة New بتطلع من تحت */
  .quick-scrim:not([hidden]) { display: block; position: fixed; inset: 0; background: rgba(6, 20, 40, .45); z-index: 49; }
  .quick-menu { position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; padding: 10px; border-radius: 20px; z-index: 50; }
  .quick-menu a { padding: 14px; font-size: 15px; }

  /* الكروت والجريدات */
  .grid { gap: 14px; }
  .mb { margin-bottom: 14px; }
  .mt { margin-top: 14px; }
  .card + .card { margin-top: 14px; }
  .g-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-head { padding: 14px; gap: 10px; }
  .card-body { padding: 14px; }
  .card-head .spacer { display: none; }
  .card-head > .btn, .card-head > form:not(.filters) { margin-left: auto; }
  .form-grid { gap: 12px; }
  .form-grid > [class*="f-"] { grid-column: span 12 !important; }
  .kpi { padding: 14px; }
  .kpi .k-icon { width: 38px; height: 38px; font-size: 15px; border-radius: 11px; }
  .kpi .k-label { margin-top: 10px; font-size: 11.5px; }
  .kpi .k-value { font-size: 17px; word-break: break-word; }
  .kpi .k-foot { font-size: 11px; }
  .hero { padding: 20px; border-radius: 18px; }
  .hero h2 { font-size: 21px; }
  .hero .btn-row .btn { flex: 1 1 calc(50% - 10px); }
  .hero::after { width: 200px; height: 200px; right: -50px; bottom: -60px; }

  /* الفلاتر والزراير */
  .filters { width: 100%; }
  .filters .field { flex: 1 1 140px; min-width: 0; }
  .filters .grow { flex: 1 1 100%; }
  .filters > .btn { flex: 1 1 auto; }
  .btn-row { gap: 8px; }
  .content > .btn-row > .btn, .content > .btn-row > form > .btn { flex: 1 1 auto; }
  .content > .btn-row > span[style*="flex:1"] { display: none; }
  .form-actions .btn { flex: 1 1 100%; }
  .seg { display: flex; width: 100%; }
  .seg label { flex: 1; }
  .seg span { justify-content: center; width: 100%; padding: 10px 8px; }
  .page-switch > a { flex: 1 1 calc(50% - 8px); justify-content: center; padding: 11px 10px; }
  .range-bar label { flex: 1 1 40%; width: auto; }
  .range-bar input { height: 46px; }
  .range-bar .btn { height: 46px; flex: 1 1 auto; }
  .range-presets { order: 5; flex: 1 1 100%; margin-left: 0; height: 46px; }
  .range-presets a { flex: 1; justify-content: center; padding: 0 6px; font-size: 12.5px; }
  .range-print span { display: none; }
  .print-btn { display: none; }

  .page-switch .switch-pick { flex: 1 1 100%; margin-left: 0; min-width: 0; }
  .steps .step { padding: 12px; }
  .count-box { grid-template-columns: 1fr; }
  .wh-pick a { min-width: 200px; }

  /* الجداول بتتحول لكروت على الموبايل (العنوان من رأس العمود) */
  .tbl.stack thead { display: none; }
  .tbl.stack, .tbl.stack tbody, .tbl.stack tfoot { display: block; width: 100%; }
  .tbl.stack tr { display: block; position: relative; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  .tbl.stack tbody tr:last-child { border-bottom: 0; }
  .tbl.stack tbody tr:hover { background: transparent; }
  .tbl.stack td { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 4px 0; border: 0; text-align: right; min-height: 26px; }
  .tbl.stack td::before { content: attr(data-label); flex: none; max-width: 48%; text-align: left; font-size: 11px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
  .tbl.stack td:not([data-label])::before, .tbl.stack td[data-label=""]::before { content: none; }
  .tbl.stack td:not([data-label]), .tbl.stack td[data-label=""] { justify-content: flex-end; }
  .tbl.stack td:first-child { display: block; text-align: left; font-size: 15px; padding: 0 0 8px; }
  .tbl.stack td:first-child::before { content: none; }
  .tbl.stack td[colspan] { display: block; text-align: left; padding: 0; }
  .tbl.stack tr:has(td[colspan]:only-child) { padding: 8px 14px; background: #f8fbfe; }
  .tbl.stack td .sub { text-align: inherit; }
  .tbl.stack td:first-child .sub { margin-top: 2px; }
  .tbl.stack tfoot tr { background: #f6faff; border-top: 2px solid var(--line); }
  .tbl.stack tfoot td { border: 0; padding: 4px 0; }
  .tbl.stack tfoot td:empty { display: none; }
  .tbl.stack .progress { width: 100%; max-width: 180px; }
  .tbl.stack tr.row-warn { background: #fff8f8; }
  .tbl.stack tr.row-filled { background: #f2fbff; }

  /* جداول الإدخال (بنود الفاتورة / التركيبة): كل بند كارت، والخانات تحت بعض */
  .buy-lines { table-layout: auto; }
  .tbl.lines.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 14px 52px 14px 14px; }
  .tbl.lines.stack td { display: block; padding: 0; text-align: left; min-height: 0; }
  .tbl.lines.stack td::before { display: block; max-width: none; margin-bottom: 4px; }
  .tbl.lines.stack td:first-child { grid-column: 1 / -1; font-size: inherit; padding: 0; }
  .tbl.lines.stack td:first-child[data-label]::before { content: attr(data-label); }
  .tbl.lines.stack td.num { text-align: left; font-weight: 600; }
  .tbl.lines.stack td:has(> .del), .tbl.lines.stack td.td-del { position: absolute; top: 10px; right: 8px; }
  .tbl.lines.stack td:has(> .del)::before { content: none; }
  .tbl.lines.stack td:empty { display: none; }
  .tbl.lines.stack tfoot tr { padding-right: 14px; }
  .tbl.lines.stack tfoot td:first-child { grid-column: 1 / -1; font-weight: 800; }
  .tbl.lines td[style*="width"] { width: auto !important; }
  .lines .del { width: 38px; height: 38px; display: grid; place-items: center; background: var(--line-2); color: var(--muted); }
  .add-line { margin: 12px 14px 4px; white-space: normal; max-width: calc(100% - 28px); text-align: left; }

  /* جداول صغيرة من غير عناوين (مستلزمات العبوة / ملخصات) بتفضل جدول */
  .tbl:not(.stack) td, .tbl:not(.stack) th { padding: 9px 10px; }
  .tbl.lines:not(.stack) td { padding: 6px 4px; }
  .tbl.lines:not(.stack) td[style*="width:140px"] { width: 120px !important; }
  /* مستلزمات العبوة في أمر التصنيع: الصنف في سطر ، والكمية + لكل عبوة/كرتونة + مسح تحته */
  .pc-table, .pc-table tbody { display: block; width: 100%; }
  .pc-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
  .pc-table td { display: block; width: auto !important; padding: 0; }
  .pc-table td:first-child { grid-column: 1 / -1; }
  .pc-table td.td-x .del { width: 100%; height: 46px; }
  .pc-table input, .pc-table select { min-width: 0 !important; width: 100%; }
  .pc-table .input-group input { flex: 1; }

  /* الملخص اللي على اليمين */
  .sum-box .row { flex-wrap: wrap; }
  .sum-box .row.total b { font-size: 18px; }
  .pct-in input { font-size: 16px; min-height: 38px !important; }
  .sum-box .row:has(.pct-in) { flex-wrap: nowrap; }
  .sum-box .row:has(.pct-in) > span { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }

  /* المودال بيطلع من تحت زي تطبيقات الموبايل */
  dialog.modal { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 92vh; max-height: 92dvh; }
  dialog.modal[open] { animation: sheetUp .25s cubic-bezier(.2, .8, .2, 1); }
  .modal-head { padding: 16px; position: sticky; top: 0; background: #fff; z-index: 1; }
  .modal-body { padding: 16px; max-height: none; }
  .modal-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line-2); }
  .modal-foot .btn { flex: 1; }

  .alert { padding: 12px 14px; font-size: 13.5px; }
  .empty { padding: 34px 16px; }
  .bars { height: 150px; gap: 6px; }
  .bars .bar em { font-size: 9.5px; }
  .dl { grid-template-columns: 1fr 1fr; gap: 12px 14px; }
  .sheet { width: 100%; padding: 18px; min-height: 0; }
  .print-tools { position: sticky; top: 0; background: #e9eff6; z-index: 2; }
  .sheet-head { flex-direction: column; }
  .sheet-company { text-align: left; }
  .sheet-boxes { grid-template-columns: 1fr; }
  .sheet .totals { width: 100%; }
  .sheet table { font-size: 11px; }
}

/* موبايل صغير (آيفون SE وأقل) */
@media screen and (max-width: 380px) {
  .kpi .k-value { font-size: 15px; }
  .kpi .k-value small { font-size: 10px; }
  .bottom-nav span { font-size: 9.5px; }
  .page-title h1 { font-size: 16px; }
  .tbl.lines.stack tr { grid-template-columns: 1fr; }
  .pc-table tr { grid-template-columns: minmax(0, 1fr) 44px; }
  .pc-table td.td-x { grid-column: 2; grid-row: 2; }
}

/* ============================================================
   الزووم والتابلت: جداول البنود (بيع / شراء / طلب إنتاج) بتتحول لكروت
   لما المكان اللي هي فيه يضيق — مش حسب حجم الشاشة — فمفيش خانة تتزنق أو تركب على اللي جنبها
   (لو المتصفح قديم ومش بيدعم ده ، الجدول بيتسحب يمين وشمال زي الأول)
   ============================================================ */
.table-wrap:has(> .tbl.lines.fit) { container-type: inline-size; }
@container (max-width: 860px) {
  .tbl.lines.fit.stack thead { display: none; }
  .tbl.lines.fit.stack, .tbl.lines.fit.stack tbody, .tbl.lines.fit.stack tfoot { display: block; width: 100%; }
  .tbl.lines.fit.stack tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; position: relative;
    padding: 14px 56px 14px 14px; border-bottom: 1px solid var(--line-2); }
  .tbl.lines.fit.stack tbody tr:hover { background: transparent; }
  .tbl.lines.fit.stack td { display: block; padding: 0; border: 0; text-align: left; min-height: 0; width: auto !important; }
  .tbl.lines.fit.stack td::before { content: attr(data-label); display: block; margin-bottom: 4px; font-size: 11px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
  .tbl.lines.fit.stack td:not([data-label])::before, .tbl.lines.fit.stack td[data-label=""]::before { content: none; }
  .tbl.lines.fit.stack td:first-child { grid-column: 1 / -1; }
  .tbl.lines.fit.stack td.num { font-weight: 600; }
  .tbl.lines.fit.stack td:has(> .del), .tbl.lines.fit.stack td.td-del, .tbl.lines.fit.stack td:last-child:has(> .btn.del) { position: absolute; top: 10px; right: 8px; }
  .tbl.lines.fit.stack td:has(> .del)::before { content: none; }
  .tbl.lines.fit.stack td:empty { display: none; }
  .tbl.lines.fit.stack tfoot tr { padding-right: 14px; background: #f6faff; }
  .tbl.lines.fit.stack tfoot td:first-child { font-weight: 800; }
  .tbl.lines.fit.stack input, .tbl.lines.fit.stack select { min-width: 0; width: 100%; }
  .buy-lines.fit.stack { table-layout: auto; }
}
html[dir="rtl"] .tbl.lines.fit.stack td { text-align: right; }
@container (max-width: 860px) {
  html[dir="rtl"] .tbl.lines.fit.stack tr { padding: 14px 14px 14px 56px; }
  html[dir="rtl"] .tbl.lines.fit.stack td:has(> .del), html[dir="rtl"] .tbl.lines.fit.stack td:last-child:has(> .btn.del) { right: auto; left: 8px; }
}

/* الآيباد والتابلت (أي جهاز باللمس): خط الخانات 16 عشان الشاشة متعملش زووم لوحدها لما تدوس على خانة */
@media (hover: none) and (pointer: coarse) {
  input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea { font-size: 16px; }
}

@keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ============================================================
   الطباعة: أي صفحة في السيستم بتطلع كتقرير A4
   (الفواتير وأمر التشغيل ليهم شكلهم الخاص ومش بيتأثروا)
   ============================================================ */
.print-head { display: none; }
.print-btn { width: 42px; height: 42px; padding: 0; }

@page {
  size: A4;
  margin: 12mm 11mm 15mm;
  @bottom-left { content: "PURIMIX · Ingredients Matter"; font-family: Helvetica, Arial, sans-serif; font-size: 8pt; color: #8a9bb0; }
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font-family: Helvetica, Arial, sans-serif; font-size: 8pt; color: #8a9bb0; }
}

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body:not(.print-body) { background: #fff; font-size: 10.5pt; color: #10223a; }
  body:not(.print-body) .app, body:not(.print-body) .main { display: block; min-height: 0; margin: 0; }
  body:not(.print-body) .content { padding: 0; }

  /* كل اللي ليه علاقة بالشاشة بس */
  body:not(.print-body) .sidebar, body:not(.print-body) .scrim, body:not(.print-body) .topbar, body:not(.print-body) .foot,
  body:not(.print-body) .bottom-nav, body:not(.print-body) .tabs, body:not(.print-body) .no-print, body:not(.print-body) .btn,
  body:not(.print-body) .filters, body:not(.print-body) .range-bar, body:not(.print-body) .page-switch, body:not(.print-body) .alert,
  body:not(.print-body) dialog, body:not(.print-body) .k-icon, body:not(.print-body) .kpi::after, body:not(.print-body) .del,
  body:not(.print-body) .card-head:has(> .filters) { display: none !important; }

  /* رأس التقرير */
  body:not(.print-body) .print-head { display: flex; align-items: center; gap: 14px; padding-bottom: 9px; margin-bottom: 12px; border-bottom: 2.5px solid #0ea5e9; }
  .print-head img { height: 44px; }
  .print-head .ph-title { flex: 1; min-width: 0; }
  .print-head h1 { font-size: 17pt; font-weight: 800; color: #0b1f3a; line-height: 1.15; }
  .print-head p { margin: 2px 0 0; font-size: 9.5pt; color: #0369a1; font-weight: 600; }
  .print-head .ph-meta { text-align: right; font-size: 8pt; line-height: 1.5; color: #6b7f96; }
  .print-head .ph-meta b { display: block; font-size: 9.5pt; color: #0b1f3a; letter-spacing: .05em; }

  /* الترتيب: الأرقام الكبيرة صف واحد، وكل جدول بعرض الورقة */
  .grid { display: grid; gap: 7px; }
  .grid.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.g-2, .grid.g-main { display: block; }
  .grid.g-2 > *, .grid.g-main > * { margin-bottom: 10px; }
  .mb { margin-bottom: 10px; }
  .mt { margin-top: 10px; }

  /* الكروت بتتحول لأقسام تقرير */
  .card { background: none; border: 0; border-radius: 0; box-shadow: none; }
  .card + .card, .rep-card, .grid + .rep-card { margin-top: 10px; margin-bottom: 0; }
  .card-head { padding: 0 0 3px; gap: 8px; border-bottom: 1.5px solid #0b1f3a; break-after: avoid; page-break-after: avoid; }
  .card-head h2, .card-head h3 { font-size: 10.5pt; font-weight: 800; }
  .card-head h2 i, .card-head h3 i { display: none; }
  .card-head .sub { font-size: 8.5pt; }
  .card-body { padding: 6px 0 0; }
  .card-body.flush { padding: 0; }
  .table-wrap { overflow: visible; }

  .card.kpi { padding: 6px 9px; border: 1px solid #dbe6f1; border-radius: 7px; overflow: visible; break-inside: avoid; }
  .kpi .k-label { margin: 0; font-size: 7.5pt; text-transform: uppercase; letter-spacing: .05em; }
  .kpi .k-value { margin: 1px 0 0; font-size: 12pt; }
  .kpi .k-value small { font-size: 7.5pt; }
  .kpi .k-foot { margin-top: 1px; font-size: 7.5pt; }

  /* الجداول */
  table.tbl { font-size: 9pt; }
  .tbl thead { display: table-header-group; }
  .tbl tfoot { display: table-row-group; }
  .tbl th { padding: 4px 6px; font-size: 7.5pt; letter-spacing: .04em; color: #0b1f3a; background: #e8f3fb; border-bottom: 1px solid #b9d3e6; }
  .tbl td { padding: 3.5px 6px; border-bottom: 1px solid #e6edf4; }
  .tbl.compact td, .tbl.compact th { padding: 3.5px 6px; }
  .tbl tbody tr { break-inside: avoid; page-break-inside: avoid; }
  .tbl tbody tr:nth-child(even) td { background: #f8fbfe; }
  .tbl tfoot td { padding: 4px 6px; border-top: 1.5px solid #0b1f3a; border-bottom: 0; background: none; }
  .tbl td .sub { font-size: 7.5pt; }
  .tbl a, .tbl .code, .tbl a.row-link { color: inherit; text-decoration: none; }
  .tbl tr.row-warn td { background: #fff6f6; }
  .pill { padding: 0 5px; font-size: 7.5pt; background: none; border: 0; }
  .pill i { display: none; }
  .tag { padding: 0 4px; font-size: 7.5pt; }

  .sum-box { gap: 3px; font-size: 9.5pt; max-width: 110mm; }
  .sum-box .row.total { padding-top: 5px; font-size: 10.5pt; }
  .sum-box .row.total b { font-size: 11.5pt; }
  .sum-box .row.sub-total { padding: 3px 0; }
  .rep-bar { margin-bottom: 5px; break-inside: avoid; }
  .rep-bar > div { font-size: 9pt; }
  .rep-bar > i { height: 5px; margin-top: 2px; }
  .empty { padding: 8px 0; flex-direction: row; font-size: 9pt; }
  .empty i, .empty span { display: none; }
  .empty b { font-size: 9pt; font-weight: 500; }
  .move-sum { gap: 7px; }
  .move-sum > div { padding: 6px 9px; border-radius: 7px; break-inside: avoid; }
  .move-sum b { font-size: 12pt; }
  .steps, .wh-pick { display: none; }
}

/* ============================================================
   أصحاب الأصناف + بيانات دخول العميل (صفحات الإدارة)
   ============================================================ */
.tbl tr.row-changed td { background: #effaf4; }
.cred-box { margin-bottom: 16px; padding: 14px 16px; border-radius: 14px; background: var(--green-bg); border: 1px solid #bfeedd; }
.cred-title { font-weight: 700; color: #065f46; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.cred-row { display: flex; gap: 12px; padding: 3px 0; font-size: 13.5px; }
.cred-row span { width: 80px; color: var(--muted); flex: none; }
.cred-row b { word-break: break-all; color: var(--navy-900); }
.acc-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.acc-row:first-of-type { padding-top: 0; }
.acc-who { flex: 1; min-width: 140px; display: flex; flex-direction: column; }
.acc-who small { color: var(--muted); font-size: 12px; }
.acc-actions { display: flex; gap: 4px; }
.acc-actions form { margin: 0; }
.acc-new { margin-top: 12px; }
.acc-new summary { cursor: pointer; font-weight: 700; color: var(--sky-700); display: inline-flex; gap: 8px; align-items: center; list-style: none; }
.acc-new summary::-webkit-details-marker { display: none; }
.pt-link { font-size: 12px; background: var(--sky-50); padding: 6px 9px; border-radius: 8px; color: var(--navy-900); word-break: break-all; }
.pt-chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============================================================
   بوابة العميل (portal.php)
   ============================================================ */
body.portal { background: var(--bg, #f4f8fc); min-height: 100vh; display: flex; flex-direction: column; }
.pt-wrap { width: min(1180px, 100%); margin: 0 auto; padding-left: 24px; padding-right: 24px; }
.pt-head { background: linear-gradient(135deg, var(--navy-900), #12325c); color: #fff; box-shadow: 0 6px 24px rgba(11, 31, 58, .18); position: sticky; top: 0; z-index: 30; }
.pt-bar { display: flex; align-items: center; gap: 16px; padding-top: 14px; padding-bottom: 12px; }
.pt-bar .spacer { flex: 1; }
.pt-brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.pt-brand img { height: 34px; width: auto; }
.pt-brand b { font-size: 21px; font-weight: 800; letter-spacing: -.02em; margin-left: -4px; }
.grid.pt-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pt-brand span { font-size: 12px; font-weight: 600; color: #9fc3e4; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .2); }
.pt-who { display: flex; align-items: center; gap: 10px; }
.pt-who b { display: block; font-size: 14px; }
.pt-who small { display: block; font-size: 11.5px; color: #9fc3e4; }
.pt-out { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; color: #cfe3f5; background: rgba(255, 255, 255, .08); font-weight: 600; font-size: 13px; }
.pt-out:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.pt-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.pt-tabs::-webkit-scrollbar { display: none; }
.pt-tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 11px 16px 13px; color: #9fc3e4; font-weight: 600; font-size: 13.5px; border-bottom: 3px solid transparent; white-space: nowrap; }
.pt-tabs a:hover { color: #fff; }
.pt-tabs a.on { color: #fff; border-bottom-color: var(--sky-300, #7dd3fc); }
.pt-main { flex: 1; padding-top: 24px; padding-bottom: 30px; }
.pt-kpis a.kpi { color: inherit; transition: transform .15s; }
.pt-kpis a.kpi:hover { transform: translateY(-2px); }
.pt-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pt-facts div { padding: 10px 12px; border-radius: 12px; background: var(--sky-50); border: 1px solid var(--sky-100); }
.pt-facts span { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pt-facts b { display: block; margin-top: 2px; font-size: 16px; color: var(--navy-900); }
.pt-foot { text-align: center; }
@media screen and (max-width: 700px) {
  .pt-wrap { padding-left: 16px; padding-right: 16px; }
  .pt-brand span, .pt-who small, .pt-out span { display: none; }
  .pt-who b { font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pt-tabs a { padding: 10px 12px 12px; font-size: 13px; }
  .grid.pt-kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
  .pt-kpis .kpi:last-child { grid-column: span 2; }
  .pt-kpis .kpi { padding: 14px; }
  .pt-kpis .k-value { font-size: 19px; }
}
@media print {
  .pt-head, .pt-kpis, .pt-foot, .pt-main .btn-row { display: none !important; }
  .pt-wrap { width: auto; padding: 0; }
  .pt-main { padding: 0; }
}

/* ============================================================
   صاحب البضاعة (PURIMIX / عميل): فاتورة الشراء + المخزون
   ============================================================ */
.buy-lines .c-owner { width: 150px; }
.buy-lines .c-x { width: 76px; }
.lines .i-split { border: 0; background: transparent; color: #b8c6d6; cursor: pointer; padding: 8px; border-radius: 8px; font-size: 13px; }
.lines .i-split:hover { color: var(--sky-700); background: var(--sky-50); }
.tbl tr.row-cust td { background: #f7f5ff; }
.own-tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; margin: 2px 4px 2px 0; border-radius: 7px; background: #efebff; color: #5b47d6; font-size: 11.5px; font-weight: 600; }
.own-tag b { color: #3f2fb0; }
@media screen and (max-width: 700px) {
  .lines .i-split { width: 38px; height: 38px; display: inline-grid; place-items: center; background: var(--line-2); color: var(--muted); margin-right: 6px; }
}

/* ============================================================
   قايمة المهام (الداشبورد)
   ============================================================ */
.todo { overflow: hidden; }
.todo > .card-head { padding: 14px 20px; gap: 10px; }
.td-tabs { display: flex; gap: 2px; padding: 3px; background: var(--line-2); border-radius: 10px; flex-wrap: wrap; }
.td-tabs button { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); padding: 5px 10px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.td-tabs button:hover { color: var(--ink-2); }
.td-tabs button.on { background: #fff; color: var(--navy-900); box-shadow: 0 1px 3px rgba(11, 31, 58, .12); }
.td-tabs em { font-style: normal; font-size: 10.5px; font-weight: 700; min-width: 18px; padding: 0 5px; line-height: 17px; border-radius: 99px; background: #fff; color: var(--ink-2); text-align: center; }
.td-tabs button.on em { background: var(--sky-50); color: var(--sky-700); }
.td-tabs em.warn { background: var(--amber-bg); color: #b45309; }
.td-bar { height: 3px; background: var(--line-2); }
.td-bar span { display: block; height: 100%; width: 0; background: var(--green); transition: width .4s ease; }

.td-add { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--line-2); }
.td-add .td-in { flex: 1; min-width: 0; min-height: 36px; padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.td-add .td-date { width: 150px; flex: none; min-height: 36px; padding: 6px 10px; font-size: 13px; border-radius: 9px; color: var(--ink-2); }
.td-flag-in { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #d7e3ef; border-radius: 9px; color: #9fb1c4; cursor: pointer; flex: none; font-size: 13px; transition: all .15s; }
.td-flag-in:hover { color: var(--red); border-color: #f6caca; }
.td-flag-in input { position: absolute; opacity: 0; pointer-events: none; }
.td-flag-in:has(input:checked) { color: #fff; background: var(--red); border-color: var(--red); }
.td-add .btn { flex: none; min-height: 36px; }

.td-list { list-style: none; margin: 0; padding: 4px 10px; max-height: 300px; overflow-y: auto; }
.td-list:empty { display: none; }
.td-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; transition: background .15s, opacity .25s; min-height: 40px; }
.td-item + .td-item { border-top: 1px solid var(--line-2); }
.td-item:hover { background: #f7fbff; }
.td-check { flex: none; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid #b8c8da; background: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent; font-size: 10px; transition: all .15s; }
.td-check:hover { border-color: var(--green); color: var(--green); }
.td-item.done .td-check, .td-item.ticking .td-check { background: var(--green); border-color: var(--green); color: #fff; }
.td-item.ticking { opacity: .45; }
.td-body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.td-text { font-size: 13.5px; font-weight: 500; color: var(--ink); word-break: break-word; cursor: text; }
.td-item.hi .td-text { font-weight: 700; }
.td-item.done .td-text { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.td-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.td-chip i { font-size: 9.5px; }
.td-chip.late { background: var(--red-bg); color: #c62828; }
.td-chip.now { background: var(--amber-bg); color: #b45309; }
.td-chip.ok { background: var(--green-bg); color: #047857; }
.td-acts { display: flex; gap: 0; flex: none; }
.td-acts button { width: 26px; height: 26px; border: 0; background: none; border-radius: 7px; color: #9fb1c4; cursor: pointer; font-size: 11.5px; opacity: 0; transition: opacity .15s; }
.td-item:hover .td-acts button, .td-item:focus-within .td-acts button, .td-acts .td-flag.on { opacity: 1; }
.td-acts button:hover { background: var(--line-2); color: var(--ink-2); }
.td-acts .td-flag.on { color: var(--red); }
.td-acts .td-del:hover { color: var(--red); background: var(--red-bg); }
.td-edit { flex: 1; min-width: 140px; min-height: 32px !important; padding: 5px 10px !important; font-size: 13.5px !important; border-color: var(--sky-400) !important; border-radius: 8px !important; }
.td-edit-due { width: 140px !important; flex: none; min-height: 32px !important; padding: 4px 8px !important; font-size: 12.5px !important; border-radius: 8px !important; }
.td-empty { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px 20px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; text-align: center; }
.td-empty i { color: var(--green); font-size: 15px; }
.td-empty b { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.td-foot { display: flex; justify-content: flex-end; padding: 4px 16px 10px; }
.td-clear { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--red); padding: 5px 10px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.td-clear:hover { background: var(--red-bg); }
.td-err { margin: 0 20px 12px; padding: 8px 12px; border-radius: 9px; background: var(--red-bg); color: #b91c1c; font-size: 12.5px; font-weight: 600; }
@media (hover: none) { .td-acts button { opacity: 1; } }
@media (max-width: 700px) {
  .todo > .card-head { padding: 12px 14px; }
  .td-tabs { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .td-tabs button, .td-tabs a { justify-content: center; padding: 6px 8px; }
  .td-add { padding: 10px 14px; flex-wrap: wrap; }
  .td-add .td-in { flex-basis: 100%; }
  .td-add .td-date { flex: 1; width: auto; }
  .td-list { padding: 4px 4px; }
}

/* ============================================================
   طلبات الإنتاج (البوابة + الإدارة)
   ============================================================ */
.nav-badge.red { background: var(--red); }
.td-tabs a { font-size: 12px; font-weight: 600; color: var(--muted); padding: 5px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.td-tabs a:hover { color: var(--ink-2); }
.td-tabs a.on { background: #fff; color: var(--navy-900); box-shadow: 0 1px 3px rgba(11, 31, 58, .12); }
.td-tabs a.on em { background: var(--sky-50); color: var(--sky-700); }
.bell-btn { position: relative; flex: none; padding: 0 12px; color: var(--red); border-color: #f6caca; }
.bell-btn:hover { color: var(--red); border-color: var(--red); }
.bell-btn i { animation: bell 2.4s ease-in-out infinite; }
.bell-btn em { position: absolute; top: -6px; right: -6px; font-style: normal; font-size: 10.5px; font-weight: 800; min-width: 18px; line-height: 18px; padding: 0 5px; border-radius: 99px; background: var(--red); color: #fff; text-align: center; }
@keyframes bell { 0%, 70%, 100% { transform: rotate(0); } 75% { transform: rotate(14deg); } 82% { transform: rotate(-12deg); } 89% { transform: rotate(8deg); } }
.req-alert { border-color: #f6caca; overflow: hidden; }
.req-alert > .card-head { padding: 12px 20px; background: #fff7f7; border-bottom-color: #fbe1e1; }
.req-alert > .card-head h2 { font-size: 15px; }
.req-alert > .card-head h2 i { color: var(--red); }
.req-list { list-style: none; margin: 0; padding: 4px 10px; }
.req-list li + li { border-top: 1px solid var(--line-2); }
.req-list a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; color: var(--ink); }
.req-list a:hover { background: #f7fbff; }
.req-list .code { font-weight: 700; color: var(--sky-700); font-size: 12.5px; flex: none; }
.rq-main { flex: 1; min-width: 0; }
.rq-main b { display: block; font-size: 13.5px; }
.rq-main small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rq-due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rq-due b { color: var(--ink-2); }
.req-list a > i { color: #9fb1c4; font-size: 11px; }
.tbl tr.row-new td { background: #fff9f2; }
.tbl tr.row-new td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.pr-lines td { vertical-align: top; }
.pr-lead { margin: 0 0 14px; font-size: 14.5px; color: var(--ink-2); }
.pr-note { padding: 10px 14px; border-radius: 10px; background: #f6f9fc; border: 1px solid var(--line-2); }
.pr-note + .pr-note { margin-top: 10px; }
.pr-note.reply { background: var(--sky-50); border-color: var(--sky-100); }
.pr-note span { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pr-note p { margin: 4px 0 0; }
.help-list { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--ink-2); }
@media (max-width: 700px) {
  .rq-due { display: none; }
  .bell-btn { padding: 0 10px; }
}

/* زرار اللغة في بوابة العملاء */
.pt-lang { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .08);
  color: #e6f2fc; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; flex: none; }
.pt-lang:hover { background: rgba(255, 255, 255, .16); color: #fff; }
html[lang="ar"] .pt-lang span { font-family: 'Plus Jakarta Sans', sans-serif; }
html:not([lang="ar"]) .pt-lang span { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; font-size: 14px; }
.auth-form { position: relative; }
.auth-lang { position: absolute; top: calc(18px + env(safe-area-inset-top)); right: 18px; }
html[dir="rtl"] .auth-lang { right: auto; left: 18px; }
html[dir="rtl"] .pt-brand b { margin-left: 0; margin-right: -4px; }
html[dir="rtl"] .pt-brand span { padding-left: 0; border-left: 0; padding-right: 12px; border-right: 1px solid rgba(255, 255, 255, .2); }
html[dir="rtl"] .pt-tabs a { font-family: inherit; }
@media (max-width: 700px) { .pt-lang { padding: 7px 10px; } .pt-lang i { display: none; } .pt-bar { gap: 10px; } }
@media (max-width: 440px) { .pt-who > span:not(.avatar) { display: none; } .pt-brand img { height: 30px; } .pt-brand b { font-size: 19px; } }

/* ============================================================
   زرار اللغة + الواجهة العربي (من اليمين للشمال)
   ============================================================ */
.lang-btn { flex: none; gap: 7px; font-weight: 700; }
.lang-btn span { font-size: 13px; }
html[lang="ar"] .lang-btn span { font-family: 'Plus Jakarta Sans', sans-serif; }
html:not([lang="ar"]) .lang-btn span { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; font-size: 14px; }
@media (max-width: 640px) { .lang-btn { padding: 0 10px; } .lang-btn i { display: none; } }

html[dir="rtl"] body { font-family: 'Plus Jakarta Sans', 'Cairo', system-ui, 'Segoe UI', Tahoma, sans-serif; }
html[dir="rtl"] * { letter-spacing: normal !important; }   /* المسافات بين الحروف بتقطّع الحروف العربي */
html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
html[dir="rtl"] .main { margin-left: 0; margin-right: var(--side-w); }
html[dir="rtl"] .nav-badge { margin-left: 0; margin-right: auto; }
html[dir="rtl"] .bell-btn em { right: auto; left: -6px; }
html[dir="rtl"] .req-list a > i { transform: scaleX(-1); }
html[dir="rtl"] .tbl tr.row-new td:first-child { box-shadow: inset -3px 0 0 var(--amber); }
html[dir="rtl"] .help-list { padding-left: 0; padding-right: 18px; }
html[dir="rtl"] .quick .caret { margin-left: 0; margin-right: 2px; }
html[dir="rtl"] .quick-menu { right: auto; left: 0; }
html[dir="rtl"] .hero::after { right: auto; left: -40px; transform: rotate(8deg) scaleX(-1); }
html[dir="rtl"] .kpi::after { right: auto; left: -30px; }
html[dir="rtl"] .num, html[dir="rtl"] .tbl .num, html[dir="rtl"] .tbl th.num { text-align: left; }
html[dir="rtl"] .tbl th { text-align: right; }
html[dir="rtl"] select { padding-right: 14px; padding-left: 34px; background-position: left 12px center; }
html[dir="rtl"] .input-group input { border-radius: 11px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
html[dir="rtl"] .input-group .addon { border-left: 1px solid #d7e3ef; border-right: 0; border-radius: 11px 0 0 11px; }
html[dir="rtl"] .input-group .unit-sel { border-left: 1px solid #d7e3ef; border-right: 0; border-radius: 11px 0 0 11px; }
html[dir="rtl"] .price-wrap input { border-radius: 11px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
html[dir="rtl"] .price-wrap .s-clear { border-left: 1px solid #d7e3ef; border-right: 0; border-radius: 11px 0 0 11px; }
html[dir="rtl"] .alert ul { padding-left: 0; padding-right: 18px; }
html[dir="rtl"] .sum-box .row span i, html[dir="rtl"] .income-card .sum-box .row span i, html[dir="rtl"] .legend i { margin-right: 0; margin-left: 6px; }
html[dir="rtl"] .pct-in { margin-left: 0; margin-right: 6px; }
html[dir="rtl"] .page-switch .switch-pick, html[dir="rtl"] .range-presets { margin-left: 0; margin-right: auto; }
html[dir="rtl"] .step-no { margin-right: 0; margin-left: 2px; }
html[dir="rtl"] .lines .i-split { margin-right: 0; margin-left: 6px; }
html[dir="rtl"] .fa-arrow-right, html[dir="rtl"] .fa-arrow-left, html[dir="rtl"] .fa-chevron-right, html[dir="rtl"] .fa-chevron-left,
html[dir="rtl"] .fa-arrow-right-from-bracket, html[dir="rtl"] .fa-right-left { transform: scaleX(-1); }
html[dir="rtl"] input[type="date"], html[dir="rtl"] input[inputmode="decimal"], html[dir="rtl"] input[inputmode="numeric"] { direction: ltr; text-align: right; }
html[dir="rtl"] input.num { text-align: left; }
@media screen and (max-width: 1024px) {
  html[dir="rtl"] .sidebar { transform: translateX(105%); }
  html[dir="rtl"] .sidebar.open { transform: none; }
  html[dir="rtl"] .side-close { right: auto; left: 14px; }
  html[dir="rtl"] .main { margin-right: 0; }
}
@media screen and (max-width: 700px) {
  html[dir="rtl"] .card-head > .btn, html[dir="rtl"] .card-head > form:not(.filters) { margin-left: 0; margin-right: auto; }
  html[dir="rtl"] .tbl.stack td { text-align: left; }
  html[dir="rtl"] .tbl.stack td::before { text-align: right; }
  html[dir="rtl"] .tbl.stack td:first-child, html[dir="rtl"] .tbl.stack td[colspan],
  html[dir="rtl"] .tbl.lines.stack td, html[dir="rtl"] .tbl.lines.stack td.num { text-align: right; }
  html[dir="rtl"] .tbl.lines.stack td:has(> .del), html[dir="rtl"] .tbl.lines.stack td.td-del { right: auto; left: 8px; }
  html[dir="rtl"] .tbl.lines.stack tfoot tr { padding-right: 0; padding-left: 14px; }
}

/* طلب مسح من العميل */
.pr-cancel { align-items: center; flex-wrap: wrap; }
.pr-cancel > span { flex: 1 1 220px; }
.pr-cancel form { margin-left: auto; }
[dir=rtl] .pr-cancel form { margin-left: 0; margin-right: auto; }

/* خانة التاريخ على الآيفون: سفاري بيديها عرض ثابت فبتطلع برا الكارت */
input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; box-sizing: border-box; }
input[type=date]::-webkit-date-and-time-value { text-align: inherit; min-height: 1.2em; }
.field { min-width: 0; }

/* الفاتورة بالعربي (بوابة العميل) */
html[dir="rtl"] .sheet-company, html[dir="rtl"] .sheet-meta { text-align: left; }
html[dir="rtl"] .sheet th { text-align: right; }
html[dir="rtl"] .sheet th.num, html[dir="rtl"] .sheet td.num { text-align: left; }
html[dir="rtl"] .sheet .totals { margin-left: 0; margin-right: auto; }
html[dir="rtl"] .sheet-title h2 small, html[dir="rtl"] .sheet-box span, html[dir="rtl"] .sheet th { letter-spacing: 0; }
html[dir="rtl"] .sheet .num, html[dir="rtl"] .sheet .totals b, html[dir="rtl"] .sheet .totals .grand span:last-child { direction: ltr; unicode-bidi: isolate; }
@media (max-width: 700px) { html[dir="rtl"] .sheet-company { text-align: right; } }
/* النصوص اللي فيها إنجليزي وعربي مع بعض (اسم المنتج ، التليفون ، العنوان) تتعرض صح */
html[dir="rtl"] .sheet td, html[dir="rtl"] .sheet-box div, html[dir="rtl"] .sheet-box b { unicode-bidi: plaintext; }
html[dir="rtl"] .sheet td, html[dir="rtl"] .sheet-box div, html[dir="rtl"] .sheet-box b { text-align: right; }
html[dir="rtl"] .sheet td.num { text-align: left; }
html[dir="rtl"] .sheet-company span { direction: ltr; unicode-bidi: isolate; }

/* ===== دليل النظام (help.php / portal_help.php) ===== */
.hp-wrap { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 18px; align-items: start; }
.hp-toc { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.hp-toc nav { display: flex; flex-direction: column; margin-top: 10px; }
.hp-toc nav b { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--sky-600); margin: 10px 8px 4px; }
.hp-toc nav a { padding: 6px 10px; border-radius: 9px; color: var(--ink-2); font-size: 13.5px; }
.hp-toc nav a:hover { background: #f1f7fd; color: var(--ink); }
.hp-main { min-width: 0; }
.hp-group { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--sky-600); margin: 22px 4px 10px; }
.hp-sec { margin-bottom: 14px; scroll-margin-top: 84px; }
.hp-sec .card-head h3 { display: flex; align-items: center; gap: 8px; }
.hp-body { font-family: 'Cairo', 'Plus Jakarta Sans', sans-serif; line-height: 1.85; font-size: 14.5px; }
.hp-body ul, .hp-body ol { margin: 6px 0; padding-inline-start: 22px; }
.hp-body li { margin: 3px 0; }
.hp-sum { font-size: 15px; margin: 0 0 6px; }
.hp-lbl { font-weight: 700; color: var(--navy-900); margin-top: 8px; }
.hp-note { display: flex; gap: 10px; background: #fff8e8; border: 1px solid #fbe2b0; border-radius: 12px; padding: 8px 12px; margin-top: 10px; }
.hp-note > i { color: #d97706; margin-top: 7px; }
.hp-note ul { margin: 0; flex: 1; }
.hp-sub { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; scroll-margin-top: 84px; }
.hp-sub h4 { margin: 0 0 4px; font-size: 15px; color: var(--navy-900); display: flex; align-items: center; gap: 8px; }
.hp-sub h4 a { color: var(--sky-500); font-size: 12px; }
.hp-badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; font-family: 'Cairo', sans-serif; }
.hp-badge.new { background: var(--green-bg); color: #047857; }
.hp-badge.upd { background: var(--amber-bg); color: #b45309; }
.hp-missing { border-style: dashed; }
.hp-empty { color: #b45309; margin: 0; }
.hp-meta { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; font-family: 'Cairo', sans-serif; }
.hp-meta i { color: var(--sky-500); }
.hp-meta .btn { margin-inline-start: auto; }
.hp-warn { margin-top: 10px; background: var(--amber-bg); color: #92400e; border-radius: 10px; padding: 8px 12px; font-family: 'Cairo', sans-serif; }
.hp-recent { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-family: 'Cairo', sans-serif; }
.hp-recent a { background: #eef6fd; border-radius: 99px; padding: 3px 11px; font-size: 13px; }
.hp-none { text-align: center; color: var(--ink-2); padding: 20px; font-family: 'Cairo', sans-serif; }
.hp-flow { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.hp-flow > div { position: relative; background: #f4f9fe; border: 1px solid #dceaf6; border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.hp-flow > div > span { position: absolute; top: 8px; left: 10px; font-size: 11px; font-weight: 800; color: var(--sky-600); }
.hp-flow > div > i { color: var(--sky-500); font-size: 18px; margin-bottom: 4px; }
.hp-flow small { color: var(--ink-2); line-height: 1.6; }
.hp-log .hp-day { margin-bottom: 10px; }
.hp-st td { vertical-align: middle; }
@media (max-width: 900px) {
  .hp-wrap { grid-template-columns: 1fr; }
  .hp-toc { position: static; max-height: none; }
  .hp-toc nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .hp-toc nav b { width: 100%; margin: 6px 4px 0; }
}
@media print { .hp-wrap { display: block; } .hp-sec { break-inside: avoid; } [data-hp][hidden] { display: block !important; } }

/* زرار الطباعة في هيدر البوابة + الطباعة بالعربي */
@media (max-width: 700px) { .pt-print span { display: none; } }
@media print {
  .pt-print, .hp-toc, #hpSearch, .hp-none { display: none !important; }
  html[dir="rtl"] .print-head .ph-meta { text-align: left; }
  .hp-body { font-size: 10pt; line-height: 1.7; }
  .hp-badge { border: 1px solid currentColor; }
}

/* بوابة العميل: منتجاتي وتركيباتي (مقفولة بباسورد) */
.fx-lock { max-width: 460px; margin: 30px auto; text-align: center; }
.fx-lock h3 { margin: 10px 0 6px; }
.fx-ico { width: 64px; height: 64px; margin: 6px auto 0; border-radius: 50%; display: grid; place-items: center; background: var(--sky-50, #e0f2fe); color: var(--sky-600, #0284c7); font-size: 26px; }
.fx-form { display: flex; gap: 8px; margin-top: 14px; }
.fx-form .field { flex: 1; margin: 0; }
.fx-admin { border: 1px dashed var(--line, #dbe3ee); border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; }
.fx-admin .sub { display: block; }
.st-note { font-style: italic; }
@media print { .fx-lock { display: none; } }

.fx-admin { scroll-margin-top: 90px; transition: box-shadow .3s, border-color .3s; }
.flash-hl { border-color: var(--sky-500, #0ea5e9) !important; box-shadow: 0 0 0 4px rgba(14,165,233,.25); }
