/* ========================================
   GLOBAL BOTTOM SHEET DIALOG STYLES
   High-priority overrides for MudBlazor dialogs
   ======================================== */

/* Force all MudDialog containers to bottom alignment */
.mud-overlay .mud-dialog-container {
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Backdrop styling */
.bottom-sheet-backdrop,
.mud-overlay-dialog {
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* MudDialog Bottom Sheet Positioning */
.mud-dialog-container .mud-dialog {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;

    margin: 0 !important;
    padding: 0 !important;

    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 100vw !important;

    height: 97dvh !important;
    max-height: 97dvh !important;   /* override MudBlazor's max-height: calc(100dvh - appbar-height) */

    border-radius: 20px 20px 0 0 !important;

    display: flex !important;
    flex-direction: column !important;

    box-shadow: 0 -4px 20px rgba(0,0,0,0.3) !important;
}

/* Slide up animation */
@keyframes slideUpBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Slide down animation */
@keyframes slideDownBottom {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Apply slide up animation to all bottom dialogs */
.mud-dialog-container .mud-dialog {
    animation: slideUpBottom 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                opacity 0.3s ease-out;
}

/* Closing animation */
.mud-dialog-container .mud-dialog.closing {
    animation: slideDownBottom 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

/* Swiping state - disable animations during swipe */
.mud-dialog-container .mud-dialog.swiping {
    animation: none !important;
    transition: none !important;
}

/* Dialog content structure */
.mud-dialog-container .mud-dialog .mud-dialog-title {
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
}

.mud-dialog-container .mud-dialog .mud-dialog-content {
    padding: 0 !important;
    margin: 0 !important;
    flex: 1 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

.mud-dialog-container .mud-dialog .mud-dialog-actions {
    padding: 16px !important;
    border-top: 1px solid var(--mud-palette-divider);
    gap: 12px;
    background: var(--mud-palette-surface);
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    flex-shrink: 0 !important;
}

/* Ensure proper z-index layering.
   WICHTIG: Nur den Dialog-Overlay überschreiben (.mud-overlay-dialog), NICHT den
   generischen .mud-overlay — dieser würde sonst auch Popover-Overlays betreffen
   (.mud-overlay-popover z-index ~1200) und den Popover-Inhalt (~1201) verdecken,
   wodurch Klicks auf Dropdown-Items den Overlay statt die Items treffen.
   1401/1402 entsprechen MudBlazors eigenem Dialog-Default (calc(--mud-zindex-dialog + 1)).
   MudDialogProvider steht in MainLayout NACH der AppBar im DOM, daher gewinnt der
   Dialog auch bei Gleichstand durch die spätere DOM-Position. */
.mud-overlay.mud-overlay-dialog {
    z-index: 1401 !important;
}

.mud-dialog-container {
    z-index: 1402 !important;
}

/* Mobile optimization */
@media (max-width: 959px) {
    .mud-dialog-container .mud-dialog {
        width: 100vw !important;
        max-width: 100vw !important;
        border-radius: 20px 20px 0 0 !important;
    }
}

/* Desktop - still bottom sheet but with max width */
@media (min-width: 960px) {
    .mud-dialog-container .mud-dialog {
        width: 100vw !important;
        max-width: 100vw !important;
    }
}

/* ========================================
   DESKTOP COMPACT MODAL (dialog-desktop-compact)
   Opt-in: only dialogs that set Class="dialog-desktop-compact" are affected.
   Overrides the global bottom-sheet rules above for desktop viewports.
   ======================================== */
@media (min-width: 960px) {
    /* Center the dialog using fixed positioning with translate trick.
       The global rules set position:fixed + bottom:0 + left:0 + right:0.
       We override to fixed + top:50% + left:50% + translate(-50%,-50%)
       so it floats centered regardless of the container's align-items. */
    .mud-dialog-container .mud-dialog.dialog-desktop-compact {
        top: 50% !important;
        left: 50% !important;
        bottom: auto !important;
        right: auto !important;
        transform: translate(-50%, -50%) !important;
        width: auto !important;
        max-width: 480px !important;
        min-width: 320px !important;
        height: auto !important;
        max-height: 80dvh !important;
        border-radius: 8px !important;
        animation: none !important;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24) !important;
    }

    /* Hide drag handle — not useful on desktop */
    .mud-dialog.dialog-desktop-compact .dialog-handle-container {
        display: none !important;
    }

    /* Remove grab cursor and touch-action from drag area */
    .mud-dialog.dialog-desktop-compact .bottom-sheet-title-drag-area {
        cursor: default !important;
        touch-action: auto !important;
    }

    /* Remove iPhone safe-area padding — not applicable on desktop */
    .mud-dialog-container .mud-dialog.dialog-desktop-compact .mud-dialog-actions {
        padding-bottom: 16px !important;
    }
}

/* Title drag area — covers handle pill + title text so the whole header is swipeable */
.bottom-sheet-title-drag-area {
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    cursor: grab;
    display: flex;
    flex-direction: column;
}

.bottom-sheet-title-drag-area:active {
    cursor: grabbing;
}

/* ========================================
   BOTTOM SHEET COMPONENT SHARED CLASSES
   ======================================== */

/* Drag handle pill container */
.dialog-handle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 0;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-divider);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    min-height: 28px;
    width: 100%;
    margin: 0;
}

.dialog-handle-container:active {
    cursor: grabbing;
}

/* Drag handle pill bar */
.dialog-handle {
    width: 40px;
    height: 4px;
    background: var(--mud-palette-divider);
    border-radius: 2px;
    pointer-events: none;
    margin: 0 auto;
}

/* Title row layout */
.dialog-title-row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 16px;
    box-sizing: border-box;
}

.dialog-title-side {
    width: 40px;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.dialog-title-text {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    font-weight: bold;
}

/* Scrollable sheet content */
.sheet-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 4px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-divider) transparent;
}

.sheet-content::-webkit-scrollbar {
    width: 6px;
}

.sheet-content::-webkit-scrollbar-track {
    background: transparent;
}

.sheet-content::-webkit-scrollbar-thumb {
    background: var(--mud-palette-divider);
    border-radius: 3px;
}

/* MudDialog title typography centering */
.mud-dialog-container .mud-dialog .mud-dialog-title .mud-typography {
    padding: 12px 8px !important;
    margin: 0 !important;
    text-align: center !important;
}
