/* ===== معرض الصور — تصميم متجاوب يبدأ من الهاتف ===== */

:root {
  --bg: #0f1115;
  --bg-2: #151922;
  --surface: #1a1f2b;
  --surface-2: #212837;
  --line: #2b3446;
  --text: #e8ecf4;
  --muted: #97a1b5;
  --accent: #4c8dff;
  --accent-ink: #ffffff;
  --danger: #ff5f6b;
  --ok: #34c98a;
  --warn: #ffb020;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-2: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --line: #dde3ee;
    --text: #161c26;
    --muted: #5f6b80;
    --shadow: 0 6px 20px rgba(20, 30, 55, .08);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Naskh Arabic", "Tahoma", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; display: block; }

/* ---------- الترويسة ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  max-width: 1100px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-icon { font-size: 20px; }

.whoami { display: flex; align-items: center; gap: 10px; min-width: 0; }
.uname {
  color: var(--muted);
  font-size: 14px;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.logout:active { background: var(--surface-2); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 10px 8px;
  max-width: 1100px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
}
.tab.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- التخطيط ---------- */

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 14px calc(28px + var(--safe-b));
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 17px; }

.meta { color: var(--muted); font-size: 14px; }
.meta .dot { margin: 0 6px; opacity: .6; }
.note { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 10px 0 calc(18px + var(--safe-b));
}

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

.flash {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash-success { background: color-mix(in srgb, var(--ok) 16%, transparent); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.flash-error   { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

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

.form { display: flex; flex-direction: column; gap: 12px; }
.form-inline { padding: 12px 0; border-top: 1px dashed var(--line); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }

input[type="text"],
input[type="password"] {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px; /* يمنع تكبير الصفحة تلقائياً على iOS */
  font-family: inherit;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform .06s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: 14px; }

.danger-zone { border-top: 1px dashed color-mix(in srgb, var(--danger) 45%, transparent); }

/* ---------- تسجيل الدخول ---------- */

.login {
  max-width: 380px;
  margin: 8vh auto 0;
  text-align: center;
}
.login-logo { font-size: 52px; line-height: 1; }
.login-title { margin: 10px 0 4px; font-size: 24px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: start;
  box-shadow: var(--shadow);
}

/* ---------- شبكة الأشخاص ---------- */

.people {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}
@media (min-width: 600px) {
  .people { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
}

.person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.person:active { transform: scale(.98); }
.person[hidden] { display: none; }
.person.is-unnamed { opacity: .78; }

.person-face {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-2);
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
}
.person-face img { width: 100%; height: 100%; object-fit: cover; }
.person-noface { font-size: 26px; color: var(--muted); }

.person-name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.35;
  margin-top: 6px;
  overflow-wrap: anywhere;
}
.person-count { color: var(--muted); font-size: 11px; }

.search { margin-bottom: 10px; }
.search input[type="search"] {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.empty-search { text-align: center; }

/* ---------- ترويسة الشخص ---------- */

.back {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 10px;
}

.ph-row { display: flex; align-items: center; gap: 12px; }
.ph-face {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  flex: none;
}
.ph-text { min-width: 0; }
.ph-text h2 { margin: 0 0 2px; font-size: 20px; overflow-wrap: anywhere; }

.dl-group { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.dl-group .btn { width: 100%; }
@media (min-width: 600px) {
  .dl-group { flex-direction: row; flex-wrap: wrap; }
  .dl-group > .btn { width: auto; }
}

.parts { width: 100%; }
.parts-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.parts-row { display: flex; gap: 6px; flex-wrap: wrap; }

.lb-dl {
  position: absolute;
  bottom: calc(44px + var(--safe-b));
  inset-inline: 0;
  margin: 0 auto;
  width: max-content;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
}

/* ---------- منطقة الرفع ---------- */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 14px;
  text-align: center;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.dz-icon { font-size: 30px; }
.dz-title { font-weight: 700; margin-top: 4px; }
.dz-hint { color: var(--muted); font-size: 13px; margin-top: 2px; }
.dz-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.dz-status { margin-top: 14px; }
.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s ease;
}
.dz-status-text { color: var(--muted); font-size: 13px; margin-top: 6px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- الشبكة ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
}

.cell {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: zoom-in;
}
.cell img { width: 100%; height: 100%; object-fit: cover; }

.cell-bar {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, .65), transparent);
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: none;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger { background: color-mix(in srgb, var(--danger) 75%, black); }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty-icon { font-size: 44px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}
.pager-info { color: var(--muted); font-size: 14px; }

/* ---------- العارض ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, .94);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 82vh;
  object-fit: contain;
}
.lb-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  inset-inline-end: 12px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: none;
  background: rgba(255, 255, 255, .10);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
}
.lb-prev { inset-inline-start: 8px; }
.lb-next { inset-inline-end: 8px; }
.lb-info {
  position: absolute;
  bottom: calc(14px + var(--safe-b));
  inset-inline: 0;
  text-align: center;
  color: #cfd6e4;
  font-size: 13px;
  padding: 0 16px;
}

/* ---------- الإحصاءات ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 12px; }

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

.user-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--bg-2);
  overflow: hidden;
}
.user-card.is-off { opacity: .68; }
.user-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-card > summary::-webkit-details-marker { display: none; }
.user-card[open] > summary { border-bottom: 1px solid var(--line); }

.uc-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.uc-name { font-weight: 700; }
.uc-alias { color: var(--muted); font-size: 14px; }
.uc-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.uc-count { color: var(--muted); font-size: 12px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge-admin { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--text); }
.badge-off { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--text); }

.uc-body { padding: 4px 14px 14px; }
.uc-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 0; border-top: 1px dashed var(--line); }
.uc-actions form { margin: 0; }
