/**
 * Beherzig Modal V4 — Single-System CSS
 * --------------------------------------
 * Replaces beherzig-modal-v3.css + beherzig-modal-v3.2.css (~2.370 LOC) with
 * a single, modern stylesheet using native <dialog>, no visibility:hidden
 * cascade traps, no V3+V3.2 dualism.
 *
 * Architecture:
 *   - Native <dialog>::backdrop for overlay (no manual .is-open toggle)
 *   - HTML5 [hidden] attribute for step visibility (no display:none CSS hack)
 *   - CSS-Variables driven (theme + size variants)
 *   - WCAG 2.2 AA compliant (Brown-100, contrast ≥4.5:1)
 *   - Dark-mode via prefers-color-scheme
 *   - Reduced-motion respected
 */

/* ============================================================
   1. Native <dialog> Reset + Base
   ============================================================ */

.bhz-modal-v4 {
    /* Reset native dialog defaults */
    padding: 0;
    border: none;
    background: var(--beherzig-alpine-white, #fff);
    color: var(--beherzig-graphite, #3d3937);
    max-width: min(960px, 92vw);
    max-height: 92dvh;
    width: 100%;
    margin: auto;
    border-radius: 12px;
    box-shadow:
        0 20px 60px rgb(61 57 55 / 18%),
        0 0 0 1px rgb(61 57 55 / 6%);
    overflow: hidden;
    z-index: 9999;
}

.bhz-modal-v4--sm {
    max-width: min(480px, 92vw);
}

.bhz-modal-v4--md {
    max-width: min(720px, 92vw);
}

.bhz-modal-v4--lg {
    max-width: min(960px, 92vw);
}

/* Native ::backdrop replaces .beherzig-overlay manual background */
.bhz-modal-v4::backdrop {
    background: rgb(61 57 55 / 65%);
    backdrop-filter: blur(8px);
}

/* Lock body scroll when dialog is open */
.bhz-modal-v4[open] ~ body,
body:has(.bhz-modal-v4[open]) {
    overflow: hidden;
}

/* Inner layout: header + body (scrollable) + footer */
.bhz-modal-v4__inner {
    display: flex;
    flex-direction: column;
    width: 100%; /* CRITICAL: ohne dies schrumpft article auf content-width im flex-dialog */
    height: 100%;
    max-height: 92dvh;
    overflow: hidden;
    box-sizing: border-box;
}

.bhz-modal-v4,
.bhz-modal-v4 *,
.bhz-modal-v4 *::before,
.bhz-modal-v4 *::after {
    box-sizing: border-box;
}

/* ============================================================
   2. Header (badge + title + subtitle + progress)
   ============================================================ */

.bhz-modal-v4__header {
    position: relative;
    padding: clamp(20px, 3vw, 32px) clamp(20px, 3vw, 40px) clamp(16px, 2vw, 24px);
    border-bottom: 1px solid var(--beherzig-light-gray, #e5e5e5);
    background: var(--beherzig-cream, #f7f5f2);
}

.bhz-modal-v4__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--beherzig-graphite, #3d3937);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.bhz-modal-v4__close:hover,
.bhz-modal-v4__close:focus-visible {
    background: rgb(61 57 55 / 8%);
    outline: 2px solid var(--beherzig-brown-100, #5c4338);
    outline-offset: 2px;
}

.bhz-modal-v4__badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--beherzig-brown-100, #5c4338);
    padding: 4px 12px;
    background: var(--beherzig-alpine-white, #fff);
    border-radius: 4px;
    margin-bottom: 12px;
}

.bhz-modal-v4__title {
    font-family: var(--font-secondary, 'Libre Baskerville', Georgia, serif);
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    font-weight: 700;
    margin: 0 0 8px;
    line-height: 1.2;
    color: var(--beherzig-graphite, #3d3937);
}

.bhz-modal-v4__subtitle {
    font-size: 0.9375rem;
    margin: 0 0 16px;
    color: var(--beherzig-brown-100, #5c4338);
    line-height: 1.5;
}

/* Progress-Indicator (segmented bar) */
.bhz-modal-v4__progress {
    display: flex;
    gap: 6px;
    margin-top: 12px;
}

.bhz-modal-v4__progress-step {
    flex: 1;
    height: 4px;
    background: var(--beherzig-light-gray, #e5e5e5);
    border-radius: 2px;
    transition: background 0.3s;
}

.bhz-modal-v4__progress-step.is-active {
    background: var(--beherzig-brown-100, #5c4338);
}

.bhz-modal-v4__progress-step.is-done {
    background: var(--beherzig-brown-100, #5c4338);
    opacity: 0.5;
}

/* ============================================================
   3. Body (scrollable form-area)
   ============================================================ */

.bhz-modal-v4__body {
    flex: 1;
    overflow: hidden auto;
    padding: clamp(20px, 3vw, 32px) clamp(20px, 3vw, 40px);
    -webkit-overflow-scrolling: touch;
}

.bhz-modal-v4__form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Step sections — hidden by default, shown when not [hidden] */
.bhz-modal-v4__form [data-step] {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Native HTML5 [hidden] attribute handles step visibility */
.bhz-modal-v4__form [data-step][hidden] {
    display: none !important;
}

/* ============================================================
   4. Field-Grid (responsive 2-column / 1-column on mobile)
   ============================================================ */

.bhz-field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

@media (width <= 640px) {
    .bhz-field-grid {
        grid-template-columns: 1fr;
    }
}

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

.bhz-field--full {
    grid-column: 1 / -1;
}

.bhz-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--beherzig-graphite, #3d3937);
}

.bhz-required {
    color: var(--beherzig-brown-100, #5c4338);
    font-weight: 700;
}

/* Inputs / Selects / Textareas — unified styling */
.bhz-field input[type='text'],
.bhz-field input[type='email'],
.bhz-field input[type='tel'],
.bhz-field input[type='number'],
.bhz-field select,
.bhz-field textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--beherzig-light-gray, #e5e5e5);
    border-radius: 6px;
    font-size: 0.9375rem;
    background: var(--beherzig-alpine-white, #fff);
    color: var(--beherzig-graphite, #3d3937);
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
    min-height: 44px; /* WCAG 2.2 target-size */
}

.bhz-field textarea {
    min-height: 80px;
    resize: vertical;
    font-family: inherit;
}

.bhz-field input:focus-visible,
.bhz-field select:focus-visible,
.bhz-field textarea:focus-visible {
    outline: none;
    border-color: var(--beherzig-brown-100, #5c4338);
    box-shadow: 0 0 0 3px rgb(92 67 56 / 15%);
}

/* Error-state */
.bhz-field.has-error input,
.bhz-field.has-error select,
.bhz-field.has-error textarea,
[aria-invalid='true'] {
    border-color: #c2382e;
    box-shadow: 0 0 0 3px rgb(194 56 46 / 12%);
}

.bhz-error {
    color: #c2382e;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    min-height: 1.2em;
}

/* Submit-error banner */
.bhz-submit-error {
    background: rgb(194 56 46 / 8%);
    color: #c2382e;
    border: 1px solid rgb(194 56 46 / 24%);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.9375rem;
}

/* ============================================================
   5. Card-Group (Type-Cards for objekttyp etc.)
   ============================================================ */

.bhz-card-group {
    border: none;
    padding: 0;
    margin: 0;
}

.bhz-card-group.has-error .bhz-card-grid {
    outline: 2px solid #c2382e;
    outline-offset: 4px;
    border-radius: 8px;
}

.bhz-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 6px;
}

.bhz-type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 12px;
    min-height: 80px;
    background: var(--beherzig-alpine-white, #fff);
    border: 1.5px solid var(--beherzig-light-gray, #e5e5e5);
    border-radius: 8px;
    cursor: pointer;
    transition:
        border-color 0.2s,
        background 0.2s,
        transform 0.1s;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--beherzig-graphite, #3d3937);
}

.bhz-type-card:hover,
.bhz-type-card:focus-visible {
    border-color: var(--beherzig-brown-100, #5c4338);
    background: var(--beherzig-cream, #f7f5f2);
    outline: none;
}

.bhz-type-card:active {
    transform: scale(0.98);
}

.bhz-type-card.is-selected,
.bhz-type-card[aria-pressed='true'] {
    border-color: var(--beherzig-brown-100, #5c4338);
    background: var(--beherzig-brown-100, #5c4338);
    color: var(--beherzig-alpine-white, #fff);
}

.bhz-type-card__label {
    text-align: center;
    line-height: 1.2;
}

/* ============================================================
   6. Checkbox (inline + standalone)
   ============================================================ */

.bhz-checkbox {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.875rem;
    line-height: 1.4;
    cursor: pointer;
}

.bhz-checkbox input[type='checkbox'] {
    margin-top: 2px;
    min-width: 18px;
    min-height: 18px;
    accent-color: var(--beherzig-brown-100, #5c4338);
    cursor: pointer;
}

.bhz-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 6px;
}

.bhz-checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    cursor: pointer;
}

.bhz-checkbox-inline input[type='checkbox'] {
    min-width: 16px;
    min-height: 16px;
    accent-color: var(--beherzig-brown-100, #5c4338);
}

/* ============================================================
   7. Footer (SSL + action-buttons)
   ============================================================ */

.bhz-modal-v4__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px clamp(20px, 3vw, 40px);
    border-top: 1px solid var(--beherzig-light-gray, #e5e5e5);
    background: var(--beherzig-cream, #f7f5f2);
    flex-wrap: wrap;
}

.bhz-modal-v4__ssl {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--beherzig-brown-100, #5c4338);
    font-weight: 500;
}

.bhz-modal-v4__actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.bhz-modal-v4__actions button {
    min-height: 44px;
    padding: 10px 22px;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.bhz-modal-v4__actions button[data-action='back'] {
    background: transparent;
    color: var(--beherzig-brown-100, #5c4338);
    border-color: var(--beherzig-light-gray, #e5e5e5);
}

.bhz-modal-v4__actions button[data-action='back']:hover,
.bhz-modal-v4__actions button[data-action='back']:focus-visible {
    border-color: var(--beherzig-brown-100, #5c4338);
    background: var(--beherzig-alpine-white, #fff);
    outline: none;
}

.bhz-modal-v4__actions button[data-action='next'],
.bhz-modal-v4__actions button[data-action='close-after-success'] {
    background: var(--beherzig-brown-100, #5c4338);
    color: var(--beherzig-alpine-white, #fff);
    border-color: var(--beherzig-brown-100, #5c4338);
}

.bhz-modal-v4__actions button[data-action='next']:hover,
.bhz-modal-v4__actions button[data-action='next']:focus-visible,
.bhz-modal-v4__actions button[data-action='close-after-success']:hover {
    background: var(--beherzig-graphite, #3d3937);
    border-color: var(--beherzig-graphite, #3d3937);
    outline: none;
}

.bhz-modal-v4__actions button:focus-visible {
    outline: 2px solid var(--beherzig-brown-100, #5c4338);
    outline-offset: 2px;
}

/* ============================================================
   8. Success State
   ============================================================ */

.bhz-success {
    text-align: center;
    padding: clamp(24px, 4vw, 48px) 16px;
}

.bhz-success__icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--beherzig-brown-100, #5c4338);
    color: var(--beherzig-alpine-white, #fff);
    border-radius: 50%;
}

.bhz-success__title {
    font-family: var(--font-secondary, 'Libre Baskerville', Georgia, serif);
    font-size: 1.5rem;
    margin: 0 0 12px;
    color: var(--beherzig-graphite, #3d3937);
}

.bhz-success__text {
    font-size: 0.9375rem;
    color: var(--beherzig-brown-100, #5c4338);
    margin: 0;
    line-height: 1.5;
}

/* ============================================================
   9. Note Text (newsletter etc.)
   ============================================================ */

.bhz-note {
    font-size: 0.8125rem;
    color: var(--beherzig-brown-100, #5c4338);
    line-height: 1.5;
    margin: 0;
}

/* ============================================================
   10. Animations (respects prefers-reduced-motion)
   ============================================================ */

@keyframes bhzFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bhzBackdropFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .bhz-modal-v4[open] {
        animation: bhzFadeIn 0.25s ease-out;
    }

    .bhz-modal-v4[open]::backdrop {
        animation: bhzBackdropFadeIn 0.25s ease-out;
    }
}

/* ============================================================
   11. Dark Mode (auto via prefers-color-scheme)
   ============================================================ */

@media (prefers-color-scheme: dark) {
    .bhz-modal-v4 {
        background: #1a1918;
        color: #e8e6e3;
    }

    .bhz-modal-v4__header,
    .bhz-modal-v4__footer {
        background: #2a2624;
        border-color: #3a3633;
    }

    .bhz-modal-v4__badge {
        background: #1a1918;
        color: #d4c4b8;
    }

    .bhz-modal-v4__title {
        color: #e8e6e3;
    }

    .bhz-modal-v4__subtitle {
        color: #b8a99a;
    }

    .bhz-field input,
    .bhz-field select,
    .bhz-field textarea {
        background: #2a2624;
        border-color: #3a3633;
        color: #e8e6e3;
    }

    .bhz-type-card {
        background: #2a2624;
        border-color: #3a3633;
        color: #e8e6e3;
    }

    .bhz-type-card.is-selected,
    .bhz-type-card[aria-pressed='true'] {
        background: #d4c4b8;
        color: #1a1918;
        border-color: #d4c4b8;
    }

    .bhz-modal-v4__actions button[data-action='next'] {
        background: #d4c4b8;
        color: #1a1918;
        border-color: #d4c4b8;
    }

    .bhz-modal-v4__actions button[data-action='back'] {
        color: #d4c4b8;
        border-color: #3a3633;
    }
}

/* ============================================================
   12. Mobile-Specific (sticky footer on small screens)
   ============================================================ */

@media (width <= 640px) {
    .bhz-modal-v4 {
        max-width: 100vw;
        max-height: 100dvh;
        height: 100dvh;
        border-radius: 0;
        margin: 0;
    }

    .bhz-modal-v4__inner {
        max-height: 100dvh;
    }

    .bhz-modal-v4__footer {
        position: sticky;
        bottom: 0;
        background: var(--beherzig-cream, #f7f5f2);
        z-index: 2;
    }
}
