/* Pulsing highlight for selected elements — opacity only, no transform (avoids drift) */
@keyframes pulse-opacity {
    0%   { opacity: 0.9; }
    50%  { opacity: 0.25; }
    100% { opacity: 0.9; }
}
.pulse-marker {
    animation: pulse-opacity 1s ease-in-out infinite;
}
.highlight-pulse {
    animation: pulse-opacity 0.8s ease-in-out infinite;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f6f9;
}

.app-container {
    height: 100vh;
    width: 100vw;
}

/* Logo */

.app-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.app-logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.2rem;
}

.app-logo-text {
    display: flex;
    flex-direction: column;
}

.app-logo-title {
    font-weight: 700;
    font-size: 1.2rem;
    color: #0f172a;
}

.app-logo-subtitle {
    font-size: 0.8rem;
    color: #64748b;
}

.app-logo--sidebar .app-logo-title,
.app-logo--sidebar .app-logo-subtitle {
    color: #e0e6f0;
}

/* Login */

.login-page {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: #ffffff;
    padding: 2.5rem 3rem;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    max-width: 420px;
    width: 100%;
}

.login-card h1 {
    margin: 0 0 0.5rem 0;
    font-size: 1.6rem;
}

.login-subtitle {
    margin: 0 0 1.5rem 0;
    color: #555;
    font-size: 0.95rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-form label {
    font-size: 0.9rem;
    font-weight: 500;
}

.login-form input {
    padding: 0.5rem 0.75rem;
    border-radius: 5px;
    border: 1px solid #ccd3dd;
    font-size: 0.95rem;
}

.login-form button {
    margin-top: 1rem;
    padding: 0.6rem 0.75rem;
    border: none;
    border-radius: 5px;
    background: #0066cc;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.login-form button:hover {
    background: #0053a3;
}

.login-hint {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: #777;
}

.error-box {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 5px;
    background: #ffe0e0;
    color: #a00;
    font-size: 0.9rem;
}

/* Dashboard-Layout */

.dashboard-layout {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    height: 100%;
}

/* Links */

.sidebar-left {
    background: #0d1b2a;
    color: #e0e6f0;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.sidebar-header {
    margin-bottom: 1rem;
}

.main-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-btn {
    width: 100%;
    text-align: left;
    margin-bottom: 0.4rem;
    padding: 0.5rem 0.7rem;
    border-radius: 5px;
    border: none;
    background: transparent;
    color: #e0e6f0;
    cursor: pointer;
    font-size: 0.95rem;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.menu-danger {
    color: #fecaca;
}

.menu-danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

.sidebar-footer {
    margin-top: auto;
    font-size: 0.85rem;
}

.logout-link {
    color: #ffcc66;
    font-size: 0.9rem;
    text-decoration: none;
}

/* Sidebar-Footer: Profil + Abmelden untereinander (nicht nebeneinander) */
.sidebar-footer .logout-link {
    display: block;
    width: 100%;
}

.sidebar-footer .logout-link + .logout-link {
    margin-top: 0.35rem;
}

.logout-link:hover {
    text-decoration: underline;
}

.user-info {
    margin-top: 0.6rem;
    color: #aeb9cc;
}

/* Karte */

.main-map {
    position: relative;
}

.map-container {
    height: 100%;
    width: 100%;
    position: relative;
}

/* Hintergrund-Schweiz: Strassen-Beschriftung */
.street-label-icon-wrapper {
    pointer-events: none; /* nicht klickbar, nicht auswählbar */
}

.street-label-outer {
    display: flex;
    align-items: center;
    justify-content: center;
}

.street-label-inner {
    font-size: 11px;
    font-weight: 500;
    color: #444;
    white-space: nowrap;
    padding: 1px 4px;
    /* leichte „Leuchtkante“ gegen den weissen Strassenpuffer */
    text-shadow:
        0 0 2px #ffffff,
        0 0 4px #ffffff;

    transform-origin: 50% 50%; /* Drehung um die Mitte */
}

/* Map Search */

.map-search-box {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 500;
    background: rgba(15, 23, 42, 0.8);
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.35);
}

.map-search-box input {
    border: none;
    outline: none;
    padding: 0.3rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    min-width: 220px;
}

/* Map Tools */

.map-tools {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.map-tool-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-tool-btn:hover {
    background: #e9f1ff;
}

.map-tool-btn.active {
    background: #0066cc;
    color: #ffffff;
    border-color: #0066cc;
}

/* Map Status unten links */

.map-status {
    position: absolute;
    bottom: 4px;
    left: 8px;
    z-index: 500;
    padding: 0.2rem 0.5rem;
    background: rgba(15, 23, 42, 0.8);
    color: #e5e7eb;
    border-radius: 4px;
    font-size: 0.75rem;
    display: flex;
    gap: 0.75rem;
}

/* Label für Längenmessung in der Karte */
.measure-label-box {
    background: #ffffff;
    border-radius: 4px;
    padding: 2px 6px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    font-size: 0.8rem;
    color: #0f172a;
    white-space: nowrap;
}

/* Leaflet-Controls anpassen, damit nichts überlappt */

.leaflet-control-scale {
    margin-left: 8px !important;
    margin-bottom: 28px !important; /* über der map-status-Box */
}

/* Rechts */

.sidebar-right {
    background: #f8fafc;
    border-left: 1px solid #dde3ee;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-right h3 {
    margin-top: 0;
}

.tool-group h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    color: #333;
}

.tool-btn {
    width: 100%;
    text-align: left;
    margin-bottom: 0.3rem;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    border-radius: 5px;
    border: 1px solid #ccd3dd;
    background: #ffffff;
    cursor: pointer;
}

.tool-btn:hover {
    background: #e9f1ff;
}

.tool-primary {
    background: #0066cc;
    color: #fff;
    border-color: #0066cc;
}

.tool-primary:hover {
    background: #0053a3;
}

.tool-secondary {
    background: #ffffff;
    color: #0066cc;
    border-color: #0066cc;
}

.tool-secondary:hover {
    background: #e9f1ff;
}

.btn-danger {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-danger:hover {
    background: #991b1b;
}

/* Modal */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: #ffffff;
    border-radius: 10px;
    width: 800px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.35);
}

/* Stammdaten-Modal darf mehr Breite nutzen (für Gemeinden-Picker) */
#masterdata-modal .modal {
    width: 980px;
    max-width: 95vw;
}

/* --- Layer-Ansichten breiter: stabiler Layout bei BGDATA-Spinner --- */
#layerviews-modal .modal {
  width: 860px;
  max-width: calc(100vw - 80px);
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 1.6rem;
    cursor: pointer;
    color: #64748b;
}

.modal-close:hover {
    color: #0f172a;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 1.5rem;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.5rem 0.9rem;
    border-radius: 6px 6px 0 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: #64748b;
}

.tab-btn.active {
    background: #ffffff;
    border-bottom-color: #0066cc;
    color: #0f172a;
    font-weight: 600;
}

.modal-body {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.form-row {
    margin-bottom: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.form-row label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #111827;
}

.form-row input,
.form-row select,
.form-row textarea {
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    font-size: 0.9rem;
    font-family: inherit;
}

.modal-footer {
    padding: 0.8rem 1.5rem 1.1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

.layer-tab-footnote{
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.35;
}

.btn-primary,
.btn-secondary {
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
}

.btn-primary {
    background: #0066cc;
    color: #ffffff;
}

.btn-primary:hover {
    background: #0053a3;
}

.btn-secondary {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

/* -------------------------------------------------------------
   Stammdaten – Gemeinden-Picker (Option 1: Chips + Suche + Liste)
   ------------------------------------------------------------- */

.masterdata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 900px) {
    .masterdata-grid {
        grid-template-columns: 1fr;
    }
}

.muni-picker-top {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.muni-picker-searchrow {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

#md-municipalities-chips {
    flex: 1 1 420px;
}

#md-municipalities-search {
    flex: 1 1 280px;
}

/* Chips */
#md-municipalities-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.82rem;
    border: 1px solid #cbd5f5;
    background: #e5edff;
    color: #0f172a;
}

.chip-remove {
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    font-size: 1.05rem;
    line-height: 1;
    padding: 0;
}

.chip-remove:hover {
    color: #0f172a;
}

/* Liste */
#md-municipalities-list {
    max-height: 260px;
    overflow: auto;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 0.45rem;
    background: #ffffff;
}

.muni-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.35rem;
    border-radius: 5px;
    cursor: pointer;
}

.muni-row:hover {
    background: #f1f5f9;
}

.muni-cb {
    width: 16px;
    height: 16px;
}

.muni-label {
    font-size: 0.9rem;
    color: #0f172a;
}

/* Zähler */
#md-municipalities-count {
    font-size: 0.85rem;
    color: #64748b;
    white-space: nowrap;
}

/* -------------------------------------------------------------
   Stammdaten – Gemeinden-Picker (Split-Layout: Liste links, Chips rechts)
   ------------------------------------------------------------- */

.muni-picker-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 0.9rem;
    align-items: start;
}

@media (max-width: 900px) {
    .muni-picker-split {
        grid-template-columns: 1fr;
    }
}

.muni-picker-left {
    min-width: 0;
}

.muni-picker-right {
    min-width: 0;
}

.muni-picker-right-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.45rem;
}

/* Chips rechts wie ein eigenes Panel */
.muni-picker-right #md-municipalities-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.55rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    max-height: 260px;
    overflow: auto;
}

/* Im Split-Layout sollen die alten Flex-Breiten nicht greifen */
.muni-picker-split #md-municipalities-chips {
    flex: initial;
}

/* Responsiv */

@media (max-width: 1100px) {
    .dashboard-layout {
        grid-template-columns: 220px 1fr;
        grid-template-rows: auto auto;
    }

    .sidebar-right {
        grid-column: 1 / span 2;
        border-left: none;
        border-top: 1px solid #dde3ee;
    }
}

/* WICHTIG: hidden MUSS am Ende stehen und alles überstimmen */
.hidden {
    display: none !important;
}

/* Verschiebt die Leaflet Zoom-Buttons etwas weiter nach unten,
   damit die Suchleiste oben links nicht überdeckt wird */
.leaflet-top.leaflet-left {
    top: 55px !important;
}

/* -------------------------------------------------------------
   LAYER-ANSICHTEN: Einheitliches Layout der Layer-Zeilen
   -------------------------------------------------------------
   Jede Zeile besteht aus:
   1) einer Checkbox (sichtbar / unsichtbar)
   2) einem Layernamen (Label)
   3) einem Transparenz-Slider (0–100 %)
   
   Die Grid-Struktur sorgt für:
   - saubere, gleiche Ausrichtung aller Elemente
   - ausreichend Platz für lange Layer-Namen
   - ein einheitliches Look & Feel über alle Layer-Gruppen hinweg

   Hinweis:
   Dieses Layout wird NUR für die Layer-Reiter verwendet,
   nicht für Stammdaten oder Tools. Änderungen hier wirken
   direkt auf alle Layer des "Hintergrund / Schweiz"-Tabs
   sowie später auf Stammdaten- und Berechnungslayer.
-------------------------------------------------------------- */
.layer-row {
    display: grid;
    min-width: 0;
    grid-template-columns: 22px 1fr 120px; /* Checkbox | Label | Slider */
    align-items: center;
    gap: 0.6rem;
    padding: 0.3rem 0;
    font-size: 0.85rem; /* etwas kleiner, damit lange Layernamen nicht gequetscht sind */
}
/* Spezielles Layout für Hintergrund-Schweiz-Layer:
   Checkbox | Label | Spinner | Datum | Update | Slider
   (Spinner-Spalte fix, damit beim Ein-/Ausblenden nichts „umbricht“)
*/
.layer-row-bg {
    grid-template-columns: 22px minmax(0, 1fr) 20px auto auto 120px;
}

/* Explizite Spaltenzuordnung – robust, auch wenn der Spinner als eigenes Element
   in die Zeile eingefügt wird (keine zweite Zeile / kein Layout-Hüpfen) */
.layer-row-bg label,
.layer-row-bg .layer-label {
    grid-column: 2;
}

.layer-row-bg .bgdata-spinner {
    grid-column: 3;
    justify-self: start;
}

.layer-row-bg .layer-meta-date {
    grid-column: 4;
}

.layer-row-bg .layer-update-btn {
    grid-column: 5;
}

.layer-row-bg .layer-opacity-slider {
    grid-column: 6;
}

/* Label in Layer-Zeilen: immer einzeilig, kein "Layout-Hüpfen" */
.layer-row label,
.layer-row-bg label,
.layer-row .layer-label,
.layer-row-bg .layer-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* wichtig für Grid: erlaubt Ellipsis statt Umbruch */
}

/* Datum-Label (kompakt) */
.layer-meta-date {
    font-size: 0.78rem;
    color: #64748b;
    white-space: nowrap;
}

/* Update-Button schlank halten */
.layer-update-btn {
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #cbd5f5;
    background-color: #e5edff;
    cursor: pointer;
}

.layer-update-btn:hover {
    background-color: #d4e4ff;
}

/* BGDATA: Spinner nie im Update-Button rendern (Spinner gehört in die eigene Grid-Spalte) */
.layer-update-btn .bgdata-spinner {
    display: none !important;
    visibility: hidden !important;
}

/* -------------------------------------------------------------
   Transparenz-Slider für Layer
   -------------------------------------------------------------
   - Einheitliche Breite
   - Wird rechtsbündig in der layer-row dargestellt
-------------------------------------------------------------- */
.layer-opacity-slider {
    width: 110px;
}
/* Info-Box für Perimeter im Layer-Ansichten-Modal */
.perimeter-info {
    margin-bottom: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    background-color: #eff6ff;  /* leichtes Blau */
    border: 1px solid #bfdbfe;  /* Blauton Rahmen */
    font-size: 0.8rem;
    color: #1e3a8a;            /* dunkleres Blau */
}
.layer-perimeter-info {
    font-size: 0.85rem;
    color: #555;
    margin: 0 0 0.5rem 0;
}

.street-label {
    font-size: 10px;
    font-family: system-ui, sans-serif;
    color: #444;
    text-shadow: 0 0 3px rgba(255,255,255,0.9);
    white-space: nowrap;
}

.street-label-outer,
.street-label-inner,
.street-label-icon-wrapper {
    display: none;
}

.selection-info-panel {
    position: absolute;
    /* Panel schwebt innerhalb der Karte */
    bottom: 8px;
    right: 10px;
    z-index: 600;

    background: rgba(255, 255, 255, 0.96);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);

    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;

    max-width: 360px;
    max-height: 35vh;              /* statt fixe 180px → ca. ein Drittel des Screens */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* flüssiges Scrollen auf macOS/iOS */
}

/* Rest bleibt wie von dir schon definiert */
.selection-info-panel table.selection-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.selection-info-panel table.selection-table th,
.selection-info-panel table.selection-table td {
    padding: 0.25rem 0.4rem;
    border-bottom: 1px solid #e2e8f0;
}
.selection-info-panel tr.selection-more-row td {
    font-style: italic;
    color: #64748b;
}
.selection-info-panel tr[data-type][data-index] {
    cursor: pointer;
}
.selection-info-panel tr[data-type][data-index]:hover {
    background-color: #f1f5f9;
}

.heating-hexagon-wrapper {
    /* keine speziellen Styles notwendig, dient als Container */
}

.heating-hexagon {
    width: 8px;
    height: 8px;
    /* echtes Sechseck: */
    clip-path: polygon(
        25% 0%,
        75% 0%,
        100% 50%,
        75% 100%,
        25% 100%,
        0% 50%
    );
    border: 0.5px solid #111827;
    box-sizing: border-box;
}
/* --- BGDATA: Loading-State + Toast (minimal-invasiv) --- */
.bgdata-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  visibility: hidden;          /* Platz reservieren, aber unsichtbar */
  animation: bgdata-spin 0.8s linear infinite;
  margin: 0;
  vertical-align: middle;
  opacity: 0.8;
}

.bgdata-loading .bgdata-spinner { visibility: visible; }

@keyframes bgdata-spin { to { transform: rotate(360deg); } }

#bgdata-toast-container{
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}

.bgdata-toast{
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  font-size: 13px;
  line-height: 1.25;
  background: rgba(20,20,20,0.92);
  color: #fff;
}

.bgdata-toast.info  { background: rgba(20,120,80,0.92); }
.bgdata-toast.warn  { background: rgba(180,120,20,0.92); }
.bgdata-toast.error { background: rgba(160,40,40,0.92); }