:root {
  --bg: #14161a; --panel: #1d2026; --panel-2: #262a32; --fg: #e8eaed; --muted: #9aa0a6;
  --line: #2f343c; --accent: #4c8dff; --accent-fg: #fff; --danger: #e5534b; --ok: #3fb950;
  --gutter: 16px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7; --panel: #fff; --panel-2: #eceef1; --fg: #1d2026; --muted: #5f6672;
    --line: #dcdfe4; --accent: #2563eb;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
body.noscroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select {
  font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input:focus-visible, button:focus-visible, .tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.spacer { flex: 1; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px var(--gutter); background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); }
.menu-items {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; display: flex; flex-direction: column; gap: 4px;
  padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.menu-items button { text-align: left; border-color: transparent; background: transparent; }
.menu-items button:hover { background: var(--panel-2); }

main { padding: var(--gutter); max-width: 1600px; margin: 0 auto; }
.bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.bar h2 { font-size: 20px; margin-right: 6px; }
.bar .count { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }
.drop-hint { display: none; }
body.dropping main { outline: 3px dashed var(--accent); outline-offset: -8px; }

/* альбомы */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.album { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: block; }
.album:hover { border-color: var(--accent); }
.album .cover { aspect-ratio: 4 / 3; background: var(--panel-2); display: grid; place-items: center; font-size: 40px; }
.album .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-name { padding: 10px 12px 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-count { padding: 0 12px 10px; color: var(--muted); font-size: 13px; }

/* сетка файлов */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.tile { position: relative; aspect-ratio: 1; background: var(--panel-2); border-radius: 6px; overflow: hidden; cursor: pointer; display: grid; place-items: center; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .ph { font-size: 34px; opacity: .6; }
.tile .badge { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 10px; }
.tile .check {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.35); display: none;
}
.selecting .tile .check { display: block; }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected .check { background: var(--accent); }
.tile.selected .check::after { content: "✓"; color: #fff; display: block; text-align: center; line-height: 20px; font-size: 14px; }

/* вход */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.login { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { text-align: center; margin-bottom: 6px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* загрузки */
.uploads {
  position: fixed; right: 12px; bottom: 12px; width: min(340px, calc(100vw - 24px)); max-height: 50vh; z-index: 20;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.4);
  display: flex; flex-direction: column; overflow: hidden;
}
.up-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.up-head button { padding: 2px 8px; }
.up-list { overflow: auto; padding: 4px 12px 8px; }
.up-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0; font-size: 13px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-row .st { color: var(--muted); }
.up-row.done .st { color: var(--ok); }
.up-row.err .st { color: var(--danger); }
.progress { grid-column: 1 / -1; height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.up-row.done .progress i { background: var(--ok); }
.up-row.err .progress i { background: var(--danger); }

/* просмотр */
.lb { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.95); color: #fff; display: flex; flex-direction: column; }
.lb-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: linear-gradient(rgba(0,0,0,.7), transparent); }
.lb-meta { min-width: 0; flex: 1; }
.lb-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-info { font-size: 12px; opacity: .7; }
.lb button, .lb a.btn {
  background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 8px; padding: 8px 12px; font-size: 15px; cursor: pointer; line-height: 1.2;
}
.lb button:hover, .lb a.btn:hover { background: rgba(255,255,255,.22); }
.lb-stage {
  flex: 1; min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center; padding: 0 8px 8px; touch-action: pan-y;
}
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px !important; padding: 10px 14px !important; }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }

/* окна */
dialog.dlg { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(440px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(0,0,0,.55); }
dialog.dlg h3 { margin-bottom: 12px; }
dialog.dlg form, .dlg-body { display: flex; flex-direction: column; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.user-row .role { color: var(--muted); font-size: 13px; }
.user-row button { padding: 4px 8px; font-size: 13px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline input[type=text], .inline input[type=password] { flex: 1; min-width: 110px; }

/* уведомления */
#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100vw - 24px); pointer-events: none; }
.toast { background: #2b2f36; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 520px; }

@media (max-width: 560px) {
  :root { --gutter: 10px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .albums { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .bar h2 { flex-basis: 100%; }
  .lb-nav { display: none; }
}
