/* ══════════════════════════════════════════
   SAGEECHOES — Complete Stylesheet
   Parchment Light + Sage Dark Theme
   SageSphere Rebrand
══════════════════════════════════════════ */

/* ── LIGHT MODE (Parchment & Sage) ── */
:root {
  --bg-primary: #F7F2E9;
  --bg-secondary: #EDE8DE;
  --bg-card: #E2DDD3;
  --bg-card-hover: #D6D0C5;
  --accent-gold: #8A9A84;
  --accent-warm: #6B7F65;
  --text-primary: #3C3C3C;
  --text-secondary: #5A5A5A;
  --text-muted: #8A8A8A;
  --border: #C4BFB4;
  --shadow: rgba(0,0,0,0.10);
  --font-heading: 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --toggle-bg: #8A9A84;
  --toggle-dot: #F7F2E9;
  --header-border: #8A9A84;
}

/* ── DARK MODE (Deep Charcoal & Sage) ── */
[data-theme="dark"] {
  --bg-primary: #2A2A2A;
  --bg-secondary: #333333;
  --bg-card: #3C3C3C;
  --bg-card-hover: #484848;
  --accent-gold: #8A9A84;
  --accent-warm: #A0B09A;
  --text-primary: #F0EDE8;
  --text-secondary: #B8B4AE;
  --text-muted: #7A7A7A;
  --border: #505050;
  --shadow: rgba(0,0,0,0.4);
  --toggle-bg: #8A9A84;
  --toggle-dot: #2A2A2A;
  --header-border: #8A9A84;
}

/* ── RESET ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── BODY ── */
html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-primary);
  background-image: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

/* ── HEADER ── */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--header-border);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px var(--shadow);
  transition: background 0.3s, border-color 0.3s;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

/* ── ICON ── */
.app-logo {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  max-width: 40px;
  max-height: 40px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.app-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent-gold);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ── THEME TOGGLE ── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
}

.toggle-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.toggle-track {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--toggle-bg);
  position: relative;
  transition: background 0.3s;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.toggle-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--toggle-dot);
  position: absolute;
  top: 2px;
  left: 3px;
  transition: transform 0.3s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

[data-theme="dark"] .toggle-thumb {
  transform: translateX(20px);
}

.toggle-icon { font-size: 14px; line-height: 1; }

/* ── TAB NAVIGATION ── */
.tab-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.83rem;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
}

.tab-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent-gold);
  color: var(--bg-primary);
  border-color: var(--accent-gold);
  font-weight: 600;
}

/* ── MAIN CONTENT ── */
.app-main {
  padding: 24px 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── TAB PANELS ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── SECTION HEADER ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  font-family: var(--font-heading);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--accent-gold);
}

/* ── SEARCH BAR ── */
.search-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 16px;
  border-radius: 24px;
  font-size: 0.9rem;
  width: 260px;
  outline: none;
  transition: border 0.2s;
  font-family: var(--font-body);
}

.search-bar::placeholder { color: var(--text-muted); }
.search-bar:focus { border-color: var(--accent-gold); }

/* ── BOOK GRID ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px;
}

/* ── BOOK CARD ── */
.book-card {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  position: relative;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow);
  border-color: var(--accent-gold);
}

.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}

.book-cover-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-card-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.book-info { padding: 10px; }

.book-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.book-series {
  font-size: 0.72rem;
  color: var(--accent-gold);
  margin-top: 4px;
}

/* ── WISHLIST FADED EFFECT ── */
.wishlist-grid .book-card::after {
  content: '⭐ Wishlist';
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--accent-gold);
  color: var(--bg-primary);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
}

.wishlist-grid .book-cover,
.wishlist-grid .book-cover-placeholder {
  opacity: 0.55;
  filter: sepia(20%);
}

/* ── WISHLIST ACTIONS ── */
.wishlist-actions {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}

.btn-own {
  flex: 1;
  background: var(--accent-gold);
  color: var(--bg-primary);
  border: none;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-own:hover { opacity: 0.8; }

.btn-remove {
  flex: 1;
  background: transparent;
  color: var(--accent-warm);
  border: 1px solid var(--accent-warm);
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-remove:hover {
  background: var(--accent-warm);
  color: var(--bg-primary);
}

/* ── SERIES GRID ── */
.series-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

/* ── SERIES CARD ── */
.series-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  transition: box-shadow 0.2s;
}

.series-card:hover { box-shadow: 0 6px 20px var(--shadow); }

.series-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent-gold);
  margin-bottom: 6px;
}

.series-author {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.series-progress-bar {
  background: var(--bg-secondary);
  border-radius: 10px;
  height: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.series-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-warm));
  border-radius: 10px;
  transition: width 0.4s;
}

.series-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.series-books {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* ── LIBRARY TOOLBAR ── */
.library-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.book-count-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent-gold);
  color: var(--bg-primary);
  border: none;
  padding: 10px 20px;
  border-radius: 24px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: opacity 0.2s;
  display: inline-block;
  text-align: center;
}

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

.btn-secondary {
  background: transparent;
  color: var(--accent-gold);
  border: 1px solid var(--accent-gold);
  padding: 10px 20px;
  border-radius: 24px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: all 0.2s;
  display: inline-block;
  text-align: center;
}

.btn-secondary:hover {
  background: var(--accent-gold);
  color: var(--bg-primary);
}

.btn-disabled {
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.9rem;
  cursor: not-allowed;
}

/* ── IMPORT SECTION ── */
.import-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 30px;
}

.import-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.import-card h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--accent-gold);
  font-size: 1.1rem;
}

.import-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.file-input { display: none; }

/* ── IMPORT SUMMARY ── */
.import-summary {
  background: var(--bg-card);
  border: 2px solid var(--accent-gold);
  border-radius: 14px;
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}

.import-summary h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--accent-gold);
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.import-summary p {
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ── LOG VIEWER ── */
.log-viewer {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  font-family: monospace;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.7;
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ── FLOATING ACTION BUTTON ── */
.fab {
  position: fixed;
  bottom: 28px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-gold);
  color: var(--bg-primary);
  font-size: 1.8rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: transform 0.2s;
}

.fab:hover { transform: scale(1.1); }

/* ── HIDDEN UTILITY ── */
.hidden { display: none !important; }

/* ── BACKUP MODAL ── */
.backup-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s;
  color: var(--text-primary);
}

.backup-btn:hover { background: var(--bg-card); }

.backup-section { display: flex; flex-direction: column; gap: 8px; }

.backup-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.backup-section-desc {
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.backup-last-saved {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.backup-tip {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.backup-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.restore-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ── DIALOG ── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dialog-box {
  background: var(--bg-secondary);
  border: 2px solid var(--accent-gold);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  position: relative;
  z-index: 501;
}

.dialog-title {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--accent-gold);
  font-size: 1.3rem;
}

.dialog-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.dialog-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.dialog-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: var(--font-body);
  outline: none;
  width: 100%;
  transition: border 0.2s;
}

.dialog-input:focus { border-color: var(--accent-gold); }
.dialog-input::placeholder { color: var(--text-muted); }

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.dialog-actions .btn-primary,
.dialog-actions .btn-secondary { flex: 1; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .app-title { font-size: 1.1rem; }
  .search-bar { width: 100%; }
  .section-header { flex-direction: column; align-items: flex-start; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
  .series-grid { grid-template-columns: 1fr; }
  .import-options { grid-template-columns: 1fr; }
  .toggle-label { display: none; }
}
