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

:root {
  --bg: #0a0a0a;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --bg-surface: #141414;
  --border: #2a2a2a;
  --border-light: #333;
  --text: #e5e5e5;
  --text-muted: #888;
  --text-dim: #555;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: rgba(124, 58, 237, 0.15);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --score-green: #22c55e;
  --score-yellow: #eab308;
  --score-red: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --header-height: 60px;
  --sidebar-width: 280px;
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-light);
  background: var(--bg-card);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
}
.btn-full {
  width: 100%;
  justify-content: center;
}
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: all 0.15s ease;
}
.btn-icon:hover {
  color: var(--text);
  background: var(--bg-card);
}

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-container {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}
.login-header {
  text-align: center;
  margin-bottom: 2rem;
}
.login-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.login-subtitle {
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-size: 0.9rem;
}
.input-group {
  margin-bottom: 1.2rem;
}
.input-group input,
.filter-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: border-color 0.15s ease;
}
.input-group input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--accent);
}
.error-text {
  color: var(--score-red);
  text-align: center;
  font-size: 0.85rem;
  margin-top: 0.8rem;
}

/* === Gallery Page Layout === */
.gallery-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}
.header-center {
  flex: 1;
  max-width: 480px;
  margin: 0 1.5rem;
}
.search-box {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
}
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stats-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.sidebar.open {
  transform: translateX(0);
}
.sidebar-content {
  padding: 1.2rem;
}
.sidebar-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}
.filter-group {
  margin-bottom: 1.2rem;
}
.filter-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-select {
  padding: 8px 10px;
  font-size: 0.85rem;
}
.range-inputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
.range-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.tags-filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.tag-chip {
  padding: 3px 10px;
  font-size: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tag-chip:hover,
.tag-chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* Main Content */
.main-content {
  margin-top: var(--header-height);
  padding: 1.5rem;
  transition: margin-left 0.25s ease;
}
.sidebar.open ~ .main-content {
  margin-left: var(--sidebar-width);
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

/* Image Card */
.image-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
}
.image-card:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.card-image-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #111;
}
.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.image-card:hover .card-image-wrap img {
  transform: scale(1.05);
}
.card-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.card-body {
  padding: 0.8rem;
}
.card-prompt {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* Badges */
.brand-badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.score-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 20px;
  color: #fff;
}
.score-green { background: var(--score-green); }
.score-yellow { background: var(--score-yellow); color: #000; }
.score-red { background: var(--score-red); }

.version-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-dim);
  gap: 1rem;
}
.empty-state p {
  font-size: 1rem;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 0 1rem;
}
.page-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* === Detail Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 1100px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  z-index: 10;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.modal-close:hover {
  color: var(--text);
  background: var(--bg);
}

.detail-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 400px;
}
.detail-image-wrap {
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
}
.detail-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 80vh;
}
.detail-info {
  padding: 1.5rem;
  overflow-y: auto;
}
.detail-header {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.detail-section {
  margin-bottom: 1rem;
}
.detail-section h4 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.3rem;
}
.detail-prompt-text {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-notes-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.detail-tag {
  padding: 2px 10px;
  font-size: 0.75rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  border: 1px solid transparent;
}
.detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Genealogy */
.genealogy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.genealogy-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.8rem;
}
.genealogy-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.genealogy-item img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
}
.genealogy-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .header-center {
    display: none;
  }
  .sidebar {
    width: 100%;
  }
  .sidebar.open ~ .main-content {
    margin-left: 0;
  }
  .main-content {
    padding: 1rem;
  }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
  }
  .detail-layout {
    grid-template-columns: 1fr;
  }
  .detail-image-wrap {
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 50vh;
  }
  .detail-image-wrap img {
    max-height: 50vh;
  }
  .stats-badge {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Smooth transitions for sidebar toggle */
.main-content,
.sidebar {
  will-change: transform, margin-left;
}
