@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap');

/* ============================================================
   نظام معلومات المختارين
   الهوية: سجل رسمي - كحلي عميق، ورق فاتح، خطوط شعرية رفيعة

   مقياس الخط: كل الاحجام بوحدة rem، فتغيير حجم الجذر
   يكبر او يصغر الواجهة كاملة بشكل متناسق.
   ============================================================ */

:root {
  --navy-900: #0d2137;
  --navy-800: #16324f;
  --navy-700: #1f4468;
  --navy-100: #e7edf4;

  --brass:    #a8842c;
  --brass-50: #f6f0dd;

  --paper:    #f4f6f9;
  --card:     #ffffff;

  --ink:      #17202c;
  --ink-soft: #4e5c69;
  --ink-mute: #7d8a97;

  --rule:     #dde3ea;
  --rule-hard:#c3ccd6;

  --ok:       #1f6b4d;
  --ok-bg:    #e6f2ec;
  --warn:     #8a6413;
  --warn-bg:  #fbf1dc;
  --bad:      #9d2b2b;
  --bad-bg:   #f7e7e7;

  --radius:   5px;
  --shadow:   0 1px 2px rgba(13, 33, 55, .06), 0 4px 14px rgba(13, 33, 55, .05);

  --rail-w:   17rem;
  --content-max: 1600px;
}

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

/* مقياس الخط - يتحكم به المستخدم من الشريط العلوي */
html                { font-size: 17px; }
html.fs-1           { font-size: 15px; }
html.fs-2           { font-size: 17px; }
html.fs-3           { font-size: 19px; }
html.fs-4           { font-size: 21px; }

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-700); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

.skip { position: absolute; right: -9999px; top: 0; background: var(--navy-900); color: #fff; padding: .6rem 1rem; z-index: 100; }
.skip:focus { right: 1rem; }

/* ---------- الهيكل ---------- */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--navy-900);
  color: #cfd9e4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand {
  padding: 1.3rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.rail-seal { width: 2.9rem; height: 2.9rem; object-fit: contain; flex: 0 0 2.9rem; }
.rail-brand-text { display: flex; flex-direction: column; line-height: 1.4; }
.rail-org  { color: #fff; font-weight: 700; font-size: 1.02rem; }
.rail-dept { color: #93a7bb; font-size: .8rem; }

.rail-nav { padding: .9rem .6rem; flex: 1; overflow-y: auto; }

.rail-heading {
  font-size: .76rem;
  letter-spacing: .08em;
  color: #74899f;
  padding: 1rem .55rem .4rem;
  border-top: 1px solid rgba(255, 255, 255, .07);
  margin-top: .5rem;
}
.rail-nav .rail-heading:first-child { border-top: 0; margin-top: 0; padding-top: .2rem; }

.rail-link {
  display: block;
  padding: .6rem .6rem;
  border-radius: var(--radius);
  color: #cfd9e4;
  font-size: .97rem;
  border-right: 3px solid transparent;
}
.rail-link:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: #fff; }
.rail-link.is-on {
  background: rgba(255, 255, 255, .1);
  color: #fff;
  border-right-color: var(--brass);
  font-weight: 600;
}

.rail-foot { padding: 1rem 1.1rem; border-top: 1px solid rgba(255, 255, 255, .09); }
.rail-user { color: #fff; font-weight: 600; font-size: .95rem; }
.rail-role { color: #8497aa; font-size: .8rem; }
.rail-actions { margin-top: .5rem; display: flex; gap: .45rem; color: #4f637a; }
.rail-actions a { color: #a6b8ca; font-size: .88rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--rule);
  padding: 1.15rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-title { font-size: 1.6rem; font-weight: 700; color: var(--navy-900); line-height: 1.3; }
.topbar-sub   { font-size: .88rem; color: var(--ink-mute); }

/* اداة تكبير الخط */
.zoom { display: flex; align-items: center; gap: .45rem; }
.zoom-lbl { font-size: .82rem; color: var(--ink-mute); }
.zoom-btn {
  width: 2.1rem; height: 2.1rem;
  border: 1px solid var(--rule-hard);
  background: #fff;
  border-radius: var(--radius);
  color: var(--navy-800);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.zoom-btn:hover { background: var(--navy-100); border-color: var(--navy-700); }
.zoom-btn:disabled { opacity: .4; cursor: default; }
.zoom-now { font-size: .82rem; color: var(--ink-soft); min-width: 3.2rem; text-align: center; font-variant-numeric: tabular-nums; }

.content {
  padding: 1.75rem 2rem;
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.foot {
  padding: 1.1rem 2rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-mute);
  font-size: .85rem;
  text-align: center;
}

/* ---------- الرسائل ---------- */

.notes { padding: 1.1rem 2rem 0; width: 100%; max-width: var(--content-max); margin-inline: auto; }

.note {
  padding: .8rem 1.05rem;
  border-radius: var(--radius);
  font-size: .97rem;
  margin-bottom: .6rem;
  border-right: 4px solid;
}
.note-ok    { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok); }
.note-warn  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.note-error { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad); }

/* ---------- البطاقات ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.4rem;
}

.card-head {
  padding: 1rem 1.3rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.card-title { font-size: 1.1rem; font-weight: 700; color: var(--navy-900); }
.card-note  { font-size: .88rem; color: var(--ink-mute); }
.card-body  { padding: 1.3rem; }

/* ---------- الاحصائيات ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1.1rem;
  margin-bottom: 1.4rem;
}

.stat {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--navy-800);
}
.stat-num {
  font-size: 2.3rem;
  font-weight: 700;
  color: var(--navy-900);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.stat-lbl { font-size: .92rem; color: var(--ink-soft); }
.stat.is-brass { border-top-color: var(--brass); }
.stat.is-bad   { border-top-color: var(--bad); }
.stat.is-mute  { border-top-color: var(--rule-hard); }

.bars { display: flex; flex-direction: column; gap: .7rem; }
.bar-row { display: grid; grid-template-columns: 10rem 1fr 3.5rem; align-items: center; gap: .8rem; }
.bar-name { font-size: .95rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--navy-100); height: .7rem; border-radius: 2px; overflow: hidden; }
.bar-fill  { background: var(--navy-700); height: 100%; }
.bar-val   { font-size: .95rem; font-weight: 600; color: var(--navy-800); font-variant-numeric: tabular-nums; text-align: left; }

/* ---------- الجداول ---------- */

.table-wrap { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; font-size: .97rem; }

table.grid th {
  background: var(--navy-800);
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  text-align: right;
  padding: .8rem .85rem;
  white-space: nowrap;
  position: sticky;
  top: 0;
  border-left: 1px solid rgba(255, 255, 255, .12);
}
table.grid th:last-child { border-left: 0; }
table.grid th a { color: #fff; display: inline-block; }
table.grid th a:hover { color: var(--brass-50); }

table.grid td {
  padding: .75rem .85rem;
  border-bottom: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
  vertical-align: middle;
}
table.grid td:last-child { border-left: 0; }

table.grid tbody tr:nth-child(even) { background: #fafbfc; }
table.grid tbody tr:hover { background: var(--brass-50); }

.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; unicode-bidi: plaintext; }
.serial { color: var(--ink-mute); font-size: .88rem; font-variant-numeric: tabular-nums; }
.strong-cell { font-weight: 600; color: var(--navy-900); }

.empty { padding: 3.5rem 1rem; text-align: center; color: var(--ink-mute); font-size: 1.02rem; }
.empty p { margin-bottom: 1rem; }

/* ---------- الشارات ---------- */

.tag {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 3px;
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
}
.tag-ok   { background: var(--ok-bg);   color: var(--ok); }
.tag-bad  { background: var(--bad-bg);  color: var(--bad); }
.tag-mute { background: var(--navy-100); color: var(--navy-700); }

/* ---------- الازرار ---------- */

.btn {
  display: inline-block;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule-hard);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: .97rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  line-height: 1.5;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #eff3f7; text-decoration: none; border-color: var(--navy-700); }

.btn-primary { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.btn-primary:hover { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }

.btn-danger { background: #fff; border-color: #dcbcbc; color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad); }

.btn-brass { background: var(--brass); border-color: var(--brass); color: #fff; }
.btn-brass:hover { background: #8f6f22; border-color: #8f6f22; color: #fff; }

.btn-sm { padding: .38rem .75rem; font-size: .89rem; font-weight: 500; }
.btn-block { width: 100%; display: block; }

.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* ---------- النماذج ---------- */

.field { display: block; margin-bottom: 1.15rem; }

.field-label {
  display: block;
  font-size: .93rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: .35rem;
}
.field-label .req { color: var(--bad); }

.field input[type=text],
.field input[type=password],
.field input[type=search],
.field input[type=file],
.field select,
.field textarea,
input.inp, select.inp {
  width: 100%;
  padding: .62rem .8rem;
  min-height: 2.7rem;
  border: 1px solid var(--rule-hard);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}
.field textarea { min-height: 6rem; resize: vertical; line-height: 1.6; }

.field input:focus, .field select:focus, .field textarea:focus, input.inp:focus, select.inp:focus {
  border-color: var(--navy-700);
  outline: 3px solid rgba(31, 68, 104, .14);
  outline-offset: 0;
}

.field.has-error input, .field.has-error select { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: .87rem; margin-top: .25rem; }
.field-hint  { color: var(--ink-mute); font-size: .85rem; margin-top: .25rem; line-height: 1.5; }

.fieldset { margin-bottom: 1.9rem; }
.fieldset:last-of-type { margin-bottom: .75rem; }

.fieldset-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.1rem; }
.fieldset-title { font-size: .98rem; font-weight: 700; color: var(--navy-800); white-space: nowrap; }
.fieldset-rule { flex: 1; height: 1px; background: var(--rule); }
.fieldset.is-term .fieldset-title { color: var(--bad); }

/* اعمدة النموذج: 4 كحد اقصى حتى لا تتمدد الحقول بلا داع على الشاشات العريضة */
.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0 1.3rem;
}

/* ---------- شريط الفلترة ---------- */

.filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: .8rem;
  align-items: end;
}
.filters .field { margin-bottom: 0; }

/* ---------- الترقيم ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.3rem;
  border-top: 1px solid var(--rule);
  font-size: .93rem;
  color: var(--ink-soft);
  flex-wrap: wrap;
}
.pager-links { display: flex; gap: .35rem; flex-wrap: wrap; }
.pager-links a, .pager-links span {
  padding: .35rem .75rem;
  border: 1px solid var(--rule-hard);
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}
.pager-links .is-on { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.pager-links .off { color: var(--ink-mute); border-color: var(--rule); }

/* ---------- بطاقة السجل ---------- */

.record-head {
  background: var(--navy-900);
  color: #fff;
  padding: 1.4rem 1.6rem;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.record-name { font-size: 1.45rem; font-weight: 700; }
.record-meta { color: #93a7bb; font-size: .9rem; margin-top: .2rem; }
.record-serial {
  font-size: .85rem;
  color: var(--brass);
  border: 1px solid rgba(168, 132, 44, .5);
  padding: .25rem .65rem;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.dl-item { padding: .9rem 1.3rem; border-bottom: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.dl-key { font-size: .85rem; color: var(--ink-mute); margin-bottom: .15rem; }
.dl-val { font-size: 1.05rem; color: var(--ink); font-weight: 500; word-break: break-word; }

/* ---------- الاستيراد ---------- */

.steps {
  display: flex;
  margin-bottom: 1.4rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}
.step {
  flex: 1;
  padding: .85rem 1.1rem;
  font-size: .97rem;
  color: var(--ink-mute);
  border-left: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.step:last-child { border-left: 0; }
.step-no {
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  background: var(--navy-100);
  color: var(--navy-700);
  display: grid; place-items: center;
  font-size: .85rem; font-weight: 700;
  flex: 0 0 1.6rem;
}
.step.is-on { color: var(--navy-900); font-weight: 600; background: #fff; }
.step.is-on .step-no { background: var(--navy-800); color: #fff; }

.map-table td { vertical-align: middle; }
.map-table select { min-width: 13rem; }
.map-sample { color: var(--ink-mute); font-size: .89rem; }

.preview { font-size: .89rem; }
.preview th { background: var(--navy-100); color: var(--navy-800); font-weight: 600; }
.preview td { color: var(--ink-soft); max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.checkline { display: flex; align-items: flex-start; gap: .6rem; margin-bottom: .7rem; font-size: .97rem; }
.checkline input { margin-top: .45rem; width: 1.05rem; height: 1.05rem; }
.checkline span { color: var(--ink-soft); font-size: .89rem; display: block; line-height: 1.6; }

.problems {
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: .85rem 1.05rem;
  font-size: .93rem;
  color: var(--ink-soft);
  background: #fbfcfd;
  line-height: 1.75;
}
.problems li { list-style: none; padding: .25rem 0; border-bottom: 1px dotted var(--rule); }
.problems li:last-child { border-bottom: 0; }

/* ---------- شاشة الدخول ---------- */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(13, 33, 55, .96), rgba(13, 33, 55, .99)),
    repeating-linear-gradient(135deg, #16324f 0 2px, #0d2137 2px 9px);
  padding: 1.5rem;
}

.auth-shell { width: 100%; max-width: 26rem; }

.auth-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 2.3rem 2rem 2rem;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  border-top: 4px solid var(--brass);
}

.auth-seal { margin-bottom: 1rem; }
.auth-seal img { width: 5.2rem; height: 5.2rem; object-fit: contain; }

.auth-org   { font-weight: 700; color: var(--navy-900); font-size: 1.15rem; }
.auth-dept  { color: var(--ink-mute); font-size: .9rem; }
.auth-title { font-size: 1.02rem; color: var(--navy-700); font-weight: 600; margin-top: .4rem; }

.auth-rule { height: 1px; background: var(--rule); margin: 1.3rem 0; }

.auth-form { text-align: right; }
.auth-form .btn { margin-top: .5rem; padding: .7rem; font-size: 1.02rem; }

.auth-foot { text-align: center; color: #8497aa; font-size: .85rem; margin-top: 1.2rem; }

/* ---------- الاستجابة ---------- */

@media (max-width: 1100px) {
  .filters { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .rail { width: 100%; flex: none; height: auto; position: static; }
  .rail-nav { display: flex; flex-wrap: wrap; gap: .35rem; padding: .7rem; }
  .rail-heading { display: none; }
  .rail-link { border-right: 0; border-bottom: 2px solid transparent; padding: .45rem .7rem; }
  .rail-link.is-on { border-right: 0; border-bottom-color: var(--brass); }
  .rail-foot { display: flex; justify-content: space-between; align-items: center; }

  .content, .topbar, .notes, .foot { padding-left: 1rem; padding-right: 1rem; }
  .filters { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 7rem 1fr 3rem; }
  .zoom { display: none; }
}

@media print {
  .rail, .topbar, .foot, .btn-row, .notes, .pager, .zoom { display: none !important; }
  .card { border: 1px solid #999; box-shadow: none; }
  body { background: #fff; }
  .content { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
