/* Design Tokens & Theme Primitives - Dark Wood & Parchment Sans-Serif Theme */
:root {
  --bg-dark: #0f1117;
  --bg-surface: #1a1d27;
  --bg-card: #232736;
  --primary-gold: #e5b968;
  --primary-gold-hover: #f3cc83;
  --accent-cyan: #38bdf8;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border-color: rgba(255, 255, 255, 0.1);
  --font-sans: 'Rubik', 'Heebo', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.45);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  direction: rtl;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navigation Bar */
.navbar {
  background: rgba(26, 29, 39, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.8rem;
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary-gold);
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Buttons System */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-gold), #c49945);
  color: #000;
  font-weight: 600;
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-sans);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-gold-hover), var(--primary-gold));
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(229, 185, 104, 0.3);
}

.btn-icon-text {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-icon-text:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-gold);
}

/* Main Container Layout */
.main-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2.5rem 2.5rem;
  width: 100%;
  flex: 1;
}

/* Site Footer */
.site-footer {
  text-align: center;
  padding: 1.2rem 0;
  margin-top: 2.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.88rem;
  color: var(--text-muted);
  width: 100%;
  background: rgba(26, 29, 39, 0.4);
}

.site-footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 2.5rem 0 6rem;
  flex-wrap: wrap;
  gap: 1.2rem;
}

/* Featured Hero Section */
.hero-featured {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  margin-bottom: 3rem;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2.5rem;
  align-items: start;
  box-shadow: var(--shadow-lg);
}

.hero-featured .cover-wrapper {
  margin-top: 2.8rem;
}

.featured-badge {
  display: inline-block;
  background: rgba(229, 185, 104, 0.15);
  color: var(--primary-gold);
  border: 1px solid rgba(229, 185, 104, 0.3);
  padding: 0.3rem 0.8rem;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.hero-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
  line-height: 1.25;
}

.hero-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.2rem;
}

.hero-title-group {
  flex: 1;
}

.hero-header-row .hero-title {
  margin-bottom: 0.3rem;
}

.hero-header-row .hero-author {
  margin-bottom: 0;
}

.hero-purchase-btn {
  white-space: nowrap;
  font-size: 0.95rem;
  padding: 0.65rem 1.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(229, 185, 104, 0.25);
  margin-inline-start: 1rem;
}

@media (max-width: 768px) {
  .hero-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }
  .hero-purchase-btn {
    width: 100%;
    justify-content: center;
    margin-inline-start: 0;
    margin-top: 0.4rem;
  }
}

.hero-summary {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 1.8rem;
  line-height: 1.7;
}

.hero-summary p,
.hero-summary span,
.hero-summary div {
  color: inherit !important;
  background: transparent !important;
  background-color: transparent !important;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}


/* Cover Styling */
.cover-wrapper {
  aspect-ratio: 2/3;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  background: #000;
}

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

/* Section Titles */
.section-header {
  margin-bottom: 1.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-gold);
}

/* Books Grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.8rem;
}

.book-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  transition: all 0.25 ease;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.book-card:hover {
  transform: translateY(-6px);
  border-color: var(--primary-gold);
  box-shadow: var(--shadow-lg);
}

.book-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.3rem;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-author {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.book-card-actions {
  margin-top: auto;
  display: flex;
  gap: 0.5rem;
}

/* Floating Librarian Chat Drawer */
.chat-drawer {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  width: 450px;
  max-width: calc(100vw - 2.5rem);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(229, 185, 104, 0.15);
  z-index: 1001;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s ease;
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transform-origin: bottom left;
}

.chat-drawer.collapsed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(20px) scale(0.9);
}

.chat-header {
  padding: 0.9rem 1.2rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.chat-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.chat-close-btn:hover {
  color: var(--primary-gold);
  background: rgba(255, 255, 255, 0.08);
}

/* Floating Action Button (FAB) */
.chat-fab {
  position: fixed;
  bottom: 1.8rem;
  left: 1.8rem;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-gold), #c49945);
  color: #000;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 18px rgba(229, 185, 104, 0.35);
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease, opacity 0.25s ease, visibility 0.25s ease;
}

.chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), 0 0 25px rgba(229, 185, 104, 0.6);
}

.chat-fab.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.6);
}

.chat-fab .fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--bg-card);
  color: var(--primary-gold);
  border: 1px solid var(--primary-gold);
  font-size: 0.72rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.librarian-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.librarian-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(229, 185, 104, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.librarian-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-gold);
}

.active-book-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-body {
  height: 360px;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.chat-message {
  max-width: 85%;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.5;
}

.chat-message.user {
  background: var(--primary-gold);
  color: #000;
  align-self: flex-start;
  font-weight: 500;
}

.chat-message.librarian {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  align-self: flex-end;
}

.chat-footer {
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  outline: none;
}

.chat-input:focus {
  border-color: var(--primary-gold);
}

.chat-send-btn {
  background: var(--primary-gold);
  color: #000;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

.chat-send-btn:hover {
  background: var(--primary-gold-hover);
  transform: scale(1.05);
}

/* EPUB Reader Overlay Modal */
.reader-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.95);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  flex-direction: column;
}

.reader-modal.active {
  display: flex;
}

.reader-toolbar {
  padding: 1rem 2rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reader-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.reader-frame-container {
  flex: 1;
  max-width: 900px;
  margin: 2rem auto;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem;
  overflow-y: auto;
  font-family: var(--font-sans);
}

/* Settings Modal Styles */
.settings-modal-card {
  background: var(--bg-surface);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  width: 94%;
  max-width: 1450px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.settings-row-three-cols {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.2rem;
}

.settings-col {
  flex: 1;
  min-width: 0;
}

.settings-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.settings-footer-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Comprehensive Mobile Responsive Media Queries */
@media (max-width: 768px) {
  .navbar {
    padding: 0.8rem 1rem;
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }

  .brand {
    justify-content: center;
  }

  .brand-title {
    font-size: 1.25rem;
  }

  .brand-icon {
    font-size: 1.5rem;
  }

  .nav-links {
    width: 100%;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .nav-links .btn-primary,
  .nav-links .btn-icon-text {
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    flex: 1;
    text-align: center;
    justify-content: center;
    min-width: 130px;
  }

  .main-container {
    padding: 1.2rem 0.85rem;
  }

  .hero-featured {
    grid-template-columns: 1fr;
    padding: 1.4rem 1rem;
    gap: 1.4rem;
    text-align: center;
  }

  .cover-wrapper {
    max-width: 170px;
    margin: 0 auto;
  }

  .hero-featured .cover-wrapper {
    margin-top: 0;
  }

  .hero-header-row {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
  }

  .hero-title {
    font-size: 1.65rem;
    text-align: center;
  }

  .hero-author {
    font-size: 0.95rem;
  }

  .hero-purchase-btn {
    width: 100%;
    justify-content: center;
    font-size: 0.9rem;
    padding: 0.65rem 1rem;
    margin-inline-start: 0;
    margin-top: 0.4rem;
  }

  .hero-summary {
    font-size: 0.95rem;
    line-height: 1.6;
    text-align: right;
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.6rem;
  }

  .hero-actions button,
  .hero-actions a {
    width: 100%;
    justify-content: center;
    font-size: 0.88rem;
    padding: 0.65rem 1rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1.2rem;
  }

  .section-title {
    font-size: 1.35rem;
  }

  /* Catalog Books Grid: 2 Books per row on Mobile */
  .book-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
  }

  .book-card {
    padding: 0.75rem 0.6rem;
    min-width: 0;
  }

  .book-card .cover-wrapper {
    max-height: 170px;
  }

  .book-card-title {
    font-size: 0.92rem;
    margin-top: 0.5rem;
    margin-bottom: 0.2rem;
  }

  .book-card-author {
    font-size: 0.8rem;
    margin-bottom: 0.6rem;
  }

  .book-card button,
  .book-card a {
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
    width: 100%;
    justify-content: center;
  }

  /* Librarian Chat Drawer on Mobile */
  .chat-drawer {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-left: none;
    border-right: none;
  }

  .chat-header {
    padding: 0.85rem 1rem;
  }

  .chat-fab {
    bottom: 1.2rem;
    left: 1.2rem;
    width: 52px;
    height: 52px;
    font-size: 1.4rem;
  }

  /* Footer on Mobile */
  .site-footer {
    padding: 1.2rem 0 4.5rem 0 !important;
  }

  .site-footer-inner {
    padding: 0 1rem;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }

  #admin-footer-controls {
    width: 100%;
    justify-content: center;
    display: flex;
  }

  /* Responsive Settings Modal on Mobile */
  .settings-modal-card {
    padding: 1.2rem;
    width: 95%;
    max-height: 95vh;
  }

  .settings-footer {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }

  .settings-footer-buttons {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem !important;
    width: 100%;
  }

  .settings-footer button,
  .settings-footer-buttons button {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .settings-row-three-cols {
    flex-direction: column;
    gap: 1rem;
  }

  .settings-col {
    width: 100%;
  }
}

/* WhatsApp Bouncing Dots typing indicator */
.typing-indicator-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  padding: 2px 4px;
}

.typing-indicator-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-muted);
  animation: bounce 1.3s infinite ease-in-out both;
}

.typing-indicator-dots span:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%, 80%, 100% { 
    transform: scale(0);
    opacity: 0.5;
  } 
  40% { 
    transform: scale(1);
    opacity: 1;
  }
}

/* Toast Notification Styling */
.toast-notification {
  position: fixed;
  top: 1.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(18, 14, 36, 0.95);
  border: 1px solid rgba(81, 207, 102, 0.5);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(81, 207, 102, 0.25);
  backdrop-filter: blur(12px);
  padding: 0.9rem 1.6rem;
  border-radius: var(--radius-lg, 12px);
  color: var(--text-primary, #ffffff);
  animation: toastSlideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toastSlideDown {
  from {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}
.toast-fade-out {
  opacity: 0;
  transform: translate(-50%, -20px);
  transition: all 0.5s ease;
}
.toast-icon {
  font-size: 1.5rem;
}
.toast-content {
  display: flex;
  flex-direction: column;
}
.toast-title {
  font-weight: 700;
  color: #51cf66;
  font-size: 0.98rem;
}
.toast-message {
  font-size: 0.85rem;
  color: var(--text-muted, #a0a0b0);
}
.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.3rem;
  margin-inline-start: 0.5rem;
}
