:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-primary: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger-color: #ef4444;
  --reading-color: #6366f1;
  --completed-color: #10b981;
  --want-color: #f59e0b;
}

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

body {
  font-family:
    "Outfit",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  padding: 1.5rem;
  line-height: 1.5;
}

.app-container {
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.back-link {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  display: inline-block;
  margin-bottom: 0.4rem;
  transition: transform 0.2s;
}
.back-link:hover {
  transform: translateX(-4px);
}

.header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #6366f1, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-secondary {
  background: var(--bg-hover);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--border-color);
}
.btn-outline {
  background: var(--bg-dark);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  border-color: var(--accent-primary);
}
.btn-danger {
  background: var(--danger-color);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}
.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.btn-ghost:hover {
  color: var(--text-main);
}

/* ── Export Dropdown ──────────────────────────────────────────── */
.export-dropdown {
  position: relative;
}
.dropdown-content {
  position: absolute;
  right: 0;
  top: 110%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  min-width: 200px;
  z-index: 100;
  overflow: hidden;
}
.dropdown-content[hidden] {
  display: none !important;
}
.dropdown-content button,
.dropdown-file-label {
  background: none;
  border: none;
  color: var(--text-main);
  padding: 0.65rem 1rem;
  text-align: left;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
.dropdown-content button:hover,
.dropdown-file-label:hover {
  background: var(--bg-hover);
}

/* ── Stats Dashboard ──────────────────────────────────────────── */
.stats-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  border-color: var(--accent-primary);
}
.stat-icon {
  font-size: 1.75rem;
  line-height: 1;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: "JetBrains Mono", monospace;
  line-height: 1;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* ── Tabs ─────────────────────────────────────────────────────── */
.tabs-nav {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: -1px;
}
.tab-btn:hover {
  color: var(--text-main);
}
.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}
.tab-panel {
  display: block;
}
.tab-panel[hidden] {
  display: none;
}

/* ── Filter Bar ───────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.filter-group select,
.search-group input {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}
.filter-group select:focus,
.search-group input:focus {
  border-color: var(--accent-primary);
}
.search-group {
  flex: 1;
}
.search-group input {
  width: 100%;
  min-width: 180px;
}

/* ── Books Grid ───────────────────────────────────────────────── */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Book Card ────────────────────────────────────────────────── */
.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition:
    transform 0.2s,
    box-shadow 0.2s,
    border-color 0.2s;
  cursor: pointer;
}
.book-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  border-color: var(--accent-primary);
}

.book-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}
.book-title-group {
  flex: 1;
  min-width: 0;
}
.book-card-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-card-author {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.book-card-actions {
  display: flex;
  gap: 0.4rem;
  opacity: 0;
  transition: opacity 0.2s;
}
.book-card:hover .book-card-actions {
  opacity: 1;
}
.action-btn {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.action-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-primary);
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.badge-reading {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.badge-completed {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-want {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Progress Bar */
.progress-section {
}
.progress-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-dark);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(90deg, #6366f1, #818cf8);
}
.progress-bar-fill.completed {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.book-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.book-card-genre {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
}
.est-date {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
}

/* ── Sessions Panel ───────────────────────────────────────────── */
.sessions-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.panel-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.session-row {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1rem;
  align-items: center;
  transition: border-color 0.2s;
}
.session-row:hover {
  border-color: var(--accent-primary);
}
.session-book-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.session-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.session-pages-badge {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-radius: 8px;
  padding: 0.25rem 0.6rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.session-actions {
  display: flex;
  gap: 0.4rem;
}

/* ── Analytics Panel ──────────────────────────────────────────── */
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.analytics-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
}
.analytics-card.wide {
  grid-column: 1 / -1;
}
.analytics-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-muted);
}
.chart-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 1rem 0;
}

/* Bar Chart */
.bar-chart-container {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 140px;
  padding-bottom: 0.5rem;
  overflow-x: auto;
}
.bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: 48px;
  flex: 1;
}
.bar-column {
  width: 100%;
  background: linear-gradient(to top, #6366f1, #818cf8);
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-height: 4px;
  position: relative;
  cursor: default;
}
.bar-column:hover {
  filter: brightness(1.2);
}
.bar-column::after {
  content: attr(data-value);
  position: absolute;
  top: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
  white-space: nowrap;
}
.bar-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Genre List */
.genre-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.genre-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.genre-name {
  font-size: 0.8rem;
  min-width: 100px;
}
.genre-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg-dark);
  border-radius: 999px;
  overflow: hidden;
}
.genre-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #818cf8);
}
.genre-count {
  font-size: 0.75rem;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-muted);
}

/* Speed Stats */
.speed-stats {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.speed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.speed-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.speed-value {
  font-size: 1.1rem;
  font-weight: 700;
}
.mono {
  font-family: "JetBrains Mono", monospace;
}

/* ── Book Detail Modal Content ────────────────────────────────── */
.detail-progress-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.detail-progress-big {
  font-size: 2.5rem;
  font-weight: 800;
  font-family: "JetBrains Mono", monospace;
}
.detail-progress-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.detail-bar-track {
  width: 100%;
  height: 10px;
  background: var(--bg-dark);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.4rem 0;
}
.detail-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #34d399);
  transition: width 0.6s ease;
}
.detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.detail-meta-item {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
}
.detail-meta-key {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.detail-meta-val {
  font-size: 0.95rem;
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}
.detail-sessions-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.detail-session-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 200px;
  overflow-y: auto;
}
.detail-session-item {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}
.detail-session-date {
  font-family: "JetBrains Mono", monospace;
  color: var(--text-muted);
}
.detail-session-pages {
  color: #818cf8;
  font-weight: 600;
}
.detail-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* ── Empty States ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}
.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}
.empty-state p {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ── Modals ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  max-width: 520px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card-wide {
  max-width: 680px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}
.modal-close {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}
.modal-close:hover {
  color: var(--text-main);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}
.form-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}
.required {
  color: #f43f5e;
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-row {
  display: flex;
  gap: 0.75rem;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}
.footer-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stats-dashboard {
    grid-template-columns: repeat(3, 1fr);
  }
  .books-grid {
    grid-template-columns: 1fr;
  }
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  .analytics-card.wide {
    grid-column: auto;
  }
  .detail-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
  .form-row {
    flex-direction: column;
  }
}
@media (max-width: 480px) {
  body {
    padding: 1rem;
  }
  .header h1 {
    font-size: 1.5rem;
  }
  .stats-dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
  .session-row {
    grid-template-columns: 1fr;
  }
}

/* Alert Container */
.alert-container {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  color: #ef4444;
  font-size: 0.875rem;
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1.5rem;
  line-height: 1.4;
}
.alert-container .alert-icon {
  flex-shrink: 0;
}

/* Accessibility: Respect user's reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  /* Disable modal entry animation — modal still appears */
  .modal-card {
    animation: none !important;
  }

  /* Disable close button color transition */
  .modal-close {
    transition: none !important;
  }
}
