:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1e21;
  --text-muted: #65676b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --border: #e4e6eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Шапка ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

/* Пошук альбомів */
.search-box {
  position: relative;
  width: min(60vw, 420px);
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  font-size: .95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.search-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: auto;
  right: 0;
  /* На вузьких екранах панель ширша за поле вводу */
  width: min(90vw, 420px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  max-height: min(60vh, 420px);
  overflow-y: auto;
  z-index: 20;
}

.search-results li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1.35;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.search-results li .qty {
  color: var(--text-muted);
  font-size: .8rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.search-results li:hover,
.search-results li.active {
  background: #eef3fe;
}

.search-results li.empty {
  color: var(--text-muted);
  cursor: default;
}

.search-results li.empty:hover { background: none; }

.search-results mark {
  background: none;
  color: var(--accent);
  font-weight: 700;
}

/* ---------- Контент ---------- */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.page-title {
  font-size: 1.4rem;
  margin: 8px 0 20px;
}

.back-link {
  display: inline-block;
  margin: 4px 0 2px;
  padding: 6px 0;
  color: var(--accent);
  text-decoration: none;
  font-size: .92rem;
}

.back-link:hover { text-decoration: underline; }

/* Кнопка «догори» */
.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
  transition: opacity .2s;
}

.to-top:hover { background: var(--accent-dark); }

.page-title .count {
  font-size: .95rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Панель фільтрів (рік / місяць) */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: -8px 0 18px;
}

.filter-bar select {
  padding: 8px 12px;
  font-size: .9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.filter-reset {
  padding: 8px 12px;
  font-size: .85rem;
  border: 0;
  border-radius: 8px;
  background: #eef0f3;
  color: var(--text);
  cursor: pointer;
}

.filter-reset:hover { background: #e2e5e9; }

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

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  #app { padding: 12px; }
}

/* Картка альбому */
.album-card {
  display: block;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform .15s ease, box-shadow .15s ease;
}

.album-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, .1), 0 8px 24px rgba(0, 0, 0, .1);
}

.album-card .cover {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.album-card .meta {
  padding: 10px 12px 12px;
}

.album-card .name {
  font-weight: 600;
  font-size: .95rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.album-card .qty {
  margin-top: 4px;
  font-size: .82rem;
  color: var(--text-muted);
}

/* Мініатюра фото */
.photo-tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: zoom-in;
  padding: 0;
  border: 0;
  background: var(--border);
  transition: transform .15s ease;
}

.photo-tile:hover { transform: scale(1.02); }

.photo-tile img {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  display: block;
}

/* Статус / завантаження */
.status {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
}

.sentinel { height: 1px; }

.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

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

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 10, 12, .94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

.lightbox[hidden] { display: none; }

.lb-stage {
  margin: 0;
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px 64px;
}

@media (max-width: 640px) {
  .lb-stage { padding: 8px; }
}

.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
}

.lb-spinner {
  position: absolute;
  width: 40px; height: 40px;
  border: 4px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.lb-btn {
  position: absolute;
  z-index: 101;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}

.lb-btn:hover { background: rgba(255, 255, 255, .28); }

.lb-close {
  top: 14px; right: 14px;
  width: 42px; height: 42px;
  font-size: 1.1rem;
}

.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 48px; height: 48px;
  font-size: 2rem;
  line-height: 1;
  padding-bottom: 4px;
}

.lb-prev { left: 12px; }
.lb-next { right: 12px; }

.lb-nav:disabled { opacity: .3; cursor: default; }

@media (max-width: 640px) {
  .lb-nav { width: 40px; height: 40px; font-size: 1.6rem; }
}

.lb-footer {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  color: #d0d3d8;
  font-size: .9rem;
}

.lb-caption {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.lb-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.lb-download {
  padding: 9px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  text-decoration: none;
  font-size: .88rem;
  white-space: nowrap;
  transition: background .15s ease;
}

.lb-download:hover { background: rgba(255, 255, 255, .3); }

.lb-download--primary { background: var(--accent); }
.lb-download--primary:hover { background: var(--accent-dark); }
