/**
 * Modal Component
 * Preview modals, confirmation dialogs
 */

@use "sass:color";
@use '../variables' as *;
@use '../mixins' as *;

// Modal backdrop
.mpr-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: $es-z-modal;
    opacity: 0;
    transition: opacity $es-transition-normal;

    &.show {
        opacity: 1;
    }
}

// Modal container (exclude Bootstrap .modal to prevent collision)
.mpr-modal:not(.modal) {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    z-index: $es-z-modal + 1;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    background: $es-white;
    border-radius: $es-radius-xl;
    box-shadow: $es-shadow-xl;
    opacity: 0;
    transition: all $es-transition-normal;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    &.show {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    &.modal-sm {
        max-width: 400px;
    }

    &.modal-lg {
        max-width: 800px;
    }

    &.modal-xl {
        max-width: 1000px;
    }

    &.modal-fullscreen {
        width: 95%;
        max-width: none;
        height: 90vh;
        max-height: none;
    }
}

// Modal header
.mpr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $es-spacing-md;
    padding: $es-spacing-md $es-spacing-lg;
    background: $es-bg-header;
    border-bottom: 1px solid $es-border-color;
    flex-shrink: 0;
}

.mpr-modal-title {
    font-size: $es-font-size-base;
    font-weight: $es-font-weight-semibold;
    color: $es-text-primary;
    margin: 0;
}

.mpr-modal-close {
    @include button-reset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: $es-text-muted;
    border-radius: $es-radius-md;
    transition: all $es-transition-fast;

    &:hover {
        background: $es-slate-200;
        color: $es-text-secondary;
    }

    i {
        font-size: $es-font-size-lg;
    }
}

// Modal body
.mpr-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: $es-spacing-lg;
    @include custom-scrollbar;
}

// Modal footer
.mpr-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: $es-spacing-sm;
    padding: $es-spacing-md $es-spacing-lg;
    background: $es-bg-header;
    border-top: 1px solid $es-border-color;
    flex-shrink: 0;
}

.mpr-modal-btn {
    @include button-reset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: $es-spacing-xs;
    padding: $es-spacing-sm $es-spacing-md;
    font-size: $es-font-size-sm;
    font-weight: $es-font-weight-medium;
    border-radius: $es-radius-md;
    transition: all $es-transition-fast;

    &.btn-secondary {
        color: $es-text-secondary;
        background: $es-slate-100;

        &:hover {
            background: $es-slate-200;
        }
    }

    &.btn-primary {
        color: $es-white;
        background: $es-primary;

        &:hover {
            background: $es-primary-hover;
        }
    }

    &.btn-danger {
        color: $es-white;
        background: $es-danger;

        &:hover {
            background: color.adjust($es-danger, $lightness: -10%);
        }
    }

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
}

// Preview popover styles moved to _list-preview.scss

.popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $es-spacing-sm;
    padding: $es-spacing-sm $es-spacing-md;
    background: $es-bg-header;
    border-bottom: 1px solid $es-border-color;
    border-radius: $es-radius-lg $es-radius-lg 0 0;
}

.popover-title {
    font-size: $es-font-size-sm;
    font-weight: $es-font-weight-semibold;
    color: $es-text-primary;
}

.popover-close {
    @include button-reset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: $es-text-muted;
    border-radius: $es-radius-sm;
    transition: all $es-transition-fast;

    &:hover {
        background: $es-slate-200;
        color: $es-text-secondary;
    }
}

.popover-body {
    max-height: 300px;
    overflow-y: auto;
    padding: $es-spacing-sm;
    @include custom-scrollbar;
}

.popover-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: $es-spacing-sm;
    padding: $es-spacing-sm $es-spacing-md;
    background: $es-bg-header;
    border-top: 1px solid $es-border-color;
    border-radius: 0 0 $es-radius-lg $es-radius-lg;
}

.popover-info {
    font-size: $es-font-size-xs;
    color: $es-text-muted;
}

.popover-load-more {
    @include button-reset;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: $es-font-size-xs;
    font-weight: $es-font-weight-medium;
    color: $es-primary;
    border-radius: $es-radius-sm;
    transition: all $es-transition-fast;

    &:hover {
        background: $es-primary-light;
    }
}

// Popover arrow
.popover-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: $es-white;
    border: 1px solid $es-border-color;
    transform: rotate(45deg);

    &.arrow-top {
        top: -7px;
        left: 50%;
        margin-left: -6px;
        border-right: none;
        border-bottom: none;
    }

    &.arrow-bottom {
        bottom: -7px;
        left: 50%;
        margin-left: -6px;
        border-left: none;
        border-top: none;
    }
}

// ==========================================================================
// Holiday Preview Modal
// ==========================================================================

#mpr-holiday-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: $es-z-modal;

    &.show {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mpr-modal-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        cursor: pointer;
    }

    .mpr-modal-dialog {
        position: relative;
        width: 90%;
        max-width: 480px;
        max-height: 80vh;
        background: $es-white;
        border-radius: $es-radius-lg;
        box-shadow: $es-shadow-xl;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .mpr-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: $es-spacing-md;
        padding: $es-spacing-md $es-spacing-lg;
        background: $es-bg-header;
        border-bottom: 1px solid $es-border-color;
        flex-shrink: 0;
    }

    .mpr-modal-title {
        display: flex;
        align-items: center;
        gap: $es-spacing-sm;
        font-size: $es-font-size-base;
        font-weight: $es-font-weight-semibold;
        color: $es-text-primary;
        margin: 0;

        i> i {
            font-size: 20px;
            color: $es-primary;
        }
    }

    .mpr-modal-close {
        @include button-reset;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        color: $es-text-muted;
        border-radius: $es-radius-md;
        transition: all $es-transition-fast;

        &:hover {
            background: $es-slate-200;
            color: $es-text-secondary;
        }

        i {
            font-size: 18px;
        }
    }

    .mpr-modal-body {
        flex: 1;
        overflow-y: auto;
        padding: $es-spacing-lg;
        @include custom-scrollbar;
    }

    // Loading state
    .holiday-preview-loading {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: $es-spacing-sm;
        padding: $es-spacing-xl 0;
        color: $es-text-muted;
        font-size: $es-font-size-sm;

        i {
            font-size: $es-font-size-lg;
        }
    }

    // Empty state
    .holiday-preview-empty {
        text-align: center;
        padding: $es-spacing-xl 0;
        color: $es-text-muted;

        i> i {
            font-size: 48px;
            opacity: 0.5;
            margin-bottom: $es-spacing-md;
        }

        p {
            margin: 0 0 $es-spacing-xs;
        }

        .hint {
            font-size: $es-font-size-xs;
            color: $es-text-muted;
        }
    }

    // Holiday list
    .holiday-list {
        display: flex;
        flex-direction: column;
        gap: $es-spacing-sm;
    }

    .holiday-item {
        display: flex;
        align-items: flex-start;
        gap: $es-spacing-md;
        padding: $es-spacing-sm $es-spacing-md;
        background: $es-slate-50;
        border-radius: $es-radius-md;
        border-left: 3px solid $es-success;

        &.holiday-type-bank {
            border-left-color: $es-info;
        }

        &.holiday-type-observance {
            border-left-color: $es-warning;
        }

        &.holiday-type-regional {
            border-left-color: #8b5cf6;
        }
    }

    .holiday-date {
        flex-shrink: 0;
        min-width: 100px;

        .holiday-day {
            display: block;
            font-size: $es-font-size-sm;
            font-weight: $es-font-weight-semibold;
            color: $es-text-primary;
        }

        .holiday-weekday {
            display: block;
            font-size: $es-font-size-xs;
            color: $es-text-muted;
        }
    }

    .holiday-info {
        flex: 1;
        min-width: 0;
    }

    .holiday-name {
        display: block;
        font-size: $es-font-size-sm;
        color: $es-text-primary;
        word-wrap: break-word;
    }

    .holiday-type-badge {
        display: inline-block;
        margin-top: $es-spacing-xs;
        padding: 0.125rem 0.375rem;
        font-size: 10px;
        font-weight: $es-font-weight-medium;
        text-transform: capitalize;
        background: $es-slate-200;
        color: $es-text-secondary;
        border-radius: $es-radius-sm;
    }

    .holiday-preview-note {
        margin-top: $es-spacing-md;
        font-size: $es-font-size-xs;
        color: $es-text-muted;
        text-align: center;
    }
}
