/* Textbaustein- / Leitfaden-Popup — geladen mit [textbaustein_popup] / [leitfaden_popup] */

:root {
    --mk-color-primary: #80abb5;
    --mk-color-dark: #1c5f6b;
    --mk-popup-pad: clamp(16px, 3vw, 36px);
}

.mk-textbaustein-popup[hidden] {
    display: none !important;
}

.mk-textbaustein-popup {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 3vw, 24px);
    padding-top: max(clamp(12px, 3vw, 24px), env(safe-area-inset-top, 0px));
    padding-bottom: max(clamp(12px, 3vw, 24px), env(safe-area-inset-bottom, 0px));
    padding-left: max(clamp(12px, 3vw, 24px), env(safe-area-inset-left, 0px));
    padding-right: max(clamp(12px, 3vw, 24px), env(safe-area-inset-right, 0px));
    box-sizing: border-box;
    font-family: "DM Sans", system-ui, sans-serif;
}

.mk-textbaustein-popup__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mk-textbaustein-popup__dialog {
    position: relative;
    z-index: 1;
    width: min(960px, 100%);
    max-height: min(100%, 100dvh - 24px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: #fff;
    border-radius: 8px;
    padding: var(--mk-popup-pad);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
    contain: layout paint;
}

/* Logo links + Close rechts — eigene Zeile, Titel kommt darunter */
.mk-textbaustein-popup__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 16px;
    min-height: 44px;
}

.mk-textbaustein-popup__logo-wrap {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 140px;
    display: flex;
    align-items: center;
}

.mk-textbaustein-popup__logo-wrap:empty {
    visibility: hidden;
}

.mk-textbaustein-popup__logo {
    display: block;
    max-width: 100%;
    max-height: 56px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.mk-textbaustein-popup__close {
    position: static;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    margin: 0;
    border: 0;
    border-radius: 4px;
    background: rgba(28, 95, 107, 0.12);
    color: var(--mk-color-dark);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mk-textbaustein-popup__close:hover,
.mk-textbaustein-popup__close:focus-visible {
    background: rgba(28, 95, 107, 0.22);
}

/* Titel unter Topbar — volle Breite, kein Überlagern */
.mk-textbaustein-popup__title {
    margin: 0 0 16px;
    max-width: 100%;
    color: var(--mk-color-dark);
    font-size: clamp(1.1rem, 2.2vw, 1.4rem);
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.mk-textbaustein-popup__title[hidden] {
    display: none !important;
}

/* Ersteller:in — linksbündig; feste Abstände */
.mk-textbaustein-popup__credit {
    margin: 0;
    padding: 0;
    color: #5a6a6e;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
    text-align: left;
    margin-top: 40px !important;
    margin-bottom: 20px !important;
}

.mk-textbaustein-popup__credit[hidden] {
    display: none !important;
}

/* WYSIWYG-Inhalt möglichst original übernehmen */
.mk-textbaustein-popup__body {
    color: #1a1a1a;
    font-size: 1rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.mk-textbaustein-popup__body p {
    margin: 0 0 1em;
    min-height: 1em;
}

.mk-textbaustein-popup__body p:last-child {
    margin-bottom: 0;
}

.mk-textbaustein-popup__body ul,
.mk-textbaustein-popup__body ol {
    margin: 0 0 1em 1.25em;
    padding: 0;
}

.mk-textbaustein-popup__body li {
    margin: 0 0 0.35em;
}

.mk-textbaustein-popup__body a {
    color: var(--mk-color-dark);
    text-decoration: underline;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.mk-textbaustein-popup__body img,
.mk-textbaustein-popup__body figure {
    max-width: 100%;
    height: auto;
}

.mk-textbaustein-popup__body figure {
    margin: 0 0 1em;
}

.mk-textbaustein-popup__body blockquote {
    margin: 0 0 1em;
    padding: 0.25em 0 0.25em 1em;
    border-left: 3px solid var(--mk-color-primary);
    color: #333;
}

.mk-textbaustein-popup__body table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 0 0 1em;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mk-textbaustein-popup__body th,
.mk-textbaustein-popup__body td {
    border: 1px solid #d0d7d9;
    padding: 0.4em 0.6em;
    vertical-align: top;
}

.mk-textbaustein-popup__body h1,
.mk-textbaustein-popup__body h2,
.mk-textbaustein-popup__body h3,
.mk-textbaustein-popup__body h4 {
    margin: 1.1em 0 0.55em;
    line-height: 1.3;
    color: var(--mk-color-dark);
}

.mk-textbaustein-popup__body h1:first-child,
.mk-textbaustein-popup__body h2:first-child,
.mk-textbaustein-popup__body h3:first-child,
.mk-textbaustein-popup__body h4:first-child {
    margin-top: 0;
}

.mk-textbaustein-popup__actions {
    margin-top: 24px;
    display: flex;
    justify-content: center;
}

.mk-textbaustein-popup__download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 22px;
    border-radius: 4px;
    background: var(--mk-color-dark);
    color: #fff !important;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.mk-textbaustein-popup__download:hover,
.mk-textbaustein-popup__download:focus-visible {
    background: #164a54;
}

.mk-textbaustein-popup__download[hidden] {
    display: none !important;
}

/* Scroll sperren, Scrollbar-Breite per JS kompensieren (--mk-scrollbar-compensate) */
html.mk-textbaustein-popup-open,
html.mk-textbaustein-popup-open body {
    overflow: hidden;
}

html.mk-textbaustein-popup-open body {
    padding-right: var(--mk-scrollbar-compensate, 0px);
}

html.mk-textbaustein-popup-open .bde-header,
html.mk-textbaustein-popup-open .breakdance-header,
html.mk-textbaustein-popup-open header.sticky,
html.mk-textbaustein-popup-open [data-sticky="true"] {
    padding-right: var(--mk-scrollbar-compensate, 0px);
}

/* Tablet */
@media (max-width: 900px) {
    .mk-textbaustein-popup__dialog {
        width: min(720px, 100%);
        max-height: min(100%, 100dvh - 20px);
        padding: 20px;
    }

    .mk-textbaustein-popup__topbar {
        margin-bottom: 14px;
    }

    .mk-textbaustein-popup__logo-wrap {
        max-width: 110px;
    }

    .mk-textbaustein-popup__logo {
        max-height: 48px;
    }

    .mk-textbaustein-popup__title {
        margin-bottom: 14px;
        font-size: clamp(1.05rem, 2.8vw, 1.25rem);
    }

    .mk-textbaustein-popup__credit {
        font-size: 0.92rem;
    }

    .mk-textbaustein-popup__body {
        font-size: 0.98rem;
    }
}

/* Handy */
@media (max-width: 600px) {
    .mk-textbaustein-popup {
        align-items: flex-start;
        padding: 8px;
        padding-top: max(8px, env(safe-area-inset-top, 0px));
        padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
        padding-left: max(8px, env(safe-area-inset-left, 0px));
        padding-right: max(8px, env(safe-area-inset-right, 0px));
    }

    .mk-textbaustein-popup__dialog {
        width: 100%;
        max-height: calc(100dvh - 16px);
        max-height: calc(100svh - 16px);
        border-radius: 6px;
        padding: 14px 14px 18px;
    }

    .mk-textbaustein-popup__topbar {
        margin-bottom: 12px;
        gap: 8px;
        min-height: 40px;
    }

    .mk-textbaustein-popup__close {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }

    .mk-textbaustein-popup__logo-wrap {
        max-width: 72px;
    }

    .mk-textbaustein-popup__logo {
        max-height: 40px;
    }

    .mk-textbaustein-popup__title {
        margin-bottom: 12px;
        font-size: 1.05rem;
    }

    .mk-textbaustein-popup__credit {
        font-size: 0.9rem;
    }

    .mk-textbaustein-popup__body {
        font-size: 0.95rem;
        line-height: 1.5;
    }

    .mk-textbaustein-popup__actions {
        margin-top: 20px;
        position: sticky;
        bottom: 0;
        padding-top: 8px;
        background: linear-gradient(to top, #fff 70%, rgba(255, 255, 255, 0));
    }

    .mk-textbaustein-popup__download {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mk-textbaustein-popup__dialog {
        scroll-behavior: auto;
    }
}
