.ds-modal__overlay {
  position: fixed;
  inset: 0;
  z-index: var(--ds-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-md);
  background-color: var(--ds-color-overlay);
  overflow-y: auto;
  animation: ds-modal-fade var(--ds-duration-base) var(--ds-ease-standard);
}

.ds-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - var(--ds-space-xl));
  background-color: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-xl);
  color: var(--ds-color-text);
  font-size: var(--ds-text-md);
  line-height: var(--ds-leading-md);
  animation: ds-modal-rise var(--ds-duration-base) var(--ds-ease-standard);
}

.ds-modal:focus {
  outline: none;
}

.ds-modal--sm { max-width: 400px; }
.ds-modal--md { max-width: 560px; }
.ds-modal--lg { max-width: 800px; }

.ds-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ds-space-md);
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-bottom: 1px solid var(--ds-color-border);
}

.ds-modal__header-text {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-3xs);
  min-width: 0;
}

.ds-modal__title {
  margin: 0;
  font-size: var(--ds-text-xl);
  line-height: var(--ds-leading-xl);
  font-weight: var(--ds-weight-semibold);
}

.ds-modal__description {
  margin: 0;
  color: var(--ds-color-text-muted);
  font-size: var(--ds-text-sm);
  line-height: var(--ds-leading-sm);
}

.ds-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: -2px calc(var(--ds-space-2xs) * -1) 0 0;
  background: none;
  border: none;
  border-radius: var(--ds-radius-sm);
  color: var(--ds-color-text-muted);
  cursor: pointer;
}

.ds-modal__close:hover {
  background-color: var(--ds-color-surface-hover);
  color: var(--ds-color-text);
}

.ds-modal__close:focus-visible {
  outline: 2px solid var(--ds-color-accent);
  outline-offset: 1px;
}

.ds-modal__close > svg {
  display: block;
  width: 16px;
  height: 16px;
}

.ds-modal__body {
  padding: var(--ds-space-lg);
  overflow-y: auto;
}

.ds-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ds-space-xs);
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-top: 1px solid var(--ds-color-border);
  background-color: var(--ds-color-surface-sunken);
}

@keyframes ds-modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ds-modal-rise {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
