/*
 * ═══════════════════════════════════════════════════════════
 * Lions.dev - Overlay Components Styles
 * ═══════════════════════════════════════════════════════════
 * Styles pour Dialog, ConfirmDialog, Sidebar, OverlayPanel
 *
 * Version: 1.0.0
 * Date: 1er Janvier 2026
 * Author: Lions Development Team
 * Priority: CRITIQUE #21-24
 * ═══════════════════════════════════════════════════════════
 */

@import '../variables';
@import '../mixins';

// ============================================
// 🌑 OVERLAY MASK (BACKDROP)
// ============================================

.ui-dialog-mask,
.ui-confirmdialog-mask,
.ui-sidebar-mask,
.ui-overlaypanel-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  backdrop-filter: blur(3px);
  @include lions-transition(opacity, 200ms);

  &.ui-dialog-mask-scrollblocker {
    overflow: hidden;
  }
}

// ============================================
// 💬 DIALOG STYLES
// ============================================

.ui-dialog {
  position: fixed;
  background: $lions-white;
  @include lions-rounded('lg');
  @include lions-shadow('2xl');
  z-index: 1001;
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  @include lions-transition(transform, 300ms);

  // Dialog header
  .ui-dialog-titlebar {
    background: linear-gradient(135deg, rgba($lions-blue-500, 0.1) 0%, rgba($lions-blue-700, 0.05) 100%);
    border-bottom: 2px solid $lions-blue-500;
    padding: $lions-spacing-5 $lions-spacing-6;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .ui-dialog-title {
      @include lions-font-size('xl');
      @include lions-font-weight('bold');
      color: $lions-text-primary;
      margin: 0;
      display: flex;
      align-items: center;
      gap: $lions-spacing-3;

      i {
        color: $lions-blue-500;
        font-size: 1.5rem;
      }
    }

    .ui-dialog-titlebar-icon {
      @include lions-button-base;
      width: 2.5rem;
      height: 2.5rem;
      padding: 0;
      @include lions-flex-center;
      background: transparent;
      border: none;
      color: $lions-gray-600;
      @include lions-transition();

      &:hover {
        background: rgba($lions-danger-500, 0.1);
        color: $lions-danger-600;
        transform: scale(1.1) rotate(90deg);
      }

      &:focus-visible {
        @include lions-focus-ring();
      }
    }
  }

  // Dialog content
  .ui-dialog-content {
    padding: $lions-spacing-6;
    overflow-y: auto;
    flex: 1;
    color: $lions-text-primary;
    line-height: $lions-line-height-normal;

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

    &::-webkit-scrollbar-track {
      background: $lions-gray-100;
    }

    &::-webkit-scrollbar-thumb {
      background: $lions-gray-400;
      @include lions-rounded('full');

      &:hover {
        background: $lions-blue-500;
      }
    }
  }

  // Dialog footer
  .ui-dialog-footer {
    background: linear-gradient(135deg, rgba($lions-gray-50, 0.8) 0%, rgba($lions-gray-100, 0.5) 100%);
    border-top: 1px solid $lions-gray-300;
    padding: $lions-spacing-4 $lions-spacing-6;
    display: flex;
    justify-content: flex-end;
    gap: $lions-spacing-3;
  }

  // Resizable handle
  .ui-resizable-handle {
    position: absolute;
    background: transparent;

    &.ui-resizable-se {
      bottom: 0;
      right: 0;
      width: 20px;
      height: 20px;
      cursor: se-resize;

      &::after {
        content: '';
        position: absolute;
        bottom: 4px;
        right: 4px;
        width: 12px;
        height: 12px;
        border-right: 2px solid $lions-gray-400;
        border-bottom: 2px solid $lions-gray-400;
      }
    }
  }
}

// ============================================
// ✅ CONFIRM DIALOG STYLES
// ============================================

.ui-confirmdialog {
  @extend .ui-dialog;
  max-width: 500px;

  .ui-confirmdialog-icon {
    font-size: 3rem;
    margin-right: $lions-spacing-4;
    flex-shrink: 0;
  }

  .ui-confirmdialog-message {
    flex: 1;
    @include lions-font-size('lg');
    color: $lions-text-primary;
    line-height: $lions-line-height-relaxed;
  }

  // Severity variants
  &.ui-confirmdialog-info {
    .ui-dialog-titlebar {
      background: linear-gradient(135deg, rgba($lions-info-500, 0.1) 0%, rgba($lions-info-700, 0.05) 100%);
      border-bottom-color: $lions-info-500;
    }

    .ui-confirmdialog-icon {
      color: $lions-info-600;
    }
  }

  &.ui-confirmdialog-warn {
    .ui-dialog-titlebar {
      background: linear-gradient(135deg, rgba($lions-warning-500, 0.1) 0%, rgba($lions-warning-700, 0.05) 100%);
      border-bottom-color: $lions-warning-500;
    }

    .ui-confirmdialog-icon {
      color: $lions-warning-600;
    }
  }

  &.ui-confirmdialog-error {
    .ui-dialog-titlebar {
      background: linear-gradient(135deg, rgba($lions-danger-500, 0.1) 0%, rgba($lions-danger-700, 0.05) 100%);
      border-bottom-color: $lions-danger-500;
    }

    .ui-confirmdialog-icon {
      color: $lions-danger-600;
    }
  }
}

// ============================================
// 📱 SIDEBAR STYLES
// ============================================

.ui-sidebar {
  position: fixed;
  background: $lions-white;
  @include lions-shadow('2xl');
  z-index: 1001;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  @include lions-transition(transform, 300ms);

  // Sidebar header
  .ui-sidebar-header {
    background: linear-gradient(135deg, rgba($lions-blue-500, 0.1) 0%, rgba($lions-blue-700, 0.05) 100%);
    border-bottom: 2px solid $lions-blue-500;
    padding: $lions-spacing-5 $lions-spacing-6;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h3, h4, h5 {
      margin: 0;
      @include lions-font-weight('bold');
      color: $lions-text-primary;
    }

    .ui-sidebar-close {
      @include lions-button-base;
      width: 2.5rem;
      height: 2.5rem;
      padding: 0;
      @include lions-flex-center;
      background: transparent;
      border: none;
      color: $lions-gray-600;
      @include lions-transition();

      &:hover {
        background: rgba($lions-danger-500, 0.1);
        color: $lions-danger-600;
        transform: scale(1.1) rotate(90deg);
      }

      &:focus-visible {
        @include lions-focus-ring();
      }
    }
  }

  // Sidebar content
  .ui-sidebar-content {
    padding: $lions-spacing-6;
    overflow-y: auto;
    flex: 1;

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

    &::-webkit-scrollbar-track {
      background: $lions-gray-100;
    }

    &::-webkit-scrollbar-thumb {
      background: $lions-gray-400;
      @include lions-rounded('full');

      &:hover {
        background: $lions-blue-500;
      }
    }
  }

  // Sidebar footer
  .ui-sidebar-footer {
    background: linear-gradient(135deg, rgba($lions-gray-50, 0.8) 0%, rgba($lions-gray-100, 0.5) 100%);
    border-top: 1px solid $lions-gray-300;
    padding: $lions-spacing-4 $lions-spacing-6;
  }

  // Position variants
  &.ui-sidebar-left {
    top: 0;
    left: 0;
    height: 100%;
    width: 400px;
    border-right: 1px solid $lions-gray-300;

    &.ui-sidebar-active {
      transform: translateX(0);
    }

    &:not(.ui-sidebar-active) {
      transform: translateX(-100%);
    }
  }

  &.ui-sidebar-right {
    top: 0;
    right: 0;
    height: 100%;
    width: 400px;
    border-left: 1px solid $lions-gray-300;

    &.ui-sidebar-active {
      transform: translateX(0);
    }

    &:not(.ui-sidebar-active) {
      transform: translateX(100%);
    }
  }

  &.ui-sidebar-top {
    top: 0;
    left: 0;
    width: 100%;
    height: 300px;
    border-bottom: 1px solid $lions-gray-300;

    &.ui-sidebar-active {
      transform: translateY(0);
    }

    &:not(.ui-sidebar-active) {
      transform: translateY(-100%);
    }
  }

  &.ui-sidebar-bottom {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 300px;
    border-top: 1px solid $lions-gray-300;

    &.ui-sidebar-active {
      transform: translateY(0);
    }

    &:not(.ui-sidebar-active) {
      transform: translateY(100%);
    }
  }

  &.ui-sidebar-full {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

// ============================================
// 📌 OVERLAY PANEL STYLES
// ============================================

.ui-overlaypanel {
  position: absolute;
  background: $lions-white;
  @include lions-rounded('lg');
  @include lions-shadow('xl');
  z-index: 1002;
  padding: 0;
  @include lions-transition(opacity, 200ms);

  // Arrow pointer
  &::before,
  &::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: solid transparent;
  }

  &::before {
    border-width: 11px;
  }

  &::after {
    border-width: 10px;
  }

  // Arrow positions
  &.ui-overlaypanel-flipped {
    &::before,
    &::after {
      bottom: 100%;
      left: 50%;
    }

    &::before {
      margin-left: -11px;
      border-bottom-color: $lions-gray-300;
    }

    &::after {
      margin-left: -10px;
      border-bottom-color: $lions-white;
    }
  }

  &:not(.ui-overlaypanel-flipped) {
    &::before,
    &::after {
      top: 100%;
      left: 50%;
    }

    &::before {
      margin-left: -11px;
      border-top-color: $lions-gray-300;
    }

    &::after {
      margin-left: -10px;
      border-top-color: $lions-white;
    }
  }

  // Header
  .ui-overlaypanel-header {
    background: linear-gradient(135deg, rgba($lions-blue-500, 0.1) 0%, rgba($lions-blue-700, 0.05) 100%);
    border-bottom: 2px solid $lions-blue-500;
    padding: $lions-spacing-4 $lions-spacing-5;
    @include lions-rounded('lg');
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h5, h6 {
      margin: 0;
      @include lions-font-weight('bold');
      color: $lions-text-primary;
    }

    .ui-overlaypanel-close {
      @include lions-button-base;
      width: 2rem;
      height: 2rem;
      padding: 0;
      @include lions-flex-center;
      background: transparent;
      border: none;
      color: $lions-gray-600;
      @include lions-transition();

      &:hover {
        background: rgba($lions-danger-500, 0.1);
        color: $lions-danger-600;
        transform: scale(1.1);
      }

      &:focus-visible {
        @include lions-focus-ring();
      }
    }
  }

  // Content
  .ui-overlaypanel-content {
    padding: $lions-spacing-5;
    max-height: 400px;
    overflow-y: auto;
    color: $lions-text-primary;

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

    &::-webkit-scrollbar-track {
      background: $lions-gray-100;
    }

    &::-webkit-scrollbar-thumb {
      background: $lions-gray-400;
      @include lions-rounded('full');

      &:hover {
        background: $lions-blue-500;
      }
    }
  }

  // Footer
  .ui-overlaypanel-footer {
    background: linear-gradient(135deg, rgba($lions-gray-50, 0.8) 0%, rgba($lions-gray-100, 0.5) 100%);
    border-top: 1px solid $lions-gray-300;
    padding: $lions-spacing-3 $lions-spacing-5;
    @include lions-rounded('lg');
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
}

// ============================================
// 📱 RESPONSIVE ADJUSTMENTS
// ============================================

@media (max-width: $lions-breakpoint-md) {
  .ui-dialog {
    max-width: 95vw !important;
    max-height: 95vh !important;
    margin: $lions-spacing-3 !important;

    .ui-dialog-titlebar {
      padding: $lions-spacing-4 $lions-spacing-5;

      .ui-dialog-title {
        @include lions-font-size('lg');
      }
    }

    .ui-dialog-content {
      padding: $lions-spacing-5;
    }

    .ui-dialog-footer {
      padding: $lions-spacing-3 $lions-spacing-5;
      flex-wrap: wrap;
    }
  }

  .ui-sidebar {
    &.ui-sidebar-left,
    &.ui-sidebar-right {
      width: 85vw !important;
    }

    &.ui-sidebar-top,
    &.ui-sidebar-bottom {
      height: 50vh !important;
    }

    .ui-sidebar-header,
    .ui-sidebar-content,
    .ui-sidebar-footer {
      padding: $lions-spacing-4 $lions-spacing-5;
    }
  }

  .ui-overlaypanel {
    max-width: 90vw !important;

    .ui-overlaypanel-content {
      max-height: 300px;
      padding: $lions-spacing-4;
    }
  }
}

// ============================================
// ✨ ANIMATIONS
// ============================================

@keyframes lions-dialog-fade-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes lions-dialog-fade-out {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
}

.ui-dialog,
.ui-confirmdialog {
  animation: lions-dialog-fade-in 300ms ease-out;

  &.ui-dialog-exit {
    animation: lions-dialog-fade-out 200ms ease-in;
  }
}

.ui-overlaypanel {
  animation: lions-dialog-fade-in 200ms ease-out;
}

// ============================================
// ♿ ACCESSIBILITY ENHANCEMENTS
// ============================================

.ui-dialog,
.ui-confirmdialog,
.ui-sidebar,
.ui-overlaypanel {
  // Focus trap
  &[aria-modal="true"] {
    outline: none;
  }

  // High contrast mode
  @media (prefers-contrast: high) {
    border: 3px solid currentColor !important;
  }

  // Reduced motion
  @media (prefers-reduced-motion: reduce) {
    animation: none !important;
    transition: none !important;

    * {
      animation: none !important;
      transition: none !important;
    }
  }
}

// ============================================
// 🎯 DIALOG POSITIONS
// ============================================

.ui-dialog {
  &.ui-dialog-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  &.ui-dialog-top {
    top: $lions-spacing-6;
    left: 50%;
    transform: translateX(-50%);
  }

  &.ui-dialog-bottom {
    bottom: $lions-spacing-6;
    left: 50%;
    transform: translateX(-50%);
  }

  &.ui-dialog-left {
    top: 50%;
    left: $lions-spacing-6;
    transform: translateY(-50%);
  }

  &.ui-dialog-right {
    top: 50%;
    right: $lions-spacing-6;
    transform: translateY(-50%);
  }

  &.ui-dialog-top-left {
    top: $lions-spacing-6;
    left: $lions-spacing-6;
  }

  &.ui-dialog-top-right {
    top: $lions-spacing-6;
    right: $lions-spacing-6;
  }

  &.ui-dialog-bottom-left {
    bottom: $lions-spacing-6;
    left: $lions-spacing-6;
  }

  &.ui-dialog-bottom-right {
    bottom: $lions-spacing-6;
    right: $lions-spacing-6;
  }
}
