:root {
  --primary: #3e3a8c;
  --primary-dark: #2c2968;
  --primary-soft: #ecebf7;
  --accent: #23877b;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --text: #1f2330;
  --muted: #646b7d;
  --border: #dfe2ec;
  --ok: #26734d;
  --ok-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #a8261d;
  --bad-soft: #fbe5e3;
  --info: #2f5bb7;
  --info-soft: #e5edfb;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Sakkal Majalla", Arial, sans-serif;
  line-height: 1.65;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; color: var(--primary-dark); }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* ------------------------------------------------ الإطار */
.topbar {
  background: var(--primary); color: #fff; padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.5rem; min-height: 56px; flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; color: #fff; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #e6e4fb; padding: .45rem .75rem; border-radius: 8px; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.topbar .who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: #e6e4fb; }
.topbar .who button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; }
.drive-badge { font-size: .78rem; background: rgba(255,255,255,.16); padding: .1rem .5rem; border-radius: 99px; }

main { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem;
}
.card > h2:first-child { margin-top: 0; }
.section-tag { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); border-radius: 6px; padding: 0 .5rem; margin-left: .4rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ------------------------------------------------ رسائل */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .5rem; border: 1px solid transparent; }
.messages .success { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cf; }
.messages .error { background: var(--bad-soft); color: var(--bad); border-color: #f3c4c0; }
.messages .warning { background: var(--warn-soft); color: var(--warn); border-color: #f2d6a6; }
.messages .info { background: var(--info-soft); color: var(--info); }
.callout { padding: .8rem 1rem; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 1rem; }
.callout.info { background: var(--info-soft); color: var(--info); }
.callout.ok { background: var(--ok-soft); color: var(--ok); }
.junk-hint { padding: .7rem .9rem; border-radius: 8px; border: 1px dashed var(--info); background: var(--info-soft);
  line-height: 1.7; margin-bottom: 1rem; }
.btn[disabled] { opacity: .65; cursor: wait; }
.callout ul { margin: .3rem 0 0; padding-right: 1.2rem; }

/* ------------------------------------------------ أزرار ونماذج */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: .5rem 1rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: inline-flex; align-items: center; gap: .35rem;
}
.btn:hover, button:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-warn { background: var(--surface); border-color: #e2b25e; color: var(--warn); }
.btn-ms { background: #fff; border: 1px solid #8c8c8c; color: #1f1f1f; font-weight: 600; padding: .7rem 1.2rem; width: 100%; justify-content: center; }
.btn-link { border: 0; background: none; color: var(--primary); padding: .25rem .4rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=search],
select, textarea {
  font: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 2.6rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9b5ea; border-color: var(--primary); }
input:disabled, textarea:disabled, select:disabled { background: #f6f7fb; color: #3a3f4f; border-color: #eceef4; }
.field { margin-bottom: .9rem; }
.field .help { color: var(--muted); font-size: .82rem; }
.errorlist { color: var(--bad); list-style: none; padding: 0; margin: .2rem 0; font-size: .85rem; }
.has-error input, .has-error textarea, .has-error select { border-color: var(--bad); }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 140px; }

/* ------------------------------------------------ جداول */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: .5rem .55rem; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
table.data th { background: #f7f7fc; color: var(--muted); font-weight: 600; font-size: .84rem; white-space: nowrap; }
table.data tr:hover td { background: #fbfbfe; }
table.data td.num, table.data th.num { text-align: center; }
table.form-table td { padding: .35rem .3rem; }
table.form-table textarea { min-height: 2.4rem; }
.domain-row td { background: var(--primary-soft) !important; color: var(--primary-dark); font-weight: 700; }
table.grades { min-width: 760px; }
table.grades input { text-align: center; padding: .35rem .2rem; min-width: 44px; }
table.grades th { text-align: center; }

/* ------------------------------------------------ الحالات */
.badge { display: inline-block; padding: .08rem .6rem; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st-none { background: #eef0f5; color: var(--muted); }
.st-draft { background: #eef0f5; color: #3a3f4f; }
.st-submitted { background: var(--info-soft); color: var(--info); }
.st-returned { background: var(--warn-soft); color: var(--warn); }
.st-approved { background: var(--ok-soft); color: var(--ok); }
.hit { color: var(--ok); font-weight: 700; }
.miss { color: var(--bad); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .85rem; }
.progress { height: 8px; background: #eceef4; border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.progress i { display: block; height: 100%; background: var(--ok); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .45rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .note { background: #f7f7fc; border-radius: 6px; padding: .35rem .6rem; margin-top: .25rem; white-space: pre-wrap; }

/* ------------------------------------------------ مستودع الأدلة */
.evidence-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; align-items: start; }
.criteria-list { max-height: 75vh; overflow-y: auto; padding: .5rem; }
.criteria-list a { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem .55rem; border-radius: 6px; color: var(--text); font-size: .88rem; }
.criteria-list a:hover { background: #f4f4fb; text-decoration: none; }
.criteria-list a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.criteria-list .std { margin: .7rem .4rem .3rem; font-weight: 700; color: var(--primary-dark); font-size: .85rem; }
.criteria-list .zero { color: var(--bad); }
.count { background: #eef0f5; border-radius: 99px; padding: 0 .5rem; font-size: .78rem; height: fit-content; }
.count.zero { background: var(--bad-soft); }

/* ------------------------------------------------ الدخول */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 2rem; }
.login-card h1 { color: var(--primary-dark); }
.divider { text-align: center; color: var(--muted); margin: 1.25rem 0; font-size: .85rem; }
.btn-block { width: 100%; justify-content: center; padding: .65rem 1rem; }
.ltr-input { direction: ltr; text-align: left; }
.code-input { direction: ltr; text-align: center; font-size: 1.8rem; letter-spacing: .6rem; font-variant-numeric: tabular-nums; }
.login-links { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
.login-links form { margin: 0; }

.sticky-bar {
  position: sticky; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--border);
  padding: .75rem 1.25rem; display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap;
  margin: 0 -1.25rem; backdrop-filter: blur(4px);
}
.row-del { white-space: nowrap; font-size: .82rem; color: var(--muted); }

@media (max-width: 860px) {
  .evidence-layout { grid-template-columns: 1fr; }
  .criteria-list { max-height: 260px; }
  main { padding: 1rem .75rem 4rem; }
}
