/* ==========================================================================
   COMPONENTS.CSS — Reusable UI Components
   Contains: Buttons, Cards, Forms, Navbar, Hero, Footer,
   Preloader, Tags Input, File Uploader, Reader, Book Reader, Toast
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--color-text);
  color: #FFFFFF;
  transition: 0.3s ease;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

/* Primary action button */
.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF !important;
}

.btn-primary:hover {
  background: var(--color-primary-light);
}

/* Auth button (outlined style) */
.btn-auth {
  background: transparent;
  color: var(--color-text);
  border: 2px solid var(--color-text);
  padding: 10px 22px;
}

.btn-auth:hover {
  background: var(--color-text);
  color: #FFFFFF;
}

/* Outline / Ghost variants */
.btn-outline,
.btn-ghost {
  border: 1px solid rgba(42, 53, 42, 0.18);
  background: rgba(255, 255, 255, 0.72);
  color: var(--color-text);
}

.btn-outline:hover,
.btn-ghost:hover {
  background: rgba(42, 53, 42, 0.08);
}

/* Danger button (e.g., delete actions) */
.btn-danger {
  background: #8B2E2E;
  color: #ffffff !important;
}

.btn-danger:hover {
  background: #6B1E1E;
}

/* Navigation button (used in reader) */
.btn-nav {
  background-color: var(--color-text);
  color: white;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 6px;
  transition: opacity 0.3s ease;
}

.btn-nav:hover {
  opacity: 0.85;
}

/* Share button */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
}

/* ----- Button Loading / Submitting State ----- */
.btn.submitting {
  opacity: 0.7;
  pointer-events: none;
  cursor: not-allowed;
}

.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn.submitting .btn-spinner {
  display: inline-block;
  margin-left: 8px;
}

.btn-auth.submitting .btn-spinner {
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: var(--color-text);
}

.btn-auth.submitting {
  background: #cccccc !important;
  color: #999999 !important;
  border-color: #999999 !important;
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   2. Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-bg-card);
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.card-title {
  font-size: 18px;
  margin-bottom: var(--space-sm);
  color: var(--color-text);
}

.card-text {
  font-size: 14px;
  color: var(--color-text-light);
}

/* Book card (used in catalog grids) */
.book-card {
  display: grid;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(196, 214, 200, 0.2));
  border: 1px solid rgba(164, 186, 166, 0.5);
  box-shadow: var(--shadow-md);
}

.book-card__media {
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: calc(var(--radius-xl) - 8px);
  background: linear-gradient(135deg, rgba(42, 53, 42, 0.08), rgba(196, 214, 200, 0.15));
}

.book-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card__title {
  font-size: 20px;
  margin: 0;
  color: var(--color-text);
}

.book-card__description {
  color: var(--color-text-light);
  font-size: 15px;
  line-height: 1.9;
}

.book-card__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
}

/* Book cover placeholder */
.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(42, 53, 42, 0.12), rgba(196, 214, 200, 0.25));
  color: var(--color-text-light);
  font-size: 16px;
  font-weight: 600;
  min-height: 200px;
}

/* Price & Status badges */
.book-price,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(42, 53, 42, 0.06);
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
}

.status-badge--success {
  background: rgba(22, 125, 50, 0.12);
  color: #166534;
}

.status-badge--pending {
  background: rgba(200, 140, 20, 0.16);
  color: #8B6010;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-pending {
  background: #fff3e0;
  color: #e65100;
}

.badge-rejected {
  background: #ffebee;
  color: #c62828;
}

/* --------------------------------------------------------------------------
   3. Forms
   -------------------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.form-label {
  font-weight: 600;
  margin-bottom: 6px;
}

.form-input,
.form-textarea,
select,
input[type="file"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus,
.form-textarea:focus,
select:focus {
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
  outline: none;
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-submit {
  background: var(--color-primary);
  color: white;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 700;
}

/* Tags input (used in admin post editor) */
.tags-input {
  min-height: 40px;
  padding: 6px 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tags-input .tags-text-input {
  border: none;
  outline: none;
  min-width: 120px;
  flex: 1 1 120px;
}

.tag-item {
  background: #f1f3f5;
  color: #111;
  padding: 4px 8px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-item .tag-remove {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 4px;
}

/* File / Thumbnail uploader */
.thumbnail-uploader,
.file-uploader {
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  display: inline-block;
  min-width: 160px;
}

.thumbnail-placeholder,
.file-placeholder {
  color: var(--color-text-light);
}

.thumbnail-preview img,
.file-preview img {
  border-radius: 4px;
}

/* Checkbox row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  flex-wrap: wrap;
}

.upload-field {
  display: grid;
  gap: 8px;
}

.cover-thumb {
  width: 180px;
  border-radius: 16px;
  border: 1px solid rgba(203, 213, 225, 0.8);
}

/* --------------------------------------------------------------------------
   4. Navbar (Main Site Navigation)
   -------------------------------------------------------------------------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 999;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(164, 186, 166, 0.5);
  box-shadow: var(--shadow-sm);
  padding: var(--space-sm) 0;
}

body.nav-open {
  overflow: hidden;
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.nav-logo {
  text-decoration: none;
}

.nav-logo-img {
  height: 44px;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: var(--space-lg);
}

.nav-links a {
  position: relative;
  text-decoration: none;
  color: var(--color-text);
  font-size: 15px;
}

.nav-links a::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -8px;
  width: 100%;
  height: 2px;
  transform: scaleX(0);
  transform-origin: right;
  background: var(--color-primary);
  transition: transform 0.3s ease;
}

.nav-links a:hover,
.nav-links a.is-active {
  color: var(--color-primary);
}

.nav-links a:hover::after,
.nav-links a.is-active::after {
  transform: scaleX(1);
}

.nav-actions {
  display: flex;
  align-items: center;
}

/* Mobile toggle button */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
}

.nav-toggle span {
  width: 22px;
  height: 2px;
  background: var(--color-text);
  transition: 0.3s;
}

/* Mobile slide-in menu */
.mobile-menu {
  position: fixed;
  top: 0;
  right: -260px;
  width: 260px;
  height: 100vh;
  background: var(--color-bg-card);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
  padding-top: 90px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: right 0.3s ease;
  z-index: 1000;
}

.mobile-menu.active {
  right: 0;
}

.mobile-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.mobile-links a {
  text-decoration: none;
  color: var(--color-text);
  font-size: 16px;
}

.mobile-links a:hover {
  color: var(--color-primary);
}

.mobile-login {
  margin-top: 0;
  padding-top: var(--space-md);
}

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 999;
}

.mobile-menu-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 768px) {
  .navbar {
    z-index: 1001;
  }

  .nav-links,
  .nav-actions {
    display: none;
  }

  .nav-toggle {
    display: flex;
  }

  .mobile-menu {
    width: min(320px, 84vw);
    height: 100vh;
    right: -100%;
  }

  .mobile-menu.active {
    right: 0;
  }
}

@media (max-width: 480px) {
  .mobile-menu {
    width: 100vw;
  }
}

/* --------------------------------------------------------------------------
   5. Hero Section
   -------------------------------------------------------------------------- */
.hero {
  padding: 30px 0;
  background: var(--color-bg);
}

.hero-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xl);
  min-height: calc(100vh - 20vh);
}

.hero-text {
  flex: 1;
}

.hero-title {
  font-size: 42px;
  line-height: 1.3;
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

.hero-title span {
  color: var(--color-primary);
}

.hero-subtitle {
  font-size: 18px;
  color: var(--color-text-light);
  margin-bottom: var(--space-lg);
}

.hero-actions {
  display: flex;
  gap: var(--space-md);
}

.hero-image {
  flex: 1;
  text-align: center;
}

.hero-image img {
  max-width: 100%;
  height: auto;
}

@media (max-width: 900px) {
  .hero-content {
    flex-direction: column;
    text-align: center;
  }

  .hero-title {
    font-size: 32px;
  }

  .hero-actions {
    justify-content: center;
  }
}

/* --------------------------------------------------------------------------
   6. Footer
   -------------------------------------------------------------------------- */
.footer {
  background: var(--color-primary);
  color: #FFFFFF;
  padding: var(--space-2xl) 0 var(--space-lg);
  margin-top: var(--space-2xl);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.footer-col h3 {
  font-size: 20px;
  margin-bottom: var(--space-md);
  color: #FFFFFF;
}

.footer-col h4 {
  font-size: 16px;
  margin-bottom: var(--space-md);
  color: #C4D6C8;
}

.footer-col p {
  font-size: 14px;
  line-height: 1.8;
  color: #A8C0AE;
}

.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-links a {
  color: #A8C0AE;
  text-decoration: none;
  font-size: 14px;
}

.footer-links a:hover {
  color: #FFFFFF;
}

.footer-bottom {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid rgba(196, 214, 200, 0.2);
  padding-top: var(--space-lg);
  text-align: center;
}

.footer-bottom p {
  font-size: 13px;
  color: #8A9A8A;
}

@media (max-width: 768px) {
  .footer-grid {
    grid-template-columns: 1fr;
    text-align: center;
  }
}

/* --------------------------------------------------------------------------
   7. Full-Page Preloader
   -------------------------------------------------------------------------- */
.full-page-preloader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.preloader-content {
  text-align: center;
}

.preloader-logo {
  width: 120px;
  height: auto;
  margin-bottom: 20px;
  animation: preloaderPulse 1.5s ease-in-out infinite;
}

.preloader-text {
  font-family: "Vazirmatn", sans-serif;
  font-size: 18px;
  color: var(--color-text-light, #333);
  margin: 0;
}

@media (max-width: 768px) {
  .preloader-logo {
    width: 90px;
  }
  .preloader-text {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .preloader-logo {
    width: 70px;
  }
  .preloader-text {
    font-size: 14px;
  }
}

/* --------------------------------------------------------------------------
   8. Reader Component (Generic chapter/book reader)
   -------------------------------------------------------------------------- */
.reader-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
  direction: rtl;
}

.reader-content {
  font-size: 18px;
  line-height: 2;
  unicode-bidi: plaintext;
  color: var(--color-text);
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
}

/* --------------------------------------------------------------------------
  *  9. Book Reader Content Styles
  *  Uses CSS custom properties so the typography panel can override them.
  *  Defaults match Vazirmatn at 18px with 2.2 line-height.
  *  -------------------------------------------------------------------------- */

.book-content {
  direction: rtl;
  text-align: right;
  font-family: var(--reader-font-family, "Vazirmatn", sans-serif);
  line-height: var(--reader-line-height, 2.2);
  font-size: var(--reader-font-size, 18px);
  max-width: 700px;
  margin: auto;
  unicode-bidi: plaintext;
}

.book-paragraph {
  margin-bottom: 1.4rem;
}

.book-heading {
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   10. Toast Notification System
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
  overflow: hidden;
  position: relative;
  direction: rtl;
  font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.toast-success { border-right: 4px solid #28a745; }
.toast-error   { border-right: 4px solid #dc3545; }
.toast-warning { border-right: 4px solid #ffc107; }
.toast-info    { border-right: 4px solid #17a2b8; }

.toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 14px;
  font-weight: bold;
  flex-shrink: 0;
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #212529;
  margin-bottom: 4px;
}

.toast-message {
  font-size: 13px;
  color: #495057;
  line-height: 1.5;
  word-wrap: break-word;
}

.toast-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #6c757d;
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.toast-close:hover {
  background-color: #f8f9fa;
  color: #212529;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background-color: rgba(0, 0, 0, 0.1);
}

.toast-progress-fill {
  height: 100%;
  transition: width 0.1s linear;
}

.toast-success .toast-progress-fill { background-color: #28a745; }
.toast-error   .toast-progress-fill { background-color: #dc3545; }
.toast-warning .toast-progress-fill { background-color: #ffc107; }
.toast-info    .toast-progress-fill { background-color: #17a2b8; }

/* Toast positions */
.toast-container.toast-top-right    { top: 20px; right: 20px; left: auto; }
.toast-container.toast-top-left     { top: 20px; left: 20px; right: auto; }
.toast-container.toast-top-center   { top: 20px; left: 50%; transform: translateX(-50%); }
.toast-container.toast-bottom-right { top: auto; bottom: 20px; right: 20px; left: auto; }
.toast-container.toast-bottom-left  { top: auto; bottom: 20px; left: 20px; right: auto; }
.toast-container.toast-bottom-center{ top: auto; bottom: 20px; left: 50%; transform: translateX(-50%); }

/* Admin panel toast offset */
.admin-content .toast-container {
  top: 80px;
}

@media (max-width: 480px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
  .toast { padding: 12px; }
  .toast-title { font-size: 13px; }
  .toast-message { font-size: 12px; }
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: #2d2d2d;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
  .toast-title { color: #f8f9fa; }
  .toast-message { color: #adb5bd; }
  .toast-close { color: #6c757d; }
  .toast-close:hover { background-color: #3d3d3d; color: #f8f9fa; }
}

/* --------------------------------------------------------------------------
   11. Modal
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 0;
  max-width: 440px;
  width: 90%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #f5f5f5;
  color: #333;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.modal-tab {
  flex: 1;
  padding: 16px;
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: #999;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.modal-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.modal-tab:hover:not(.active) {
  color: #666;
  background: #f9f9f9;
}

.modal-body {
  padding: var(--space-lg);
}

.modal-form {
  display: none;
}

.modal-form.active {
  display: block;
}

.modal-form .form-group {
  margin-bottom: 16px;
}

.modal-form .form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
}

.modal-form .form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
}

.modal-form .form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(42, 53, 42, 0.1);
}
