/* Popup Component */


/* Component-specific custom properties */
.c-popup {
  /* Base properties */
  --c-popup-font-family: var(--ds-font-family-sans);
  --c-popup-font-size: var(--ds-font-size-m);
  --c-popup-line-height: var(--ds-line-height-s);
  --c-popup-transition: all var(--ds-duration-fast) var(--ds-ease-out);
  
  /* Content properties */
  --c-popup-background: var(--ds-color-surface);
  --c-popup-border-color: var(--ds-color-border);
  --c-popup-border-radius: var(--ds-radius-m);
  --c-popup-box-shadow: var(--ds-shadow-l);
  --c-popup-min-width: 10rem;
  --c-popup-max-width: 20rem;
  --c-popup-max-height: 25rem;
  
  /* Header properties */
  --c-popup-header-padding: var(--ds-space-m);
  --c-popup-header-border-color: var(--ds-color-border);
  --c-popup-title-color: var(--ds-color-text);
  --c-popup-title-font-size: var(--ds-font-size-l);
  --c-popup-title-font-weight: var(--ds-font-weight-medium);
  
  /* Body properties */
  --c-popup-body-padding: var(--ds-space-m);
  --c-popup-body-max-height: 25rem;
  
  /* Footer properties */
  --c-popup-footer-padding: var(--ds-space-m);
  --c-popup-footer-border-color: var(--ds-color-border);
  --c-popup-footer-gap: var(--ds-space-s);
  
  /* Close button */
  --c-popup-close-size: 1.5rem;
  --c-popup-close-color: var(--ds-color-text-weak);
  --c-popup-close-color-hover: var(--ds-color-text);
  
  /* Positioning */
  --c-popup-offset: 0.5rem;
  --c-popup-z-index: var(--ds-z-index-popover);
  
  /* Animation */
  --c-popup-scale-from: 0.95;
  --c-popup-opacity-from: 0;
}

/* Base component */
.c-popup {
  position: relative;
  display: inline-block;
  font-family: var(--c-popup-font-family);
  font-size: var(--c-popup-font-size);
  line-height: var(--c-popup-line-height);
}

/* Trigger element */
.c-popup__trigger {
  /* Inherits styles from button or other trigger element */
}

/* Content container */
.c-popup__content {
  position: absolute;
  z-index: var(--c-popup-z-index);
  min-width: var(--c-popup-min-width);
  max-width: var(--c-popup-max-width);
  max-height: var(--c-popup-max-height);
  background: var(--c-popup-background);
  border: 1px solid var(--c-popup-border-color);
  border-radius: var(--c-popup-border-radius);
  box-shadow: var(--c-popup-box-shadow);
  opacity: var(--c-popup-opacity-from);
  visibility: hidden;
  transform: scale(var(--c-popup-scale-from));
  transition: var(--c-popup-transition);
  overflow: hidden;
  outline: none;
}

.c-popup--open .c-popup__content {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

/* Header */
.c-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--c-popup-header-padding);
  border-bottom: 1px solid var(--c-popup-header-border-color);
  background: var(--ds-color-surface-raised);
}

.c-popup__title {
  margin: 0;
  font-size: var(--c-popup-title-font-size);
  font-weight: var(--c-popup-title-font-weight);
  color: var(--c-popup-title-color);
  line-height: var(--ds-line-height-s);
}

.c-popup__header-actions {
  display: flex;
  align-items: center;
  gap: var(--ds-space-xs);
  margin-inline-start: var(--ds-space-s);
}

/* Body */
.c-popup__body {
  padding: var(--c-popup-body-padding);
  max-height: var(--c-popup-body-max-height);
  overflow-y: auto;
  color: var(--ds-color-text);
}

/* Footer */
.c-popup__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--c-popup-footer-gap);
  padding: var(--c-popup-footer-padding);
  border-top: 1px solid var(--c-popup-footer-border-color);
  background: var(--ds-color-surface-raised);
}

/* Close button */
.c-popup__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--c-popup-close-size);
  height: var(--c-popup-close-size);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--ds-radius-xs);
  color: var(--c-popup-close-color);
  cursor: pointer;
  transition: var(--c-popup-transition);
}

.c-popup__close:hover {
  color: var(--c-popup-close-color-hover);
  background: var(--ds-color-surface-lowered);
}

.c-popup__close:focus {
  outline: 2px solid var(--ds-color-accent);
  outline-offset: 2px;
}

.c-popup__close svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* Positioning variants */
.c-popup--position-top .c-popup__content {
  bottom: 100%;
  margin-bottom: var(--c-popup-offset);
}

.c-popup--position-top-start .c-popup__content {
  bottom: 100%;
  left: 0;
  margin-bottom: var(--c-popup-offset);
}

.c-popup--position-top-end .c-popup__content {
  bottom: 100%;
  right: 0;
  margin-bottom: var(--c-popup-offset);
}

.c-popup--position-bottom .c-popup__content,
.c-popup--position-bottom-start .c-popup__content {
  top: 100%;
  left: 0;
  margin-top: var(--c-popup-offset);
}

.c-popup--position-bottom-end .c-popup__content {
  top: 100%;
  right: 0;
  margin-top: var(--c-popup-offset);
}

.c-popup--position-left .c-popup__content {
  right: 100%;
  top: 0;
  margin-right: var(--c-popup-offset);
}

.c-popup--position-left-start .c-popup__content {
  right: 100%;
  top: 0;
  margin-right: var(--c-popup-offset);
}

.c-popup--position-left-end .c-popup__content {
  right: 100%;
  bottom: 0;
  margin-right: var(--c-popup-offset);
}

.c-popup--position-right .c-popup__content {
  left: 100%;
  top: 0;
  margin-left: var(--c-popup-offset);
}

.c-popup--position-right-start .c-popup__content {
  left: 100%;
  top: 0;
  margin-left: var(--c-popup-offset);
}

.c-popup--position-right-end .c-popup__content {
  left: 100%;
  bottom: 0;
  margin-left: var(--c-popup-offset);
}

/* Size variants */
.c-popup--size-s {
  --c-popup-min-width: 8rem;
  --c-popup-max-width: 16rem;
  --c-popup-header-padding: var(--ds-space-s);
  --c-popup-body-padding: var(--ds-space-s);
  --c-popup-footer-padding: var(--ds-space-s);
  --c-popup-title-font-size: var(--ds-font-size-m);
}

.c-popup--size-l {
  --c-popup-min-width: 16rem;
  --c-popup-max-width: 32rem;
  --c-popup-max-height: 40rem;
  --c-popup-header-padding: var(--ds-space-l);
  --c-popup-body-padding: var(--ds-space-l);
  --c-popup-footer-padding: var(--ds-space-l);
  --c-popup-title-font-size: var(--ds-font-size-xl);
}

/* Expand variant */
.c-popup--expand .c-popup__content {
  width: 100%;
  min-width: 100%;
}

/* No header variant */
.c-popup--no-header .c-popup__header {
  display: none;
}

/* No footer variant */
.c-popup--no-footer .c-popup__footer {
  display: none;
}

/* Scrollable body */
.c-popup__body--scrollable {
  max-height: var(--c-popup-body-max-height);
  overflow-y: auto;
}

/* Portal styles */
.c-popup-portal {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--c-popup-z-index);
  pointer-events: none;
}

.c-popup-portal .c-popup__content {
  position: absolute;
  pointer-events: auto;
}

/* Backdrop for modal-like behavior */
.c-popup__backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: calc(var(--c-popup-z-index) - 1);
  background: transparent;
  opacity: 0;
  visibility: hidden;
  transition: var(--c-popup-transition);
}

.c-popup--open .c-popup__backdrop {
  opacity: 1;
  visibility: visible;
}

/* Loading state */
.c-popup--loading .c-popup__body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 4rem;
}

.c-popup__spinner {
  width: 1.5rem;
  height: 1.5rem;
  animation: spin 1s linear infinite;
}

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

/* Responsive behavior */
@media (max-width: 768px) {
  .c-popup {
    --c-popup-max-width: calc(100vw - 2rem);
    --c-popup-max-height: calc(100vh - 4rem);
  }
  
  .c-popup__content {
    max-width: var(--c-popup-max-width);
    max-height: var(--c-popup-max-height);
  }
  
  /* On mobile, center the popup */
  .c-popup--position-bottom .c-popup__content,
  .c-popup--position-bottom-start .c-popup__content,
  .c-popup--position-bottom-end .c-popup__content {
    left: 50%;
    transform: translateX(-50%) scale(var(--c-popup-scale-from));
  }
  
  .c-popup--open .c-popup--position-bottom .c-popup__content,
  .c-popup--open .c-popup--position-bottom-start .c-popup__content,
  .c-popup--open .c-popup--position-bottom-end .c-popup__content {
    transform: translateX(-50%) scale(1);
  }
}

@media (max-width: 480px) {
  .c-popup {
    --c-popup-header-padding: var(--ds-space-s);
    --c-popup-body-padding: var(--ds-space-s);
    --c-popup-footer-padding: var(--ds-space-s);
  }
  
  .c-popup__footer {
    flex-direction: column;
    align-items: stretch;
  }
  
  .c-popup__footer .c-button {
    width: 100%;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .c-popup__content {
    border-width: 2px;
  }
  
  .c-popup__header,
  .c-popup__footer {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .c-popup__content {
    transition: none;
    transform: none;
  }
  
  .c-popup--open .c-popup__content {
    transform: none;
  }
  
  .c-popup__spinner {
    animation: none;
  }
}

/* Print styles */
@media print {
  .c-popup__content {
    position: static;
    box-shadow: none;
    border: 1px solid #000;
    opacity: 1;
    visibility: visible;
    transform: none;
    max-height: none;
    overflow: visible;
  }
  
  .c-popup__backdrop {
    display: none;
  }
}
