/* Gemeinsames Erscheinungsbild der vier Arbeitsbereiche. */
:root {
    --dashboard-bg: #f6f7f9;
    --dashboard-surface: #ffffff;
    --dashboard-border: #d8dee5;
    --dashboard-text: #253746;
    --dashboard-muted: #607080;
    --dashboard-accent: #4a6da7;
}

/* Mobile rules declared last override legacy fixed-height desktop layouts. */
@media (max-width: 767px) {
    #tab1-layout,
    .tab2-layout,
    .tab3-page,
    .tab4-layout,
    .maxqda-layout {
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        padding-bottom: 12px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    #tab1-layout > #map-container,
    .tab3-layout > .map-pane {
        flex: 0 0 42dvh !important;
        height: 42dvh !important;
        min-height: 260px !important;
    }

    #tab1-layout > #middle-container,
    .tab3-layout > .tab3-right-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 14px !important;
    }

    #toggle-button-container,
    #toggle-button-container-BAMAST { max-width: 100% !important; flex-wrap: wrap !important; gap: 6px; }
    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn,
    .tab4-button-group .btn { min-height: 44px; white-space: normal; }
    #tab2-similarity-scroll-container { max-height: 36dvh; }
    .tab4-card, .tab4-selection-panel { min-width: 0; overflow-wrap: anywhere; }
    .site-footer { bottom: calc(var(--bottom-tabs-height) + 8px); }
}

@media (max-width: 767px) {
    .tab1-map-filter {
        position: fixed !important;
        top: 10px;
        right: 8px;
        left: auto !important;
        bottom: auto !important;
        z-index: 1100 !important;
        width: min(250px, calc(100vw - 16px)) !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.96) !important;
    }
    .tab1-institution-filter { top: 52px; }
    .tab1-map-filter-summary {
        display: block;
        min-height: 36px;
        padding: 9px 11px;
        cursor: pointer;
        color: var(--dashboard-text);
        font-size: 0.82rem;
        font-weight: 700;
        list-style: none;
    }
    .tab1-map-filter-summary::-webkit-details-marker { display: none; }
    .tab1-map-filter:not([open]) { width: auto !important; }
    .tab1-map-filter .row { margin: 0; padding: 3px 10px; }
}

@media (max-width: 767px) {
    #map-container,
    .map-pane {
        max-height: 32dvh !important;
        height: 32dvh !important;
        min-height: 220px !important;
        flex-basis: 32dvh !important;
    }
    #toggle-button-container,
    #toggle-button-container-BAMAST {
        display: flex !important;
        flex-wrap: nowrap !important;
        width: calc(100% + 8px) !important;
        max-width: none !important;
        margin-right: -8px !important;
        padding: 2px 8px 8px 0;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        justify-content: flex-start !important;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }
    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn {
        flex: 0 0 auto !important;
        width: auto !important;
        min-height: 36px !important;
        padding: 7px 11px !important;
        border-radius: 999px !important;
        font-size: 0.8rem !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
    }
}

@media (max-width: 767px) {
    #info-text,
    #dynamic-text,
    #accordion-summary,
    .tab3-right-container,
    .tab4-card,
    .maxqda-toolbar {
        overflow-wrap: anywhere;
        word-break: normal;
    }

    #toggle-button-container,
    #toggle-button-container-BAMAST {
        display: flex !important;
        width: 100% !important;
        max-width: none !important;
        overflow: visible !important;
        justify-content: stretch !important;
    }

    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn {
        flex: 1 1 calc(50% - 8px) !important;
        width: auto !important;
        min-width: 0 !important;
        padding: 9px 6px !important;
        font-size: 0.88rem !important;
        overflow-wrap: anywhere;
    }

    #map-container,
    .map-pane {
        max-height: 32dvh !important;
        height: 32dvh !important;
        min-height: 220px !important;
        flex-basis: 32dvh !important;
    }

    /* Mobile filter controls behave like compact, swipeable chips instead of
       turning into several tall desktop button rows. */
    #toggle-button-container,
    #toggle-button-container-BAMAST {
        display: flex !important;
        flex-wrap: nowrap !important;
        width: calc(100% + 8px) !important;
        max-width: none !important;
        margin-right: -8px !important;
        padding: 2px 8px 8px 0;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        justify-content: flex-start !important;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn {
        flex: 0 0 auto !important;
        width: auto !important;
        min-height: 36px !important;
        padding: 7px 11px !important;
        border-radius: 999px !important;
        font-size: 0.8rem !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
    }
}

/* Final mobile overrides: kept last so legacy desktop inline layouts cannot
   squeeze or clip the phone interface. */
@media (max-width: 767px) {
    #tab1-layout,
    .tab2-layout,
    .tab3-page,
    .tab4-layout,
    .maxqda-layout {
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        padding-bottom: 12px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    #tab1-layout > #map-container,
    .tab3-layout > .map-pane {
        flex: 0 0 42dvh !important;
        height: 42dvh !important;
        min-height: 260px !important;
    }

    #tab1-layout > #middle-container,
    .tab3-layout > .tab3-right-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 14px !important;
    }

    #toggle-button-container,
    #toggle-button-container-BAMAST {
        max-width: 100% !important;
        flex-wrap: wrap !important;
        gap: 6px;
    }

    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn,
    .tab4-button-group .btn {
        min-height: 44px;
        white-space: normal;
    }

    #pie-chart,
    #tab2-pie-chart,
    #tab2-detail-pie-graph,
    #tab4-pie-a,
    #tab4-pie-b {
        width: 100% !important;
        max-width: 100% !important;
    }

    .tab2-layout > div,
    .tab2-layout > div > div,
    .tab2-layout > div > div > div {
        width: 100% !important;
        flex: 0 0 auto !important;
    }

    .tab2-layout > div:nth-child(2) > div {
        flex-direction: column !important;
    }

    #tab2-similarity-scroll-container {
        max-height: 36dvh;
    }

    .tab4-layout {
        padding: 12px !important;
    }

    .tab4-card,
    .tab4-selection-panel {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .tab4-pies .js-plotly-plot,
    .tab4-pies .plot-container {
        width: 100% !important;
    }

    .site-footer {
        bottom: calc(var(--bottom-tabs-height) + 8px);
    }
}

.site-footer {
    position: fixed;
    right: 16px;
    bottom: 10px;
    z-index: 1100;
    padding: 5px 10px;
    border: 1px solid var(--dashboard-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    color: var(--dashboard-muted);
    font-size: 0.78rem;
}

.site-footer a,
.legal-back-link {
    color: var(--dashboard-accent);
    text-decoration: none;
}

.site-footer a:hover,
.legal-back-link:hover {
    text-decoration: underline;
}

.mobile-navigation {
    display: none;
}

.tab1-map-filter-summary { display: none; }

.legal-page-container {
    position: fixed;
    inset: 0;
    z-index: 2000;
    box-sizing: border-box;
    width: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--dashboard-bg);
}

.legal-page {
    box-sizing: border-box;
    width: 100%;
    min-height: 100dvh;
    padding: 48px 20px 72px;
    color: var(--dashboard-text);
}

.legal-page-inner {
    max-width: 760px;
    margin: 0 auto;
    line-height: 1.6;
}

.legal-page h1 {
    margin: 18px 0 24px;
    font-size: 2rem;
}

.legal-page h2 {
    margin: 26px 0 8px;
    font-size: 1.2rem;
}

.legal-page p,
.legal-page ul {
    margin: 0 0 14px;
}

@media (max-width: 767px) {
    .legal-page-container {
        min-height: 100dvh;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .legal-page {
        min-height: 100dvh;
        padding: 32px 16px calc(84px + env(safe-area-inset-bottom, 0px));
    }

    .site-footer { right: 8px; bottom: 8px; }
}

.tab-parent {
    border-bottom: 1px solid var(--dashboard-border);
    background: var(--dashboard-surface);
}

.tab {
    color: var(--dashboard-muted);
    font-weight: 600;
    padding: 11px 18px;
}

.tab--selected {
    color: var(--dashboard-text) !important;
    border-top: 3px solid var(--dashboard-accent) !important;
    background: var(--dashboard-surface) !important;
}

/* Standard Layout für größere Bildschirme */
@media (min-width: 768px) {
    #map {
        width: 100%;
        height: 100%;
    }

    /* Tab 1: Karte & Info nebeneinander */
    #map-container {
        flex: 0 0 66%;
        width: 66%;
        float: left;
    }

    .right-container {
        flex: 1 1 34%;
        width: 34%;
        float: right;
        padding: 10px;
    }

    .toggle-buttons {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 10px;
    }
}

/* Tab 3 has its own grid so Tab 1's float/width rules cannot affect it. */
.tab3-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.tab2-layout,
.tab3-page,
.tab4-layout {
    background: var(--dashboard-bg);
}

.tab2-layout > div {
    background: var(--dashboard-surface);
}

.tab3-page {
    padding: 16px;
}

.tab3-layout {
    gap: 16px;
}

.tab3-layout > .map-pane,
.tab3-layout > .tab3-right-container {
    border: 1px solid var(--dashboard-border);
    border-radius: 10px;
    background: var(--dashboard-surface);
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.tab3-layout > .tab3-right-container {
    overflow-y: auto;
}

#middle-container {
    background: var(--dashboard-surface);
    border-left: 1px solid var(--dashboard-border);
}

.tab-section-title {
    margin: 0 0 12px;
    color: var(--dashboard-text);
    font-size: 1.2rem;
    font-weight: 700;
}

.tab3-intro {
    margin: -5px 0 16px;
    color: var(--dashboard-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

.tab3-layout > .map-pane,
.tab3-layout > .tab3-right-container {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/* Tab 4: Vergleich */
.tab4-layout {
    --tab4-comparison-columns: minmax(0, 1fr) minmax(210px, 0.55fr) minmax(0, 1fr);
    height: calc(100vh - 48px);
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    padding: 18px;
    background: #f6f7f9;
}

.tab4-header {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.tab4-independent-selectors {
    display: grid;
    grid-template-columns: var(--tab4-comparison-columns);
    gap: 16px;
    margin-bottom: 14px;
}

.tab4-selector-bridge {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    gap: 9px;
    color: #607080;
}

.tab4-bridge-link {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab4-selector-bridge span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #6687a6;
    color: white;
    font-size: 0.78rem;
    font-weight: 700;
}

.tab4-selector-bridge span:nth-of-type(2) {
    background: #a76767;
}

.tab4-selector-bridge strong {
    font-size: 1.3rem;
}

.tab4-bridge-metric {
    flex: 0 0 auto;
}

.tab4-bridge-metric .btn {
    min-width: 38px;
}

.tab4-selection-panel {
    min-width: 0;
    padding: 14px;
    border: 1px solid #d8dee5;
    border-top: 4px solid #6687a6;
    border-radius: 10px;
    background: white;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.04);
}

.tab4-selection-panel-b {
    border-top-color: #a76767;
}

.tab4-selection-panel h4 {
    margin: 0 0 10px;
    font-size: 1.05rem;
}

.tab4-selection-panel > label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.82rem;
    font-weight: 700;
}

.tab4-selection-label {
    margin-top: 11px;
}

.tab4-single-site-hint {
    align-items: flex-start;
    margin-top: 11px;
    padding: 8px;
    border-radius: 7px;
    background: #f2f6fa;
}

.tab4-button-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.tab4-button-filters label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.tab4-button-group {
    display: flex;
    width: 100%;
}

.tab4-button-group .btn {
    flex: 1 1 0;
    white-space: normal;
}

.tab4-button-group .tab4-option-unavailable:not(.active) {
    color: #7a7f85;
    background: #e2e5e8;
    border-color: #c9cdd1;
    border-style: dashed;
    cursor: pointer;
    opacity: 0.72;
}

.tab4-button-group .tab4-option-unavailable:not(.active):hover {
    color: #495057;
    background: #d6dade;
    opacity: 1;
}

.tab4-filter {
    min-width: 0;
}

.tab4-filter label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.tab4-qualification-hint {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin: -3px 0 12px;
    padding: 9px 12px;
    border: 1px solid #cfe2ff;
    border-radius: 8px;
    background: #eef6ff;
}

.tab4-qualification-title {
    display: flex;
    flex-direction: column;
    color: #415a77;
    font-size: 0.82rem;
    font-weight: 700;
}

.tab4-qualification-title span {
    color: #60758a;
    font-size: 0.72rem;
    font-weight: 400;
}

.tab4-qualification-item {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.tab4-qualification-item > div {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 0.78rem;
    line-height: 1.25;
}

.tab4-qualification-item strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab4-qualification-item span:not(.tab4-qualification-letter) {
    color: #52606d;
}

.tab4-qualification-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    border-radius: 50%;
    background: #0d6efd;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
}

.tab4-pies {
    display: grid;
    grid-template-columns: var(--tab4-comparison-columns);
    gap: 16px;
}

.tab4-diagram-card-a,
.tab4-diagram-card-b {
    border-top: 4px solid #6687a6;
}

.tab4-diagram-card-b {
    border-top-color: #a76767;
}

.tab4-focus-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 360px;
    background: linear-gradient(180deg, #fff, #f7f9fc);
}

.tab4-focus-placeholder {
    padding: 20px;
    color: #6c757d;
    text-align: center;
}

.tab4-focus-placeholder-title {
    margin-bottom: 8px;
    color: #34495e;
    font-size: 1.05rem;
    font-weight: 700;
}

.tab4-focus-placeholder-text,
.tab4-focus-hint {
    font-size: 0.78rem;
    line-height: 1.35;
}

.tab4-focus-content {
    width: 100%;
    padding: 12px;
    text-align: center;
}

.tab4-focus-swatch {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
}

.tab4-focus-parent {
    color: #6c757d;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.tab4-focus-content h4 {
    margin: 7px 0 16px;
    font-size: 1rem;
    line-height: 1.25;
}

.tab4-focus-values {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.tab4-focus-values > div,
.tab4-focus-delta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px;
    border: 1px solid #dee2e6;
    border-radius: 7px;
    background: white;
}

.tab4-focus-values span,
.tab4-focus-delta span {
    color: #6c757d;
    font-size: 0.7rem;
}

.tab4-focus-delta {
    margin: 9px 0 12px;
}

.tab4-metric-bar {
    display: grid;
    grid-template-columns: var(--tab4-comparison-columns);
    gap: 16px;
    margin: 0 0 10px;
}

.tab4-metric-control {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 7px;
    border: 1px solid #dbe1e7;
    border-radius: 8px;
    background: white;
}

.tab4-metric-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #495057;
}

.tab4-cross-school-warning {
    margin: 0 0 12px;
    border-left: 5px solid #e0a800;
}

.tab4-metric-switch .form-check {
    margin: 0;
    padding: 0;
}

.tab4-card {
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 10px;
    background: white;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.tab4-card .dash-graph {
    height: 360px;
    max-height: 360px;
    overflow: hidden;
}

.tab4-total {
    min-height: 24px;
    text-align: center;
    font-weight: 600;
    color: #34495e;
}

.tab4-difference {
    margin-top: 16px;
}

.tab4-difference .dash-graph {
    height: auto;
    max-height: none;
}

.tab4-table-wrap {
    overflow-x: auto;
}

.tab4-table-wrap h4 {
    margin: 4px 0 12px;
}

.tab4-table-key {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-bottom: 14px;
    padding: 9px 12px;
    border-radius: 7px;
    background: #eef2f6;
    color: #495057;
    font-size: 0.9rem;
}

.tab4-table-key > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tab4-legend-solid,
.tab4-legend-striped {
    display: inline-block;
    width: 24px;
    height: 9px;
    border: 1px solid #667;
    border-radius: 3px;
    background: #6687a6;
}

.tab4-legend-striped {
    background: repeating-linear-gradient(135deg, #6687a6 0, #6687a6 4px, #fff 4px, #fff 7px);
}

.tab4-category-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
}

.tab4-category-section {
    min-width: 0;
    overflow: hidden;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
}

.tab4-category-section h5 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    font-size: 1rem;
    font-weight: 700;
}

.tab4-visual-item {
    padding: 9px 10px 10px;
    border-bottom: 1px solid #e8eaed;
}

.tab4-visual-item:last-child {
    border-bottom: 0;
}

.tab4-visual-item:hover {
    background: #f7faff;
}

.tab4-visual-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.tab4-visual-name {
    min-width: 0;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.2;
}

.tab4-visual-difference {
    flex: 0 0 auto;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.tab4-bar-line {
    display: grid;
    grid-template-columns: 16px minmax(40px, 1fr) 70px;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.tab4-bar-label {
    color: #495057;
    font-size: 0.75rem;
    font-weight: 700;
}

.tab4-bar-track {
    height: 10px;
    overflow: hidden;
    border: 1px solid #ccd1d6;
    border-radius: 5px;
    background: #edf0f2;
}

.tab4-bar-track > div {
    height: 100%;
    min-width: 0;
}

.tab4-bar-track-b > div {
    background: repeating-linear-gradient(135deg, var(--bar-color) 0, var(--bar-color) 4px, #fff 4px, #fff 7px);
}

.tab4-bar-value {
    font-size: 0.75rem;
    text-align: right;
    white-space: nowrap;
}

.tab4-difference-positive {
    color: #157347;
    background: #d1e7dd;
    font-weight: 700;
}

.tab4-difference-negative {
    color: #b02a37;
    background: #f8d7da;
    font-weight: 700;
}

.tab4-difference-equal {
    color: #6c757d;
    background: #e9ecef;
}

/* Layout für mobile Geräte: Spalten untereinander stapeln */
@media (max-width: 767px) {
    :root {
        --bottom-tabs-height: 60px;
    }

    /* Die Hauptanwendung bleibt ein fester Viewport. Die einzelnen Tabs
       besitzen ihre eigenen Scrollflächen; eine globale Dokumenthöhe würde
       die feststehende Tab-Leiste weit nach unten verschieben. */
    #app-shell {
        height: 100dvh !important;
        min-height: 0 !important;
        overflow: hidden !important;
        box-sizing: border-box;
    }

    .tab-parent {
        position: relative;
        display: block;
        height: 100%;
        padding: 0;
        border: 0;
        box-shadow: none;
        background: transparent;
    }

    /* Dash hält die aktive Tab-Seite innerhalb dieses Containers. Deshalb
       wird die interne Leiste nicht ausgeblendet, sondern nur auf eine
       unsichtbare Zeile reduziert; die sichtbare Bedienung ist die eigene
       App-Leiste unten. */
    .tab-parent .tab {
        display: none !important;
    }

    .mobile-navigation {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 2147483647;
        display: flex !important;
        height: var(--bottom-tabs-height);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--dashboard-surface);
        border-top: 1px solid var(--dashboard-border);
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.06);
    }

    .mobile-nav-button {
        display: flex;
        flex: 1 1 20%;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 0;
        padding: 3px 1px;
        border: 0;
        background: transparent;
        color: var(--dashboard-muted);
        font-size: 0.64rem;
        font-weight: 600;
        line-height: 1.1;
    }

    .mobile-nav-icon {
        font-size: 1.25rem;
        line-height: 1;
    }

    .mobile-nav-button:active,
    .mobile-nav-button:focus-visible {
        background: #edf3f9;
        color: var(--dashboard-accent);
    }

    .tab--selected {
        border-top: 0 !important;
        border-bottom: 3px solid var(--dashboard-accent) !important;
        background: var(--dashboard-surface) !important;
        color: var(--dashboard-text) !important;
    }

    #tab1-layout {
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        min-height: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        flex-direction: column !important;
    }

    #tab1-layout > #map-container {
        height: 46vh !important;
        flex-basis: 46vh !important;
    }

    .tab1-map-filter {
        position: static !important;
        width: auto !important;
        margin: 10px;
    }

    .tab1-institution-filter {
        margin-top: 0;
    }

    .tab2-layout {
        display: flex !important;
        flex-direction: column !important;
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        min-height: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    .tab2-layout > div,
    .tab2-layout > div > div,
    .tab2-layout > div > div > div {
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        flex: 0 0 auto !important;
    }

    .tab2-layout > div:first-child {
        padding: 14px !important;
        border-right: 0 !important;
        border-bottom: 1px solid var(--dashboard-border);
    }

    .tab2-layout > div:nth-child(2) > div {
        flex-direction: column !important;
        gap: 18px !important;
    }

    #tab2-similarity-scroll-container {
        max-height: 46vh;
        overflow-y: auto !important;
    }

    .tab3-page,
    .tab3-layout,
    .tab4-layout,
    .maxqda-layout {
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        min-height: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    .tab3-layout {
        grid-template-rows: 46vh auto !important;
    }

    .tab4-layout {
        padding: 12px !important;
    }

    .tab4-card {
        overflow: visible !important;
    }

    .site-footer {
        bottom: calc(8px + var(--bottom-tabs-height));
    }

    #map-container,
    .map-pane {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        float: none !important;
        height: 50vh !important;
    }

    #map {
        width: 100% !important;
        height: 100% !important;
    }

    .right-container {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        float: none !important;
        height: auto !important;
        max-height: 60vh !important;
        overflow-y: auto !important;
        padding: 10px !important;
    }

    .tab3-layout {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: 50vh minmax(0, auto);
        overflow-y: auto !important;
    }

    .tab3-layout > .tab3-right-container {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow-y: visible !important;
        padding: 10px !important;
    }

    .tab4-layout {
        height: calc(100vh - 48px);
        padding: 10px;
    }

    .tab4-header,
    .tab4-button-filters,
    .tab4-pies,
    .tab4-independent-selectors {
        grid-template-columns: minmax(0, 1fr);
    }

    .tab4-independent-selectors {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .tab4-independent-selectors > * {
        width: 100%;
        min-width: 0;
    }

    .tab4-selector-bridge {
        min-height: 58px;
        order: 2;
    }

    .tab4-selection-panel-b {
        order: 3;
    }

    .tab4-metric-bar {
        grid-template-columns: minmax(0, 1fr);
    }

    .tab4-metric-control {
        grid-column: 1;
    }

    .tab4-category-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .tab4-focus-card {
        min-height: 220px;
    }

    .toggle-buttons {
        display: block; /* Buttons untereinander */
        margin-top: 10px;
    }

    .pie-chart-container {
        display: block; /* Diagramm unter dem Text */
    }

    .legend-container {
        display: block; /* Legende wird unterhalb angezeigt */
    }

    /* Schalter und Labels vertikal */
    .switch-container {
        display: block;
    }
}

@media (max-width: 767px) {
    .tab1-map-filter-summary {
        display: flex !important;
        align-items: center;
        gap: 7px;
        min-height: 38px;
        padding: 10px 12px;
        cursor: pointer;
        color: #253746;
        font-size: 0.82rem;
        font-weight: 700;
        list-style: none;
    }
    .tab1-map-filter-summary::before {
        content: "☰";
        color: #2f5fa7;
        font-size: 1rem;
    }
    .tab1-map-filter-summary::after {
        content: "Filter öffnen";
        margin-left: auto;
        color: #526579;
        font-size: 0.72rem;
        font-weight: 600;
    }
    .tab1-map-filter[open] .tab1-map-filter-summary::after {
        content: "Schließen ×";
        color: #2f5fa7;
    }
    .tab1-map-filter {
        position: fixed !important;
        top: 10px !important;
        right: 8px !important;
        left: auto !important;
        bottom: auto !important;
        z-index: 2000 !important;
        width: min(250px, calc(100vw - 16px)) !important;
        max-height: calc(100dvh - 84px);
        overflow-y: auto;
        margin: 0 !important;
        padding: 0 !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.97) !important;
    }
    .tab1-institution-filter { top: 56px !important; }
    .tab1-school-filter[open] ~ .tab1-institution-filter {
        top: min(274px, calc(100dvh - 84px)) !important;
    }
    .tab1-map-filter:not([open]) { width: auto !important; }
}

/* Mobile rules declared last override legacy fixed-height desktop layouts. */
@media (max-width: 767px) {
    #tab1-layout,
    .tab2-layout,
    .tab3-page,
    .tab4-layout,
    .maxqda-layout {
        height: calc(100dvh - var(--bottom-tabs-height)) !important;
        padding-bottom: 12px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
    #tab1-layout > #map-container,
    .tab3-layout > .map-pane {
        flex: 0 0 42dvh !important;
        height: 42dvh !important;
        min-height: 260px !important;
    }
    #tab1-layout > #middle-container,
    .tab3-layout > .tab3-right-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 14px !important;
    }
    #toggle-button-container,
    #toggle-button-container-BAMAST { max-width: 100% !important; flex-wrap: wrap !important; gap: 6px; }
    #toggle-button-container .btn,
    #toggle-button-container-BAMAST .btn,
    .tab4-button-group .btn { min-height: 44px; white-space: normal; }
    #tab2-similarity-scroll-container { max-height: 36dvh; }
    .tab4-card, .tab4-selection-panel { min-width: 0; overflow-wrap: anywhere; }
    .site-footer { bottom: calc(var(--bottom-tabs-height) + 8px); }
}
