// ========================================
// COMPONENT STYLES - Modern UI Components
// ========================================


@import './design-tokens';

// Card Components
// ========================================

.modern-card {
  background: $card-bg;
  backdrop-filter: $backdrop-blur-md;
  border: 1px solid $card-border;
  border-radius: $radius-xl;
  box-shadow: $card-shadow;
  padding: $space-6;
  transition: all $duration-300 $ease-out;
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: $glass-gradient;
  }

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

  &.glassmorphism {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: $backdrop-blur-lg;
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  &.gradient {
    background: $gradient-primary;
    color: $white;
    border: none;

    &::before {
      background: rgba(255, 255, 255, 0.1);
    }
  }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: $space-4;
  padding-bottom: $space-4;
  border-bottom: 1px solid $gray-200;

  .card-title {
    font-size: $text-xl;
    font-weight: $font-semibold;
    color: $gray-900;
    margin: 0;
  }

  .card-actions {
    display: flex;
    gap: $space-2;
  }
}

.card-body {
  color: $gray-700;
  line-height: $leading-relaxed;
}

.card-footer {
  margin-top: $space-4;
  padding-top: $space-4;
  border-top: 1px solid $gray-200;
  display: flex;
  justify-content: flex-end;
  gap: $space-3;
}

// Button Components
// ========================================

.modern-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: $space-2;
  padding: $space-3 $space-6;
  font-size: $text-sm;
  font-weight: $font-medium;
  line-height: 1;
  border-radius: $radius-lg;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all $duration-200 $ease-out;
  text-decoration: none;
  position: relative;
  overflow: hidden;

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

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

  // Sizes
  &.btn-sm {
    padding: $space-2 $space-4;
    font-size: $text-xs;
    height: $btn-height-sm;
  }

  &.btn-md {
    padding: $space-3 $space-6;
    font-size: $text-sm;
    height: $btn-height-md;
  }

  &.btn-lg {
    padding: $space-4 $space-8;
    font-size: $text-base;
    height: $btn-height-lg;
  }

  // Variants
  &.btn-primary {
    background: $gradient-primary;
    color: $white;
    border-color: $primary-600;

    &:hover {
      background: linear-gradient(135deg, $primary-600 0%, $primary-800 100%);
      transform: translateY(-1px);
      box-shadow: $shadow-lg;
    }

    &:active {
      transform: translateY(0);
      box-shadow: $shadow-md;
    }
  }

  &.btn-secondary {
    background: $white;
    color: $gray-700;
    border-color: $gray-300;

    &:hover {
      background: $gray-50;
      border-color: $gray-400;
      transform: translateY(-1px);
      box-shadow: $shadow-md;
    }
  }

  &.btn-outline {
    background: transparent;
    color: $primary-600;
    border-color: $primary-600;

    &:hover {
      background: $primary-50;
      border-color: $primary-700;
      color: $primary-700;
    }
  }

  &.btn-ghost {
    background: transparent;
    color: $gray-600;
    border-color: transparent;

    &:hover {
      background: $gray-100;
      color: $gray-900;
    }
  }

  &.btn-success {
    background: $gradient-success;
    color: $white;
    border-color: $accent-green;

    &:hover {
      background: linear-gradient(135deg, #059669 0%, #047857 100%);
      transform: translateY(-1px);
      box-shadow: $shadow-lg;
    }
  }

  &.btn-warning {
    background: $gradient-warning;
    color: $white;
    border-color: $accent-orange;

    &:hover {
      background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
      transform: translateY(-1px);
      box-shadow: $shadow-lg;
    }
  }

  &.btn-error {
    background: $gradient-error;
    color: $white;
    border-color: $accent-red;

    &:hover {
      background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
      transform: translateY(-1px);
      box-shadow: $shadow-lg;
    }
  }

  // Loading state
  &.loading {
    position: relative;
    color: transparent;

    &::after {
      content: '';
      position: absolute;
      width: 16px;
      height: 16px;
      border: 2px solid transparent;
      border-top: 2px solid currentColor;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

// Form Components
// ========================================

.modern-form-group {
  margin-bottom: $space-6;

  .form-label {
    display: block;
    font-size: $text-sm;
    font-weight: $font-medium;
    color: $gray-700;
    margin-bottom: $space-2;
  }

  .form-input {
    width: 100%;
    padding: $space-3 $space-4;
    font-size: $text-sm;
    line-height: $leading-normal;
    color: $gray-900;
    background: $white;
    border: 1px solid $input-border;
    border-radius: $radius-lg;
    transition: all $duration-200 $ease-out;

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

    &:disabled {
      background: $gray-100;
      color: $gray-500;
      cursor: not-allowed;
    }

    &.error {
      border-color: $input-border-error;
      box-shadow: 0 0 0 3px rgba($error, 0.1);
    }

    &::placeholder {
      color: $gray-400;
    }
  }

  .form-textarea {
    @extend .form-input;
    min-height: 120px;
    resize: vertical;
  }

  .form-select {
    @extend .form-input;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right $space-3 center;
    background-repeat: no-repeat;
    background-size: 16px 12px;
    padding-right: $space-10;
    appearance: none;
  }

  .form-error {
    margin-top: $space-1;
    font-size: $text-xs;
    color: $error;
  }

  .form-help {
    margin-top: $space-1;
    font-size: $text-xs;
    color: $gray-500;
  }
}

// Input Group
.input-group {
  display: flex;
  align-items: stretch;

  .input-group-prepend {
    display: flex;
    align-items: center;
    padding: $space-3 $space-4;
    background: $gray-100;
    border: 1px solid $gray-300;
    border-right: none;
    border-radius: $radius-lg 0 0 $radius-lg;
    color: $gray-600;
  }

  .input-group-append {
    display: flex;
    align-items: center;
    padding: $space-3 $space-4;
    background: $gray-100;
    border: 1px solid $gray-300;
    border-left: none;
    border-radius: 0 $radius-lg $radius-lg 0;
    color: $gray-600;
  }

  .form-input {
    border-radius: 0;

    &:first-child {
      border-radius: $radius-lg 0 0 $radius-lg;
    }

    &:last-child {
      border-radius: 0 $radius-lg $radius-lg 0;
    }

    &:only-child {
      border-radius: $radius-lg;
    }
  }
}

// Table Components
// ========================================

.modern-table {
  width: 100%;
  border-collapse: collapse;
  background: $white;
  border-radius: $radius-xl;
  overflow: hidden;
  box-shadow: $shadow-lg;

  thead {
    background: $gray-50;

    th {
      padding: $space-4 $space-6;
      text-align: left;
      font-size: $text-xs;
      font-weight: $font-semibold;
      color: $gray-600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      border-bottom: 1px solid $gray-200;

      &:first-child {
        padding-left: $space-8;
      }

      &:last-child {
        padding-right: $space-8;
      }
    }
  }

  tbody {
    tr {
      transition: background-color $duration-150 $ease-out;

      &:hover {
        background: $gray-50;
      }

      &:not(:last-child) {
        border-bottom: 1px solid $gray-200;
      }
    }

    td {
      padding: $space-4 $space-6;
      font-size: $text-sm;
      color: $gray-700;

      &:first-child {
        padding-left: $space-8;
      }

      &:last-child {
        padding-right: $space-8;
      }
    }
  }
}

// Badge Components
// ========================================

.modern-badge {
  display: inline-flex;
  align-items: center;
  padding: $space-1 $space-3;
  font-size: $text-xs;
  font-weight: $font-medium;
  border-radius: $radius-full;
  text-transform: uppercase;
  letter-spacing: 0.05em;

  &.badge-primary {
    background: $primary-100;
    color: $primary-800;
  }

  &.badge-secondary {
    background: $secondary-100;
    color: $secondary-800;
  }

  &.badge-success {
    background: rgba($accent-green, 0.1);
    color: $accent-green;
  }

  &.badge-warning {
    background: rgba($accent-orange, 0.1);
    color: $accent-orange;
  }

  &.badge-error {
    background: rgba($accent-red, 0.1);
    color: $accent-red;
  }

  &.badge-gray {
    background: $gray-100;
    color: $gray-700;
  }
}

// Alert Components
// ========================================

.modern-alert {
  padding: $space-4 $space-6;
  border-radius: $radius-lg;
  border: 1px solid;
  margin-bottom: $space-4;
  display: flex;
  align-items: flex-start;
  gap: $space-3;

  .alert-icon {
    flex-shrink: 0;
    margin-top: 2px;
  }

  .alert-content {
    flex: 1;

    .alert-title {
      font-weight: $font-semibold;
      margin-bottom: $space-1;
    }

    .alert-message {
      font-size: $text-sm;
      line-height: $leading-relaxed;
    }
  }

  &.alert-info {
    background: rgba($primary-500, 0.05);
    border-color: rgba($primary-500, 0.2);
    color: $primary-800;

    .alert-icon {
      color: $primary-600;
    }
  }

  &.alert-success {
    background: rgba($accent-green, 0.05);
    border-color: rgba($accent-green, 0.2);
    color: #065f46;

    .alert-icon {
      color: $accent-green;
    }
  }

  &.alert-warning {
    background: rgba($accent-orange, 0.05);
    border-color: rgba($accent-orange, 0.2);
    color: #92400e;

    .alert-icon {
      color: $accent-orange;
    }
  }

  &.alert-error {
    background: rgba($accent-red, 0.05);
    border-color: rgba($accent-red, 0.2);
    color: #991b1b;

    .alert-icon {
      color: $accent-red;
    }
  }
}

// Modal Components
// ========================================

.modern-modal {
  .modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba($black, 0.5);
    backdrop-filter: $backdrop-blur-sm;
    z-index: $z-modal-backdrop;
    animation: fadeIn $duration-200 $ease-out;
  }

  .modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: $white;
    border-radius: $radius-2xl;
    box-shadow: $shadow-2xl;
    z-index: $z-modal;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    animation: slideIn $duration-300 $ease-out;

    .modal-header {
      padding: $space-6 $space-8;
      border-bottom: 1px solid $gray-200;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .modal-title {
        font-size: $text-xl;
        font-weight: $font-semibold;
        color: $gray-900;
        margin: 0;
      }

      .modal-close {
        background: none;
        border: none;
        color: $gray-400;
        cursor: pointer;
        padding: $space-2;
        border-radius: $radius-md;
        transition: all $duration-200 $ease-out;

        &:hover {
          background: $gray-100;
          color: $gray-600;
        }
      }
    }

    .modal-body {
      padding: $space-6 $space-8;
      max-height: 60vh;
      overflow-y: auto;
    }

    .modal-footer {
      padding: $space-6 $space-8;
      border-top: 1px solid $gray-200;
      display: flex;
      justify-content: flex-end;
      gap: $space-3;
    }
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

// Loading Components
// ========================================

.modern-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid $gray-200;
  border-top: 2px solid $primary-500;
  border-radius: 50%;
  animation: spin 1s linear infinite;

  &.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 1.5px;
  }

  &.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
  }
}

.modern-skeleton {
  background: linear-gradient(90deg, $gray-200 25%, $gray-100 50%, $gray-200 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: $radius-md;

  &.skeleton-text {
    height: 1em;
    margin-bottom: $space-2;
  }

  &.skeleton-title {
    height: 1.5em;
    margin-bottom: $space-4;
  }

  &.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  &.skeleton-button {
    height: 40px;
    width: 100px;
  }
}

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