/* ============================================
   نظام التقارير — تصميم بنفسجي v3
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;900&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; font-family: "Tajawal", sans-serif; }
html { scroll-behavior: smooth; }

body {
  background: linear-gradient(to bottom, #12002f, #1a003f);
  background-attachment: fixed;
  color: white;
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
  position: relative;
}

/* ============ خلفية متحركة ============ */
.animated-background {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  overflow: hidden; z-index: 0; pointer-events: none;
}
.planet {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #a855f7, #12002f);
  opacity: 0.12; animation: floatPlanet 60s linear infinite alternate;
}
.planet1 { width: 80px; height: 80px; top: 10%; left: 20%; animation-delay: 0s; }
.planet2 { width: 150px; height: 150px; top: 70%; left: 75%; animation-delay: 15s; }
.planet3 { width: 60px; height: 60px; top: 50%; left: 8%; animation-delay: 8s; }
.planet4 { width: 120px; height: 120px; top: 25%; left: 82%; animation-delay: 25s; }
.planet5 { width: 90px; height: 90px; top: 85%; left: 30%; animation-delay: 10s; }
@keyframes floatPlanet {
  0%   { transform: translateY(0) scale(1); opacity: 0.06; }
  50%  { transform: translateY(-30px) scale(1.05); opacity: 0.16; }
  100% { transform: translateY(0) scale(1); opacity: 0.09; }
}
.blue-star {
  position: absolute; width: 4px; height: 4px;
  background: radial-gradient(circle, #c084fc, #3b0764);
  border-radius: 50%; opacity: 0.4;
  animation: blinkStar 4s infinite ease-in-out;
}
.star1 { top: 12%; left: 12%; animation-delay: 0s; }
.star2 { top: 22%; left: 78%; animation-delay: 1s; }
.star3 { top: 55%; left: 62%; animation-delay: 2s; }
.star4 { top: 72%; left: 32%; animation-delay: 3s; }
.star5 { top: 42%; left: 18%; animation-delay: 4s; }
.star6 { top: 15%; left: 55%; animation-delay: 2.5s; }
.star7 { top: 88%; left: 68%; animation-delay: 1.5s; }
.star8 { top: 35%; left: 45%; animation-delay: 3.5s; }
@keyframes blinkStar {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50%      { opacity: 0.8; transform: scale(1.5); }
}

/* ============ الهيدر ============ */
.page-header {
  text-align: center;
  padding: 60px 20px 20px;
  position: relative; z-index: 2;
  animation: fadeInDown 0.8s ease;
}
.page-header h1 {
  font-size: 42px; font-weight: 900; margin-bottom: 12px;
  color: white; text-shadow: 0 0 20px rgba(168, 85, 247, 0.6);
}
.page-header p { font-size: 17px; color: #dcdcdc; max-width: 700px; margin: 0 auto; line-height: 1.7; }
.page-header h1 .accent {
  background: linear-gradient(135deg, #a855f7, #c084fc);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.site-intro {
  max-width: 800px; margin: 20px auto; padding: 14px 24px;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 12px; font-size: 15px; color: #dcdcdc; text-align: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  position: relative; z-index: 2;
}

/* ============ الصفحة الرئيسية ============ */
.home-container {
  max-width: 1300px; margin: 0 auto; padding: 20px 20px 40px;
  position: relative; z-index: 2;
}

.home-grid {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 18px; margin-top: 25px;
}
.home-grid.secondary-grid { margin-top: 10px; }

.section-separator {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin: 30px auto; color: #a855f7; max-width: 700px;
}
.section-separator::before, .section-separator::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 85, 247, 0.5), transparent);
}
.section-separator span {
  font-size: 13px; font-weight: 700; letter-spacing: 3px;
  padding: 6px 16px; border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 20px; background: rgba(168, 85, 247, 0.08);
}

.dept-card {
  width: 170px; flex: 0 0 auto;
  background: linear-gradient(145deg, #1e0939, #2a0052);
  border-radius: 18px; overflow: hidden;
  text-decoration: none; color: white;
  transition: transform 0.4s ease, box-shadow 0.4s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.15);
  display: flex; flex-direction: column;
  animation: cardFadeIn 0.6s ease both; opacity: 0;
}
.dept-card:nth-child(1) { animation-delay: 0.05s; }
.dept-card:nth-child(2) { animation-delay: 0.1s; }
.dept-card:nth-child(3) { animation-delay: 0.15s; }
.dept-card:nth-child(4) { animation-delay: 0.2s; }
.dept-card:nth-child(5) { animation-delay: 0.25s; }
.dept-card:nth-child(6) { animation-delay: 0.3s; }
.dept-card:nth-child(7) { animation-delay: 0.35s; }

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dept-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 40px rgba(168, 85, 247, 0.4);
  border-color: #a855f7;
}

.dept-card .card-image {
  width: 100%; aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #2a0052, #1e0939);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.dept-card .card-image img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.dept-card:hover .card-image img { transform: scale(1.08); }
.dept-card .card-image .placeholder {
  color: rgba(168, 85, 247, 0.6); font-size: 13px; text-align: center;
  padding: 15px; font-weight: 700; line-height: 1.4;
}

.dept-card .card-btn {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white; padding: 14px 10px; text-align: center;
  font-size: 14px; font-weight: 900; letter-spacing: 0.01em;
  transition: background 0.3s ease;
  line-height: 1.4;
}
.dept-card:hover .card-btn {
  background: linear-gradient(135deg, #9333ea, #7e22ce);
}

/* ============ صفحة التقرير ============ */
.report-container {
  max-width: 1200px; margin: 0 auto; padding: 20px;
  position: relative; z-index: 2;
}

.back-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(168, 85, 247, 0.1); color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
  padding: 10px 20px; border-radius: 50px; cursor: pointer;
  margin-bottom: 20px; text-decoration: none; font-size: 14px; font-weight: 700;
  backdrop-filter: blur(10px); transition: all 0.3s ease;
}
.back-btn:hover {
  background: #a855f7; color: white; transform: translateX(6px);
  box-shadow: 0 6px 18px rgba(168, 85, 247, 0.4);
}

.report-wrap {
  max-width: 1200px; margin: 20px auto; padding: 40px;
  background: linear-gradient(145deg, rgba(30, 9, 57, 0.7), rgba(42, 0, 82, 0.6));
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 24px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  animation: fadeInUp 0.6s ease;
}
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

.report-wrap h1 {
  text-align: center; margin: 0 0 24px;
  font-size: 2rem; font-weight: 900;
  background: linear-gradient(135deg, #fff 0%, #c084fc 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(168, 85, 247, 0.3);
}

.report-logo {
  display: block; margin: 0 auto 28px; max-width: 130px; height: auto;
  filter: drop-shadow(0 8px 24px rgba(168, 85, 247, 0.5));
}

.bar {
  background: rgba(168, 85, 247, 0.05);
  border: 1px solid rgba(168, 85, 247, 0.15);
  padding: 18px 20px; margin-bottom: 18px; border-radius: 14px;
  transition: border-color 0.3s ease;
}

.row {
  display: flex; gap: 10px; align-items: center;
  margin: 8px 0; flex-wrap: wrap;
}
.label { min-width: 120px; font-weight: 700; color: #c084fc; font-size: 14px; }

/* حقول عامة */
input[type="text"], select, textarea {
  padding: 8px 12px;
  border: 1px solid rgba(168, 85, 247, 0.25);
  background: rgba(12, 0, 30, 0.6); color: white;
  border-radius: 8px; font-family: inherit; font-size: 14px;
  transition: all 0.25s ease; outline: none;
}
select { min-width: 70px; }
input:focus, select:focus, textarea:focus {
  border-color: #a855f7;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.25);
}
textarea { resize: vertical; min-height: 100px; line-height: 1.7; width: 100%; }

/* مجموعة الوقت */
.time-group {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0, 0, 0, 0.2); padding: 4px 8px;
  border-radius: 8px; border: 1px solid rgba(168, 85, 247, 0.2);
}
.time-group select { min-width: 60px; padding: 6px 8px; border: none; background: transparent; }
.time-group select:focus { box-shadow: none; }
.time-colon { color: #a855f7; font-weight: 900; }

/* ============ Buttons ============ */
.btn {
  border: 0; border-radius: 10px; padding: 10px 18px;
  cursor: pointer; font-weight: 900; font-family: inherit; font-size: 14px;
  transition: all 0.3s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.ghost {
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: #c084fc;
}
.btn.ghost:hover {
  background: rgba(168, 85, 247, 0.2); border-color: #a855f7; color: white;
  transform: translateY(-1px);
}
.btn.main {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white; box-shadow: 0 6px 18px rgba(168, 85, 247, 0.4);
}
.btn.main:hover {
  background: linear-gradient(135deg, #9333ea, #7e22ce);
  box-shadow: 0 8px 24px rgba(168, 85, 247, 0.6);
  transform: translateY(-2px) scale(1.03);
}

.actions {
  display: flex; gap: 12px; justify-content: center;
  margin: 16px 0; flex-wrap: wrap;
}

.success {
  text-align: center; margin-top: 12px; color: #4ade80;
  font-weight: 900; display: none; padding: 10px 16px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 10px; animation: fadeInUp 0.3s ease;
}
.success.show { display: block; }

.divider { margin: 24px 0; border: 0; border-top: 1px dashed rgba(168, 85, 247, 0.25); }

.site-footer {
  text-align: center; padding: 30px 16px; margin-top: 40px;
  color: #a094b8; font-size: 13px; font-weight: 500;
  border-top: 1px solid rgba(168, 85, 247, 0.15);
  background: rgba(12, 0, 30, 0.5); position: relative; z-index: 2;
}

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white; border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 14px 28px; border-radius: 12px; z-index: 9999;
  opacity: 0; transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-weight: 700; box-shadow: 0 12px 30px rgba(168, 85, 247, 0.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#scrollTopBtn {
  position: fixed; bottom: 30px; left: 30px;
  width: 50px; height: 50px;
  background: linear-gradient(135deg, #9333ea, #a855f7);
  color: white; border: none; border-radius: 50%;
  font-size: 22px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(168, 85, 247, 0.5);
  transition: transform 0.3s ease; z-index: 999;
}
#scrollTopBtn:hover { transform: scale(1.15) rotate(-8deg); }
#scrollTopBtn.show { display: flex; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #12002f; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #a855f7, #7e22ce);
  border-radius: 8px; border: 2px solid #12002f;
}

/* ============================================
   قوالب النموذج (Template)
   ============================================ */
.tmpl-form {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 4px;
}

.tmpl-spacer { height: 8px; }

.tmpl-sep {
  text-align: center; color: #a855f7; opacity: 0.5;
  font-size: 14px; letter-spacing: 2px; padding: 6px 0;
}

.tmpl-header {
  color: #c084fc; font-weight: 900; font-size: 16px;
  margin-top: 12px; padding: 10px 14px;
  background: rgba(168, 85, 247, 0.08);
  border-right: 3px solid #a855f7;
  border-radius: 6px;
}

.tmpl-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px;
  transition: background 0.15s;
}
.tmpl-row:hover { background: rgba(168, 85, 247, 0.04); }

.tmpl-label {
  min-width: 150px; color: #e2e8f0; font-weight: 700; font-size: 14px;
}
.tmpl-label.full { min-width: 100%; margin-bottom: 6px; }

.tmpl-pipe {
  color: #a855f7; font-weight: 900; font-size: 16px;
  padding: 0 2px;
}

.tmpl-input {
  padding: 7px 10px; font-size: 13px;
  background: rgba(12, 0, 30, 0.5);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 6px; color: white; font-family: inherit;
}
.tmpl-input:focus {
  border-color: #a855f7; outline: none;
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

/* أحجام مختلفة للحقول */
.tmpl-code { width: 110px; text-align: center; font-family: "Cairo", monospace; flex: 0 0 auto; }
.tmpl-name { width: 160px; flex: 0 0 auto; }
.tmpl-mention {
  flex: 1; min-width: 150px;
  font-family: monospace; font-size: 12px;
  color: #a094b8;
}
.tmpl-mention:focus { color: white; }

.tmpl-notes { width: 100%; min-height: 80px; resize: vertical; }

/* ============ Toggle Sections ============ */
.tmpl-toggle {
  margin: 12px 0;
  padding: 12px 14px;
  background: rgba(168, 85, 247, 0.04);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 12px;
  transition: all 0.25s ease;
}
.tmpl-toggle:hover { border-color: rgba(168, 85, 247, 0.35); }

.toggle-header {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; padding: 6px 4px;
  font-weight: 900; color: #c084fc; font-size: 15px;
  user-select: none;
}

.toggle-cb {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px;
  border: 2px solid rgba(168, 85, 247, 0.4);
  border-radius: 6px;
  background: rgba(12, 0, 30, 0.6);
  cursor: pointer; position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.toggle-cb:hover { border-color: #a855f7; }
.toggle-cb:checked {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  border-color: #a855f7;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.5);
}
.toggle-cb:checked::after {
  content: "✓"; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -55%);
  color: white; font-size: 16px; font-weight: 900;
}

.toggle-content {
  max-height: 0; overflow: hidden; opacity: 0;
  transition: max-height 0.4s ease, opacity 0.3s ease, margin-top 0.3s ease;
  margin-top: 0;
}
.toggle-cb:checked ~ .toggle-content,
.tmpl-toggle:has(.toggle-cb:checked) .toggle-content {
  max-height: 3000px; opacity: 1; margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed rgba(168, 85, 247, 0.2);
}

.toggle-extra {
  background: rgba(168, 85, 247, 0.06);
  border: 1px dashed rgba(168, 85, 247, 0.3) !important;
}

/* ============ Lists (add multiple items) ============ */
.tmpl-list {
  padding: 10px 14px; margin: 6px 0;
  background: rgba(168, 85, 247, 0.03);
  border: 1px solid rgba(168, 85, 247, 0.15);
  border-radius: 10px;
}
.tmpl-list-items {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 8px;
}
.tmpl-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.15);
  border-radius: 8px;
  animation: fadeInUp 0.25s ease;
  flex-wrap: wrap;
}
.tmpl-list-item input {
  padding: 6px 10px; font-size: 13px;
  background: rgba(12, 0, 30, 0.5);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 6px; color: white; font-family: inherit;
}
.tmpl-list-item input:focus { border-color: #a855f7; outline: none; }
.tmpl-list-item .li-name { width: 140px; }
.tmpl-list-item .li-code { width: 110px; text-align: center; font-family: monospace; }
.tmpl-list-item .li-mention { flex: 1; min-width: 140px; font-family: monospace; font-size: 12px; color: #a094b8; }
.tmpl-list-item .li-mention:focus { color: white; }
.tmpl-list-item .li-del {
  padding: 6px 10px; font-size: 14px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #f87171; border-radius: 6px;
  cursor: pointer; transition: all 0.2s;
  margin-right: auto;
}
.tmpl-list-item .li-del:hover { background: #f87171; color: white; }

.tmpl-add { align-self: flex-start; }

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .dept-card { width: 155px; }
}
@media (max-width: 900px) {
  .dept-card { width: 140px; }
  .dept-card .card-btn { font-size: 12px; padding: 12px 8px; }
}
@media (max-width: 640px) {
  .report-wrap { padding: 20px 14px; margin: 12px 8px; border-radius: 16px; }
  .report-wrap h1 { font-size: 1.4rem; }
  .page-header h1 { font-size: 26px; }
  .page-header p { font-size: 14px; }
  .tmpl-label { min-width: 100%; font-size: 13px; }
  .tmpl-row { flex-wrap: wrap; }
  .tmpl-code, .tmpl-name { width: 100%; }
  .tmpl-mention { width: 100%; min-width: 0; }
  .tmpl-list-item .li-name, .tmpl-list-item .li-code, .tmpl-list-item .li-mention {
    width: 100%; min-width: 0;
  }
  .dept-card { width: 140px; }
  .btn { padding: 10px 14px; font-size: 13px; }
  input[type="text"], select, textarea { font-size: 16px; }
  #scrollTopBtn { bottom: 20px; left: 20px; width: 44px; height: 44px; }
}

/* ============================================
   v4 — Tabs + Field Add Buttons + Dropdowns
   ============================================ */

/* ==== ألوان الخيارات في القوائم المنسدلة ==== */
select option {
  color: #000 !important;
  background: #fff;
  font-weight: 500;
}

.time-select {
  color: white;
  cursor: pointer;
}

/* ==== زر + بجانب كل حقل ==== */
.field-add-btn {
  width: 28px; height: 28px;
  min-width: 28px;
  border: 1px solid rgba(168, 85, 247, 0.4);
  background: rgba(168, 85, 247, 0.1);
  color: #c084fc;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px; font-weight: 900;
  display: inline-flex;
  align-items: center; justify-content: center;
  transition: all 0.2s ease;
  font-family: inherit;
  padding: 0;
  line-height: 1;
  margin-right: auto;
  flex-shrink: 0;
}
.field-add-btn:hover {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white; border-color: #a855f7;
  transform: scale(1.15) rotate(90deg);
  box-shadow: 0 4px 12px rgba(168, 85, 247, 0.5);
}

.field-del-btn {
  width: 28px; height: 28px;
  min-width: 28px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px; font-weight: 900;
  display: inline-flex;
  align-items: center; justify-content: center;
  transition: all 0.2s ease;
  font-family: inherit;
  padding: 0;
  margin-right: auto;
  flex-shrink: 0;
}
.field-del-btn:hover {
  background: #f87171; color: white;
  transform: scale(1.15);
}

/* ==== صف مستنسخ (extra) ==== */
.tmpl-row-extra {
  background: rgba(168, 85, 247, 0.06);
  border: 1px dashed rgba(168, 85, 247, 0.3);
  border-radius: 8px;
  margin: 4px 0 4px 20px !important;
  padding: 6px 10px !important;
  animation: fadeInUp 0.25s ease;
}

.tmpl-label-input {
  min-width: 140px;
  padding: 6px 10px;
  font-size: 13px;
  background: rgba(12, 0, 30, 0.5);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 6px;
  color: white;
  font-family: inherit;
  font-weight: 700;
}
.tmpl-label-input:focus {
  border-color: #a855f7; outline: none;
  box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

/* ==== Tabs الرئيسية ==== */
.main-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  max-width: 700px;
  margin: 20px auto 10px;
  padding: 8px;
  background: rgba(168, 85, 247, 0.05);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 60px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  z-index: 2;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.main-tab {
  flex: 1;
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 900;
  font-family: inherit;
  border: none;
  background: transparent;
  color: #c084fc;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.02em;
}

.main-tab:hover {
  background: rgba(168, 85, 247, 0.1);
  color: white;
}

.main-tab.active {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white;
  box-shadow: 0 6px 18px rgba(168, 85, 247, 0.45);
  transform: translateY(-1px);
}

.tab-panel {
  display: none;
  animation: fadeInUp 0.4s ease;
}
.tab-panel.active {
  display: block;
}

/* Mobile */
@media (max-width: 640px) {
  .main-tabs {
    flex-direction: column;
    max-width: calc(100% - 20px);
    margin: 15px auto;
    padding: 6px;
    border-radius: 20px;
    gap: 6px;
  }
  .main-tab {
    padding: 12px 20px;
    font-size: 14px;
  }
  .field-add-btn, .field-del-btn { width: 32px; height: 32px; }
  .tmpl-row-extra { margin: 4px 0 !important; }
  .tmpl-label-input { width: 100%; min-width: 0; }
}

/* ============================================
   نظام النماذج (Templates) — v2 Inline
   ============================================ */
.tpl-intro {
  text-align: center;
  color: #dcdcdc;
  font-size: 14px;
  margin-bottom: 24px;
  padding: 12px 20px;
  background: rgba(168, 85, 247, 0.06);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 12px;
}

.tpl-category { margin-bottom: 30px; }

.tpl-cat-title {
  color: #c084fc;
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 14px;
  padding: 12px 18px;
  background: linear-gradient(90deg, rgba(168, 85, 247, 0.15), transparent);
  border-right: 4px solid #a855f7;
  border-radius: 8px;
}

.tpl-cat-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tpl-card {
  background: rgba(30, 9, 57, 0.5);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.tpl-card:hover { border-color: rgba(168, 85, 247, 0.4); }
.tpl-card.open {
  border-color: #a855f7;
  box-shadow: 0 8px 24px rgba(168, 85, 247, 0.25);
}

.tpl-card-header {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}
.tpl-card-header:hover { background: rgba(168, 85, 247, 0.08); }

.tpl-title { color: white; font-weight: 900; font-size: 15px; }

.tpl-arrow {
  color: #c084fc;
  font-size: 14px;
  transition: transform 0.3s ease;
}
.tpl-card.open .tpl-arrow { transform: rotate(180deg); }

.tpl-card-body {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
  padding: 0 20px;
}
.tpl-card.open .tpl-card-body {
  max-height: 5000px;
  opacity: 1;
  padding: 20px;
  border-top: 1px dashed rgba(168, 85, 247, 0.2);
}

/* ==== محتوى النموذج كمستند مع inputs مضمّنة ==== */
.tpl-inline-content {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(168, 85, 247, 0.15);
  border-radius: 12px;
  padding: 24px 26px;
  color: #e2e8f0;
  font-family: "Tajawal", sans-serif;
  font-size: 14.5px;
  line-height: 2.2;
  white-space: pre-wrap;
  word-wrap: break-word;
  direction: rtl;
  text-align: right;
  margin-bottom: 16px;
}

.tpl-inline-input {
  display: inline-block;
  min-width: 120px;
  max-width: 100%;
  padding: 3px 10px;
  margin: 0 2px;
  background: rgba(168, 85, 247, 0.12);
  border: 1px dashed rgba(168, 85, 247, 0.5);
  border-radius: 5px;
  color: #ffffff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  vertical-align: baseline;
  transition: all 0.2s ease;
  outline: none;
  box-sizing: border-box;
}
.tpl-inline-input::placeholder {
  color: #a094b8;
  font-weight: 500;
  opacity: 0.8;
}
.tpl-inline-input:hover {
  background: rgba(168, 85, 247, 0.18);
  border-color: rgba(168, 85, 247, 0.7);
}
.tpl-inline-input:focus {
  background: rgba(168, 85, 247, 0.22);
  border-color: #a855f7;
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}

.tpl-inline-textarea {
  min-width: 260px;
  min-height: 34px;
  vertical-align: middle;
  resize: vertical;
  line-height: 1.6;
  padding: 5px 10px;
}

/* ==== checkbox الرقابة ==== */
.tpl-monitor-row {
  margin: 12px 0;
  padding: 12px 14px;
  background: rgba(251, 191, 119, 0.06);
  border: 1px solid rgba(251, 191, 119, 0.25);
  border-radius: 10px;
}
.tpl-checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: #fbbf77;
  font-weight: 700;
  font-size: 14px;
  user-select: none;
}
.tpl-monitor-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border: 2px solid rgba(251, 191, 119, 0.5);
  border-radius: 5px;
  background: rgba(12, 0, 30, 0.6);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}
.tpl-monitor-cb:checked {
  background: #fbbf77;
  border-color: #fbbf77;
}
.tpl-monitor-cb:checked::after {
  content: "✓";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%);
  color: #12002f;
  font-size: 14px;
  font-weight: 900;
}

.tpl-actions {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

@media (max-width: 640px) {
  .tpl-inline-content { padding: 16px 14px; font-size: 13px; line-height: 2; }
  .tpl-inline-input { min-width: 90px; font-size: 12.5px; }
  .tpl-inline-textarea { min-width: 100%; }
}

/* ============ بحث النماذج ============ */
.tpl-search-wrap {
  margin: 0 0 20px;
  position: relative;
}

.tpl-search {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  background: rgba(168, 85, 247, 0.08);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 12px;
  color: white;
  font-family: inherit;
  font-weight: 700;
  outline: none;
  transition: all 0.2s ease;
}

.tpl-search::placeholder {
  color: #a094b8;
  font-weight: 500;
}

.tpl-search:focus {
  border-color: #a855f7;
  background: rgba(168, 85, 247, 0.12);
  box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.15);
}

.tpl-search-info {
  display: none;
  margin-top: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: #c084fc;
  font-weight: 700;
  text-align: center;
  background: rgba(168, 85, 247, 0.08);
  border-radius: 8px;
}
