/* ========== Basis / Tokens ========== */
:root {
  --bg: #0f1422;
  --panel: #151b2b;
  --card: #1a2236;
  --line: #2a3550;
  --txt: #e9eef5;
  --muted: #9aa3ad;
  --acc: #27acd4;

  --ctrl-scale: 1.12;
  --radius: 14px;

  --pad-y: calc(12px * var(--ctrl-scale));
  --pad-x: calc(14px * var(--ctrl-scale));
  --fs-base: calc(15px * var(--ctrl-scale));
  --fs-label: calc(14px * var(--ctrl-scale));
  --gap: calc(14px * var(--ctrl-scale));
  --shadow-panel: 0 10px 28px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.ts-body {
  background: var(--bg);
  color: var(--txt);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Layout ========== */
.ts-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  grid-template-rows: 100vh;
}

.ts-sidebar {
  height: 100vh;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px;
}

.ts-title {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .2px;
}

.ts-muted { color: var(--muted); font-size: 13px; }

/* ========== Controls (Sort + Filter) ========== */
.ts-controls {
  margin-top: 18px;
  display: grid;
  gap: var(--gap);
  background: linear-gradient(180deg, rgba(255, 255, 255, .02), rgba(255, 255, 255, 0));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: calc(12px * var(--ctrl-scale));
  box-shadow: var(--shadow-panel);
}
.ts-control { display: grid; gap: 8px; }

.ts-label {
  display: block;
  margin: 0;
  font-size: var(--fs-label);
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .2px;
}

.ts-select, .ts-input, .ts-accordion-toggle {
  width: 100%;
  background: #121828;
  border: 1px solid var(--line);
  color: var(--txt);
  padding: var(--pad-y) var(--pad-x);
  border-radius: var(--radius);
  font-size: var(--fs-base);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .06s ease;
}
.ts-select:hover, .ts-input:hover, .ts-accordion-toggle:hover { border-color: #2f3c5d; }
.ts-select:focus, .ts-input:focus, .ts-accordion-toggle[aria-expanded="true"] {
  border-color: var(--acc);
  box-shadow: 0 0 0 4px rgba(39, 172, 212, .22);
}

/* Select: Chevron */
.ts-select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);
  background-position:
    calc(100% - 22px) calc(50% - 3px),
    calc(100% - 14px) calc(50% - 3px),
    calc(100% - 2.2em) .5em;
  background-size: 8px 8px, 8px 8px, 1px 1.8em;
  background-repeat: no-repeat;
  padding-right: 46px;
}

/* Accordion-Toggle mit Pfeil */
.ts-accordion-toggle {
  text-align: left;
  font-weight: 700;
  position: relative;
}
.ts-accordion-toggle::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-50%) rotate(45deg);
  opacity: .85;
}
.ts-accordion-toggle[aria-expanded="true"]::after {
  transform: translateY(-35%) rotate(-135deg);
}

/* Accordion-Body */
.ts-accordion-body {
  margin-top: 8px;
  background: #0f1527;
  border: 1px solid #2a3550;
  border-radius: calc(var(--radius) - 4px);
  padding: calc(10px * var(--ctrl-scale));
}

/* Filter-Checkboxen (kleine Kacheln / Chips) */
.ts-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ts-check {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a2236;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--txt);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.ts-check:hover {
  border-color: var(--acc);
  background: #202a42;
}
.ts-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--acc);
}

/* Buttons (Alle/Keine) */
.ts-accordion-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.ts-btn {
  background: #1b2340;
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: calc(14px * var(--ctrl-scale));
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .06s ease;
}
.ts-btn.sm { padding: 8px 12px; font-size: calc(13px * var(--ctrl-scale)); }
.ts-btn:hover { border-color: var(--acc); }
.ts-btn:active { transform: translateY(1px); }

/* ========== Kachelmenü ========== */
.ts-tiles { display: grid; gap: 12px; margin-top: 16px; }
.ts-tiles-tours { grid-template-columns: 1fr; }

.ts-tile {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--txt);
  transition: transform .06s ease, border-color .12s ease, box-shadow .12s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.ts-tile:hover {
  transform: translateY(-1px);
  border-color: var(--acc);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .24);
}
.ts-tile-title {
  font-size: calc(16px * var(--ctrl-scale));
  font-weight: 800;
  margin: 0 0 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ts-tile-meta {
  font-size: calc(14px * var(--ctrl-scale));
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Karte & Leaflet ========== */
.ts-map { height: 100vh; }
.leaflet-container { background: #0c1220; outline: none; }

.leaflet-control-layers {
  background: #121828;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--txt);
}
.leaflet-control-layers-expanded { background: #121828; color: var(--txt); }
.leaflet-control-layers-expanded label { color: var(--txt); }
.leaflet-control-layers-toggle { filter: invert(1) hue-rotate(180deg); }
.leaflet-bar a, .leaflet-bar a:hover {
  background: #121828;
  border-bottom: 1px solid var(--line);
  color: var(--txt);
}
.leaflet-bar a:hover { border-color: var(--acc); }

/* Legende unten links */
.ts-legend {
  position: fixed;
  left: 12px;
  bottom: 10px;
  z-index: 500;
  background: rgba(18, 24, 40, .92);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
}

/* ========== Popup Styling ========== */
.leaflet-popup.ts-popup .leaflet-popup-content-wrapper {
  background: #222;
  color: #fff;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
  padding: 6px 10px;
}
.leaflet-popup.ts-popup .leaflet-popup-tip {
  background: #222;
  border: 1px solid rgba(255, 255, 255, .12);
}
.ts-popup .ts-popup-body {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  padding: 4px 2px;
}
.ts-popup .ts-popup-body em {
  font-style: normal;
  color: #9aa3ad;
  font-weight: 500;
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
}
.leaflet-popup-close-button { color: #fff !important; font-size: 18px; }

/* ========== Responsive ========== */
@media (max-width: 980px) {
  .ts-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh;
  }
  .ts-sidebar {
    height: auto;
    max-height: 70vh;
    overflow: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .ts-map { height: 60vh; }
  .ts-controls {
    padding: calc(14px * var(--ctrl-scale));
    gap: calc(16px * var(--ctrl-scale));
  }
  .ts-tiles-tours { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .ts-tiles-tours { grid-template-columns: 1fr; }
}
/* ===== Mobile: Vollbild-Karte + Sidebar als Overlay ===== */
@media (max-width: 980px) {
  /* Karte nimmt die ganze Höhe */
  .ts-layout{
    grid-template-columns: 1fr;
    grid-template-rows: 100vh; /* volle Höhe */
  }
  .ts-map{ height: 100vh; }

  /* Sidebar als Off-Canvas Overlay */
  .ts-sidebar{
    position: fixed;
    inset: 0 auto 0 0;      /* links andocken */
    width: min(92vw, 420px);
    max-width: 92vw;
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .25s ease, box-shadow .25s ease;
    z-index: 1000;
    box-shadow: 18px 0 42px rgba(0,0,0,.45);
    border-right: 1px solid var(--line);
    border-bottom: none;
  }
  .ts-sidebar.is-open{
    transform: translateX(0);
  }

  /* Body nicht scrollen, wenn Overlay offen */
  body.noscroll{ overflow: hidden; }

  /* Close-Button in der Sidebar (nur mobil sichtbar) */
  .ts-close-mobile{
    position: sticky;
    top: 0;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: #1f2942;
    color: var(--txt);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    z-index: 2;
  }

  /* Floating Action Button: Filter öffnen */
  .ts-fab{
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 900;
    background: var(--acc);
    color: #062430;
    border: none;
    border-radius: 999px;
    padding: 12px 16px;
    font-weight: 800;
    box-shadow: 0 10px 28px rgba(0,0,0,.35);
    cursor: pointer;
  }

  /* Legende etwas anheben, damit sie nicht mit FAB kollidiert */
  .ts-legend{ bottom: 66px; left: 12px; }
}

/* Optional: leichte Vergrößerung der Layer-Control auf sehr kleinen Screens */
@media (max-width: 420px){
  .leaflet-control-layers{ font-size: 14px; }
}
/* ===== X-Button ausblenden ===== */
.ts-close-mobile { display: none !important; }

/* ===== Backdrop + Vollbreite-Overlay auf Mobile ===== */
.ts-backdrop { display: none; }

@media (max-width: 980px) {
  /* Layout: Karte volle Höhe */
  .ts-layout{
    grid-template-columns: 1fr;
    grid-template-rows: 100vh;
  }
  .ts-map{ height:100vh; }

  /* Sidebar als Overlay in VOLLER Breite */
  .ts-sidebar{
    position: fixed;
    inset: 0;                 /* oben/rechts/unten/links = 0 */
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .25s ease, box-shadow .25s ease;
    z-index: 1000;            /* über Karte und FAB */
    box-shadow: 18px 0 42px rgba(0,0,0,.45);
    border-right: 1px solid var(--line);
    border-bottom: none;
  }
  .ts-sidebar.is-open{ transform: translateX(0); }
  body.noscroll{ overflow: hidden; }

  /* Backdrop unter Sidebar */
  .ts-backdrop{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 950;
    display: none;
  }
  .ts-backdrop.is-open{ display: block; }

  /* Floating Button */
  .ts-fab{
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 900;
    background: var(--acc);
    color: #062430;
    border: none;
    border-radius: 999px;
    padding: 12px 16px;
    font-weight: 800;
    box-shadow: 0 10px 28px rgba(0,0,0,.35);
    cursor: pointer;
  }

  /* Legende mittig unten, oberhalb FAB */
  .ts-legend{
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: 66px;
  }
}

/* Desktop/Tablet: Legende ebenfalls mittig (wenn gewünscht) */
.ts-legend{
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

/* Z-Index Ordnung */
.leaflet-container { z-index: 1; }

/* Mobile: Legende noch weiter nach unten */
@media (max-width: 980px){
  .ts-legend{
    bottom: 14px;    /* vorher 66px */
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}
