:root {
  --color-bg: #ffffff;
  --color-text: #222;
  --color-border: #ddd;
  --color-panel-bg: #fafafa;
  --color-primary: #2a6f97;
  --color-primary-dark: #1d4e6b;
  --color-error: #b3261e;
  --color-success: #2a7a3b;
  --panel-width: 340px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
}

.hidden { display: none !important; }

body.waiting-for-map-click #map { cursor: crosshair; }

/* ---------- Layout ---------- */

.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
  background: #eef;
}

.panel {
  width: var(--panel-width);
  flex: 0 0 var(--panel-width);
  height: 100%;
  overflow-y: auto;
  background: var(--color-panel-bg);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}

.panel-header h1 {
  font-size: 1.15rem;
  margin: 0;
}

.role-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e0e0e0;
  color: #444;
  white-space: nowrap;
}

.role-badge.role-editor {
  background: #d6ebd9;
  color: #1e5b2c;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logout-btn {
  text-decoration: none;
  color: #444;
  white-space: nowrap;
}

.panel-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--color-border);
}

.tab-btn {
  flex: 1 1 auto;
  padding: 7px 8px;
  font-size: 0.85rem;
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: #444;
}

.tab-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.panel-tab {
  padding: 14px 16px;
  overflow-y: auto;
}

/* ---------- Formulare ---------- */

form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: #333;
}

form input[type="text"],
form input[type="password"],
form input[type="number"],
form input[type="file"],
form select,
form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  font-size: 0.9rem;
  border: 1px solid #bbb;
  border-radius: 5px;
  font-weight: normal;
}

.btn {
  padding: 8px 14px;
  border: 1px solid #bbb;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
}

.btn:hover { background: #f2f2f2; }

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.btn-primary:hover { background: var(--color-primary-dark); }

.btn-danger {
  color: var(--color-error);
  border-color: var(--color-error);
}

.btn-small {
  padding: 3px 8px;
  font-size: 0.75rem;
}

.upload-result { margin-top: 10px; font-size: 0.85rem; }

.upload-file-assignments { margin-bottom: 12px; }

.upload-file-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.upload-file-row .upload-file-name {
  flex: 1 1 40%;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-row input[type="text"] {
  flex: 1 1 55%;
  margin-top: 0;
}

/* ---------- Tourenliste ---------- */

.tag-filter { margin-bottom: 10px; }
.tag-filter label { font-size: 0.8rem; }

.tour-list { display: flex; flex-direction: column; gap: 8px; }

.tour-item {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.tour-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tour-item-row input[type="checkbox"] { flex: 0 0 auto; }

.tour-color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.25);
  cursor: pointer;
  flex: 0 0 auto;
  padding: 0;
}

.tour-name {
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.tour-actions {
  display: flex;
  gap: 4px;
}

.tour-tags {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-chip {
  font-size: 0.72rem;
  background: #eef3f7;
  color: #2a6f97;
  padding: 2px 7px;
  border-radius: 999px;
}

.tour-stats {
  margin-top: 6px;
  font-size: 0.78rem;
  color: #555;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tour-files-toggle {
  margin-top: 6px;
  font-size: 0.78rem;
}

.tour-files-list {
  margin-top: 4px;
  padding-left: 0;
  list-style: none;
  font-size: 0.78rem;
}

.tour-files-list li {
  padding: 3px 0;
  border-top: 1px dashed #eee;
}

.file-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tour-files-list .file-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-stats {
  margin-top: 2px;
  color: #777;
  font-size: 0.72rem;
}

.empty-hint {
  color: #777;
  font-size: 0.85rem;
  padding: 12px 4px;
}

/* ---------- Wegpunkte ---------- */

.waypoint-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.waypoint-list { display: flex; flex-direction: column; gap: 6px; }

.waypoint-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

.waypoint-item img { width: 22px; height: 22px; object-fit: contain; flex: 0 0 auto; }
.waypoint-item .wp-text { flex: 1 1 auto; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Höhenprofil-Overlay ---------- */

.elevation-overlay {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: min(400px, 46vw);
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  z-index: 1000;
  padding: 8px 10px;
}

.elevation-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

#elevation-title { font-weight: 600; flex: 1 1 auto; }

.elevation-toggle { display: flex; align-items: center; gap: 3px; font-size: 0.75rem; white-space: nowrap; }

#elevation-file-select { font-size: 0.75rem; max-width: 120px; }

#elevation-close {
  border: none;
  background: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
  padding: 0 2px;
}

.elevation-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: #444;
  margin-bottom: 4px;
}

#elevation-chart {
  width: 100%;
  height: 90px;
  display: block;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  width: min(480px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}

.modal-box h2 { margin-top: 0; font-size: 1.1rem; }

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.symbol-grid label {
  margin: 0;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.symbol-grid input { display: none; }
.symbol-grid img { width: 32px; height: 32px; object-fit: contain; }
.symbol-grid input:checked + img,
.symbol-grid label:has(input:checked) { border-color: var(--color-primary); background: #eef3f7; }

.symbol-grid-item {
  position: relative;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.symbol-grid-item img { width: 32px; height: 32px; object-fit: contain; }

.symbol-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  line-height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--color-error);
  background: #fff;
  color: var(--color-error);
  font-size: 0.8rem;
  cursor: pointer;
}

.symbol-delete-btn:hover { background: var(--color-error); color: #fff; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- Login / Setup / Einstellungen ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  padding: 20px;
}

.auth-box {
  background: #fff;
  border-radius: 10px;
  padding: 28px 30px;
  width: min(420px, 100%);
  box-shadow: 0 4px 18px rgba(0,0,0,0.12);
}

.settings-box { width: min(480px, 100%); }

.auth-box h1 { margin-top: 0; font-size: 1.3rem; }
.auth-box .subtitle { color: #666; margin-top: -8px; font-size: 0.9rem; }

.auth-box fieldset {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 14px;
}

.error { color: var(--color-error); font-size: 0.88rem; }
.success { color: var(--color-success); font-size: 0.88rem; }
.hint { color: #777; font-size: 0.8rem; }

.radio-row { display: flex; align-items: center; gap: 6px; font-weight: normal; }

/* ---------- Leaflet Popups (Wegpunkte) ---------- */

.leaflet-popup-content { font-size: 0.85rem; }

/* ---------- Responsive: Tablet/Smartphone ---------- */

@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .map-wrap { height: 55vh; flex: none; }
  .panel {
    width: 100%;
    flex: 1 1 auto;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
  .elevation-overlay { width: min(340px, 92vw); }
}

@media (max-width: 480px) {
  .panel-header h1 { font-size: 1.05rem; }
  .tab-btn { font-size: 0.78rem; padding: 6px; }
}
