/* ====================================
   F39A1 — تصميم احترافي عربي RTL
   ==================================== */

:root {
  --bg: #f5f8fc;
  --bg-soft: #eaf0f7;
  --surface: #ffffff;
  --surface-alt: #f9fbfd;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --primary: #1e40af;
  --primary-600: #1d4ed8;
  --primary-700: #1e3a8a;
  --primary-soft: #e0e7ff;
  --teal: #0d9488;
  --teal-soft: #ccfbf1;

  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-bg: #fee2e2;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;

  --transition: all 0.2s ease;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* مهم: نضمن أن خاصية hidden تتفوق على display:grid في .modal و .app */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tajawal', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
}

h1,
h2,
h3 {
  font-family: 'Readex Pro', 'Tajawal', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

h1 {
  font-size: 24px;
}
h2 {
  font-size: 20px;
}
h3 {
  font-size: 17px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 15px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: var(--transition);
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12);
}

label {
  display: block;
  margin-bottom: 12px;
}

label span {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.muted {
  color: var(--text-muted);
  font-size: 14px;
  margin: 4px 0 0;
}

code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

/* ===== أزرار ===== */
.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(30, 64, 175, 0.3);
}
.btn-primary.big {
  padding: 14px 30px;
  font-size: 16px;
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

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

.btn-link {
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-link:hover {
  color: var(--primary);
  background: var(--bg-soft);
}
.btn-link.danger:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text-muted);
  transition: var(--transition);
}
.btn-icon:hover {
  background: var(--primary-soft);
  color: var(--primary);
}
.btn-icon.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ===== شاشة الدخول ===== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 0% 0%, rgba(13, 148, 136, 0.08), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(30, 64, 175, 0.1), transparent 50%),
    var(--bg);
}

.login-card {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary) 0%, var(--teal) 100%);
  color: white;
  font-family: 'Readex Pro', sans-serif;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 18px;
  letter-spacing: 1px;
  margin-bottom: 18px;
  box-shadow: 0 6px 18px rgba(30, 64, 175, 0.2);
}
.brand-mark.sm {
  padding: 6px 12px;
  font-size: 14px;
  margin-bottom: 0;
}

.login-brand h1 {
  font-size: 22px;
  margin-bottom: 6px;
}
.login-brand p {
  color: var(--text-muted);
  margin: 0;
  font-size: 14px;
}

.login-form .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 14px;
  text-align: center;
}

.login-hint {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== التطبيق الرئيسي ===== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand-text h2 {
  font-size: 15px;
  margin: 0;
}
.brand-text small {
  color: var(--text-muted);
  font-size: 12px;
}

.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  text-align: right;
  transition: var(--transition);
  position: relative;
}
.nav-item:hover {
  background: var(--bg-soft);
}
.nav-item.active {
  background: linear-gradient(135deg, var(--primary-soft) 0%, var(--teal-soft) 100%);
  color: var(--primary-700);
  font-weight: 600;
}
.nav-item .nav-ico {
  font-size: 18px;
}

.nav-badge {
  margin-right: auto;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}
.nav-badge.pulse {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(220, 38, 38, 0);
  }
}

.sidebar-user {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.user-info {
  padding: 8px 10px;
}
.user-info .name {
  font-weight: 600;
  font-size: 14px;
}
.user-info .username {
  color: var(--text-muted);
  font-size: 12px;
}
.user-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.user-actions .btn-link {
  flex: 1;
  text-align: center;
}

.role-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 6px;
  font-weight: 700;
}
.role-badge.admin {
  background: linear-gradient(135deg, var(--teal) 0%, var(--primary) 100%);
  color: white;
}
.role-badge.user {
  background: var(--bg-soft);
  color: var(--text-muted);
}

/* ===== العرض ===== */
.main {
  padding: 28px 32px;
  overflow-x: hidden;
}

.view {
  display: none;
  animation: fadeIn 0.3s ease;
}
.view.active {
  display: block;
}

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

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}

/* ===== Banner المتأخرين ===== */
.overdue-banner {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  border: 1.5px solid var(--danger);
  color: #7f1d1d;
  padding: 14px 18px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  font-weight: 600;
  animation: pulse-soft 2s ease-in-out infinite;
}
.overdue-banner .banner-ico {
  font-size: 22px;
}
@keyframes pulse-soft {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(220, 38, 38, 0);
  }
}

/* ===== بطاقات الدورات ===== */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.course-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.course-card:hover {
  box-shadow: var(--shadow);
}
.course-card.overdue {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.08);
}

.course-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.course-identity .name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-family: 'Readex Pro', sans-serif;
}
.course-identity .name .rank-prefix {
  color: var(--teal);
  font-weight: 500;
  margin-left: 6px;
}
.course-identity .course-name {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 2px;
}

.overdue-tag {
  background: var(--danger);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.course-meta {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}
.course-meta div strong {
  color: var(--text);
  font-weight: 600;
  margin-right: 4px;
}

.user-stamp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-soft);
  color: var(--primary-700);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}
.user-stamp.teal {
  background: var(--teal-soft);
  color: #0f766e;
}

/* ===== Stepper المراحل ===== */
.stepper {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.step {
  flex: 1;
  min-width: 110px;
  background: var(--surface-alt);
  padding: 10px;
  border-radius: var(--radius-sm);
  position: relative;
  text-align: center;
  font-size: 12px;
  border: 1.5px solid transparent;
}
.step.done {
  background: var(--teal-soft);
  color: #0f766e;
}
.step.current {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: white;
  border-color: var(--primary-700);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.2);
}
.step .step-num {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  line-height: 22px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 4px;
}
.step.done .step-num {
  background: white;
  color: var(--teal);
}
.step.current .step-num {
  background: white;
  color: var(--primary);
}
.step .step-label {
  display: block;
  font-weight: 500;
  line-height: 1.3;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal) 0%, var(--primary) 100%);
  transition: width 0.4s ease;
}

.course-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* قسم حفظ الشهادة (يظهر بعد المرحلة 6) */
.cert-section {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #fef9c3 0%, #fffbeb 100%);
  border: 1.5px dashed #d97706;
}
.cert-section.locked {
  background: var(--surface-alt);
  border-color: var(--border);
  opacity: 0.85;
}
.cert-section .cert-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cert-section.locked .cert-title {
  color: var(--text-muted);
}
.cert-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 880px) {
  .cert-actions {
    grid-template-columns: 1fr;
  }
}
.cert-toggle {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  text-align: right;
  transition: var(--transition);
}
.cert-toggle:hover {
  border-color: var(--primary);
}
.cert-toggle.done {
  background: linear-gradient(135deg, #d1fae5 0%, #ecfdf5 100%);
  border-color: var(--success);
}
.cert-toggle .ct-label {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cert-toggle.done .ct-label {
  color: #065f46;
}
.cert-toggle .ct-by {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.cert-toggle.done .ct-by {
  color: #047857;
  font-weight: 500;
}
.cert-toggle .ct-check {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  position: relative;
}
.cert-toggle.done .ct-check {
  background: var(--success);
  border-color: var(--success);
}
.cert-toggle.done .ct-check::after {
  content: '✓';
  color: white;
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 12px;
}

/* شارات معلومات إضافية في البطاقة */
.info-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  margin-left: 4px;
}
.info-chip.code {
  background: var(--primary-soft);
  color: var(--primary-700);
  font-weight: 700;
  letter-spacing: 0.5px;
}
.info-chip.squad {
  background: var(--teal-soft);
  color: #0f766e;
}

.history-toggle {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}
.history-toggle:hover {
  color: var(--primary);
}

.history-list {
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.history-list.open {
  display: block;
}
.history-list ol {
  margin: 0;
  padding-right: 16px;
}
.history-list li {
  margin-bottom: 4px;
  color: var(--text-muted);
}
.history-list li strong {
  color: var(--text);
}

/* ===== جداول البيانات ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  text-align: right;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.data-table thead th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0;
  white-space: nowrap;
}
.data-table tbody tr:hover {
  background: var(--surface-alt);
}
.data-table tbody tr:last-child td {
  border-bottom: none;
}

.rank-order-pill {
  display: inline-block;
  width: 26px;
  height: 26px;
  line-height: 26px;
  text-align: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--teal) 100%);
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

/* ===== جدول التدريب ===== */
.training-table {
  table-layout: fixed;
}
.training-table th,
.training-table td {
  text-align: center;
  padding: 8px;
  min-width: 130px;
}
.training-cell {
  position: relative;
}
.training-cell textarea {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  font-size: 13px;
  padding: 8px;
  background: var(--surface-alt);
  border: 1.5px solid transparent;
}
.training-cell textarea:focus {
  background: var(--surface);
}
.training-cell .updated-by {
  font-size: 10px;
  color: var(--text-soft);
  margin-top: 4px;
  display: block;
}

/* ===== الرسائل (دردشة) ===== */
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 480px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.load-older {
  align-self: center;
  margin-bottom: 12px;
  font-size: 13px;
  padding: 6px 14px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface-alt);
  align-self: flex-start;
  border: 1px solid var(--border);
  word-wrap: break-word;
}
.msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: white;
  border-color: transparent;
}
.msg .msg-head {
  font-size: 12px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.9;
}
.msg.mine .msg-head {
  opacity: 0.85;
}
.msg .msg-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
}
.msg .msg-name {
  font-weight: 700;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
.chat-form input {
  flex: 1;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  animation: pop 0.22s ease;
}
@keyframes pop {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  font-size: 26px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--text-muted);
}
.modal-close:hover {
  background: var(--bg-soft);
}
.modal-body {
  padding: 22px;
}
.modal-body .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* تنبيه الأحد */
.modal-mandatory .modal-backdrop {
  background: rgba(127, 29, 29, 0.7);
}
.sunday-card {
  text-align: center;
  padding: 36px 28px;
  border: 3px solid var(--warning);
}
.sunday-icon {
  font-size: 56px;
  margin-bottom: 10px;
}
.sunday-card h2 {
  color: var(--warning);
  margin-bottom: 10px;
}
.sunday-card p {
  color: var(--text);
  margin-bottom: 24px;
  font-size: 15px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: var(--text);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  font-size: 14px;
  animation: slideUp 0.25s ease;
}
.toast.error {
  background: var(--danger);
}
.toast.success {
  background: var(--success);
}
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== الطباعة ===== */
.print-only {
  display: none;
}

@media print {
  .sidebar,
  .view-header,
  .nav,
  .modal,
  .toast,
  #overdueBanner {
    display: none !important;
  }
  .app {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 0;
  }
  .print-only {
    display: block;
    text-align: center;
    margin-bottom: 18px;
  }
  .training-cell textarea {
    border: 1px solid #ccc;
    background: white;
    color: black;
  }
  .updated-by {
    display: none !important;
  }
}

/* =====================================================
   بطاقة تأكيد رفع البرنامج التدريبي
   ===================================================== */
.post-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  margin-bottom: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.post-card.is-sunday-pending {
  border-color: var(--danger);
  background: linear-gradient(180deg, #fee2e2 0%, var(--surface) 100%);
  box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.08);
}
.post-card.is-posted {
  border-color: var(--success);
  background: linear-gradient(180deg, #d1fae5 0%, var(--surface) 100%);
  box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.08);
}
.post-card-head {
  margin-bottom: 14px;
}
.post-day {
  font-family: 'Readex Pro', sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: var(--text);
}
.post-card.is-sunday-pending .post-day {
  color: var(--danger);
}
.post-card.is-posted .post-day {
  color: var(--success);
}
.post-hijri {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}
.post-status {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  margin: 18px 0;
  line-height: 1.7;
}
.post-status.warn {
  background: linear-gradient(135deg, #fee2e2 0%, #fef2f2 100%);
  color: #7f1d1d;
  border: 1.5px dashed var(--danger);
}
.post-status.ok {
  background: linear-gradient(135deg, #d1fae5 0%, #ecfdf5 100%);
  color: #065f46;
  border: 1.5px solid var(--success);
}
.post-status.neutral {
  background: var(--surface-alt);
  color: var(--text-muted);
}
.post-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 18px 24px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 17px;
  color: white;
  transition: var(--transition);
  font-family: 'Readex Pro', sans-serif;
}
.post-btn:hover {
  transform: translateY(-2px);
}
.post-btn.red {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 8px 22px rgba(220, 38, 38, 0.4);
  animation: pulse-soft 1.6s ease-in-out infinite;
}
.post-btn.green {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  box-shadow: 0 8px 22px rgba(22, 163, 74, 0.35);
}
.post-byline {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
}
.post-byline strong {
  color: var(--success);
}
.post-byline .undo-link {
  display: inline-block;
  margin-right: 12px;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.post-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.post-log h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
}
.post-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.post-log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 13px;
  gap: 8px;
}
.post-log-item .pli-week {
  font-weight: 700;
  color: var(--primary);
  font-family: monospace;
  font-size: 13px;
}
.post-log-item .pli-by {
  color: var(--text);
}
.post-log-item .pli-by strong {
  color: var(--text);
}
.post-log-item .pli-at {
  color: var(--text-muted);
  font-size: 12px;
}

@media (max-width: 880px) {
  .post-card {
    padding: 20px 16px;
  }
  .post-day {
    font-size: 22px;
  }
  .post-btn {
    padding: 16px;
    font-size: 15px;
  }
  .post-log-item {
    flex-wrap: wrap;
  }
}

/* =====================================================
   بطاقة الإجراء — طباعة البرنامج الأسبوعي (مستخدمة سابقاً)
   ===================================================== */
.print-action-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.print-action-card.is-sunday {
  border: 2.5px solid var(--danger);
  background: linear-gradient(135deg, #fee2e2 0%, var(--surface) 60%);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.1);
}
.pa-info {
  flex: 1;
  min-width: 0;
}
.pa-day {
  font-weight: 700;
  font-size: 18px;
  font-family: 'Readex Pro', sans-serif;
  margin-bottom: 4px;
}
.pa-hint {
  color: var(--text-muted);
  font-size: 13px;
}
.print-action-card.is-sunday .pa-day {
  color: var(--danger);
}
.print-action-card.is-sunday .pa-hint {
  color: #7f1d1d;
  font-weight: 500;
}
.pa-btn {
  padding: 14px 26px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  color: white;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}
.pa-btn:hover {
  transform: translateY(-1px);
}
.pa-btn.green {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  box-shadow: 0 6px 18px rgba(22, 163, 74, 0.3);
}
.pa-btn.green:hover {
  box-shadow: 0 8px 22px rgba(22, 163, 74, 0.4);
}
.pa-btn.red {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.45);
  animation: pulse-soft 1.8s ease-in-out infinite;
}
.pa-btn.red:hover {
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.55);
}

/* =====================================================
   قسم: نظرة عامة (Overview)
   ===================================================== */
.overview-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.summary-pill {
  background: var(--surface);
  border: 1.5px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}
.summary-pill .pill-num {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
}
.summary-pill.danger .pill-num {
  color: var(--danger);
}

.overview-groups {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}
@media (min-width: 1100px) {
  .overview-groups {
    grid-template-columns: 1fr 1fr;
  }
}

.overview-group {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.og-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.og-head .og-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  font-family: 'Readex Pro', sans-serif;
}
.og-head .og-ico {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 17px;
}
.og-head .og-count {
  background: var(--primary);
  color: white;
  padding: 2px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  min-width: 30px;
  text-align: center;
}

/* ألوان حسب المرحلة */
.og-stage-1 .og-ico { background: #fef3c7; color: #92400e; }
.og-stage-2 .og-ico { background: #dbeafe; color: #1e40af; }
.og-stage-3 .og-ico { background: #ddd6fe; color: #5b21b6; }
.og-stage-4 .og-ico { background: #d1fae5; color: #065f46; }
.og-stage-5 .og-ico { background: #fed7aa; color: #9a3412; }
.og-stage-6 .og-ico { background: #d1fae5; color: var(--success); }
.og-stage-6 .og-count { background: var(--success); }

.og-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.og-list li {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.og-list li:last-child {
  border-bottom: none;
}
.og-list li.is-overdue {
  background: linear-gradient(90deg, #fef2f2 0%, transparent 100%);
  border-right: 4px solid var(--danger);
}

.og-person {
  flex: 1;
  min-width: 0;
}
.og-person .person-name {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.og-person .person-rank {
  color: var(--teal);
  font-weight: 500;
  font-size: 13px;
}
.og-person .person-course {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.og-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  text-align: left;
  flex-shrink: 0;
}
.og-days {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.og-days.overdue {
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 700;
}

.og-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
}

/* =====================================================
   هيدر الموبايل + قائمة منسدلة
   ===================================================== */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.mh-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mh-title {
  font-weight: 700;
  font-size: 15px;
  font-family: 'Readex Pro', sans-serif;
}
.mh-menu-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-soft);
  display: grid;
  gap: 4px;
  align-content: center;
  justify-items: center;
}
.mh-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.mobile-menu {
  display: none;
  position: fixed;
  top: 60px;
  left: 12px;
  right: 12px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  animation: pop 0.18s ease;
}
.mobile-menu:not([hidden]) {
  display: block;
}
.mm-user {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.mm-item {
  display: block;
  width: 100%;
  text-align: right;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.mm-item:hover {
  background: var(--bg-soft);
}
.mm-item.danger {
  color: var(--danger);
}
.mm-item.danger:hover {
  background: var(--danger-bg);
}

/* =====================================================
   إصلاحات رسائل الحذف
   ===================================================== */
.msg-delete {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(220, 38, 38, 0.85);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}
.msg {
  position: relative;
}
.msg:hover .msg-delete,
.msg .msg-delete.always {
  display: flex;
}
.msg.deleted {
  opacity: 0.55;
  font-style: italic;
}

/* =====================================================
   موبايل (تصميم قوي وواضح)
   ===================================================== */
@media (max-width: 880px) {
  body {
    font-size: 14px;
  }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  /* إظهار هيدر الموبايل */
  .mobile-header {
    display: flex;
  }

  /* الشريط الجانبي → شريط سفلي ثابت */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    width: 100%;
    z-index: 30;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    padding: 6px 4px;
    overflow-x: auto;
    box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.08);
  }
  .sidebar-brand,
  .sidebar-user {
    display: none;
  }
  .nav {
    flex: 1;
    flex-direction: row;
    gap: 2px;
    justify-content: space-around;
  }
  .nav-item {
    flex-direction: column;
    gap: 2px;
    padding: 6px 6px;
    font-size: 10px;
    min-width: 60px;
    text-align: center;
    border-radius: 10px;
    line-height: 1.2;
  }
  .nav-item span:not(.nav-ico):not(.nav-badge) {
    font-size: 10px;
    white-space: nowrap;
  }
  .nav-item .nav-ico {
    font-size: 22px;
  }
  .nav-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    margin: 0;
    font-size: 9px;
    padding: 1px 5px;
    min-width: 16px;
  }

  /* المحتوى يأخذ كل المساحة + هامش سفلي للشريط */
  .main {
    padding: 12px 12px 90px 12px;
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  }

  .view-header {
    margin-bottom: 14px;
  }
  .view-header h1 {
    font-size: 19px;
  }
  .view-header .btn-primary,
  .view-header .btn-secondary {
    width: 100%;
  }

  /* بطاقات الدورات على الموبايل */
  .course-card {
    padding: 14px;
  }
  .course-identity .name {
    font-size: 16px;
  }

  /* stepper مبسّط: نخفي الشريط الكامل، نعرض فقط المرحلة الحالية بوضوح */
  .stepper {
    display: none;
  }
  .course-card .mobile-stage-now {
    display: flex !important;
  }

  .course-meta {
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
  }
  .course-actions {
    flex-direction: column;
    gap: 6px;
  }
  .course-actions > * {
    width: 100%;
  }
  .course-actions label {
    flex-direction: column;
    align-items: stretch !important;
  }
  .course-actions select {
    width: 100% !important;
  }

  /* النظرة العامة على الموبايل */
  .overview-summary {
    width: 100%;
    justify-content: stretch;
  }
  .summary-pill {
    flex: 1;
    justify-content: center;
    font-size: 12px;
    padding: 8px 10px;
  }
  .og-list li {
    padding: 10px 12px;
  }
  .og-person .person-name {
    font-size: 14px;
  }

  /* الجداول → كروت رأسية */
  .table-wrap {
    border: none;
    background: transparent;
    box-shadow: none;
  }
  .data-table {
    background: transparent;
  }
  .data-table thead {
    display: none;
  }
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  .data-table td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
  }
  .data-table td.no-label::before {
    display: none;
  }
  .row-actions {
    justify-content: flex-end;
    width: 100%;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 6px;
  }

  /* بطاقة الإجراء على الموبايل: عمودي + زر كامل العرض */
  .print-action-card {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    padding: 16px;
  }
  .pa-btn {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    justify-content: center;
  }

  /* جدول التدريب → مع تمرير أفقي + خانات أصغر */
  .training-table {
    min-width: 600px;
  }
  .table-wrap.training-wrap {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    overflow-x: auto;
  }

  /* الدردشة */
  .chat-shell {
    height: calc(100vh - 230px);
    min-height: 380px;
  }
  .msg {
    max-width: 90%;
  }
  .msg-delete {
    display: flex; /* دائماً ظاهر على الموبايل */
  }

  .modal-card {
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 420px) {
  .nav-item {
    min-width: 52px;
    padding: 5px 3px;
  }
  .nav-item span:not(.nav-ico):not(.nav-badge) {
    font-size: 9px;
  }
}

/* === stage now badge (يظهر فقط على الموبايل) === */
.mobile-stage-now {
  display: none;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: white;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-weight: 600;
}
.mobile-stage-now .stage-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 700;
}
.mobile-stage-now .stage-text {
  flex: 1;
}
.mobile-stage-now .stage-text small {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
}
