/* =============================================================================
   Zurich Sailing – Öffentliche Galerie
   Stil angelehnt an zsv-sstr5.clubdesk.com (Roboto, #044c77, #1a73e8)
   ============================================================================= */

/* ---------------------------------------------------------------------------
   Custom Properties
   --------------------------------------------------------------------------- */

:root {
    --color-primary:   #044c77;
    --color-accent:    #1a73e8;
    --color-light:     #cde7f3;
    --color-bg:        #f5f9fc;
    --color-surface:   #ffffff;
    --color-text:      #1a1a1a;
    --color-muted:     #5d7085;
    --color-border:    #d0dae6;
    --color-overlay:   rgba(0, 0, 0, .88);
    --radius:          0.375rem;
    --gap:             6px;
    --header-h:        60px;
    --font:            'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition:      .2s ease;
}

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-weight: 400;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.5;
}

img { display: block; max-width: 100%; }

a { color: var(--color-accent); }

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */

.gallery-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-primary);
    color: #fff;
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    box-shadow: 0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);
}

.gallery-header__brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.0625rem;
    white-space: nowrap;
}

.gallery-header__brand svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.gallery-header__spacer { flex: 1; }

.gallery-header__admin {
    font-size: .875rem;
    color: #fff;
    text-decoration: none;
    padding: .3125rem 1.25rem;
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,.7);
    transition: background var(--transition);
    white-space: nowrap;
    background: transparent;
}

.gallery-header__admin:hover {
    background: var(--color-light);
    color: var(--color-primary);
    border-color: var(--color-light);
}

/* ---------------------------------------------------------------------------
   Kategorie-Navigation
   --------------------------------------------------------------------------- */

.gallery-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.gallery-nav::-webkit-scrollbar { display: none; }

.gallery-nav__list {
    display: flex;
    gap: .375rem;
    padding: .625rem 0;
    list-style: none;
    white-space: nowrap;
}

.gallery-nav__link {
    display: inline-block;
    padding: .3125rem 1rem;
    border-radius: 50px;
    font-size: .875rem;
    font-weight: 400;
    text-decoration: none;
    color: var(--color-muted);
    background: transparent;
    border: 1px solid transparent;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.gallery-nav__link:hover {
    background: var(--color-light);
    color: var(--color-primary);
    border-color: var(--color-light);
}

.gallery-nav__link.is-active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* ---------------------------------------------------------------------------
   Galerie-Grid (CSS Grid – stabil, kein Layout-Shift)
   --------------------------------------------------------------------------- */

.gallery-main {
    padding: var(--gap);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--color-border);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    transition: box-shadow .2s ease;
}

.gallery-item:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

.gallery-item__link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.gallery-item__img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
    /* Hintergrundfarbe zeigt sich solange das Bild lädt */
    background: var(--color-border);
}

.gallery-item:hover .gallery-item__img {
    transform: scale(1.03);
}

/* Overlay mit Metadaten */
.gallery-item__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: .875rem .75rem .625rem;
    background: linear-gradient(transparent, rgba(0,0,0,.65));
    color: #fff;
    opacity: 0;
    transition: opacity var(--transition);
    pointer-events: none;
}

.gallery-item:hover .gallery-item__caption,
.gallery-item:focus-within .gallery-item__caption {
    opacity: 1;
}

.gallery-item__title {
    font-size: .875rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: .2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item__meta {
    font-size: .75rem;
    font-weight: 300;
    opacity: .85;
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

/* No-JS Fallback: caption always visible */
.no-js .gallery-item__caption {
    opacity: 1;
    position: static;
    background: none;
    color: var(--color-text);
    padding: .5rem .625rem;
}

.no-js .gallery-item__title { color: var(--color-text); font-weight: 700; }
.no-js .gallery-item__meta  { color: var(--color-muted); }

/* ---------------------------------------------------------------------------
   Leerer Zustand
   --------------------------------------------------------------------------- */

.gallery-empty {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--color-muted);
}

.gallery-empty__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: .4;
}

.gallery-empty p { font-size: 1rem; }

/* ---------------------------------------------------------------------------
   "Mehr laden" Button / Ladeindikator
   --------------------------------------------------------------------------- */

.gallery-footer {
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
    gap: 1rem;
}

.btn-load-more {
    padding: .5625rem 2rem;
    border-radius: 50px;
    background: var(--color-primary);
    color: #fff;
    font-family: var(--font);
    font-size: .9375rem;
    font-weight: 400;
    border: 1px solid var(--color-primary);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background var(--transition), border-color var(--transition);
}

.btn-load-more:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.btn-load-more:disabled { opacity: .45; cursor: not-allowed; }
.btn-load-more.is-loading { opacity: .6; }

.load-spinner {
    display: none;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.btn-load-more.is-loading .load-spinner { display: inline-block; }
.btn-load-more.is-loading .load-text   { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Lightbox
   --------------------------------------------------------------------------- */

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: var(--color-overlay);
    align-items: center;
    justify-content: center;
    overscroll-behavior: contain;
}

.lightbox.is-open {
    display: flex;
}

.lightbox__inner {
    position: relative;
    max-width: min(92vw, 1400px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox__img-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox__img {
    max-width: min(92vw, 1400px);
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 8px 48px rgba(0,0,0,.6);
    display: block;
}

.lightbox__info {
    width: 100%;
    padding: .75rem 1rem .25rem;
    color: rgba(255,255,255,.9);
    display: flex;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.lightbox__title {
    font-size: 1rem;
    font-weight: 700;
    flex: 1;
}

.lightbox__meta {
    font-size: .8125rem;
    font-weight: 300;
    color: rgba(255,255,255,.65);
    white-space: nowrap;
}

/* Navigation Buttons */
.lightbox__btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.375rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    z-index: 9010;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.lightbox__btn:hover { background: rgba(255,255,255,.25); }
.lightbox__btn:disabled { opacity: .2; cursor: default; }

.lightbox__prev { left: 1rem; }
.lightbox__next { right: 1rem; }

/* Schliessen-Button */
.lightbox__close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    z-index: 9010;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    line-height: 1;
}

.lightbox__close:hover { background: rgba(255,255,255,.25); }

/* Zähler */
.lightbox__counter {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,.65);
    font-size: .8125rem;
    background: rgba(0,0,0,.35);
    padding: .2rem .75rem;
    border-radius: 9999px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9010;
    pointer-events: none;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */

.gallery-page-footer {
    text-align: center;
    padding: 2.5rem 1rem;
    border-top: 1px solid var(--color-border);
    color: var(--color-muted);
    font-size: .8125rem;
    font-weight: 300;
    margin-top: 1rem;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .gallery-grid { grid-template-columns: repeat(3, 1fr); }
    .lightbox__btn { width: 40px; height: 40px; font-size: 1.125rem; }
    .lightbox__prev { left: .5rem; }
    .lightbox__next { right: .5rem; }
}

@media (max-width: 600px) {
    :root { --gap: 4px; }
    .gallery-grid { grid-template-columns: repeat(2, 1fr); }
    .gallery-header { padding: 0 1rem; }
    .gallery-header__brand span { display: none; }
    .lightbox__btn { display: none; }  /* Mobile: Swipe statt Buttons */
}

@media (max-width: 360px) {
    .gallery-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Skeleton-Screens (Loading States)
   --------------------------------------------------------------------------- */

@keyframes skeleton-pulse {
    0%   { opacity: 1; }
    50%  { opacity: .45; }
    100% { opacity: 1; }
}

.gallery-skeleton {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-border);
    animation: skeleton-pulse 1.4s ease-in-out infinite;
    aspect-ratio: 4 / 3;
}

.gallery-skeleton__img {
    width: 100%;
    height: 100%;
    background: var(--color-border);
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    .gallery-skeleton { animation: none; opacity: .6; }
}

/* ---------------------------------------------------------------------------
   Accessibility
   --------------------------------------------------------------------------- */

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
