/* =============================================================================
   GLOBAL MODAL SYSTEM (gm-)
   Einheitliches Modal-System für alle Module.
   Prefix gm- vermeidet Konflikte mit bestehenden Klassen.
   ============================================================================= */

/* --- CSS Custom Properties --- */
:root {
    --gm-nav-h-sm: 3.5rem;   /* 56px - Nav-Höhe mobile */
    --gm-nav-h: 4rem;         /* 64px - Nav-Höhe desktop */
    --gm-gap: 1.5rem;          /* Abstand oben/unten */
    --gm-z: 45;                /* Unter Nav (z-50), über Header (z-40) */
    --gm-radius: 0.75rem;
    --gm-anim: 150ms;
    --gm-border: #e5e7eb;      /* gray-200 */
    --gm-bg-subtle: #f9fafb;   /* gray-50 */
}

/* =============================================================================
   OVERLAY (Backdrop)
   ============================================================================= */
.gm-overlay {
    position: fixed;
    top: var(--gm-nav-h-sm);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--gm-z);
    background: rgba(31, 41, 55, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gm-gap);
    animation: gm-fade-in var(--gm-anim) ease-out;
}
@media (min-width: 640px) {
    .gm-overlay {
        top: var(--gm-nav-h);
    }
    .gm-box {
        max-height: calc(100vh - var(--gm-nav-h) - var(--gm-gap) * 2);
        max-height: calc(100dvh - var(--gm-nav-h) - var(--gm-gap) * 2);
    }
}

/* Fullscreen-Modus: Overlay und Box decken alles ab */
.gm-overlay.gm-fullscreen {
    top: 0 !important;
    padding: 0 !important;
    z-index: 99999;
}
.gm-overlay.gm-fullscreen .gm-box {
    max-height: 100vh !important;
    max-height: 100dvh !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* =============================================================================
   BOX (Container)
   ============================================================================= */
.gm-box {
    background: #fff;
    border-radius: var(--gm-radius);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--gm-nav-h-sm) - var(--gm-gap) * 2);
    max-height: calc(100dvh - var(--gm-nav-h-sm) - var(--gm-gap) * 2);
    width: 100%;
    overflow: hidden;
    animation: gm-enter var(--gm-anim) ease-out;
}

/* --- Breitenvarianten --- */
.gm-sm   { max-width: 28rem; }    /* 448px */
.gm-md   { max-width: 40rem; }    /* 640px */
.gm-lg   { max-width: 56rem; }    /* 896px */
.gm-xl   { max-width: 72rem; }    /* 1152px */
.gm-full { max-width: calc(100vw - var(--gm-gap) * 2); align-self: stretch; }

/* =============================================================================
   HEADER
   ============================================================================= */
.gm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--gm-border);
    flex-shrink: 0;
    gap: 1rem;
}
.gm-header h2,
.gm-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    line-height: 1.4;
    min-width: 0;
}

/* Danger Header */
.gm-header.gm-danger {
    background: #fef2f2;
    border-bottom-color: #fecaca;
}
.gm-header.gm-danger h2,
.gm-header.gm-danger h3 {
    color: #991b1b;
}

/* =============================================================================
   CLOSE BUTTON
   ============================================================================= */
.gm-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 0.375rem;
    background: none;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    font-size: 1.25rem;
    line-height: 1;
}
.gm-close:hover {
    color: #374151;
    background: #f3f4f6;
}
.gm-close::after {
    content: '\00D7'; /* x */
}

/* =============================================================================
   TAB NAVIGATION (im Modal)
   Design identisch mit tab-nav-button aus main.css
   ============================================================================= */
.gm-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1.25rem;
    border-bottom: 1px solid var(--gm-border);
    background: var(--gm-bg-subtle);
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.gm-tab {
    border: none;
    background-color: #f3f4f6;
    color: #4b5563;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}
.gm-tab.active {
    color: #ffffff;
    background-color: #2563eb;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.2);
}
.gm-tab:not(.active):hover {
    background-color: #e5e7eb;
    color: #1f2937;
}
.gm-tab i {
    font-size: 0.85rem;
}

/* Tab im "done"-Zustand (Wizard - Schritt erledigt) */
.gm-tab.done {
    background-color: #dcfce7;
    color: #166534;
}
.gm-tab.done:hover {
    background-color: #bbf7d0;
}

/* Wizard-Nummer-Badge im Tab */
.gm-wizard-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}
.gm-tab.active .gm-wizard-num {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
}
.gm-tab.done .gm-wizard-num {
    background: #16a34a;
    color: #fff;
}

/* Tab Panels */
.gm-tab-panel {
    display: none;
}
.gm-tab-panel.active {
    display: block;
}

/* =============================================================================
   WIZARD NAVIGATION (Schrittanzeige)
   ============================================================================= */
.gm-wizard-nav {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0.625rem 1.25rem;
    border-bottom: 1px solid var(--gm-border);
    background: var(--gm-bg-subtle);
    flex-shrink: 0;
}
.gm-wizard-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #9ca3af;
    white-space: nowrap;
}
.gm-wizard-step.active {
    color: #2563eb;
    font-weight: 600;
}
.gm-wizard-step.done {
    color: #16a34a;
}
.gm-wizard-dot {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    background: #e5e7eb;
    color: #9ca3af;
    transition: all 0.2s;
}
.gm-wizard-step.active .gm-wizard-dot {
    background: #2563eb;
    color: #fff;
}
.gm-wizard-step.done .gm-wizard-dot {
    background: #16a34a;
    color: #fff;
}
.gm-wizard-line {
    flex: 1;
    height: 2px;
    min-width: 1rem;
    background: #e5e7eb;
    margin: 0 0.25rem;
}
.gm-wizard-line.done {
    background: #16a34a;
}
.gm-wizard-line.active {
    background: #2563eb;
}

/* Wizard Step Panels */
.gm-wizard-panel {
    display: none;
}
.gm-wizard-panel.active {
    display: block;
}

/* =============================================================================
   FORM innerhalb gm-box (damit die Flex-Kette nicht bricht)
   ============================================================================= */
.gm-box > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* =============================================================================
   BODY (scrollbarer Inhalt)
   ============================================================================= */
.gm-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1.25rem;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* =============================================================================
   FOOTER (fixiert)
   ============================================================================= */
.gm-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--gm-border);
    background: var(--gm-bg-subtle);
    flex-shrink: 0;
}
.gm-footer-split {
    justify-content: space-between;
}
.gm-footer-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.gm-footer-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* Button-Styles wurden nach main.css (.btn) migriert. */

/* =============================================================================
   ANIMATIONEN
   ============================================================================= */
@keyframes gm-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes gm-enter {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
@keyframes gm-spin {
    to { transform: rotate(360deg); }
}

/* =============================================================================
   MOBILE RESPONSIVE
   ============================================================================= */

/* Mobile: Rand zum Nav und zum unteren Bildschirmrand */
@media (max-width: 639px) {
    .gm-overlay {
        padding: 0.5rem;
    }
    .gm-box {
        border-radius: 0.5rem;
        max-height: calc(100vh - var(--gm-nav-h-sm) - 1rem);
        max-height: calc(100dvh - var(--gm-nav-h-sm) - 1rem);
    }
    .gm-header h2,
    .gm-header h3 {
        font-size: 1rem;
    }
    .gm-body {
        padding: 1rem;
    }
    .gm-header,
    .gm-footer {
        padding: 0.625rem 1rem;
    }
    .gm-tabs {
        padding: 0.375rem 0.75rem;
    }
}

/* Sehr kleine Bildschirme: Vollbild-Modale */
@media (max-width: 479px) {
    .gm-overlay {
        padding: 0;
    }
    .gm-box {
        border-radius: 0;
        max-height: calc(100vh - var(--gm-nav-h-sm));
        max-height: calc(100dvh - var(--gm-nav-h-sm));
    }
    .gm-footer {
        flex-wrap: wrap;
    }
    .gm-footer .btn {
        flex: 1 1 auto;
        min-width: 0;
    }
    .gm-wizard-step span:not(.gm-wizard-dot) {
        display: none;
    }
}

/* =============================================================================
   BODY SCROLL LOCK
   ============================================================================= */
body.gm-scroll-locked {
    overflow: hidden;
}
