/* =====================================================================
   Boukhari Digital Library — Admin Dashboard Styles
   ===================================================================== */

:root {
  --admin-sidebar-width: 250px;
  --admin-bg: #f4f7f6;
  --admin-surface: #ffffff;
  --admin-border: #d6e2dc;
  --admin-dark: #0b2545;
  --admin-dark-2: #07502f;
}

html[dir="rtl"] body.admin-body { font-family: var(--font-ar); }
html[dir="ltr"] body.admin-body { font-family: var(--font-en); }

body.admin-body { background: var(--admin-bg); }

.admin-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------- */
.admin-sidebar {
  width: var(--admin-sidebar-width);
  background: var(--admin-dark);
  color: #cbd2e8;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 40;
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.25s ease;
}
.admin-sidebar .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.admin-sidebar__head {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.admin-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 600;
  padding: 22px 20px;
  flex: 1;
  min-width: 0;
}
.admin-sidebar__close {
  display: none;
  background: none;
  border: none;
  color: #cbd2e8;
  font-size: 1.25rem;
  line-height: 1;
  padding: 8px 10px;
  margin-inline-end: 10px;
  border-radius: 8px;
  cursor: pointer;
}
.admin-sidebar__close:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-sidebar__brand strong { color: var(--color-accent); }
.admin-sidebar__brand .brand__logo { height: 34px; max-width: 120px; }
body.sidebar-collapsed .admin-sidebar__brand .brand__logo { max-width: 44px; }

.admin-sidebar__nav {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 2px;
  flex: 1;
}
.admin-sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #cbd2e8;
  font-weight: 500;
  font-size: 0.94rem;
}
.admin-sidebar__nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.admin-sidebar__nav a.is-active { background: var(--color-primary, #2952e3); color: #fff; }
.admin-sidebar__nav .icon { font-size: 1.05rem; }

.admin-sidebar__footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-sidebar__footer a { color: #9aa4c4; font-size: 0.88rem; display: flex; align-items: center; gap: 10px; }
.admin-sidebar__footer a:hover { color: #fff; }

/* ---------------------------------------------------------------------
   Main content
   --------------------------------------------------------------------- */
.admin-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-topbar {
  background: var(--admin-surface);
  border-bottom: 1px solid var(--admin-border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.admin-topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-topbar__user { font-size: 0.9rem; color: var(--color-text-muted, #6b7280); white-space: nowrap; }
.admin-topbar .nav-toggle { display: flex; }
.admin-topbar .nav-toggle span { background: var(--color-text, #1c2130); }

/* Folded (icon-only) sidebar on desktop. */
@media (min-width: 961px) {
  body.sidebar-collapsed .admin-sidebar { width: 72px; }
  body.sidebar-collapsed .admin-sidebar .label { display: none; }
  body.sidebar-collapsed .admin-sidebar__brand { justify-content: center; padding-inline: 0; }
  body.sidebar-collapsed .admin-sidebar__nav { padding-inline: 10px; }
  body.sidebar-collapsed .admin-sidebar__nav a { justify-content: center; padding-inline: 0; }
  body.sidebar-collapsed .admin-sidebar__nav .icon { font-size: 1.2rem; }
  body.sidebar-collapsed .admin-sidebar__footer { padding-inline: 0; align-items: center; }
  .admin-overlay { display: none !important; }
}

.admin-page {
  padding: 24px;
  flex: 1;
}

/* ---------------------------------------------------------------------
   Login page
   --------------------------------------------------------------------- */
.admin-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-deep) 100%);
  padding: 20px;
}
.login-box {
  background: #fff;
  padding: 40px 36px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box__brand { text-align: center; margin-bottom: 24px; }
.login-box__brand .brand__icon { font-size: 2.4rem; display: block; margin-bottom: 8px; }
.login-box__brand .brand__logo { height: 64px; max-width: 200px; margin: 0 auto 10px; }
.login-box__brand h1 { font-size: 1.2rem; margin: 0 0 4px; }
.login-box__brand p { margin: 0; color: var(--color-text-muted, #6b7280); font-size: 0.9rem; }
.login-box form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 14px 0 6px;
  color: #374151;
}
.login-box form input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  font-size: 0.95rem;
}
.login-box form button { margin-top: 22px; }
.login-box__back {
  display: block;
  text-align: center;
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--color-text-muted, #6b7280);
}

/* ---------------------------------------------------------------------
   Cards / stat tiles
   --------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-card .icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: #eaf1ff;
  flex-shrink: 0;
}
.stat-card .value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .label { color: var(--color-text-muted, #6b7280); font-size: 0.85rem; margin-top: 2px; }

.admin-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 24px;
}
.admin-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.admin-card__header h2 { margin: 0; font-size: 1.05rem; }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: start;
  border-bottom: 1px solid var(--admin-border);
  white-space: nowrap;
}
.data-table th {
  color: var(--color-text-muted, #6b7280);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tr:hover td { background: #fafbff; }
.data-table .cell-title { white-space: normal; max-width: 260px; }
.data-table img.thumb { width: 40px; height: 54px; object-fit: cover; border-radius: 4px; }
.data-table .actions { display: flex; gap: 8px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-published { background: #e6f7ec; color: #1a8f4c; }
.badge-draft { background: #fff4e0; color: #b0730a; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.form-grid .full { grid-column: 1 / -1; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
}
.form-group .hint { font-size: 0.78rem; color: var(--color-text-muted, #6b7280); margin-top: 4px; }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
}
.form-group textarea { resize: vertical; min-height: 110px; }
.form-group { margin-bottom: 18px; }

.radio-group { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--color-text, #1c2130); }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--color-text, #1c2130); }

.current-file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f4f6fb;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.current-file img { width: 36px; height: 48px; object-fit: cover; border-radius: 4px; }

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--admin-border);
  margin-top: 8px;
}

.field-error { color: var(--color-error, #d64545); font-size: 0.8rem; margin-top: 4px; }

/* ---------------------------------------------------------------------
   Misc
   --------------------------------------------------------------------- */
.text-muted { color: var(--color-text-muted, #6b7280); }

/* ---------------------------------------------------------------------
   Settings page
   --------------------------------------------------------------------- */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr));
  gap: 14px;
}
.palette-option { position: relative; cursor: pointer; display: block; }
.palette-option input { position: absolute; opacity: 0; pointer-events: none; }
.palette-option__card {
  border: 2px solid var(--admin-border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.palette-option:hover .palette-option__card { border-color: var(--color-text-muted); }
.palette-option input:checked + .palette-option__card {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.palette-option input:focus-visible + .palette-option__card { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.palette-option__preview { display: flex; height: 64px; }
.palette-option__preview span { flex: 1; }
.palette-option__name {
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.palette-option__check { visibility: hidden; color: var(--color-primary); }
.palette-option input:checked + .palette-option__card .palette-option__check { visibility: visible; }

.branding-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--color-surface-alt);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.branding-preview img { max-height: 56px; max-width: 200px; object-fit: contain; }
.branding-preview--favicon img { width: 32px; height: 32px; }

.slide-admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.slide-admin-item {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  flex-wrap: wrap;
}
.slide-admin-item.is-hidden .slide-admin-item__thumb { opacity: 0.45; }
.slide-admin-item__thumb { width: 160px; aspect-ratio: 1672 / 941; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.slide-admin-item__body { flex: 1; min-width: 140px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.slide-admin-item__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.slide-upload-form {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.slide-upload-form .slide-dropzone { flex: 1 1 320px; }
.slide-upload-form .btn { align-self: center; }

.slide-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 110px;
  padding: 18px;
  border: 2px dashed var(--admin-border);
  border-radius: 12px;
  background: var(--color-surface-alt);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  max-width: 640px;
}
.slide-upload-form .slide-dropzone { max-width: none; }
.slide-dropzone:hover,
.slide-dropzone.is-dragover { border-color: var(--color-primary); }
.slide-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.slide-dropzone__text { font-weight: 600; }
.slide-dropzone__files { font-size: 0.85rem; }
.slide-dropzone__preview {
  width: 100%;
  aspect-ratio: 1672 / 941;
  object-fit: cover;
  border-radius: 8px;
}

@media (max-width: 560px) {
  .slide-admin-item__thumb { width: 100%; }
}
.mb-0 { margin-bottom: 0; }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.form-actions { flex-wrap: wrap; }

@media (max-width: 960px) {
  .admin-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    height: auto;
    width: min(280px, 85vw);
    z-index: 100;
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0.25s ease;
  }
  html[dir="rtl"] .admin-sidebar { transform: translateX(100%); }
  .admin-sidebar.is-open,
  html[dir="rtl"] .admin-sidebar.is-open { transform: none; visibility: visible; }
  .admin-sidebar__close { display: block; }

  .admin-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }
  .admin-overlay.is-visible { opacity: 1; visibility: visible; }
  body.nav-open { overflow: hidden; }

  .admin-content { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .admin-topbar { padding: 0 12px; gap: 10px; height: 56px; }
  .admin-topbar h1 { font-size: 1rem; }
  .admin-topbar__user { display: none; }
  .admin-page { padding: 14px; }
  .admin-card { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-card .icon { width: 40px; height: 40px; font-size: 1.15rem; }
  .stat-card .value { font-size: 1.2rem; }
  .data-table th, .data-table td { padding: 10px; }
  .form-actions .btn { flex: 1 1 auto; justify-content: center; }
  .login-box { padding: 28px 20px; }
  .current-file { flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .stat-grid { grid-template-columns: 1fr; }
}
