:root {
    --friedwald-green: #5e8b4f;
    --friedwald-green-dark: #4a6e3d;
    --friedwald-green-light: #e8f5e9;
    --friedwald-beige: #f5f3f0;
    --header-height: 140px;
    --font-size-base: 13px;
    --font-size-small: 12px;
    --font-size-strong: 16px;
    --font-size-badge: 11px;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow-x: hidden;
}

body {
    padding-top: var(--header-height);
    box-sizing: border-box;

    &.update-body {
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        background: linear-gradient(135deg, #4a7c59 0%, #3a5f47 100%);
    }
}

body.font-size-1 {
    --font-size-base: 13px;
    --font-size-small: 12px;
    --font-size-strong: 16px;
    --font-size-badge: 11px;
}

body.font-size-2 {
    --font-size-base: 15px;
    --font-size-small: 14px;
    --font-size-strong: 18px;
    --font-size-badge: 12px;
}

body.font-size-3 {
    --font-size-base: 17px;
    --font-size-small: 16px;
    --font-size-strong: 20px;
    --font-size-badge: 13px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#map {
    height: calc(100vh - var(--header-height));
    margin: 0;
}

.orientation-blocker {
    position: fixed;
    inset: 0;
    background: #ffffff;
    color: #1f1f1f;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
}

.orientation-blocker__content {
    max-width: 360px;
    display: grid;
    gap: 8px;
    font-size: var(--font-size-base);
}

.topbar {
    position: fixed;
    z-index: 900;
    left: 0;
    right: 0;
    top: 0;
    background: #fff;
    padding: 12px 20px;
    border-radius: 0;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    max-width: none;
    border-bottom: 1px solid #ddd;
    width: 100%;
    box-sizing: border-box;

    .topbar-inner {
        max-width: none;
        margin: 0;
    }

    .topbar-header {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 16px;
        margin-bottom: 8px;
    }

    .topbar-utility {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 12px;
        margin-bottom: 8px;
    }

    .topbar-utility-actions {
        display: flex;
        gap: 10px;
        align-items: center;
        justify-content: flex-start;
        margin-bottom: 8px;
    }

    .topbar-utility-left {
        display: flex;
        align-items: center;
        gap: 10px;
        flex-wrap: wrap;
    }

    .legend-toggle-top {
        justify-self: end;
        background: #f5f5f5;
        color: #2f3a2f;
        border: 1px solid #e0e0e0;
        padding: 6px 10px;
        font-size: var(--font-size-base);
        width: 50%;
    }

    .legend-toggle-top:hover {
        background: #eeeeee;
        color: #2f3a2f;
    }

    .show-filters-btn {
        display: none;
        background: #f5f5f5;
        color: #2f3a2f;
        border: 1px solid #e0e0e0;
        padding: 6px 10px;
        font-size: var(--font-size-base);
        width: 50%;
    }

    .show-filters-btn:hover {
        background: #eeeeee;
        color: #2f3a2f;
    }
}

.logo-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.font-size-controls {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.font-size-controls button {
    min-width: 36px;
}

.logo-subtitle {
    font-size: var(--font-size-small);
    color: #6b6b6b;
    margin-top: 2px;
}

.friedwald-logo {
    height: 40px;
    display: block;
}

.friedwald-logo-mini {
    height: 22px;
    display: none;
    margin-left: 6px;
    justify-self: end;
}

.row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;

    &:last-child {
        margin-bottom: 0;
    }

    &.row-top {
        margin-top: 8px;
    }
}

.field-group.inline-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    width: 100%;
}

.field-group .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

@media (min-width: 769px) {
    .row .field {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .row .field label {
        margin: 0;
        white-space: nowrap;
    }

    .row .field input,
    .row .field select {
        width: auto;
        min-width: 160px;
        flex: 1 1 auto;
    }

    .field-group.inline-2 {
        width: auto;
        grid-template-columns: auto auto;
    }

    .field-group.inline-2 .field {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .field-group.inline-2 .field label {
        margin: 0;
        white-space: nowrap;
    }

    .field-group.inline-2 select {
        width: auto;
        min-width: 140px;
    }

    .legend-toggle-top,
    .show-filters-btn {
        width: auto;
    }
}

strong {
    color: var(--friedwald-green-dark);
    font-size: var(--font-size-strong);
    font-weight: 600;
}

label {
    color: #666;
    font-size: var(--font-size-small);
    font-weight: 500;
    margin: 0;
}

input,
select {
    padding: 6px 10px;
    font-size: var(--font-size-base);
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-family: inherit;
    transition: all 0.2s;
    box-sizing: border-box;

    &:focus {
        outline: none;
        border-color: var(--friedwald-green);
        box-shadow: 0 0 0 2px var(--friedwald-green-light);
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 240px;
    }

    .topbar {
        padding: 12px 14px;
    }

    .topbar-header {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .topbar-title {
        flex: 1 1 100%;
    }

    .row {
        gap: 8px;
        align-items: stretch;
    }

    .row .field,
    .row button {
        width: 100%;
    }

    .row .field label,
    .row .field input,
    .row .field select {
        width: 100%;
    }

}

button {
    padding: 6px 12px;
    font-size: var(--font-size-base);
    border-radius: 4px;
    border: none;
    background: var(--friedwald-green);
    color: white;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;

    &:hover {
        background: var(--friedwald-green-dark);
    }
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--friedwald-green-dark);
    outline-offset: 2px;
}

#loadBtn,
#clearBtn {
    background: var(--friedwald-green);
    color: white;

    &:hover {
        background: var(--friedwald-green-dark);
        transform: translateY(-1px);
        box-shadow: 0 2px 8px rgba(74, 124, 89, 0.3);
    }
}

.muted {
    color: #5f6368;
    font-size: var(--font-size-small);
    line-height: 1.5;

    &.muted-top {
        margin-top: 8px;
    }
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: var(--font-size-badge);
    font-weight: 600;
}

.b-frei {
    background: var(--friedwald-green-light);
    color: var(--friedwald-green-dark);
}

.b-belegt {
    background: #fce8e6;
    color: #c5221f;
}

.b-unk {
    background: #f1f3f4;
    color: #5f6368;
}

body.topbar-collapsed .topbar {
    max-height: 25vh;
    padding-top: 8px;
    padding-bottom: 8px;
    overflow: hidden;
}

body.topbar-collapsed .topbar-inner {
    max-height: 25vh;
    overflow-y: auto;
    padding-bottom: 12px;
}

body.topbar-collapsed .topbar .row,
body.topbar-collapsed .muted-top,
body.topbar-collapsed .bookmarks-section,
body.topbar-collapsed .all-mode-info {
    display: none;
}

body.topbar-collapsed .topbar-filters {
    display: none;
}

body.topbar-collapsed .font-size-controls {
    display: none;
}

body.topbar-collapsed .topbar-header {
    display: none;
}

body.topbar-collapsed .friedwald-logo-mini {
    display: inline-block;
}

body.topbar-collapsed .show-filters-btn {
    display: inline-flex;
}

@media (orientation: landscape) and (max-width: 1024px) {
    .orientation-blocker {
        display: flex;
    }

    body {
        overflow: hidden;
    }
}


.legend-section-title {
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 8px;
    color: var(--friedwald-green-dark);
    font-size: 13px;

    &.spaced {
        margin-top: 16px;
    }
}

.legend-icon {
    font-size: 16px;
    margin-right: 10px;
}


.leaflet-popup-pane {
    z-index: 1200;
}

.leaflet-control-container {
    z-index: 800;
}

.legend-item {
    display: flex;
    align-items: center;
    margin: 6px 0;
    color: #3c4043;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;

    &.legend-color-familienbaum {
        background: #8B4513;
    }

    &.legend-color-partnerbaum {
        background: #FF6B9D;
    }

    &.legend-color-gemeinschaftsbaum {
        background: #9370DB;
    }

    &.legend-color-basisgemeinschaftsbaum {
        background: #4169E1;
    }

    &.legend-color-generationenbaum {
        background: #20B2AA;
    }

    &.legend-color-freundschaftsbaum {
        background: #FFD700;
    }

    &.legend-color-baum {
        background: #FF8C00;
    }

    &.legend-color-platz {
        background: #32CD32;
    }

    &.legend-color-basisplatz {
        background: #00CED1;
    }

    &.legend-color-platz-am-gemeinschaftsbaum {
        background: #BA55D3;
    }

    &.legend-color-sternschnuppenbaum {
        background: #FFB6C1;
    }

    &.legend-color-unbekannt {
        background: #808080;
    }
}

.legend-status {
    display: flex;
    align-items: center;
    margin: 6px 0;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e8eaed;
    color: #3c4043;
}

.legend-ring {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
    border: 3px solid;
}

.menu-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: none;
}

.menu-modal__panel {
    position: absolute;
    inset: 0;
    background: #fff;
    display: flex;
    flex-direction: column;
    padding: 16px 18px;
    box-sizing: border-box;
}

.menu-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.menu-modal__close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #5f6368;
}

.menu-modal__tabs {
    display: flex;
    gap: 8px;
    margin: 12px 0;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 8px;
}

.menu-tab {
    padding: 6px 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    font-weight: 500;
    border-radius: 4px 4px 0 0;
    transition: all 0.2s;
}

.menu-tab.active {
    color: var(--friedwald-green-dark);
    background: var(--friedwald-green-light);
    font-weight: 600;
}

.menu-modal__content {
    flex: 1;
    overflow: auto;
    padding-right: 6px;
}

.menu-tab-content {
    display: none;
}

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

@media (min-width: 769px) {

    .topbar-utility-actions .legend-toggle-top,
    .topbar-utility-actions .show-filters-btn {
        width: auto;
    }
}

.ring-frei {
    border-color: var(--friedwald-green);
    background: #fff;
}

.ring-belegt {
    border-color: #c5221f;
    background: #fff;
}

.bookmark-btn {
    background: var(--friedwald-green);
    color: white;
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 8px;
    transition: all 0.2s;

    &:hover {
        background: var(--friedwald-green-dark);
        transform: translateY(-1px);
    }

    &.bookmarked {
        background: #c5221f;

        &:hover {
            background: #a50e0e;
        }
    }
}

.bookmarks-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e8eaed;
}

.bookmarks-title {
    font-weight: 500;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #3c4043;
}

.bookmarks-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.bookmark-tag {
    background: var(--friedwald-green-light);
    color: var(--friedwald-green-dark);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;

    &:hover {
        background: var(--friedwald-green);
        color: white;
    }
}

.bookmark-remove {
    font-weight: bold;
    margin-left: 4px;
}

.show-bookmarks-btn {
    background: var(--friedwald-green-light);
    color: var(--friedwald-green-dark);
    border: 1px solid var(--friedwald-green);
    padding: 6px 14px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;

    &:hover {
        background: var(--friedwald-green);
        color: white;
    }

    &.active {
        background: var(--friedwald-green);
        color: white;
    }
}

.tree-marker {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    .tree-marker-inner {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        position: relative;
        z-index: 2;
        color: #fff;

        &.grabart-familienbaum {
            background: #8B4513;
        }

        &.grabart-partnerbaum {
            background: #FF6B9D;
        }

        &.grabart-gemeinschaftsbaum {
            background: #9370DB;
        }

        &.grabart-basisgemeinschaftsbaum {
            background: #4169E1;
        }

        &.grabart-generationenbaum {
            background: #20B2AA;
        }

        &.grabart-freundschaftsbaum {
            background: #FFD700;
        }

        &.grabart-baum {
            background: #FF8C00;
        }

        &.grabart-platz {
            background: #32CD32;
        }

        &.grabart-basisplatz {
            background: #00CED1;
        }

        &.grabart-platz-am-gemeinschaftsbaum {
            background: #BA55D3;
        }

        &.grabart-sternschnuppenbaum {
            background: #FFB6C1;
        }

        &.grabart-unknown {
            background: #808080;
        }
    }

    .tree-marker-ring {
        position: absolute;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        border: 3px solid;
        z-index: 1;

        &.status-frei {
            border-color: #1a8f3a;
        }

        &.status-belegt {
            border-color: #c62828;
        }

        &.status-unk {
            border-color: #666;
        }
    }

    &.bookmarked {
        .tree-marker-inner {
            width: 32px;
            height: 32px;
            font-size: 18px;
        }

        .tree-marker-ring {
            width: 40px;
            height: 40px;
            border-width: 4px;
        }
    }
}

.custom-div-icon {
    background: none !important;
    border: none !important;
}

.all-mode-info {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;

    .all-mode-info-text {
        color: var(--friedwald-green-dark);
        font-size: 13px;
        line-height: 1.6;
    }
}

.loading-indicator {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    text-align: center;

    .loading-indicator__icon {
        font-size: 48px;
        margin-bottom: 15px;
    }

    .loading-indicator__title {
        margin: 0 0 10px 0;
        color: var(--friedwald-green-dark);
        font-size: 18px;
    }
}

.loading-bar {
    width: 300px;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin: 15px 0;

    .loading-bar__fill {
        width: 0%;
        height: 100%;
        background: linear-gradient(90deg, var(--friedwald-green) 0%, var(--friedwald-green-dark) 100%);
        transition: width 0.3s ease;
    }
}

.loading-status {
    color: #666;
    font-size: 13px;
    margin-top: 10px;
}

.popup-content {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
    font-size: 13px;
    line-height: 1.35;
}

.popup-divider {
    border: none;
    border-top: 1px solid #ddd;
    margin: 6px 0;
}

.popup-shop {
    margin-top: 6px;
}

.allmode-marker {
    background: var(--friedwald-green);
    color: white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.allmode-popup {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
    font-size: 14px;
    text-align: center;
}

.allmode-title {
    margin: 0 0 10px 0;
    color: var(--friedwald-green-dark);
}

.allmode-code {
    margin: 8px 0;
}

.allmode-button {
    background: var(--friedwald-green);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    margin-top: 8px;

    &:hover {
        background: var(--friedwald-green-dark);
    }
}

.loader-container {
    text-align: center;
    color: white;
}

.loader {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
}

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

.loader-subtitle {
    margin-top: 10px;
}

.progress-bar {
    width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    margin: 20px auto;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: white;
    border-radius: 4px;
    animation: progress 3s ease-in-out;
}

@keyframes progress {
    from {
        width: 0%;
    }

    to {
        width: 100%;
    }
}