:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
}

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

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

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* ── Header ── */

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 { font-size: 1.25rem; font-weight: 600; }

.stats-bar {
  display: flex;
  gap: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stats-bar span { display: flex; align-items: center; gap: 0.25rem; }

/* ── Tabs ── */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin: 1rem 0;
}

.tab {
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Toolbar ── */

.toolbar { margin-bottom: 1rem; }

.search-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-box input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.search-box button {
  padding: 0.6rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.search-box button:hover { background: var(--primary-dark); }

.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.filters {
  display: flex;
  gap: 0.5rem;
}

.filter-btn {
  padding: 0.4rem 0.875rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 2rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.platform-select {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.8rem;
  background: var(--card);
}

.results-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* ── Grid ── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
}

.card {
  background: var(--card);
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.card-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f1f5f9;
  display: block;
}

.card-body { padding: 0.5rem 0.625rem; }

.card-title {
  font-weight: 500;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.2rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 1rem;
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: uppercase;
  margin-left: 0.25rem;
}

.badge-listed { background: #dcfce7; color: #166534; }
.badge-review { background: #fef3c7; color: #92400e; }

.confidence-bar {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin-top: 0.375rem;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 1px;
}

/* ── Pagination ── */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.375rem;
  margin: 1.5rem 0;
}

.pagination button {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .ellipsis { color: var(--text-muted); font-size: 0.8rem; }

/* ── Modal ── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--card);
  border-radius: 0.75rem;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-body { padding: 1rem; }

.modal-img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #f1f5f9;
  border-radius: 0.375rem;
}

.ai-info {
  display: flex;
  align-items: start;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 0.375rem;
  font-size: 0.8rem;
}

.ai-label {
  background: var(--primary);
  color: white;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  flex-shrink: 0;
}

.detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.75rem;
}

.chip {
  padding: 0.2rem 0.5rem;
  background: #f1f5f9;
  border-radius: 0.25rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.form-group { margin-top: 0.75rem; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.2rem;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.85rem;
  font-family: inherit;
}

.form-group textarea { resize: vertical; min-height: 60px; }
.form-group textarea.readonly { background: #f8fafc; color: var(--text-muted); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.reidentify-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #faf5ff;
  border: 1px solid #e9d5ff;
  border-radius: 0.375rem;
}

.reidentify-bar .label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 0.45rem 0.875rem;
  border-radius: 0.375rem;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.75rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); }

/* ── Locations ── */

.locations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.location-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  cursor: pointer;
}

.location-card:hover { border-color: var(--primary); }

.location-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.location-card h3 { font-size: 0.9rem; margin-bottom: 0.125rem; }
.location-card span { color: var(--text-muted); font-size: 0.8rem; }
.location-notes { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; }

.section-title {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

/* ── Empty state ── */

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

/* ── Header actions ── */

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ── Onboarding (empty state) ── */

.onboarding {
  text-align: center;
  padding: 4rem 2rem;
  max-width: 480px;
  margin: 0 auto;
}

.onboarding-icon { font-size: 3rem; margin-bottom: 1rem; }
.onboarding h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.onboarding p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; line-height: 1.6; }

/* ── Import Wizard ── */

.import-wizard { max-width: 520px; }

.wizard-step { min-height: 200px; }

.wizard-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.wizard-subtitle {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.wizard-summary {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 1rem 0;
}

.summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.summary-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.wizard-subfolders { margin: 0.75rem 0; }

.subfolder-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  margin: 0.5rem 0;
}

.form-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Method selection cards */

.method-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.method-card {
  display: flex;
  align-items: start;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.method-card:hover { border-color: var(--primary); }

.method-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.method-card input[type="radio"] { margin-top: 0.25rem; flex-shrink: 0; }

.method-card strong { display: block; font-size: 0.9rem; margin-bottom: 0.15rem; }

.method-card p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

.method-card code {
  background: rgba(0,0,0,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 0.2rem;
  font-size: 0.7rem;
}

.import-summary {
  margin-top: 1rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.8rem;
}

.import-summary strong { display: block; margin-bottom: 0.375rem; }

.import-summary ul {
  list-style: none;
  padding: 0;
}

.import-summary li {
  color: var(--text-muted);
  padding: 0.1rem 0;
}

.import-summary li::before {
  content: "•";
  color: var(--primary);
  margin-right: 0.5rem;
}

.import-summary code {
  background: rgba(0,0,0,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 0.2rem;
  font-size: 0.75rem;
}

.wizard-error {
  padding: 0.75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 0.375rem;
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.75rem 0;
}

.wizard-success {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 0.5rem;
}

/* ── Progress bar ── */

.progress-container { margin: 1rem 0; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-text {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.progress-current {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  font-size: 0.8rem;
  color: var(--text);
  margin-top: 0.75rem;
}

/* ── Settings ── */

.settings-modal { max-width: 520px; }

.settings-saved {
  text-align: center;
  padding: 0.5rem;
  background: #dcfce7;
  color: #166534;
  border-radius: 0.375rem;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.source-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.source-badge.env {
  background: #fef3c7;
  color: #92400e;
}

.source-badge.db {
  background: #dcfce7;
  color: #166534;
}

/* ── Responsive ── */

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .locations-grid { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; align-items: stretch; }
  .form-row { grid-template-columns: 1fr; }
  .header-row { flex-direction: column; align-items: start; }
}
