/* ---------- Farben & Maße ---------- */
:root {
  color-scheme: light dark;

  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #000000;
  --text-2: rgba(60, 60, 67, 0.6);
  --separator: rgba(60, 60, 67, 0.18);
  --accent: #007aff;
  --on-accent: #ffffff;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);

  --radius-card: 16px;
  --gutter: 16px;
  --fab-size: 60px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.6);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- Basis: native App-Gefühl ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* gescrollt wird nur in #app */
  overscroll-behavior: none;     /* kein Gummiband / Pull-to-Refresh */
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;   /* kein Lang-Druck-Menü auf UI */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;    /* kein Doppeltipp-Zoom */
}

/* Eingabefelder bleiben auswählbar; 16px+ verhindert Auto-Zoom beim Fokus */
input, textarea, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
  font: inherit;
  font-size: max(16px, 1em);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

img { -webkit-user-drag: none; user-select: none; }

/* ---------- Layout ---------- */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding:
    calc(var(--safe-top) + 8px)
    calc(var(--safe-right) + var(--gutter))
    calc(var(--safe-bottom) + var(--fab-size) + 32px)
    calc(var(--safe-left) + var(--gutter));
}

.app-header h1 {
  margin: 8px 0 16px;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.wallet {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Leerer Zustand ---------- */
.empty-state {
  margin: auto 0;
  padding: 32px 24px;
  text-align: center;
  color: var(--text-2);
}
.empty-icon {
  display: block;
  margin: 0 auto 16px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.empty-state h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}
.empty-state p {
  margin: 0 auto;
  max-width: 30ch;
}

/* ---------- Footer / Status ---------- */
.app-footer {
  padding-top: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
}

/* ---------- Plus-Button ---------- */
.fab {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 20px);
  width: var(--fab-size);
  height: var(--fab-size);
  margin-left: calc(var(--fab-size) / -2);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.35), 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 120ms ease, filter 120ms ease;
  z-index: 10;
}
.fab:active {
  transform: scale(0.92);
  filter: brightness(0.9);
}

.fab:disabled { opacity: 0.5; }

/* Kleiner Knopf neben dem Plus: Foto oder Datei auswählen */
.pick {
  position: fixed;
  left: calc(50% + var(--fab-size) / 2 + 16px);
  bottom: calc(var(--safe-bottom) + 20px + (var(--fab-size) - 48px) / 2);
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 0.5px var(--separator);
  transition: transform 120ms ease, filter 120ms ease;
  z-index: 10;
}
.pick:active { transform: scale(0.92); filter: brightness(0.9); }
.pick:disabled { opacity: 0.5; }

[hidden] { display: none !important; }

.visually-hidden {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Wallet: großes Ticket oben, Rest gestapelt ---------- */
.wallet-cards {
  --strip: 52px;        /* sichtbarer oberer Rand eines gestapelten Tickets */
  --stack-card: 190px;  /* Höhe einer Karte im Stapel */
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.card {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.12), 0 -6px 16px rgba(0, 0, 0, 0.22), var(--shadow);
}
.card img {
  display: block;
  width: 100%;
  object-fit: cover;
  object-position: top;
}
.card-date {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* Datei ohne Bildvorschau */
.card-nopreview { min-height: 190px; }
.card-nopreview::after {
  content: "Keine Vorschau";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-2);
}

/* Das oberste Ticket: groß */
.card-top img {
  height: auto;
  min-height: 220px;
  max-height: 62vh;
  max-height: 62dvh;
}
.card-top:active { transform: scale(0.985); }

/* Der Stapel: jede Karte verdeckt die vorige bis auf den oberen Rand */
.stack { display: flex; flex-direction: column; }
.card-stacked { height: var(--stack-card); flex: none; }
.card-stacked + .card-stacked { margin-top: calc(var(--strip) - var(--stack-card)); }
.card-stacked img { height: 100%; }
.card-stacked:active { filter: brightness(0.9); }

::view-transition-group(*) { animation-duration: 320ms; animation-timing-function: cubic-bezier(0.3, 0.7, 0.2, 1); }

/* ---------- Vollbild ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.viewer img {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
}
.viewer-bar {
  display: flex;
  justify-content: space-between;
  padding: 8px var(--gutter) 12px;
}
.viewer-bar button {
  min-height: 44px;
  padding: 0 8px;
  font-weight: 600;
  color: #0a84ff;
}
.viewer-bar .viewer-delete { color: #ff453a; font-weight: 400; }

/* ---------- Meldung ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--fab-size) + 36px);
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(40, 40, 42, 0.95);
  color: #fff;
  font-size: 15px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
