@use '../globals' as *;

/**
 * FlagPicker Component Styles
 *
 * Country flag picker with search, regional filtering, and keyboard navigation.
 *
 * @package MultilingualPressZone
 * @since 1.0.0
 */

/* ==========================================================================
   Variables
   ========================================================================== */

// Colors
$primary-color: #0073aa !default;
$primary-hover: #005a87 !default;
$text-primary: #1e1e1e !default;
$text-secondary: #757575 !default;
$background-white: #ffffff !default;
$background-light: #f9f9f9 !default;
$border-color: #dcdcdc !default;
$border-color-light: #e5e5e5 !default;
$shadow-color: rgba(0, 0, 0, 0.1) !default;

// Dark mode colors
$dark-bg: #1e1e1e !default;
$dark-surface: #2c2c2c !default;
$dark-surface-hover: #3c3c3c !default;
$dark-text: #e4e4e4 !default;
$dark-text-secondary: #a0a0a0 !default;
$dark-border: #3c3c3c !default;

// Spacing
$spacing-xs: 4px !default;
$spacing-sm: 8px !default;
$spacing-md: 16px !default;
$spacing-lg: 24px !default;

// Borders
$border-radius-sm: 4px !default;
$border-radius-md: 6px !default;
$border-radius-lg: 8px !default;
$border-radius-full: 50% !default;

// Transitions
$transition-fast: 0.15s ease !default;
$transition-normal: 0.2s ease !default;

// Flag sizes
$flag-size: 48px;
$flag-size-preview: 32px;

/* ==========================================================================
   Base Container
   ========================================================================== */

.mpz-flag-picker {
    display: flex;
    flex-direction: column;
    gap: $spacing-md;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: $spacing-md;
    background: $background-white;
    border: 1px solid $border-color;
    border-radius: $border-radius-md;
    box-shadow: 0 2px 4px $shadow-color;

    &--disabled {
        opacity: 0.6;
        pointer-events: none;
        cursor: not-allowed;
    }
}

/* ==========================================================================
   Header (Search + Preview)
   ========================================================================== */

.mpz-flag-picker__header {
    display: flex;
    align-items: center;
    gap: $spacing-md;
    padding-bottom: $spacing-md;
    border-bottom: 1px solid $border-color-light;
}

/* ==========================================================================
   Search Input
   ========================================================================== */

.mpz-flag-picker__search {
    flex: 1;
    padding: 10px $spacing-md;
    font-size: 14px;
    color: $text-primary;
    background: $background-light;
    border: 1px solid $border-color;
    border-radius: $border-radius-sm;
    outline: none;
    transition: all $transition-fast;

    &::placeholder {
        color: $text-secondary;
    }

    &:hover {
        border-color: darken($border-color, 10%);
    }

    &:focus {
        border-color: $primary-color;
        background: $background-white;
        box-shadow: 0 0 0 1px $primary-color;
    }

    &:disabled {
        background: lighten($border-color, 15%);
        cursor: not-allowed;
    }
}

/* ==========================================================================
   Preview (Selected Flag)
   ========================================================================== */

.mpz-flag-picker__preview {
    display: flex;
    align-items: center;
    gap: $spacing-sm;
    padding: $spacing-sm $spacing-md;
    background: $background-light;
    border: 1px solid $border-color;
    border-radius: $border-radius-sm;
    min-width: 200px;

    .mpz-flag-picker__flag {
        width: $flag-size-preview;
        height: $flag-size-preview;
        flex-shrink: 0;
        cursor: default;

        &:hover {
            transform: none;
            box-shadow: none;
        }
    }

    &--empty {
        justify-content: center;
        color: $text-secondary;
        font-style: italic;
    }
}

.mpz-flag-picker__preview-name {
    font-size: 13px;
    font-weight: 500;
    color: $text-primary;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================================================
   Region Tabs
   ========================================================================== */

.mpz-flag-picker__tabs {
    display: flex;
    gap: $spacing-xs;
    flex-wrap: wrap;
    padding: $spacing-sm 0;
    border-bottom: 1px solid $border-color-light;
}

.mpz-flag-picker__tab {
    padding: $spacing-sm $spacing-md;
    font-size: 13px;
    font-weight: 500;
    color: $text-secondary;
    background: transparent;
    border: 1px solid transparent;
    border-radius: $border-radius-sm;
    cursor: pointer;
    transition: all $transition-fast;
    outline: none;

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

    &:focus-visible {
        outline: 2px solid $primary-color;
        outline-offset: 2px;
    }

    &--active {
        color: $primary-color;
        background: lighten($primary-color, 45%);
        border-color: lighten($primary-color, 30%);
        font-weight: 600;

        &:hover {
            background: lighten($primary-color, 40%);
        }
    }
}

/* ==========================================================================
   Flag Grid
   ========================================================================== */

.mpz-flag-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax($flag-size, 1fr));
    gap: $spacing-md;
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
    padding: $spacing-sm;

    // Custom scrollbar
    &::-webkit-scrollbar {
        width: 8px;
    }

    &::-webkit-scrollbar-track {
        background: $background-light;
        border-radius: $border-radius-sm;
    }

    &::-webkit-scrollbar-thumb {
        background: $border-color;
        border-radius: $border-radius-sm;

        &:hover {
            background: darken($border-color, 10%);
        }
    }
}

/* ==========================================================================
   Flag Element
   ========================================================================== */

.mpz-flag-picker__flag {
    position: relative;
    width: $flag-size;
    height: $flag-size;
    display: flex;
    align-items: center;
    justify-content: center;
    background: $background-light;
    border: 2px solid $border-color;
    border-radius: $border-radius-md;
    cursor: pointer;
    transition: all $transition-fast;
    outline: none;
    overflow: hidden;

    &:hover {
        transform: translateY(-2px);
        border-color: $primary-color;
        box-shadow: 0 4px 8px rgba($primary-color, 0.2);
    }

    &:focus-visible {
        border-color: $primary-color;
        box-shadow: 0 0 0 3px rgba($primary-color, 0.3);
        outline: none;
    }

    &:active {
        transform: translateY(0);
    }

    &--selected {
        border-color: $primary-color;
        border-width: 3px;
        box-shadow: 0 0 0 2px rgba($primary-color, 0.2);

        &::after {
            content: '✓';
            position: absolute;
            top: 2px;
            right: 2px;
            width: 16px;
            height: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: $primary-color;
            color: white;
            font-size: 10px;
            font-weight: bold;
            border-radius: $border-radius-full;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        }
    }

    // Fallback text style when image fails
    &--text {
        font-size: 14px;
        font-weight: 600;
        color: $text-primary;
        background: $background-light;
    }
}

.mpz-flag-picker__flag-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.mpz-flag-picker__empty {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: $spacing-lg * 2;
    color: $text-secondary;
    font-style: italic;
    text-align: center;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .mpz-flag-picker {
        padding: $spacing-sm;
        max-width: 100%;
    }

    .mpz-flag-picker__header {
        flex-direction: column;
        align-items: stretch;
    }

    .mpz-flag-picker__preview {
        min-width: auto;
        justify-content: center;
    }

    .mpz-flag-picker__tabs {
        gap: calc(#{$spacing-xs} / 2);
    }

    .mpz-flag-picker__tab {
        padding: 6px 10px;
        font-size: 12px;
    }

    .mpz-flag-picker__grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
        gap: $spacing-sm;
        max-height: 400px;
    }

    .mpz-flag-picker__flag {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 480px) {
    .mpz-flag-picker__grid {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
        gap: $spacing-xs;
    }

    .mpz-flag-picker__flag {
        width: 36px;
        height: 36px;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

body.dark-mode {
    .mpz-flag-picker {
        background: $dark-surface;
        border-color: $dark-border;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    }

    .mpz-flag-picker__header {
        border-bottom-color: $dark-border;
    }

    .mpz-flag-picker__search {
        color: $dark-text;
        background: $dark-bg;
        border-color: $dark-border;

        &::placeholder {
            color: $dark-text-secondary;
        }

        &:hover {
            border-color: lighten($dark-border, 10%);
        }

        &:focus {
            background: lighten($dark-bg, 5%);
            border-color: $primary-color;
        }

        &:disabled {
            background: darken($dark-surface, 5%);
        }
    }

    .mpz-flag-picker__preview {
        background: $dark-bg;
        border-color: $dark-border;

        &--empty {
            color: $dark-text-secondary;
        }
    }

    .mpz-flag-picker__preview-name {
        color: $dark-text;
    }

    .mpz-flag-picker__tabs {
        border-bottom-color: $dark-border;
    }

    .mpz-flag-picker__tab {
        color: $dark-text-secondary;

        &:hover {
            color: $dark-text;
            background: $dark-surface-hover;
        }

        &--active {
            color: lighten($primary-color, 20%);
            background: rgba($primary-color, 0.2);
            border-color: rgba($primary-color, 0.3);
        }
    }

    .mpz-flag-picker__grid {
        &::-webkit-scrollbar-track {
            background: $dark-bg;
        }

        &::-webkit-scrollbar-thumb {
            background: $dark-border;

            &:hover {
                background: lighten($dark-border, 10%);
            }
        }
    }

    .mpz-flag-picker__flag {
        background: $dark-bg;
        border-color: $dark-border;

        &:hover {
            border-color: $primary-color;
            box-shadow: 0 4px 8px rgba($primary-color, 0.3);
        }

        &--selected {
            border-color: $primary-color;
            box-shadow: 0 0 0 2px rgba($primary-color, 0.3);
        }

        &--text {
            color: $dark-text;
            background: $dark-bg;
        }
    }

    .mpz-flag-picker__empty {
        color: $dark-text-secondary;
    }
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

// Reduced motion support
@media (prefers-reduced-motion: reduce) {
    .mpz-flag-picker__flag {
        transition: none;

        &:hover {
            transform: none;
        }
    }

    .mpz-flag-picker__tab,
    .mpz-flag-picker__search {
        transition: none;
    }
}

// High contrast mode support
@media (prefers-contrast: high) {
    .mpz-flag-picker {
        border-width: 2px;
    }

    .mpz-flag-picker__flag {
        border-width: 2px;

        &--selected {
            border-width: 4px;
        }
    }

    .mpz-flag-picker__tab--active {
        border-width: 2px;
    }
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.mpz-flag-picker__flag-img[loading="lazy"] {
    &::before {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(
            90deg,
            $background-light 0%,
            lighten($background-light, 2%) 50%,
            $background-light 100%
        );
        animation: skeleton-loading 1.5s ease-in-out infinite;
    }
}

@keyframes skeleton-loading {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .mpz-flag-picker {
        box-shadow: none;
        border: 1px solid $border-color;
    }

    .mpz-flag-picker__search,
    .mpz-flag-picker__tabs {
        display: none;
    }

    .mpz-flag-picker__grid {
        max-height: none;
        overflow: visible;
    }
}
