/* Fotokiste – Haupt-CSS (iOS/iPad optimiert, UTF-8 ohne BOM) */
/* ====================================================================== */

:root {
  --c-bg:       #0f0f0f;
  --c-surface:  #1a1a1a;
  --c-card:     #242424;
  --c-border:   #333;
  --c-accent:   #e44d26;
  --c-accent2:  #f06529;
  --c-text:     #f0f0f0;
  --c-muted:    #888;
  --c-success:  #4caf50;
  --c-warning:  #ff9800;
  --c-danger:   #f44336;
  --radius:     12px;
  --radius-sm:  6px;
  --shadow:     0 4px 24px rgba(0,0,0,.6);
  --trans:      .2s ease;
  --safe-top:   env(safe-area-inset-top, 0px);
  --safe-bottom:env(safe-area-inset-bottom, 0px);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--c-accent); text-decoration: none; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--c-accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.main-content {
  flex: 1;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top: 57px;
  z-index: 90;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1;
  min-width: 80px;
  padding: 14px 8px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--c-muted);
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  transition: color var(--trans), border-color var(--trans);
  white-space: nowrap;
}

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

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  transition: opacity var(--trans), transform .1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary { background: var(--c-accent); color: #fff; }
.btn-secondary { background: var(--c-card); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-success { background: var(--c-success); color: #fff; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--c-text); border: 1px solid var(--c-border); }
.btn-lg { padding: 16px 28px; font-size: 1.1rem; border-radius: var(--radius); }
.btn-sm { padding: 8px 14px; font-size: .85rem; }
.btn-icon { padding: 10px; border-radius: 50%; }
.btn-full { width: 100%; }

/* ── Kamera-Panel ────────────────────────────────────────────────────── */
/* Wichtig: display-Wert NUR über .active setzen – ID-Spezifität würde
   `.tab-panel { display: none }` sonst überschreiben! */
#cam-panel {
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 8px;
}
#cam-panel.active {
  display: flex;
}

.video-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 4/3;
}

#cam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#cam-canvas { display: none; }

.cam-overlay-info {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.countdown-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 0 30px rgba(0,0,0,.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}

.countdown-display.visible { opacity: 1; }

.flash-overlay {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity .1s;
}

.flash-overlay.flash { opacity: 0.8; }

.cam-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 600px;
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid white;
  background: var(--c-accent);
  box-shadow: 0 0 0 4px var(--c-surface), var(--shadow);
  transition: transform .1s, background var(--trans);
}

.shutter-btn:active { transform: scale(.9); }
.shutter-btn.recording { background: var(--c-danger); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--c-surface), 0 0 0 0 rgba(244,67,54,.6); }
  50%       { box-shadow: 0 0 0 4px var(--c-surface), 0 0 0 12px rgba(244,67,54,0); }
}

/* ── Vorschau / Preview ──────────────────────────────────────────────── */
.preview-section {
  width: 100%;
  max-width: 600px;
}

.preview-img-wrap {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--c-border);
  aspect-ratio: 4/3;
  background: #000;
  position: relative;
}

.preview-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-actions {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.upload-status-msg {
  font-size: .85rem;
  color: var(--c-muted);
  flex: 1;
}

/* ── Galerie ─────────────────────────────────────────────────────────── */
.gallery-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.gallery-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--c-card);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--trans);
  display: block;
}

.gallery-item:hover img,
.gallery-item:focus-within img { transform: scale(1.05); }

.gallery-item.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  background: var(--c-accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
}

.gallery-item.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--c-accent);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 1;
}

.gallery-loading {
  grid-column: 1/-1;
  text-align: center;
  padding: 40px;
  color: var(--c-muted);
}

.gallery-pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

/* ── Lightbox ────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.95);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox.open { display: flex; }

/* Mail / SMS / Druck kommen über das Share-Modal */
#mail-modal, #sms-modal, #print-modal { z-index: 1020; }

.lightbox-img {
  max-width: 100%;
  max-height: 80dvh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.lightbox-toolbar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: max(16px, var(--safe-top));
  right: 16px;
  background: rgba(0,0,0,.6);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Effekte-Panel ───────────────────────────────────────────────────── */
.effects-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.effects-strip::-webkit-scrollbar { display: none; }

.effect-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text);
  font-size: .85rem;
  white-space: nowrap;
  transition: background var(--trans), border-color var(--trans);
}

.effect-btn.active {
  background: var(--c-accent);
  border-color: var(--c-accent);
}

/* ── Share-Panel ─────────────────────────────────────────────────────── */
.share-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.qr-wrapper {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

.qr-wrapper img {
  border-radius: var(--radius-sm);
  background: white;
  padding: 8px;
}

.share-link {
  font-size: .85rem;
  color: var(--c-muted);
  word-break: break-all;
  margin: 8px 0;
}
.share-modal-card {
  min-width: min(460px, 92vw);
  max-height: 90dvh;
  overflow-y: auto;
  position: relative;
}
.share-offline-hint {
  text-align: center;
  padding: 20px 12px 8px;
  color: var(--c-muted);
  line-height: 1.5;
}
.share-offline-hint p {
  margin: 8px 0 0;
  font-size: .9rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
}

.status-badge.pending { background: rgba(255,152,0,.2); color: var(--c-warning); }
.status-badge.ready   { background: rgba(76,175,80,.2); color: var(--c-success); }
.status-badge.failed  { background: rgba(244,67,54,.2); color: var(--c-danger); }

/* ── Toast-Nachrichten ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: max(24px, var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(400px, 90vw);
}

.toast {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: .9rem;
  pointer-events: auto;
  animation: slideUp .3s ease;
  max-width: 100%;
  text-align: center;
}

.toast.success { border-color: var(--c-success); background: rgba(76,175,80,.15); }
.toast.error   { border-color: var(--c-danger);  background: rgba(244,67,54,.15); }
.toast.warning { border-color: var(--c-warning); background: rgba(255,152,0,.15); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Lade-Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

/* ── Help-Button ─────────────────────────────────────────────────────── */
.help-btn {
  position: fixed;
  bottom: max(24px, calc(var(--safe-bottom) + 12px));
  left: 16px;
  z-index: 200;
  background: var(--c-warning);
  color: #000;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Card / Forms ────────────────────────────────────────────────────── */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: .85rem; color: var(--c-muted); margin-bottom: 6px; }

.form-input,
.form-select {
  width: 100%;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  padding: 10px 14px;
  font-size: 1rem;
  transition: border-color var(--trans);
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--c-accent);
}

.form-input::placeholder { color: var(--c-muted); }

/* ── Effekt-Vorschau-Canvas ──────────────────────────────────────────── */
#fx-canvas {
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius);
  display: none;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .cam-controls { gap: 8px; }
  .main-content { padding: 10px; }
  .gallery-toolbar { flex-direction: column; }
}

@media (min-width: 768px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .video-wrapper { max-height: 70vh; aspect-ratio: auto; }
  .tabs { top: 49px; }
}

/* ── Selection-Bar ───────────────────────────────────────────────────── */
.selection-bar {
  position: fixed;
  bottom: max(80px, calc(var(--safe-bottom) + 68px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: var(--shadow);
  z-index: 150;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(500px, 96vw);
  display: none;
}

.selection-bar.visible { display: flex; }

/* ── Greenscreen-Controls ────────────────────────────────────────────── */
.bg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.bg-thumb {
  aspect-ratio: 16/9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--trans);
}

.bg-thumb.active { border-color: var(--c-accent); }
.bg-thumb img { width: 100%; height: 100%; object-fit: cover; }
