/* ============================================
   BOOKHAVEN - Online Book Store Stylesheet
   ============================================ */

/* ---- CSS Variables / Theme ---- */
:root {
  --primary: #1e3a5f;
  --primary-light: #2d5a87;
  --accent: #e8913a;
  --accent-hover: #d4802e;
  --bg: #f5f3ef;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-light: #666;
  --border: #e0ddd5;
  --success: #2e7d32;
  --danger: #c62828;
  --sidebar: #1e3a5f;
  --sidebar-text: #b8c5d6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 30px rgba(0,0,0,0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: all 0.25s ease;
}

/* ---- Reset & Base ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- App Layout ---- */
.app { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: white;
  position: fixed;
  height: 100vh;
  left: 0; top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  box-shadow: 2px 0 20px rgba(0,0,0,0.1);
}
.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h1 {
  font-size: 22px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: -0.5px;
}
.sidebar-header h1 svg { width: 30px; height: 30px; }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 4px;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: white;
}
.sidebar-nav a svg { width: 20px; height: 20px; opacity: 0.8; flex-shrink: 0; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
  color: var(--sidebar-text);
}

/* ---- Main Content ---- */
.main-content { margin-left: 260px; flex: 1; min-height: 100vh; }

/* ---- Top Bar ---- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  width: 380px;
  max-width: 100%;
  transition: var(--transition);
}
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.08);
}
.search-box input {
  border: none;
  background: transparent;
  padding: 10px 10px;
  outline: none;
  flex: 1;
  font-size: 14px;
  font-family: inherit;
}
.search-box svg { width: 18px; height: 18px; color: var(--text-light); flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.topbar-right button {
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  padding: 6px;
  border-radius: 8px;
  transition: var(--transition);
}
.topbar-right button:hover { background: var(--bg); }
.topbar-right button svg { width: 22px; height: 22px; color: var(--text-light); }
.badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.menu-toggle:hover { background: var(--bg); }
.menu-toggle svg { width: 24px; height: 24px; }

/* ---- Content Area ---- */
.content { padding: 28px; max-width: 1400px; }
.page-title { font-size: 28px; font-weight: 800; margin-bottom: 6px; letter-spacing: -0.5px; }
.page-subtitle { color: var(--text-light); font-size: 14px; margin-bottom: 28px; }

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  border: 1px solid var(--border);
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-value { font-size: 32px; font-weight: 800; margin-bottom: 4px; letter-spacing: -1px; }
.stat-label { font-size: 13px; color: var(--text-light); font-weight: 500; }
.stat-change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ---- Section Headers ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-header h2 { font-size: 18px; font-weight: 700; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }

/* ---- Book Grid ---- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}
.book-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.book-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}
.book-cover {
  aspect-ratio: 2/3;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.book-card:hover .book-cover img { transform: scale(1.05); }
.cover-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}
.cover-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: white;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.cover-author {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  margin-top: 6px;
  font-weight: 500;
}
.book-badge {
  position: absolute;
  top: 10px; left: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.book-badge.bestseller { background: #c62828; color: white; }
.book-badge.new { background: #2e7d32; color: white; }
.book-badge.sale { background: var(--accent); color: white; }

.book-info { padding: 16px; flex: 1; display: flex; flex-direction: column; }
.book-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.book-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.stars { display: flex; gap: 1px; }
.stars svg { width: 14px; height: 14px; fill: #e8913a; }
.review-count { font-size: 12px; color: var(--text-light); }

/* ---- Format Selector (NEW) ---- */
.format-selector {
  margin-bottom: 10px;
}
.format-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.format-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.format-chip {
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text-light);
  transition: var(--transition);
  font-family: inherit;
}
.format-chip:hover { border-color: var(--primary-light); color: var(--primary); }
.format-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.format-chip .fmt-price {
  font-weight: 700;
  margin-left: 3px;
}
.format-chip.unavailable {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Price Display ---- */
.book-price-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}
.book-price {
  font-size: 18px;
  font-weight: 800;
  color: var(--danger);
}
.book-price .old {
  font-size: 13px;
  color: var(--text-light);
  text-decoration: line-through;
  font-weight: 400;
  margin-left: 4px;
}
.book-price .save {
  font-size: 11px;
  color: var(--success);
  font-weight: 600;
  margin-left: 4px;
}

/* ---- Book Actions ---- */
.book-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.book-actions button { flex: 1; justify-content: center; }

/* ---- Tables ---- */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  padding: 14px 18px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(30,58,95,0.02); }

/* ---- Status Badges ---- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status.completed { background: #e8f5e9; color: var(--success); }
.status.completed .status-dot { background: var(--success); }
.status.pending { background: #fff3e0; color: #e65100; }
.status.pending .status-dot { background: #e65100; }
.status.shipped { background: #e3f2fd; color: #1565c0; }
.status.shipped .status-dot { background: #1565c0; }
.status.cancelled { background: #ffebee; color: var(--danger); }
.status.cancelled .status-dot { background: var(--danger); }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: var(--transition);
}
.modal-close:hover { background: var(--bg); }
.modal-close svg { width: 22px; height: 22px; color: var(--text-light); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---- Forms ---- */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--text-light);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: var(--card);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.08);
}
.form-group textarea { min-height: 90px; resize: vertical; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-hint {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

/* ---- Format Editor (NEW) ---- */
.format-editor {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.format-editor-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}
.format-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}
.format-row input,
.format-row select {
  padding: 8px 12px;
  font-size: 13px;
}
.format-row .btn {
  padding: 8px 12px;
  height: fit-content;
}

/* ---- Cart Sidebar ---- */
.cart-overlay-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 140;
  display: none;
  backdrop-filter: blur(2px);
}
.cart-overlay-bg.active { display: block; }
.cart-sidebar {
  position: fixed;
  right: -420px;
  top: 0;
  width: 400px;
  height: 100vh;
  background: var(--card);
  z-index: 150;
  box-shadow: -4px 0 30px rgba(0,0,0,0.12);
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.cart-sidebar.open { right: 0; }
.cart-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cart-header h3 { font-size: 18px; font-weight: 700; }
.cart-items { flex: 1; overflow-y: auto; padding: 16px 24px; }
.cart-item {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item-img {
  width: 52px;
  height: 74px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: white;
  font-weight: 700;
  text-align: center;
  padding: 4px;
  overflow: hidden;
}
.cart-item-img img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item-format { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; }
.cart-item-author { font-size: 11px; color: var(--text-light); margin-bottom: 6px; }
.cart-item-price { font-size: 15px; font-weight: 700; color: var(--danger); }
.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.cart-item-qty button {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.cart-item-qty button:hover { background: var(--border); }
.cart-item-qty span { font-size: 13px; font-weight: 700; min-width: 20px; text-align: center; }
.cart-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}
.cart-footer .btn { width: 100%; justify-content: center; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 14px 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ---- Empty State ---- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.35; }
.empty-state h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 14px; }

/* ---- Page Visibility ---- */
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .search-box { width: 240px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .cart-sidebar { width: 100%; right: -100%; }
  .content { padding: 20px; }
  .form-row { grid-template-columns: 1fr; }
  .format-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .search-box { display: none; }
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .topbar { padding: 12px 16px; }
  .page-title { font-size: 22px; }
  .format-row { grid-template-columns: 1fr; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #ccc; }
