:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --ink: #22301f;
  --muted: #75816f;
  --line: #e3e7df;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #b3442e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
  font-size: 16px;
  white-space: nowrap;
}

.crumbs { flex: 1; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.top-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.storage-note { font-size: 12.5px; color: var(--muted); }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.tiny { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }

.section-title { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 16px; }
.section-title h1 { font-size: 22px; margin: 0; }
.section-title .sub { color: var(--muted); font-size: 13.5px; }

/* альбомы */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.album-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
}
.album-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(30, 45, 30, 0.10); }
.album-cover {
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, #e8ede6, #d7e0d4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-meta { padding: 10px 12px 12px; }
.album-name { font-weight: 600; margin-bottom: 2px; }
.album-sub { font-size: 12.5px; color: var(--muted); }
.album-del {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.12s;
}
.album-card:hover .album-del { opacity: 1; }

/* сетка файлов */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.file-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #e9ece7;
  cursor: pointer;
}
.file-cell img.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-cell .ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.file-cell .badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(20, 28, 20, 0.72);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
}
.file-cell .badge.proc { background: rgba(179, 68, 46, 0.85); }
.file-cell .fdel {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  background: rgba(255,255,255,0.92);
  border: none;
  border-radius: 7px;
  padding: 4px;
  cursor: pointer;
  color: var(--danger);
}
.file-cell:hover .fdel { opacity: 1; }

.desc { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 60px 0;
}
.empty .big { font-size: 17px; color: var(--ink); margin-bottom: 6px; }

/* панель загрузки */
.upload-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  width: 320px;
  max-height: 46vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(20, 30, 20, 0.16);
  padding: 10px 12px;
}
.up-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.up-item { padding: 6px 0; border-top: 1px solid var(--line); }
.up-item .name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-item .state { font-size: 12px; color: var(--muted); }
.up-item .state.err { color: var(--danger); }
.up-item.done { opacity: .55; }
.up-item.done .progress { display: none; }
.progress { height: 5px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.15s; }

/* нижняя строка-статус загрузки */
.up-bar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 29;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 9px 7px 16px;
  box-shadow: 0 10px 26px rgba(20, 30, 20, 0.18);
  max-width: calc(100vw - 32px);
}
.up-bar.has-error { border-color: var(--danger); }
.up-bar-open {
  border: none;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 13.5px;
  padding: 2px 4px;
  white-space: nowrap;
}
.up-bar-open:hover { color: var(--accent); }
.up-bar-close {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.up-bar-close:hover { color: var(--ink); background: var(--bg); }

/* переключатель «видна гостям» (админ) */
.vis-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.vis-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
.album-meta .vis-toggle { margin-top: 6px; }

/* ссылки доступа (админ, главная) */
.links-box { margin-top: 30px; }
.links-box .section-title { margin-bottom: 10px; }
.links-box .section-title h2 { font-size: 17px; margin: 0; }
.link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.link-label { width: 112px; flex: none; font-size: 13.5px; color: var(--muted); }
.link-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fbfcfa;
}
.link-input:focus { outline: 2px solid rgba(47, 111, 79, 0.35); border-color: var(--accent); }

/* дропзона */
.dropzone {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(47, 111, 79, 0.12);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  background-color: rgba(246, 247, 245, 0.9);
}

/* модалки */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(25, 32, 25, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  padding: 22px;
  width: 380px;
  max-width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal .hint { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.modal input, .modal textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fbfcfa;
}
.modal input:focus, .modal textarea:focus { outline: 2px solid rgba(47, 111, 79, 0.35); border-color: var(--accent); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0; }

/* лайтбокс */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(14, 18, 14, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-stage { max-width: calc(100vw - 160px); max-height: calc(100vh - 96px); display: flex; align-items: center; justify-content: center; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: calc(100vh - 96px); border-radius: 6px; display: block; }
.lb-btn {
  position: absolute;
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.22); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  color: #e8ece8;
  font-size: 13.5px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.45));
}
.lb-bar .btn { background: rgba(255,255,255,0.14); border-color: transparent; color: #fff; }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand span { display: none; }
  main { padding: 16px 12px 80px; }
  .lb-stage { max-width: 100vw; }
  .lb-prev { left: 6px; }
  .lb-next { right: 6px; }
  .upload-panel { width: calc(100vw - 24px); right: 12px; }
  .up-bar { left: 12px; right: 12px; transform: none; justify-content: space-between; max-width: none; }
  .link-row { flex-wrap: wrap; }
  .link-input { flex-basis: 100%; order: 3; }
}

/* атрибут hidden всегда сильнее авторских display */
[hidden] { display: none !important; }
