/* ---- tokens (dark theme; a light theme only needs another set of these) */
:root {
  --bg: #111214;
  --surface: #1b1c1f;
  --surface-2: #26272b;
  --line: #2e3034;
  --text: #e8e8ea;
  --muted: #9a9ba1;
  --accent: #8ab4f8;
  --accent-bg: #22324a;
  --danger: #f28b82;
  --ok: #81c995;
  --tile-bg: #1f2023;
  --topbar-h: 60px;
  --sidebar-w: 240px;
  --pad-x: 12px;
  --scrub-w: 0px;
  color-scheme: dark;
}
body.has-scrubber { --scrub-w: 52px; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* Keep the scrollbar's space when the viewer locks scrolling, so the grid
   width (and with it the row layout) doesn't change. */
html { scrollbar-gutter: stable; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
code { font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 24px;
  padding: 0 12px 0 20px;
  background: rgba(17, 18, 20, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: conic-gradient(from 200deg, #8ab4f8, #81c995, #fdd663, #f28b82, #8ab4f8);
}
.spacer { flex: 1; }

.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 8px; border-radius: 999px; color: var(--muted);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { background: var(--surface); color: var(--text); }
.user-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  padding: 6px; border-radius: 12px; background: var(--surface-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column;
}
.user-menu .menu form { margin: 0; }
.user-menu .menu a, .user-menu .menu button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px;
  border: 0; background: none; cursor: pointer;
}
.user-menu .menu a:hover, .user-menu .menu button:hover { background: #33353b; }

/* ---- side bar */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 10;
  width: var(--sidebar-w); padding: 12px 12px 12px 0;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar a {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 24px; border-radius: 0 999px 999px 0;
  color: var(--muted); font-weight: 500;
}
.sidebar a:hover { background: var(--surface); color: var(--text); }
.sidebar a.active { background: var(--accent-bg); color: var(--accent); }

/* ---- content */
.content {
  padding: calc(var(--topbar-h) + 8px) calc(var(--pad-x) + var(--scrub-w)) 40px calc(var(--sidebar-w) + var(--pad-x));
}
.page-head { display: flex; align-items: baseline; gap: 16px; padding: 16px 4px 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 500; letter-spacing: -.01em; }
.album-head { align-items: center; flex-wrap: nowrap; }
.album-head h1 { font-size: 24px; }
.back { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: none; }
.back:hover { background: var(--surface); }

.empty { padding: 100px 20px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); font-weight: 500; margin: 0 0 8px; }
.empty .btn { margin-top: 16px; }

/* ---- buttons, forms, panels */
.btn {
  display: inline-block; padding: 8px 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--accent); font-weight: 500; font-size: 14px;
}
.btn:hover { background: #30323a; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #0b1a33; }
.btn.primary:hover { background: #a3c4fa; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }

input:not([type=checkbox]), select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label input, label select { font-size: 15px; color: var(--text); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; }

.form-col { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.form-col .btn { align-self: flex-start; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
form.inline { display: flex; gap: 6px; align-items: center; margin: 0; }

.panel { background: var(--surface); border-radius: 16px; padding: 20px 24px; margin: 0 4px 20px; max-width: 980px; }
.panel.narrow { max-width: 480px; }
.panel h2 { margin: 0 0 12px; font-size: 18px; font-weight: 500; }
.panel p { margin: 0 0 16px; }
.panel form { margin: 0; }

.alert { margin: 0 4px 20px; padding: 10px 16px; border-radius: 10px; max-width: 980px; }
.alert.ok { background: #1d3325; color: var(--ok); }
.alert.error { background: #3c1f1f; color: var(--danger); }

.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 14px; }
.tabs a:hover { background: var(--surface); color: var(--text); }
.tabs a.active { background: var(--surface-2); color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 0 4px 20px; max-width: 980px; }
.stat { background: var(--surface); border-radius: 14px; padding: 16px 20px; display: flex; flex-direction: column; }
.stat b { font-size: 28px; font-weight: 500; }
.stat span { color: var(--muted); font-size: 13px; }

.scan-controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.scan-status { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.scan-phase { font-weight: 500; margin-bottom: 12px; }
.scan-phase.error { color: var(--danger); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-bottom: 14px; }
.bar div { height: 100%; background: var(--accent); width: 0; transition: width .5s; }
.scan-numbers { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; margin: 0 0 12px; }
.scan-numbers dt { font-size: 12px; color: var(--muted); }
.scan-numbers dd { margin: 0; font-size: 18px; }
.scan-list { margin-top: 10px; }
.scan-list summary { cursor: pointer; color: var(--muted); }
.scan-list ul { max-height: 260px; overflow: auto; font-size: 13px; font-family: ui-monospace, monospace; }

table.users { width: 100%; border-collapse: collapse; }
.users th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 0 8px 8px; }
.users td { padding: 8px; border-top: 1px solid var(--line); }
.users input { width: 170px; }

/* ---- login */
.login-page { display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; padding: 32px 28px;
  display: flex; flex-direction: column; gap: 16px;
}
.login-card .brand { justify-content: center; font-size: 26px; margin-bottom: 8px; }
.login-card .alert { margin: 0; }
.login-card .btn { padding: 10px; font-size: 15px; margin-top: 4px; }

/* ---- photo grid */
.grid { position: relative; }
.grid-row, .grid-head { position: absolute; left: 0; right: 0; }
.tile {
  position: absolute; top: 0; height: 100%;
  overflow: hidden; background: var(--tile-bg);
  cursor: pointer; outline-offset: 2px;
}
.tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .25s, transform .3s;
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.03); }
.tile.broken img { display: none; }
.tile .play {
  position: absolute; right: 6px; top: 6px;
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0, 0, 0, .55);
}
.tile .play svg { width: 18px; height: 18px; }
.tile.broken.video .play { right: 50%; top: 50%; transform: translate(50%, -50%); width: 44px; height: 44px; }

.grid-head { display: flex; align-items: flex-end; padding: 0 2px 10px; }
.grid-month span { font-size: 22px; font-weight: 500; letter-spacing: -.01em; }
.grid-day span { font-size: 14px; color: var(--muted); font-weight: 500; }
.grid-head:first-child { align-items: center; padding-bottom: 6px; }

/* ---- floating date while scrolling */
.date-pill {
  position: fixed; z-index: 15; left: calc(50% + var(--sidebar-w) / 2); top: calc(var(--topbar-h) + 14px);
  transform: translate(-50%, -6px);
  padding: 6px 14px; border-radius: 999px;
  background: rgba(38, 39, 43, .92); box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
  font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.date-pill.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- year scrubber */
.scrubber {
  position: fixed; z-index: 16; right: 0; top: calc(var(--topbar-h) + 16px); bottom: 24px;
  width: 52px; cursor: ns-resize; touch-action: none; user-select: none;
}
.scrub-years { position: absolute; inset: 0; }
.scrub-year {
  position: absolute; right: 10px; transform: translateY(-50%);
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.scrub-dot {
  position: absolute; right: 18px; width: 3px; height: 3px; border-radius: 50%;
  background: var(--muted); opacity: .6;
}
.scrub-indicator {
  position: absolute; right: 42px; width: 8px; height: 3px; background: var(--accent);
  border-radius: 2px; transform: translateY(-1.5px);
}
.scrub-tip {
  position: absolute; right: 56px; transform: translateY(-50%);
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
  background: var(--accent); color: #0b1a33; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.scrubber:hover .scrub-tip, .scrubber.dragging .scrub-tip { opacity: 1; }

/* ---- albums list */
.album-list {
  display: grid; gap: 28px 20px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  padding: 0 4px;
}
.album-cover { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--tile-bg); }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.album-card:hover .album-cover img { transform: scale(1.04); }
.album-name { margin-top: 10px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-meta { font-size: 13px; color: var(--muted); }

/* ---- viewer */
body.viewer-open { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 100; background: #000; color: #fff; }
.v-stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transition: right .2s;
}
.v-img, .v-video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.v-video { width: 100%; height: 100%; }
.v-msg { text-align: center; color: #ccc; }
.v-bar {
  position: absolute; inset: 0 0 auto 0; height: 64px;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: linear-gradient(rgba(0, 0, 0, .6), transparent);
  transition: right .2s;
}
.v-title { flex: 1; font-size: 14px; color: #ddd; }
.v-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: none; cursor: pointer; color: #fff;
}
.v-btn:hover { background: rgba(255, 255, 255, .12); }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0, 0, 0, .35); width: 52px; height: 52px; }
.v-nav svg { width: 32px; height: 32px; }
.v-prev { left: 16px; }
.v-next { right: 16px; transition: right .2s; }
.v-nav:disabled { display: none; }
.v-info {
  position: absolute; top: 0; right: 0; bottom: 0; width: 360px;
  padding: 20px 24px; overflow-y: auto;
  background: var(--surface); color: var(--text);
  transform: translateX(100%); transition: transform .2s;
}
.viewer.info-open .v-info { transform: none; }
.viewer.info-open .v-stage, .viewer.info-open .v-bar { right: 360px; }
.viewer.info-open .v-next { right: 376px; }
.v-info h2 { margin: 4px 0 20px; font-size: 18px; font-weight: 500; }
.v-info dl { margin: 0 0 24px; display: grid; gap: 16px; }
.v-info dt { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: -12px; }
.v-info dd { margin: 0; word-break: break-word; }
.v-info dd small { display: block; color: var(--muted); font-size: 13px; }
.v-info dd a { color: var(--accent); }

/* ---- selection (admin) */
.tile .check {
  position: absolute; left: 6px; top: 6px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid rgba(255, 255, 255, .9); background: rgba(0, 0, 0, .25);
  opacity: 0; transition: opacity .15s;
}
.tile .check svg { width: 16px; height: 16px; opacity: 0; }
.tile:hover .check, body.selecting .tile .check { opacity: 1; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); color: #0b1a33; }
.tile.selected .check svg { opacity: 1; }
.tile.selected img { transform: scale(.88); border-radius: 6px; }
.tile.selected { background: var(--accent-bg); }
body.selecting .tile:hover img { transform: none; }
body.selecting .tile.selected:hover img { transform: scale(.88); }

.selection-bar {
  position: fixed; inset: 0 0 auto 0; z-index: 30; height: var(--topbar-h);
  display: none; align-items: center; gap: 12px; padding: 0 16px 0 8px;
  background: var(--accent-bg); color: var(--text);
}
body.selecting .selection-bar { display: flex; }
.sel-count { font-weight: 500; font-size: 16px; }

.modal { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .6); display: grid; place-items: center; padding: 16px; }
.modal-box {
  width: 100%; max-width: 420px; max-height: 80vh; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface-2); border-radius: 18px; padding: 20px;
}
.modal-box h2 { margin: 0; font-size: 18px; font-weight: 500; }
.album-pick { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 60px; }
.album-pick li { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; cursor: pointer; }
.album-pick li.muted { cursor: default; }
.album-pick li:not(.muted):hover { background: #33353b; }
.pick-cover { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--tile-bg); flex: none; display: grid; place-items: center; }
.pick-cover img { width: 100%; height: 100%; object-fit: cover; }
.pick-cover.new { font-size: 24px; color: var(--accent); }
.pick-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-actions { display: flex; justify-content: flex-end; }

.toast {
  position: fixed; z-index: 300; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 10px; background: #e8e8ea; color: #111214; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast { display: flex; align-items: center; gap: 16px; }
.toast button { border: 0; background: none; color: #1a56c4; font-weight: 600; cursor: pointer; padding: 0; }
.page-note { margin: -8px 4px 20px; max-width: 980px; }
a.stat:hover { background: var(--surface-2); }

.album-title { min-width: 0; }
.album-actions { display: flex; gap: 8px; flex: none; }

/* ---- upload */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer;
  padding: 40px 20px; border: 2px dashed var(--line); border-radius: 14px; color: var(--muted); font-size: 15px;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--text); background: rgba(138, 180, 248, .05); }
.dropzone svg { width: 48px; height: 48px; }
.dropzone input { display: none; }
.upload-summary { margin: 16px 0 8px; font-weight: 500; }
.upload-summary a { color: var(--accent); }
.upload-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.upload-list li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.upload-list .bar { grid-column: 1 / -1; margin: 0; height: 4px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok { color: var(--ok); }
.error { color: var(--danger); }

/* ---- mobile bottom navigation */
.bottomnav { display: none; }

@media (hover: none) {
  .v-nav { display: none; }
  .tile:hover img, .album-card:hover .album-cover img { transform: none; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
}

@media (max-width: 640px) {
  :root { --topbar-h: 52px; --pad-x: 2px; }
  body.has-scrubber { --scrub-w: 0px; }
  .topbar { padding: 0 8px 0 12px; gap: 12px; }
  .user-menu summary span { display: none; }
  .content { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .bottomnav {
    position: fixed; inset: auto 0 0 0; z-index: 20;
    display: flex; justify-content: space-around;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
    background: rgba(17, 18, 20, .95); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 4px 16px; }
  .bottomnav a.active { color: var(--accent); }
  .page-head { padding: 12px 8px 16px; }
  .page-head h1 { font-size: 22px; }
  .album-head { gap: 8px; padding-left: 0; }
  .grid-month span { font-size: 18px; }
  .grid-head { padding-left: 8px; }
  .panel { padding: 16px; margin: 0 6px 16px; border-radius: 14px; }
  .stats, .alert { margin-left: 6px; margin-right: 6px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .tabs { margin-left: 0; }
  table.users thead { display: none; }
  .users tr { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
  .users td { border: 0; padding: 0; }
  .users td:nth-child(3) { grid-column: 1 / -1; }
  .users input { width: 100%; }
  .form-row label { width: 100%; }
  /* scrubber: thin strip at the edge, labels only while dragging */
  .scrubber { width: 28px; bottom: 80px; }
  .scrub-year, .scrub-dot { opacity: 0; transition: opacity .2s; }
  .scrubber.dragging .scrub-year { opacity: 1; }
  .scrub-indicator { width: 6px; height: 36px; right: 2px; border-radius: 3px; transform: translateY(-18px); opacity: .8; }
  .scrub-tip { right: 36px; }
  .tile .check { opacity: 0; }
  body.selecting .tile .check { opacity: 1; }
  .album-actions .btn { padding: 5px 10px; }
  .album-list { grid-template-columns: repeat(2, 1fr); gap: 18px 10px; padding: 0 8px; }
  .viewer.info-open .v-stage, .viewer.info-open .v-bar { right: 0; bottom: 55vh; }
  .v-info { top: auto; width: auto; left: 0; height: 55vh; transform: translateY(100%); border-radius: 16px 16px 0 0; }
}
