/* بنك الأسئلة الثقافية v5 — أداة تدقيق + تصدير (متجاوبة) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

/* معاينة الداشبورد (?embed=1) — إخفاء تسجيل الخروج داخل الإطار */
html[data-embed="1"] #signOutBtn { display: none !important; }

:root {
  --bg: #f0f4f3;
  --bg-card: #ffffff;
  --primary: #0d7377;
  --primary-dark: #095456;
  --accent: #ffb400;
  --accent-dark: #e6a200;
  --text: #1a1a1a;
  --text-muted: #555;
  --border: #e0e6e5;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --shadow-hover: 0 4px 20px rgba(0,0,0,.12);
  --font: "Tajawal", "Cairo", "Segoe UI", Arial, sans-serif;
  --easy: #2e7d32;
  --medium: #1565c0;
  --hard: #ef6c00;
  --extreme: #c62828;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

#appScreen { width: 100%; max-width: 100%; }

button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== الهيدر ========== */
.top-bar {
  background: var(--primary);
  color: #fff;
  padding: 0.9rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.title-block h1 { font-size: 1.45rem; font-weight: 700; margin-bottom: 0.1rem; font-family: "Blabeloo", system-ui, sans-serif; }
.tagline { font-size: 0.85rem; opacity: .9; }
.top-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  transition: transform .15s, box-shadow .15s;
  min-height: 40px;
}
.btn:active { transform: scale(.98); }
.btn-accent { background: var(--accent); color: #1a1a1a; }
.btn-accent:hover { background: var(--accent-dark); color: #fff; }
.btn-outline { background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.6); }
.btn-outline:hover { border-color: #fff; background: rgba(255,255,255,.1); }
.top-bar .btn-sign-out { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.5); }
.top-bar .btn-sign-out:hover { background: rgba(255,255,255,.25); border-color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }

/* ========== شريط الأدوات اللاصق ========== */
.stickybar {
  position: sticky;
  top: 0;
  z-index: 120;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  padding: 0.5rem 1rem 0.45rem;
}
.stickybar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.search-input {
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-width: 220px;
  font-size: 0.9rem;
}
.search-input:focus { border-color: var(--primary); background: #fff; }
.toolbar-info { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }
.toolbar-check { font-size: 0.85rem; display: flex; align-items: center; gap: 0.35rem; cursor: pointer; white-space: nowrap; }
.per-page select { padding: 0.4rem 0.5rem; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; }

.viewtoggle { display: inline-flex; border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden; }
.vbtn { background: #fff; color: var(--text-muted); font-size: 1.05rem; padding: 0.3rem 0.7rem; min-height: 38px; }
.vbtn.on { background: var(--primary); color: #fff; }

/* حبوب الفلاتر النشطة */
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pills:empty { display: none; }
.pill {
  --cc: var(--primary);
  display: inline-flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--cc) 12%, #fff);
  border: 1.5px solid var(--cc);
  color: #223;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem; font-weight: 700;
}
.pill b { color: var(--cc); font-size: 0.9rem; line-height: 1; }
.pill:hover { background: color-mix(in srgb, var(--cc) 22%, #fff); }

/* ========== التخطيط ========== */
.layout {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr;
  min-height: calc(100vh - 140px);
  align-items: stretch;
}
@media (min-width: 768px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
}

/* ========== الشريط الجانبي ========== */
.sidebar {
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  padding: 1rem;
}
.sheet-head { display: none; }
@media (min-width: 768px) {
  .sidebar { min-height: calc(100vh - 140px); }
}

.stats-box h2, .filter-section h3 {
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
  font-weight: 700;
}
.stats-box p { font-size: 0.875rem; margin-bottom: 0.2rem; color: var(--text-muted); }
.stats-qna strong { color: #4527a0; }

.diff-bars { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 4px; }
.diff-bar {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  border: 2px solid transparent;
  cursor: pointer;
  font-weight: 700;
}
.diff-bar.easy { background: var(--easy); }
.diff-bar.medium { background: var(--medium); }
.diff-bar.hard { background: var(--hard); }
.diff-bar.extreme { background: var(--extreme); }
.diff-bar.on { border-color: #1a1a1a; box-shadow: 0 0 0 2px #fff inset; }

.filter-section { margin-top: 1.15rem; }
.filter-hint { font-size: 0.75rem; color: #64748b; margin: 0 0 0.5rem; line-height: 1.35; }

.cat-search {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
}
.cat-search:focus { border-color: var(--primary); background: #fff; outline: none; }

/* شرائح التصنيفات */
.chips-scroll { max-height: 260px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 6px; padding: 2px; }
.chip {
  --cc: var(--primary);
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
  font-size: 0.8rem; font-weight: 700; color: var(--text);
  transition: border-color .12s, background .12s, transform .08s;
  min-height: 34px;
}
.chip:active { transform: scale(.97); }
.chip img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.chip .chip-n { font-size: 0.68rem; color: var(--text-muted); font-weight: 600; }
.chip:hover { border-color: var(--cc); }
.chip.on {
  border-color: var(--cc);
  background: color-mix(in srgb, var(--cc) 14%, #fff);
  box-shadow: 0 0 0 1px var(--cc) inset;
}
.chip.on .chip-n { color: var(--cc); }
.chips-scroll.letters .chip { min-width: 40px; justify-content: center; font-size: 0.95rem; }

/* أزرار مقسمة (صعوبة/نوع/معلقة) */
.seg-group { display: flex; flex-wrap: wrap; gap: 5px; }
.seg {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem; font-weight: 700; color: var(--text-muted);
  min-height: 34px;
}
.seg:hover { border-color: var(--primary); color: var(--primary); }
.seg.on { background: var(--primary); border-color: var(--primary); color: #fff; }

#resetFiltersBtn { width: 100%; margin-top: 1.1rem; padding: 0.6rem; }

/* ========== المحتوى ========== */
.main { padding: 1rem; min-width: 0; width: 100%; max-width: 100%; overflow-x: hidden; }

.loading, .error { text-align: center; padding: 1.2rem; font-size: 1.02rem; }
.error { color: var(--extreme); }

.questions-grid { display: grid; gap: 1rem; }
.questions-grid.cards { grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .questions-grid.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}
.questions-grid.list { gap: 8px; }

/* ========== سكيليتون التحميل ========== */
.skel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid; gap: 10px;
}
.skel-line, .skel-box {
  background: linear-gradient(90deg, #ecf1f0 25%, #f7faf9 50%, #ecf1f0 75%);
  background-size: 200% 100%;
  animation: skel 1.2s infinite;
  border-radius: 6px;
  height: 14px;
}
.skel-line.w40 { width: 40%; } .skel-line.w60 { width: 60%; }
.skel-line.w70 { width: 70%; } .skel-line.w90 { width: 90%; }
.skel-box { height: 120px; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel-line, .skel-box { animation: none; } }

/* ========== كرت السؤال ========== */
.question-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-top: 4px solid var(--cc, var(--primary));
  transition: box-shadow .2s;
}
.question-card:hover { box-shadow: var(--shadow-hover); }
.question-card.is-sus { outline: 2px dashed var(--extreme); outline-offset: -2px; opacity: .92; }

.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 0.7rem; }
.badge { font-size: 0.74rem; padding: 0.18rem 0.5rem; border-radius: 6px; font-weight: 700; }
.badge.sm { font-size: 0.68rem; padding: 0.12rem 0.42rem; white-space: nowrap; }
.badge.cat { background: #e3f2fd; color: var(--medium); }
.badge.easy { background: #e8f5e9; color: var(--easy); }
.badge.medium { background: #e3f2fd; color: var(--medium); }
.badge.hard { background: #fff3e0; color: var(--hard); }
.badge.extreme { background: #ffebee; color: var(--extreme); }
.badge.tf { background: #f3e5f5; color: #6a1b9a; }
.badge.mcq { background: #e0f2f1; color: #00695c; }
.badge.qna { background: #ede7f6; color: #4527a0; }
.badge.letter { background: #f1f5f9; color: var(--primary); border-radius: 999px; }
.badge.suspended { background: #ffebee; color: var(--extreme); border: 1px solid #f3b8b8; border-radius: 999px; }

/* أزرار الأدمن السريعة */
.admin-btns { display: inline-flex; align-items: center; gap: 4px; }
.mini-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 30px; min-height: 30px;
  font-size: 0.8rem; font-weight: 800; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }

.card-q { font-size: 1rem; font-weight: 700; margin-bottom: 0.7rem; line-height: 1.55; }
.card-options { list-style: none; }
.card-options li {
  padding: 0.42rem 0.55rem;
  margin-bottom: 0.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1.5px solid transparent;
}
/* الإجابة الصحيحة: حد أخضر + ✓ (لا اعتماداً على اللون وحده) */
.card-options li.correct {
  background: #e8f5e9;
  color: var(--easy);
  border-color: var(--easy);
  font-weight: 700;
}
.card-options li.correct::after { content: " ✓"; font-weight: 900; }
.card-source { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; }

/* صورة السؤال المصوّر — النقر يكبّر */
.card-img { margin: 2px 0 10px; display: flex; justify-content: center; }
.card-img img {
  max-width: 100%; max-height: 210px; object-fit: contain;
  border: 2px solid #2c3e50; border-radius: 12px; background: #fff;
  box-shadow: 2px 2px 0 rgba(44,62,80,.25);
  cursor: zoom-in;
}

/* ========== وضع القائمة المضغوطة ========== */
.qrow {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-right: 4px solid var(--cc, var(--primary));
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.qrow.is-sus { outline: 2px dashed var(--extreme); outline-offset: -2px; }
.qrow-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qrow-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cc, var(--primary)); flex: none; }
.qrow-q {
  flex: 1 1 260px;
  font-size: 0.92rem; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.qrow.open .qrow-q { white-space: normal; }
.qrow-cam { font-size: 0.85rem; }
.qrow-detail { display: none; margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 10px; }
.qrow.open .qrow-detail { display: block; }
.qrow-img { margin: 4px 0 10px; display: flex; justify-content: center; }
.qrow-img img {
  max-width: 100%; max-height: 240px; object-fit: contain;
  border: 2px solid #2c3e50; border-radius: 12px; background: #fff; cursor: zoom-in;
}

/* ========== لايتبوكس الصور ========== */
#imgLB {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(10, 20, 25, .88);
  display: none;
  align-items: center; justify-content: center;
  padding: 3vh 3vw;
}
#imgLB.open { display: flex; }
#imgLB img {
  max-width: 94vw; max-height: 92vh; object-fit: contain;
  border-radius: 12px; background: #fff; padding: 6px;
}
#imgLBx {
  position: absolute; top: 12px; right: 14px;
  width: 42px; height: 42px; border-radius: 50%;
  background: #fff; color: #1a1a1a; font-size: 1.5rem; font-weight: 700;
}

/* ========== الترقيم ========== */
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin-top: 1.5rem; padding: 1rem 0; }
.pagination button {
  padding: 0.4rem 0.8rem; border-radius: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); font-size: 0.9rem; min-height: 38px;
}
.pagination button:hover { background: var(--bg); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ========== المودالات ========== */
.modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 520px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute; top: 0.5rem; left: 0.5rem;
  width: 38px; height: 38px; font-size: 1.5rem; line-height: 1;
  background: var(--bg); border-radius: 50%; color: var(--text-muted);
}
.modal-close:hover { color: var(--text); background: var(--border); }

/* مودال التصدير */
.export-content { max-width: 560px; }
.export-title { color: var(--primary); font-size: 1.2rem; margin-bottom: 4px; }
.export-info { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 14px; }
.export-grid { display: grid; gap: 12px; }
.exp-field { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 700; color: var(--text); }
.exp-field input[type="text"], .exp-field select, .exp-field input[type="number"] {
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  width: 100%;
  background: #fff;
}
.exp-field input:focus, .exp-field select:focus { border-color: var(--primary); outline: none; }
.exp-inline { display: flex; gap: 8px; }
.exp-inline select { flex: 1; }
.exp-inline input { width: 110px; }
.exp-checks { display: grid; gap: 7px; font-size: 0.87rem; padding-top: 2px; }
.exp-checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.export-prog { margin-top: 10px; font-size: 0.85rem; color: var(--primary); font-weight: 700; }
/* التحديد المخصص داخل مودال التصدير */
.exp-custom { border: 1.5px dashed var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 12px; background: #fafcfb; }
.exp-sub { display: grid; gap: 6px; font-size: 0.85rem; font-weight: 700; }
.exp-sub small { color: var(--text-muted); font-weight: 500; }
.exp-chiprow { display: flex; flex-wrap: wrap; gap: 6px; }
.exp-chiprow.exp-cats { max-height: 150px; overflow-y: auto; }
.xchip {
  background: #fff; border: 1.5px solid var(--border); border-radius: 999px;
  padding: 4px 11px; font-size: 0.8rem; font-weight: 700; color: var(--text-muted);
  min-height: 32px;
}
.xchip small { font-weight: 600; color: var(--text-muted); }
.xchip:hover { border-color: var(--primary); color: var(--primary); }
.xchip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.xchip.on small { color: #d8efee; }
.exp-checkline { display: flex; align-items: center; gap: 8px; font-size: 0.87rem; cursor: pointer; }
.exp-diffcounts {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  border: 1.5px dashed var(--border); border-radius: 12px; padding: 10px 12px; background: #fafcfb;
}
.exp-diffcounts label { display: grid; gap: 4px; font-size: 0.78rem; font-weight: 700; }
.exp-diffcounts input { width: 74px; padding: 0.4rem 0.5rem; border: 1.5px solid var(--border); border-radius: 8px; }
.exp-sum { font-size: 0.82rem; font-weight: 800; color: var(--primary); margin-inline-start: auto; }
.export-run { width: 100%; margin-top: 14px; font-size: 1rem; padding: 0.7rem; }

/* توست صغير */
.mini-toast {
  position: fixed; bottom: 18px; right: 50%; transform: translateX(50%);
  background: #111827; color: #f9fafb;
  padding: 9px 18px; border-radius: 999px;
  font-size: 0.86rem; font-weight: 700;
  z-index: 500; opacity: 0; pointer-events: none;
  transition: opacity .3s;
  direction: rtl;
}
.mini-toast.show { opacity: 1; }

/* ========== زر الفلاتر العائم + الشيت (جوال) ========== */
.filters-fab {
  display: none;
  position: fixed; bottom: 16px; inset-inline-start: 16px;
  z-index: 250;
  background: var(--primary); color: #fff;
  border-radius: 999px; padding: 0.7rem 1.2rem;
  font-size: 0.95rem; font-weight: 800;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.sheet-backdrop { display: none; }

@media (max-width: 767px) {
  .filters-fab { display: block; }
  .sidebar {
    position: fixed; inset-inline: 0; bottom: 0; top: auto;
    max-height: 82vh; overflow-y: auto;
    z-index: 320;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    transition: transform .25s ease;
    box-shadow: 0 -8px 30px rgba(0,0,0,.25);
  }
  body.filters-open .sidebar { transform: translateY(0); }
  .sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 310; }
  body.filters-open .sheet-backdrop { display: block; }
  .sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 1rem; color: var(--primary);
    padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 10px;
  }
  .sheet-x { background: var(--bg); border-radius: 50%; width: 34px; height: 34px; font-size: 1.2rem; }
  .top-bar { flex-direction: column; align-items: stretch; text-align: center; }
  .top-actions { justify-content: center; }
  .search-input { min-width: 0; flex: 1 1 100%; }
  .stickybar-row { gap: 0.45rem; }
}

/* ========== أيباد ========== */
@media (min-width: 1024px) { .main { padding: 1.5rem; } }

/* ========== شاشة الدخول والحساب الموقوف ========== */
.auth-screen { min-height: 60vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 2rem; max-width: 400px; width: 100%;
  display: flex; flex-direction: column; gap: 1rem;
}
.auth-title { font-size: 1.5rem; color: var(--primary); margin-bottom: 0; }
.auth-subtitle { color: var(--text-muted); font-size: 0.95rem; margin: 0; }
.auth-error { color: #c62828; font-size: 0.9rem; padding: 0.5rem; background: rgba(198,40,40,.08); border-radius: 8px; }
.auth-input { width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; }
.auth-input:focus { outline: none; border-color: var(--primary); }
.auth-buttons { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }
.auth-card .btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.auth-card .btn-outline:hover { background: rgba(13,115,119,.08); border-color: var(--primary-dark); }
.auth-card--blocked .auth-title { color: #c62828; }
.auth-card--blocked .auth-subtitle { margin-bottom: 0.5rem; }
.auth-card--blocked .btn-outline { color: var(--text); border-color: var(--border); }
.auth-card--blocked .btn-outline:hover { background: var(--bg); border-color: var(--text-muted); }

/* ========== علامة وناااسة والفوتر ========== */
@font-face {
  font-family: "Blabeloo";
  src: url("Blabeloo-font-v.1.0.ttf") format("truetype");
  font-display: swap;
}
.brand-mark {
  font-family: "Blabeloo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.03em;
  color: #f9d82e !important;
}
.brand-link { color: inherit; text-decoration: none; font-weight: 700; }
.brand-link:hover { text-decoration: underline; }

.credit-footer {
  text-align: center; padding: 14px 12px;
  font-size: 12px; color: var(--text-muted); opacity: 0.85;
  display: flex; flex-direction: column; gap: 4px;
}
.credit-footer .credit-by { font-weight: 600; }
