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

:root {
  --bg: #0b1120;
  --panel: #111827;
  --card: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --accent: #7c3aed;
  --warn: #f59e0b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
}

.brand h1 {
  font-size: 16px;
  font-weight: 700;
}

.badge-local {
  font-size: 11px;
  color: #86efac;
}

.locale-select {
  margin-top: 6px;
  width: 145px;
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
}

.upload-card {
  background: var(--card);
  border: 1.5px dashed #475569;
  border-radius: 11px;
  padding: 12px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.upload-card.dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.14);
}

.upload-title {
  font-weight: 600;
  font-size: 13px;
}

.upload-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin: 3px 0 9px;
}

.upload-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.upload-status {
  margin-top: 7px;
  font-size: 11.5px;
  color: #93c5fd;
  min-height: 16px;
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.book-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.book-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.book-card:hover {
  border-color: #60a5fa;
}

.book-card.active {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.16);
}

.book-card-title {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-meta {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-warn {
  color: #fbbf24;
  font-weight: 600;
}

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

.main {
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 520px;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--text);
  margin-bottom: 10px;
  font-size: 20px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
}

.hidden {
  display: none !important;
}

.book-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.book-title-wrap {
  flex: 1;
}

.book-title-input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  padding: 3px 6px;
  margin-left: -6px;
  border-radius: 6px;
}

.book-title-input:hover,
.book-title-input:focus {
  border-color: var(--border);
  background: var(--panel);
  outline: none;
}

.book-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
}

.panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 11.5px;
  color: var(--muted);
}

.control-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding-bottom: 6px;
  font-size: 12.5px;
}

.control-checks label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.ocr-buttons {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  background: #0f172a;
  color: var(--text);
  border: 1px solid #475569;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12.5px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-secondary { background: #334155; color: #f1f5f9; }
.btn-secondary:hover:not(:disabled) { background: #475569; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #6d28d9; }

.btn-ghost-danger {
  background: transparent;
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.35);
}
.btn-ghost-danger:hover { background: rgba(220, 38, 38, 0.16); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}

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

.progress-bar {
  height: 8px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #22c55e);
  transition: width 0.2s;
}

.progress-text {
  margin-top: 5px;
  font-size: 12px;
  color: #93c5fd;
}

.quality-details {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.quality-details summary {
  cursor: pointer;
  font-size: 12.5px;
  color: #c4b5fd;
  font-weight: 600;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.quality-actions {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.export-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.export-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pdf-group {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

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

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 12px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--card);
  color: var(--text);
}

.tab-filter {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 12px;
  padding-bottom: 24px;
}

.page-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-card.flagged {
  border-color: var(--warn);
}

.page-thumb {
  height: 210px;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-epub-preview {
  padding: 12px;
  font-size: 11.5px;
  color: #cbd5e1;
  overflow: hidden;
  height: 100%;
  width: 100%;
  text-align: left;
  white-space: pre-wrap;
}

.page-foot {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px solid var(--border);
}

.page-foot-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.badge-conf {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-ok { background: rgba(22, 163, 74, 0.2); color: #86efac; }
.badge-warn { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge-none { background: rgba(148, 163, 184, 0.16); color: #94a3b8; }

.page-snippet {
  font-size: 11px;
  color: var(--muted);
  height: 30px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.page-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
}

.mini-btn {
  background: none;
  border: none;
  color: #60a5fa;
  font-size: 11.5px;
  cursor: pointer;
}

.mini-btn.del { color: #f87171; }
.mini-btn:hover { text-decoration: underline; }

.text-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 420px;
}

.text-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
}

.toast {
  color: #86efac;
  font-weight: 600;
}

#combinedText {
  flex: 1;
  width: 100%;
  min-height: 460px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  width: min(1160px, 96vw);
  height: min(86vh, 840px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.modal-img-wrap {
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--border);
}

.modal-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.modal-text-wrap {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
}

.modal-meta {
  font-size: 12px;
  color: var(--muted);
}

#modalTextarea {
  flex: 1;
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  resize: none;
}
