:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --warning: #ca8a04;
  --danger: #dc2626;
  --bg: #f4f4f5;
  --card-bg: #ffffff;
  --text: #18181b;
  --text-muted: #71717a;
  --border: #e4e4e7;
  --radius: 8px;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 100px; /* Space for sticky player */
}

.app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

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

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.nav-tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: var(--radius);
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab-btn:hover {
  background: var(--border);
  color: var(--text);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  font-weight: 600;
}

.input-toggle {
  display: flex;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.toggle-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
  font-weight: 500;
  color: var(--text-muted);
}

.toggle-btn.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.form-section {
  display: none;
}

.form-section.active {
  display: block;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.form-group label {
  font-weight: 500;
  font-size: 0.9rem;
}

input[type="text"], input[type="file"], select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--card-bg);
  color: var(--text);
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-hover); }
.btn-large { width: 100%; padding: 14px; font-size: 1.1rem; }

.hidden { display: none !important; }

/* Progress bar styles */
.progress-box {
  margin: 16px 0;
}

.progress-bar-bg {
  width: 100%;
  height: 12px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width 0.3s ease;
}

.percent-text {
  font-weight: bold;
  text-align: right;
  font-size: 0.9rem;
}

/* Editor preview Stats */
.editor-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: right;
}

.tts-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 20px 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.checkbox-group {
  grid-column: span 2;
  justify-content: center;
}

.checkbox-group label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: normal;
}

.tts-live-stats {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.stat-badge {
  background: var(--bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
}
.stat-badge.success { background: #dcfce7; color: #15803d; }
.stat-badge.warning { background: #fef9c3; color: #a16207; }
.stat-badge.danger { background: #fee2e2; color: #b91c1c; }

/* Library Grid */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.empty-text {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

.book-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.book-info h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
  font-weight: 600;
}

.book-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.book-actions {
  display: flex;
  gap: 8px;
}

/* Chapters layout inside details */
.chapter-list {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  list-style: none;
}

.chapter-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dotted var(--border);
  font-size: 0.9rem;
}

.chapter-controls {
  display: flex;
  gap: 8px;
}

.mini-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.mini-btn:hover {
  background: var(--border);
}

.mini-btn.play {
  background: #dbeafe;
  color: var(--primary);
  border-color: #bfdbfe;
}

/* Floating Audio Player */
.audio-player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  z-index: 100;
}

.player-info {
  display: flex;
  flex-direction: column;
  max-width: 250px;
}

.player-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 500px;
}

.player-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.player-btn:hover {
  background: var(--primary-hover);
}

.player-time-slider {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-time-slider span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

input[type="range"] {
  flex: 1;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.player-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.player-settings select {
  padding: 4px 8px;
  width: auto;
}
