:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --input-bg: #ffffff;
  --primary: #ff6b35;
  --primary-dark: #e85a26;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --border: #ececec;
  --danger: #e23b3b;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

/* Dunkle Farben automatisch nach System-Einstellung (außer explizit "light" gewählt). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161311;
    --card: #221e1b;
    --input-bg: #2c2723;
    --text: #f1ece6;
    --muted: #a39a90;
    --border: #3a342e;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

/* Manuell gewählter Dark Mode (überschreibt System). */
:root[data-theme="dark"] {
  --bg: #161311;
  --card: #221e1b;
  --input-bg: #2c2723;
  --text: #f1ece6;
  --muted: #a39a90;
  --border: #3a342e;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* Kleine Versionsanzeige unten links (zur Kontrolle, ob neue Version geladen ist). */
.app-version {
  position: fixed; left: 6px; bottom: 4px; z-index: 3;
  font-size: 10px; color: var(--muted); opacity: 0.55; pointer-events: none;
}

/* Datum/Uhrzeit nebeneinander, gut lesbar. */
.datetime-row { display: flex; gap: 8px; }
.datetime-row input { margin-bottom: 0; }
.datetime-row input[type="date"] { flex: 1 1 60%; }
.datetime-row input[type="time"] { flex: 1 1 40%; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Sichere Bereiche für iPhone (Notch / Home-Indicator) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }
.view { min-height: 100vh; }

/* ---------- Auth ---------- */
#auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-card h1 { margin: 0 0 4px; font-size: 28px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  flex: 1; padding: 10px; border: none; border-radius: 10px;
  background: var(--bg); color: var(--muted); font-weight: 600; font-size: 15px;
}
.tab.active { background: var(--primary); color: #fff; }

input, textarea {
  width: 100%; padding: 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  font-size: 16px; font-family: inherit; background: var(--input-bg); color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
textarea { resize: vertical; }

.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 700;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary {
  padding: 10px 14px; border: 1px solid var(--primary); border-radius: 10px;
  background: var(--card); color: var(--primary); font-weight: 600; font-size: 14px;
}
.btn-ghost { background: none; border: none; color: var(--muted); font-size: 15px; font-weight: 600; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 12px; }
.remember {
  display: flex; align-items: center; gap: 8px; justify-content: flex-start;
  font-size: 14px; color: var(--muted); margin: 2px 0 14px; cursor: pointer;
}
.remember input { width: auto; margin: 0; }
.share-text { color: var(--muted); font-size: 14px; line-height: 1.4; margin: 0 0 14px; }
#share-link { font-size: 13px; }
#share-stop { color: var(--danger); margin-top: 6px; }

/* ---------- Netzwerk / Folgen ---------- */
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px;
}
.user-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.user-name.clickable { color: var(--primary); cursor: pointer; text-decoration: underline; }
#viewer-diary-select { margin-bottom: 14px; }
.user-row button { flex: 0 0 auto; padding: 7px 12px; font-size: 13px; }
.user-empty { color: var(--muted); font-size: 14px; margin: 2px 0; }

.invite-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 12px 16px; font-size: 14px;
}
.invite-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.invite-actions .btn-primary { width: auto; padding: 8px 14px; font-size: 14px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
#hello { color: var(--muted); font-size: 14px; }

/* ---------- Entries ---------- */
main { padding: 16px 16px 96px; max-width: 600px; margin: 0 auto; }
.entries { display: flex; flex-direction: column; gap: 16px; }
.empty { text-align: center; color: var(--muted); margin-top: 64px; padding: 0 24px; }

.entry-card {
  background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
}
.entry-card img { width: 100%; max-height: 320px; object-fit: cover; display: block; background: #eee; }
.entry-body { padding: 14px 16px; }
.entry-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.entry-title { font-size: 18px; font-weight: 700; margin: 0; }
.entry-stars { color: var(--primary); font-size: 16px; white-space: nowrap; }
.entry-stars .off { color: var(--border); }
.entry-meta { color: var(--muted); font-size: 13px; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.entry-meta a { color: var(--primary); text-decoration: none; }
.entry-notes { margin: 10px 0 0; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.entry-actions { display: flex; gap: 16px; margin-top: 12px; }
.entry-edit { color: var(--primary); background: none; border: none; font-size: 13px; font-weight: 600; padding: 0; }
.entry-delete { color: var(--danger); background: none; border: none; font-size: 13px; padding: 0; }

/* Eintrag, der noch auf den Upload wartet */
.entry-card.pending { opacity: 0.92; border: 1px dashed var(--primary); }
.badge {
  display: inline-block; margin-bottom: 8px; padding: 3px 10px; border-radius: 999px;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 600;
}

/* Offline-Hinweis oben */
.offline-banner {
  background: #5b4636; color: #fff; text-align: center;
  padding: 10px 16px; font-size: 13px; line-height: 1.3;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5); z-index: 6;
}
.fab:active { background: var(--primary-dark); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.modal-content {
  background: var(--bg); width: 100%; max-width: 600px;
  border-radius: 20px 20px 0 0; padding: 20px;
  max-height: 92vh; overflow-y: auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h2 { margin: 0; font-size: 20px; }

.photo-picker { display: block; cursor: pointer; }
.photo-preview {
  width: 100%; min-height: 140px; border: 2px dashed var(--border); border-radius: 14px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center;
  color: var(--muted); background: var(--input-bg); margin-bottom: 12px; padding: 6px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.photo-preview .thumb { width: calc(33.333% - 4px); height: 100px; }
.photo-preview .add-more {
  width: 100%; text-align: center; color: var(--primary); font-size: 13px; font-weight: 600;
}

/* Bestehende Fotos beim Bearbeiten */
.existing-photos { display: flex; flex-wrap: wrap; gap: 6px; }
.existing-photos:not(:empty) { margin-bottom: 12px; }
.thumb { position: relative; width: calc(33.333% - 4px); }
.thumb img { width: 100%; height: 90px; object-fit: cover; border-radius: 8px; display: block; }
.thumb-x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0;
  border: none; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 12px; line-height: 22px; text-align: center;
}

.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

.rating { display: flex; gap: 6px; }
.rating button {
  background: none; border: none; font-size: 34px; line-height: 1; color: var(--border); padding: 0;
}
.rating button.active { color: var(--primary); }

.location-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.location-status { font-size: 13px; color: var(--muted); }
.location-status.ok { color: #2e9e4f; }

/* ---------- Theme-Umschalter ---------- */
.theme-btn {
  font-size: 20px; line-height: 1; padding: 4px; cursor: pointer;
  background: none; border: none;
}
.auth-theme {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px;
}
#auth-view { position: relative; }

/* ---------- Tagebuch-Leiste ---------- */
.diary-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 57px; z-index: 4;
}
#diary-select {
  flex: 1; margin: 0; padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--input-bg); color: var(--text); font-size: 15px;
}
.icon-btn {
  flex: 0 0 auto; width: 42px; height: 42px; padding: 0;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--input-bg); color: var(--text); font-size: 17px;
}
.icon-btn:disabled { opacity: 0.4; }

/* ---------- Foto-Galerie in den Karten (durchwischbar) ---------- */
.gallery {
  display: flex; gap: 4px; overflow-x: auto;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.gallery img {
  flex: 0 0 100%; width: 100%; height: 260px; object-fit: cover;
  scroll-snap-align: start; background: var(--input-bg);
}

/* ---------- Lightbox (Foto in Vollbild) ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.93);
  display: flex; align-items: center; justify-content: center; padding: 10px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 16px;
  width: 42px; height: 42px; padding: 0; border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 18px; z-index: 51;
}
