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

:root {
  --bg: #111;
  --bg-card: #1a1a1a;
  --bg-sidebar: #161616;
  --bg-hover: #222;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #4a9eff;
  --accent-hover: #6db3ff;
  --gold: #d4a017;
  --gold-hover: #e8b42e;
  --green: #2ecc71;
  --red: #e74c3c;
  --selected-border: #4a9eff;
  --hero-border: #d4a017;
  --radius: 8px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }

.app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #222;
}
.sidebar-header { padding: 16px; border-bottom: 1px solid #222; }
.sidebar-header h1 { font-size: 18px; font-weight: 700; }
.sidebar-header .subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.global-stats { margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.global-stats .warn-text { display: block; color: var(--red); margin-top: 2px; }
.section-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.section-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent; transition: background 0.15s;
}
.section-item:hover { background: var(--bg-hover); }
.section-item.active { background: var(--bg-hover); border-left-color: var(--accent); }
.section-item.has-warning .section-name { color: var(--red); }
.section-name { flex: 1; line-height: 1.3; }
.section-count {
  font-size: 11px; color: var(--text-dim); background: #222;
  padding: 2px 6px; border-radius: 10px; margin-left: 8px; white-space: nowrap;
}
.sidebar-actions { padding: 12px 16px; border-top: 1px solid #222; }

/* Main content */
.main { flex: 1; overflow-y: auto; padding: 24px; }
.loading { text-align: center; color: var(--text-dim); padding: 60px 0; }
.main-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.main-header h2 { font-size: 20px; font-weight: 600; }
.section-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.main-toolbar { display: flex; gap: 8px; }

/* Photo grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.photo-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.photo-card:hover { transform: translateY(-2px); border-color: #333; }
.photo-card.selected { border-color: var(--selected-border); }
.photo-card.hero { border-color: var(--hero-border); }

.thumb-wrap {
  aspect-ratio: 1;
  overflow: hidden;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}
.photo-card:hover .thumb-wrap img { transform: scale(1.05); }

.select-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.15s;
}
.photo-card:hover .select-indicator,
.photo-card.selected .select-indicator { opacity: 1; }
.select-indicator .check { color: transparent; font-size: 14px; font-weight: bold; }
.photo-card.selected .select-indicator { background: var(--accent); border-color: var(--accent); }
.photo-card.selected .select-indicator .check { color: #fff; }

.photo-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
}
.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-hero { background: var(--gold); color: #000; }
.badge-source { background: rgba(0,0,0,0.6); color: #ccc; }
.badge-camera { color: #8be9fd; }
.badge-phone { color: #bd93f9; }
.badge-drone { color: #50fa7b; }

.card-actions {
  position: absolute;
  bottom: 50px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.photo-card:hover .card-actions { opacity: 1; }
.card-btn {
  font-size: 11px;
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.card-btn:hover { background: var(--accent); }
.hero-btn:hover { background: var(--gold); color: #000; }

.photo-info { padding: 8px 10px; }
.photo-name { display: block; font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-meta { display: block; font-size: 10px; color: #555; margin-top: 2px; }

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #333; color: var(--text); }
.btn-secondary:hover { background: #444; }
.btn-gold { background: var(--gold); color: #000; }
.btn-gold:hover { background: var(--gold-hover); }

/* Lightbox */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.lightbox-overlay.active { display: flex; }
.lightbox-inner {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox-inner img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 8px 16px;
  background: rgba(30,30,30,0.9);
  border-radius: var(--radius);
}
.lb-filename { font-size: 13px; color: var(--text); }
.lb-meta { font-size: 12px; color: var(--text-dim); }
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  z-index: 1001;
}
.lightbox-prev, .lightbox-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  font-size: 40px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius);
  z-index: 1001;
}
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-prev:hover, .lightbox-next:hover { background: rgba(0,0,0,0.8); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 900;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
  background: #1e1e1e;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h3 { margin-bottom: 12px; }
.modal-content pre {
  background: #0a0a0a;
  padding: 12px;
  border-radius: 4px;
  font-size: 11px;
  max-height: 300px;
  overflow: auto;
  margin: 12px 0;
}
.manifest-summary { font-size: 13px; color: var(--text-dim); margin: 8px 0; }
.manifest-summary div { padding: 2px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; }
.toast {
  background: #333;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  margin-top: 8px;
  font-size: 13px;
  transition: opacity 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.success { background: #27ae60; }
.toast.error { background: var(--red); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 200px; min-width: 200px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
