@use 'ui-design-system/src/styles/semantic/index' as *;

// Tokens available globally via main application styles

.ui-card {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  margin-right: $semantic-spacing-grid-gap-xs;
  margin-bottom: $semantic-spacing-grid-gap-xs;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  
  // Base styles
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: all $semantic-duration-fast $semantic-easing-standard;
  
  // Size variants - following 8px grid increments
  &--sm {
    min-height: $semantic-sizing-card-height-sm;
    
    .card-content-layer {
      padding: $semantic-spacing-component-padding-sm;
    }
    
    .card-header {
      padding-bottom: $semantic-spacing-component-sm;
    }
    
    .card-footer {
      padding-top: $semantic-spacing-component-sm;
    }
  }
  
  &--md {
    min-height: $semantic-sizing-card-height-md;
    
    .card-content-layer {
      padding: $semantic-spacing-component-padding-lg;
    }
    
    .card-header {
      padding-bottom: $semantic-spacing-component-md;
    }
    
    .card-footer {
      padding-top: $semantic-spacing-component-md;
    }
  }
  
  &--lg {
    min-height: $semantic-sizing-card-height-lg;
    
    .card-content-layer {
      padding: $semantic-spacing-component-padding-xl;
    }
    
    .card-header {
      padding-bottom: $semantic-spacing-component-lg;
    }
    
    .card-footer {
      padding-top: $semantic-spacing-component-lg;
    }
  }
  
  // Elevation variants - Material Design shadow levels
  &--elevation-none {
    box-shadow: none;
  }
  
  &--elevation-sm {
    box-shadow: $semantic-shadow-elevation-1;
  }
  
  &--elevation-md {
    box-shadow: $semantic-shadow-elevation-2;
  }
  
  &--elevation-lg {
    box-shadow: $semantic-shadow-elevation-3;
  }
  
  &--elevation-xl {
    box-shadow: $semantic-shadow-elevation-4;
  }
  
  // Radius variants - consistent scale
  &--radius-none {
    border-radius: 0;
  }
  
  &--radius-sm {
    border-radius: $semantic-border-radius-sm;
  }
  
  &--radius-md {
    border-radius: $semantic-border-radius-md;
  }
  
  &--radius-lg {
    border-radius: $semantic-border-radius-lg;
  }
  
  &--radius-full {
    border-radius: $semantic-border-radius-full;
    aspect-ratio: 1;
  }
  
  // Variant styles - Material Design 3 inspired colors
  &--elevated {
    background-color: $semantic-color-surface-primary;
    color: $semantic-color-text-primary;
    border: none;
    
    &:hover:not(.ui-card--disabled) {
      transform: translateY(-2px);
      box-shadow: $semantic-shadow-card-hover;
    }
  }
  
  &--filled {
    background-color: $semantic-color-surface-secondary;
    color: $semantic-color-text-primary;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    
    &:hover:not(.ui-card--disabled) {
      background-color: $semantic-color-surface-elevated;
    }
  }
  
  &--outlined {
    background-color: transparent;
    color: $semantic-color-text-primary;
    border: $semantic-border-width-1 solid $semantic-color-border-secondary;
    
    &:hover:not(.ui-card--disabled) {
      border-color: $semantic-color-border-focus;
      background-color: $semantic-color-surface-elevated;
    }
  }
  
  // Clickable state
  &--clickable {
    cursor: pointer;
    user-select: none;
    
    &:active:not(.ui-card--disabled) {
      transform: scale(0.98); // Subtle press effect
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-border-focus;
      outline-offset: 2px;
    }
  }
  
  // Disabled state
  &--disabled {
    opacity: 0.38; // Material Design disabled opacity
    cursor: not-allowed;
    pointer-events: none;
  }
  
  // Glass effect using CSS variables and semantic approach
  &--glass {
    position: relative;
    isolation: isolate;
    backdrop-filter: blur(var(--glass-blur-md, 8px));
    -webkit-backdrop-filter: blur(var(--glass-blur-md, 8px));
    border: 1px solid var(--glass-border-color, rgba(255, 255, 255, 0.2));
    transition: all $semantic-duration-short $semantic-easing-standard;
    
    .card-content-layer {
      position: relative;
      z-index: 2;
    }
    
    // Glass variant styles using CSS variables - fixed syntax
    &.ui-card--glass-translucent {
      background: rgba(var(--glass-background-base, 255, 255, 255), var(--glass-opacity-translucent, 0.1));
      backdrop-filter: blur(var(--glass-blur-sm, 4px));
      -webkit-backdrop-filter: blur(var(--glass-blur-sm, 4px));
    }
    
    &.ui-card--glass-light {
      background: rgba(var(--glass-background-base, 255, 255, 255), var(--glass-opacity-light, 0.3));
      backdrop-filter: blur(var(--glass-blur-md, 8px));
      -webkit-backdrop-filter: blur(var(--glass-blur-md, 8px));
    }
    
    &.ui-card--glass-medium {
      background: rgba(var(--glass-background-base, 255, 255, 255), var(--glass-opacity-medium, 0.5));
      backdrop-filter: blur(var(--glass-blur-md, 8px));
      -webkit-backdrop-filter: blur(var(--glass-blur-md, 8px));
    }
    
    &.ui-card--glass-heavy {
      background: rgba(var(--glass-background-base, 255, 255, 255), var(--glass-opacity-heavy, 0.7));
      backdrop-filter: blur(var(--glass-blur-lg, 16px));
      -webkit-backdrop-filter: blur(var(--glass-blur-lg, 16px));
    }
    
    &.ui-card--glass-frosted {
      background: rgba(var(--glass-background-base, 255, 255, 255), var(--glass-opacity-frosted, 0.85));
      backdrop-filter: blur(var(--glass-blur-xl, 24px));
      -webkit-backdrop-filter: blur(var(--glass-blur-xl, 24px));
    }
    
    // Interactive glass states
    &.ui-card--clickable:hover:not(.ui-card--disabled) {
      transform: translateY(-2px);
      box-shadow: $semantic-shadow-elevation-3;
    }
    
    &.ui-card--clickable:active:not(.ui-card--disabled) {
      transform: scale(0.98);
    }
    
    // Disabled state for glass cards
    &.ui-card--disabled {
      backdrop-filter: blur(var(--glass-blur-xs, 2px));
      -webkit-backdrop-filter: blur(var(--glass-blur-xs, 2px));
      opacity: 0.6;
    }
  }
  
  // With background layer
  &--with-background {
    .card-background-layer {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      box-sizing: border-box;
      transform: translateZ(0);
      z-index: 0;
    }
    
    .card-content-layer {
      position: relative;
      z-index: 1;
      background: $semantic-color-surface-primary;
      color: $semantic-color-text-primary;
    }
  }
}

// Card content structure
.card-content-layer {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 1;
  color: inherit;
}

.card-header {
  border-bottom: $semantic-border-width-1 solid $semantic-color-border-secondary;
  
  h1, h2, h3, h4, h5, h6 {
    margin: 0;
    color: $semantic-color-text-primary;
  }
  
  p {
    margin: 0;
    color: $semantic-color-text-secondary;
  }
}

.card-body {
  flex: 1;
  color: inherit;
  
  // Typography reset
  > *:first-child {
    margin-top: 0;
  }
  
  > *:last-child {
    margin-bottom: 0;
  }
  
  p {
    color: $semantic-color-text-primary;
  }
}

.card-footer {
  border-top: $semantic-border-width-1 solid $semantic-color-border-secondary;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: $semantic-spacing-component-sm;
}

// Glass overlay for enhanced glass effect
.card-glass-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(145deg, 
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(255, 255, 255, 0.1) 100%);
  pointer-events: none;
  z-index: 1;
  border-radius: inherit;
}

// Ripple effect for clickable cards
.card-ripple-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
  
  &::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(120, 53, 255, 0.2); // Brand color ripple
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
  
  .ui-card--clickable:active & {
    &::after {
      transform: translate(-50%, -50%) scale(2);
      opacity: 1;
      transition: none;
    }
  }
}

// Hover effects based on elevation
.ui-card:hover:not(.ui-card--disabled) {
  &.ui-card--elevation-sm {
    box-shadow: $semantic-shadow-elevation-2;
  }
  
  &.ui-card--elevation-md {
    box-shadow: $semantic-shadow-elevation-3;
  }
  
  &.ui-card--elevation-lg {
    box-shadow: $semantic-shadow-elevation-4;
  }
}

// Dark mode support - Remove problematic dark mode overrides
// Semantic tokens should handle dark mode automatically

// Responsive adaptations  
@media (max-width: ($semantic-breakpoint-md - 1)) {
  .ui-card {
    margin-right: 0;
    
    &--lg {
      .card-content-layer {
        padding: $semantic-spacing-component-padding-lg;
      }
    }
    
    .card-footer {
      flex-direction: column;
      gap: $semantic-spacing-component-md;
    }
  }
}

// Accessibility
@media (prefers-reduced-motion: reduce) {
  .ui-card {
    transition: none;
    
    &:hover,
    &:active {
      transform: none;
    }
  }
  
  .card-ripple-overlay::after {
    transition: none;
  }
}