:root {
  --bg: #0f1114;
  --surface: #1a1d23;
  --surface2: #242830;
  --border: #2e3440;
  --text: #e8eaed;
  --text-muted: #9aa0a8;
  --accent: #c9a962;
  --accent-hover: #dfc07a;
  --accent-dim: rgba(201, 169, 98, 0.15);
  --danger: #e57373;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.15rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex: 1;
  max-width: 520px;
  justify-content: flex-end;
}

.search-box {
  flex: 1;
  min-width: 200px;
}

.search-box input {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Layout */
.layout {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  min-height: calc(100vh - 80px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  position: sticky;
  top: 80px;
  height: fit-content;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.sidebar-toggle {
  display: none;
  flex-shrink: 0;
}

.sidebar h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 1.25rem;
  margin-bottom: 0.75rem;
}

.section-filter {
  width: calc(100% - 2.5rem);
  margin: 0 1.25rem 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.section-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-hint {
  padding: 0.5rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toolbar-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.breadcrumb {
  font-size: 1.1rem;
  font-weight: 600;
}

.group-nav {
  display: flex;
  flex-direction: column;
}

.group-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.group-link:hover {
  background: var(--surface2);
}

.group-link.active {
  background: var(--accent-dim);
  border-left-color: var(--accent);
  color: var(--accent-hover);
}

.group-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.main {
  padding: 1.25rem 1.5rem 2rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.result-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.view-controls select {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.card-image {
  position: relative;
  overflow: hidden;
  background: var(--surface2);
  width: 100%;
  /* Надёжная высота превью: aspect-ratio + min-height (старые мобильные браузеры). */
  aspect-ratio: 4 / 3;
  min-height: 140px;
}

.card-image img,
.card-image .no-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.card-image img {
  object-fit: cover;
  display: block;
}

.card-image .no-image {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

.card-badges {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  z-index: 1;
}

.badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}

.badge-accent {
  background: var(--accent);
  color: #1a1d23;
  font-weight: 600;
}

.card-body {
  padding: 0.85rem 1rem 1rem;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #1a1d23;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1d23;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(1100px, 96vw);
  width: 100%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
}

.modal-close:hover {
  background: var(--border);
}

.detail-header {
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  font-size: 1.35rem;
  padding-right: 2.5rem;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.tag {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  background: var(--accent-dim);
  color: var(--accent-hover);
  border-radius: 6px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.detail-gallery {
  padding: 1rem 1.5rem;
}

.detail-gallery h3,
.detail-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  aspect-ratio: 1;
  background: var(--surface2);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item:hover {
  border-color: var(--accent);
}

.lightbox-img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  background: #000;
  border-radius: 8px;
}

.detail-section {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.variant-block {
  background: var(--surface2);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.variant-block h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.file-list {
  list-style: none;
}

.file-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  gap: 0.5rem;
}

.file-list li:last-child {
  border-bottom: none;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.file-size {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.card.loading-skeleton .card-image {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ——— Мобильная версия ——— */
@media (max-width: 768px) {
  .header-inner {
    padding: 0.75rem 1rem;
  }

  .brand h1 {
    font-size: 1.15rem;
  }

  .header-actions {
    width: 100%;
    max-width: none;
    order: 3;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .search-box {
    min-width: 0;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
    position: static;
    top: auto;
    max-height: none;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0 1rem;
  }

  .sidebar.is-open {
    display: block;
  }

  .main {
    padding: 1rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .card-image {
    min-height: 120px;
  }

  .card-body {
    padding: 0.65rem 0.75rem 0.75rem;
  }

  .card-title {
    font-size: 0.85rem;
    -webkit-line-clamp: 3;
  }

  .card-meta {
    font-size: 0.72rem;
  }

  .card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border);
  }

  .card:active {
    border-color: var(--accent);
    opacity: 0.95;
  }

  .modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
  }

  .modal-content {
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    min-height: 100%;
  }

  .modal-close {
    top: max(0.5rem, env(safe-area-inset-top));
    right: 0.5rem;
    width: 44px;
    height: 44px;
  }

  .detail-header {
    padding: 1rem 1rem 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .detail-gallery,
  .detail-section {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .lightbox-img {
    max-height: 50vh;
    max-height: 50dvh;
  }

  .file-list li {
    flex-wrap: wrap;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .card-image {
    min-height: 180px;
  }
}
