@use './variables' as *;
@use './utilities' as *;
@use './animations';
@use './material-ui-custom';

.mui-enhanced {
  font-family: $font-family-sans;
  color: $text-primary;
  
  * {
    box-sizing: border-box;
  }
  
  code, pre {
    font-family: $font-family-mono;
  }
  
  h1, h2, h3, h4, h5, h6 {
    font-family: $font-family-display;
  }
}

.custom-mui-container {
  max-width: $container-max-width;
  margin-left: auto;
  margin-right: auto;
  padding-left: $container-padding;
  padding-right: $container-padding;
  
  @include respond-to('lg') {
    padding-left: calc($container-padding * 2);
    padding-right: calc($container-padding * 2);
  }
}

.custom-mui-grid {
  display: grid;
  gap: $grid-gutter;
  
  &--cols-1 {
    grid-template-columns: repeat(1, 1fr);
  }
  
  &--cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  &--cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  &--cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  &--cols-6 {
    grid-template-columns: repeat(6, 1fr);
  }
  
  &--cols-12 {
    grid-template-columns: repeat(12, 1fr);
  }
  
  &--responsive {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

.custom-mui-flex {
  display: flex;
  
  &--row {
    flex-direction: row;
  }
  
  &--col {
    flex-direction: column;
  }
  
  &--wrap {
    flex-wrap: wrap;
  }
  
  &--center {
    justify-content: center;
    align-items: center;
  }
  
  &--between {
    justify-content: space-between;
  }
  
  &--around {
    justify-content: space-around;
  }
  
  &--evenly {
    justify-content: space-evenly;
  }
  
  &--start {
    justify-content: flex-start;
    align-items: flex-start;
  }
  
  &--end {
    justify-content: flex-end;
    align-items: flex-end;
  }
}

.custom-mui-stack {
  display: flex;
  flex-direction: column;
  gap: spacing('4');
  
  &--horizontal {
    flex-direction: row;
  }
  
  &--gap-1 {
    gap: spacing('1');
  }
  
  &--gap-2 {
    gap: spacing('2');
  }
  
  &--gap-3 {
    gap: spacing('3');
  }
  
  &--gap-4 {
    gap: spacing('4');
  }
  
  &--gap-6 {
    gap: spacing('6');
  }
  
  &--gap-8 {
    gap: spacing('8');
  }
}

.custom-mui-surface {
  background: $background-card;
  border: 1px solid $border-color;
  border-radius: $radius-lg;
  padding: spacing('6');
  
  &--elevated {
    box-shadow: $shadow-lg;
    background: $background-elevated;
  }
  
  &--interactive {
    cursor: pointer;
    transition: all $transition-base;
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: $shadow-xl;
      border-color: $border-color-strong;
    }
    
    &:active {
      transform: translateY(0);
      box-shadow: $shadow-md;
    }
  }
}

.custom-mui-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: z-index('modal-backdrop');
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in $transition-fast;
}

.custom-mui-drawer {
  position: fixed;
  background: $background-card;
  z-index: z-index('modal');
  box-shadow: $shadow-2xl;
  overflow-y: auto;
  
  &--left {
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    animation: slide-in-left $transition-base;
  }
  
  &--right {
    top: 0;
    right: 0;
    bottom: 0;
    width: 320px;
    animation: slide-in-right $transition-base;
  }
  
  &--top {
    top: 0;
    left: 0;
    right: 0;
    height: auto;
    animation: slide-in-down $transition-base;
  }
  
  &--bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    max-height: 90vh;
    animation: slide-in-up $transition-base;
  }
}

.custom-mui-navbar {
  position: sticky;
  top: 0;
  z-index: z-index('sticky');
  background: rgba($background-card, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid $border-color;
  padding: spacing('4') spacing('6');
  
  @include respond-below('md') {
    padding: spacing('3') spacing('4');
  }
}

.custom-mui-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: $background-card;
  border-right: 1px solid $border-color;
  overflow-y: auto;
  z-index: z-index('fixed');
  
  @include respond-below('lg') {
    transform: translateX(-100%);
    transition: transform $transition-base;
    
    &--open {
      transform: translateX(0);
    }
  }
}

.custom-mui-footer {
  background: $background-card;
  border-top: 1px solid $border-color;
  padding: spacing('8') spacing('6');
  margin-top: auto;
  
  @include respond-below('md') {
    padding: spacing('6') spacing('4');
  }
}

.custom-mui-breadcrumbs {
  display: flex;
  align-items: center;
  gap: spacing('2');
  flex-wrap: wrap;
  
  &-item {
    display: flex;
    align-items: center;
    color: $text-secondary;
    font-size: font-size('sm');
    
    &--active {
      color: $text-primary;
      font-weight: font-weight('medium');
    }
    
    &:not(:last-child)::after {
      content: '/';
      margin-left: spacing('2');
      color: $text-disabled;
    }
  }
  
  a {
    color: inherit;
    text-decoration: none;
    transition: color $transition-fast;
    
    &:hover {
      color: $accent-color;
    }
  }
}

.custom-mui-stepper {
  display: flex;
  align-items: center;
  
  &-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: spacing('2');
    flex: 1;
    position: relative;
    
    &:not(:last-child)::after {
      content: '';
      position: absolute;
      top: 16px;
      left: 50%;
      width: 100%;
      height: 2px;
      background: $border-color;
    }
    
    &--completed::after {
      background: $success-color;
    }
    
    &--active::after {
      background: $primary-color;
    }
  }
  
  &-icon {
    @include center;
    width: 32px;
    height: 32px;
    border-radius: $radius-full;
    background: $background-elevated;
    border: 2px solid $border-color;
    color: $text-secondary;
    font-size: font-size('sm');
    font-weight: font-weight('semibold');
    z-index: 1;
    
    .custom-mui-stepper-step--completed & {
      background: $success-color;
      border-color: $success-color;
      color: white;
    }
    
    .custom-mui-stepper-step--active & {
      background: $primary-color;
      border-color: $primary-color;
      color: white;
    }
  }
  
  &-label {
    font-size: font-size('sm');
    color: $text-secondary;
    text-align: center;
    
    .custom-mui-stepper-step--active & {
      color: $text-primary;
      font-weight: font-weight('medium');
    }
  }
}

.custom-mui-timeline {
  position: relative;
  padding-left: spacing('6');
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: $border-color;
  }
  
  &-item {
    position: relative;
    padding-bottom: spacing('6');
    
    &::before {
      content: '';
      position: absolute;
      left: -29px;
      top: 4px;
      width: 12px;
      height: 12px;
      border-radius: $radius-full;
      background: $primary-color;
      border: 2px solid $background-dark;
    }
    
    &--success::before {
      background: $success-color;
    }
    
    &--error::before {
      background: $error-color;
    }
    
    &--warning::before {
      background: $warning-color;
    }
  }
}

.custom-mui-table {
  width: 100%;
  border-collapse: collapse;
  
  thead {
    background: $background-elevated;
    border-bottom: 2px solid $border-color-strong;
  }
  
  th {
    padding: spacing('3') spacing('4');
    text-align: left;
    font-weight: font-weight('semibold');
    font-size: font-size('sm');
    color: $text-secondary;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  td {
    padding: spacing('3') spacing('4');
    border-bottom: 1px solid $border-color;
  }
  
  tbody tr {
    transition: background $transition-fast;
    
    &:hover {
      background: $background-hover;
    }
  }
  
  &--striped tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
  }
  
  &--bordered {
    border: 1px solid $border-color;
    
    td, th {
      border: 1px solid $border-color;
    }
  }
}

.custom-mui-list {
  @include reset-list;
  
  &-item {
    padding: spacing('3') spacing('4');
    transition: background $transition-fast;
    border-radius: $radius-md;
    cursor: pointer;
    
    &:hover {
      background: $background-hover;
    }
    
    &--active {
      background: rgba($primary-color, 0.1);
      color: $primary-color;
      font-weight: font-weight('medium');
    }
    
    &--disabled {
      opacity: 0.5;
      cursor: not-allowed;
      pointer-events: none;
    }
  }
  
  &--bordered &-item {
    border: 1px solid $border-color;
    margin-bottom: spacing('2');
  }
  
  &--divided &-item {
    border-bottom: 1px solid $border-color;
    border-radius: 0;
    
    &:last-child {
      border-bottom: none;
    }
  }
}

.custom-mui-code-block {
  background: $background-elevated;
  border: 1px solid $border-color;
  border-radius: $radius-md;
  padding: spacing('4');
  overflow-x: auto;
  font-family: $font-family-mono;
  font-size: font-size('sm');
  
  @include show-scrollbar;
  
  pre {
    margin: 0;
    padding: 0;
  }
  
  code {
    color: $text-primary;
    font-family: inherit;
  }
}

.custom-mui-tag {
  display: inline-flex;
  align-items: center;
  gap: spacing('1');
  padding: spacing('1') spacing('2');
  border-radius: $radius-md;
  font-size: font-size('xs');
  font-weight: font-weight('medium');
  background: rgba($primary-color, 0.15);
  color: $primary-color;
  
  &--sm {
    padding: 2px spacing('1');
    font-size: 10px;
  }
  
  &--lg {
    padding: spacing('2') spacing('3');
    font-size: font-size('sm');
  }
}

.utility-text {
  &-truncate {
    @include truncate(1);
  }
  
  &-truncate-2 {
    @include truncate(2);
  }
  
  &-truncate-3 {
    @include truncate(3);
  }
}

.utility-visually-hidden {
  @include visually-hidden;
}

.utility-focus-ring {
  @include focus-ring;
}
