:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #263349;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
}

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

body {
  font-family: "Cairo", "Tajawal", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.85rem; }
.req { color: var(--danger); }
.link { color: var(--primary-hover); text-decoration: underline; cursor: pointer; }
code { background: #0b1220; padding: 1px 6px; border-radius: 6px; font-size: 0.85em; }

/* ============ التخطيط ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #312e81 0%, #1e1b4b 60%, #0f172a 100%);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; padding: 0 8px; }
.brand-icon { font-size: 1.6rem; }
.brand-name { font-weight: 800; font-size: 1.25rem; letter-spacing: 0.5px; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item {
  display: block;
  padding: 12px 16px;
  border-radius: 10px;
  color: #c7d2fe;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.14); color: #fff; }

.sidebar-footer { font-size: 0.75rem; color: #818cf8; text-align: center; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); }

.content { flex: 1; padding: 32px 40px; max-width: 1100px; }
.page-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 24px; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 28px 0 12px; color: #cbd5e1; }

/* ============ البطاقات ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.stat-icon { font-size: 1.8rem; }
.stat-value { font-size: 2rem; font-weight: 800; margin: 6px 0 2px; color: var(--primary-hover); }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on .dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.chip.off .dot { background: var(--danger); }

.activity-feed { display: flex; flex-direction: column; gap: 10px; }
.activity-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}
.activity-item .a-message { font-weight: 600; }
.activity-item .a-details { color: var(--text-muted); font-size: 0.88rem; margin-top: 4px; word-break: break-word; }
.activity-item .a-time { color: var(--text-muted); font-size: 0.78rem; margin-top: 6px; }
.activity-item.error { border-color: #7f1d1d; }
.empty-state { color: var(--text-muted); text-align: center; padding: 40px 0; }

/* ============ النماذج ============ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field span { font-weight: 600; font-size: 0.92rem; }

input[type="text"], input[type="password"], input[type="url"], textarea, select {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; }
.hint { color: var(--text-muted); font-size: 0.82rem; line-height: 1.6; }

/* ============ الأزرار ============ */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 22px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg-card-hover); }
.btn-yt { background: #c00; color: #fff; }
.btn-yt:hover { background: #e00; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 34px; font-size: 1.05rem; margin-top: 20px; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-success { background: var(--success); color: #fff; }

/* ============ منطقة الرفع ============ */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: rgba(99, 102, 241, 0.06); }
.drop-icon { font-size: 2.4rem; margin-bottom: 8px; }
#video-preview { max-width: 100%; max-height: 300px; border-radius: 10px; }
.file-meta { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }

/* ============ اختيار المنصات ============ */
.platform-toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.platform-toggle {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: border-color 0.15s, opacity 0.15s;
  opacity: 0.5;
  user-select: none;
}
.platform-toggle .pt-check { margin-inline-start: auto; color: var(--brand); font-weight: 800; opacity: 0; }
.platform-toggle.active { border-color: var(--brand); opacity: 1; }
.platform-toggle.active .pt-check { opacity: 1; }
.pt-icon { font-size: 1.3rem; }

/* ============ حالة مهمة النشر ============ */
.job-status { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.job-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}
.job-row .jr-platform { font-weight: 700; min-width: 110px; }
.job-row .jr-state { color: var(--text-muted); }
.job-row.done { border-color: #14532d; }
.job-row.done .jr-state { color: var(--success); }
.job-row.error { border-color: #7f1d1d; }
.job-row.error .jr-state { color: var(--danger); }
.job-row a { color: var(--primary-hover); word-break: break-all; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ التعليقات ============ */
.comments-toolbar { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-bottom: 20px; }
.switch-wrap { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.field-inline { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.field-inline select { width: auto; }

.switch { position: relative; width: 46px; height: 26px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px; inset-inline-start: 3px;
  transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(-20px); }

.comment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.comment-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.comment-author { font-weight: 800; }
.comment-time { color: var(--text-muted); font-size: 0.8rem; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.4);
}
.badge.own { background: rgba(99, 102, 241, 0.15); color: var(--primary-hover); border-color: rgba(99, 102, 241, 0.4); }
.comment-message { margin: 10px 0 14px; line-height: 1.8; white-space: pre-wrap; }
.comment-reply-area { margin-top: 10px; }
.comment-reply-area textarea { margin-bottom: 8px; }
.comment-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* ============ الإعدادات ============ */
.settings-card { margin-bottom: 18px; }
.settings-card h3 { margin-bottom: 16px; font-size: 1.05rem; }
.settings-card .field { margin-bottom: 12px; }
.card-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.test-result { font-size: 0.88rem; font-weight: 600; }
.test-result.ok { color: var(--success); }
.test-result.fail { color: var(--danger); }

/* ============ تسجيل الدخول ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1e1b4b 0%, var(--bg) 60%);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px;
  width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-size: 2.6rem; }
.login-card h1 { font-size: 1.4rem; }
.login-card p { color: var(--text-muted); font-size: 0.9rem; }
.login-error { color: var(--danger); font-size: 0.88rem; font-weight: 600; }

/* ============ التنبيهات ============ */
#toasts {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--primary);
  border-radius: 10px;
  padding: 14px 20px;
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.25s ease;
  max-width: 420px;
}
.toast.success { border-inline-start-color: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 800px) {
  .sidebar { width: 72px; padding: 20px 8px; }
  .brand-name, .nav-item { font-size: 0; }
  .nav-item { text-align: center; font-size: 1.2rem; }
  .sidebar-footer { display: none; }
  .content { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
}
