/*
 * The photo gallery shared by guest links, legacy public galleries, and the
 * owner's gallery in the account area: photo grid, viewer, owner sharing.
 * Colors come from --gallery-* variables that each host stylesheet defines
 * (guest.css, account.css, and staff.css), so the gallery matches its surroundings.
 */
body.viewer-open { overflow: hidden; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.gallery img, .photo-viewer img { color: transparent; }
.gallery svg, .photo-viewer svg { flex: 0 0 auto; }
.gallery :is(button, a), .photo-viewer :is(button, a) { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.gallery button:disabled, .photo-viewer button:disabled { opacity: .35; cursor: default; }

/* ---------------------------------------------------------- Buttons */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 46px; border-radius: 14px; padding: 12px 18px; border: 1px solid transparent; font: inherit; font-size: 13px; font-weight: 650; line-height: 1.2; white-space: nowrap; text-decoration: none; cursor: pointer; transition: background .18s, transform .18s; }
.button svg { width: 19px; height: 19px; }
.button-primary { background: var(--gallery-accent); color: var(--gallery-on-accent); }
.button-primary:hover { background: #7cc7bf; }
.button-secondary { background: var(--gallery-elevated); border-color: var(--gallery-border); color: var(--gallery-fg); }
.button-secondary:hover { background: var(--gallery-muted); }
.button:active:not(:disabled) { transform: scale(.97); }

/* ---------------------------------------------------------- Grid */
.gallery-hint { margin: 7px 0 0; color: var(--gallery-secondary); font-size: 13px; }
.photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.photo-grid:has(.photo-card:only-child) { grid-template-columns: minmax(0, 1fr); max-width: 1100px; margin-inline: auto; }
.photo-grid:has(.photo-card:nth-child(2):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 1100px; margin-inline: auto; }
@media (min-width: 601px) { .photo-grid:has(.photo-card:nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.photo-card { position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 16px; background: var(--gallery-muted); isolation: isolate; }
/* Alt text stays available to assistive technology but is never painted while a photo loads. */
.photo-card img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease, opacity .25s; }
.photo-card:only-child { aspect-ratio: 3 / 2; }
.photo-card:only-child img { object-fit: contain; }
.photo-card:focus-visible { outline-offset: 3px; }
@media (hover: hover) { .photo-card:hover img { transform: scale(1.035); } }
.photo-fallback { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; flex-direction: column; gap: 10px; color: var(--gallery-secondary); font-size: 12px; }
.photo-card.is-error img { opacity: 0; }
.photo-card.is-error .photo-fallback { display: flex; }
/* A photo still processing: a muted tile with a spinner, as in the desktop app. */
.photo-processing { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.photo-spinner { width: 22px; height: 22px; border: 2px solid color-mix(in srgb, var(--gallery-secondary) 25%, transparent); border-top-color: var(--gallery-secondary); border-radius: 50%; animation: gallery-spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .photo-spinner { animation-duration: 2.4s; } }
.gallery-pagination { display: flex; justify-content: center; gap: 12px; padding: 32px 0 0; }
.gallery-pagination:empty { display: none; }
.empty-state { min-height: 52vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 48px 20px; }
.empty-state h2, .empty-state h1 { margin: 0; color: var(--gallery-fg); font-size: 23px; font-weight: 700; letter-spacing: -.6px; }
.empty-state p { font-size: 14px; line-height: 1.6; color: var(--gallery-secondary); max-width: 300px; margin: 12px 0 24px; }
.empty-art { width: 150px; height: 120px; position: relative; margin-bottom: 30px; }
.empty-art span { position: absolute; top: 10px; left: 27px; width: 96px; height: 100px; border: 1px solid var(--gallery-border); border-radius: 15px; background: var(--gallery-elevated); box-shadow: 0 8px 25px #00000008; }
.empty-art span:first-child { transform: rotate(-17deg) translateX(-16px); background: var(--gallery-muted); }
.empty-art span:nth-child(2) { transform: rotate(15deg) translateX(16px); background: var(--gallery-muted); }
.empty-art span:last-child { display: grid; place-items: center; transform: rotate(-3deg); color: var(--gallery-accent-text); }
.empty-art svg { width: 32px; height: 32px; }
.noscript-note { text-align: center; color: var(--gallery-secondary); font-size: 13px; margin-top: 24px; }

/* ---------------------------------------------------------- Viewer */
/* The viewer is always dark, just like the native galleries. */
.photo-viewer { --gallery-fg: #fafafa; --gallery-secondary: #b4b4bd; --gallery-elevated: #222225; --gallery-muted: #303034; --gallery-border: #444449; --gallery-accent-text: #7fd0c6; position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; color: #fff; background: #080809; overflow: hidden; color-scheme: dark; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.photo-viewer[open] { display: flex; flex-direction: column; animation: viewer-in .2s ease-out; }
.photo-viewer::backdrop { background: #080809; }
.photo-viewer p { margin: 0; }
.viewer-topbar { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 16px; padding: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left)); }
.icon-button { width: 46px; height: 46px; display: inline-flex; justify-content: center; align-items: center; flex: 0 0 auto; padding: 0; border: 1px solid #ffffff0d; border-radius: 50%; color: inherit; background: #ffffff12; cursor: pointer; transition: background .18s; }
.icon-button:hover:not(:disabled) { background: #ffffff24; }
.viewer-count { flex-shrink: 0; font-size: 13px; font-weight: 550; font-variant-numeric: tabular-nums; color: #ffffffb3; }
.viewer-brand { min-width: 0; max-width: 45%; text-align: right; }
.viewer-brand .guest-brand-name { display: block; font-size: 15px; letter-spacing: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.viewer-brand .logo { width: 118px; height: 20px; }
.viewer-stage { position: relative; display: flex; align-items: center; justify-content: center; flex: 1; min-height: 0; margin: 0 72px; touch-action: pan-y pinch-zoom; }
.viewer-image { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; }
.viewer-image.is-loading { opacity: 0; }
.viewer-loading, .viewer-error { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 20px; color: #ffffffb3; }
.viewer-error { z-index: 1; font-size: 14px; }
.viewer-error > svg { width: 36px; height: 36px; color: #ffffff66; }
.viewer-previous, .viewer-next { position: absolute; top: 50%; transform: translateY(-50%); background: #1c1c20dd; backdrop-filter: blur(12px); z-index: 2; }
.viewer-previous { left: -58px; }
.viewer-next { right: -58px; }
.viewer-bottom { flex-shrink: 0; padding: 16px max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
.filmstrip { display: flex; gap: 7px; overflow-x: auto; overscroll-behavior-x: contain; max-width: 520px; margin: 0 auto 18px; padding: 4px; scrollbar-width: none; }
.filmstrip::-webkit-scrollbar { display: none; }
.filmstrip button { background: #222225; border: 0; border-radius: 7px; padding: 0; width: 46px; height: 46px; overflow: hidden; flex: 0 0 auto; opacity: .45; cursor: pointer; transition: opacity .2s; }
.filmstrip button[aria-current="true"] { opacity: 1; outline: 2px solid var(--gallery-accent); outline-offset: 2px; }
.filmstrip button:hover { opacity: 1; }
.filmstrip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewer-actions { display: flex; justify-content: center; align-items: center; gap: 10px; }
.button-download { background: var(--gallery-accent); color: var(--gallery-on-accent); min-width: 155px; }
.button-download:hover { background: #7cc7bf; }
.button-glass { color: #fff; background: #ffffff12; border-color: #ffffff0a; min-width: 155px; }
.button-glass:hover { background: #ffffff24; }
.toast { position: fixed; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; width: max-content; max-width: calc(100vw - 32px); margin: 0; background: #f4f4f5; color: #18181b; border: 1px solid #ddd; border-radius: 14px; padding: 14px 20px; box-shadow: 0 8px 40px #0003; text-align: center; font-size: 13px; line-height: 1.5; }
.photo-viewer .toast { bottom: max(156px, calc(env(safe-area-inset-bottom) + 136px)); }
.spinner { display: block; width: 26px; height: 26px; border: 2px solid #ffffff25; border-top-color: var(--gallery-accent); border-radius: 50%; animation: gallery-spin .8s linear infinite; }
@keyframes gallery-spin { to { transform: rotate(360deg); } }
@keyframes viewer-in { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }

@media (min-width: 1400px) { .photo-grid { gap: 16px; } }
@media (max-width: 1000px) { .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px) {
  .gallery-hint { font-size: 11px; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .photo-card { border-radius: 11px; aspect-ratio: 1; }
  .viewer-topbar { padding-right: 16px; padding-left: 16px; }
  .viewer-stage { margin: 0; }
  .viewer-previous { left: 10px; }
  .viewer-next { right: 10px; }
  .viewer-previous, .viewer-next { width: 44px; height: 44px; background: #0006; }
  .viewer-previous svg, .viewer-next svg { width: 18px; height: 18px; }
  .viewer-bottom { padding-right: 16px; padding-left: 16px; }
  .viewer-actions { gap: 8px; }
  .viewer-actions .button { min-width: 0; flex: 1; padding: 13px 12px; }
  .filmstrip { margin-bottom: 14px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .viewer-topbar { padding-top: 8px; padding-bottom: 4px; }
  .filmstrip { display: none; }
  .viewer-bottom { padding-top: 8px; padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .gallery *, .photo-viewer, .photo-viewer * { animation: none !important; transition: none !important; }
}
