/* ============================================
   BookWorm — Reading Habit Tracker
   Dark Theme Stylesheet
   ============================================ */

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #1e1e1e;
  --bg-hover: #2a2a2a;
  --bg-input: #252525;
  --border: #333;
  --text-primary: #f0f0f0;
  --text-secondary: #999;
  --text-muted: #666;
  --accent-blue: #4a9eff;
  --accent-green: #4ade80;
  --accent-orange: #fb923c;
  --accent-purple: #a78bfa;
  --accent-red: #f87171;
  --accent-yellow: #facc15;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

button, input, select, a {
  -webkit-app-region: no-drag;
}

.sidebar-header {
  -webkit-app-region: drag;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-top: 40px;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 0 20px 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  list-style: none;
  padding: 0 12px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(74, 158, 255, 0.12);
  color: var(--accent-blue);
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 12px;
  background: rgba(251, 146, 60, 0.1);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(251, 146, 60, 0.2);
}

.fire {
  font-size: 20px;
}

#sidebar-streak {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-orange);
}

.streak-label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Main Content */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 40px 40px 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.view-header h1 {
  font-size: 28px;
  font-weight: 700;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 4px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.stat-card:hover {
  border-color: #444;
  transform: translateY(-2px);
}

.stat-icon {
  font-size: 24px;
  margin-bottom: 12px;
}

.stat-value {
  font-size: 36px;
  font-weight: 800;
  display: block;
  line-height: 1;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  display: block;
  margin-top: 4px;
}

.accent-blue .stat-value { color: var(--accent-blue); }
.accent-green .stat-value { color: var(--accent-green); }
.accent-orange .stat-value { color: var(--accent-orange); }
.accent-purple .stat-value { color: var(--accent-purple); }

.stat-progress {
  margin-top: 12px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.accent-blue .progress-fill { background: var(--accent-blue); }
.accent-green .progress-fill { background: var(--accent-green); }

.progress-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.stat-sub {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-sub strong {
  color: var(--text-primary);
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.chart-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.chart-card.full-width {
  margin-bottom: 24px;
}

/* Book Progress List */
.book-progress-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.book-progress-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.book-progress-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.book-progress-percent {
  font-size: 13px;
  color: var(--accent-blue);
  font-weight: 600;
}

.book-progress-bar {
  height: 8px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
}

.book-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 12px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}

.btn-primary:hover {
  background: #3a8eef;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #333;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 15px;
}

.btn-round {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Library */
.library-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.filter-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}

.filter-btn:hover {
  border-color: #555;
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  transition: var(--transition);
  cursor: pointer;
  position: relative;
}

.book-card:hover {
  border-color: #444;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.book-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.book-genre-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(74, 158, 255, 0.12);
  color: var(--accent-blue);
  font-weight: 500;
}

.book-status-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.status-reading {
  background: rgba(74, 158, 255, 0.12);
  color: var(--accent-blue);
}

.status-to-read {
  background: rgba(250, 204, 21, 0.12);
  color: var(--accent-yellow);
}

.status-completed {
  background: rgba(74, 222, 128, 0.12);
  color: var(--accent-green);
}

.book-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.3;
}

.book-author {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.book-card-progress {
  margin-top: auto;
}

.book-card-progress .progress-bar {
  height: 4px;
  margin-bottom: 6px;
}

.book-card-progress .progress-fill {
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
}

.book-card-progress .progress-text {
  display: flex;
  justify-content: space-between;
}

.book-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* Timer */
.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  max-width: 500px;
  margin: 0 auto;
}

.timer-book-select {
  width: 100%;
}

.timer-book-select label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.timer-book-select select {
  width: 100%;
}

.timer-display {
  position: relative;
}

.timer-circle {
  width: 260px;
  height: 260px;
  position: relative;
}

.timer-circle svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-bg {
  fill: none;
  stroke: var(--bg-hover);
  stroke-width: 8;
}

.timer-progress {
  fill: none;
  stroke: var(--accent-blue);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 1s linear;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

#timer-value {
  font-size: 48px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: block;
}

.timer-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.timer-controls {
  display: flex;
  gap: 16px;
  align-items: center;
}

.timer-log {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.timer-log h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  transition: var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* History */
.history-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.history-stat {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  border: 1px solid var(--border);
}

.history-stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent-blue);
  display: block;
}

.history-stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-book {
  font-weight: 600;
  font-size: 14px;
}

.session-date {
  font-size: 12px;
  color: var(--text-muted);
}

.session-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.session-stat {
  text-align: center;
}

.session-stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-blue);
  display: block;
}

.session-stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* Goals */
.goals-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.goal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.goal-card h3 {
  font-size: 16px;
  margin-bottom: 16px;
}

/* Streak Calendar */
.streak-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.streak-day {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
}

.streak-day.has-session {
  background: var(--accent-green);
  color: #000;
  font-weight: 600;
}

.streak-day.no-session {
  background: var(--bg-hover);
}

.streak-day.future {
  background: transparent;
  border: 1px solid var(--border);
}

.streak-day.today {
  border: 2px solid var(--accent-blue);
}

/* Tips */
.tips-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tip {
  padding: 12px 16px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.tip strong {
  color: var(--text-primary);
}

/* Empty States */
.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.empty-state-large {
  text-align: center;
  padding: 60px 20px;
  grid-column: 1 / -1;
}

.empty-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.empty-state-large h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.empty-state-large p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* Responsive */
@media (max-width: 1000px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-row {
    grid-template-columns: 1fr;
  }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--accent-green);
  color: var(--text-primary);
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s;
  box-shadow: var(--shadow);
}

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

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ============================================
   Web version: sign in, sign out, phone layout
   ============================================ */

#sidebar { padding-top: 24px; }

/* The book picker on Read Now matches the other fields */
.timer-book-select select {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

.sign-out-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
}
.sign-out-link:hover { color: var(--text-primary); }
.sign-out-mobile { display: none; align-self: flex-start; }

.login {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg-primary);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}
.login-card .logo-icon { display: block; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; }
.login-card .subtitle { margin-bottom: 24px; }
.login-card .form-group { text-align: left; }
.login-card .btn { width: 100%; justify-content: center; }
.login-error { min-height: 20px; margin-bottom: 12px; font-size: 13px; color: var(--accent-red); }

@media (max-width: 760px) {
  body { height: 100dvh; }
  #app { flex-direction: column-reverse; height: 100dvh; }

  /* Sidebar becomes a bottom tab bar */
  #sidebar {
    width: 100%;
    padding: 0 0 env(safe-area-inset-bottom);
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .sidebar-header, .sidebar-footer { display: none; }
  .nav-links { display: flex; padding: 0; }
  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 8px 2px;
    margin: 0;
    border-radius: 0;
    font-size: 11px;
  }
  .nav-icon { font-size: 20px; }

  #content { padding: 20px 16px 32px; }
  .view-header { margin-bottom: 20px; gap: 12px; }
  .view-header h1 { font-size: 22px; }
  #view-dashboard .view-header { display: block; }
  .timer-book-select select { font-size: 16px; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 28px; }
  .charts-row { gap: 10px; margin-bottom: 20px; }
  .chart-card { padding: 16px; }
  .book-progress-title { max-width: 60vw; }

  .quick-actions { flex-direction: column; }
  .quick-actions .btn { justify-content: center; }

  .library-filters { overflow-x: auto; }
  .filter-btn { white-space: nowrap; }
  .books-grid { grid-template-columns: 1fr; }

  .timer-circle { width: 220px; height: 220px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }

  /* 16px stops iPhone zooming into fields */
  .form-group input, .form-group select, .form-group textarea { font-size: 16px; }

  .history-stats { gap: 8px; }
  .history-stat { padding: 14px 8px; }
  .history-stat-value { font-size: 24px; }
  .session-item { padding: 12px 14px; gap: 12px; }

  .modal-content { width: calc(100% - 32px); }
  .toast { left: 16px; right: 16px; bottom: 80px; text-align: center; }

  .sign-out-mobile { display: inline-flex; }
}
