/* Mobile-first dark theme. Served versioned via the layout's asset func. */

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #1a1d23;
  --surface-2: #242933;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #8ab4f8;
  --danger: #f28b82;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { overflow-x: clip; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* Form controls at ≥16px: below that, iOS Safari zooms the page on focus. */
input, select, textarea, button { font-size: 1rem; font-family: inherit; }

/* One consistent keyboard-focus ring: browser defaults are faint on the dark
   round icon buttons, and tap-highlight is suppressed above. :focus-visible
   keeps it off mouse/touch interactions. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type=file] { max-width: 100%; }

input[type=text], textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid #3a3f4a;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.version-tag { margin-top: 2.5rem; font-size: .8rem; color: var(--muted); text-align: center; }
code {
  background: var(--surface-2);
  padding: .15rem .4rem;
  border-radius: 6px;
  word-break: break-all;
}

/* --- Floating chrome (back / account) over the banner --- */

.chrome {
  position: fixed;
  top: env(safe-area-inset-top);
  left: env(safe-area-inset-left);
  right: env(safe-area-inset-right);
  display: flex;
  justify-content: space-between;
  padding: .5rem;
  z-index: 10;
  pointer-events: none;
}
.chrome > * { pointer-events: auto; }
.chrome-right { margin-left: auto; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(15, 17, 21, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn svg { width: 22px; height: 22px; }

/* Small variant for per-photo action bars: quieter, still a 40px hit area. */
.icon-btn--sm {
  width: 40px;
  height: 40px;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--muted);
}
.icon-btn--sm svg { width: 20px; height: 20px; }
.icon-btn--sm:active { color: var(--text); }
.icon-btn--danger { color: var(--danger); }

/* --- Copy / QR actions next to share and enrollment links --- */

.copy-btn span { display: contents; }
.copy-btn .copy-done { display: none; }
.copy-btn.copied .copy-idle { display: none; }
.copy-btn.copied .copy-done { display: contents; }
.copy-btn.copied { color: var(--accent); }

details.qr summary { list-style: none; }
details.qr summary::-webkit-details-marker { display: none; }
details.qr[open] summary { color: var(--text); }
/* Rows holding these actions are wrapping flex rows; an open QR takes a
   full row of its own so the image never squeezes the link text. */
details.qr[open] { flex-basis: 100%; }
.qr-img {
  display: block;
  margin: .5rem auto;
  border-radius: 8px;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
.link-row code { flex: 1; min-width: 12rem; }

/* --- Headers: photo hero fading into the page, or a plain dark header --- */

.hero {
  position: relative;
  height: 38vh;
  min-height: 200px;
  max-height: 420px;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: flex-end;
}
.hero-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
    rgba(15, 17, 21, .35), rgba(15, 17, 21, 0) 35%, var(--bg) 100%);
}
.hero h1 {
  position: relative;
  margin: 0 auto .25rem;
  padding: 0 1rem;
  width: 100%;
  max-width: 48rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, .6);
}

header.plain {
  max-width: 48rem;
  margin: 0 auto;
  padding: calc(52px + env(safe-area-inset-top)) 1rem 0;
}
header.plain h1 { margin: .5rem 0 0; }

main {
  max-width: 48rem;
  margin: 0 auto;
  padding: .25rem 1rem calc(3rem + env(safe-area-inset-bottom));
}

/* --- Cards, buttons, forms --- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}
.card h2 { margin-top: 0; }

/* Account page: disk-usage meter for photo storage. */
.storage-meter {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}
.storage-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
}
.storage p { margin: .5rem 0 0; font-size: .85rem; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  min-height: 48px;
  margin: .75rem 0;
  padding: .6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #10131a; font-weight: 600; }
.btn-danger { color: var(--danger); }

/* --- Floating add-photos button --- */

/* A hidden file input sits next to it; upload.js opens the picker on tap and
   swaps the + for "Uploading… i/n" text while files go up. */
.fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  min-width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 28px;
  background: var(--accent);
  color: #10131a;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
}
.fab svg { width: 26px; height: 26px; }
.fab.is-busy { padding: 0 1.1rem; }

/* Keep the page's last controls reachable under the floating button. */
main:has(.fab) { padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }

/* --- Floating edit (gear) button --- */

/* Mirrors the add button in the opposite (bottom-left) corner so edit mode is
   reachable however far the grid is scrolled. Quieter than the accent fab: the
   glassy icon-btn look, tinting to the accent while edit mode is on. */
.fab-gear {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 15;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(15, 17, 21, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
}
.fab-gear svg { width: 24px; height: 24px; }
.fab-gear[aria-pressed="true"] { color: var(--accent); background: var(--surface-2); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

/* --- Loading feedback (busy.js) --- */

/* Indeterminate bar along the top while a navigation or form post is in
   flight; the installed PWA shows no browser spinner of its own. */
.busy-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 20;
  pointer-events: none;
  visibility: hidden;
  overflow: hidden;
}
.busy-bar.on { visibility: visible; }
.busy-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: 3px;
  background: var(--accent);
  animation: busy-slide 1.2s ease-in-out infinite;
}
@keyframes busy-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

.is-busy { pointer-events: none; }
.btn.is-busy { opacity: .75; }
.btn.is-busy::after,
.fab.is-busy::after,
.icon-btn.is-busy::after {
  content: "";
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: busy-spin .7s linear infinite;
}
.icon-btn.is-busy svg { display: none; }
@keyframes busy-spin {
  to { transform: rotate(360deg); }
}

/* Loading feedback stays (it's information, not decoration), but for users
   who ask for reduced motion the sliding bar and spinning arcs become a
   gentle opacity pulse. */
@media (prefers-reduced-motion: reduce) {
  .busy-bar::before {
    width: 100%;
    animation: busy-fade 2s ease-in-out infinite;
  }
  .btn.is-busy::after,
  .fab.is-busy::after,
  .icon-btn.is-busy::after {
    border-right-color: currentColor;
    animation: busy-fade 2s ease-in-out infinite;
  }
}
@keyframes busy-fade {
  from, to { opacity: .25; }
  50% { opacity: .85; }
}

.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; }
.inline-form input[type=text] { flex: 1; min-width: 10rem; width: auto; }
.inline-form .btn { width: auto; margin: 0; }

details.edit { margin: 1rem 0; }
details.edit summary { list-style: none; }
details.edit summary::-webkit-details-marker { display: none; }

/* --- Photo / album grids --- */

/* minmax(0, …): plain 1fr tracks refuse to shrink below the tiles'
   min-content width, overflowing the page. */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin: 1rem 0;
}
@media (min-width: 40rem) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
}

.tile { margin: 0; min-width: 0; }
.tile-media { position: relative; }
.tile a { display: block; color: var(--text); text-decoration: none; }
.tile a.ph { position: relative; }

/* One-line caption overlay along the tile's bottom edge, only on photos that
   have a description — its presence is also what marks captioned photos in
   edit mode. Ellipsized to a single line; the full text lives on the photo
   page. In edit mode it slides up clear of the caption bubble and position
   pill that take over the bottom corners. */
.tile-alt {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .8rem;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
body.editing .tile-alt { bottom: 48px; }

/* Caption bubble: sits over the image's lower-left corner, edit mode only. */
.tile-desc {
  display: none;
  position: absolute;
  left: 6px;
  bottom: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  cursor: pointer;
}
body.editing .tile-desc { display: grid; }
.tile-desc svg { width: 18px; height: 18px; }
.tile img, .empty-cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: var(--surface);
}
.empty-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed #3a3f4a;
}
.tile-caption { padding: .25rem .25rem .6rem; line-height: 1.3; }
.tile-caption .muted { display: block; font-size: .85rem; }
/* Per-photo actions overlay the thumbnail's corners — cover top-left, delete
   top-right, move-to-position bottom-right (the caption bubble has the lower
   left) — hidden until the gear (edit.js) turns on the album's edit mode.
   Overlaying instead of a bar under the tile keeps the tile (and page) height
   the same either way. The wrapper spans the tile but lets taps through to
   the photo link; only the controls themselves catch the pointer. */
.tile-actions {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
}
body.editing .tile-actions { display: block; }
.tile-actions form { position: absolute; pointer-events: auto; }
.tile-actions .tile-cover { top: 6px; left: 6px; }
.tile-actions .tile-delete { top: 6px; right: 6px; }
.tile-actions .icon-btn--sm {
  width: 36px;
  height: 36px;
  color: #fff;
  background: rgba(0, 0, 0, .55);
}
.tile-actions .icon-btn--danger { color: var(--danger); }

/* The move-to-position control: a compact number input that both shows the
   photo's current 1-based order and takes a new one, in a dark pill matching
   the other overlay bubbles. */
.pos-form {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.tile-actions .pos-form {
  right: 6px;
  bottom: 6px;
  padding: 2px 2px 2px 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
}
.tile-actions .pos-form .icon-btn--sm {
  width: 32px;
  height: 32px;
  background: none;
}
.pos-input {
  width: 2.75rem;
  padding: 2px 4px;
  text-align: center;
  /* 1rem (16px) is deliberate: iOS Safari zooms the page when a focused input
     is under 16px, and the earlier .8rem here was the one control that tripped
     it. Keep this at/above 1rem — the width above absorbs the wider digits. */
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--surface-2);
  border-radius: 4px;
}

.grid-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  margin: .75rem 0 -.75rem;
}
/* --- Album toolbar: share toggle + panel, edit-mode pen and delete --- */

/* The share disclosure sits in the toolbar row; display:contents makes its
   summary a row item while the open panel wraps to a full-width row of its
   own below. */
details.share { display: contents; }
details.share summary { position: relative; list-style: none; }
details.share summary::-webkit-details-marker { display: none; }
details.share[open] summary { color: var(--text); }
.share-panel { flex-basis: 100%; }

/* Active-share-link count on the share button: a visible reminder that the
   album is reachable by public links. */
.badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #10131a;
  font-size: .7rem;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}

/* Pen (title/description form), sort order and album delete only appear in
   the gear's edit mode, as extra icons in the toolbar row next to share — so
   revealing them never changes the page length. Like the share disclosure,
   display:contents puts each summary in the row while the open panel wraps
   to a full-width row of its own; order pushes panels after every button. */
details.edit-album { display: none; }
body.editing details.edit-album { display: contents; }
details.edit-album summary { list-style: none; }
details.edit-album summary::-webkit-details-marker { display: none; }
details.edit-album[open] summary { color: var(--text); }
.tool-panel { flex-basis: 100%; order: 1; }

/* Sort-order panel: label, select and check submit on a single line, so the
   open panel stays as short as the toolbar allows. The select matches the
   text-input look. */
.sort-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}
.sort-form select {
  flex: 1;
  min-width: 0;
  padding: .5rem .6rem;
  border: 1px solid #3a3f4a;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

form.album-delete { display: none; margin: 0; }
body.editing form.album-delete { display: block; }
.btn svg { width: 20px; height: 20px; }

/* --- Single photo page (full-bleed, native pinch-zoom) --- */

main.bare { max-width: none; margin: 0; padding: 0; }

.photo-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #000;
}
.photo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem;
  padding-left: max(.5rem, env(safe-area-inset-left));
  padding-right: max(.5rem, env(safe-area-inset-right));
}
.photo-bar--top { padding-top: max(.5rem, env(safe-area-inset-top)); }
.photo-bar--nav { padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
.photo-figure {
  flex: 1;
  min-height: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-figure img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.photo-date { font-size: .85rem; }
.icon-btn.is-disabled { opacity: .3; }

/* Owner's capture-date editor: the date text discloses a panel that floats
   above the nav bar, so opening it doesn't shift the layout. */
.photo-date-edit { position: relative; }
.photo-date-edit > summary {
  cursor: pointer;
  list-style: none;
  text-decoration: underline dotted;
  text-underline-offset: .2em;
}
.photo-date-edit > summary::-webkit-details-marker { display: none; }
.photo-date-form {
  position: absolute;
  bottom: calc(100% + .5rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .5rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
  width: max-content;
  max-width: calc(100vw - 1rem);
}
.photo-date-form .btn { width: auto; margin: 0; min-height: 0; padding: .5rem .9rem; }
.photo-date-form input[type=datetime-local] {
  padding: .45rem .6rem;
  border: 1px solid #3a3f4a;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

/* Caption, shown below the navigation. Rendered from minor markdown. */
.photo-desc {
  color: var(--text);
  max-width: 48rem;
  margin: 0 auto;
  padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}
.photo-desc a { color: var(--accent); }

/* Caption editor dialog. */
.desc-dialog {
  width: min(32rem, calc(100vw - 2rem));
  border: 0;
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--surface);
  color: var(--text);
}
.desc-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.desc-dialog h2 { margin: 0 0 .25rem; }
.desc-hint { font-size: .8rem; margin: 0 0 .75rem; }
.desc-hint code { background: var(--surface-2); padding: 0 .2rem; border-radius: 4px; }
.desc-dialog textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
}
.desc-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: .75rem;
}

/* --- Lists --- */

.share-list { list-style: none; padding: 0; }
.share-list li {
  margin: .5rem 0;
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.revoked { text-decoration: line-through; }

.passkey-list { list-style: none; padding: 0; }
.passkey-list li {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin: .5rem 0;
}
.passkey-list .muted { display: block; font-size: .85rem; }

/* --- Share-link activity page --- */

.share-url-line code { word-break: break-all; }

.revoked-badge {
  margin-left: .5rem;
  padding: .1rem .5rem;
  border-radius: 999px;
  background: var(--danger);
  color: #10131a;
  font-size: .8rem;
  font-weight: 600;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .5rem;
  margin-bottom: 1rem;
}

.stat { text-align: center; padding: .75rem .5rem; }
.stat-num { display: block; font-size: 1.6rem; font-weight: 700; }
.stat-num--sm { font-size: 1rem; line-height: 2.2; }
.stat-label { color: var(--muted); font-size: .85rem; }

.chart { width: 100%; height: auto; display: block; }
.chart-bar { fill: var(--accent); }
.chart-axis { stroke: var(--surface-2); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 7px; }

.access-log { overflow-x: auto; }
.access-log table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.access-log th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: .25rem .6rem .25rem 0;
}
.access-log td { padding: .25rem .6rem .25rem 0; border-top: 1px solid var(--surface-2); }
.access-log .nowrap { white-space: nowrap; }

/* Prev/next arrows + "2/5" count that pager.js adds under tables spanning
   more than one page. Sticky-left keeps the controls in view when a wide
   table scrolls horizontally inside .access-log. */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .25rem;
  position: sticky;
  left: 0;
}
.pager .icon-btn:disabled { opacity: .35; cursor: default; }
.pager-count {
  color: var(--muted);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: center;
}
.access-minor { color: var(--muted); }
.access-minor code { color: var(--muted); }

.new-badge {
  padding: .05rem .4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #10131a;
  font-size: .7rem;
  font-weight: 600;
}

.top-photo-cell a {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.top-photo-cell img {
  width: 2.25rem;
  height: 2.25rem;
  object-fit: cover;
  border-radius: .35rem;
}

.attribution { font-size: .8rem; text-align: center; }

/* Share-link overview on the account page. */
.share-overview { margin-top: 1.5rem; }
.share-overview h2 { margin-bottom: .75rem; }
.share-overview .access-log a { font-weight: 500; }
