/* AllScience — Book Editor */

.book-app { display: flex; flex-direction: column; min-height: 100vh; }

.book-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; height: 48px;
  background: var(--color-bg-secondary, #111827);
  border-bottom: 1px solid var(--color-border, #1e293b);
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-brand {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 700; color: var(--color-text, #e2e8f0);
  text-decoration: none; font-size: 0.9375rem;
}
.book-title-display { font-size: 0.8125rem; color: var(--color-text-muted, #8896ab); font-weight: 500; }
.topbar-nav { display: flex; align-items: center; gap: 0.25rem; margin-left: 1rem; }
.topbar-nav a {
  font-size: 0.75rem; padding: 0.25rem 0.625rem; border-radius: 4px;
  color: var(--color-text-muted, #8896ab); text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.topbar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--color-text, #e2e8f0); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 1; min-width: 0; overflow: hidden; }
.save-status { font-size: 0.75rem; color: var(--color-success, #10b981); white-space: nowrap; }
.word-total { font-size: 0.75rem; color: var(--color-text-dim, #5a6a80); white-space: nowrap; }

/* Layout */
.book-layout {
  display: grid; grid-template-columns: 380px 1fr;
  flex: 1; min-height: 0;
}

/* Sidebar */
.book-sidebar {
  background: var(--color-bg-secondary, #111827);
  border-right: 1px solid var(--color-border, #1e293b);
  overflow-y: auto; padding: 1rem;
}
.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section h4 { font-size: 0.8125rem; color: var(--color-text-muted, #8896ab); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.sidebar-section .form-group { margin-bottom: 0.625rem; }
.sidebar-section .form-input { font-size: 0.8125rem; padding: 0.375rem 0.625rem; }
.sidebar-section .form-select { font-size: 0.8125rem; padding: 0.375rem 0.625rem; }

.chapter-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }

.chapter-list-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.625rem; border-radius: 6px; cursor: pointer;
  font-size: 0.8125rem; color: var(--color-text, #e2e8f0);
  transition: background 0.15s; margin-bottom: 0.25rem;
}
.chapter-list-item:hover { background: rgba(255,255,255,0.04); }
.chapter-list-item.active { background: rgba(59,130,246,0.12); color: var(--color-primary, #3b82f6); }
.chapter-num { font-weight: 600; color: var(--color-text-dim, #5a6a80); min-width: 1.5rem; }
.chapter-item-info { flex: 1; min-width: 0; }
.chapter-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-item-wc { font-size: 0.6875rem; color: var(--color-text-dim, #5a6a80); white-space: nowrap; }
.no-chapters { font-size: 0.8125rem; color: var(--color-text-dim, #5a6a80); padding: 0.5rem; }

/* Drag handle */
.chapter-drag {
  cursor: grab; color: var(--color-text-dim, #5a6a80);
  font-size: 0.75rem; opacity: 0.4; transition: opacity 0.15s;
  user-select: none;
}
.chapter-list-item:hover .chapter-drag { opacity: 1; }
.chapter-list-item.dragging { opacity: 0.5; }
.chapter-list-item.drag-over { border-top: 2px solid var(--color-primary, #3b82f6); }

/* Chapter progress mini bar */
.chapter-progress {
  height: 3px; background: var(--color-border, #1e293b);
  border-radius: 2px; margin-top: 0.25rem; overflow: hidden;
}
.chapter-progress-fill {
  height: 100%; background: var(--color-accent, #06d6a0);
  border-radius: 2px; transition: width 0.3s;
}

/* Chapter actions */
.chapter-actions {
  display: flex; gap: 0.125rem; opacity: 0;
  transition: opacity 0.15s;
}
.chapter-list-item:hover .chapter-actions { opacity: 1; }
.ch-move-btn, .ch-delete-btn {
  background: none; border: none; color: var(--color-text-dim, #5a6a80);
  cursor: pointer; font-size: 0.5rem; padding: 0.125rem; line-height: 1;
  border-radius: 3px; transition: color 0.15s;
}
.ch-move-btn:hover { color: var(--color-primary, #3b82f6); }
.ch-delete-btn:hover { color: var(--color-danger, #ef4444); }

/* Editor */
.chapter-editor {
  display: flex; flex-direction: column; min-height: 0;
}
.editor-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem; text-align: center; color: var(--color-text-muted, #8896ab);
}
.editor-empty h3 { margin-bottom: 0.5rem; color: var(--color-text, #e2e8f0); }

.chapter-edit-area { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chapter-toolbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1.5rem; border-bottom: 1px solid var(--color-border, #1e293b);
}
.chapter-title-input { font-size: 1.125rem; font-weight: 600; border: none; background: transparent; color: var(--color-text, #e2e8f0); flex: 1; }
.chapter-title-input:focus { outline: none; border-bottom: 1px solid var(--color-primary, #3b82f6); }
.chapter-wc { font-size: 0.75rem; color: var(--color-text-dim, #5a6a80); white-space: nowrap; }

.chapter-target-group {
  display: flex; align-items: center; gap: 0.375rem;
}
.chapter-target-group .target-label {
  font-size: 0.6875rem; color: var(--color-text-dim, #5a6a80); white-space: nowrap;
}
.chapter-target-input {
  width: 80px; font-size: 0.75rem; padding: 0.25rem 0.375rem;
  text-align: right;
}
.chapter-progress-wrap {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1.5rem; height: 20px;
}
.chapter-progress-wrap .progress-bar { flex: 1; height: 4px; }
.chapter-progress-label {
  font-size: 0.6875rem; color: var(--color-text-dim, #5a6a80); white-space: nowrap;
}

.chapter-textarea {
  flex: 1; padding: 2rem 3rem; border: none; resize: none;
  background: var(--color-bg, #0a0e17); color: var(--color-text, #e2e8f0);
  font-family: 'Lora', serif; font-size: 1.0625rem; line-height: 2;
}
.chapter-textarea:focus { outline: none; }
.chapter-textarea::placeholder { color: var(--color-text-dim, #5a6a80); }

/* My books list */
.my-book-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  background: var(--color-bg-secondary, #111827);
  border: 1px solid var(--color-border, #1e293b); border-radius: 8px;
  cursor: pointer; transition: border-color 0.15s;
}
.my-book-item:hover { border-color: var(--color-primary, #3b82f6); }
.my-book-title { font-weight: 500; font-size: 0.875rem; }
.my-book-meta { font-size: 0.6875rem; color: var(--color-text-dim, #5a6a80); }

@media (max-width: 768px) {
  .book-layout { grid-template-columns: 1fr; }
  .book-sidebar { border-right: none; border-bottom: 1px solid var(--color-border, #1e293b); max-height: 300px; }
  .chapter-textarea { padding: 1rem; font-size: 1rem; line-height: 1.8; }
  .book-topbar { padding: 0 0.75rem; flex-wrap: wrap; height: auto; min-height: 48px; gap: 0.25rem; }
  .topbar-nav { display: none; }
  .chapter-toolbar { flex-wrap: wrap; padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .chapter-title-input { font-size: 1rem; min-width: 0; }
  .chapter-target-group { width: 100%; }
  .chapter-progress-wrap { padding: 0 0.75rem; }
  .chapter-actions { opacity: 1; }
}

@media (max-width: 480px) {
  .book-sidebar { max-height: 200px; }
  .sidebar-section h4 { font-size: 0.75rem; }
}
