:root {
  /* DLRG CI-Farben */
  --dlrg-red: #e30613;
  --dlrg-red-dark: #a30410;
  --dlrg-red-light: #fdeceb;
  --dlrg-yellow: #ffed00;
  --dlrg-grey: #575756;
  --dlrg-blue: #0069b4;

  /* Material-Design-Tokens auf Basis der DLRG-Farben */
  --color-primary: var(--dlrg-red);
  --color-primary-dark: var(--dlrg-red-dark);
  --color-primary-light: var(--dlrg-red-light);
  --color-on-primary: #ffffff;
  --color-accent: var(--dlrg-yellow);
  --color-on-accent: #201f1e;

  --surface: #ffffff;
  --surface-variant: #f4f3f1;
  --outline: #ddd9d6;
  --text: #201f1e;
  --text-muted: var(--dlrg-grey);

  --radius-s: 8px;
  --radius-m: 16px;
  --radius-l: 24px;
  --radius-pill: 999px;

  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.24), 0 1px 3px 1px rgba(0, 0, 0, 0.12);
  --elevation-2: 0 2px 4px rgba(0, 0, 0, 0.22), 0 3px 8px 2px rgba(0, 0, 0, 0.13);
  --elevation-3: 0 4px 8px rgba(0, 0, 0, 0.2), 0 6px 16px 3px rgba(0, 0, 0, 0.14);
  --elevation-4: 0 6px 14px rgba(0, 0, 0, 0.22), 0 10px 26px 4px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--surface-variant);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.25rem;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: var(--color-on-primary);
  box-shadow: var(--elevation-2);
  z-index: 500;
  position: relative;
}

#app-header h1 {
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.2px;
  margin: 0;
}

#header-actions {
  display: flex;
  gap: 0.5rem;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  box-shadow: var(--elevation-1);
}

.header-btn:active {
  transform: scale(0.97);
}

.header-btn-accent {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.header-btn-accent:hover {
  background: var(--color-accent);
  filter: brightness(1.06);
  box-shadow: var(--elevation-1);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: 0.75rem;
  font-weight: 700;
}

#app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1;
  min-width: 0;
  background: var(--surface-variant);
}

#sidebar {
  width: 290px;
  background: var(--surface);
  box-shadow: var(--elevation-2);
  overflow-y: auto;
  padding: 0.9rem;
  z-index: 400;
}

#sidebar.hidden {
  display: none;
}

#sidebar h2 {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 0.2rem 0 0.75rem;
}

#marker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

#marker-list li {
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-s);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

#marker-list li:hover {
  background: var(--color-primary-light);
  box-shadow: var(--elevation-1);
}

#marker-list li .place-name {
  font-weight: 500;
  display: block;
}

#marker-list li .place-desc {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}

#hint {
  margin: 0;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.08);
}

/* Leaflet-Steuerelemente an Material Design angleichen */
.leaflet-bar {
  border: none !important;
  border-radius: var(--radius-s) !important;
  overflow: hidden;
  box-shadow: var(--elevation-1) !important;
}

.leaflet-bar a {
  color: var(--text) !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-m) !important;
  box-shadow: var(--elevation-3) !important;
}

.leaflet-popup-tip {
  box-shadow: var(--elevation-1) !important;
}

/* Emoji-Pin-Marker: nur das Emoji, ohne Hintergrundform */
.emoji-pin {
  background: transparent;
  border: none;
}

.pin-emoji-only {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

/* Popup content inside Leaflet markers */
.popup-content {
  max-width: 220px;
}

.popup-content h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  font-weight: 500;
}

.popup-content p {
  margin: 0 0 0.6rem;
  font-size: 0.88rem;
  white-space: pre-wrap;
  color: var(--text);
}

.popup-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 0.6rem;
}

.popup-photos img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius-s);
  cursor: pointer;
  border: 1px solid var(--outline);
}

.popup-content .popup-edit {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.popup-content .popup-edit:hover {
  background: var(--color-primary-dark);
}

/* Form overlay */
#marker-form-overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 31, 30, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#marker-form-overlay.hidden {
  display: none;
}

#marker-form {
  background: var(--surface);
  border-radius: var(--radius-l);
  padding: 1.5rem;
  width: min(440px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--elevation-4);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#marker-form h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 500;
}

#marker-form label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

#marker-form input[type="text"],
#marker-form textarea {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--outline);
  border-radius: var(--radius-s);
  font: inherit;
  resize: vertical;
  background: var(--surface-variant);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#marker-form input[type="text"]:focus,
#marker-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-icon-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.3rem;
}

.form-icon-row-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.pin-preview {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

.emoji-custom-input {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--outline);
  border-radius: var(--radius-s);
  font: inherit;
  font-size: 1.1rem;
  background: var(--surface-variant);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.emoji-custom-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* Foto-Upload als moderne Dropzone statt nacktem <input type=file> */
.upload-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 1.2rem 1rem;
  border: 2px dashed var(--outline);
  border-radius: var(--radius-m);
  background: var(--surface-variant);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.upload-dropzone:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.upload-dropzone.is-dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: scale(1.01);
}

.upload-dropzone .upload-icon {
  font-size: 1.6rem;
}

.upload-dropzone .upload-text {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.upload-dropzone .upload-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

#photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 0.4rem;
}

#photo-preview .thumb {
  position: relative;
  width: 64px;
  height: 64px;
}

#photo-preview .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-s);
  border: 1px solid var(--outline);
  box-shadow: var(--elevation-1);
}

#photo-preview .thumb button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--elevation-1);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.form-actions button {
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--outline);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.form-actions button:hover {
  background: var(--surface-variant);
}

.form-actions #btn-save {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: var(--elevation-1);
}

.form-actions #btn-save:hover {
  background: var(--color-primary-dark);
  box-shadow: var(--elevation-2);
}

.form-actions .danger {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
  margin-right: auto;
}

.form-actions .danger:hover {
  background: var(--color-primary-light);
}

.hidden {
  display: none !important;
}

/* Lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  cursor: zoom-out;
}

#lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: var(--radius-s);
  box-shadow: var(--elevation-4);
}

@media (max-width: 640px) {
  #app-header h1 {
    font-size: 0.95rem;
  }
  #sidebar {
    position: absolute;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 400;
    width: 80vw;
    max-width: 300px;
  }
}
