/*
 * Sessio-Galerie-Laufzeit: Grundgestaltung für Übersicht und Lichtbox.
 * Templates laden diese Datei vor ihrem eigenen style.css und passen das Aussehen über die folgenden
 * Eigenschaften an (am besten auf :root, weil die Lichtbox als <dialog> direkt in <body> liegt):
 *
 *   --sg-bg               Hintergrund der Galerie (Übersicht, Bedienelemente)
 *   --sg-fg               Textfarbe
 *   --sg-muted            Zurückhaltende Textfarbe (Zähler, Hinweise)
 *   --sg-accent           Akzent (Fokus, Markierung „neu“, gewählte Sterne)
 *   --sg-font             Schrift der Bedienelemente (Vorgabe: vom Template geerbt)
 *   --sg-gap              Abstand zwischen Bildern (Länge)
 *   --sg-row-height       Zielhöhe der Mosaik-Reihen (Länge)
 *   --sg-tile             Mindestbreite der Gitter-Kacheln (Länge)
 *   --sg-grid-fit         object-fit der Gitter-Kacheln: cover (Vorgabe, quadratisch beschnitten) oder contain
 *   --sg-band-height      Höhe des Bandes (Länge)
 *   --sg-carousel-height  Höhe des Karussells (Länge)
 *   --sg-placeholder      Fläche, solange ein Bild lädt
 *   --sg-radius           Eckenradius der Bilder
 *   --sg-lightbox-bg      Hintergrund der Lichtbox
 *   --sg-lightbox-fg      Text der Lichtbox
 *   --sg-lightbox-muted   Zurückhaltender Text der Lichtbox
 *   --sg-label-red, --sg-label-yellow, --sg-label-green, --sg-label-blue, --sg-label-purple  Farbmarken
 *
 * Klassen (für eigene Regeln im Template): .sg-root, .sg-layout-<grid|mosaic|carousel|band>,
 * .sg-toolbar, .sg-overview, .sg-item, .sg-badge, .sg-mark, .sg-lightbox, .sg-lightbox-<bottom|side>,
 * .sg-lb-stage, .sg-lb-panel, .sg-rating, .sg-hint, .sg-download, .sg-caption, .sg-nav.
 */

:root {
  --sg-bg: #fafaf8;
  --sg-fg: #1f1f1d;
  --sg-muted: #77746e;
  --sg-accent: #b08d57;
  --sg-font: inherit;
  --sg-gap: 8px;
  --sg-row-height: clamp(150px, 26vw, 320px);
  --sg-tile: clamp(140px, 22vw, 260px);
  --sg-grid-fit: cover;
  --sg-band-height: min(72vh, 680px);
  --sg-carousel-height: min(78vh, 900px);
  --sg-placeholder: rgba(128, 128, 128, 0.12);
  --sg-radius: 0px;
  --sg-lightbox-bg: #121212;
  --sg-lightbox-fg: #ececea;
  --sg-lightbox-muted: #9b9994;
  --sg-label-red: #d9534f;
  --sg-label-yellow: #e8c33a;
  --sg-label-green: #5cae5a;
  --sg-label-blue: #4a7fd4;
  --sg-label-purple: #9a63c9;
}

html.sg-locked {
  overflow: hidden;
}

.sg-root {
  color: var(--sg-fg);
  background: var(--sg-bg);
  font-family: var(--sg-font);
}

.sg-root button,
.sg-lightbox button,
.sg-root select,
.sg-lightbox textarea {
  font: inherit;
  color: inherit;
}

.sg-root :focus-visible,
.sg-lightbox :focus-visible {
  outline: 2px solid var(--sg-accent);
  outline-offset: 2px;
}

/* Werkzeugleiste */

.sg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 0 0 var(--sg-gap);
  font-size: 0.875rem;
  color: var(--sg-muted);
}

.sg-filter {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sg-filter-select {
  padding: 4px 8px;
  border: 1px solid color-mix(in srgb, var(--sg-fg) 20%, transparent);
  border-radius: 4px;
  background: var(--sg-bg);
}

.sg-finish {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.sg-finish-notice {
  margin: 0;
}

.sg-finish-button,
.sg-finish-cancel,
.sg-finish-submit {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 16px;
  border: 1px solid color-mix(in srgb, var(--sg-fg) 30%, transparent);
  border-radius: 4px;
  background: var(--sg-bg);
  color: var(--sg-fg);
  font: inherit;
  cursor: pointer;
}

.sg-finish-submit {
  border-color: var(--sg-accent);
  background: var(--sg-accent);
  color: var(--sg-bg);
}

.sg-finish-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.sg-finish-dialog {
  width: min(32rem, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid color-mix(in srgb, var(--sg-fg) 25%, transparent);
  border-radius: 8px;
  background: var(--sg-bg);
  color: var(--sg-fg);
}

.sg-finish-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.sg-finish-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sg-finish-title {
  margin: 0;
  font-size: 1.125rem;
}

.sg-finish-note {
  box-sizing: border-box;
  width: 100%;
  min-height: 6em;
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--sg-fg) 30%, transparent);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  resize: vertical;
}

.sg-finish-dialog .sg-status {
  color: inherit;
}

.sg-finish-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.sg-download {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.sg-download:hover {
  color: var(--sg-accent);
}

.sg-empty {
  color: var(--sg-muted);
  padding: 32px 0;
  margin: 0;
}

/* Bilder der Übersicht */

.sg-item {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--sg-placeholder);
  border-radius: var(--sg-radius);
  overflow: hidden;
  cursor: zoom-in;
}

.sg-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 240ms ease, filter 240ms ease;
}

.sg-item img.sg-loaded,
.sg-carousel-stage img.sg-loaded {
  opacity: 1;
}

.sg-item img.sg-error {
  opacity: 0;
}

@media (hover: hover) {
  .sg-item:hover img.sg-loaded {
    filter: brightness(1.05);
  }
}

.sg-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
  color: #fff;
  background: var(--sg-accent);
  border-radius: 2px;
  pointer-events: none;
}

.sg-mark {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  font-size: 0.75rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 3px;
  pointer-events: none;
}

.sg-mark[hidden] {
  display: none;
}

.sg-stars {
  letter-spacing: 0.08em;
  color: var(--sg-accent);
}

.sg-mark .sg-stars {
  color: #fff;
}

.sg-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--sg-label-color, currentColor);
}

.sg-color-red { --sg-label-color: var(--sg-label-red); }
.sg-color-yellow { --sg-label-color: var(--sg-label-yellow); }
.sg-color-green { --sg-label-color: var(--sg-label-green); }
.sg-color-blue { --sg-label-color: var(--sg-label-blue); }
.sg-color-purple { --sg-label-color: var(--sg-label-purple); }

/* Gitter: gleich große, quadratische Kacheln; Spaltenzahl setzt die Laufzeit. */

.sg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--sg-tile), 1fr));
  gap: var(--sg-gap);
}

.sg-grid .sg-item {
  aspect-ratio: 1 / 1;
}

.sg-grid .sg-item img {
  object-fit: var(--sg-grid-fit);
}

/* Mosaik: Reihen mit fester Höhe, Breiten setzt die Laufzeit. */

.sg-mosaic {
  display: flex;
  flex-direction: column;
  gap: var(--sg-gap);
}

.sg-row {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--sg-gap);
  overflow: hidden;
}

.sg-mosaic .sg-item {
  flex: 0 0 auto;
  height: 100%;
}

/* Ohne Laufzeit-Breiten (vor dem ersten Layout) nach Seitenverhältnis. */
.sg-mosaic .sg-item:not([style*="width"]) {
  aspect-ratio: var(--sg-ratio);
}

/* Band: waagerechter Streifen */

.sg-band {
  position: relative;
}

.sg-band-strip {
  display: flex;
  gap: var(--sg-gap);
  height: var(--sg-band-height);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.sg-band .sg-item {
  flex: 0 0 auto;
  height: 100%;
  aspect-ratio: var(--sg-ratio);
  scroll-snap-align: start;
}

/* Pfeilknöpfe (Band, Karussell, Lichtbox) */

.sg-nav {
  position: absolute;
  top: 50%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, 0.32);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 160ms ease, background-color 160ms ease;
}

.sg-nav:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.5);
}

.sg-nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.sg-nav svg,
.sg-lb-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sg-nav-prev { left: 8px; }
.sg-nav-next { right: 8px; }

/* Karussell */

.sg-carousel-frame {
  position: relative;
}

.sg-carousel-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--sg-carousel-height);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  touch-action: pan-y pinch-zoom;
}

.sg-carousel-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 320ms ease;
}

.sg-carousel-stage .sg-badge {
  top: 12px;
  left: 12px;
}

.sg-caption {
  margin: 12px 0 0;
  font-size: 0.9375rem;
}

.sg-caption[hidden] {
  display: none;
}

.sg-carousel-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--sg-muted);
}

.sg-auto {
  padding: 4px 10px;
  border: 1px solid color-mix(in srgb, var(--sg-fg) 20%, transparent);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.sg-auto[aria-pressed="true"] {
  border-color: var(--sg-accent);
}

.sg-auto:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Download-Schutz: kein Markieren, kein Ziehen, kein Sichern per langem Drücken */

.sg-protect img {
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* Lichtbox */

.sg-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--sg-lightbox-fg);
  background: var(--sg-lightbox-bg);
  font-family: var(--sg-font);
  overflow: hidden;
}

.sg-lightbox[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "stage" "panel";
}

.sg-lightbox::backdrop {
  background: var(--sg-lightbox-bg);
}

.sg-lb-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 16px;
  font-size: 0.8125rem;
  color: var(--sg-lightbox-muted);
}

.sg-lb-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.sg-lb-close:hover {
  background: rgba(127, 127, 127, 0.2);
}

.sg-lb-stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  padding: 0 clamp(8px, 5vw, 72px);
  touch-action: pan-y pinch-zoom;
}

.sg-lb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sg-lb-panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 40vh;
  overflow-y: auto;
  padding: 12px clamp(16px, 5vw, 72px) 16px;
  font-size: 0.875rem;
}

.sg-lb-panel[hidden] {
  display: none;
}

.sg-lb-panel .sg-caption {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sg-lb-panel .sg-badge {
  position: static;
}

.sg-lb-panel .sg-badge[hidden],
.sg-download[hidden],
.sg-history[hidden],
.sg-others[hidden] {
  display: none;
}

.sg-lightbox .sg-download {
  align-self: flex-start;
  color: var(--sg-lightbox-muted);
}

@media (min-width: 900px) {
  .sg-lightbox-side[open] {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar bar" "stage panel";
  }

  .sg-lightbox-side .sg-lb-stage {
    padding: 0 16px 24px clamp(16px, 4vw, 56px);
  }

  .sg-lightbox-side .sg-lb-panel {
    max-height: none;
    padding: 0 24px 24px 8px;
  }
}

/* Bewertung */

.sg-rating {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sg-rating-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}

.sg-stars-input,
.sg-colors-input {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sg-star {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--sg-lightbox-muted);
  cursor: pointer;
}

.sg-star.sg-on {
  color: var(--sg-accent);
}

.sg-color {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.sg-color::before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  margin: auto;
  border-radius: 50%;
  background: var(--sg-label-color);
  box-shadow: 0 0 0 2px transparent;
  transition: box-shadow 120ms ease;
}

.sg-color[aria-pressed="true"]::before {
  box-shadow: 0 0 0 2px var(--sg-lightbox-bg), 0 0 0 4px var(--sg-lightbox-fg);
}

.sg-rating button:disabled {
  cursor: not-allowed;
}

.sg-rating[aria-disabled="true"] .sg-rating-row,
.sg-rating[aria-disabled="true"] .sg-note {
  opacity: 0.45;
}

.sg-note {
  width: 100%;
  box-sizing: border-box;
  min-height: 2.5em;
  padding: 6px 8px;
  border: 1px solid rgba(127, 127, 127, 0.4);
  border-radius: 4px;
  background: transparent;
  resize: vertical;
}

.sg-hint,
.sg-status,
.sg-entry {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--sg-lightbox-muted);
}

.sg-status:empty {
  display: none;
}

.sg-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .sg-item img,
  .sg-carousel-stage img,
  .sg-nav,
  .sg-color::before {
    transition: none;
  }
}

@media (max-width: 600px) {
  .sg-nav {
    width: 36px;
    height: 36px;
    margin-top: -18px;
  }

  .sg-lb-stage {
    padding: 0;
  }
}
