/* ================= الأساسيات ================= */
:root {
  /* هوية رسمية: كحلي غامق مع ذهبي عتيق */
  --bg:          #f4f5f8;
  --surface:     #ffffff;
  --surface-2:   #ebedf2;
  --border:      #dadee6;
  --text:        #101828;
  --muted:       #667085;
  --brand:       #16233a;
  --brand-2:     #22355a;
  --brand-soft:  #e9edf4;
  --accent:      #a8813a;
  --accent-soft: #f5efe2;
  --danger:      #a3231c;
  --ok:          #1a6f45;
  --radius:      12px;
  --shadow:      0 1px 2px rgba(16,24,40,.05), 0 8px 24px rgba(16,24,40,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #090e17;
    --surface:     #121a27;
    --surface-2:   #1a2433;
    --border:      #253044;
    --text:        #e6eaf2;
    --muted:       #8b96a8;
    --brand:       #2c4a7c;
    --brand-2:     #375c9a;
    --brand-soft:  #152238;
    --accent:      #c9a260;
    --accent-soft: #241d10;
    --danger:      #d4564d;
    --ok:          #359d68;
    --shadow:      0 1px 2px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Cairo", "Tajawal", "IBM Plex Sans Arabic", "Noto Kufi Arabic",
               "Geeza Pro", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  letter-spacing: normal;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3 { letter-spacing: normal; line-height: 1.35; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; font-weight: 800; }
h2 { font-size: 1.1rem;  font-weight: 700; }

.ltr { display: inline-block; direction: ltr; unicode-bidi: isolate; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

/* ================= التخطيط ================= */
.app { max-width: 780px; margin: 0 auto; padding: 0 0 5rem; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: #16233a;
  border-bottom: 2px solid var(--accent);
  color: #fff;
  padding: .85rem 1rem;
  padding-top: max(.85rem, env(safe-area-inset-top));
  display: flex; align-items: center; gap: .7rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.topbar h1 { margin: 0; font-size: 1.05rem; color: #fff; }
.topbar .sub { font-size: .75rem; opacity: .8; font-weight: 400; }
.topbar .spacer { margin-inline-start: auto; }
.topbar button {
  background: rgba(255,255,255,.14); color: #fff; border: 0;
  border-radius: 10px; padding: .4rem .7rem; font: inherit; font-size: .8rem;
  cursor: pointer;
}
.topbar button:active { background: rgba(255,255,255,.28); }

.screen { padding: 1rem; display: none; }
.screen.active { display: block; }

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

/* ================= النماذج ================= */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: .7rem .85rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder { color: var(--muted); opacity: .7; }
.field { margin-bottom: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (max-width: 430px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  width: 100%;
  font: inherit; font-weight: 700;
  background: var(--brand); color: #fff;
  border: 0; border-radius: 11px;
  padding: .8rem 1rem;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-2); }
.btn:active { transform: scale(.99); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.ghost:hover { background: var(--border); }
.btn.sm { width: auto; padding: .45rem .8rem; font-size: .85rem; }
.btn.danger { background: var(--danger); }

/* ================= تبويبات البحث ================= */
.tabs {
  display: flex; gap: .35rem;
  background: var(--surface-2);
  padding: .3rem; border-radius: 12px;
  margin-bottom: .9rem;
  overflow-x: auto;
}
.tabs button {
  flex: 1 0 auto; white-space: nowrap;
  font: inherit; font-size: .85rem; font-weight: 600;
  background: transparent; color: var(--muted);
  border: 0; border-radius: 9px; padding: .5rem .7rem;
  cursor: pointer;
}
.tabs button.on {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  border-bottom: 2px solid var(--accent);
}

/* ================= النتائج ================= */
.meta {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  font-size: .82rem; color: var(--muted);
  margin: .2rem 0 .8rem;
}

.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .85rem 1rem;
  margin-bottom: .6rem;
  cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.result:hover { border-color: var(--brand-2); }
.result:active { transform: scale(.995); }
.result .name { font-weight: 700; font-size: 1.02rem; line-height: 1.45; }
.result .line { font-size: .84rem; color: var(--muted); margin-top: .15rem; }

.chip {
  display: inline-block;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: .1rem .55rem;
  font-size: .74rem; font-weight: 700;
}
.chip.gray { background: var(--surface-2); color: var(--muted); }
.chip.gold { background: var(--accent-soft); color: var(--accent); }

/* ================= تفاصيل الناخب ================= */
.detail dl { margin: 0; }
.detail .row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .6rem 0;
  border-bottom: 1px dashed var(--border);
}
.detail .row:last-child { border-bottom: 0; }
.detail dt { color: var(--muted); font-size: .84rem; flex: 0 0 auto; }
.detail dd { margin: 0; font-weight: 600; text-align: start; }

/* ================= حالات ================= */
.msg { border-radius: 11px; padding: .7rem .9rem; font-size: .88rem; margin-bottom: .8rem; }
.msg.err  { background: rgba(179,38,30,.1);  color: var(--danger); }
.msg.ok   { background: rgba(26,127,75,.1);  color: var(--ok); }
.msg.info { background: var(--surface-2);    color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 1.2rem;
}
.center-wrap .card { width: 100%; max-width: 420px; margin: 0; }

.logo {
  width: 60px; height: 60px; border-radius: 16px;
  background: #16233a; color: var(--accent);
  border: 1px solid rgba(168,129,58,.45);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto .9rem;
}
.logo svg { width: 28px; height: 28px; }

/* أيقونات الحالات الفارغة */
.empty svg { width: 44px; height: 44px; color: var(--muted); opacity: .55; margin-bottom: .7rem; }

.code-box {
  font-size: 1.6rem; font-weight: 800;
  text-align: center; letter-spacing: normal;
  direction: ltr; unicode-bidi: isolate;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.muted-sm { font-size: .78rem; color: var(--muted); line-height: 1.6; }

.pager { display: flex; gap: .5rem; margin-top: .8rem; }
