/* components/image-card.css */
image-card {
  display: inline-block;
  width: 100%;
  margin-bottom: 16px;
  break-inside: avoid;
  position: relative;
  z-index: 1;
}

image-card.expanded {
  position: fixed;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: auto;
  max-width: calc(90vw - 20px); /* Subtract timeline width */
  max-height: 90vh;
  z-index: 1000 !important;
  margin: 0;
  animation: expandIn 0.3s ease-out;
}

@keyframes expandIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Backdrop for expanded state */
image-card.expanded::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: -1;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 768px) {
  image-card {
    margin-bottom: 36px;
  }
}

image-card .card {
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  width: 100%;
}

image-card .card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-hover-shadow);
}

image-card.expanded .card {
  box-shadow: none;
  background: transparent;
  border-radius: 0;
  height: auto; /* Changed from 100% */
  max-height: 90vh;
  width: auto; /* Allow card to fit content */
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
}

image-card .image-container {
  position: relative;
  width: 100%;
  background: var(--image-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

image-card.expanded .image-container {
  width: auto; /* Changed from 100% */
  flex: 0 0 auto; /* Don't grow, just fit content */
  aspect-ratio: auto !important;
  background: transparent;
  overflow: visible;
  max-height: calc(90vh - 80px);
  max-width: 90vw;
}

image-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.3s;
}

image-card.expanded img {
  max-width: 90vw;
  max-height: calc(90vh - 80px);
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

image-card img.loading {
  opacity: 0;
}

image-card img.loaded {
  opacity: 1;
}

image-card .info {
  padding: 12px 16px;
  flex: 0 0 auto;
  transition: padding 0.3s;
  background: var(--card-bg);
}

image-card.expanded .info {
  padding: 16px 20px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-radius: 8px;
  margin-top: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  width: 100%; /* Match the image width */
  box-sizing: border-box;
}

image-card .title {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: font-size 0.3s;
}

image-card.expanded .title {
  font-size: 16px;
  white-space: normal;
}

image-card .subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: font-size 0.3s;
}

image-card.expanded .subtitle {
  font-size: 14px;
  white-space: normal;
  line-height: 1.5;
  max-height: none;
}

image-card .expand-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

image-card .card:hover .expand-indicator {
  opacity: 1;
}

image-card.expanded .expand-indicator {
  opacity: 1;
}

image-card.expanded .expand-indicator::before {
  content: '−';
}

image-card .expand-indicator::before {
  content: '+';
}

image-card .detail-button {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(52, 152, 219, 0.4);
  transition: background 0.2s, transform 0.2s;
  z-index: 10;
}

image-card.expanded .detail-button {
  display: block;
}

image-card .detail-button:hover {
  background: var(--accent-hover);
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.5);
}

image-card .classification-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: calc(100% - 56px); /* Leave space for expand indicator */
}

image-card .badge {
  background: rgba(52, 152, 219, 0.9);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(4px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

image-card.expanded .classification-badges {
  display: none; /* Hide badges when expanded */
}

/* Drag and drop styles */
image-card.drag-over .card {
  border: 3px solid var(--accent-color);
  box-shadow: 0 0 20px rgba(52, 152, 219, 0.4);
  transform: translateY(-4px) scale(1.02);
}

image-card.link-created .card {
  animation: linkCreated 1s ease-out;
}

@keyframes linkCreated {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
  }
  50% {
    box-shadow: 0 0 20px 10px rgba(46, 204, 113, 0.4);
    border-color: #2ecc71;
  }
  100% {
    box-shadow: var(--shadow-md);
  }
}