/* ============================================================
   Галерея — светлая минималистичная тема
   ============================================================ */
:root {
  --bg: #ffffff;
  --fg: #14161a;
  --muted: #85898f;
  --line: #e8e9ec;
  --accent: #14161a;
  --accent-fg: #ffffff;
  --fav: #ef4b5e;
  --radius: 10px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

/* display:flex у панелей сильнее атрибута hidden — гасим явно */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 12px 24px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.topbar__meta {
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }

.topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: #f5f6f7; border-color: #d8dade; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { background: #2b2f36; border-color: #2b2f36; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: #f0f1f3; }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--wide { width: 100%; justify-content: center; padding: 12px; }
.btn.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

.ico { width: 16px; height: 16px; }

.counter {
  min-width: 18px;
  padding: 2px 5px;
  border-radius: 999px;
  background: var(--fav);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

/* ---------- Панели ---------- */
.selbar, .filterbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: #f7f8f9;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.selbar__buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.filterbar { color: var(--muted); }

.intro {
  padding: 22px 24px 4px;
  max-width: 720px;
  color: #4a4e55;
  font-size: 15px;
  line-height: 1.6;
}

/* ---------- Сетка ---------- */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 16px;
}

.tile {
  position: relative;
  margin: 0;
  overflow: hidden;
  background: #eef0f2;
  border-radius: 4px;
  cursor: zoom-in;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
}
.tile img.is-loaded { opacity: 1; }
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background .15s;
  pointer-events: none;
}
.tile:hover::after { background: rgba(0, 0, 0, .07); }
.tile.is-hidden { display: none; }

.tile__fav {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 22, 26, .38);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s, transform .1s;
}
.tile__fav svg { width: 16px; height: 16px; }
.tile:hover .tile__fav { opacity: 1; }
.tile__fav:hover { background: rgba(20, 22, 26, .62); }
.tile__fav:active { transform: scale(.9); }
.tile.is-fav .tile__fav { opacity: 1; color: var(--fav); }
.tile.is-fav .tile__fav svg { fill: var(--fav); stroke: var(--fav); }

.tile__check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(20, 22, 26, .3);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  display: none;
}
body.select-mode .tile { cursor: pointer; }
body.select-mode .tile__check { display: block; }
body.select-mode .tile__fav { display: none; }
.tile.is-selected .tile__check {
  background: #2d7ef7 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 13l4 4L19 7'/%3E%3C/svg%3E") center / 13px no-repeat;
  border-color: #fff;
}
.tile.is-selected { outline: 3px solid #2d7ef7; outline-offset: -3px; }

.empty { padding: 60px 24px; text-align: center; color: var(--muted); }

/* ---------- Подвал ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 40px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.footer a { color: var(--fg); }

/* ---------- Список галерей ---------- */
.albums {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 22px;
  padding: 24px;
}
.album { text-decoration: none; color: inherit; }
.album__cover {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: var(--radius);
  background: #eef0f2;
  display: grid;
  place-items: center;
}
.album__cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s; }
.album:hover .album__cover img { transform: scale(1.03); }
.album__empty { color: var(--muted); font-size: 13px; }
.album__lock {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(20, 22, 26, .72);
  color: #fff;
  font-size: 11.5px;
}
.album__lock--draft { background: rgba(220, 120, 20, .85); top: auto; bottom: 10px; }
.album__title { margin: 12px 0 2px; font-size: 15.5px; font-weight: 600; }
.album__meta { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- Пароль ---------- */
.lock { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.lock__card { width: 100%; max-width: 340px; text-align: center; }
.lock__ico { width: 34px; height: 34px; color: var(--muted); }
.lock__card h1 { margin: 14px 0 4px; font-size: 20px; }
.lock__hint { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.lock__card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
}
.lock__card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.lock__error { color: var(--fav); font-size: 13.5px; }

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0d0e10;
  color: #fff;
  display: flex;
  flex-direction: column;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lightbox__bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  font-size: 13px;
  color: rgba(255, 255, 255, .72);
}
.lightbox__counter { font-variant-numeric: tabular-nums; }
.lightbox__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox__tools { margin-left: auto; display: flex; gap: 6px; }

.iconbtn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn:hover { background: rgba(255, 255, 255, .18); }
.iconbtn:active { transform: scale(.92); }
.iconbtn.is-fav { color: var(--fav); }
.iconbtn.is-fav svg { fill: var(--fav); stroke: var(--fav); }

.lightbox__stage {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 0 18px;
  touch-action: pan-y;
}
/* абсолютное позиционирование вместо max-height:100% — проценты от высоты
   flex-элемента браузер разрешает не всегда, и фото вылезало за экран */
.lightbox__stage img {
  position: absolute;
  inset: 0 18px;
  width: calc(100% - 36px);
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .2s;
}
.lightbox__stage img.is-loaded { opacity: 1; }

.lightbox__info {
  flex: none;
  padding: 14px 18px 20px;
  text-align: center;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .5);
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  /* фото бывает светлым — тёмная подложка держит стрелки читаемыми */
  background: rgba(13, 14, 16, .55);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .28);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
}
.lightbox__nav:hover { background: rgba(13, 14, 16, .85); }
.lightbox__nav svg { width: 22px; height: 22px; }
.lightbox__nav--prev { left: 16px; }
.lightbox__nav--next { right: 16px; }

/* ---------- Тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  z-index: 200;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(20, 22, 26, .93);
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Мобильные ---------- */
@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 14px; }
  /* сеткой, а не flex: кнопки с длинными подписями не сжимаются ниже своего
     текста и раздвигали страницу шире экрана — от этого ехала и галерея */
  .topbar__actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); width: 100%; }
  .btn { width: 100%; justify-content: center; padding: 10px 8px; }
  .topbar__actions .btn span:not(.counter) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .selbar, .filterbar { top: 0; padding: 10px 14px; }
  .grid { padding: 10px; gap: 4px; }
  .intro { padding: 16px 14px 0; font-size: 14px; }
  .footer { padding: 30px 14px; }
  .albums { padding: 14px; gap: 16px; }
  .lightbox__nav { width: 40px; height: 40px; }
  .lightbox__nav--prev { left: 6px; }
  .lightbox__nav--next { right: 6px; }
  .tile__fav { opacity: 1; width: 26px; height: 26px; top: 6px; right: 6px; }
  .tile__fav svg { width: 14px; height: 14px; }
}

@media (max-width: 860px) {
  .topbar { position: static; }
}
