:root {
  --navy: #1F3A5F;
  --navy-2: #2C4E78;
  --navy-dark: #142842;
  --orange: #C2410C;
  --orange-dark: #9A3412;
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --line: #E2E5EA;
  --line-2: #EEF0F3;
  --input: #CBD2DC;
  --text: #1A1F27;
  --muted: #5B6472;
  --chip: #EEF2F7;
  --red: #9B1C1C;
  --red-bg: #FDECEC;
  --amber: #7A4510;
  --amber-bg: #FEF3C7;
  --amber-line: #F3D08A;
  --green: #1F6B3A;
  --green-bg: #E7F5EC;
  --sans: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--navy); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

#app { max-width: 600px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- الرأس ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 12px;
  background: var(--navy); color: #FFFFFF;
}
.top h1 { flex: 1; min-width: 0; margin: 0; font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { display: block; font-size: 12px; font-weight: 400; color: #D5DEEA; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 22px; background: transparent; color: inherit; cursor: pointer;
}
.top .icon-btn.solid { background: var(--navy-2); }
.badge-role { padding: 5px 10px; border-radius: 14px; background: var(--navy-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.brand { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.wordmark { font-family: var(--mono); font-weight: 600; font-size: 20px; letter-spacing: .2px; direction: ltr; text-align: right; }
.wordmark b { color: #F7A072; font-weight: 600; }
.tagline { font-size: 12px; color: #D5DEEA; }

/* ---------- المحتوى ---------- */
main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 12px 12px calc(92px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.card.flush { padding: 4px 12px; }
.card h2, .section-title { margin: 0; font-size: 15px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 600; line-height: 1.3; }
.stat .v.red { color: var(--red); }
.stat .h { font-size: 11px; color: var(--muted); }
.stat .v small { font-size: 13px; font-weight: 500; }

.banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px;
  background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber);
  font-size: 13px; font-weight: 500; text-decoration: none;
}
.banner.info { background: #EEF2F7; border-color: #D5DEEA; color: var(--navy); }
.banner.ok { background: var(--green-bg); border-color: #BFE3CC; color: var(--green); }
.banner.err { background: var(--red-bg); border-color: #F3C2C2; color: var(--red); }

/* ---------- القوائم ---------- */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line-2);
  text-decoration: none; color: var(--text); background: none; border-top: 0; border-left: 0; border-right: 0;
  width: 100%; text-align: right; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .t1 { font-size: 14px; font-weight: 500; }
.item .t2 { font-size: 13px; color: #3F4752; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .t3 { font-size: 12px; color: var(--muted); }
.item .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.eqcode { font-family: var(--mono); font-weight: 500; direction: ltr; unicode-bidi: isolate; }
.empty { padding: 18px 8px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- الشارات ---------- */
.ty { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.ty-repair { background: #FFEDD5; color: #9A3412; }
.ty-pm { background: #E0ECFA; color: #1F3A5F; }
.ty-insp { background: #EDE7F6; color: #5B2A86; }
.ty-follow { background: #EEF0F3; color: #3F4752; }
.ty-admin { background: #DDF3F1; color: #0F5C5A; }
.ty-none { background: #F3F4F6; color: var(--muted); border: 1px dashed var(--input); }
.rv { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.rv::before { content: ''; width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.rv-high { color: #B91C1C; }
.rv-normal { color: #B45309; }
.rv-done { color: var(--green); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; background: var(--chip); color: var(--navy); font-size: 12px; }
.tag.warn { background: var(--amber-bg); color: var(--amber); }
.iso { font-family: var(--mono); font-size: 12px; padding: 2px 6px; border-radius: 6px; background: var(--chip); color: var(--navy); direction: ltr; }

/* ---------- النماذج ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 0 12px;
  font-family: inherit; font-size: 16px; color: var(--text);
  background: #FFFFFF; border: 1px solid var(--input); border-radius: 10px;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5l5-5' fill='none' stroke='%235B6472' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: left 12px center; background-size: 12px 8px; background-repeat: no-repeat; padding-left: 32px;
}
textarea { padding: 10px 12px; line-height: 1.6; min-height: 84px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; padding: 0; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--navy); }
input[type="date"], input[type="datetime-local"] { padding: 0 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8FB1DA; outline-offset: 0; border-color: var(--navy); }
/* حقول الكتابة: الاتجاه يتبدل حسب النص (app.js، fitDir)، والنص يبقى يمين حتى ما يطفر لمن يتبدل */
:where(input[data-bidi], textarea[data-bidi]) { text-align: right; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.code-input { text-align: center; font-family: var(--mono); font-size: 20px; letter-spacing: 1px; text-transform: uppercase; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--input); background: #FFFFFF; color: var(--text);
  font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.chip .iso-code { font-family: var(--mono); font-size: 12px; color: var(--muted); direction: ltr; }
.chip[aria-pressed="true"], .chip.on { background: var(--navy); border-color: var(--navy); color: #FFFFFF; }
.chip[aria-pressed="true"] .iso-code, .chip.on .iso-code { color: #D5DEEA; }
.chip.dashed { border-style: dashed; border-color: #8A94A3; }
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll .chip { flex: none; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--chip); }
.seg button { min-height: 44px; border: none; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; padding: 0 4px; }
.seg button[aria-pressed="true"] { background: #FFFFFF; color: var(--navy); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }

.parts-rows { display: flex; flex-direction: column; gap: 8px; }
.part-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 44px; gap: 6px; align-items: center; }
.part-row input[name="pqty"] { direction: ltr; text-align: left; }
/* القطعة من المخزن: سطر الربط وقائمة الاختيار تحت القطعة */
.part-row .part-link, .part-row .part-sug { grid-column: 1 / -1; }
.part-link { display: flex; align-items: center; gap: 8px; margin-top: -2px; font-size: 13px; color: var(--navy); }
.part-link > svg { width: 16px; height: 16px; flex: none; }
.part-link .loc { margin-top: 0; }
.part-sug { display: flex; flex-direction: column; max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: 0 4px 14px rgba(15, 23, 42, .08); }
.sug { flex: none; display: flex; flex-direction: column; align-items: stretch; gap: 3px; min-height: 48px; padding: 8px 10px; border: 0;
  border-bottom: 1px solid var(--line-2); background: none; color: var(--text); font: inherit; text-align: right; cursor: pointer; }
.sug:last-child { border-bottom: 0; }
.sug:hover, .sug:active { background: #F8FAFC; }
.sug .t1 { font-size: 14px; font-weight: 500; }
.sug .t3 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; color: var(--muted); }
.sug .loc { margin-top: 0; }
.tag > svg { width: 14px; height: 14px; flex: none; }

.duration { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--chip); color: var(--navy); font-size: 13px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--orange); color: #FFFFFF; }
.btn-primary:active { background: var(--orange-dark); }
.btn-navy { background: var(--navy); color: #FFFFFF; }
.btn-outline { background: #FFFFFF; border-color: var(--navy); color: var(--navy); }
.btn-plain { background: #FFFFFF; border-color: var(--input); color: var(--text); }
.btn-danger { background: #FFFFFF; border-color: #E5B4B4; color: var(--red); }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 13px; font-weight: 500; border-radius: 10px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

/* زر الحفظ ملصوق بأسفل الشاشة (الصفحات اللي بيها حفظ ما بيها شريط تنقل) */
main.no-nav { padding-bottom: 0; }
.save-bar {
  position: sticky; bottom: 0; z-index: 4;
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); margin: 0 -12px;
  background: rgba(255, 255, 255, .98); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 12px rgba(16, 24, 40, .06);
}
main.no-nav > :last-child:not(form) { margin-bottom: calc(16px + env(safe-area-inset-bottom)); }

/* «تفاصيل أكثر» بنموذج التسجيل */
details.more { padding: 0; }
details.more > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 10px 12px; font-size: 15px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary .grow { display: flex; flex-direction: column; gap: 2px; }
details.more > summary .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
details.more > summary::after {
  content: ''; flex: none; width: 9px; height: 9px; margin: 0 4px;
  border-left: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .2s;
}
details.more[open] > summary::after { transform: rotate(135deg); }
details.more > .stack { padding: 0 12px 14px; }
.now-btn { min-height: 30px; padding: 0 10px; border: none; border-radius: 15px; background: var(--chip); color: var(--navy); font-size: 12px; font-weight: 600; cursor: pointer; }

/* قائمة المعدات: مضخة بسطر واحد بيه حروفها كلها (A، B، C...)، وتحتها المواصفات */
.group-title { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.pair { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); }
.pair:last-child { border-bottom: 0; }
.pair-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pair-code { font-size: 17px; text-align: right; }
.pair-sides { display: grid; grid-template-columns: repeat(2, 84px); gap: 6px; flex: none; }
.pair-sides.one { grid-template-columns: 84px; }
.pair-specs { flex-basis: 100%; min-width: 0; padding: 6px 10px; border-radius: 8px; background: #F5F7FA; color: #3F4752; font-size: 12.5px; line-height: 1.6; }
/* سطرين بس، وكل نص بلغته (الإنگليزي من اليسار والعربي من اليمين) */
.pair-specs > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; unicode-bidi: plaintext; text-align: start; }
.pair-specs b { font-size: 12px; color: var(--navy); }
.specs-text { white-space: pre-wrap; unicode-bidi: plaintext; text-align: start; overflow-wrap: anywhere; }
.eq-side {
  width: 84px; min-height: 58px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  border: 1px solid var(--input); border-radius: 10px; background: #FFFFFF; color: var(--text); text-decoration: none;
}
a.eq-side:active { background: var(--chip); }
.side-l { font-family: var(--mono); font-weight: 600; font-size: 16px; line-height: 1.3; }
.side-c { font-size: 11px; color: var(--muted); }
.sb-n { font-size: 11px; font-weight: 600; }
.sb-n.amber { color: #B45309; }

/* صفحة المعدة: التنقل بين الحروف وزر الحرف الجديد */
.seg .seg-add { display: flex; align-items: center; justify-content: center; gap: 2px; color: var(--orange); font-weight: 600; }
.seg .seg-add svg { width: 18px; height: 18px; }
.add-specs { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); font-weight: 600; border-style: dashed; }
.add-specs > span { display: flex; flex-direction: column; }
.add-specs .hint { font-size: 12px; font-weight: 400; color: var(--muted); }

/* عدد المضخات (A، B، C...) */
.stepper { display: flex; align-items: center; gap: 8px; direction: ltr; }
.stepper .icon-btn { width: 44px; height: 44px; border: 1px solid var(--input); border-radius: 10px; background: #FFFFFF; color: var(--navy); }
.stepper-v { min-width: 28px; text-align: center; font-family: var(--mono); font-size: 18px; font-weight: 600; }
.stepper-l { flex: 1; min-width: 0; direction: rtl; text-align: right; font-family: var(--mono); color: var(--navy); font-weight: 500; overflow-wrap: anywhere; }

/* الرئيسية: أكثر المعدات تعطلاً */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 10px; min-height: 44px; text-decoration: none; color: var(--text); }
.bar-label { width: 82px; flex: none; display: flex; flex-direction: column; line-height: 1.35; }
.bar { flex: 1; height: 10px; border-radius: 5px; background: #EEF2F7; display: flex; overflow: hidden; }
.bar > span { border-radius: 5px; background: var(--navy); }
.bar-n { width: 26px; flex: none; text-align: center; font-size: 14px; font-weight: 600; }

.seg a { min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none; }
.seg a[aria-pressed="true"] { background: #FFFFFF; color: var(--navy); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }

/* ---------- تفاصيل الإدخال ---------- */
.kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px 10px; font-size: 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.hist { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.hist:last-child { border-bottom: 0; }
.hist .chg { color: #3F4752; }
.hist .old { color: var(--red); text-decoration: line-through; }
.hist .new { color: var(--green); }

.code-box {
  direction: ltr; text-align: center; font-family: var(--mono); font-size: 21px; letter-spacing: 1px;
  padding: 10px 8px; border-radius: 8px; background: var(--chip); color: var(--navy);
  -webkit-user-select: all; user-select: all; word-break: break-all;
}

/* ---------- الشريط السفلي ---------- */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  max-width: 600px; margin: 0 auto;
  display: flex; justify-content: space-around; align-items: center;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  background: #FFFFFF; border-top: 1px solid var(--line);
}
.bottom a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 56px; min-height: 44px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap;
}
.bottom a[aria-current="page"] { color: var(--navy); font-weight: 600; }
.bottom a.plus { width: 52px; min-width: 52px; height: 52px; border-radius: 26px; background: var(--orange); color: #FFFFFF; }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; }
.login .hero { background: var(--navy); color: #FFFFFF; padding: calc(env(safe-area-inset-top) + 40px) 20px 32px; display: flex; flex-direction: column; gap: 6px; }
.login .hero .wordmark { font-size: 30px; text-align: right; }
.login .hero .tagline { font-size: 15px; }
.login .body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- الإشعار ---------- */
#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 560px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: #1A1F27; color: #FFFFFF; font-size: 14px; text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--red); }

.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 28px; text-align: center; color: var(--muted); }

@media (min-width: 620px) and (max-width: 899px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* الوكيل */
.ask-q { align-self: flex-start; max-width: 92%; background: var(--chip); color: var(--navy); border-radius: 12px; padding: 8px 12px; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
.ask-a { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; font-size: 15px; }
.ask-a a { color: var(--orange); font-family: var(--mono); font-weight: 600; }
.ask-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.follow-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #FFF7ED; border: 1px solid #FED7AA; color: #7C2D12; border-radius: 10px; padding-block: 2px; padding-inline: 10px 2px; font-size: 13px; }
.follow-chip button { background: none; border: 0; min-width: 40px; min-height: 40px; color: inherit; font-size: 16px; cursor: pointer; }
.ask-samples .chip { white-space: normal; text-align: start; line-height: 1.5; padding-block: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- الأقسام بالرئيسية (التلفون): المؤشرات، الأعمال اليومية، المخزن ---------- */
.sections { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sections a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 74px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  color: var(--navy); text-decoration: none; font-size: 13px; font-weight: 600; text-align: center;
}
.sections a:active { background: var(--chip); }
.sec-badge {
  position: absolute; top: 6px; left: 8px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; background: var(--red-bg); color: var(--red); font-size: 11px; font-weight: 700;
}

/* ---------- الأعمال اليومية ---------- */
.dtext { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.75; }

/* الأعمال اليومية: علامة «مهم» والتأشير وقت التصدير (2026-11-30) */
.d-item > a.main { color: var(--text); text-decoration: none; }
.star-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin: -6px -8px -6px 0; border: 0; border-radius: 22px;
  background: none; color: #A3ABB7; cursor: pointer;
}
.star-btn.on { color: #D97706; }
.star-btn:disabled { opacity: .6; }
.star-btn:active { background: var(--chip); }
.star-mark { flex: none; display: inline-flex; color: #D97706; }
.star-mark svg { width: 17px; height: 17px; }
.star-check { gap: 8px; }
.tag.star-tag { background: #FEF3C7; color: #92400E; font-weight: 500; }
.tag.star-tag svg { width: 14px; height: 14px; color: #D97706; }
.btn.star-toggle.on { border-color: #D97706; color: #92400E; background: #FFFBEB; }
.btn.star-toggle.on svg { color: #D97706; }
.chip svg { width: 16px; height: 16px; color: #D97706; }
.chip[aria-pressed="true"] svg { color: #FCD34D; }
.chip:disabled { opacity: .45; cursor: default; }
.x-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.x-pick { max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }
.x-day { position: sticky; top: 0; z-index: 1; background: var(--card); padding: 8px 0 5px; border-bottom: 1px solid var(--line-2); font-size: 13px; font-weight: 600; color: var(--navy); }
.x-row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.x-row:last-child { border-bottom: 0; }
.x-row input { flex: none; margin-top: 1px; }
.x-text { flex: 1; min-width: 0; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.x-text .star-mark { display: inline-flex; vertical-align: -3px; margin-left: 4px; }
.x-text .star-mark svg { width: 15px; height: 15px; }
/* تقرير سجل الأعطال: سطر المعدة والنوع فوق نص الإدخال */
.r-eq { display: block; margin-bottom: 2px; }
details.more summary b svg { width: 18px; height: 18px; vertical-align: -3px; }

/* ---------- المخزن ---------- */
.tag.ok { background: var(--green-bg); color: var(--green); }
.tag.bad { background: var(--red-bg); color: var(--red); }
.tag.same { background: #F3F4F6; color: var(--muted); }
.srows { display: flex; flex-direction: column; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); }
.srow:last-child { border-bottom: 0; }
.srow .s-c, .srow.head { display: none; }
.s-name { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.s-name b { font-weight: 600; font-size: 14px; text-align: right; overflow-wrap: anywhere; }
.s-sub { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; color: var(--muted); }
.s-sub .mono, .s-pn { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
.s-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.s-bal { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.s-bal b { font-size: 20px; font-weight: 600; line-height: 1.25; }
.s-bal small { font-size: 11px; color: var(--muted); }
.s-n { font-variant-numeric: tabular-nums; }
.loc { display: inline-block; margin-top: 2px; padding: 1px 7px; border-radius: 6px; background: var(--chip); color: var(--navy); font-family: var(--mono); font-size: 12px; direction: ltr; unicode-bidi: isolate; }
.desk-inline { display: none; }

/* ---------- لوحة المؤشرات ---------- */
.kpi-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpi-filters .field { gap: 4px; }
.kpi-filters .field > label { font-size: 12px; color: var(--muted); }
.kpi-filters select { min-height: 44px; padding-right: 10px; padding-left: 26px; background-position: left 9px center; font-size: 15px; }
#kpi-body { display: flex; flex-direction: column; gap: 12px; transition: opacity .15s; }
#kpi-body.refreshing { opacity: .55; }
.how b { color: var(--navy); }

/* الأعطال حسب الشهر أو السنة: أعمدة رفيعة على خط واحد، والأرقام يمين */
.kchart { position: relative; padding-top: 4px; }
.kplot { position: relative; height: 170px; }
.kgrid, .kcols { position: absolute; inset-block: 22px 0; inset-inline: 30px 0; }
.kgl { position: absolute; inset-inline: 0; height: 1px; background: var(--line-2); }
.kgl.base { background: #C9D0DA; }
.kgl b { position: absolute; inset-inline-start: -30px; width: 24px; transform: translateY(-50%); text-align: end; font-size: 11px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.kcols { display: flex; gap: 2px; }
.kcol { position: relative; flex: 1 1 0; min-width: 0; height: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; }
.kcol:focus-visible { outline: 2px solid #8FB1DA; outline-offset: 0; border-radius: 4px; }
.kbar { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: min(24px, 70%); border-radius: 4px 4px 0 0; background: var(--navy); }
.kcol:hover .kbar, .kcol.hot .kbar { background: var(--navy-2); }
.kval { position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.kx { display: flex; gap: 2px; margin-inline-start: 30px; padding-top: 6px; }
.kx span { flex: 1 1 0; min-width: 0; text-align: center; font-size: 11px; line-height: 1.3; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kx i { display: block; font-style: normal; font-size: 10px; }
.ktip { position: absolute; top: 0; z-index: 2; transform: translateX(-50%); padding: 5px 9px; border-radius: 8px; background: #1A1F27; color: #FFFFFF; font-size: 12px; font-weight: 500; white-space: nowrap; pointer-events: none; }
.ktable { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.ktable th, .ktable td { padding: 7px 4px; border-bottom: 1px solid var(--line-2); text-align: right; }
.ktable th { font-size: 12px; font-weight: 600; color: var(--muted); }
.ktable tr > :last-child { text-align: left; }
.ktable tbody tr:last-child td { border-bottom: 0; }

/* المعدات حسب الأعطال: صف لكل معدة ينفتح على صفحتها */
.krows { display: flex; flex-direction: column; }
.krow {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .75fr) minmax(0, .8fr) minmax(0, .8fr) minmax(0, 1.15fr);
  gap: 4px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line-2);
  text-decoration: none; color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums;
}
.krow:last-child { border-bottom: 0; }
.krow.head { padding: 2px 0 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); align-items: end; }
.krow.head i { display: block; font-style: normal; font-weight: 400; font-size: 10.5px; }
.krow .c { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.krow .n { text-align: center; }
.krow .b { font-weight: 600; }
.krow .d { font-size: 12px; color: var(--muted); }

/* أشرطة الجزء ونوع العطل والجهة: الاسم أعرض، وسطرين بالأكثر */
.kbars .bar-label { width: 46%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.kbars .bar-n { width: 32px; }
.nobr { white-space: nowrap; }

/* ---------- الكمبيوتر والشاشات العريضة ----------
   بالتلفون: عمود واحد وشريط تحت. من 900px: شريط جانبي، والمحتوى يملي الشاشة بأعمدة. */
.rail-brand, .rail-user, .plus-label, .desk-only { display: none; }

@media (max-width: 899px) {
  /* الأعمدة تختفي بالتلفون، والأقسام ترجع بترتيبها الأصلي */
  .cols, .col { display: contents; }
  .o1 { order: 1; }
  .o2 { order: 2; }
  .o3 { order: 3; }
  .o4 { order: 4; }
  .o5 { order: 5; }
  .o6 { order: 6; }
  .o7 { order: 7; }
  .bottom.m-hide { display: none; }
  /* «المؤشرات» بالشريط الجانبي بس، وبالتلفون تنفتح من الرئيسية */
  .bottom a.rail-only { display: none; }
  .bottom a.parent-current { color: var(--navy); font-weight: 600; }
  .kx span.thin { visibility: hidden; }
}

@media (min-width: 900px) {
  :root { --rail: 236px; }
  #app { max-width: none; margin: 0; }
  #app.has-rail { padding-right: var(--rail); }

  /* الرأس فاتح والشريط الجانبي كحلي */
  .top { padding: 14px 28px; background: #FFFFFF; color: var(--text); border-bottom: 1px solid var(--line); }
  .top h1 { font-size: 20px; }
  .top .sub { color: var(--muted); font-size: 13px; }
  .top .icon-btn.solid { background: var(--chip); color: var(--navy); }
  .top .badge-role { background: var(--chip); color: var(--navy); }
  .top .brand { display: none; }
  .top .desk-only { display: block; }

  main { width: 100%; max-width: 1440px; margin: 0 auto; padding: 22px 28px 40px; gap: 16px; }
  main.no-nav { padding-bottom: 24px; }
  main.w-mid { max-width: 1100px; }
  main.w-narrow { max-width: 820px; }

  .bottom {
    top: 0; bottom: 0; left: auto; right: 0; width: var(--rail); max-width: none; margin: 0;
    flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 4px;
    padding: 20px 14px; background: var(--navy); border-top: 0; overflow-y: auto;
  }
  .bottom a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 14px; border-radius: 10px; font-size: 15px; color: #C9D4E3; }
  .bottom a:hover { background: rgba(255, 255, 255, .07); color: #FFFFFF; }
  .bottom a[aria-current="page"] { background: var(--navy-2); color: #FFFFFF; font-weight: 600; }
  .bottom a.plus { order: -1; width: auto; min-width: 0; height: 48px; margin: 4px 0 14px; border-radius: 12px; justify-content: center; gap: 8px; background: var(--orange); color: #FFFFFF; font-weight: 600; }
  .bottom a.plus:hover, .bottom a.plus[aria-current="page"] { background: var(--orange-dark); }
  .bottom .plus-label { display: inline; }
  .rail-brand { display: flex; flex-direction: column; gap: 2px; order: -2; padding: 4px 6px 18px; color: #FFFFFF; }
  .rail-brand .wordmark { font-size: 22px; }
  .rail-user { display: flex; flex-direction: column; gap: 2px; margin-top: auto; padding: 14px 8px 2px; border-top: 1px solid rgba(255, 255, 255, .14); color: #D5DEEA; font-size: 13px; }
  .rail-user b { color: #FFFFFF; font-weight: 600; }

  /* أعمدة */
  .cols { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .cols.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols.eq-cols { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
  .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

  .stats4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
  .stat { padding: 14px 16px; }
  .stat .v { font-size: 28px; }
  a.stat:hover { border-color: #9FB3CC; }
  .grid-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hscroll { flex-wrap: wrap; overflow: visible; }

  /* قائمة المعدات: بطاقات جنب بعض */
  .eq-group { background: transparent; border: 0; padding: 0; }
  .eq-group > .list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
  .eq-group .pair, .eq-group .pair:last-child { background: #FFFFFF; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; align-content: flex-start; }
  .eq-group a.pair:hover, a.eq-side:hover { border-color: #9FB3CC; }
  .pair-specs > span { -webkit-line-clamp: 3; }
  .eq-switch { max-width: 560px; }

  /* زر الحفظ يطوف تحت */
  .save-bar { margin: 0; bottom: 16px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 14px; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 16px; }
  .save-bar .btn-block { width: auto; min-width: 240px; }
  main.no-nav > :last-child:not(form) { margin-bottom: 16px; }

  .kv { grid-template-columns: 140px minmax(0, 1fr); }
  .m-only { display: none !important; }
  .kpi-filters { max-width: 760px; }
  .kplot { height: 220px; }
  a.krow:hover { background: #F8FAFC; }
  .krow { font-size: 15px; }
  .desk-inline { display: inline; }
  .srow, .srow.head {
    display: grid; gap: 8px; padding: 9px 0;
    grid-template-columns: minmax(0, 2.6fr) minmax(0, .9fr) minmax(0, 1fr) minmax(0, .55fr) repeat(4, minmax(0, .6fr)) minmax(0, .7fr);
  }
  .srow .s-c { display: block; text-align: center; font-size: 14px; }
  .srow .s-bal, .srow .s-sub { display: none; }
  .srow.head { padding: 8px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
  .srow.head > span { text-align: center; }
  .srow.head > span:first-child { text-align: right; }
  a.srow:hover { background: #F8FAFC; }
  .btn-primary:hover { background: var(--orange-dark); }
  .btn-plain:hover, .btn-outline:hover { background: #F8FAFC; }
  .chip:hover { border-color: var(--navy); }
  .bar-row:hover .bar > span { background: var(--navy-2); }
  #toast { right: calc(var(--rail) + 24px); left: 24px; bottom: 24px; }

  /* الدخول: الشاشة مقسومة */
  .login { flex-direction: row; }
  .login .hero { flex: 1; justify-content: center; padding: 56px; }
  .login .hero .wordmark { font-size: 52px; }
  .login .hero .tagline { font-size: 20px; }
  .login .body { flex: 1; justify-content: center; align-items: center; padding: 48px; }
  .login .body > * { width: 100%; max-width: 440px; }
}

@media (min-width: 1500px) {
  .eq-group > .list { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
}

/* ---------- 2026-12-01: رأس الرئيسية، يحتاج انتباهك، الأرقام، المخزن بالوكيل وصفحة المعدة ---------- */
.home-top { flex-wrap: wrap; row-gap: 10px; }
.home-top .brand { flex-direction: row; align-items: center; gap: 10px; }
.logo-tile { width: 36px; height: 36px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--orange); color: #FFFFFF; }
.logo-tile svg { width: 21px; height: 21px; }
.wordmark2 { font-family: var(--sans); font-weight: 700; font-size: 20px; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.wordmark2 b { color: #F7A072; font-weight: 700; }
.avatar { width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 20px; background: var(--navy-2); color: #FFFFFF; font-size: 17px; font-weight: 600; text-decoration: none; }
.top-search { order: 3; flex-basis: 100%; position: relative; display: flex; align-items: center; }
.top-search svg { position: absolute; inset-inline-start: 12px; width: 20px; height: 20px; color: #C9D4E3; pointer-events: none; }
.top-search input { width: 100%; min-height: 44px; padding-right: 42px; padding-left: 12px; border: 1px solid transparent; border-radius: 12px; background: rgba(255, 255, 255, .13); color: #FFFFFF; font-size: 16px; }
.top-search input::placeholder { color: #C9D4E3; }
.top-search input:focus { outline: none; background: #FFFFFF; color: var(--text); border-color: #8FB1DA; }
.top-search input:focus::placeholder { color: var(--muted); }
.top-search:focus-within svg { color: var(--muted); }

.att .card-head { padding-bottom: 2px; }
.att-row { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 0; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); font-size: 14px; font-weight: 500; }
.att-row:last-child { border-bottom: 0; }
.att-row > svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.att-ic { width: 30px; height: 30px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.att-ic svg { width: 17px; height: 17px; }
.att-ic.bad { background: var(--red-bg); color: var(--red); }
.att-ic.warn { background: var(--amber-bg); color: var(--amber); }

.nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.num { display: flex; flex-direction: column; align-items: center; padding: 10px 4px 9px; text-decoration: none; color: var(--text); }
.num + .num { border-inline-start: 1px solid var(--line-2); }
.num b { font-size: 22px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.num b small { margin-inline-start: 3px; font-size: 12px; font-weight: 500; color: var(--muted); }
.num > span { font-size: 12px; color: var(--muted); }

/* مادة مختصرة (الوكيل وصفحة المعدة) */
.skm { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); }
.skm:last-child { border-bottom: 0; }
.ask-item .list { border-top: 1px solid var(--line-2); }
.sk-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.sk-head a { font-weight: 500; font-size: 12px; }
.sk-all { margin: 2px 0 10px; }
.cite-st { white-space: nowrap; }

/* قائمة المعدات: الحرف اللي بيه إدخالات مملي */
.eq-side.has { background: var(--chip); border-color: #C9D5E5; }
.eq-side:not(.has) .side-l { color: var(--muted); }

@media (min-width: 900px) {
  .home-top { flex-wrap: nowrap; }
  .top-search { order: 0; flex: 0 1 440px; }
  .top-search svg { color: var(--muted); }
  .top-search input { background: var(--bg); color: var(--text); border-color: var(--line); }
  .top-search input::placeholder { color: var(--muted); }
  .top .avatar { display: none; }
  a.att-row:hover, a.skm:hover { background: #F8FAFC; }
  .home-head { align-items: stretch; }
  .home-head .nums { flex: 1; }
  .num { justify-content: center; padding: 14px 6px 12px; }
  .num b { font-size: 28px; }
}

/* الحسابات: سطر لكل حساب، والإجراءات بشيت */
.acc { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 60px; padding: 8px 0; border: 0; border-bottom: 1px solid var(--line-2); background: none; text-align: start; cursor: pointer; }
.acc:last-child { border-bottom: 0; }
.acc > svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.acc-av { width: 38px; height: 38px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 19px; background: var(--chip); color: var(--navy); font-weight: 600; font-size: 16px; }
.acc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.acc-name { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.acc .t3 { font-size: 12px; color: var(--muted); }
.acc.off .acc-name, .acc.off .acc-av { color: var(--muted); }

.sheet { width: 100%; max-width: 600px; max-height: 88dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 16px 16px 0 0; background: var(--card); color: var(--text); overflow: auto; }
.sheet::backdrop { background: rgba(20, 40, 66, .45); }
.sheet-in { display: flex; flex-direction: column; gap: 12px; padding: 6px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-head .icon-btn { margin-inline-end: -10px; }
.sheet-body { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 900px) {
  .sheet { max-width: 460px; margin: auto; border-radius: 16px; }
  .acc:hover { background: #F8FAFC; }
}

/* نموذج التسجيل: نوع العطل بسطر واحد ينفتح */
.iso-row > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 4px 0; }
.iso-row > summary::-webkit-details-marker { display: none; }
.iso-row > summary .label { font-size: 13px; font-weight: 600; }
.iso-sel { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 14px; }
.iso-sel .iso-code { font-family: var(--mono); font-size: 12px; color: var(--navy); background: var(--chip); padding: 1px 6px; border-radius: 6px; direction: ltr; }
.iso-row > summary::after { content: ''; flex: none; width: 8px; height: 8px; margin: 0 4px; border-left: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .2s; }
.iso-row[open] > summary::after { transform: rotate(135deg); }
.iso-row > .chips { padding: 6px 0 4px; }
#eq-recent .chip .small { color: var(--muted); }
#eq-recent .chip[aria-pressed="true"] .small { color: #D5DEEA; }
.ask-a a.cite-st { font-family: var(--sans); }
