/* ============================================================
   BookLister — Design System
   Dark mode · Glassmorphism · Premium feel
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Variables ────────────────────────────────────────────── */
:root {
  --bg-base:        #080b14;
  --bg-card:        rgba(255,255,255,0.04);
  --bg-card-hover:  rgba(255,255,255,0.07);
  --bg-input:       rgba(255,255,255,0.06);
  --bg-sidebar:     rgba(10,14,28,0.95);

  --border:         rgba(255,255,255,0.08);
  --border-focus:   rgba(245,185,60,0.6);

  --accent:         #f5b93c;
  --accent-dim:     rgba(245,185,60,0.15);
  --accent-glow:    rgba(245,185,60,0.25);

  --success:        #34d399;
  --success-dim:    rgba(52,211,153,0.12);
  --error:          #f87171;
  --error-dim:      rgba(248,113,113,0.12);
  --warning:        #fbbf24;
  --warning-dim:    rgba(251,191,36,0.12);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 30px rgba(245,185,60,0.15);

  --sidebar-w: 320px;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ── Background grid ──────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(245,185,60,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245,185,60,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  top: -40%;
  left: 50%;
  transform: translateX(-50%);
  width: 80vw;
  height: 60vh;
  background: radial-gradient(ellipse, rgba(245,185,60,0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ───────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.layout {
  display: flex;
  flex: 1;
  gap: 0;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,11,20,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.header-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #e8951e);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 16px var(--accent-glow);
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

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

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #e8951e);
  color: #1a0a00;
  box-shadow: 0 2px 12px rgba(245,185,60,0.3);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(245,185,60,0.45);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-ghost {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.14);
}

.btn-success {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(52,211,153,0.25);
}
.btn-success:hover:not(:disabled) {
  background: rgba(52,211,153,0.2);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid rgba(248,113,113,0.25);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(248,113,113,0.2);
}

.btn-icon {
  padding: 9px;
  border-radius: var(--radius-sm);
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  backdrop-filter: blur(20px);
}

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

.sidebar-section:last-child { border-bottom: none; }

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── Upload Zone ──────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 24px var(--accent-glow);
}

.upload-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 70%);
  opacity: 0;
  transition: opacity var(--transition);
}
.upload-zone:hover::before,
.upload-zone.dragover::before { opacity: 1; }

.upload-icon {
  font-size: 36px;
  margin-bottom: 10px;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.upload-zone h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

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

#file-input { display: none; }

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.stat-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 500;
}

/* ── Form elements ────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

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

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  transition: all var(--transition);
  resize: none;
  outline: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--border-focus);
  background: rgba(255,255,255,0.07);
  box-shadow: 0 0 0 3px rgba(245,185,60,0.1);
}

.form-textarea { min-height: 100px; resize: vertical; }

.form-select option { background: #1a1f30; }

/* ── Sidebar actions ──────────────────────────────────────── */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  opacity: 0.5;
}

.empty-state-icon { font-size: 64px; margin-bottom: 20px; }
.empty-state h2 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--text-muted); max-width: 340px; }

/* ── Book Card ────────────────────────────────────────────── */
.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
  animation: slideIn 0.35s cubic-bezier(0.4,0,0.2,1);
}

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

.book-card:hover { border-color: rgba(255,255,255,0.12); background: var(--bg-card-hover); }
.book-card.status-processing { border-color: rgba(245,185,60,0.3); }
.book-card.status-success { border-color: rgba(52,211,153,0.25); }
.book-card.status-error { border-color: rgba(248,113,113,0.25); }

/* ── Card Header ──────────────────────────────────────────── */
.card-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.card-thumb {
  width: 68px;
  height: 90px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
}

.card-thumb-placeholder {
  width: 68px;
  height: 90px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.card-meta {
  flex: 1;
  min-width: 0;
}

.card-filename {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 8px;
}

.badge-idle { background: rgba(148,163,184,0.12); color: var(--text-muted); }
.badge-processing { background: var(--warning-dim); color: var(--warning); }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-error { background: var(--error-dim); color: var(--error); }

.badge-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(251,191,36,0.3);
  border-top-color: var(--warning);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.card-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.card-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #e8951e);
  border-radius: 2px;
  transition: width 0.5s ease;
  position: relative;
}

.card-progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4));
  animation: shimmer 1.5s ease infinite;
}

@keyframes shimmer {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.card-remove {
  padding: 6px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  transition: all var(--transition);
}
.card-remove:hover { background: var(--error-dim); color: var(--error); }

/* ── Card Body (result) ───────────────────────────────────── */
.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-full { grid-column: 1 / -1; }

.field-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field-input,
.field-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  transition: all var(--transition);
  resize: vertical;
  outline: none;
}

.field-input:focus,
.field-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(245,185,60,0.1);
  background: rgba(255,255,255,0.07);
}

.field-textarea { min-height: 80px; }

.card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ── Preview panel ────────────────────────────────────────── */
.preview-panel {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.preview-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.preview-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.preview-text {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Inter', monospace;
}

/* ── OCR raw text ─────────────────────────────────────────── */
.ocr-raw {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Error message ────────────────────────────────────────── */
.error-msg {
  background: var(--error-dim);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--error);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* ── Toast notifications ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(30,35,55,0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(20px);
  animation: toastIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 340px;
}

.toast.toast-success { border-color: rgba(52,211,153,0.3); }
.toast.toast-error { border-color: rgba(248,113,113,0.3); }
.toast.toast-fade { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(30px) scale(0.95); }
}

/* ── Section heading ──────────────────────────────────────── */
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ── Collapsible ocr details ──────────────────────────────── */
details > summary {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
}
details > summary::before { content: '▶'; font-size: 9px; transition: transform 0.2s; }
details[open] > summary::before { transform: rotate(90deg); }
details > summary::-webkit-details-marker { display: none; }

/* ── Search hint ──────────────────────────────────────────── */
.search-hint {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
}

.candidate-box {
  background: rgba(245,185,60,0.08);
  border: 1px solid rgba(245,185,60,0.25);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.candidate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .main-content { padding: 16px; }
  .card-fields { grid-template-columns: 1fr; }
}

/* ── Toggle switch ────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.toggle-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.toggle {
  width: 38px;
  height: 22px;
  background: var(--border);
  border-radius: 100px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  outline: none;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle.on::after { transform: translateX(16px); }
