:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #e8e8e8;
  --text-muted: #8b8b9e;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --border: #2a2a4a;
  --radius: 12px;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Navigation */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item svg {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
}

/* Main content */
.app {
  padding-bottom: 70px;
  min-height: 100vh;
}

.view {
  display: none;
  padding: 16px;
}

.view.active {
  display: block;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 12px;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
}

.header .count {
  color: var(--text-muted);
  font-size: 14px;
}

/* Scanner */
.scanner-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.scanner-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 20%;
  border: 2px solid var(--accent);
  border-radius: 8px;
  pointer-events: none;
}

.scanner-overlay.detected {
  border-color: var(--green);
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.4);
}

.scanner-status {
  text-align: center;
  padding: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.scanner-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

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

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

.btn-secondary {
  background: var(--bg-input);
}

.btn-full {
  width: 100%;
}

.btn-sell { background: var(--green); color: #000; }
.btn-keep { background: var(--blue); color: #000; }
.btn-trash { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.book-card {
  display: flex;
  gap: 12px;
  cursor: pointer;
}

.book-cover {
  width: 60px;
  height: 85px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-input);
  flex-shrink: 0;
}

.book-cover-placeholder {
  width: 60px;
  height: 85px;
  border-radius: 6px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 24px;
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-author {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.book-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-sell { background: rgba(74, 222, 128, 0.2); color: var(--green); }
.badge-keep { background: rgba(96, 165, 250, 0.2); color: var(--blue); }
.badge-trash { background: rgba(248, 113, 113, 0.2); color: var(--red); }
.badge-unsorted { background: rgba(251, 191, 36, 0.2); color: var(--yellow); }

/* Category buttons in detail */
.category-selector {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.category-selector .btn {
  flex: 1;
}

/* Search */
.search-bar {
  width: 100%;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
}

.search-bar::placeholder {
  color: var(--text-muted);
}

/* Filters */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
}

/* Stats dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

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

/* Detail view */
.detail-cover {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--bg-card);
  margin-bottom: 16px;
}

.detail-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.detail-row .label {
  color: var(--text-muted);
}

.prices-list {
  margin-top: 12px;
}

.price-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.price-source {
  font-size: 14px;
  font-weight: 500;
}

.price-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
}

.price-value.unavailable {
  color: var(--text-muted);
  font-size: 13px;
}

/* Scan result popup */
.scan-result {
  position: fixed;
  bottom: 70px;
  left: 16px;
  right: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  z-index: 50;
  transform: translateY(120%);
  transition: transform 0.3s ease;
}

.scan-result.show {
  transform: translateY(0);
}

/* Forms */
.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

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

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  transition: transform 0.3s ease;
  font-size: 14px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty p {
  font-size: 15px;
}

/* Photo gallery */
.photo-gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.photo-item {
  flex-shrink: 0;
  width: 100px;
  text-align: center;
}

.photo-item img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-input);
}

.photo-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.photo-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Vision preview */
.vision-preview h3 {
  font-size: 16px;
  font-weight: 600;
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
