/* ===== CSS-Variablen: Farben für Light/Dark Mode ===== */
:root {
  --color-bg:          #e0dfd5;
  --color-surface:     #ffffff;
  --color-text:        #313638;
  --color-text-muted:  #6b6f72;
  --color-accent:      #ef6461;
  --color-accent-2:    #e4b363;
  --color-border:      rgba(49, 54, 56, 0.12);
  --radius:            12px;
  --shadow:            0 2px 12px rgba(0,0,0,0.08);
}

/* Dark Mode: wird aktiviert via prefers-color-scheme ODER data-theme="dark" am <html> */
@media (prefers-color-scheme: dark) { :root { --dark: 1; } }
[data-theme="dark"] {
  --color-bg:          #1a1d1e;
  --color-surface:     #313638;
  --color-text:        #e8e9eb;
  --color-text-muted:  #9aa0a3;
  --color-accent:      #ef6461;
  --color-accent-2:    #e4b363;
  --color-border:      rgba(232, 233, 235, 0.10);
  --shadow:            0 2px 12px rgba(0,0,0,0.3);
}
[data-theme="light"] {
  --color-bg:          #e0dfd5;
  --color-surface:     #ffffff;
  --color-text:        #313638;
  --color-text-muted:  #6b6f72;
  --color-accent:      #ef6461;
  --color-accent-2:    #e4b363;
  --color-border:      rgba(49, 54, 56, 0.12);
  --shadow:            0 2px 12px rgba(0,0,0,0.08);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: hidden;
  transition: background 0.2s, color 0.2s;
}

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

/* ===== Seiten-System ===== */
/* Alle .page-Divs sind standardmäßig versteckt */
.page { display: none; min-height: 100dvh; }
.page.active { display: flex; flex-direction: column; }

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  color: var(--color-text);
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--color-border); }

/* ===== Login-Seite ===== */
#login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 0;
}

.login-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.login-box h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.login-box p {
  color: var(--color-text-muted);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--color-accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 44px;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.error-msg {
  color: var(--color-accent);
  font-size: 0.85rem;
  margin-top: 8px;
  display: none;
}
.error-msg.visible { display: block; }

/* Name-Step (zweiter Schritt beim Login) */
#name-step { display: none; margin-top: 16px; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 44px;
  transition: color 0.15s, border-color 0.15s;
}

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

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: block; }

/* ===== Timeline ===== */
#timeline-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Datumsgruppen-Trennlinie */
.date-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* Eintrags-Karte */
.entry-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.entry-card:active { transform: scale(0.98); }

.card-image-grid { position: relative; }

/* Vorschaubild in der Timeline-Karte: feste Höhe, volle Breite */
.card-img-main {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

/* Zwei kleine Bilder nebeneinander (unter dem Hauptbild, bei 3 Bildern) */
.card-img-row {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}
.card-img-row img {
  flex: 1;
  aspect-ratio: 2/1;
  object-fit: cover;
}

/* Sonderfall: genau 2 Bilder → kein Hauptbild, stattdessen zwei gleiche Spalten */
.card-img-pair {
  margin-top: 0; /* kein Abstand nach oben, da kein Hauptbild drüber */
}
.card-img-pair img {
  aspect-ratio: 1; /* quadratisch, da nur halbe Kartenbreite */
}

/* Karten-Textteil */
.card-body {
  padding: 12px 14px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.card-author {
  font-weight: 700;
  font-size: 0.9rem;
}

.card-time {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.card-text {
  font-size: 0.9rem;
  color: var(--color-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-location {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Leerzustand */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--color-text-muted);
}
.empty-state-icon { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.4; display: block; }

/* FAB – Floating Action Button */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(239,100,97,0.4);
  z-index: 200;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }

/* ===== Karten-Tab ===== */
#map-container {
  height: calc(100dvh - 44px - 45px); /* Viewport minus Header und Tabs */
}

/* ===== Eintrag erstellen #create ===== */
.create-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-back {
  background: none;
  border: none;
  color: var(--color-accent);
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Bildauswahl */
.image-input-wrapper {
  position: relative;
  margin-bottom: 16px;
}

.image-pick-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.95rem;
  min-height: 56px;
}

#image-input { display: none; }

.image-preview-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.preview-thumb {
  width: calc(33.333% - 6px);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--color-border);
}

/* Standort-Button */
.btn-location {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.9rem;
  min-height: 44px;
  margin-bottom: 16px;
}

.location-status {
  font-size: 0.8rem;
  color: var(--color-accent);
  margin-top: 4px;
  min-height: 16px;
}

/* ===== Detail-Seite #detail ===== */
.detail-scroll {
  flex: 1;
  overflow-y: auto;
}

.detail-hero {
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  display: block;
}

.detail-img-row {
  display: flex;
  gap: 2px;
}
.detail-img-row img {
  flex: 1;
  aspect-ratio: 2/1;
  object-fit: cover;
}

/* Sonderfall Detail: genau 2 Bilder → zwei gleiche Spalten ohne Hero */
.detail-img-pair img {
  aspect-ratio: 1; /* quadratisch, da halbe Bildschirmbreite */
}

.detail-body {
  padding: 16px;
}

.detail-meta {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.detail-location {
  font-size: 0.9rem;
  margin-bottom: 12px;
  color: var(--color-accent);
}
.detail-location button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-text {
  font-size: 1rem;
  line-height: 1.7;
  white-space: pre-wrap; /* Zeilenumbrüche aus der Textarea erhalten */
  margin-bottom: 24px;
}

/* Aktions-Buttons in der Detailansicht (Bearbeiten + Löschen) */
.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-delete,
.btn-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 44px;
}

.btn-delete {
  border: 1px solid var(--color-accent);
  color: var(--color-accent);
}

.btn-edit {
  border: 1px solid var(--color-border);
  color: var(--color-text);
}
.btn-edit:hover { background: var(--color-border); }

/* ===== Galerie-Thumbnails (Feature 3) ===== */
.thumbnail-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  background: var(--color-bg);
  /* scrollbar verstecken aber scrollbar weiterhin nutzbar */
  scrollbar-width: none;
}
.thumbnail-bar::-webkit-scrollbar { display: none; }

.thumbnail-bar img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: border-color 0.15s, opacity 0.15s;
  opacity: 0.65;
}

.thumbnail-bar img.active {
  border-color: var(--color-accent);
  opacity: 1;
}

/* ===== Spinner ===== */
.spinner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.spinner-overlay.visible { display: flex; }
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Lucide Icons ===== */
.lucide {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  display: block;
  flex-shrink: 0;
}
.btn-icon .lucide { width: 22px; height: 22px; }
.fab .lucide { width: 24px; height: 24px; }
.tab-btn .lucide { width: 18px; height: 18px; }
.btn-back .lucide { width: 18px; height: 18px; }
.btn-location .lucide { width: 18px; height: 18px; }
.image-pick-btn .lucide { width: 18px; height: 18px; }
.btn-edit .lucide, .btn-delete .lucide { width: 16px; height: 16px; }
.card-location .lucide { width: 14px; height: 14px; }
.detail-location button .lucide { width: 16px; height: 16px; }
#scroll-top-btn .lucide { width: 20px; height: 20px; }

/* ===== Scroll-to-top Button ===== */
.scroll-top-btn {
  position: fixed;
  bottom: 24px;
  right: 88px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
}
