/* =====================================================================
   🎨 نظام الثيمات المعياري المنفصل (Modular Multi-Theme System)
   كل ثيم محفوظ ومفصول بملف مستقل في themes/ لضمان أقصى درجات التوافق
   ===================================================================== */
@import url("themes/theme-light.css?v=20261008_v2");
@import url("themes/theme-dark.css?v=20261008_v2");
@import url("themes/theme-emerald.css?v=20261008_v2");
@import url("themes/theme-gold.css?v=20261008_v2");
@import url("themes/theme-burgundy.css?v=20261008_v2");


* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: "Noto Kufi Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
  background:
    radial-gradient(1400px 500px at 50% -200px, rgba(111,45,53,.05), transparent 70%),
    var(--bg-outer);
  color: var(--ink);
  line-height: 1.7;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  transition: background-color .25s ease, color .25s ease;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 22px; }
/* الورقة الرئيسية: خلفية بيضاء متمركزة بين هوامش فاتحة */
.main-sheet {
  max-width: 1160px; margin: 0 auto; background: var(--bg);
  border-inline: 1px solid rgba(217,169,63,.28);
  box-shadow: 0 0 0 1px rgba(31,41,51,.04), 0 10px 30px rgba(31,41,51,.08);
}
.main { padding: 26px 18px 60px; min-height: calc(100vh - 140px); }

/* الشريط العلوي */
.site-notice-banner {
  background: var(--banner-bg, #b8860b);
  color: var(--banner-color, #fff);
  padding: 8px 16px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .3px;
}
.topbar {
  background: var(--topbar-bg, linear-gradient(180deg, #46545f 0%, #3c4a56 55%, #34414c 100%));
  color: #fff;
  border-bottom: 1px solid var(--topbar-border, rgba(244,217,138,.35));
  box-shadow: 0 2px 14px rgba(15,23,32,.25), inset 0 -1px 0 rgba(255,255,255,.05);
  position: relative;
  max-width: 1160px; margin: 14px auto 0;
  border-radius: 16px 16px 0 0;
  border-inline: 1px solid var(--topbar-border, rgba(244,217,138,.25));
}
.topbar::after {
  content: ''; position: absolute; right: 0; left: 0; bottom: -3px; height: 2px;
  background: var(--topbar-line-glow, linear-gradient(90deg, transparent 0%, rgba(217,169,63,.85) 18%,
              rgba(244,217,138,.95) 50%, rgba(217,169,63,.85) 82%, transparent 100%));
  pointer-events: none;
}
.topbar a { color: #eef2f5; }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 68px; gap: 8px; position: relative;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 0; text-decoration: none; }
a.brand:hover { text-decoration: none; }
a.brand:hover .brand-title { filter: brightness(1.08); }
.brand-mark {
  display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 50%;
  background: var(--brand-mark-bg, radial-gradient(circle at 30% 25%, #55656f 0%, #3c4a56 60%, #2e3944 100%));
  box-shadow:
    0 0 0 2px rgba(244,217,138,.55),
    0 0 0 4px rgba(244,217,138,.14),
    0 4px 12px rgba(15,23,32,.45),
    inset 0 1px 3px rgba(255,255,255,.14);
  position: relative;
  transition: transform .25s ease, box-shadow .25s ease;
}
.brand-mark img { width: 30px; height: 30px; object-fit: contain; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); border-radius: 4px; }
.brand:hover .brand-mark {
  transform: scale(1.05) rotate(-2deg);
  box-shadow:
    0 0 0 2px rgba(244,217,138,.8),
    0 0 16px rgba(244,217,138,.35),
    0 4px 14px rgba(15,23,32,.5),
    inset 0 1px 3px rgba(255,255,255,.18);
}
.brand-sub { font-size: 12.5px; color: #cfd8df; }
.brand-title {
  font-weight: 800; font-size: 1.25rem; line-height: 1.15; letter-spacing: .2px;
  white-space: nowrap;
  background: linear-gradient(180deg, #ffffff 55%, #f4d98a 130%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 1px 1px rgba(0,0,0,.18);
}
.brand-title small {
  display: block; font-size: 11.5px; font-weight: 600; margin-top: 2px;
  color: #e9d9ae; letter-spacing: .3px; white-space: nowrap;
}

/* زر القائمة للشاشات الصغيرة */
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid rgba(244,217,138,.35);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #f4d98a;
  border-radius: 2px;
  transition: all .2s ease;
}

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13.5px;
  flex-wrap: nowrap;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav a {
  font-weight: 600; padding: 6px 9px; border-radius: 8px;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.nav a:hover {
  color: #ffe9bd; background: rgba(244,217,138,.12); text-decoration: none;
}
.user-chip {
  background: rgba(244,217,138,.15); border: 1px solid rgba(244,217,138,.35);
  padding: 4px 12px; border-radius: 999px; font-size: 13px; color: #ffe9bd;
}

/* هوية المستخدم أقصى يسار التوب بار - حرة تماماً بدون أي إطار أو بطاقة أو خلفية */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.user-header-block {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0;
  transition: opacity .2s ease;
}
.user-header-block:hover {
  text-decoration: none;
  opacity: 0.92;
}
.user-header-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: left;
  gap: 1px;
}
.user-header-name {
  font-weight: 800;
  font-size: 13.5px;
  color: #ffffff;
  letter-spacing: .2px;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.user-header-role {
  font-size: 11px;
  font-weight: 600;
  color: #f4d98a;
  letter-spacing: .3px;
  white-space: nowrap;
}

/* الصورة الشخصية بحجم 44x44 متناسقة مع اللوجو وبنفس التدرج والحدود الذهبية الملكية */
.user-avatar-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: var(--brand-mark-bg, radial-gradient(circle at 30% 25%, #55656f 0%, #3c4a56 60%, #2e3944 100%));
  box-shadow:
    0 0 0 2px rgba(244,217,138,.55),
    0 0 0 4px rgba(244,217,138,.14),
    0 4px 12px rgba(15,23,32,.45),
    inset 0 1px 3px rgba(255,255,255,.14);
  position: relative;
  overflow: hidden;
  transition: transform .25s ease, box-shadow .25s ease;
}
.user-header-block:hover .user-avatar-mark {
  transform: scale(1.05) rotate(2deg);
  box-shadow:
    0 0 0 2px rgba(244,217,138,.8),
    0 0 16px rgba(244,217,138,.35),
    0 4px 14px rgba(15,23,32,.5),
    inset 0 1px 3px rgba(255,255,255,.18);
}
.user-avatar-mark .user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.user-avatar-mark .user-avatar-icon {
  font-size: 22px;
  color: #f4d98a;
  display: block;
  line-height: 1;
}

/* بطاقة الهوية الأفقية لصفحة البروفايل */
.profile-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  box-shadow: var(--shadow);
}
.profile-hero-left {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  min-width: 260px;
}
.profile-hero-avatar {
  position: relative;
  width: 84px;
  height: 84px;
  flex: 0 0 84px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}
.profile-hero-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-hero-details h2 {
  margin: 0 0 4px;
  font-size: 20px;
  color: var(--ink);
}
.profile-hero-details p {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}
.profile-stats-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.profile-stat-pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
}
.profile-stat-pill span.label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.profile-stat-pill span.val {
  font-weight: 700;
  color: var(--ink);
}
.profile-avatar-upload-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-link {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  padding: 4px 10px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  transition: all .15s ease;
}
.inline-form button.btn-link { line-height: inherit; vertical-align: middle; }
.btn-link:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  text-decoration: none;
}
.btn-link.danger {
  background: rgba(185, 28, 28, .08);
  border-color: rgba(185, 28, 28, .25);
  color: #b91c1c;
}
.btn-link.danger:hover {
  background: #b91c1c;
  color: #ffffff;
  border-color: #b91c1c;
}

@media (max-width: 840px) {
  .profile-hero {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 16px 18px;
  }
  .profile-stats-bar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .profile-stat-pill {
    width: 100%;
  }
  .profile-avatar-upload-box {
    width: 100%;
  }
}


/* الفوتر */
.footer {
  border-top: 1px solid var(--line);
  padding: 22px 0;
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
}
.footer-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.footer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.footer-meta strong {
  color: var(--ink);
  font-weight: 700;
}
.footer-desc {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (min-width: 1025px) and (max-width: 1180px) {
  .nav { gap: 1px; font-size: 12.5px; }
  .nav a { padding: 5px 6px; }
  .brand-title { font-size: 1.15rem; }
  .brand-title small { font-size: 10.5px; }
  .user-header-name { font-size: 12.5px; }
  .topbar-inner { gap: 4px; }
}

@media (max-width: 1024px) {
  .topbar { margin-top: 0; border-radius: 0; }
  .user-profile-bar {
    padding: 2px 8px 2px 4px;
    gap: 8px;
  }
  .user-avatar-frame {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
  }
  .user-avatar-placeholder {
    font-size: 20px;
  }
  .user-name {
    font-size: 12px;
  }
  .user-role-badge {
    font-size: 10px;
  }
  .nav-toggle { display: flex; }
  .nav {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: #34414c;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 18px 18px;
    border-bottom: 2px solid rgba(244,217,138,.5);
    box-shadow: 0 10px 24px rgba(0,0,0,.3);
    z-index: 999;
  }
  .nav.nav-open {
    display: flex;
  }
  .nav a {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,.07);
  }
  .footer-wrap {
    flex-direction: column;
    text-align: center;
    gap: 6px;
  }
}

/* أزرار */
.btn {
  display: inline-block; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  padding: 9px 18px; border-radius: var(--radius);
  font-size: 14px; cursor: pointer; font-family: inherit;
  text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-ghost { color: var(--navy); border-color: var(--line-strong); background: var(--surface-2); font-weight: 600; }
.btn-ghost:hover { background: var(--surface); color: var(--accent); }
.btn-danger { color: var(--err); border-color: rgba(220, 38, 38, .3); background: rgba(220, 38, 38, .08); font-weight: 600; }
.btn-danger:hover { background: rgba(220, 38, 38, .16); color: var(--err); }
.export-label { font-weight: 700; color: var(--navy); }

/* أزرار التوثيق */
.doc-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* صندوق البحث */
.searchbox { margin-top: 6px; }
.searchbox-row { display: flex; gap: 8px; }
.input-search {
  flex: 1; padding: 12px 18px; font-size: 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-family: inherit; background: var(--surface); color: var(--ink);
}
.input-search:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; border-color: var(--accent-2); }
.searchbox-sm .input-search { padding: 9px 12px; font-size: 14px; }

/* البطل */
.hero { text-align: center; padding: 34px 0 12px; }
.hero h1 { font-size: 30px; margin: 0 0 8px; color: var(--navy); }
.hero-sub { color: var(--muted); margin: 0 0 20px; }

/* شرائح التصنيف */
.cats { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 18px 0; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 8px 18px; border-radius: 999px; font-size: 14px;
  color: var(--ink); box-shadow: var(--shadow);
}
.cat-chip span { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.cat-chip:hover { border-color: var(--accent); text-decoration: none; box-shadow: 0 2px 8px rgba(111,45,53,.15); }

.quick { display: grid; gap: 12px; margin-top: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: block; }
.card h3 { margin: 0 0 4px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

/* تخطيط النتائج */
.layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; margin-top: 16px; }
.layout.layout--full, .layout--full {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  grid-template-columns: 1fr !important;
}
.layout.layout--full > .page-main, .layout--full > .page-main {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  grid-column: 1 / -1 !important;
}
.filters h3 { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.filter-item {
  display: block; padding: 6px 10px; border-radius: 8px;
  font-size: 14px; color: var(--ink); margin-bottom: 2px;
}
.filter-item:hover { background: var(--surface-2); text-decoration: none; }
.filter-item.on { background: var(--accent); color: #fff; font-weight: 600; }
.filter-item .cat-ico { font-size: 15px; line-height: 1; }
.filter-item .cat-n { margin-right: auto; font-size: 12px; color: var(--muted); padding-right: 8px; }
.filter-item.on .cat-n { color: #ffd9bd; }
.page-main { min-width: 0; }
.side-div { margin: 14px 0 10px; border: 0; border-top: 1px solid var(--line); }
.side-title { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.side-link { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 8px; font-size: 13px; color: var(--ink); }
.side-link:hover { background: var(--surface-2); color: var(--accent-2); text-decoration: none; }
.side-fav-wrap { position: relative; width: 16px; height: 16px; flex: 0 0 16px; }
.side-fav-glyph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; }
.side-fav { position: relative; display: block; width: 16px; height: 16px; border-radius: 3px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.results-head h1 { font-size: 22px; margin: 0; color: var(--navy); }
.results-head h1 small { color: var(--muted); font-size: 15px; font-weight: 400; }
.results-head .searchbox { flex: 1; max-width: 420px; }

/* بطاقة ترويسة المستندات والبحث الفوري والفرز */
.results-head-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.results-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.results-head-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.results-search-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 2px 0;
}
.searchbox-centered {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.sort-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sort-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
}
.sort-pills {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}
.sort-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  text-decoration: none;
  transition: all .15s ease;
}
.sort-pill:hover {
  background: var(--surface);
  color: var(--accent-2);
  border-color: var(--accent);
  text-decoration: none;
}
.sort-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(111,45,53,.25);
}
.sort-select-more {
  padding: 4px 8px;
  border: 1px dashed #cbd5e1;
  border-radius: 999px;
  background: transparent;
  font-size: 11px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  outline: none;
}
.sort-select-more:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.sort-select {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.sort-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(111,45,53,.15);
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--surface-2);
  color: var(--ok);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.clear-filter-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.clear-filter-btn:hover {
  text-decoration: underline;
}

/* شريط البحث والفرز في المكتبة */
.lib-search-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}
.lib-main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.lib-main-head-info {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.results-list, .files-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 20px; }
.result-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.result-card h3 { margin: 0 0 4px; font-size: 16px; }
.result-card h3 a { color: var(--navy); text-decoration: none; }
.result-card h3 a:hover { color: var(--accent); text-decoration: underline; }
.result-cat { display: inline-block; font-size: 12px; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 1px 10px; margin: 0 0 6px; }
.result-snippet { margin: 0; font-size: 14px; color: var(--ink); line-height: 1.8; }
.result-snippet mark { background: var(--gold-light); color: #000; padding: 0 3px; border-radius: 3px; }

/* قائمة الملفات */
.file-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.file-link { color: var(--ink); display: block; }
.file-link:hover { text-decoration: none; }
.file-name { font-weight: 600; font-size: 15px; display: block; }
.file-meta { font-size: 12px; color: var(--muted); }

.pager { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); margin-top: 8px; }

.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--line); padding: 26px; border-radius: var(--radius); text-align: center; }

/* صفحة الملف */
.doc-head { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 16px; }
.doc-head h1 { margin: 0 0 4px; font-size: 22px; word-break: break-word; color: var(--ink-heading); }
.doc-meta { color: var(--muted); font-size: 13.5px; margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 12px; font-size: 12px; font-weight: 500; }
.badge-warn { background: var(--gold); color: #000; font-weight: 700; }
.badge-soft { background: var(--surface-2); color: var(--accent-2); border: 1px solid var(--line); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.doc-qbar-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  color: var(--ink);
}

/* 1. بطاقة نص المستند الكامل */
.doc-fulltext-card {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px 26px;
  margin-bottom: 18px;
}
.doc-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 18px;
}
.doc-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.doc-card-title h2 {
  margin: 0;
  font-size: 18px;
  color: var(--ink-heading);
}
.doc-text-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-tool {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.btn-tool:hover {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.doc-paper-content {
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  line-height: 2.05;
  letter-spacing: 0.15px;
  text-align: justify;
  transition: font-size 0.15s ease;
}
.doc-text-p {
  margin: 0 0 16px 0;
  text-indent: 1.5em;
}
.doc-text-p:last-child {
  margin-bottom: 0;
}
.doc-paper-content mark, .doc-indexed-body mark {
  background: var(--gold-light);
  color: #000;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 600;
}

/* 2. بطاقة الفقرات المستخرجة والمفهرسة */
.doc-indexed-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 18px;
}
.doc-indexed-details {
  width: 100%;
}
.doc-indexed-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
  list-style: none;
}
.doc-indexed-summary::-webkit-details-marker {
  display: none;
}
.summary-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: var(--ink);
}
.summary-hint {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 6px;
}
.doc-indexed-body {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.doc-paras-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-indexed-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14.5px;
  line-height: 1.7;
}
.para-num {
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.para-content {
  flex: 1;
  color: var(--ink);
}

.doc-body { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.doc-para { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; margin: 0; font-size: 15px; }
.doc-para mark { background: var(--gold-light); color: #000; padding: 0 3px; border-radius: 3px; }

/* اللوحات */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0; }
@media (max-width: 760px) { .layout { grid-template-columns: 1fr; } .admin-grid { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.stat-list div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.stat-list dd { margin: 0; font-weight: 700; }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.stack-form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.stack-form input, .stack-form select, .stack-form textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; background: var(--surface); color: var(--ink);
}
.row-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row-form label { flex: 1; min-width: 170px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.table tbody tr:nth-child(odd) { background: var(--surface-2); }
.table tbody tr:hover { background: rgba(120, 120, 120, .08); }
.muted { color: var(--muted); font-size: 12px; }
.table-actions { display: flex; gap: 10px; }
.inline-form { display: inline-flex; }

/* قواعد التكيف مع الثيمات والوضع الداكن */
html[data-theme="dark"] .main-sheet {
  background: var(--bg);
  border-inline-color: rgba(244,217,138,.12);
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-2) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .results-head,
html[data-theme="dark"] .results-head-card,
html[data-theme="dark"] .cat-chip,
html[data-theme="dark"] .date-card,
html[data-theme="dark"] .dates-result,
html[data-theme="dark"] .user-edit-box {
  background: var(--surface);
  border-color: var(--line);
}
html[data-theme="dark"] .set-tab {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"] .set-tab:hover {
  background: var(--surface-2);
}
html[data-theme="dark"] .set-tab.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme="dark"] .chip {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--gold-light);
}

/* الرسائل */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin: 10px 0; }
.alert-error { background: #fbeae6; color: var(--err); border: 1px solid #f3ccc3; }
.alert-ok { background: #e8f4ee; color: var(--ok); border: 1px solid #c6e5d5; }
.alert-warn { background: #fdf3e3; color: #8a5a13; border: 1px solid #ecd9ae; }

/* الدخول */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 360px; max-width: 92vw; box-shadow: 0 6px 24px rgba(31,41,51,.10); }
.brand-center { flex-direction: column; text-align: center; gap: 4px; margin-bottom: 14px; }
.brand-center .brand-mark { width: 64px; height: 64px; flex: 0 0 64px; }
.brand-center .brand-mark img { width: 48px; height: 48px; }
.brand-center .brand-title { font-size: 30px; font-weight: 800; }
.brand-center .brand-sub { color: var(--muted); }
.login-hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0 0 12px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.login-form input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; font-family: inherit; }
.login-foot { text-align: center; color: #a3a9b1; font-size: 12px; margin-top: 14px; }

.footer {
  background: var(--footer-bg, linear-gradient(180deg, #3c4a56, #34414c));
  color: var(--footer-color, #b9c4d0);
  font-size: 13px;
  text-align: center;
  padding: 18px 0;
  border-top: 1px solid var(--footer-border, rgba(244,217,138,.3));
  border-radius: 0 0 16px 16px;
  position: relative;
}
.footer::before {
  content: '';
  position: absolute;
  top: -1px;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--footer-line-glow, transparent);
  pointer-events: none;
}
/* البحث الفوري */
.live-results { width: 100%; flex-basis: 100%; clear: both; margin: 14px 0 24px; }
.live-results[hidden] { display: none; }
.live-count { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.live-more { margin-top: 12px; }
.live-more a { font-weight: 600; color: var(--accent); }

/* ---------- الإحصائيات والتقارير ---------- */
.filterbar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; box-shadow: var(--shadow); }
.filterbar label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.filterbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; background: var(--surface-2); color: var(--ink); }
.filterbar select option { background: var(--surface); color: var(--ink); }
.filterbar-actions { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; flex: 1; justify-content: space-between; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink); border-radius: 20px; padding: 5px 12px; font-size: 12px; font-weight: 600; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats-grid .card { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.stats-grid .card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.hero-num { font-size: 30px; font-weight: 800; color: var(--ink-heading); line-height: 1.1; }
.card-hero { border-top: 4px solid var(--accent); }

.panel-head { display: flex; justify-content: space-between; align-items: center; }
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.insights div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.ins-label { font-size: 12px; color: var(--muted); }
.insights b { font-size: 16px; color: var(--ink); }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-label { min-width: 110px; font-size: 14px; display: flex; align-items: center; gap: 6px; color: var(--ink); }
.bar-label-year { min-width: 150px; }
.bar-label b { color: var(--ink); }
.bar { flex: 1; height: 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 10px; min-width: 1px; }
.bar-fill-year { background: linear-gradient(90deg, #b0521c, #d98a47); }
.bar-pct { min-width: 52px; font-size: 13px; color: var(--muted); text-align: left; }
.delta { font-size: 11px; font-weight: 700; margin-right: 6px; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--err); }

.month-grid-wrap { overflow-x: auto; max-width: 100%; padding-bottom: 6px; }
.month-grid { display: grid; grid-template-columns: repeat(12, 1fr); min-width: 480px; gap: 8px; align-items: end; margin-top: 14px; }
.month-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.month-bar { height: 120px; width: 100%; max-width: 40px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px 8px 0 0; display: flex; align-items: flex-end; overflow: hidden; }
.month-fill { width: 100%; background: linear-gradient(180deg, var(--accent), var(--accent-2)); min-height: 2px; }
.month-label { font-size: 10px; color: var(--muted); }
.month-count { font-size: 12px; font-weight: 700; color: var(--ink); }

.table-scroll { overflow-x: auto; max-width: 100%; box-sizing: border-box; }
.table-matrix th, .table-matrix td { text-align: center; white-space: nowrap; font-size: 13px; color: var(--ink); }
.table-matrix th:first-child, .table-matrix td:first-child { text-align: right; }

.report-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 8px 0 20px; }
.export-group { display: inline-flex; gap: 10px; align-items: center; }

/* شريط التوزيع النوعي للفرز */
.sort-dist-box {
  margin: 20px 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 16px;
  border-radius: 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sort-dist-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-heading);
}
.sort-dist-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.sort-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}
.sort-badge.badge-ok { border-color: rgba(22, 163, 74, 0.4); background: rgba(22, 163, 74, 0.1); color: var(--ok); }
.sort-badge.badge-dup { border-color: rgba(217, 119, 6, 0.4); background: rgba(217, 119, 6, 0.1); color: var(--gold); }
.sort-badge.badge-rej { border-color: rgba(220, 38, 38, 0.4); background: rgba(220, 38, 38, 0.1); color: var(--err); }
.sort-badge.badge-uns { border-color: rgba(234, 88, 12, 0.4); background: rgba(234, 88, 12, 0.1); color: #ea580c; }
.sort-dist-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--line-strong);
  border: 1px solid var(--line);
}
.sort-dist-seg.seg-ok { background: var(--ok, #16a34a); }
.sort-dist-seg.seg-dup { background: var(--gold, #d97706); }
.sort-dist-seg.seg-rej { background: var(--err, #dc2626); }
.sort-dist-seg.seg-uns { background: #ea580c; }

.status-badge-ok { background: rgba(21, 128, 61, 0.15); color: var(--ok); border: 1px solid var(--ok); }
.status-badge-warn { background: rgba(180, 83, 9, 0.15); color: var(--gold); border: 1px solid var(--gold); }
.status-badge-err { background: rgba(185, 28, 28, 0.15); color: var(--err); border: 1px solid var(--err); }


/* التقرير للطباعة */
.report-bar { display: flex; gap: 10px; margin-bottom: 14px; }
.report { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; padding: 28px 34px; }
.report-head { border-bottom: 2px solid var(--line-strong); padding-bottom: 14px; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; }
.report-brand { background: var(--navy); color: #fff; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; }
.report-head h1 { margin: 0; font-size: 22px; color: var(--ink-heading); }
.report h2 { color: var(--ink-heading); font-size: 16px; margin: 22px 0 8px; border-right: 4px solid var(--accent); padding-right: 10px; }
.table-meta td, .table-meta th { padding: 6px 10px; color: var(--ink); }
.table-meta th { width: 230px; }
.report-barline { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.report-barlabel { min-width: 140px; font-size: 13px; color: var(--ink); }
.report-foot { border-top: 1px solid var(--line); margin-top: 26px; padding-top: 12px; color: var(--muted); font-size: 12px; text-align: center; }

@media print {
  .topbar, .footer, .report-bar, .filterbar { display: none !important; }
  body { background: #fff; color: #000; }
  .report { border: none; border-radius: 0; padding: 0; box-shadow: none; background: #fff; color: #000; }
  .main { max-width: 100%; }
  .bar-fill, .bar-fill-year, .month-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ---------- مولّد التقارير والرؤى ---------- */
.report-gen { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 4px; }
.report-gen label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.report-gen select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; background: var(--surface-2); color: var(--ink); }
.report-gen select option { background: var(--surface); color: var(--ink); }
.report-gen label[hidden] { display: none; }
.report-kind-desc { margin-top: 10px; }
.insight-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.insight-list li { padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.7; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-right: 4px solid var(--line-strong); }
.insight-list li.tone-pos { border-right-color: var(--ok); background: rgba(21, 128, 61, 0.09); }
.insight-list li.tone-warn { border-right-color: var(--gold); background: rgba(180, 83, 9, 0.09); }
.insight-list li.tone-info { border-right-color: var(--accent); background: rgba(111, 44, 62, 0.08); }
.insight-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.insight-box h2 { margin: 0 0 12px; font-size: 17px; color: var(--ink-heading); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; vertical-align: middle; }
.table-compare th { text-align: center; }
.table-compare td { text-align: center; }
.comparercell { text-align: center; }
.compare-cell b { display: block; margin-bottom: 4px; }
.bar-sm { height: 8px; }

.layout--full { grid-template-columns: 1fr; }

.qr-card { display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px; margin: 16px 0; }
.qr-info { flex: 1 1 260px; }
.qr-info h2 { margin: 0 0 4px; font-size: 16px; color: var(--ink-heading); }
.qr-info h3 { margin: 0 0 4px; font-size: 15px; color: var(--ink-heading); }
.qr-url { font-size: 12px; color: var(--muted); direction: ltr; word-break: break-all; }
.qr-img { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 6px; }
.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media print {
  body * { visibility: hidden; }
  .qr-card, .qr-card * { visibility: visible; }
  .qr-card { position: fixed; inset: 0; border: 0; margin: 12px; padding: 0; }
}

/* ---- فحص الهوية (scan) ---- */
.scan-intro h1 { margin-bottom: 6px; color: var(--ink-heading); }
.scan-capture, .scan-fields { margin-top: 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.scan-cam { cursor: pointer; text-align: center; font-size: 16px; }

/* تبويبات وسائل الإدخال */
.scan-tabs-nav {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.scan-tabs-nav .btn-tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s ease;
  white-space: nowrap;
}
.scan-tabs-nav .btn-tab:hover {
  color: var(--ink);
  background: var(--surface-2);
}
.scan-tabs-nav .btn-tab.active {
  color: var(--ink-heading);
  background: var(--surface-2);
  border-color: var(--line);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -6px;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.03);
}

.scan-tab-pane {
  padding: 4px 0 10px;
}

/* مظهر كاميرا الجهاز المدمجة */
.scan-cam-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.scan-cam-viewport {
  position: relative;
  width: 100%;
  max-width: 540px;
  height: 320px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}
.scan-cam-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.scan-cam-viewport video.mirror {
  transform: scaleX(-1);
}
.scan-cam-placeholder {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.scan-cam-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 82%;
  height: 70%;
  border: 2px solid rgba(59, 130, 246, 0.9);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
}
.scan-cam-guide span {
  font-size: 12px;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.85);
  color: #93c5fd;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.scan-cam-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 540px;
  gap: 10px;
  flex-wrap: wrap;
}
.scan-cam-tools {
  display: flex;
  gap: 6px;
  align-items: center;
}
.scan-cam-select {
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-snap-lg {
  font-size: 15px;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: 10px;
  background: var(--ok);
  color: #fff;
  flex: 1;
  min-width: 180px;
}

/* منطقة سحب وإفلات الملفات */
.scan-upload-area {
  border: 2px dashed var(--line-strong);
  border-radius: 14px;
  padding: 36px 20px;
  text-align: center;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: all .2s ease;
}
.scan-upload-area:hover, .scan-upload-area.dragover {
  border-color: var(--accent);
  background: var(--surface);
}
.upload-icon {
  font-size: 38px;
  display: block;
  margin-bottom: 8px;
}
.upload-title {
  font-size: 15px;
  color: var(--ink);
  margin: 0 0 6px;
}

/* معاينة الصورة المشتركة */
.scan-preview-wrap {
  margin-top: 16px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  color: var(--ink);
}
.preview-title {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--ink-heading);
}
.scan-preview-wrap img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.preview-actions {
  margin-top: 10px;
}

.scan-note { margin-top: 12px; font-size: 14px; }
.scan-busy { color: var(--muted); font-weight: 500; }
.scan-err { color: var(--err); background: rgba(185, 28, 28, 0.1); border: 1px solid var(--err); border-radius: 8px; padding: 10px 14px; }
.scan-extracted { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin: 12px 0; }
.scan-extracted div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.scan-extracted dt { font-size: 12px; color: var(--muted); }
.scan-extracted dd { margin: 2px 0 0; font-weight: 600; direction: ltr; text-align: right; word-break: break-all; color: var(--ink); }
.scan-mode { display: flex; gap: 14px; margin: 12px 0; }
.scan-mode-opt { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; color: var(--ink); }
.scan-input { display: block; margin: 10px 0; }
.scan-input span { display: block; font-size: 13px; margin-bottom: 4px; color: var(--ink); }
.scan-input input { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.scan-back { margin-top: 14px; }

.pair-body {
  margin: 0;
  background: #f4f1ea;
  font-family: -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.pair-wrap { width: 100%; max-width: 420px; padding: 20px 16px; box-sizing: border-box; }
.pair-card {
  background: #fff;
  border: 1px solid var(--line, #e4ddd0);
  border-radius: 14px;
  padding: 22px 18px;
  margin-top: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
}
.pair-card h1 { font-size: 20px; margin: 0 0 6px; }
.pair-card h2 { font-size: 17px; margin: 0 0 6px; }
.pair-hint { color: #6b655c; font-size: 14px; margin: 0 0 14px; line-height: 1.7; }
.pair-done { text-align: center; padding: 18px 0 8px; }
.pair-done-ico {
  font-size: 42px;
  color: #1f7a4d;
  background: #e7f5ec;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  line-height: 72px;
  margin: 0 auto 12px;
}

/* ---- الأرشيف الورقي (paper archive) ---- */
.archive-edit > summary {
  cursor: pointer;
  list-style: none;
  display: inline-block;
}
.archive-edit > summary::-webkit-details-marker { display: none; }
.archive-edit[open] > summary { color: var(--accent); }
.archive-edit-form {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: max-content;
  min-width: 260px;
  max-width: 460px;
  color: var(--ink);
}
.archive-edit-form label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
}
.archive-edit-form input {
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
}

/* ---------- لوحة التحكم المبوبة (admin dashboard) ---------- */
.dash { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: start; margin-top: 8px; width: 100%; max-width: 100%; box-sizing: border-box; }
.dash > div:not(.dash-nav) { min-width: 0; max-width: 100%; width: 100%; box-sizing: border-box; }
.dash-nav {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; position: sticky; top: 12px;
}
.dash-nav-title { font-size: 12px; color: var(--muted); padding: 16px 16px 6px; font-weight: 700; letter-spacing: .3px; }
.dash-link {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; font-size: 14px;
  color: var(--ink); border: 0; background: none; width: 100%; text-align: right;
  font-family: inherit; cursor: pointer; border-right: 3px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
}
.dash-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.dash-link.on {
  background: var(--surface-2);
  border-right-color: var(--accent);
  color: var(--accent-2);
  font-weight: 700;
}
.dash-link .dash-ico { font-size: 16px; line-height: 1; }
.dash-section[hidden] { display: none; }
.dash-section-title { font-size: 18px; margin: 0 0 4px; color: var(--ink-heading); }
.dash-section-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.dash-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
@media (max-width: 780px) {
  .dash { grid-template-columns: 1fr; }
  .dash-nav { position: static; display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-radius: 12px; }
  .dash-nav-title { display: none; }
  .dash-link { width: auto; border-right: 0; border-bottom: 2px solid transparent; padding: 9px 12px; border-radius: 8px; }
  .dash-link.on { border-bottom-color: var(--accent); background: var(--surface-2); }
}

.stat-cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat-card {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: space-between;
  min-width: 0;
}
.stat-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.stat-card .stat-num { font-size: 20px; font-weight: 800; color: var(--ink); line-height: 1.1; font-feature-settings: "tnum"; white-space: nowrap; }
.stat-card .stat-lbl { font-size: 11.5px; color: var(--muted); line-height: 1.35; white-space: normal; word-break: normal; overflow: visible; font-weight: 600; margin: 0; }
.stat-card .stat-ico {
  font-size: 16px; line-height: 1; opacity: .95;
  width: 28px; height: 28px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--accent-2); flex-shrink: 0;
}
@media (max-width: 1024px) {
  .stat-cards { grid-template-columns: repeat(6, minmax(130px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
}

/* ---------- المكتبة الرقمية (PDF) ---------- */
.lib-hero { text-align: center; padding: 26px 0 6px; }
.lib-hero h1 { font-size: 30px; margin: 0 0 6px; color: var(--navy); }
.lib-hero p { color: var(--muted); margin: 0 auto 16px; max-width: 560px; }
.lib-hero .searchbox { max-width: 640px; margin: 0 auto; }
.lib-count { color: var(--muted); font-size: 13px; text-align: center; margin: 12px 0 0; }

.lib-cats { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin: 22px 0 8px; }
.lib-cat {
  display: flex; align-items: center; gap: 12px; min-width: 230px; flex: 1 1 230px; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.lib-cat:hover { text-decoration: none; border-color: var(--accent); box-shadow: 0 4px 14px rgba(111,45,53,.16); transform: translateY(-2px); }
.lib-cat-ico { font-size: 26px; line-height: 1; width: 44px; height: 44px; border-radius: 12px; background: #f3ece2; display: flex; align-items: center; justify-content: center; flex: 0 0 44px; }
.lib-cat-body { min-width: 0; }
.lib-cat-name { font-weight: 700; font-size: 15px; display: block; }
.lib-cat-meta { font-size: 12px; color: var(--muted); }

.lib-bread { font-size: 13px; color: var(--muted); margin: 14px 0 10px; }
.lib-bread a { color: var(--accent-2); font-weight: 600; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin: 8px 0 24px; }
.lib-file {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s, border-color .12s;
}
.lib-file:hover { text-decoration: none; border-color: var(--accent); box-shadow: 0 4px 14px rgba(111,45,53,.16); transform: translateY(-2px); }
.lib-file-ico { font-size: 34px; line-height: 1; text-align: right; }
.lib-file-name { font-weight: 600; font-size: 14px; color: var(--ink); word-break: break-word; }
.lib-file-meta { font-size: 12px; color: var(--muted); margin-top: auto; display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.lib-file-dl { font-size: 12px; color: var(--accent); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }

/* إدارة المكتبة */
.lib-admin-grid { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.lib-tree { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.lib-tree h3 { margin: 0 0 10px; font-size: 15px; }
.lib-tree-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px; font-size: 14px; color: var(--ink); }
.lib-tree-item:hover { background: #efe9de; text-decoration: none; }
.lib-tree-item.on { background: var(--accent); color: #fff; }
.lib-tree-item .lib-tree-actions { opacity: 0; transition: opacity .12s; display: inline-flex; gap: 6px; }
.lib-tree-item:hover .lib-tree-actions { opacity: 1; }
.lib-tree-item .lib-tree-actions form { display: inline-flex; }
.lib-btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px; color: inherit; }
.dropzone {
  border: 2px dashed var(--line); border-radius: 14px; background: #fbf9f4;
  padding: 26px; text-align: center; color: var(--muted); margin: 0 0 16px;
  transition: border-color .15s, background .15s;
}
.dropzone.on { border-color: var(--accent); background: #fdf4ee; }
.dropzone strong { color: var(--navy); }
.upload-multi { display: grid; gap: 10px; }
.upload-multi .upload-input { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--surface); }

@media (max-width: 860px) {
  .lib-admin-grid { grid-template-columns: 1fr; }
  .lib-cat { flex: 1 1 100%; max-width: none; }
}

/* صفوف ملفات لوحة إدارة المكتبة (مولّدة عبر admin-library.js) */
.lib-file-row {
  display: flex; gap: 8px; align-items: center; padding: 5px 4px;
  border-bottom: 1px dashed var(--line); font-size: 14px; cursor: pointer; color: var(--ink);
}
.lib-file-row:hover { background: var(--surface-2); }
.lib-file-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }

@media (max-width: 1200px) {
  .topbar, .main-sheet { margin-inline: 12px; }
}
@media (max-width: 760px) {
  .topbar { margin-top: 8px; border-radius: 12px 12px 0 0; }
  .main-sheet { margin-inline: 6px; }
  .footer { border-radius: 0 0 12px 12px; }
}

/* نتائج البحث داخل المحتوى (قائمة بصفوف) */
.lib-res-head { margin: 18px 0 10px; font-size: 16px; color: var(--ink-heading); }
.lib-res-head small { font-weight: 500; }
.lib-hits { display: flex; flex-direction: column; gap: 10px; }
.lib-hit {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); color: var(--ink);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.lib-hit:hover {
  border-color: var(--accent); box-shadow: 0 5px 16px rgba(111,45,53,.16);
  transform: translateY(-2px); text-decoration: none;
}
.lib-hit-cover {
  flex: 0 0 52px; width: 52px; height: 74px; border-radius: 6px; aspect-ratio: auto;
  border: 1px solid var(--line);
}
.lib-hit-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.lib-hit-body .lib-book-name { min-height: 0; -webkit-line-clamp: 1; color: var(--ink); }
.lib-hit-snip {
  font-size: 12.5px; color: var(--muted); line-height: 1.7;
  overflow-wrap: anywhere; word-break: break-word;
  background: var(--surface-2); border-inline-start: 3px solid var(--accent);
  padding: 5px 8px; border-radius: 0 6px 6px 0;
}

/* ---------- واجهة المكتبة بنمط alarabimag (قائمة عمودية + شبكة مصغرات) ---------- */
.library-layout { display: grid; grid-template-columns: 264px 1fr; gap: 20px; align-items: start; }
.lib-side {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; position: sticky; top: 12px;
}
.lib-side-title {
  background: var(--navy); color: #fff; font-weight: 800; font-size: 14px;
  padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
}
.lib-side-title .badge { background: rgba(255,255,255,.22); color: #fff; }
.lib-side-list { list-style: none; margin: 0; padding: 8px; }
.lib-side-list li { margin: 2px 0; }
.lib-side-link {
  display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px;
  padding: 9px 10px; border-radius: 9px; color: var(--ink);
  transition: background .12s, color .12s; line-height: 1.6;
}
/* اسم القسم يأخذ النص كاملاً على أسطر متعددة دون تمدد أفقي */
.lib-side-link .cat-name {
  flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; word-break: break-word;
  hyphens: auto; text-align: start;
}
.lib-side-link:hover { background: var(--surface-2); text-decoration: none; color: var(--accent); }
.lib-side-link.on { background: var(--accent); color: #fff; font-weight: 600; }
.lib-side-link .side-count {
  flex: 0 0 auto; margin-inline-start: auto; font-size: 11.5px; color: var(--muted);
  background: var(--surface-2); border-radius: 20px; padding: 1px 7px; line-height: 1.7;
}
.lib-side-link.on .side-count { color: #fff; background: rgba(255,255,255,.24); }
.lib-side-link .cat-ico { font-size: 15px; flex: 0 0 20px; text-align: center; line-height: 1.6; }
.lib-side-foot { padding: 8px 14px 12px; font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; }

.lib-main { min-width: 0; }
/* بطاقات الأقسام — اسم القسم يظهر كاملاً على أسطر متعددة */
.lib-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.lib-cat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); display: flex; align-items: center;
  gap: 12px; min-width: 0; transition: border-color .12s, box-shadow .12s, transform .12s;
}
.lib-cat-card:hover {
  border-color: var(--accent); box-shadow: 0 5px 16px rgba(111,45,53,.16);
  transform: translateY(-2px); text-decoration: none;
}
.lib-cat-card .cat-ico { font-size: 26px; flex: 0 0 auto; }
.lib-cat-card .cat-body { min-width: 0; flex: 1 1 auto; }
.lib-cat-card h3 {
  margin: 0 0 3px; font-size: 14.5px; line-height: 1.65; color: var(--ink); font-weight: 700;
  overflow-wrap: anywhere; word-break: break-word;
}
.lib-cat-card p { margin: 0; color: var(--muted); font-size: 12.5px; }
.lib-cat-card .cat-go { flex: 0 0 auto; color: var(--accent); font-weight: 700; font-size: 13px; }
.lib-main-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px;
}
.lib-main-head h2 { margin: 0; font-size: 22px; color: var(--ink-heading); display: flex; align-items: center; gap: 10px; }
.lib-main-head h2 small { font-size: 13px; color: var(--muted); font-weight: 500; }

/* شبكة بطاقات المصغرات */
.lib-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.lib-book {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.lib-book:hover { border-color: var(--accent); box-shadow: 0 5px 16px rgba(111,45,53,.18); transform: translateY(-3px); }
.lib-book-cover { position: relative; aspect-ratio: 210 / 297; background: var(--surface-2); overflow: hidden; display: block; }
.lib-book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; z-index: 1; }
/* البديل: يظهر تلقائياً خلف الصورة، ويبقى ظاهراً وحده إن فشل تحميل الصورة */
.lib-book-cover .cover-fallback {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 44px; color: var(--muted); z-index: 0;
}
.lib-book-cover.is-fallback {
  background: var(--surface-2);
}
.lib-book-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.lib-book-name {
  font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 39px; word-break: break-word;
}
.lib-book-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: auto; }
.lib-book-size { font-size: 11.5px; color: var(--muted); }
.lib-book-open {
  font-size: 12px; font-weight: 700; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 6px; padding: 3px 8px;
  background: none; cursor: pointer; line-height: 1.4; font-family: inherit;
}
.lib-book-open:hover { background: var(--accent); color: #fff; text-decoration: none; }
.lib-book-btns { display: inline-flex; align-items: center; gap: 5px; }

/* رابط بحث الاسم من الأرشيف الورقي إلى أرشيف المستندات (والمكتبة) */
.lib-search-link-wrap { display: inline-flex; align-items: center; gap: 6px; }
.lib-search-link {
  color: var(--ink); font-weight: 600; text-decoration: none;
  border-bottom: 1px dashed var(--accent); padding-bottom: 1px;
}
.lib-search-link:hover { color: var(--accent); border-bottom-style: solid; }
.lib-search-mini {
  font-size: 13px; text-decoration: none; opacity: .75;
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; color: var(--ink);
}
.lib-search-mini:hover { opacity: 1; border-color: var(--accent); }
.lib-from-note {
  margin-top: 18px; font-size: 13px; color: var(--muted);
  border-top: 1px dashed var(--line); padding-top: 12px;
}
.lib-from-note a { color: var(--accent); font-weight: 600; }

/* ---------- صفحة عرض الملف داخل الموقع ---------- */
.lib-open-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: stretch; }
.lib-open-side {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column;
  gap: 14px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto;
}
.lib-back { align-self: flex-start; }
.lib-open-head { display: flex; gap: 12px; align-items: flex-start; }
.lib-open-ico { font-size: 32px; line-height: 1; }
.lib-open-titles { min-width: 0; }
.lib-open-name {
  margin: 0 0 4px; font-size: 16px; line-height: 1.6; color: var(--ink);
  overflow-wrap: anywhere; word-break: break-word;
}
.lib-open-head p { margin: 0; font-size: 12.5px; overflow-wrap: anywhere; color: var(--muted); }
.lib-open-actions { display: flex; flex-direction: column; gap: 8px; }
.lib-btn-block { width: 100%; text-align: center; }
.lib-admin-box { border-top: 1px solid var(--line); padding-top: 14px; }
.lib-admin-box h3 { margin: 0 0 12px; font-size: 15px; color: var(--ink-heading); }
.lib-admin-form {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
.lib-admin-form:last-child { margin-bottom: 0; }
.lib-admin-form label {
  display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink); font-weight: 600;
}
.lib-admin-form input, .lib-admin-form select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink);
  font-weight: 400; width: 100%;
}
.lib-admin-form input:focus, .lib-admin-form select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}

/* الملف: يتوسط القسم الأكبر بحجم متناسب مع الشاشة */
.lib-open-main {
  min-width: 0; display: flex; align-items: center; justify-content: center;
  background: #56636c; border-radius: 14px; padding: 10px;
  box-shadow: var(--shadow); height: calc(100vh - 24px); position: sticky; top: 12px;
}
.lib-open-frame {
  width: 100%; height: 100%; border: 0; border-radius: 10px; background: #525659;
  display: block;
}

@media (max-width: 900px) {
  .lib-open-layout { grid-template-columns: 1fr; }
  .lib-open-side { position: static; max-height: none; }
  .lib-open-main { height: 70vh; position: static; }
}
/* عند طباعة صفحة العرض: نطبع الملف فقط بلا واجهة */
@media print {
  body { background: #fff; }
  .lib-open-main { background: none; padding: 0; height: auto; box-shadow: none; }
  .lib-open-frame { width: 100%; height: 100vh; border: 0; box-shadow: none; }
}

/* الترقيم */
.lib-pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 22px 0 6px; flex-wrap: wrap; }
.lib-pager a, .lib-pager span {
  min-width: 34px; padding: 7px 10px; border-radius: 8px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-align: center;
}
.lib-pager a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.lib-pager .on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.lib-pager .dots { border: 0; background: none; }
.lib-main .searchbox { margin-bottom: 14px; }

@media (max-width: 940px) {
  .library-layout { grid-template-columns: 200px 1fr; gap: 14px; }
}
@media (max-width: 720px) {
  .library-layout { grid-template-columns: 1fr; }
  .lib-side { position: static; }
  .lib-side-list { display: flex; flex-wrap: wrap; gap: 4px; }
  .lib-side-link { padding: 7px 10px; font-size: 13px; }
  .lib-side-title .badge { display: none; }
  .lib-cats { grid-template-columns: 1fr; }
}

/* ---------- المساعد الذكي (ودجت عائم) ---------- */
#assist-fab {
  position: fixed; bottom: 22px; left: 22px; z-index: 900;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(145deg, #6f2d35, #4f5d69);
  display: flex; align-items: center; justify-content: center; padding: 0;
  box-shadow: 0 6px 20px rgba(31,41,51,.35), inset 0 0 0 2px rgba(244,217,138,.5);
  transition: transform .2s, box-shadow .2s;
}
#assist-fab svg { display: block; }
.assist-title { font-size: 14.5px; letter-spacing: .2px; }
#assist-fab:hover { transform: scale(1.08); box-shadow: 0 8px 26px rgba(31,41,51,.45), 0 0 14px rgba(244,217,138,.4); }
#assist-panel[hidden] { display: none !important; }
#assist-panel {
  position: fixed; bottom: 90px; left: 22px; z-index: 901;
  width: min(350px, calc(100vw - 32px)); height: min(500px, calc(100vh - 130px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 16px 44px rgba(31,41,51,.28); display: flex; flex-direction: column;
  overflow: hidden;
}
.assist-head {
  background: linear-gradient(180deg, #46545f, #3c4a56); color: #fff;
  padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 700;
}
.assist-head-btns { display: flex; gap: 8px; align-items: center; }
.assist-new, .assist-min, .assist-close { background: none; border: none; color: #fff; font-size: 15px; cursor: pointer; opacity: .85; transition: opacity .15s; }
.assist-new:hover, .assist-min:hover, .assist-close:hover { opacity: 1; color: var(--gold, #f6e7c1); }
.assist-history-link-wrap {
  text-align: center; margin: 4px 0 8px;
}
.assist-history-link {
  display: inline-block; font-size: 12px; color: var(--accent);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
  background: transparent; border: none; font-family: inherit; padding: 2px 6px;
  transition: color .15s;
}
.assist-history-link:hover { color: var(--accent-2); text-decoration: underline; }
.assist-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.assist-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.8; }
.assist-msg.user { align-self: flex-start; background: var(--navy); color: #fff; border-bottom-right-radius: 3px; }
.assist-msg.bot { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.assist-msg a { color: var(--accent); font-weight: 700; }
.assist-src { margin-top: 6px; font-size: 11.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 4px; }
.assist-actions { display: flex; gap: 6px; margin-top: 6px; }
.assist-actions button {
  background: none; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  font-size: 13px; padding: 1px 6px;
}
.assist-actions button:hover { border-color: var(--accent); }
.assist-typing { color: var(--muted); }
.assist-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.assist-chip {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; font-family: inherit; color: var(--ink);
  transition: all .15s ease;
}
.assist-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.assist-form { position: relative; display: flex; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.assist-form input {
  flex: none; width: 90%; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--ink);
  padding: 10px 16px; padding-inline-end: 56px; font-family: inherit; font-size: 13.5px;
}
.assist-send {
  position: absolute; inset-inline-end: calc(10% + 12px); top: 50%; transform: translateY(-50%);
  border: none; border-radius: 999px; width: 38px; height: 34px;
  cursor: pointer; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1; padding: 0;
}
.assist-send:hover { background: var(--accent-2); }
.assist-wa {
  display: block; text-align: center; font-size: 12px; padding: 8px;
  background: rgba(46, 125, 50, 0.08); color: #2e7d32; text-decoration: none; font-weight: 600;
  border-top: 1px solid var(--line);
}
html[data-theme="dark"] .assist-wa { color: #66bb6a; background: rgba(102, 187, 106, 0.1); }
.assist-wa:hover { opacity: .9; }
@media (max-width: 640px) {
  #assist-fab { bottom: 14px; left: 14px; width: 48px; height: 48px; font-size: 20px; }
  #assist-panel[hidden] { display: none !important; }
  #assist-panel { bottom: 74px; left: 10px; right: 10px; width: auto; }
}

/* محول التواريخ */
.dates-head { text-align: center; margin: 10px 0 18px; }
.dates-head h1 { margin: 0 0 6px; }
.dates-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; max-width: 860px; margin: 0 auto; }
.date-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.date-card h2 { margin: 0 0 12px; font-size: 16px; text-align: center; }
.date-row { display: flex; gap: 8px; flex-direction: column; }
.date-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.date-row select, .date-row input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; background: var(--surface-2); color: var(--ink); }
.date-row select option { background: var(--surface); color: var(--ink); }
.dates-swap { display: flex; align-items: center; }
.dates-swap .btn { font-size: 18px; border-radius: 50%; width: 44px; height: 44px; padding: 0; }
.dates-result { max-width: 860px; margin: 14px auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 15.5px; font-weight: 700; }
@media (max-width: 760px) { .dates-grid { grid-template-columns: 1fr; } .dates-swap { justify-content: center; } .dates-swap .btn { transform: rotate(90deg); } }
