/**
 * List Preview Component
 * Popover and modal views for entity preview
 *
 * Uses shared entity-item base for item styling.
 * This file only contains popover/modal container styles.
 */

@use '../variables' as *;
@use '../mixins' as *;

// =============================================================================
// Preview Popover Container
// =============================================================================

.target-preview-popover,
.target-list-preview-popover {
    position: absolute;
    z-index: 10000;
    min-width: 320px;
    max-width: 480px;
    background: $es-white;
    border: 1px solid $es-border-color;
    border-radius: $es-radius-lg;
    box-shadow: $es-shadow-lg;
    overflow: hidden;

    // Arrow pointing to badge
    &::before {
        content: '';
        position: absolute;
        top: -8px;
        left: 50%;
        transform: translateX(-50%);
        border-left: 8px solid transparent;
        border-right: 8px solid transparent;
        border-bottom: 8px solid $es-border-color;
    }

    &::after {
        content: '';
        position: absolute;
        top: -6px;
        left: 50%;
        transform: translateX(-50%);
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-bottom: 6px solid $es-white;
    }

    // Positioned to the right - arrow on left
    &.position-right {
        &::before,
        &::after {
            left: 20px;
            transform: none;
        }
    }

    // Positioned to the left - arrow on right
    &.position-left {
        &::before,
        &::after {
            left: auto;
            right: 20px;
            transform: none;
        }
    }
}

// =============================================================================
// Preview Header
// =============================================================================

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

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

    .preview-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-primary;
        }
    }
}

// =============================================================================
// Preview Tabs (entity type switcher)
// =============================================================================

.preview-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 0;
    background: $es-slate-50;
    border-bottom: 1px solid $es-border-color;
}

.preview-tab {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: $es-text-muted;
    font-size: $es-font-size-xs;
    font-weight: $es-font-weight-medium;
    cursor: pointer;
    transition: all $es-transition-fast;
    white-space: nowrap;

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

    &.active {
        background: $es-white;
        border-bottom-color: $es-primary;
        color: $es-primary;
    }

    i {
        font-size: 12px;
    }
}

// =============================================================================
// Preview Filter
// =============================================================================

.preview-filter {
    display: flex;
    align-items: center;
    gap: $es-spacing-sm;
    padding: $es-spacing-sm $es-spacing-md;
    background: $es-white;
    border-bottom: 1px solid $es-border-color;

    i {
        color: $es-text-muted;
        font-size: 12px;
    }

    .preview-filter-input {
        all: unset;
        flex: 1;
        padding: 0.25rem 0;
        font-size: $es-font-size-xs;
        color: $es-text-primary;
        box-sizing: border-box;

        &::placeholder {
            color: $es-text-muted;
        }
    }
}

// =============================================================================
// Preview Contents (tabbed content areas)
// =============================================================================

.preview-contents {
    max-height: 350px;
    overflow: hidden;
}

.preview-content {
    display: none;
    max-height: 350px;
    overflow-y: auto;
    @include custom-scrollbar;

    &.active {
        display: block;
    }
}

// =============================================================================
// Preview Items Container
// =============================================================================

.preview-items {
    display: flex;
    flex-direction: column;
    padding: $es-spacing-xs $es-spacing-sm;
}

// =============================================================================
// Preview Item - Uses entity-item patterns
// Maps legacy classes to shared styling
// =============================================================================

.preview-item {
    display: flex;
    align-items: center;
    gap: $es-spacing-sm;
    padding: $es-spacing-sm;
    background: $es-white;
    border-radius: $es-radius-sm;
    transition: background $es-transition-fast;

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

    // Clickable items
    &[data-id] {
        cursor: pointer;
    }
}

// Image - matches chip image sizing for consistency
.preview-item-image {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: $es-radius-sm;
    background: $es-slate-100;
}

// No-image placeholder
.preview-item-no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: $es-slate-100;
    color: $es-text-muted;
    border-radius: $es-radius-sm;
    font-size: $es-font-size-sm;
}

// Info container
.preview-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

// Name
.preview-item-name {
    font-size: $es-font-size-sm;
    font-weight: $es-font-weight-medium;
    color: $es-text-primary;
    @include text-truncate;
}

// Meta/ref (category, email, etc.)
.preview-item-ref,
.preview-item-meta {
    font-size: $es-font-size-xs;
    color: $es-text-muted;
    @include text-truncate;
}

// Price badge
.preview-item-price {
    flex-shrink: 0;
    padding: 0.25rem 0.5rem;
    font-size: $es-font-size-xs;
    font-weight: $es-font-weight-semibold;
    color: $es-primary;
    background: $es-primary-light;
    border-radius: $es-radius-sm;
}

// =============================================================================
// Preview Footer (load more)
// =============================================================================

.preview-footer {
    padding: $es-spacing-sm $es-spacing-md;
    background: $es-slate-50;
    border-top: 1px solid $es-border-color;
}

.load-more-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: $es-spacing-sm;
    font-size: $es-font-size-xs;
    color: $es-text-muted;

    .load-more-label {
        white-space: nowrap;
    }

    .load-more-select {
        appearance: none;
        padding: 0.25rem 1.75rem 0.25rem 0.5rem;
        border: 1px solid $es-border-color;
        border-radius: $es-radius-sm;
        background: $es-white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%23666' d='M0 2l4 4 4-4z'/%3E%3C/svg%3E") no-repeat right 0.5rem center;
        background-size: 8px;
        font-size: $es-font-size-xs;
        font-weight: $es-font-weight-medium;
        color: $es-primary;
        cursor: pointer;
        transition: all $es-transition-fast;
        height: auto;
        min-height: 0;
        line-height: 1.3;

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

        &:focus {
            outline: none;
            border-color: $es-primary;
            box-shadow: 0 0 0 2px rgba($es-primary, 0.1);
        }
    }

    .load-more-of {
        white-space: nowrap;
    }

    .remaining-count {
        font-weight: $es-font-weight-semibold;
        color: $es-text-secondary;
    }

    .btn-load-more {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: $es-spacing-xs;
        margin: 0;
        border: none;
        color: $es-primary;
        background: $es-primary-light;
        border-radius: $es-radius-sm;
        cursor: pointer;
        transition: all $es-transition-fast;
        font: inherit;

        i {
            font-size: 14px;
        }

        &:hover {
            background: rgba($es-primary, 0.2);
        }

        &.loading {
            cursor: wait;

            i {
                animation: spin 0.6s linear infinite;
            }
        }
    }
}

// =============================================================================
// Preview States
// =============================================================================

.preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: $es-spacing-sm;
    padding: $es-spacing-xl;
    text-align: center;
    color: $es-text-muted;

    i {
        font-size: 2rem;
        opacity: 0.5;
    }

    p {
        margin: 0;
        font-size: $es-font-size-sm;
    }
}

.preview-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: $es-spacing-xl;
    color: $es-text-muted;

    i {
        font-size: 20px;
        color: $es-primary;
        animation: spin 0.6s linear infinite;
    }
}

// =============================================================================
// Total Summary Popover (header total badge click)
// =============================================================================

.total-preview-popover {
    min-width: 240px;
    max-width: 320px;

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

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

        .preview-popover-count {
            flex-shrink: 0;
            font-size: $es-font-size-xs;
            font-weight: $es-font-weight-medium;
            color: $es-text-muted;
            background: $es-slate-200;
            padding: 0.125rem 0.5rem;
            border-radius: $es-radius-sm;
        }
    }

    .preview-popover-body {
        padding: $es-spacing-xs 0;
    }

    .total-summary-list {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .total-summary-item {
        display: flex;
        align-items: center;
        gap: $es-spacing-sm;
        padding: $es-spacing-sm $es-spacing-md;
        cursor: pointer;
        transition: background-color 0.15s ease;

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

        i {
            width: 18px;
            text-align: center;
            color: $es-text-muted;
            font-size: 14px;
        }

        .summary-item-label {
            flex: 1;
            font-size: $es-font-size-sm;
            color: $es-text-primary;
        }

        .summary-item-count {
            font-size: $es-font-size-sm;
            font-weight: $es-font-weight-semibold;
            color: $es-primary;
            background: rgba($es-primary, 0.1);
            padding: 2px 8px;
            border-radius: $es-radius-sm;
        }
    }
}

// Make trait-total-count clickable
.trait-total-count {
    cursor: pointer;
    transition: all 0.15s ease;

    &:hover {
        opacity: 0.8;
    }

    &.popover-open {
        opacity: 0.9;
    }
}

// =============================================================================
// Schedule Dropdown Preview
// Inline dropdown for schedule details in admin list
// =============================================================================

.mpr-dropdown-preview {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    z-index: 1000;
    padding: 0.625rem 0.75rem;
    background: $es-white;
    border: 1px solid $es-border-color;
    border-radius: $es-radius-lg;
    box-shadow: $es-shadow-lg;
    font-size: 12px;
    text-align: left;
    text-transform: none;
    font-weight: normal;
    white-space: nowrap; // Allow dropdown to grow as needed

    &.is-open {
        display: block;
    }
}

.mpr-dropdown-preview__item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0;
    color: #666;
    line-height: 1.4;

    &:not(:last-child) {
        margin-bottom: 0.25rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid rgba($es-border-color, 0.5);
    }

    // Icon styles
    > .material-icons,
    > i:first-child {
        flex-shrink: 0;
        width: 16px;
        font-size: 14px !important;
        color: #999;
        text-align: center;
    }
}

.mpr-dropdown-preview__muted {
    color: #999;
}

// Schedule inline layout
.mpr-dropdown-preview__schedule {
    display: inline;
}

.mpr-dropdown-preview__schedule-row {
    display: inline;

    &:not(:last-child)::after {
        content: ',';
        margin-right: 0.5rem;
    }
}

.mpr-dropdown-preview__day {
    color: #666;
}

.mpr-dropdown-preview__hours {
    color: $es-primary;
    font-weight: 500;
    margin-left: 0.25rem;
}

// Badge trigger for preview dropdown/popover
.mpr-badge--preview {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    position: relative;
    min-width: 20px;
    height: 20px;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50rem;
    cursor: pointer;
    text-transform: none;

    .material-icons {
        font-size: 12px !important;
        line-height: 1;
        opacity: 0.8;
    }
}

.mpr-badge--preview-primary {
    background: $es-primary;
    color: $es-white;
}

.mpr-badge--preview-success {
    background: #d4edda;
    color: #155724;
}

.mpr-badge--preview-warning {
    background: #fff3cd;
    color: #856404;
}

.mpr-badge--preview-muted {
    background: $es-slate-200;
    color: $es-text-muted;
}
