/* لوحة إدارة مكتبات العراق — RTL */

:root {
  --primary: #2f6b5e;
  --primary-light: #ddede6;
  --accent: #d9a85c;
  --success: #3e8e6b;
  --warning: #c9a227;
  --error: #c05b5b;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1a2a26;
  --text-secondary: #5f6e76;
  --border: #e2e8e6;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(26, 42, 38, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
}

/* ── تسجيل الدخول ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #1e4a40 100%);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-card h1 {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 6px;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

/* ── التخطيط الرئيسي ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-header h2 { font-size: 1.1rem; font-weight: 700; }
.sidebar-header p { font-size: 0.78rem; opacity: 0.75; margin-top: 4px; }

.nav-list { padding: 12px 10px; list-style: none; }

.nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s;
  position: relative;
}

.nav-item a:hover, .nav-item a.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.nav-badge {
  background: var(--error);
  color: #fff;
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 10px;
  margin-right: auto;
}

.main-content {
  margin-right: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 { font-size: 1.25rem; color: var(--primary); }

.page-body { padding: 24px 28px; }

/* ── بطاقات الإحصائيات ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.stat-card .label { font-size: 0.82rem; color: var(--text-secondary); }
.stat-card .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.stat-card-primary { border-right: 4px solid var(--primary); }

.section-title {
  font-size: 1.05rem;
  color: var(--primary);
  margin-bottom: 14px;
  font-weight: 700;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.82rem;
}

.bar-cell { width: 40%; min-width: 120px; }

.stat-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.stat-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
}

/* ── بطاقات المحتوى ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.card-img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--primary-light);
}

.card-title { font-weight: 600; font-size: 1rem; }
.card-meta { font-size: 0.82rem; color: var(--text-secondary); }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* ── أزرار ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline-danger { border-color: var(--error); color: var(--error); }
.btn-accent { background: var(--accent); color: #fff; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── حقول الإدخال ── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

textarea.form-control { resize: vertical; min-height: 90px; }

/* ── تبويبات ── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ── شارات الحالة ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-pending { background: #fff3cd; color: #856404; }
.badge-active { background: #d4edda; color: #155724; }
.badge-rejected { background: #f8d7da; color: #721c24; }
.badge-expired { background: #e2e3e5; color: #383d41; }

/* ── حالات فارغة / تحميل ── */
.empty-state, .loading-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── نافذة منبثقة ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { margin-bottom: 16px; color: var(--primary); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.88rem;
  z-index: 300;
  animation: fadeUp 0.3s ease;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── معاينة إعلان ── */
.ad-preview-img {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: 12px;
  background: #111;
}

/* ── بنر ── */
.banner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.banner-card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 10px;
}

/* ── جدول إحصائيات ── */
.stats-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.stats-table th, .stats-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.stats-table th { color: var(--text-secondary); font-weight: 600; }

/* ── responsive ── */
.menu-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--primary); }

@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-right: 0; }
  .menu-toggle { display: block; }
  .page-body { padding: 16px; }
}

.hidden { display: none !important; }

/* ── لوحة صاحب المكتبة ── */
.sidebar.owner-sidebar {
  background: linear-gradient(180deg, #1e4a40 0%, #163830 100%);
}

.page-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.book-card .book-cover {
  width: 72px;
  height: 96px;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  background: var(--primary-light);
}

.image-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.image-preview-item {
  position: relative;
  width: 80px;
  height: 106px;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-remove-btn {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--error);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.image-preview-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  z-index: 1;
}

.image-preview-badge.is-cover {
  background: var(--primary, #2F6B5E);
}

.owner-info-box {
  padding: 12px;
  background: var(--primary-light, #e8f0ee);
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.65;
}

.staff-perms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.staff-perm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

.staff-perm-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.banner-reorder-card {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.banner-reorder-preview {
  flex: 0 0 200px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--primary-light);
}

.banner-reorder-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.banner-reorder-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.owner-ad-card .owner-ad-thumb {
  width: 56px;
  height: 100px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.owner-ad-card .owner-ad-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.owner-ad-upload {
  background: var(--primary-light);
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.88rem;
  overflow: hidden;
}

.modal-wide {
  max-width: 520px;
  width: 95%;
}

.offer-books-checklist label.offer-book-item {
  display: block;
  padding: 6px 4px;
  font-size: 0.85rem;
  cursor: pointer;
}

.offer-books-checklist label.offer-book-item:hover {
  background: var(--primary-light);
  border-radius: 6px;
}

.owner-offer-image-preview,
.owner-logo-upload {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  background: var(--primary-light);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.owner-offer-image-preview img,
.owner-logo-upload img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chip-row .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  font-size: 0.85rem;
  cursor: pointer;
}

.chip-row .chip input {
  margin: 0;
}

.owner-status-card {
  margin-bottom: 20px;
  border-right: 4px solid var(--accent);
}

.owner-sub-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.owner-sub-active {
  background: #e8f5e9;
  color: #1b5e20;
  border: 1px solid #c8e6c9;
}

.owner-sub-expired {
  background: #fdecea;
  color: #b71c1c;
  border: 1px solid #f5c6cb;
  font-weight: 600;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}
