:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #dfe3ea;
  --accent: #2563b8;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 1.75rem; margin: .25rem 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
code { background: #e6eaf0; padding: 1px 5px; border-radius: 4px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: .55rem; }
.brand-logo { height: 36px; width: auto; max-width: 160px; object-fit: contain; display: block; }
.logo-preview { display: flex; align-items: center; gap: 1rem; padding: .75rem; background: var(--bg); border-radius: 8px; margin-bottom: 1rem; }
.logo-preview img { max-height: 60px; max-width: 220px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #1e4f99, #4f9cf0); }
.topbar nav { margin-left: auto; display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--ink); padding: .4rem .7rem; border-radius: 8px; }
.topbar nav a:hover { background: var(--bg); }
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; font-size: 1.4rem; cursor: pointer; }

.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; flex: 1; }
.narrow { max-width: 560px; margin: 0 auto; }
.narrow-form { max-width: 560px; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1.5rem; }

/* Cards, forms, buttons */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.empty { text-align: center; padding: 2.5rem 1.25rem; }
.form label { display: block; margin-bottom: .9rem; font-weight: 500; font-size: .95rem; }
.form label.inline, label.inline { display: flex; gap: .5rem; align-items: center; font-weight: 400; margin-bottom: .5rem; }
input[type=text], input[type=password], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: .55rem 1rem; border-radius: 8px; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--card); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-ok { background: #e7f3ef; border-color: #b9dccf; color: #1d4d43; }
.flash-err { background: #fbeaea; border-color: #efc0bd; color: #7d1a14; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: #1d6b4f; } .checks .bad { color: var(--danger); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0; }
.page-head .desc { margin-top: .5rem; max-width: 70ch; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumb { text-decoration: none; font-size: .9rem; }

/* Album grid */
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; }
.album-card { text-decoration: none; color: inherit; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); transition: transform .15s; }
.album-card:hover { transform: translateY(-2px); }
.album-cover { aspect-ratio: 4/3; background: #e6eaf0; position: relative; display: flex; align-items: center; justify-content: center; }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-cover { color: var(--muted); font-size: .9rem; }
.badge { position: absolute; top: .6rem; left: .6rem; background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; }
.badge-right { left: auto; right: .6rem; }
.section-title { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 1.5rem 0 .75rem; }
.sub-grid { margin-bottom: 1.5rem; }
.album-meta { padding: .75rem 1rem; display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.album-meta span { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* Photo grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; }
.photo-tile { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: #e6eaf0; cursor: zoom-in; display: block; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.photo-tile:hover img { transform: scale(1.03); }
.photo-tile input { display: none; position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; z-index: 2; accent-color: var(--accent); }
.selecting .photo-tile { cursor: pointer; }
.selecting .photo-tile input { display: block; }
.photo-tile:has(input:checked) { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo-tile:has(input:checked) img { opacity: .75; }

.bulk-bar { display: none; position: sticky; bottom: 1rem; margin-top: 1rem; background: var(--ink); color: #fff; padding: .6rem .8rem; border-radius: 12px; gap: .5rem; align-items: center; flex-wrap: wrap; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.selecting .bulk-bar { display: flex; }
.bulk-bar span { margin-right: auto; }
.bulk-bar select { width: auto; margin: 0; }
.bulk-bar .btn.ghost { color: #fff; border-color: #555; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(12,12,12,.96); z-index: 100; display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100vw; max-height: 100vh; display: flex; flex-direction: column; align-items: center; }
.lightbox img { max-width: 94vw; max-height: calc(100vh - 130px); object-fit: contain; user-select: none; }
.lightbox figcaption { color: #ddd; padding: .75rem 1rem; text-align: center; width: 100%; }
.lightbox .muted { color: #999; }
.lb-tools { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin-top: .5rem; }
.lb-edit { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; }
.lb-edit input[type=text] { width: 200px; margin: 0; padding: .3rem .6rem; background: #222; color: #fff; border-color: #444; }
.lightbox .btn.ghost { color: #eee; border-color: #444; }
.lb-close, .lb-prev, .lb-next { position: absolute; background: rgba(255,255,255,.08); color: #fff; border: 0; cursor: pointer; border-radius: 50%; width: 48px; height: 48px; font-size: 1.6rem; line-height: 1; }
.lb-close:hover, .lb-prev:hover, .lb-next:hover { background: rgba(255,255,255,.18); }
.lb-close { top: 14px; right: 14px; font-size: 1.2rem; }
.lb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 14px; top: 50%; transform: translateY(-50%); }
.lightbox.playing .lb-tools { display: none; }

/* Upload */
.dropzone { position: relative; border: 2px dashed var(--line); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: #f8fafd; margin-bottom: 1rem; transition: .15s; }
.dropzone.over { border-color: var(--accent); background: #edf3fc; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone p { margin: .2rem 0; }
.upload-list { list-style: none; padding: 0; margin: 0 0 1rem; max-height: 300px; overflow: auto; font-size: .9rem; }
.upload-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.upload-list .st-ok { color: #1d6b4f; } .upload-list .st-err { color: var(--danger); } .upload-list .st-wait { color: var(--muted); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 1rem; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Users table */
.table-card { padding: 0; overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
.users th, .users td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.users select, .users input[type=password] { margin: 0; min-width: 120px; }
.users .name-input { font-weight: 600; min-width: 140px; margin: 0 0 .2rem; padding: .35rem .5rem; }
.row-actions form { display: flex; gap: .4rem; }
.access-tree { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.access-tree li { padding-top: .35rem; padding-bottom: .35rem; border-bottom: 1px solid var(--line); }
.access-tree label.inline { margin: 0; }
.access-tree .make-private { margin: .2rem 0 0 1.6rem; }
.tag { display: inline-block; font-size: .75rem; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 0 .5rem; margin-left: .25rem; color: var(--muted); }
.check-row { display: flex; gap: .5rem; margin-bottom: .25rem; }
.access-grid { display: grid; gap: .4rem; }
.access-row { display: flex !important; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 !important; font-weight: 400 !important; }
.access-row select { width: auto; min-width: 130px; margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 360px); gap: 1.25rem; align-items: start; }
.split > .card { margin-bottom: 0; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.levels-key dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: .75rem 0; }
.levels-key dt { font-weight: 600; }
.levels-key dd { margin: 0; }
.danger-zone h2 { margin-top: 0; color: var(--danger); }

@media (max-width: 700px) {
  .menu-toggle { display: block; }
  .topbar { flex-wrap: wrap; }
  .topbar nav { display: none; width: 100%; flex-direction: column; }
  .nav-open .topbar nav { display: flex; }
  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .album-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .album-meta { flex-direction: column; gap: 0; padding: .6rem .75rem; }
  .lb-prev, .lb-next { display: none; }
  .users thead { display: none; }
  .users tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .users td { display: flex; justify-content: space-between; align-items: center; border: 0; padding: .35rem 1rem; gap: 1rem; }
  .users td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
}

/* ---------- Login page ---------- */
.login-page {
  --login-ink: #1b2433;
  --login-muted: #5d6676;
  --login-line: #b9c2ce;
  --login-field: #16304f;
  margin: 0;
  min-height: 100vh;
  background: var(--login-field);
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-end;
  padding: clamp(1rem, 5vw, 4.5rem);
}
.login-photo { position: fixed; inset: 0; margin: 0; background: var(--login-field); }
.login-photo img { width: 100%; height: 100%; object-fit: cover; display: block; animation: login-photo-in 1.4s ease-out both; }
.login-photo figcaption {
  position: absolute; right: clamp(1rem, 4vw, 3rem); bottom: clamp(1rem, 4vw, 2.5rem);
  max-width: 34ch; color: #fff; font-size: .9rem; line-height: 1.4; text-align: right;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .55);
}
@keyframes login-photo-in { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: none; } }

.login-plate {
  position: relative;
  width: min(27rem, 100%);
  background: #fff;
  color: var(--login-ink);
  padding: 2.25rem 2.25rem 2rem;
  border-radius: 3px;
  box-shadow: 0 24px 60px rgba(8, 18, 34, .35);
}
.login-name { display: flex; align-items: center; gap: .9rem; }
.login-logo { height: 46px; width: auto; max-width: 120px; object-fit: contain; }
.login-name h1 {
  margin: 0;
  font-family: Optima, Candara, "Noto Sans", "Segoe UI", sans-serif;
  font-weight: 500;
  font-size: clamp(1.9rem, 3vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: -.01em;
}
.login-lede { margin: .6rem 0 1.75rem; color: var(--login-muted); }
.login-error {
  margin: -.5rem 0 1.25rem; padding: .1rem 0 .1rem .75rem;
  border-left: 3px solid var(--danger); color: #8a1c16; font-size: .95rem;
}
.login-form label { display: block; font-size: .875rem; font-weight: 600; margin: 0 0 .15rem; }
.login-form input {
  display: block; width: 100%; margin: 0 0 1.4rem; padding: .5rem 0 .45rem;
  font: inherit; font-size: 1.05rem; color: var(--login-ink);
  background: transparent; border: 0; border-bottom: 1.5px solid var(--login-line); border-radius: 0;
}
.login-form input:focus { outline: none; border-bottom: 2px solid var(--accent); padding-bottom: calc(.45rem - .5px); }
.login-form button {
  width: 100%; height: 3rem; margin-top: .35rem;
  font: inherit; font-weight: 600; font-size: 1rem;
  color: #fff; background: var(--accent); border: 0; border-radius: 3px; cursor: pointer;
}
.login-form button:hover { background: #1d4f94; }
.login-form button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

@media (max-width: 640px) {
  .login-page { display: block; padding: 0; background: #fff; }
  .login-page:not(.has-photo) { background: var(--login-field); padding: 1rem; display: flex; align-items: flex-end; }
  .login-photo { position: relative; height: 42vh; }
  .login-photo figcaption { font-size: .8rem; }
  .has-photo .login-plate { width: 100%; box-shadow: none; border-radius: 0; padding: 1.75rem 1.25rem 2.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .login-photo img { animation: none; }
}
