/* Streifzug — moderner Feldatlas.
   Farbtokens als CSS-Variablen, Light + Dark, mobile-first, touch-first. */

:root {
  /* Identitaets-Tokens (konstant, themenunabhaengig) */
  --waldtinte: #1A2A20;
  --moos:      #3F5C46;
  --beere:     #A8323E;
  --ocker:     #B07F34;
  --pergament: #F2ECDF;
  --flechte:   #E4DECB;
  --teal:      #2F6E72;
  --schiefer:  #5E6B70;

  /* Marker-Farben pro Kategorie (in beiden Themes gleich) */
  --m-sichtung:    var(--moos);
  --m-sammelstelle:var(--beere);
  --m-saison:      var(--ocker);
  --m-wasser:      var(--teal);
  --m-pitstop:     var(--schiefer);

  --radius: 14px;
  --radius-sm: 9px;
  --tap: 48px;                 /* Mindest-Tippziel */
  --shadow: 0 6px 22px rgba(0,0,0,.14);
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;
}

/* ---- Light (Default) ---- */
:root, [data-theme="light"] {
  --bg: var(--pergament);
  --surface: #FBF7EE;
  --surface-2: var(--flechte);
  --text: var(--waldtinte);
  --text-soft: #4b5750;
  --border: #d8cfb8;
  --accent: var(--beere);
  --accent-text: #fff;
  --map-bg: #e9e3d2;
}

/* ---- Dark (wichtig fuers Feld) ---- */
[data-theme="dark"] {
  --bg: #11201A;
  --surface: #18261F;
  --surface-2: #20332A;
  --text: #ECE6D6;
  --text-soft: #A9B6AD;
  --border: #2c3d33;
  --accent: #C5505B;
  --accent-text: #fff;
  --map-bg: #16241d;
}

/* System-Praeferenz, wenn auf auto */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #11201A; --surface: #18261F; --surface-2: #20332A;
    --text: #ECE6D6; --text-soft: #A9B6AD; --border: #2c3d33;
    --accent: #C5505B; --accent-text: #fff; --map-bg: #16241d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  display: flex; flex-direction: column; min-height: 100dvh;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: .2px; }
.mono { font-family: var(--font-mono); }

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--waldtinte); color: var(--pergament);
  position: sticky; top: 0; z-index: 800;
}
.brand { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600;
  color: var(--pergament); text-decoration: none; display: flex; gap: 8px; align-items: center; }
.brand-mark { color: var(--ocker); }
.header-right { display: flex; align-items: center; gap: 6px; }
.who { color: var(--flechte); text-decoration: none; font-size: .85rem;
  padding: 8px 10px; border-radius: var(--radius-sm); }
.icon-btn {
  min-width: var(--tap); min-height: 40px; border: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.12); color: var(--pergament); font-size: 1.1rem; cursor: pointer;
}

/* ---------- Main / Layout ---------- */
.app-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.page { padding: 16px; padding-bottom: calc(86px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; width: 100%; }

.flash { background: var(--ocker); color: #1c1407; padding: 10px 16px; font-size: .9rem; text-align: center; }

/* ---------- Bottom-Nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 850;
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 62px; text-decoration: none; color: var(--text-soft);
  font-size: .72rem; font-weight: 500;
}
.nav-item.active { color: var(--accent); }
.nav-ico { font-size: 1.35rem; line-height: 1; }
.nav-cta .nav-ico {
  background: var(--accent); color: var(--accent-text); width: 46px; height: 46px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin-top: -18px; box-shadow: var(--shadow); font-size: 1.7rem; font-weight: 300;
}
.nav-cta { color: var(--accent); }

/* ---------- Karte ---------- */
#map { flex: 1; width: 100%; min-height: 60vh; background: var(--map-bg); }
.map-wrap { position: relative; flex: 1; display: flex; }
.layer-panel {
  position: absolute; top: 12px; right: 12px; z-index: 600;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); font-size: .82rem; max-width: 62vw;
}
.layer-panel label { display: flex; align-items: center; gap: 8px; padding: 5px 2px; cursor: pointer; }
.layer-panel input { width: 18px; height: 18px; accent-color: var(--moos); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.sichtung{background:var(--m-sichtung)} .dot.sammelstelle{background:var(--m-sammelstelle)}
.dot.saison_notiz{background:var(--m-saison)} .dot.wasser_notiz{background:var(--m-wasser)}
.dot.pitstop{background:var(--m-pitstop)}

/* Leaflet-Marker (eigene, gedaempfte Optik) */
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,.85); box-shadow: 0 3px 6px rgba(0,0,0,.35);
}
.pin > span { transform: rotate(45deg); display: block; }

/* Eigene gedaempfte Tile-Optik */
.leaflet-tile-pane { filter: saturate(.72) brightness(.97) contrast(.96); }
[data-theme="dark"] .leaflet-tile-pane,
[data-theme="auto"] .leaflet-tile-pane { filter: saturate(.55) brightness(.62) contrast(1.05) invert(.06); }

/* ---------- Karten-/Detail-Popup ---------- */
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.popup h3 { margin: 0 0 4px; font-size: 1.05rem; }
.popup .sci { font-style: italic; color: var(--text-soft); }
.popup img { width: 100%; border-radius: var(--radius-sm); margin: 8px 0; }
.popup .meta { font-family: var(--font-mono); font-size: .72rem; color: var(--text-soft); }

/* ---------- Cards / Liste ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.entry-card { display: flex; gap: 12px; }
.entry-card .thumb { width: 78px; height: 78px; border-radius: var(--radius-sm);
  object-fit: cover; background: var(--surface-2); flex: none; }
.entry-card .thumb.placeholder { display:flex; align-items:center; justify-content:center; font-size:1.8rem; }
.entry-card .body { min-width: 0; flex: 1; }
.entry-card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.entry-card .sci { font-style: italic; color: var(--text-soft); font-size: .85rem; }
.entry-card .note { font-size: .88rem; margin-top: 4px; }
.entry-meta { font-family: var(--font-mono); font-size: .7rem; color: var(--text-soft);
  margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; }

.badge { display: inline-block; font-size: .68rem; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; vertical-align: middle; }
.badge.cat { color:#fff; }
.badge.sichtung{background:var(--m-sichtung)} .badge.sammelstelle{background:var(--m-sammelstelle)}
.badge.saison_notiz{background:var(--m-saison)} .badge.wasser_notiz{background:var(--m-wasser)}
.badge.pitstop{background:var(--m-pitstop)}
.badge.neu { background: var(--ocker); color: #1c1407; }
.badge.offen { background: var(--surface-2); color: var(--text-soft); border:1px solid var(--border); }
.badge.bestaetigt { background: var(--moos); color: #fff; }

/* Konfidenz-Balken */
.conf { font-family: var(--font-mono); font-size: .72rem; }
.conf-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 3px; }
.conf-bar > i { display: block; height: 100%; background: var(--moos); }
.conf-low > i { background: var(--beere); }

/* ---------- Formulare / Buttons ---------- */
label.field { display: block; margin: 14px 0 6px; font-weight: 600; font-size: .9rem; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; min-height: var(--tap); padding: 11px 12px; font-size: 1rem; font-family: var(--font-ui);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
textarea { min-height: 80px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; font-size: 1rem; font-weight: 600; font-family: var(--font-ui);
  border: none; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
  background: var(--surface-2); color: var(--text); width: 100%;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 auto; min-height: var(--tap); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: .92rem; font-weight: 500; cursor: pointer;
  padding: 8px 10px; min-width: 84px;
}
.seg button.sel { background: var(--moos); color: #fff; border-color: var(--moos); }

/* ---------- Bestimmungs-Kandidaten ---------- */
.cand {
  display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}
.cand.sel { border-color: var(--moos); box-shadow: 0 0 0 2px var(--moos) inset; }
.cand .grow { flex: 1; min-width: 0; }
.cand .nm { font-weight: 600; }
.cand .sci { font-style: italic; color: var(--text-soft); font-size: .85rem; }
.cand .pct { font-family: var(--font-mono); font-weight: 700; font-size: .95rem; white-space: nowrap; }

.hint { font-size: .85rem; color: var(--text-soft); }
.warn {
  background: color-mix(in srgb, var(--ocker) 22%, var(--surface));
  border: 1px solid var(--ocker); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: .85rem; margin: 12px 0;
}
.danger {
  background: color-mix(in srgb, var(--beere) 16%, var(--surface));
  border: 1px solid var(--beere); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: .85rem; margin: 12px 0;
}
.spinner { display:inline-block; width:18px; height:18px; border:3px solid var(--surface-2);
  border-top-color: var(--accent); border-radius:50%; animation: spin .8s linear infinite; vertical-align:-3px;}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 8vh auto 0; padding: 24px; }
.login-wrap h1 { font-size: 2.2rem; margin: 0 0 4px; }
.login-wrap .tag { color: var(--text-soft); margin-bottom: 22px; }

/* ---------- Toolbar / Suche ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=text] { flex: 1; min-width: 140px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: .8rem; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-soft); cursor: pointer; }
.chip.on { background: var(--moos); color: #fff; border-color: var(--moos); }

.empty { text-align: center; color: var(--text-soft); padding: 40px 12px; }
.preview-img { width: 100%; max-height: 280px; object-fit: cover; border-radius: var(--radius); margin-top: 10px; }
.section-title { font-family: var(--font-display); font-size: 1.15rem; margin: 18px 0 8px; }

/* ---------- Mehrbild-Vorschauen ---------- */
.previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preview-thumb {
  width: 88px; height: 88px; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); flex: none;
}
.preview-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-thumb.no-preview {
  display: flex; align-items: center; justify-content: center; font-size: 2rem;
  color: var(--text-soft);
}

/* ---------- Detail-Modal ---------- */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; z-index: 1; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0; padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.4); animation: slideup .22s ease;
}
@media (min-width: 620px) {
  .modal { align-items: center; }
  .modal-card { border-radius: var(--radius); max-height: 88vh; }
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 38px; height: 38px;
  border: none; border-radius: 50%; background: var(--surface-2); color: var(--text);
  font-size: 1rem; cursor: pointer; z-index: 2;
}
.detail-loading { text-align: center; color: var(--text-soft); padding: 50px 12px; }
.detail-gallery { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 4px; }
.detail-gallery img {
  height: 200px; border-radius: var(--radius-sm); object-fit: cover; flex: none;
  max-width: 90%; background: var(--surface-2);
}
.detail-head h2 { margin: 8px 0 2px; font-size: 1.5rem; }
.detail-head .sci { font-style: italic; color: var(--text-soft); }
.detail-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .9rem; }
.detail-table th { text-align: left; color: var(--text-soft); font-weight: 600; padding: 5px 10px 5px 0; vertical-align: top; white-space: nowrap; width: 1%; }
.detail-table td { padding: 5px 0; }
.detail-desc { font-size: .92rem; line-height: 1.6; }
.detail-source a { color: var(--teal); font-size: .85rem; }
.detail-line { margin: 6px 0; font-size: .92rem; }
.detail-note { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .92rem; }
.detail-meta { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); font-size: .72rem; color: var(--text-soft); }
.entry-card { cursor: pointer; }

/* Strukturierte Fakten-Abschnitte */
.fact-sec { margin: 12px 0; }
.fact-sec h4 { font-family: var(--font-display); font-size: 1rem; margin: 0 0 4px; color: var(--moos); }
[data-theme="dark"] .fact-sec h4, [data-theme="auto"] .fact-sec h4 { color: #8fb89a; }
.fact-sec p { margin: 0; font-size: .92rem; line-height: 1.55; }
.fact-sec ul { margin: 0; padding-left: 20px; font-size: .92rem; line-height: 1.5; }
.fact-sec li { margin-bottom: 3px; }
.place-line { font-size: .8rem; color: var(--text-soft); margin-top: 3px; }
