/* ============================================================
   واجهة الأداة — هوية بست شيلد
   ============================================================ */

@font-face {
  font-family: 'Alexandria';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/alexandria-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFC, U+200C-200E, U+2010-2011;
}
@font-face {
  font-family: 'Alexandria';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/alexandria-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+2200-22FF;
}

:root {
  --red: #ea272c;
  --red-dark: #c81e23;
  --amber: #b07414;
  --amber-band: #f7b322;
  --green: #17a45b;
  --ink: #111;
  --gray: #8b8b8b;
  --line: #e5e5e5;
  --bg: #f4f4f5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Alexandria', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- الهيدر ---------- */
.app-header {
  background: #000;
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 3px solid var(--red);
}
.app-logo { height: 38px; }
.app-title { font-size: 16px; font-weight: 800; }
.app-sub { font-size: 11px; color: #b5b5b5; margin-top: 3px; }

/* ---------- الحاويات ---------- */
#app { max-width: 860px; margin: 0 auto; padding: 28px 18px 80px; }

.screen-title { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.screen-sub { font-size: 13px; color: var(--gray); margin-bottom: 26px; }

/* ---------- أزرار الاختيار الكبيرة ---------- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.choice-card {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 28px 22px;
  cursor: pointer;
  text-align: right;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  font-family: inherit;
}
.choice-card:hover { border-color: #000; transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.choice-card .ic {
  width: 46px; height: 46px; border-radius: 12px;
  background: #000; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin-bottom: 16px;
}
.choice-card.red .ic { background: var(--red); }
.choice-card h3 { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.choice-card p { font-size: 11.5px; color: var(--gray); line-height: 1.7; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--gray); font-size: 12px; font-family: inherit;
  margin-bottom: 18px;
}
.back-link:hover { color: #000; }

/* ---------- النموذج ---------- */
.form-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 18px;
}
.form-card > h3 {
  font-size: 14px; font-weight: 800;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.form-card > h3::before { content: ''; width: 5px; height: 16px; background: var(--red); border-radius: 1px; }
.form-card .hint { font-size: 11px; color: var(--gray); margin-bottom: 18px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px 16px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.field label { display: block; font-size: 11.5px; font-weight: 700; margin-bottom: 7px; }
.field .target-hint { font-weight: 400; color: var(--gray); font-size: 10px; margin-right: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  background: #fafafa;
  color: var(--ink);
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #000; background: #fff;
}
.field textarea { resize: vertical; min-height: 64px; line-height: 1.8; }
.field .suffix-wrap { position: relative; }
.field .suffix-wrap .suffix {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--gray); pointer-events: none;
}

/* مفاتيح التبديل */
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: #fafafa; }
.seg button {
  border: none; background: none; cursor: pointer;
  padding: 9px 18px; font-size: 12.5px; font-weight: 700; font-family: inherit;
  color: var(--gray);
}
.seg button.active { background: #000; color: #fff; }
.seg button.active.good { background: var(--green); }
.seg button.active.bad { background: var(--red); }
.seg button.active.mid { background: var(--amber-band); color: #000; }

/* صف بند تقييم */
.eval-item-row {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.eval-item-row:last-child { border-bottom: none; }
.eval-item-row .lbl { font-size: 12.5px; font-weight: 600; }

/* بنود ديناميكية (خطة/مهام) */
.dyn-item {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fafafa;
  position: relative;
}
.dyn-item .row { display: flex; gap: 10px; align-items: flex-start; }
.dyn-item textarea { background: #fff; }
.dyn-item .dyn-meta { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.dyn-item .dyn-meta select, .dyn-item .dyn-meta input { background: #fff; width: auto; flex: 1; }
.remove-btn {
  background: none; border: none; cursor: pointer;
  color: var(--gray); font-size: 16px; font-family: inherit;
  padding: 4px 8px; border-radius: 8px; flex: 0 0 auto;
}
.remove-btn:hover { color: var(--red); background: #fdeeee; }
.add-btn {
  background: none;
  border: 1.5px dashed #c9c9c9;
  border-radius: 10px;
  width: 100%;
  padding: 11px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--gray);
}
.add-btn:hover { border-color: #000; color: #000; }

/* ---------- الشريط السفلي الحي ---------- */
.live-bar {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  background: #000;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  z-index: 50;
}
.live-score { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; }
.live-score .val { font-size: 20px; font-weight: 800; }
.live-score .chip {
  font-size: 10.5px; font-weight: 700;
  border-radius: 999px; padding: 5px 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.live-score .chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip.c-green { background: rgba(23,164,91,.18); color: #2ecc80; }
.chip.c-green .dot { background: #2ecc80; }
.chip.c-yellow { background: rgba(247,179,34,.15); color: var(--amber-band); }
.chip.c-yellow .dot { background: var(--amber-band); }
.chip.c-red { background: rgba(234,39,44,.18); color: #ff5a5f; }
.chip.c-red .dot { background: #ff5a5f; }

.btn {
  border: none; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 13.5px;
  border-radius: 12px; padding: 13px 26px;
  transition: transform .1s, opacity .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-red { background: var(--red); color: #fff; }
.btn-dark { background: #1d1d1d; color: #fff; border: 1px solid #333; }
.btn-light { background: #fff; color: #111; border: 1.5px solid var(--line); }

/* ---------- شاشة المعاينة ---------- */
.preview-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 20px;
  position: sticky; top: 10px; z-index: 40;
  background: rgba(244,244,245,.92);
  backdrop-filter: blur(6px);
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.preview-pages { display: flex; flex-direction: column; gap: 22px; align-items: center; }
.preview-page-wrap {
  box-shadow: 0 10px 40px rgba(0,0,0,.14);
  border-radius: 4px;
  overflow: hidden;
  max-width: 100%;
}
.preview-scale { transform-origin: top right; }

/* حاوية التوليد المخفية */
#report-host { position: absolute; top: 0; right: -2000px; pointer-events: none; }
#report-host.exporting { right: 0; z-index: -1; opacity: 0; }

.toast {
  position: fixed; bottom: 84px; right: 50%; transform: translateX(50%);
  background: #000; color: #fff;
  border-radius: 999px; padding: 11px 22px;
  font-size: 12.5px; font-weight: 700;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -3px;
  margin-left: 8px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- سجل التقارير ---------- */
.history-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin: 38px 0 14px; }
.history-head h2 { font-size: 17px; font-weight: 800; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.fchip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 16px; font-size: 12px; font-weight: 700; font-family: inherit;
  cursor: pointer; color: var(--gray);
}
.fchip.active { background: #000; color: #fff; border-color: #000; }
.history-empty {
  background: #fff; border: 1.5px dashed #d5d5d5; border-radius: 14px;
  padding: 26px; text-align: center; color: var(--gray); font-size: 12.5px; line-height: 1.9;
}
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
.history-title { font-size: 13.5px; font-weight: 800; margin-bottom: 5px; }
.history-sub { font-size: 10.5px; color: var(--gray); }
.history-side { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.history-side .chip { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 6px 13px; display: inline-flex; align-items: center; gap: 6px; }
.history-side .chip.c-green { background: rgba(23,164,91,.12); color: var(--green); }
.history-side .chip.c-green .dot { background: var(--green); }
.history-side .chip.c-yellow { background: rgba(176,116,20,.12); color: var(--amber); }
.history-side .chip.c-yellow .dot { background: var(--amber-band); }
.history-side .chip.c-red { background: rgba(234,39,44,.1); color: var(--red-dark); }
.history-side .chip.c-red .dot { background: var(--red); }
.history-side .chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.history-actions { display: flex; gap: 6px; }
.hbtn {
  border: 1.5px solid var(--line); background: #fff; border-radius: 9px;
  padding: 7px 14px; font-size: 11.5px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.hbtn:hover { border-color: #000; }
.hbtn.del:hover { border-color: var(--red); color: var(--red); background: #fdeeee; }

/* ---------- منطقة تقرير الجودة داخل تقرير الفرع ---------- */
.qc-options { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.qc-select {
  flex: 1; min-width: 220px;
  border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 13px; font-size: 12.5px; font-family: inherit; background: #fafafa;
}
.qc-none { font-size: 11px; color: var(--gray); }
.qc-attached {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: #f7fcf9; border: 1.5px solid #bfe6d2; border-radius: 12px; padding: 14px;
}
.qc-attached .chip { font-size: 13px; font-weight: 800; border-radius: 999px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 7px; }
.qc-attached .chip.c-green { background: rgba(23,164,91,.14); color: var(--green); }
.qc-attached .chip.c-yellow { background: rgba(176,116,20,.14); color: var(--amber); }
.qc-attached .chip.c-red { background: rgba(234,39,44,.12); color: var(--red-dark); }
.qc-attached .chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.qc-attached-info { flex: 1; min-width: 180px; }
.qc-attached-info b { display: block; font-size: 12.5px; margin-bottom: 4px; }
.qc-attached-info span { font-size: 11px; color: var(--gray); }
.qc-attached-actions { display: flex; gap: 6px; }
.lock-note { font-size: 10px; color: var(--green); margin-top: 6px; font-weight: 700; }
.carried-note {
  background: #fff8e9; border: 1.5px solid #f3ddb0; border-radius: 10px;
  padding: 10px 14px; font-size: 11.5px; font-weight: 700; color: #8a6210; margin-bottom: 14px;
}

/* ---------- صفوف الجرد ---------- */
.audit-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.audit-row:last-child { border-bottom: none; }
.audit-name { font-size: 12.5px; font-weight: 700; margin-bottom: 10px; }
.audit-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 420px; }

/* ---------- الصور ---------- */
.photos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.photo-thumb { position: relative; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: #fafafa; }
.photo-thumb img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo-caption {
  width: 100%; border: none; border-top: 1.5px solid var(--line);
  padding: 8px 10px; font-size: 11px; font-family: inherit; background: #fff;
}
.photo-caption:focus { outline: none; background: #fffdf5; }
.photo-del {
  position: absolute; top: 6px; left: 6px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.65); color: #fff;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.photo-del:hover { background: var(--red); }
.photo-add { display: block; text-align: center; }

/* ---------- جوال ---------- */
@media (max-width: 640px) {
  #app { padding: 20px 12px 90px; }
  .screen-title { font-size: 19px; }
  .eval-item-row { flex-direction: row; }
  .eval-item-row .lbl { font-size: 11.5px; flex: 1; }
  .seg button { padding: 9px 13px; font-size: 12px; }
  .live-bar { padding: 10px 14px; }
  .live-score { font-size: 11.5px; }
  .live-score .val { font-size: 17px; }
  .btn { padding: 12px 18px; font-size: 12.5px; }
  .history-card { align-items: flex-start; }
  .audit-inputs { max-width: none; }
  .preview-actions { position: static; }
}

/* حقول التاريخ تُعرض LTR لتفادي انعكاس صيغة التاريخ في الوضع العربي */
.field input[type="date"] { direction: ltr; text-align: right; }
