/* ==========================================================================
   FOTO BERN – Kundengalerie
   Minimalistisch, hell, viel Weissraum.
   ========================================================================== */

:root {
  --dark: #1A1A18;
  --grey: #888780;
  --bg: #FAFAF8;
  --white: #FFFFFF;
  --line: #E6E5E0;
  --shadow: 0 1px 3px rgba(26, 26, 24, .06), 0 8px 30px rgba(26, 26, 24, .06);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: var(--sans);
  color: var(--dark);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 500; line-height: 1.15; margin: 0 0 .4em; }

a { color: inherit; }

.muted { color: var(--grey); }
.tiny { font-size: .8rem; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .85rem; }

/* -- Marke ---------------------------------------------------------------- */
.brand {
  font-family: var(--serif);
  font-size: 2rem;
  letter-spacing: .04em;
  font-weight: 600;
  margin-bottom: .6rem;
}
.brand span { color: var(--grey); }
.brand.small { font-size: 1.25rem; margin: 0; text-decoration: none; }
.brand em { font-style: normal; color: var(--grey); font-size: .8em; }

/* -- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-block;
  font-family: var(--sans);
  font-size: .9rem;
  font-weight: 500;
  letter-spacing: .02em;
  padding: .7rem 1.4rem;
  border: 1px solid var(--dark);
  background: var(--dark);
  color: var(--white);
  border-radius: 2px;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .2s, background .2s, color .2s;
  white-space: nowrap;
}
.btn:hover { opacity: .82; }
.btn.ghost { background: transparent; color: var(--dark); }
.btn.ghost:hover { background: var(--dark); color: var(--white); opacity: 1; }
.btn.small { padding: .5rem .9rem; font-size: .82rem; }
.btn.danger-btn { background: #8a2b22; border-color: #8a2b22; }

/* -- Zentrierte Karten (Login etc.) --------------------------------------- */
.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}
.card {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 4px;
  padding: 2.5rem 2.25rem;
  width: 100%;
  text-align: center;
}
.card.narrow { max-width: 400px; }
/* Eingangsseite /galerie/ */
.entry-card .gallery-title { margin-bottom: .4rem; }
.entry-card p { margin: .55rem 0 0; }
.entry-card .entry-back { margin-top: 1.7rem; }
/* Logo auf Login-/Kartenseiten (weisses PNG per Filter ins Dunkle gekehrt) */
.brand-logo {
  display: block;
  height: 64px;
  width: auto;
  margin: 0 auto 1.3rem;
  filter: brightness(0);
}
.gallery-title { font-family: var(--serif); font-size: 1.8rem; font-weight: 500; }

/* -- Formulare ------------------------------------------------------------ */
.stack { display: flex; flex-direction: column; gap: 1.1rem; text-align: left; margin-top: 1.5rem; }
.field { display: flex; flex-direction: column; gap: .4rem; }
.field > span { font-size: .82rem; color: var(--grey); font-weight: 500; }
input[type=text], input[type=password], input[type=date], textarea {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--dark);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: .7rem .8rem;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--dark); }
textarea { resize: vertical; }
.form-actions { display: flex; gap: .8rem; align-items: center; }

.alert {
  background: #fbeeec;
  border: 1px solid #e6c9c4;
  color: #8a2b22;
  padding: .7rem .9rem;
  border-radius: 2px;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.notice {
  background: #eef3ee;
  border: 1px solid #cfe0cf;
  color: #2f5133;
  padding: .7rem .9rem;
  border-radius: 2px;
  font-size: .9rem;
  margin-bottom: 1.5rem;
}

/* ==========================================================================
   Öffentliche Galerie
   ========================================================================== */
/* Nur vertikales Wischen zulassen – kein horizontales Verziehen/Zoomen der Seite.
   (Gezoomt wird ausschliesslich in der Lightbox.) */
.gallery-page { background: var(--white); touch-action: pan-y; }

.gallery-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.gallery-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}
/* Logo im Header: weisses PNG per Filter ins Dunkle gekehrt (helle Leiste) */
.gallery-logo {
  display: block;
  height: 44px;
  width: auto;
  filter: brightness(0);
}

.gallery-actions { display: flex; gap: .5rem; align-items: center; }
/* Dezente, zurückhaltende Aktions-Buttons im Galerie-Header */
.gallery-actions .btn {
  padding: .42rem .9rem;
  font-size: .82rem;
  font-weight: 500;
  border-radius: 100px;
}
.gallery-actions .btn.ghost {
  border-color: var(--line);
  color: var(--grey);
}
.gallery-actions .btn.ghost:hover {
  background: transparent;
  color: var(--dark);
  border-color: var(--grey);
  opacity: 1;
}

.share-menu {
  position: fixed;
  /* rechtsbündig zum Header-Inhalt (max. 1400px breit zentriert) */
  right: max(1.5rem, calc(50vw - 700px + 1.5rem));
  top: 4.1rem;
  z-index: 40;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-width: 150px;
  overflow: hidden;
}
/* Wichtig: hält das Menü verborgen, bis JS es öffnet. Ohne diese Regel würde
   das display:flex oben das hidden-Attribut überstimmen (Menü immer sichtbar). */
.share-menu[hidden] { display: none; }
.share-menu button, .share-menu a {
  padding: .55rem .85rem;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  font: inherit;
  font-size: .84rem;
  color: var(--dark);
  cursor: pointer;
  text-decoration: none;
}
.share-menu button:last-child, .share-menu a:last-child { border-bottom: none; }
.share-menu button:hover, .share-menu a:hover { background: var(--bg); }

/* -- Titelbild (Hero) ----------------------------------------------------- */
.hero {
  position: relative;
  width: 100%;
  height: 78vh;
  min-height: 340px;
  overflow: hidden;
  background: var(--dark);
}
.hero__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hero__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(20, 20, 18, .30), rgba(20, 20, 18, .42));
}
/* Feiner Rahmen im Titelbild (wie bei Pic-Time) */
.hero::after {
  content: "";
  position: absolute;
  inset: 22px;
  border: 1px solid rgba(255, 255, 255, .5);
  pointer-events: none;
}
.hero__content {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 1.5rem;
}
.hero__title {
  font-family: var(--serif);
  font-weight: 400;
  color: #fff;
  font-size: clamp(1.8rem, 5.2vw, 3.9rem);
  line-height: 1.18;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .09em;
  /* gleicht den Abstand hinter dem letzten Buchstaben aus, damit die
     Zeile trotz Laufweite exakt mittig sitzt */
  text-indent: .09em;
  text-shadow: 0 2px 30px rgba(0, 0, 0, .35);
}
.hero__sub {
  font-family: var(--serif);
  font-style: italic;
  color: rgba(255, 255, 255, .95);
  font-size: clamp(1.1rem, 2.2vw, 1.65rem);
  letter-spacing: .02em;
  margin: 1.5rem 0 0;
  text-shadow: 0 2px 20px rgba(0, 0, 0, .35);
}
/* Feine Trennlinie zwischen Titel und Untertitel */
.hero__sub::before {
  content: "";
  display: block;
  /* wächst mit der Bildschirmbreite mit, bleibt aber in Massen */
  width: clamp(100px, 13vw, 170px);
  height: 1px;
  margin: 0 auto 1.2rem;
  background: rgba(255, 255, 255, .55);
}
.hero__scroll {
  position: absolute;
  bottom: 2.6rem; /* innerhalb des feinen Rahmens */
  left: 50%;
  color: rgba(255, 255, 255, .85);
  font-size: 2rem;
  line-height: 1;
  text-decoration: none;
  animation: heroBounce 2.4s ease-in-out infinite;
}
@keyframes heroBounce {
  0%, 100% { transform: translate(-50%, 0); }
  50%      { transform: translate(-50%, 9px); }
}
@media (prefers-reduced-motion: reduce) {
  .hero__scroll { animation: none; transform: translateX(-50%); }
}

/* Bildraster über die volle Bildschirmbreite – nur der Textblock bleibt schmal. */
.gallery-main { margin: 0 auto; padding: 3rem 0 5rem; }
.gallery-intro { text-align: center; max-width: 640px; margin: 0 auto 3rem; padding: 0 1.5rem; }
.gallery-intro .gallery-title { font-size: 2.4rem; }
/* Einleitungstext: Serif, grösser, angenehme Zeilenlänge */
.intro-text {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.6;
  color: #6f6e68;
  max-width: 46ch;
  margin: 1.2rem auto 0;
}
.centered-text { text-align: center; }

/* Masonry-artiges Raster über CSS-Spalten */
/* Zeilenweises Layout ("justified rows", wie bei Pic-Time/Flickr):
   Bilder folgen strikt der Reihenfolge von links nach rechts, jede Zeile füllt
   die Breite bündig aus. CSS-Spalten wären zwar hübsch, füllen sich aber
   spaltenweise – dadurch wirkt die Reihenfolge zufällig. */
.grid {
  display: flex;
  flex-wrap: wrap;
  /* Feine Trennung, damit jedes Foto als eigenes Bild lesbar bleibt */
  gap: 3px;
  /* Zeilenhöhe wächst mit dem Bildschirm – steuert zugleich, wie viele Bilder
     pro Zeile stehen (rund 3). Höher = weniger, aber grössere Bilder. */
  --row-h: clamp(240px, 21vw, 440px);
}
.tile {
  position: relative;
  margin: 0;
  height: var(--row-h);
  /* Breite und Umbruch folgen dem Seitenverhältnis (--ratio je Bild) */
  flex-basis: calc(var(--ratio, 1.5) * var(--row-h));
  flex-grow: calc(var(--ratio, 1.5) * 100);
  cursor: zoom-in;
  background: var(--bg);
  overflow: hidden;
  border-radius: 0;
  min-width: 0;
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .6s ease, opacity .4s;
}
/* Unsichtbare Platzhalter für die letzte Zeile */
.tile-filler {
  height: 0;
  flex-grow: 100;
  flex-basis: 420px;
}
/* Hover-Zoom nur für Geräte mit echter Maus (nicht auf Touch) */
@media (hover: hover) {
  .tile:hover img { transform: scale(1.03); }
}

/* -- Lightbox ------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 20, 18, .96);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
/* Alle Touch-Gesten im Bild selbst behandeln wir per JS (Pinch/Doppeltipp/Pan) */
.lightbox { touch-action: none; }
.lb-image {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  box-shadow: 0 10px 60px rgba(0, 0, 0, .5);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  will-change: transform;
  transform-origin: center center;
  transition: transform .2s ease;
  cursor: zoom-in;
}
.lb-image.zoomed { cursor: zoom-out; }
/* Während aktiver Pinch/Pan-Geste keine Übergangs-Animation */
.lb-image.dragging { transition: none; }
.lb-close, .lb-nav {
  position: absolute;
  z-index: 10;
  background: none;
  border: none;
  color: rgba(255, 255, 255, .85);
  cursor: pointer;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}
.lb-counter { z-index: 10; }
.lb-close:hover, .lb-nav:hover { color: #fff; }
.lb-close { top: 1rem; right: 1.5rem; font-size: 2.4rem; line-height: 1; }
.lb-nav { top: 50%; transform: translateY(-50%); font-size: 3.5rem; padding: 0 1.2rem; }
.lb-prev { left: .5rem; }
.lb-next { right: .5rem; }
.lb-counter {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .7);
  font-size: .85rem;
  letter-spacing: .1em;
}

/* -- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--dark);
  color: var(--white);
  padding: .7rem 1.2rem;
  border-radius: 3px;
  font-size: .88rem;
  z-index: 200;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

/* ==========================================================================
   Admin
   ========================================================================== */
.admin-page { background: var(--bg); }
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.admin-nav { display: flex; gap: 1.4rem; font-size: .9rem; }
.admin-nav a { text-decoration: none; color: var(--grey); }
.admin-nav a:hover { color: var(--dark); }

.admin-main { max-width: 1000px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.narrow-main { max-width: 620px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; }
.admin-head h1 { font-family: var(--serif); font-size: 2rem; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: .85rem 1rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
.admin-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--grey); font-weight: 500; }
.admin-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 1rem; }
.row-actions a { color: var(--grey); text-decoration: none; font-size: .88rem; }
.row-actions a:hover { color: var(--dark); }

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}
.panel h2 { font-family: var(--serif); font-size: 1.4rem; margin-bottom: 1.2rem; }
.panel.danger { border-color: #e6c9c4; }

.access-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.copy-row { display: flex; gap: .5rem; }
.copy-row input { flex: 1; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 4px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--grey);
  transition: border-color .2s, background .2s;
}
.dropzone.dragover { border-color: var(--dark); background: var(--bg); }
.link-label { color: var(--dark); text-decoration: underline; cursor: pointer; }

.upload-progress { margin-top: 1rem; }
.upload-progress__bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.upload-progress__bar span { display: block; height: 100%; width: 0; background: var(--dark); transition: width .2s; }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 1.5rem;
}
.thumb-item { position: relative; margin: 0; aspect-ratio: 1; background: var(--bg); border-radius: 2px; overflow: hidden; }
.thumb-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del {
  position: absolute;
  top: 5px; right: 5px;
  width: 26px; height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(26, 26, 24, .75);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
}
.thumb-item:hover .thumb-del { opacity: 1; }
.thumb-del:hover { background: #8a2b22; }

/* Titelbild-Auswahl */
.thumb-cover {
  position: absolute;
  top: 5px; left: 5px;
  width: 26px; height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(26, 26, 24, .7);
  color: rgba(255, 255, 255, .9);
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s, background .2s;
}
.thumb-item:hover .thumb-cover { opacity: 1; }
.thumb-cover:hover { background: var(--dark); color: #fff; }
.thumb-item.is-cover .thumb-cover { opacity: 1; background: var(--dark); color: #fff; }
.thumb-item.is-cover { outline: 3px solid var(--dark); outline-offset: -3px; }

/* Vorschaubild in der Galerie-Übersicht */
.cover-cell { width: 72px; }
.cover-thumb {
  display: block;
  width: 60px;
  height: 42px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.cover-thumb--empty {
  background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 5px, #f2f1ed 5px, #f2f1ed 10px);
}

/* Vorschau des Titelbild-Ausschnitts (Seitenverhältnis wie im Kunden-Header) */
.cover-preview {
  width: 100%;
  aspect-ratio: 24 / 10;
  overflow: hidden;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  margin: .2rem 0 .6rem;
}
.cover-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: object-position .25s ease;
}

/* Vorschaubilder vorbereiten */
.prepare-box {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.prepare-box p { margin-top: 0; }


/* -- Responsive ----------------------------------------------------------- */
@media (max-width: 640px) {
  .gallery-intro .gallery-title { font-size: 1.9rem; }
  .access-grid { grid-template-columns: 1fr; }
  .admin-head { flex-direction: column; align-items: flex-start; }
  .gallery-header__inner { padding: .7rem .9rem; }
  .btn { padding: .6rem 1rem; font-size: .85rem; }
  .lb-nav { font-size: 2.5rem; padding: 0 .6rem; }

  /* Titelbild auf dem Handy etwas flacher */
  .hero { height: 62vh; min-height: 300px; }

  /* Galerie randlos: Bilder füllen die Bildschirmbreite bis zum Rand */
  .gallery-main { padding: 1.25rem 0 3rem; }
  .gallery-intro { padding: 0 1.25rem; margin-bottom: 1.75rem; }
  /* Einspaltig, volle Breite, natürliches Seitenverhältnis (kein Beschnitt) */
  .grid { display: block; }
  .tile { height: auto; margin-bottom: 3px; border-radius: 0; }
  .tile img { height: auto; }
  .tile-filler { display: none; }

  /* Teilen/Download noch dezenter */
  .gallery-actions { gap: .4rem; }
  .gallery-actions .btn { padding: .38rem .8rem; font-size: .8rem; }
  .brand.small { font-size: 1.1rem; }
  .gallery-logo { height: 34px; }

  /* Teilen-Menü als Bottom-Sheet – schiebt von unten herein, verdeckt den
     Galerietitel nicht (Fallback, falls das native Teilen nicht verfügbar ist) */
  .share-menu {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    margin: 0;
    min-width: 0;
    border: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 40px rgba(26, 26, 24, .18);
    z-index: 300;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .share-menu button, .share-menu a {
    padding: .62rem 1.2rem;
    font-size: .86rem;
    text-align: center;
  }
}
