// ==========================================================================
// BASE CARDS
// ==========================================================================
// Theme-agnostic card structures and layouts
// Visual styling handled by themes
// ==========================================================================

// CARD BASE
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-clip: border-box;
  border: var(--card-border-width, #{$semantic-border-card-width}) solid transparent;
  border-radius: var(--card-border-radius, #{$semantic-border-card-radius});

  &.card-interactive {
    cursor: pointer;
    transition: all var(--card-transition-duration, 0.2s) var(--card-transition-easing, ease);

    &:hover {
      transform: var(--card-hover-transform, translateY(-2px));
    }

    &:active {
      transform: var(--card-active-transform, translateY(0));
    }
  }

  &.card-clickable {
    cursor: pointer;
    text-decoration: none;

    &:focus {
      outline: var(--card-focus-outline, 2px solid transparent);
      outline-offset: var(--card-focus-outline-offset, 2px);
    }
  }
}

// CARD COMPONENTS
.card-header {
  padding: var(--card-header-padding, #{$semantic-spacing-container-card-padding} #{$semantic-spacing-container-card-padding-lg});
  border-bottom: var(--card-header-border-width, #{$semantic-border-divider-width}) solid var(--card-header-border-color, transparent);
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  display: flex;
  align-items: center;
  gap: var(--card-header-gap, #{$semantic-spacing-component-padding-sm});
  min-height: var(--card-header-min-height, auto);

  &:first-child {
    border-top-left-radius: var(--card-border-radius, #{$semantic-border-card-radius});
    border-top-right-radius: var(--card-border-radius, #{$semantic-border-card-radius});
  }

  &.card-header-borderless {
    border-bottom: none;
  }

  .card-title {
    margin: 0;
    font-size: var(--card-title-size, 1.125rem);
    font-weight: var(--card-title-weight, 600);
    line-height: var(--card-title-line-height, 1.4);
    flex: 1;
  }

  .card-subtitle {
    margin: var(--card-subtitle-margin, 4px 0 0 0);
    font-size: var(--card-subtitle-size, 0.875rem);
    opacity: var(--card-subtitle-opacity, 0.7);
  }

  .card-actions {
    display: flex;
    align-items: center;
    gap: var(--card-actions-gap, 8px);
    margin-left: auto;
  }
}

.card-body {
  flex: 1 1 auto;
  padding: var(--card-body-padding, 20px);

  &.card-body-compact {
    padding: var(--card-body-compact-padding, 12px);
  }

  &.card-body-spacious {
    padding: var(--card-body-spacious-padding, 32px);
  }

  &.card-body-flush {
    padding: 0;
  }

  &:first-child {
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
  }

  &:last-child {
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
  }

  .card-text {
    margin: 0 0 var(--card-text-spacing, 16px) 0;
    line-height: var(--card-text-line-height, 1.6);

    &:last-child {
      margin-bottom: 0;
    }
  }
}

.card-footer {
  padding: var(--card-footer-padding, 12px 20px);
  border-top: var(--card-footer-border-width, 1px) solid var(--card-footer-border-color, transparent);
  border-bottom-left-radius: inherit;
  border-bottom-right-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--card-footer-gap, 12px);

  &:last-child {
    border-bottom-left-radius: var(--card-border-radius, 8px);
    border-bottom-right-radius: var(--card-border-radius, 8px);
  }

  &.card-footer-borderless {
    border-top: none;
  }

  &.card-footer-center {
    justify-content: center;
  }

  &.card-footer-end {
    justify-content: flex-end;
  }
}

// CARD MEDIA
.card-img {
  width: 100%;
  border-radius: inherit;

  &.card-img-top {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  &.card-img-bottom {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
}

.card-img-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  padding: var(--card-overlay-padding, 20px);
  border-radius: inherit;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

// CARD VARIANTS
.card-horizontal {
  flex-direction: row;

  .card-img {
    flex-shrink: 0;
    width: var(--card-horizontal-img-width, 200px);
    height: auto;
    border-radius: var(--card-border-radius, 8px) 0 0 var(--card-border-radius, 8px);

    &.card-img-end {
      border-radius: 0 var(--card-border-radius, 8px) var(--card-border-radius, 8px) 0;
      order: 2;
    }
  }

  .card-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .card-horizontal {
    flex-direction: column;

    .card-img {
      width: 100%;
      border-radius: var(--card-border-radius, 8px) var(--card-border-radius, 8px) 0 0;

      &.card-img-end {
        border-radius: 0 0 var(--card-border-radius, 8px) var(--card-border-radius, 8px);
        order: 0;
      }
    }
  }
}

// CARD SIZES
.card-sm {
  --card-header-padding: 12px 16px;
  --card-body-padding: 16px;
  --card-footer-padding: 8px 16px;
  --card-border-radius: 6px;
}

.card-lg {
  --card-header-padding: 24px 32px;
  --card-body-padding: 32px;
  --card-footer-padding: 16px 32px;
  --card-border-radius: 12px;
}

// CARD STATES
.card-loading {
  pointer-events: none;
  opacity: var(--card-loading-opacity, 0.7);

  .card-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 1;
  }
}

.card-disabled {
  pointer-events: none;
  opacity: var(--card-disabled-opacity, 0.6);
}

// CARD GROUPS
.card-group {
  display: flex;

  > .card {
    flex: 1 0 0%;
    border-radius: 0;

    &:first-child {
      border-top-left-radius: var(--card-border-radius, 8px);
      border-bottom-left-radius: var(--card-border-radius, 8px);
    }

    &:last-child {
      border-top-right-radius: var(--card-border-radius, 8px);
      border-bottom-right-radius: var(--card-border-radius, 8px);
    }

    &:not(:last-child) {
      border-right: none;
    }
  }
}

@media (max-width: 768px) {
  .card-group {
    flex-direction: column;

    > .card {
      border-radius: 0;

      &:first-child {
        border-radius: var(--card-border-radius, 8px) var(--card-border-radius, 8px) 0 0;
      }

      &:last-child {
        border-radius: 0 0 var(--card-border-radius, 8px) var(--card-border-radius, 8px);
      }

      &:not(:last-child) {
        border-right: var(--card-border-width, 1px) solid transparent;
        border-bottom: none;
      }
    }
  }
}

// CARD DECK
.card-deck {
  display: flex;
  flex-direction: column;
  gap: var(--card-deck-gap, 24px);

  @media (min-width: 576px) {
    flex-direction: row;
  }

  > .card {
    flex: 1 0 0%;
  }
}

// CARD COLUMNS (Masonry-style)
.card-columns {
  column-count: 1;
  column-gap: var(--card-columns-gap, 24px);
  orphans: 1;
  widows: 1;

  @media (min-width: 576px) {
    column-count: 2;
  }

  @media (min-width: 768px) {
    column-count: 3;
  }

  @media (min-width: 992px) {
    column-count: 4;
  }

  > .card {
    display: inline-block;
    width: 100%;
    margin-bottom: var(--card-columns-gap, 24px);
    break-inside: avoid;
  }
}

// CARD GRID
.card-grid {
  display: grid;
  gap: var(--card-grid-gap, 24px);
  grid-template-columns: 1fr;

  @media (min-width: 576px) {
    grid-template-columns: repeat(2, 1fr);
  }

  @media (min-width: 768px) {
    grid-template-columns: repeat(3, 1fr);
  }

  @media (min-width: 992px) {
    grid-template-columns: repeat(4, 1fr);
  }

  &.card-grid-auto-fit {
    grid-template-columns: repeat(auto-fit, minmax(var(--card-grid-min-width, 280px), 1fr));
  }

  &.card-grid-auto-fill {
    grid-template-columns: repeat(auto-fill, minmax(var(--card-grid-min-width, 280px), 1fr));
  }
}

// SPECIAL CARD TYPES
.card-feature {
  text-align: center;

  .card-body {
    padding: var(--card-feature-padding, 48px 32px);
  }

  .card-icon {
    width: var(--card-feature-icon-size, 64px);
    height: var(--card-feature-icon-size, 64px);
    margin: 0 auto var(--card-feature-icon-spacing, 24px) auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--card-feature-icon-radius, 12px);
  }
}

.card-profile {
  text-align: center;

  .card-avatar {
    width: var(--card-avatar-size, 80px);
    height: var(--card-avatar-size, 80px);
    border-radius: 50%;
    margin: calc(var(--card-avatar-size, 80px) / -2) auto var(--card-avatar-spacing, 16px) auto;
    border: var(--card-avatar-border, 4px solid white);
    position: relative;
    z-index: 1;
  }

  .card-header {
    padding-bottom: calc(var(--card-avatar-size, 80px) / 2 + var(--card-header-padding-bottom, 16px));
  }
}

// ACCESSIBILITY
@media (prefers-reduced-motion: reduce) {
  .card-interactive {
    transition: none;

    &:hover {
      transform: none;
    }
  }
}

@media (prefers-contrast: high) {
  .card {
    border-width: 2px;
  }
}