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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242734;
  --border: #2e3244;
  --text: #e4e6f0;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-lg { padding: 12px 32px; font-size: 16px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg { color: var(--error); margin-top: 12px; }
.msg { margin-top: 12px; }

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header h1 { font-size: 20px; }
header nav { display: flex; gap: 8px; align-items: center; }

.tab-btn {
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.tab-content { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* Sign-in */
.signin-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  text-align: center;
}
.signin-container h1 { font-size: 36px; }
.signin-container p { color: var(--text-muted); max-width: 400px; }

/* Setup */
.setup-container {
  max-width: 480px;
  margin: 80px auto;
  padding: 32px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.setup-container h2 { margin-bottom: 8px; }
.setup-container p { color: var(--text-muted); margin-bottom: 24px; }

form label {
  display: block;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-muted);
}
form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
form input:focus { outline: none; border-color: var(--primary); }

/* Library */
.library-controls { margin-bottom: 20px; }
.library-controls select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

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

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.book-card:hover { border-color: var(--primary); }
.book-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-2);
}
.book-card .book-info {
  padding: 10px;
}
.book-card .book-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-card .book-author {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-card .book-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Book Detail */
.book-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-top: 24px;
}
.detail-header {
  display: flex;
  gap: 20px;
  margin: 16px 0;
}
.detail-header img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
}
.detail-header h2 { font-size: 18px; }
.detail-header p { color: var(--text-muted); font-size: 14px; }

.chapter-list {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.chapter-list li {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.chapter-list li:last-child { border-bottom: none; }
.chapter-list .ch-duration { color: var(--text-muted); float: right; }

/* Cards / Sync Dashboard */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge-pending { background: var(--surface-2); color: var(--text-muted); }
.badge-active { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-synced { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--error); }

.progress-bar {
  width: 100%;
  max-width: 150px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}
.progress-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Settings */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.settings-section h3 { margin-bottom: 8px; }
.settings-section p { color: var(--text-muted); font-size: 14px; margin-bottom: 12px; }
.settings-actions { display: flex; gap: 8px; }

.connected-badge {
  color: var(--success) !important;
  font-weight: 600;
}

/* Review badge */
.badge-review { background: rgba(245,158,11,0.15); color: var(--warning); }

/* Review Panel */
.review-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-top: 24px;
}
.review-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.review-panel-header h3 { margin: 0; }
.review-panel-body {
  display: flex;
  gap: 24px;
}
.cover-editor {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.cover-editor img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
}
.review-fields {
  flex: 1;
  min-width: 0;
}
.review-fields label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-muted);
}
.review-fields input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.review-fields input[type="text"]:focus { outline: none; border-color: var(--primary); }
.review-fields h4 { margin: 16px 0 8px; font-size: 14px; color: var(--text-muted); }
.chapter-editor {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.chapter-editor-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.chapter-editor-row:last-child { border-bottom: none; }
.chapter-editor-row .ch-index {
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}
.chapter-editor-row input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.chapter-editor-row input:hover { border-color: var(--border); }
.chapter-editor-row input:focus { outline: none; border-color: var(--primary); background: var(--bg); }
.chapter-editor-row .ch-dur {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.review-panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.ch-icon-select {
  width: 130px;
  flex-shrink: 0;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.ch-icon-select:hover { border-color: var(--border); }
.ch-icon-select:focus { outline: none; border-color: var(--primary); background: var(--bg); }
.ch-icon-select option, .ch-icon-select optgroup { background: var(--surface-2); color: var(--text); }
@media (max-width: 600px) {
  .review-panel-body { flex-direction: column; }
  .ch-icon-select { width: 100px; }
}
