/* ==========================================================================
   موقع تنسيق - الأنماط الرسمية المتجاوبة 100% لجميع الأجهزة
   ========================================================================== */

:root {
  --primary-color: #1a365d;
  --primary-hover: #0f2942;
  --secondary-color: #2b6cb0;
  --secondary-hover: #2c5282;
  --accent-gold: #c5a059;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --text-dark: #2d3748;
  --text-muted: #718096;
  --border-color: #e2e8f0;
  --border-focus: #3182ce;
  --badge-success-bg: #c6f6d5;
  --badge-success-text: #22543d;
  --badge-warning-bg: #feebc8;
  --badge-warning-text: #744210;
  --badge-danger-bg: #fed7d7;
  --badge-danger-text: #742a2a;
  --font-main: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-title: 'Amiri', 'Cairo', serif;
}

/* --------------------------------------------------------------------------
   Reset عام + منع التمرير الأفقي نهائياً
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-dark);
  direction: rtl;
  text-align: right;
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  width: 100%;
}

/* --------------------------------------------------------------------------
   [إصلاح 1] الهيكل الخارجي — يعمل على كل الأجهزة
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
}

/* الأعمدة الجانبية للإعلانات — تظهر على اللابتوب فقط */
.ad-sidebar {
  width: 170px;
  min-width: 170px;
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.ad-slot-sidebar {
  width: 160px;
  min-height: 600px;
  background-color: #ffffff;
  border: 1px dashed #cbd5e0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  font-size: 13px;
  text-align: center;
  position: sticky;
  top: 20px;
}

/* المحتوى الرئيسي */
.main-wrapper {
  flex: 1 1 auto;
  min-width: 0; /* مهم جداً في Flexbox لمنع التجاوز */
  max-width: 900px;
  background: var(--card-bg);
  min-height: 100vh;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.content-inner {
  padding: 24px 32px;
  flex: 1;
  width: 100%;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   الهيدر واللوجو الرسمي
   -------------------------------------------------------------------------- */
.header-official {
  border-bottom: 2px solid #edf2f7;
  padding-bottom: 16px;
  margin-bottom: 20px;
  text-align: center;
}

/* [إصلاح 5] الهيدر — يتكيف تلقائياً على الموبايل */
.header-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.official-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  padding: 2px;
  background: #ffffff;
  flex-shrink: 0;
}

.brand-titles {
  text-align: right;
}

.site-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary-color);
  line-height: 1.1;
}

.site-subtitle {
  font-size: 0.93rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

/* --------------------------------------------------------------------------
   تبويبات النظام الدراسي
   -------------------------------------------------------------------------- */
.system-tabs-container {
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
}

.system-tabs {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 11px 22px;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--border-color);
  background-color: #f7fafc;
  color: var(--text-dark);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  touch-action: manipulation;
}

.tab-btn.active {
  background-color: var(--primary-color);
  color: #ffffff;
  border-color: var(--primary-color);
}

.tab-btn.disabled {
  opacity: 0.6;
  background-color: #edf2f7;
  color: #a0aec0;
  cursor: not-allowed;
  border-color: #cbd5e0;
}

.badge-soon {
  background-color: #e2e8f0;
  color: #4a5568;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.tab-guide-text {
  font-size: 0.85rem;
  color: #4a5568;
  text-align: center;
  background: #f7fafc;
  padding: 8px 12px;
  border-radius: 6px;
  display: block;
  width: 100%;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   تنبيه دفعات 2026 وروابط المشاركة المباشرة (WhatsApp, Telegram, Messenger)
   -------------------------------------------------------------------------- */
.notice-2026-box {
  background-color: #ebf8ff;
  border: 1px solid #bee3f8;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  width: 100%;
}

.notice-2026-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.93rem;
  color: #2c5282;
  line-height: 1.5;
  margin-bottom: 12px;
}

.notice-2026-header i {
  color: #2b6cb0;
  font-size: 1.2rem;
  margin-top: 2px;
}

.share-buttons-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 150px;
}

.share-wa {
  background-color: #25d366;
  color: #ffffff;
}

.share-wa:hover {
  background-color: #1ebd56;
}

.share-tg {
  background-color: #0088cc;
  color: #ffffff;
}

.share-tg:hover {
  background-color: #0077b3;
}

.share-fb {
  background-color: #0084ff;
  color: #ffffff;
}

.share-fb:hover {
  background-color: #0073e6;
}

/* --------------------------------------------------------------------------
   [إصلاح 2] نموذج البحث — عمود واحد على الموبايل دائماً
   -------------------------------------------------------------------------- */
.search-card {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
  width: 100%;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

@media (min-width: 768px) {
  .form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 12px;
  }

  .form-group {
    gap: 4px;
    min-width: 0;
    overflow: hidden;
  }

  .form-label {
    font-size: 0.88rem;
    white-space: normal;
    word-break: keep-all;
    line-height: 1.3;
  }

  .form-select,
  .form-input {
    font-size: 0.9rem;
    padding: 8px 10px;
    min-height: 42px;
  }

  .form-select {
    padding-left: 26px;
    background-position: left 8px center;
  }

  .field-explain-text {
    font-size: 0.76rem;
    line-height: 1.25;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.form-label {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: normal;
  line-height: 1.3;
}

.form-select,
.form-input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-main);
  font-size: 16px; /* يمنع تكبير iOS تلقائياً */
  border: 2px solid #cbd5e0;
  border-radius: 8px;
  background-color: #ffffff;
  color: var(--text-dark);
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
  -webkit-appearance: none;
  appearance: none;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%23718096' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}

.form-select:focus,
.form-input:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15);
}

.field-explain-text {
  font-size: 0.82rem;
  color: #718096;
  line-height: 1.3;
  margin-top: 2px;
}

/* تنبيه مضمّن بدلاً من alert() */
.inline-notice-card {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid #bee3f8;
  background-color: #ebf8ff;
  color: #2c5282;
  margin-bottom: 16px;
  line-height: 1.5;
  transition: all 0.3s ease;
}

.btn-container-with-explain {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn-submit {
  width: 100%;
  padding: 16px;
  font-family: var(--font-main);
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  background-color: var(--secondary-color);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  min-height: 52px;
  touch-action: manipulation;
}

.btn-submit:hover { background-color: var(--secondary-hover); }
.btn-submit:active { transform: translateY(1px); }

.btn-explain-box {
  background-color: #ebf8ff;
  border: 1px solid #bee3f8;
  color: #2c5282;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   منطقة النتائج وشارات القبول
   -------------------------------------------------------------------------- */
.results-section {
  display: none;
  margin-top: 10px;
  width: 100%;
}

.results-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-color);
}

.results-summary {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-color);
  flex: 1;
  min-width: 200px;
  line-height: 1.5;
}

.table-search-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 300px;
}

.table-filter-input {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-main);
  font-size: 16px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  min-height: 44px;
  outline: none;
}

.table-filter-input:focus {
  border-color: var(--secondary-color);
}

.badges-guide-box {
  background-color: #f7fafc;
  border: 1px solid #e2e8f0;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  width: 100%;
}

.badges-guide-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 8px;
}

.badges-list {
  font-size: 0.85rem;
  color: #4a5568;
  line-height: 2;
}

/* --------------------------------------------------------------------------
   [إصلاح 3] الجدول المتجاوب — سحب بالأصابع
   -------------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: #ffffff;
  margin-bottom: 8px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  text-align: right;
  min-width: 420px; /* حد أدنى يتناسب مع 4 أعمدة فقط على الموبايل */
}

.results-table th {
  background-color: var(--primary-color);
  color: #ffffff;
  padding: 11px 12px;
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 2px solid var(--primary-hover);
}

.results-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.results-table tbody tr:nth-child(even) { background-color: #f7fafc; }
.results-table tbody tr:hover { background-color: #edf2f7; }

/* شارات فرصة القبول */
.badge-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-excellent { background-color: var(--badge-success-bg); color: var(--badge-success-text); }
.badge-probable  { background-color: var(--badge-warning-bg); color: var(--badge-warning-text); }
.badge-hard      { background-color: var(--badge-danger-bg);  color: var(--badge-danger-text); }

/* [إصلاح 6] رسالة السحب تحت الجدول */
.scroll-hint {
  display: none;
  text-align: center;
  font-size: 0.82rem;
  color: #a0aec0;
  padding: 6px 0 10px;
  gap: 6px;
}

.disclaimer-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  background-color: #fffaf0;
  border: 1px solid #feebc8;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   أزرار التصدير
   -------------------------------------------------------------------------- */
.export-section-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary-color);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
  width: 100%;
}

.export-btn-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: 8px;
  width: 100%;
}

.btn-export {
  width: 100%;
  padding: 14px 20px;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
  min-height: 48px;
  touch-action: manipulation;
}

.btn-export-pdf { background-color: #1a365d; color: #ffffff; }
.btn-export-pdf:hover { background-color: #0f2942; }
.btn-export-img { background-color: #2b6cb0; color: #ffffff; }
.btn-export-img:hover { background-color: #2c5282; }

.export-explain-text {
  font-size: 0.83rem;
  color: #4a5568;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   مساحات الإعلان
   -------------------------------------------------------------------------- */
.ad-container-mobile {
  width: 100%;
  margin: 20px 0;
  display: flex;
  justify-content: center;
}

.ad-slot-mobile {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
  background-color: #ffffff;
  border: 1px dashed #cbd5e0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a0aec0;
  font-size: 13px;
  padding: 10px;
}

/* --------------------------------------------------------------------------
   الفوتر وعداد الزوار
   -------------------------------------------------------------------------- */
.footer-official {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding: 20px 32px;
  background-color: #f7fafc;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
  width: 100%;
}

.visitor-counter-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: #ffffff;
  border: 1px solid #cbd5e0;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  color: var(--primary-color);
}

.counter-num {
  font-family: monospace, var(--font-main);
  font-size: 1.05rem;
  color: #2b6cb0;
}

/* --------------------------------------------------------------------------
   قالب تصدير الصور (مخفي خارج الشاشة)
   -------------------------------------------------------------------------- */
#exportCardTemplate {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1200px;
  background-color: #ffffff;
  padding: 40px;
  box-sizing: border-box;
  font-family: 'Cairo', sans-serif;
  direction: rtl;
  color: #2d3748;
}

.export-header-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid #1a365d;
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.export-title-block {
  display: flex;
  align-items: center;
  gap: 20px;
}

.export-logo-img { width: 80px; height: 80px; object-fit: contain; }
.export-card-title { font-size: 32px; font-weight: 700; color: #1a365d; }
.export-card-sub { font-size: 18px; color: #718096; }

.export-info-pills { display: flex; gap: 16px; margin-bottom: 24px; }
.export-pill { background-color: #edf2f7; border: 1px solid #cbd5e0; padding: 10px 20px; border-radius: 8px; font-size: 20px; font-weight: 700; color: #1a365d; }

.export-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.export-table th { background-color: #1a365d; color: #ffffff; padding: 12px; font-size: 18px; text-align: right; }
.export-table td { padding: 12px; border-bottom: 1px solid #e2e8f0; font-size: 18px; }

.export-footer-card { border-top: 2px solid #e2e8f0; padding-top: 16px; display: flex; justify-content: space-between; align-items: center; font-size: 18px; color: #718096; }
.export-site-link { font-weight: 700; color: #2b6cb0; }

/* ==========================================================================
   [إصلاح 1] التجاوب الكامل — Media Queries
   ========================================================================== */

/* --- التابلت وما دون (< 1024px): إخفاء الإعلانات الجانبية تماماً --- */
@media (max-width: 1023px) {
  .ad-sidebar {
    display: none !important;
  }

  .main-wrapper {
    max-width: 100%;
    width: 100%;
    border: none;
    box-shadow: none;
  }

  .content-inner {
    padding: 20px 20px;
  }

  .footer-official {
    padding: 16px 20px;
  }
}

/* --- الهاتف الكبير (< 768px): نموذج بعمود واحد --- */
@media (max-width: 768px) {
  .content-inner {
    padding: 16px 14px;
  }

  /* [إصلاح 2] إجبار النموذج على عمود واحد */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .results-header {
    flex-direction: column;
    gap: 12px;
  }

  .table-search-box {
    max-width: 100%;
    width: 100%;
  }

  .export-actions {
    grid-template-columns: 1fr;
  }

  .footer-official {
    flex-direction: column;
    text-align: center;
    padding: 14px;
    gap: 10px;
  }

  /* إظهار رسالة السحب تحت الجدول */
  .scroll-hint {
    display: block;
  }

  /* [إصلاح 3] إخفاء الأعمدة غير الضرورية لتوفير مساحة */
  .col-hide-mobile {
    display: none !important;
  }

  .results-table {
    min-width: 320px; /* يكفي لـ 4 أعمدة فقط */
  }

  .results-summary {
    font-size: 0.98rem;
    min-width: unset;
  }
}

/* --- الهاتف الصغير (< 480px): ضبط الهيدر والخطوط --- */
@media (max-width: 480px) {
  .content-inner {
    padding: 12px 10px;
  }

  /* [إصلاح 5] الهيدر عمودي على الشاشات الصغيرة */
  .header-brand {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  .brand-titles {
    text-align: center;
  }

  .site-title {
    font-size: 1.75rem;
  }

  .site-subtitle {
    font-size: 0.85rem;
  }

  .official-logo {
    width: 64px;
    height: 64px;
  }

  .system-tabs {
    flex-direction: column;
    width: 100%;
  }

  .tab-btn {
    width: 100%;
    justify-content: center;
    font-size: 0.95rem;
    padding: 10px 14px;
  }

  .btn-submit {
    font-size: 1rem;
    padding: 14px;
  }

  .search-card {
    padding: 14px 10px;
  }

  .results-table th,
  .results-table td {
    padding: 9px 8px;
    font-size: 0.88rem;
  }

  .badge-status {
    padding: 3px 7px;
    font-size: 0.78rem;
  }

  .export-btn-card {
    padding: 12px 10px;
  }

  .btn-explain-box {
    font-size: 0.8rem;
  }
}

/* --- الهاتف الصغير جداً (< 360px) --- */
@media (max-width: 360px) {
  .site-title { font-size: 1.5rem; }
  .official-logo { width: 56px; height: 56px; }
  .content-inner { padding: 10px 8px; }
  .form-label { font-size: 0.92rem; }
  .btn-submit { font-size: 0.95rem; }
}

/* --------------------------------------------------------------------------
   تنسيقات الطباعة
   -------------------------------------------------------------------------- */
@media print {
  .ad-sidebar,
  .ad-container-mobile,
  .system-tabs-container,
  .search-card,
  .export-actions,
  .table-search-box,
  .field-explain-text,
  .btn-explain-box,
  .inline-notice-card,
  .scroll-hint,
  .badges-guide-box { display: none !important; }

  body, .main-wrapper, .content-inner {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  .results-section { display: block !important; }
  .col-hide-mobile { display: table-cell !important; }

  .results-table th {
    background-color: #1a365d !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
