/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --c-primary: #0d7377;
  --c-primary-dark: #075a5e;
  --c-primary-light: #14a085;
  --c-secondary: #1a232a;
  --c-accent: #d4af37;
  --c-accent-light: #e6c558;
  --c-bg: #f5f0e8;
  --c-bg-card: #ffffff;
  --c-bg-dark: #1a232a;
  --c-text: #2c3e50;
  --c-text-light: #5a6c7d;
  --c-text-inv: #f0f0f0;
  --c-border: #e0d8cc;
  --c-success: #27ae60;
  --c-warning: #f39c12;
  --c-error: #e74c3c;
  --c-overlay: rgba(26, 35, 42, 0.92);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 24px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.15);
  --font-ar: 'Tajawal', 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-ar);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.8;
  direction: rtl;
  overflow-x: hidden;
}

::selection { background: var(--c-primary); color: #fff; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb { background: var(--c-primary); border-radius: 4px; }

/* ===== Layout ===== */
.app-wrapper { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== Header ===== */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--c-secondary);
  box-shadow: var(--shadow-md);
  border-bottom: 3px solid var(--c-accent);
}
.header-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; gap: 16px;
}
.logo-area { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.logo-icon {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-light));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; font-weight: 700;
  box-shadow: 0 2px 8px rgba(13,115,119,0.4);
}
.logo-text h1 {
  font-size: 1.15rem; color: #fff; font-weight: 700; line-height: 1.3;
}
.logo-text span { font-size: .72rem; color: var(--c-accent); }

.header-actions { display: flex; gap: 10px; align-items: center; }
.btn-icon {
  width: 40px; height: 40px; border: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.08); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .25s ease; font-size: 18px;
}
.btn-icon:hover { background: var(--c-primary); transform: translateY(-2px); }

/* ===== Hamburger / Sidebar Toggle ===== */
.sidebar-toggle { display: none; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; top: 0; right: -340px; width: 320px;
  height: 100vh; background: var(--c-secondary);
  z-index: 200; overflow-y: auto;
  transition: right .35s cubic-bezier(.4,0,.2,1);
  box-shadow: -4px 0 30px rgba(0,0,0,0.3);
  border-left: 2px solid var(--c-accent);
}
.sidebar.open { right: 0; }
.sidebar-header {
  padding: 20px 24px; background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-header h2 { color: #fff; font-size: 1.1rem; margin-bottom: 4px; }
.sidebar-header p { color: var(--c-accent); font-size: .8rem; }
.sidebar-close {
  position: absolute; top: 16px; left: 16px;
  width: 32px; height: 32px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.1); color: #fff; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.sidebar-close:hover { background: var(--c-error); }

.toc { list-style: none; padding: 12px 0; }
.toc-item {
  padding: 10px 24px; cursor: pointer; transition: all .2s;
  border-right: 3px solid transparent;
}
.toc-item:hover { background: rgba(255,255,255,0.05); border-right-color: var(--c-primary-light); }
.toc-item.active { background: rgba(13,115,119,0.15); border-right-color: var(--c-accent); }
.toc-item .toc-label { color: #d0d5db; font-size: .85rem; }
.toc-item.active .toc-label { color: #fff; font-weight: 600; }
.toc-item .toc-sub { color: #7a8590; font-size: .72rem; margin-top: 2px; }
.toc-item.active .toc-sub { color: var(--c-accent); }

.toc-section-title {
  padding: 14px 24px 6px; color: var(--c-accent);
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0; background: var(--c-overlay);
  z-index: 150; opacity: 0; pointer-events: none;
  transition: opacity .35s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* ===== Main Content ===== */
.main-content {
  flex: 1; max-width: 800px; margin: 0 auto;
  padding: 40px 24px 80px; width: 100%;
}

/* ===== Book Cover ===== */
.book-cover {
  text-align: center; padding: 60px 20px 40px;
  animation: fadeInUp .8s ease;
}
.book-cover .cover-badge {
  display: inline-block; padding: 6px 20px;
  background: var(--c-accent); color: var(--c-secondary);
  border-radius: 20px; font-size: .8rem; font-weight: 700;
  margin-bottom: 24px; letter-spacing: 1px;
}
.book-cover h1 {
  font-size: 2.4rem; color: var(--c-secondary); font-weight: 800;
  line-height: 1.4; margin-bottom: 16px;
}
.book-cover h1 span { color: var(--c-primary); }
.book-cover .cover-sub {
  font-size: 1.1rem; color: var(--c-text-light); margin-bottom: 32px;
}
.book-cover .cover-deco {
  width: 60px; height: 4px; background: var(--c-accent);
  margin: 0 auto 32px; border-radius: 2px;
}
.book-cover .cover-info {
  display: flex; justify-content: center; gap: 32px; flex-wrap: wrap;
  margin-bottom: 40px;
}
.cover-info-item { text-align: center; }
.cover-info-item .num {
  font-size: 2rem; font-weight: 800; color: var(--c-primary);
}
.cover-info-item .label { font-size: .8rem; color: var(--c-text-light); }

.btn-start {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 40px; background: var(--c-primary); color: #fff;
  border: none; border-radius: 30px; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; transition: all .3s ease;
  box-shadow: 0 4px 20px rgba(13,115,119,0.35);
  font-family: var(--font-ar);
}
.btn-start:hover {
  background: var(--c-primary-dark); transform: translateY(-3px);
  box-shadow: 0 8px 28px rgba(13,115,119,0.45);
}

/* ===== Page Display ===== */
.page-container { animation: fadeInUp .5s ease; }

.page-breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--c-text-light);
  margin-bottom: 16px; flex-wrap: wrap;
}
.page-breadcrumb .sep { color: var(--c-border); }
.page-breadcrumb .current { color: var(--c-primary); font-weight: 600; }

.page-title {
  font-size: 1.7rem; color: var(--c-secondary); font-weight: 800;
  margin-bottom: 8px; line-height: 1.4;
}
.page-subtitle {
  font-size: 1rem; color: var(--c-text-light); margin-bottom: 24px;
  padding-bottom: 16px; border-bottom: 2px solid var(--c-border);
}
.page-section-title {
  font-size: 1.25rem; color: var(--c-primary-dark); font-weight: 700;
  margin: 28px 0 12px; padding-right: 14px;
  border-right: 4px solid var(--c-accent);
}
.page-content p {
  margin-bottom: 16px; font-size: 1.02rem; color: var(--c-text);
  line-height: 2; text-align: justify;
}
.page-content ul, .page-content ol {
  margin: 12px 24px 20px; line-height: 2;
}
.page-content li { margin-bottom: 8px; }
.page-content strong { color: var(--c-secondary); font-weight: 700; }
.page-content em { color: var(--c-primary); font-style: normal; font-weight: 600; }

.page-content blockquote {
  margin: 20px 0; padding: 16px 20px;
  background: linear-gradient(135deg, rgba(13,115,119,0.06), rgba(212,175,55,0.06));
  border-right: 4px solid var(--c-accent);
  border-radius: var(--radius-sm);
  font-size: 1.05rem; color: var(--c-secondary);
}
.page-content blockquote strong { color: var(--c-primary-dark); }

/* Custom HTML blocks (tables, etc.) */
.page-content .custom-html-block {
  margin: 24px 0; border-radius: var(--radius-md);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.page-content .custom-html-block table {
  width: 100%; border-collapse: collapse; background: #fff;
}
.page-content .custom-html-block table th {
  background: var(--c-primary); color: #fff;
  padding: 12px 16px; font-weight: 700; font-size: .9rem; text-align: right;
}
.page-content .custom-html-block table td {
  padding: 10px 16px; border-bottom: 1px solid var(--c-border);
  font-size: .9rem; color: var(--c-text);
}
.page-content .custom-html-block table tr:nth-child(even) td { background: #faf7f2; }
.page-content .custom-html-block table tr:hover td { background: rgba(13,115,119,0.04); }
.page-content .custom-html-block .info-box {
  padding: 18px 22px; border-radius: var(--radius-md);
  margin: 16px 0;
}
.page-content .custom-html-block .info-box.warning {
  background: #fff8e1; border-right: 4px solid var(--c-warning); color: #7a5d00;
}
.page-content .custom-html-block .info-box.success {
  background: #e8f5e9; border-right: 4px solid var(--c-success); color: #1b5e20;
}
.page-content .custom-html-block .info-box.danger {
  background: #fbe9e7; border-right: 4px solid var(--c-error); color: #b71c1c;
}
.page-content .custom-html-block .info-box.info {
  background: #e0f2f1; border-right: 4px solid var(--c-primary); color: #004d40;
}

/* ===== Navigation ===== */
.page-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 40px; padding-top: 24px; border-top: 2px solid var(--c-border);
  gap: 16px;
}
.nav-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 22px; border: 2px solid var(--c-border);
  background: #fff; color: var(--c-text); border-radius: 30px;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: all .25s ease; font-family: var(--font-ar);
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--c-primary); background: var(--c-primary); color: #fff;
  transform: translateY(-2px);
}
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.nav-btn.prev { flex-direction: row-reverse; }

.page-indicator {
  font-size: .85rem; color: var(--c-text-light);
  background: #fff; padding: 8px 18px; border-radius: 20px;
  border: 1px solid var(--c-border); white-space: nowrap;
}
.page-indicator strong { color: var(--c-primary); }

/* ===== Copy All Button ===== */
.copy-all-bar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 90;
}
.btn-copy-all {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 32px;
  background: var(--c-accent); color: var(--c-secondary);
  border: none; border-radius: 30px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all .3s ease;
  box-shadow: 0 6px 24px rgba(212,175,55,0.4);
  font-family: var(--font-ar);
}
.btn-copy-all:hover {
  background: var(--c-accent-light); transform: translateY(-3px);
  box-shadow: 0 10px 32px rgba(212,175,55,0.55);
}
.btn-copy-all.copied { background: var(--c-success); color: #fff; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--c-secondary); color: #fff;
  padding: 14px 28px; border-radius: 30px; font-size: .9rem;
  z-index: 300; opacity: 0; pointer-events: none;
  transition: all .35s ease; box-shadow: var(--shadow-lg);
  border: 1px solid var(--c-accent);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Copy Modal ===== */
.copy-modal {
  position: fixed; inset: 0; background: var(--c-overlay);
  z-index: 250; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .3s;
  padding: 20px;
}
.copy-modal.show { opacity: 1; pointer-events: auto; }
.copy-modal-inner {
  background: var(--c-bg-card); border-radius: var(--radius-lg);
  max-width: 700px; width: 100%; max-height: 80vh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: scaleIn .3s ease;
}
.copy-modal-header {
  padding: 20px 28px; background: var(--c-secondary); color: #fff;
  display: flex; justify-content: space-between; align-items: center;
}
.copy-modal-header h3 { font-size: 1.1rem; }
.copy-modal-header .close-btn {
  width: 32px; height: 32px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.1); color: #fff; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.copy-modal-header .close-btn:hover { background: var(--c-error); }
.copy-modal-body {
  padding: 24px 28px; overflow-y: auto; flex: 1;
}
.copy-modal-body pre {
  font-family: 'Courier New', monospace; font-size: .85rem;
  white-space: pre-wrap; word-break: break-word; line-height: 1.6;
  color: var(--c-text); direction: ltr; text-align: left;
}
.copy-modal-footer {
  padding: 16px 28px; border-top: 1px solid var(--c-border);
  display: flex; gap: 12px; justify-content: flex-end;
}
.btn-modal-copy {
  padding: 10px 28px; background: var(--c-primary); color: #fff;
  border: none; border-radius: 25px; font-size: .9rem; font-weight: 700;
  cursor: pointer; transition: all .25s; font-family: var(--font-ar);
}
.btn-modal-copy:hover { background: var(--c-primary-dark); }
.btn-modal-close {
  padding: 10px 28px; background: #eee; color: var(--c-text);
  border: none; border-radius: 25px; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .25s; font-family: var(--font-ar);
}
.btn-modal-close:hover { background: #ddd; }

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes slideInRight {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { padding: 12px 16px; }
  .logo-text h1 { font-size: .95rem; }
  .logo-text span { font-size: .65rem; }
  .sidebar-toggle { display: flex; }
  .main-content { padding: 24px 16px 80px; }
  .book-cover h1 { font-size: 1.8rem; }
  .book-cover .cover-info { gap: 20px; }
  .page-title { font-size: 1.35rem; }
  .page-section-title { font-size: 1.1rem; }
  .page-nav { flex-direction: column; gap: 12px; }
  .nav-btn { width: 100%; justify-content: center; }
  .page-indicator { order: -1; }
  .copy-all-bar { bottom: 16px; width: 90%; }
  .btn-copy-all { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
  .book-cover { padding: 40px 16px 24px; }
  .book-cover h1 { font-size: 1.5rem; }
  .cover-info-item .num { font-size: 1.5rem; }
  .page-content p { font-size: .95rem; }
}

/* ===== Print ===== */
@media print {
  .site-header, .sidebar, .overlay, .copy-all-bar, .page-nav, .toast, .copy-modal { display: none; }
  .main-content { max-width: 100%; padding: 0; }
}
