/**
 * منصّة يلا عربي — النمط العام (RTL بالكامل)
 * نظام تصميم عصري: ألوان متدرجة، حركة ناعمة، وواجهة متجاوبة بالكامل.
 */

:root {
  --c-primary: var(--sky-600, #0284c7);
  --c-primary-light: var(--sky-500, #0ea5e9);
  --c-primary-50: var(--sky-50, #f0f9ff);
  --c-accent: var(--mango-500, #f97316);
  --c-accent-dark: var(--mango-600, #ea580c);
  --c-success: #16a34a;
  --c-success-bg: #dcfce7;
  --c-danger: #dc2626;
  --c-danger-bg: #fee2e2;
  --c-warn-bg: #fef9c3;
  --c-warn-text: #854d0e;

  --c-text: #111827;
  --c-text-muted: #6b7280;
  --c-text-faint: #9ca3af;
  --c-border: #e5e7eb;
  --c-surface: #ffffff;
  --c-bg: #faf8f5;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);

  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { direction: rtl; scroll-behavior: smooth; }

body {
  font-family: var(--font-arabic);
  background: var(--c-bg);
  background-image: radial-gradient(circle at 100% 0%, rgba(14, 165, 233, .06), transparent 45%),
    radial-gradient(circle at 0% 100%, rgba(249, 115, 22, .05), transparent 45%);
  background-attachment: fixed;
  color: var(--c-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

::selection { background: var(--c-primary-light); color: #fff; }

/* ───────── الهيكل العام ───────── */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 28px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.top-bar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 19px;
  color: var(--c-primary);
  white-space: nowrap;
}

.top-bar .brand img { height: 32px; }

.nav-tabs {
  display: flex;
  gap: 4px;
  background: #f1f0ed;
  padding: 4px;
  border-radius: 999px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tabs button {
  border: none;
  background: transparent;
  padding: 9px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--c-text-muted);
  white-space: nowrap;
  transition: color .2s var(--ease), background .2s var(--ease);
}

.nav-tabs button:hover { color: var(--c-text); }

.nav-tabs button.active {
  background: var(--c-surface);
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--c-text-muted);
  white-space: nowrap;
}

/* ───────── الأزرار ───────── */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), opacity .15s var(--ease), background .15s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-dark));
  color: #fff;
  box-shadow: 0 2px 10px rgba(249, 115, 22, .28);
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(249, 115, 22, .38); }

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
}
.btn-secondary:hover { background: #e2e8f0; }

.btn-danger { background: var(--c-danger-bg); color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ───────── التخطيط والبطاقات ───────── */

main {
  flex: 1;
  padding: 28px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  animation: fadeUp .35s var(--ease);
}

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

.section-title {
  font-size: 21px;
  font-weight: 800;
  margin-bottom: 16px;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}

.card:hover { box-shadow: var(--shadow-md); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

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

label { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; color: #374151; }

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14.5px;
  margin-bottom: 14px;
  background: #fff;
  color: var(--c-text);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary-light);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

textarea { resize: vertical; min-height: 80px; }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'><path d='M1 1l6 6 6-6' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-inline-start: 36px;
}

/* ───────── شريط مساعدة الذكاء الاصطناعي ───────── */

.ai-assist-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px dashed var(--c-primary-light);
  border-radius: var(--radius-sm);
  background: var(--c-primary-50);
}
.ai-assist-bar input,
.ai-assist-bar textarea { margin-bottom: 0; background: #fff; }
.ai-assist-bar input { flex: 1 1 220px; }
.ai-assist-bar textarea { flex: 1 1 100%; min-height: 56px; }
.ai-assist-bar .btn { white-space: nowrap; }

/* ───────── قوائم اختيار (طلاب/دروس) ───────── */

.check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 11px 14px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease);
  font-weight: 500;
  font-size: 14.5px;
  color: var(--c-text);
}

.check-row:hover { border-color: #cbd5e1; background: #f8fafc; }

.check-row input {
  width: 19px;
  height: 19px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--c-primary);
  cursor: pointer;
}

.check-row span { flex: 1; }

.check-row:has(input:checked) {
  border-color: var(--c-primary-light);
  background: var(--c-primary-50);
}

/* ───────── شارات وحالات ───────── */

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
}

.badge.draft { background: var(--c-warn-bg); color: var(--c-warn-text); }
.badge.published { background: var(--c-success-bg); color: #166534; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--c-text-faint);
  font-size: 14.5px;
}
.empty-state::before {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 2px dashed var(--c-border);
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary-light);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 28px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── محتوى تفاعلي / دروس ───────── */

.lesson-block {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 12px;
  background: #fcfbfa;
  transition: border-color .2s var(--ease);
}
.lesson-block:focus-within, .lesson-block:hover { border-color: #ddd6cc; }

.lesson-block h4 { margin-bottom: 8px; font-size: 16px; }
.lesson-block .meta-list { font-size: 14px; line-height: 1.9; color: #333; }

.ib-builder .ib-block, .ib-player .ib-player-block { background: #fff; }
.ib-type-fields { margin-top: 10px; }
.ib-row-item input, .ib-row-item select { margin-bottom: 0; }
.ans-order-item { cursor: grab; transition: box-shadow .15s var(--ease), border-color .15s var(--ease); }
.ans-order-item:active { cursor: grabbing; }
.ans-order-item.dragging { opacity: .5; }
.ans-order-item.drag-over { border-color: var(--c-primary-light) !important; box-shadow: 0 0 0 2px rgba(14, 165, 233, .2); }
.ans-order-up, .ans-order-down { padding: 4px 10px; font-size: 13px; }

/* ───────── المحادثة ───────── */

.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
@media (max-width: 760px) { .chat-layout { grid-template-columns: 1fr; } }

.thread-list { border: 1px solid var(--c-border); border-radius: var(--radius-md); overflow: hidden; background: var(--c-surface); box-shadow: var(--shadow-sm); }
.thread-item { padding: 13px 16px; border-bottom: 1px solid #f1f1f1; cursor: pointer; transition: background .15s var(--ease); }
.thread-item:hover { background: var(--c-primary-50); }
.thread-item.active { background: var(--c-primary-50); border-inline-start: 3px solid var(--c-primary); }

.message-panel { border: 1px solid var(--c-border); border-radius: var(--radius-md); background: var(--c-surface); display: flex; flex-direction: column; height: 480px; box-shadow: var(--shadow-sm); }
.message-list { flex: 1; overflow-y: auto; padding: 16px; }
.message-bubble { max-width: 70%; padding: 9px 15px; border-radius: 16px; margin-bottom: 10px; font-size: 14px; animation: fadeUp .2s var(--ease); }
.message-bubble.mine { background: linear-gradient(135deg, var(--c-primary-light), var(--c-primary)); color: #fff; margin-inline-start: auto; border-bottom-left-radius: 4px; }
.message-bubble.theirs { background: #f1f5f9; color: #333; margin-inline-end: auto; border-bottom-right-radius: 4px; }
.message-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--c-border); }
.message-form input { margin-bottom: 0; }

/* ───────── الإشعارات (Toasts) ───────── */

.toast-container {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px) scale(.97);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast-in { opacity: 1; transform: translateY(0) scale(1); }
.toast-out { opacity: 0; transform: translateY(6px) scale(.98); }

.toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ───────── الاستجابة على الجوال ───────── */

@media (max-width: 640px) {
  .top-bar { flex-wrap: wrap; padding: 10px 16px; }
  .nav-tabs { order: 3; width: 100%; }
  main { padding: 16px; }
  .toast-container { inset-inline-end: 12px; inset-inline-start: 12px; max-width: none; }
}
