:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: calc(16px + var(--safe-bottom));
}

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

.muted { color: var(--muted); font-size: 0.9rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  background: var(--surface2);
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #0f172a; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-success { background: var(--success); color: #052e16; }
.btn-warn { background: var(--warn); color: #451a03; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--surface2); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0.45rem 0.75rem; font-size: 0.875rem; }

/* Login */
.page-login {
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

.brand { text-align: center; margin-bottom: 24px; }
.brand-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }
.brand h1 { margin: 0; font-size: 1.6rem; }
.brand p { margin: 4px 0 0; color: var(--muted); }

.form-stack label { display: block; margin-bottom: 14px; }
.form-stack label span { display: block; margin-bottom: 6px; font-size: 0.9rem; color: var(--muted); }
.form-stack input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--surface2);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.alert-error { background: rgba(239,68,68,.15); color: #fecaca; }

/* Admin */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(15,23,42,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--surface2);
}

.panel {
  margin: 16px;
  padding: 18px;
  background: var(--surface);
  border-radius: var(--radius);
}

.panel h2 { margin: 0 0 8px; font-size: 1.15rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }

.link-box {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.link-input {
  flex: 1;
  min-width: 200px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 120px;
  padding: 20px;
  margin-bottom: 14px;
  border: 2px dashed var(--surface2);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  color: var(--muted);
}

.upload-drop input { display: none; }
.upload-drop small { font-size: 0.8rem; opacity: 0.8; }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.admin-card {
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
}

.admin-card.published { border-color: var(--success); }

.thumb-wrap {
  aspect-ratio: 1;
  background: #000;
  overflow: hidden;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-pending {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.admin-card-body { padding: 10px; }
.filename {
  margin: 0 0 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta { margin: 0 0 8px; font-size: 0.75rem; color: var(--muted); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.empty, .empty-gallery {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

/* Gallery (Multiuse) */
.page-gallery { padding: 0; }

.gallery-header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: rgba(15,23,42,.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--surface2);
}

.gallery-header h1 { margin: 0; font-size: 1.25rem; }
.gallery-header p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 3px;
}

@media (min-width: 480px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
}

@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
    padding: 8px;
    max-width: 1200px;
    margin: 0 auto;
  }
}

.gallery-item {
  appearance: none;
  border: none;
  padding: 0;
  margin: 0;
  background: #000;
  cursor: pointer;
  aspect-ratio: 1;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.gallery-item:active img { transform: scale(0.97); }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.96);
  display: grid;
  place-items: center;
}

.lightbox.hidden { display: none; }

.lightbox img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 2;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  z-index: 2;
}

.lightbox-prev { left: 0; border-radius: 0 8px 8px 0; }
.lightbox-next { right: 0; border-radius: 8px 0 0 8px; }

.guest-links { display: flex; flex-direction: column; gap: 14px; }
.guest-link-block {
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--surface2);
}
.guest-link-block strong { display: block; margin-bottom: 4px; }
.zone-panel { border-left: 4px solid var(--surface2); }
.zone-gast2 { border-left-color: #38bdf8; }
.zone-gast3 { border-left-color: #f59e0b; }
.dedup-form { margin: 10px 0 14px; }
.panel-ok {
  background: color-mix(in srgb, var(--success) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--success) 45%, transparent);
}

.guest-upload-panel { margin: 12px 16px; padding: 14px; }

.lightbox-stage {
  max-width: 100vw;
  max-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lightbox-name {
  color: #ccc;
  font-size: 0.85rem;
  margin: 8px 0 0;
  text-align: center;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-bar {
  position: absolute;
  bottom: calc(12px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,.65);
  max-width: 95vw;
}

.lightbox-bar .btn { min-height: 38px; }

/* Gast-Portal Tabs */
.portal-tabs {
  display: flex;
  gap: 0;
  margin: 0;
  padding: 0 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--surface2);
  background: rgba(15,23,42,.98);
  position: sticky;
  top: 0;
  z-index: 6;
}

.portal-tab {
  flex: 1;
  min-width: 100px;
  min-height: 48px;
  padding: 10px 8px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.portal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.portal-panel { display: none; padding: 12px 8px 24px; }
.portal-panel.active { display: block; }

.panel-desc {
  margin: 0 8px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.guest-upload-inline { margin: 0 8px 16px; }
.upload-drop-sm { min-height: 90px; padding: 14px; }
.empty-gallery-inline { text-align: center; color: var(--muted); padding: 24px; }

/* Cookie-Banner */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: calc(12px + var(--safe-bottom)) 12px 12px;
  background: rgba(15,23,42,.97);
  border-top: 1px solid var(--surface2);
  backdrop-filter: blur(8px);
}

.cookie-banner.hidden { display: none; }

.cookie-inner { max-width: 640px; margin: 0 auto; }

.cookie-text {
  margin: 0 0 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
}

.cookie-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Bild-Historie (Cookies) */
.gallery-item { position: relative; }

.badge-viewed, .badge-downloaded {
  display: none;
  position: absolute;
  top: 4px;
  padding: 2px 5px;
  border-radius: 6px;
  font-size: 0.65rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  pointer-events: none;
}

.badge-viewed { left: 4px; }
.badge-downloaded { right: 4px; }

.gallery-item.is-viewed .badge-viewed { display: block; }
.gallery-item.is-downloaded .badge-downloaded { display: block; }
.gallery-item.is-viewed img { opacity: 0.88; }

.panel-external { border-left: 4px solid #22c55e; }
.panel-adobe { border-left: 4px solid #a855f7; }
.panel-adobe code { font-size: 0.8rem; word-break: break-all; }
.guest-link-block .small { font-size: 0.8rem; }
