/* ============================================================
   لوحة الإدارة — تعتمد متغيّرات styles.css ووضعها الليلي
   ============================================================ */
body.admin {
  min-height: 100vh;
  margin: 0;
}

/* ---------- شاشة الدخول ---------- */
.login-wrap {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  padding: 34px 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 20px; justify-content: center; }
.login-card h1 { margin: 0 0 6px; color: var(--green); font-size: 1.5rem; }
[data-theme="dark"] .login-card h1 { color: var(--ink); }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 0.95rem; }
.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { color: var(--green); font-weight: 800; font-size: 0.92rem; }
[data-theme="dark"] .field label { color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 1rem;
}
.field textarea { min-height: 90px; padding: 12px 14px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(31,93,77,.16);
}
.msg { min-height: 1.3em; margin: 4px 0 0; font-weight: 700; }
.msg.err { color: #c0533b; }
.msg.ok { color: var(--green-2); }

/* ---------- إطار اللوحة ---------- */
.admin-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px;
  background: var(--header-bg); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.admin-header .brand { color: var(--green); }
[data-theme="dark"] .admin-header .brand { color: var(--ink); }
.admin-header .right { display: flex; align-items: center; gap: 10px; }
.admin-user { color: var(--muted); font-weight: 700; font-size: .9rem; }

.admin-main { width: min(1100px, calc(100% - 40px)); margin: 28px auto 60px; }

/* بطاقات الإحصاء */
.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 26px; }
.stat-card {
  padding: 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.stat-card strong { display: block; color: var(--green); font-size: 2rem; font-weight: 800; }
[data-theme="dark"] .stat-card strong { color: var(--green-3); }
.stat-card span { color: var(--muted); font-weight: 700; font-size: .92rem; }

/* تبويبات */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  min-height: 42px; padding: 0 18px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); color: var(--muted);
  font: inherit; font-weight: 800; cursor: pointer; transition: all .2s var(--ease);
}
.tab.is-active { background: linear-gradient(145deg,var(--green-2),var(--green)); color: #fff9ed; border-color: transparent; }
.panel[hidden] { display: none; }

/* جداول */
.table-wrap {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-sm); overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 13px 14px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--green); font-size: .85rem; font-weight: 800; background: var(--surface-2); }
[data-theme="dark"] th { color: var(--ink); }
td { color: var(--ink); font-size: .92rem; }
tr:last-child td { border-bottom: 0; }
.cell-msg { max-width: 280px; color: var(--muted); }

.badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; }
.badge.new { background: rgba(196,154,69,.18); color: var(--gold-2); }
.badge.contacted { background: rgba(31,93,77,.14); color: var(--green-2); }
.badge.done { background: rgba(31,157,85,.16); color: #1f9d55; }
.badge.off { background: rgba(192,83,59,.14); color: #c0533b; }
.badge.on { background: rgba(31,157,85,.16); color: #1f9d55; }

.status-select { min-height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-size: .85rem; }

/* أزرار */
.btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-sm); font: inherit; font-weight: 800; font-size: .9rem; cursor: pointer; transition: all .2s var(--ease); }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(145deg,var(--green-2),var(--green)); color: #fff9ed; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--green); }
[data-theme="dark"] .btn-ghost { color: var(--ink); }
.btn-danger { background: rgba(192,83,59,.12); color: #c0533b; border-color: rgba(192,83,59,.3); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .82rem; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; color: var(--green); font-size: 1.3rem; }
[data-theme="dark"] .toolbar h2 { color: var(--ink); }

.empty { padding: 30px; text-align: center; color: var(--muted); font-weight: 700; }

/* أيقونة الوضع الليلي (نفس منطق الموقع) */
.theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .moon { display: block; }

/* نافذة منبثقة */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(10,20,16,.55); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; padding: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 18px; color: var(--green); font-size: 1.25rem; }
[data-theme="dark"] .modal-card h3 { color: var(--ink); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .row2, .row3 { grid-template-columns: 1fr; }
}

/* ---------- أدوات شريط المهام ---------- */
.toolbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-input {
  min-height: 38px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--ink);
  font: inherit; font-size: .88rem;
}
.search-input:focus { outline: none; border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(31,93,77,.16); }

.badge.draft { background: rgba(150,150,150,.18); color: var(--muted); }
.badge.sched { background: rgba(196,154,69,.2); color: var(--gold-2); }

/* ---------- نافذة واسعة ---------- */
.modal-card-wide { width: min(860px, 100%); }
.checkbox-field { margin-bottom: 14px; }
.checkbox-field label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-field input { width: auto; min-height: auto; }

/* ---------- تبويبات اللغة ---------- */
.lang-tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.lang-tab {
  min-height: 38px; padding: 0 16px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font: inherit; font-weight: 800; cursor: pointer;
}
.lang-tab.is-active { color: var(--green); border-bottom-color: var(--gold); }
[data-theme="dark"] .lang-tab.is-active { color: var(--ink); }
.lang-pane[hidden] { display: none; }

/* ---------- المحرر الغني ---------- */
.rte { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.rte-toolbar button {
  min-width: 34px; height: 32px; padding: 0 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit;
  font-size: .85rem; cursor: pointer;
}
.rte-toolbar button:hover { border-color: var(--green-2); }
.rte-editor {
  min-height: 220px; max-height: 460px; overflow-y: auto; padding: 14px 16px;
  color: var(--ink); font: inherit; font-size: 1rem; line-height: 1.9;
}
.rte-editor:focus { outline: none; }
.rte-editor h2 { font-size: 1.2rem; color: var(--green); margin: 16px 0 8px; }
.rte-editor h3 { font-size: 1.05rem; color: var(--green-2); margin: 14px 0 6px; }
[data-theme="dark"] .rte-editor h2, [data-theme="dark"] .rte-editor h3 { color: var(--ink); }
.rte-editor blockquote { margin: 12px 0; padding: 10px 16px; border-inline-start: 3px solid var(--gold); background: var(--surface-2); border-radius: 8px; }
.rte-editor ul, .rte-editor ol { padding-inline-start: 24px; }
.rte-editor a { color: var(--green-2); }

/* ---------- معاينة الغلاف ---------- */
.cover-row { display: flex; gap: 8px; }
.cover-row input { flex: 1; }
.cover-preview { margin-top: 10px; }
.cover-preview img { max-width: 240px; max-height: 140px; border-radius: var(--radius-sm); border: 1px solid var(--line); object-fit: cover; }

/* ---------- مكتبة الوسائط ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.media-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; text-align: start; padding: 0; }
button.media-card { cursor: pointer; font: inherit; color: var(--ink); }
button.media-card.pickable:hover { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(31,93,77,.14); }
.media-thumb { aspect-ratio: 16 / 10; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-meta { padding: 8px 10px; display: grid; gap: 6px; }
.media-card code, .media-picker-grid code { display: block; font-size: .72rem; color: var(--muted); word-break: break-all; padding: 6px 10px; }
.media-actions { display: flex; gap: 6px; }

/* ---------- معاينة المقال ---------- */
.article-preview { max-height: 60vh; overflow-y: auto; padding: 6px 4px; }
.article-preview h1 { color: var(--green); font-size: 1.5rem; margin: 6px 0 10px; }
[data-theme="dark"] .article-preview h1 { color: var(--ink); }
.article-preview .meta { color: var(--gold-2); font-weight: 800; font-size: .85rem; }
.article-preview .lead { color: var(--muted); font-weight: 700; }
.article-preview .article-content { line-height: 1.95; }
.article-preview .article-content h2 { color: var(--green); font-size: 1.2rem; margin: 18px 0 8px; }
.article-preview .article-hero img { max-width: 100%; border-radius: var(--radius-sm); margin: 12px 0; }

/* إشعار SSE للإدارة */
.admin-toast {
  position: fixed;
  inset-block-start: 24px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.98rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--gold);
  backdrop-filter: blur(12px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.admin-toast[hidden] {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
  pointer-events: none;
}

